Skip to content

Instantly share code, notes, and snippets.

@xooxo
Created June 8, 2020 19:13
Show Gist options
  • Save xooxo/a4aa08490cc05b88f0fbcda70ed36451 to your computer and use it in GitHub Desktop.
Save xooxo/a4aa08490cc05b88f0fbcda70ed36451 to your computer and use it in GitHub Desktop.
NtQueryInformationProcess runtime-linking
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