Created
May 20, 2020 16:23
-
-
Save blaquee/c13cae04d427e70fabe6e0e8aef475b4 to your computer and use it in GitHub Desktop.
Process listing the Native way on Vista +
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HANDLE curHandle = nullptr; | |
NTSTATUS status; | |
ULONG dwLen = 0; | |
UNICODE_STRING strProcNameBuffer = { 0 }; | |
PUNICODE_STRING ucBuffer = nullptr; | |
//enumerate next processes, use flag 1 to enumerate the processlist backwards | |
while (NtGetNextProcess(curHandle, MAXIMUM_ALLOWED, 0, 0, &curHandle) == STATUS_SUCCESS) | |
{ | |
status = NtQueryInformationProcess(curHandle, ProcessImageFileName, 0, 0, &dwLen); | |
if (status != STATUS_INFO_LENGTH_MISMATCH) | |
break; | |
if (dwLen) | |
{ | |
ucBuffer = (PUNICODE_STRING)malloc(dwLen); | |
if (ucBuffer) | |
{ | |
status = NtQueryInformationProcess(curHandle, ProcessImageFileName, ucBuffer, dwLen, &dwLen); | |
printf("procname len: %d\n", ucBuffer->Length); | |
printf("Process Name: %wZ\n", ucBuffer); | |
} | |
} | |
if(ucBuffer) | |
free(ucBuffer); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment