Jump to content
Tuts 4 You

Using NtQueryInformationProcess


ibanigger

Recommended Posts

I am looking to use NtQueryProcessInformation into a C++ program. The problem is, when I declare the NtQuery function, i get a strange error.

Here's my code :

typedef NTSTATUS (WINAPI *_NtQueryInformationProcess)(
__in HANDLE ProcessHandle,
__in PROCESSINFOCLASS ProcessInformationClass,
__out PVOID ProcessInformation,
__in ULONG ProcessInformationLength,
__out_opt PULONG ReturnLength
);_NtQueryInformationProcess __NtQueryInformationProcess = NULL;HMODULE NtDll = LoadLibrary("ntdll.dll");_NtQueryInformationProcess __NtQueryInformationProcess = NULL;
__NtQueryInformationProcess = (_NtQueryInformationProcess) GetProcAddress(NtDll, "NtQueryInformationProcess");

But I get those errors because the typedef didnt work :

25uh4r5.jpg

I know that WINAPI is __stdcall (#define WINAPI __stdcall) but I can't seems to fix this error..

I have the same way way to load dynamically another API (a regular one this time, not from ntdll.dll)...

Any help is much appreciated, thanks!

I also have ntdll.lib included into my project and the header Winternl.h (coming from msdn, i needed it).

I use Visual Studio .NET 2003.

Edited by ibanigger
Link to comment

Try ZwQueryInformationProcess remove that _in and _out paste

Went and got some old code:

struct PROCESS_BASIC_INFORMATION {
void* Reserved1;
dword PebBaseAddress;
void* Reserved2[2];
dword UniqueProcessId;
void* Reserved3;
};typedef int (WINAPI* ZwQueryInformationProcess)(HANDLE,DWORD,PROCESS_BASIC_INFORMATION*,DWORD,DWORD*);
ZwQueryInformationProcess MyZwQueryInformationProcess;Example:dword SomeFunction (HANDLE hProc) {
PROCESS_BASIC_INFORMATION peb;
DWORD tmp; HMODULE hMod=GetModuleHandle("ntdll.dll");
MyZwQueryInformationProcess=(ZwQueryInformationProcess)GetProcAddress(hMod,"ZwQueryInformationProcess"); MyZwQueryInformationProcess(hProc,0,&peb,sizeof(PROCESS_BASIC_INFORMATION),&tmp); return peb.PebBaseAddress;
}
Edited by What
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...