-
-
Save xooxo/a4aa08490cc05b88f0fbcda70ed36451 to your computer and use it in GitHub Desktop.
NtQueryInformationProcess runtime-linking
This file contains 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
typedef NTSTATUS (NTAPI *pfnNtQueryInformationProcess)( | |
IN HANDLE ProcessHandle, | |
IN PROCESSINFOCLASS ProcessInformationClass, | |
OUT PVOID ProcessInformation, | |
IN ULONG ProcessInformationLength, | |
OUT PULONG ReturnLength OPTIONAL | |
); | |
// ... blahblahblah ... | |
// This function has some context but it is ripped off here. So..... | |
int demoNtQuery(void){ | |
/* Get ntdll.dll */ | |
HMODULE hNtDll = GetModuleHandleA("ntdll"); | |
pfnNtQueryInformationProcess gNtQueryInformationProcess; | |
gNtQueryInformationProcess = (pfnNtQueryInformationProcess)GetProcAddress(hNtDll, | |
"NtQueryInformationProcess"); | |
/* */ | |
HANDLE targetHandle = findProcessHandle(); | |
if(targetHandle){ | |
// OUT PVOID ProcessInformation ==> buffer to write result! Its size is important (must greater or equal to result of ProcessInformationClass [The type of process information to be retrieved]) | |
PVOID processInfoBuffer; | |
NTSTATUS processInfo = gNtQueryInformationProcess(targetHandle,ProcessImageFileName,processInfoBuffer,(ULONG)sizeof(processInfoBuffer),(PULONG)sizeof(processInfoBuffer)); | |
CloseHandle(targetHandle); | |
return 0; | |
} | |
// if handle failed: | |
return 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment