通过数组指针循环?

时间:2013-05-25 04:34:52

标签: c++ c arrays pointers wchar

我对C ++不是很有经验,我正在阅读一些代码,想知道这是有道理的......

WCHAR *Process[128];
   for(i=0; i<Process; i++)

我看到一个指向wchar数组的指针,你怎么能循环呢?它会循环遍历整个阵列吗?

以下是整个代码:

WCHAR *ProcessToHide[128];
ULONG NbProcessToHide=0;

ZWQUERYSYSTEMINFORMATION ZwQuerySystemInformationAddress = NULL;   

LONGLONG UserTime=0, KernelTime=0;

NTSTATUS ZwQuerySystemInformationHook(
            IN ULONG SystemInformationClass,
            IN PVOID SystemInformation,
            IN ULONG SystemInformationLength,
            OUT PULONG ReturnLength)
{

   NTSTATUS status;
   PSYSTEM_PROCESS_INFORMATION curr;
   PSYSTEM_PROCESS_INFORMATION prev;
   ULONG i;

   status = ((ZWQUERYSYSTEMINFORMATION)(ZwQuerySystemInformationAddress)) (
                    SystemInformationClass,
                    SystemInformation,
                    SystemInformationLength,
                    ReturnLength );

   if( !NT_SUCCESS(status) ) 
      return status;

   if(SystemInformationClass!=5) // not a process request
      return status;       

for(i=0; i<NbProcessToHide; i++) {

      curr = (PSYSTEM_PROCESS_INFORMATION)SystemInformation;
      prev = NULL;

      while(curr) {
         //DbgPrint("Current item is %x\n", curr);
         if (curr->ProcessName.Buffer != NULL) {   

            if( curr->ProcessName.Length == wcslen(ProcessToHide[i])*2 &&
                !memcmp(curr->ProcessName.Buffer,ProcessToHide[i], curr->ProcessName.Length)) 
            {                                                                       

               if(!prev) {
                  // we are first process     
                  if(curr->NextEntryDelta) // if there is a process after it
                     // first process becomes this one
                     (PBYTE)SystemInformation += curr->NextEntryDelta;
                  else 
                     // no process ! >_>
                     SystemInformation = NULL;
               }
               else {
                  // there was a process before
                  if(curr->NextEntryDelta) // if there is a process after
                     // previous process leads to next 
                     prev->NextEntryDelta += curr->NextEntryDelta;
                  else  
                     // previous process is the last one =)
                     prev->NextEntryDelta = 0;    
               }    
            } 
            else
               // not a process to hide, prev ptr go to this process
               prev = curr;  
         }

         // curr go to next process
         if(curr->NextEntryDelta) 
            ((PBYTE)curr += curr->NextEntryDelta);
         else 
             curr = NULL;
      }
   }

1 个答案:

答案 0 :(得分:2)

WCHAR *Process[128];不是指向WCHAR数组的指针,它是一个WCHAR指针数组(可能是字符串)。

您可能需要阅读Reading C Declarations

  

示例2:char * argv [];

     

步骤1,写“声明argv为”。第2步,向右排列。第3步,写“数组”。第4步,指向左侧。第5步,写“指针”。第6步,完成申报。第7步,写“char”。停止。

     

声明是:“将argv声明为指向char的指针数组”。请注意,它不是指向char数组的指针。数组描述符优先于指针描述符,并首先读取。

iNbProcessToHide可以进行比较,因为它们都是ULONG