Ejemplo n.º 1
0
//this unit will contain the functions and other crap used by the hider function
BOOLEAN CheckImageName(IN PUNICODE_STRING FullImageName, IN char* List,int listsize)
{
#ifndef AMD64
	/*
	pre:List has been initialized and all entries are UPPERCASE. Each entry is seperated
	    by a 0-marker so just setting the pointer ro the start and doing a compare will work

	*/
	ANSI_STRING tempstring;
	int i;

	DbgPrint("Checking this image name...\n");
	RtlZeroMemory(&tempstring,sizeof(ANSI_STRING));
	if (RtlUnicodeStringToAnsiString(&tempstring,FullImageName,TRUE)== STATUS_SUCCESS)
	{
		char *p;
		INT_PTR modulesize;
		__try
		{
			RtlUpperString(&tempstring,&tempstring);

			p=List;
	
			for (i=0;i<listsize;i++)
			{
				if (List[i]=='\0')
				{
					modulesize=i-(INT_PTR)(p-List);
					if (modulesize>=0)
					{	
						DbgPrint("Checking %s with %s\n",&tempstring.Buffer[tempstring.Length-modulesize],p);

						if ((tempstring.Length>=modulesize) && (strcmp(p,&tempstring.Buffer[tempstring.Length-modulesize])==0))
						{
							//we have a match!!!
							DbgPrint("It's a match with %s\n",p);
							return TRUE;	
						}						
	
					}
					p=&List[i+1];
				}
	
			}
		
			
		}
		__finally
		{
			RtlFreeAnsiString(&tempstring);	
		}
	}
Ejemplo n.º 2
0
NTSTATUS HookZwQueryDirectoryFile(
   IN HANDLE hFile,
   IN HANDLE hEvent OPTIONAL,
   IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL,
   IN PVOID IoApcContext OPTIONAL,
   OUT PIO_STATUS_BLOCK pIoStatusBlock,
   OUT PVOID FileInformationBuffer,
   IN ULONG FileInformationBufferLength,
   IN FILE_INFORMATION_CLASS FileInfoClass,
   IN BOOLEAN bReturnOnlyOneEntry,
   IN PUNICODE_STRING PathMask OPTIONAL,
   IN BOOLEAN bRestartQuery)
{
   NTSTATUS         rc;
   CHAR            aProcessName[80];   
   ANSI_STRING       ansiFileName,ansiDirName;
   UNICODE_STRING     uniFileName;
   PP_DIR          ptr;

   WCHAR           ParentDirectory[1024] = {0};
   int            BytesReturned;
   PVOID           Object;

      
   // implementation fo the old ZwQueryDirectoryFile function
   rc = ((ZWQUERYDIRECTORYFILE)(OldZwQueryDirectoryFile))(
        hFile,                  
        hEvent,
        IoApcRoutine,
        IoApcContext,
        pIoStatusBlock,
        FileInformationBuffer,
        FileInformationBufferLength,
        FileInfoClass,
        bReturnOnlyOneEntry,
        PathMask,
        bRestartQuery);

   if(NT_SUCCESS(rc))
   {
      PDirEntry p;
      PDirEntry pLast;
      BOOL bLastOne;
      int found;      
      p = (PDirEntry)FileInformationBuffer;   //will assign the structure to find out the results of
      pLast = NULL;
      
      do
      {
        bLastOne = !( p->dwLenToNext );
        RtlInitUnicodeString(&uniFileName,p->suName);
        RtlUnicodeStringToAnsiString(&ansiFileName,&uniFileName,TRUE);
        RtlUnicodeStringToAnsiString(&ansiDirName,&uniFileName,TRUE);
        RtlUpperString(&ansiFileName,&ansiDirName);

        found=0;
        
        //find the list contains the current directory
        for(ptr = list_head; ptr != NULL; ptr = ptr->next)
        {
           if (ptr->flag != PTR_HIDEDIR) continue;
           if( RtlCompareMemory( ansiFileName.Buffer, ptr->name,strlen(ptr->name) ) == strlen(ptr->name))
           {
              found=1;
              break;
           }
        }//end for

        //Find the list contains the current directory
        if(found)
        {
           if(bLastOne)
           {
              if(p == (PDirEntry)FileInformationBuffer )
              {
                 rc = 0x80000006;   //Hide
              }
              else
                pLast->dwLenToNext = 0;
              break;
           }
           else
           {
              int iPos = ((ULONG)p) - (ULONG)FileInformationBuffer;
              int iLeft = (DWORD)FileInformationBufferLength - iPos - p->dwLenToNext;
              RtlCopyMemory( (PVOID)p, (PVOID)( (char *)p + p->dwLenToNext ), (DWORD)iLeft );
              continue;
           }
        }
        pLast = p;
        p = (PDirEntry)((char *)p + p->dwLenToNext );
      }while( !bLastOne );
      RtlFreeAnsiString(&ansiDirName);  
      RtlFreeAnsiString(&ansiFileName);
   }
   return(rc);
}