Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Help Get handles of process

Help Get handles of process

Scheduled Pinned Locked Moved C / C++ / MFC
help
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    so0_lanhlung2
    wrote on last edited by
    #1

    i have function void CShowHandlesOfProc::AddHandlesToList(CListCtrl *m_list,DWORD pid) { int nItem=0; NTSTATUS status; PSYSTEM_HANDLE_INFORMATION handleInfo=new SYSTEM_HANDLE_INFORMATION; ULONG handleInfoSize ; HANDLE processHandle; ULONG i; _NtQuerySystemInformation NtQuerySystemInformation = (_NtQuerySystemInformation)GetLibraryProcAddress("ntdll.dll", "NtQuerySystemInformation"); _NtDuplicateObject NtDuplicateObject = (_NtDuplicateObject)GetLibraryProcAddress("ntdll.dll", "NtDuplicateObject"); _NtQueryObject NtQueryObject = (_NtQueryObject)GetLibraryProcAddress("ntdll.dll", "NtQueryObject"); if(!(processHandle = OpenProcess(PROCESS_DUP_HANDLE|PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,pid))) return; // handleInfo = (PSYSTEM_HANDLE_INFORMATION)malloc(handleInfoSize); //while((status = NtQuerySystemInformation(SystemHandleInformation,handleInfo,handleInfoSize,NULL)) == STATUS_INFO_LENGTH_MISMATCH) //handleInfo = (PSYSTEM_HANDLE_INFORMATION)realloc(handleInfo, handleInfoSize *= 2); DWORD size=sizeof(SYSTEM_HANDLE_INFORMATION); DWORD needed=0; status = NtQuerySystemInformation(SystemHandleInformation,handleInfo,size,&needed); if(!NT_SUCCESS(status)) { if(needed==0) return ; delete handleInfo; size = needed + 1024; handleInfo= (PSYSTEM_HANDLE_INFORMATION)new BYTE[size]; status = NtQuerySystemInformation(SystemHandleInformation,handleInfo,size,&needed); if(status==STATUS_INFO_LENGTH_MISMATCH) MessageBox(L"Khong du Length cho NtQuerySystem"); if(!NT_SUCCESS(status)) { delete handleInfo; return; } } for(i = 0; i < handleInfo->HandleCount; i++) { SYSTEM_HANDLE handle = handleInfo->Handles[i]; HANDLE dupHandle = NULL; POBJECT_TYPE_INFORMATION objectTypeInfo=new OBJECT_TYPE_INFORMATION; DWORD sizeType=0; PVOID objectNameInfo; UNICODE_STRING objectName; ULONG returnLength; if(handle.ProcessId != pid) continue; status=NtDuplicateObject( processHandle, (HANDLE)handle.Handle, GetCurrentProcess(), &dupHandle, 0, 0, 0 ); /* if (status=STATUS_ACCESS_DENIED) { MessageBox(L"deny access handle"); continue;

    H 1 Reply Last reply
    0
    • S so0_lanhlung2

      i have function void CShowHandlesOfProc::AddHandlesToList(CListCtrl *m_list,DWORD pid) { int nItem=0; NTSTATUS status; PSYSTEM_HANDLE_INFORMATION handleInfo=new SYSTEM_HANDLE_INFORMATION; ULONG handleInfoSize ; HANDLE processHandle; ULONG i; _NtQuerySystemInformation NtQuerySystemInformation = (_NtQuerySystemInformation)GetLibraryProcAddress("ntdll.dll", "NtQuerySystemInformation"); _NtDuplicateObject NtDuplicateObject = (_NtDuplicateObject)GetLibraryProcAddress("ntdll.dll", "NtDuplicateObject"); _NtQueryObject NtQueryObject = (_NtQueryObject)GetLibraryProcAddress("ntdll.dll", "NtQueryObject"); if(!(processHandle = OpenProcess(PROCESS_DUP_HANDLE|PROCESS_QUERY_INFORMATION|PROCESS_VM_READ,FALSE,pid))) return; // handleInfo = (PSYSTEM_HANDLE_INFORMATION)malloc(handleInfoSize); //while((status = NtQuerySystemInformation(SystemHandleInformation,handleInfo,handleInfoSize,NULL)) == STATUS_INFO_LENGTH_MISMATCH) //handleInfo = (PSYSTEM_HANDLE_INFORMATION)realloc(handleInfo, handleInfoSize *= 2); DWORD size=sizeof(SYSTEM_HANDLE_INFORMATION); DWORD needed=0; status = NtQuerySystemInformation(SystemHandleInformation,handleInfo,size,&needed); if(!NT_SUCCESS(status)) { if(needed==0) return ; delete handleInfo; size = needed + 1024; handleInfo= (PSYSTEM_HANDLE_INFORMATION)new BYTE[size]; status = NtQuerySystemInformation(SystemHandleInformation,handleInfo,size,&needed); if(status==STATUS_INFO_LENGTH_MISMATCH) MessageBox(L"Khong du Length cho NtQuerySystem"); if(!NT_SUCCESS(status)) { delete handleInfo; return; } } for(i = 0; i < handleInfo->HandleCount; i++) { SYSTEM_HANDLE handle = handleInfo->Handles[i]; HANDLE dupHandle = NULL; POBJECT_TYPE_INFORMATION objectTypeInfo=new OBJECT_TYPE_INFORMATION; DWORD sizeType=0; PVOID objectNameInfo; UNICODE_STRING objectName; ULONG returnLength; if(handle.ProcessId != pid) continue; status=NtDuplicateObject( processHandle, (HANDLE)handle.Handle, GetCurrentProcess(), &dupHandle, 0, 0, 0 ); /* if (status=STATUS_ACCESS_DENIED) { MessageBox(L"deny access handle"); continue;

      H Offline
      H Offline
      Hans Dietrich
      wrote on last edited by
      #2

      After this statement

      status = NtQuerySystemInformation(SystemHandleInformation,handleInfo,size,&needed);
      

      the count is

      handleInfo->HandleCount=39337

      Your code then goes on to examine each of the handles to check if it belongs to the PID. After finding 26 handles, your code crashes in malloc with ENOMEM. As far as I can tell, up until then the buffer objectTypeInfo->Name.Buffer contains valid strings. So the good news is, your code seems to be working. Maybe you could search for the specific APIs you're using, and check if you're calling them correctly? It looks like you're not freeing some memory buffer.

      Best wishes, Hans


      [Hans Dietrich Software]

      S 1 Reply Last reply
      0
      • H Hans Dietrich

        After this statement

        status = NtQuerySystemInformation(SystemHandleInformation,handleInfo,size,&needed);
        

        the count is

        handleInfo->HandleCount=39337

        Your code then goes on to examine each of the handles to check if it belongs to the PID. After finding 26 handles, your code crashes in malloc with ENOMEM. As far as I can tell, up until then the buffer objectTypeInfo->Name.Buffer contains valid strings. So the good news is, your code seems to be working. Maybe you could search for the specific APIs you're using, and check if you're calling them correctly? It looks like you're not freeing some memory buffer.

        Best wishes, Hans


        [Hans Dietrich Software]

        S Offline
        S Offline
        so0_lanhlung2
        wrote on last edited by
        #3

        i try free objectTypeInfo but still stack over flow.. can you help me?.. so hard to use this Undocument Api.... :sigh:

        H 1 Reply Last reply
        0
        • S so0_lanhlung2

          i try free objectTypeInfo but still stack over flow.. can you help me?.. so hard to use this Undocument Api.... :sigh:

          H Offline
          H Offline
          Hans Dietrich
          wrote on last edited by
          #4

          Send me your email address and I will email some code. Please send to hdietrich@gmail.com

          Best wishes, Hans


          [Hans Dietrich Software]

          S 1 Reply Last reply
          0
          • H Hans Dietrich

            Send me your email address and I will email some code. Please send to hdietrich@gmail.com

            Best wishes, Hans


            [Hans Dietrich Software]

            S Offline
            S Offline
            so0_lanhlung2
            wrote on last edited by
            #5

            i sent code for you...plz help me :) thanks so much

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups