Getting system handles

This is a discussion on Getting system handles within the Windows Programming forums, part of the Platform Specific Boards category; Code: #define SystemHandleInformation 0x10 typedef struct _SYSTEM_HANDLE_INFORMATION { ULONG ProcessId; UCHAR ObjectTypeNumber; UCHAR Flags; USHORT Handle; PVOID Object; ACCESS_MASK GrantedAccess; ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    69

    Getting system handles

    Code:
        #define SystemHandleInformation 0x10
    
    	typedef struct _SYSTEM_HANDLE_INFORMATION {
    		ULONG ProcessId;
    		UCHAR ObjectTypeNumber;
    		UCHAR Flags;
    		USHORT Handle;
    		PVOID Object;
    		ACCESS_MASK GrantedAccess;
    	} SYSTEM_HANDLE_INFORMATION, *PSYSTEM_HANDLE_INFORMATION;
    
    	typedef struct _SYSTEM_HANDLE_INFORMATION_EX {
    		ULONG NumberOfHandles;
    		SYSTEM_HANDLE_INFORMATION Information[1];
    	} SYSTEM_HANDLE_INFORMATION_EX, *PSYSTEM_HANDLE_INFORMATION_EX;
    
    
    
    	typedef DWORD (WINAPI *PfZwQuerySystemInformation)(int, PBYTE, ULONG, PULONG);
    
    	PfZwQuerySystemInformation MyZwQuerySystemInformation;
    
    	PSYSTEM_HANDLE_INFORMATION_EX pStruct;
    	ULONG dimBuffer = sizeof(SYSTEM_HANDLE_INFORMATION); 
    
    	pStruct = (PSYSTEM_HANDLE_INFORMATION_EX)malloc(dimBuffer);
    
    	MyZwQuerySystemInformation = (PfZwQuerySystemInformation)GetProcAddress(GetModuleHandle("ntdll.dll"),"ZwQuerySystemInformation");
    
    #define STATUS_INFO_LENGTH_MISMATCH     0xC0000004L
    #define STATUS_BUFFER_OVERFLOW              0x80000005L
    
    	if(STATUS_INFO_LENGTH_MISMATCH == MyZwQuerySystemInformation(SystemHandleInformation, (PBYTE)pStruct, dimBuffer, &dimBuffer)) 
    MessageBox(NULL,"STATUS_INFO_LENGTH_MISMATCH","",MB_OK | MB_ICONERROR);
    	
    else goto QUERY_OK;
     
      // realloc pStruct
    
        free(pStruct);
    
    	char c[20]; sprintf(c,"0x%x",dimBuffer);MessageBox(NULL,c,"dimBuffer",MB_OK);
    
    	pStruct = (PSYSTEM_HANDLE_INFORMATION_EX)malloc(dimBuffer);
    
    	if(STATUS_INFO_LENGTH_MISMATCH == MyZwQuerySystemInformation(SystemHandleInformation, (PBYTE)pStruct, dimBuffer, &dimBuffer)){
    	 MessageBox(NULL,"STATUS_INFO_LENGTH_MISMATCH","",MB_OK | MB_ICONERROR);
    	 return;
    	} 
    
    QUERY_OK:
    // .......
    All 3 messages wiil be printed out,and dimBuffer will be 0 after the first call to NtQuerySystemInformation( )

    the second call fails because dimBuffer is 0,but shouldn't the first call assign a nonzero value to it???

  2. #2
    Registered User
    Join Date
    Mar 2005
    Posts
    69
    ok,i found the solution by myself,it works

    Code:
    	while(STATUS_INFO_LENGTH_MISMATCH == MyZwQuerySystemInformation(SystemHandleInformation, (PBYTE)pStruct, dimBuffer, &dimBuffer)){
    	 dimBuffer += 4 * 1024;
         free(pStruct);
    	 pStruct = (PSYSTEM_HANDLE_INFORMATION_EX)malloc(dimBuffer);   
    	}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using system icons
    By @nthony in forum Windows Programming
    Replies: 1
    Last Post: 01-13-2007, 07:56 PM
  2. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 04:56 PM
  3. measuring system resources used by a function
    By Aran in forum C Programming
    Replies: 1
    Last Post: 03-13-2006, 05:35 PM
  4. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 07:12 AM
  5. Problem Reporting System. Need Advide!
    By brunomiranda in forum Tech Board
    Replies: 9
    Last Post: 09-25-2003, 10:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21