Click here to Skip to main content
15,929,504 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Function with variable number of arguments Pin
PJ Arends6-Mar-06 15:17
professionalPJ Arends6-Mar-06 15:17 
Questionabsolute value Pin
cuteee6-Mar-06 12:42
cuteee6-Mar-06 12:42 
AnswerRe: absolute value Pin
Chris Richardson6-Mar-06 13:11
Chris Richardson6-Mar-06 13:11 
AnswerRe: absolute value Pin
Neelesh K J Jain6-Mar-06 21:00
Neelesh K J Jain6-Mar-06 21:00 
QuestionConverting C source into C++ library Pin
CodeGoose6-Mar-06 12:09
CodeGoose6-Mar-06 12:09 
QuestionDelayed loading a .dll Pin
Eikthrynir6-Mar-06 11:39
Eikthrynir6-Mar-06 11:39 
AnswerRe: Delayed loading a .dll Pin
Blake Miller7-Mar-06 3:35
Blake Miller7-Mar-06 3:35 
QuestionSEX HERE Pin
gamitech6-Mar-06 11:36
gamitech6-Mar-06 11:36 
Now that I've got youir atttention I would like to ask you a question
So I want to enumerate the processes using NtQuerySystemInformation() native api.
I load it from ntdll.dll
i use the process structure below unlike the one documented by microsoft. but i've seen that others use it too.

typedef struct _SYSTEM_PROCESS_INFORMATION
{
DWORD dNext;
DWORD dThreadCount;
DWORD dReserved01;
DWORD dReserved02;
DWORD dReserved03;
DWORD dReserved04;
DWORD dReserved05;
DWORD dReserved06;
QWORD qCreateTime;
QWORD qUserTime;
QWORD qKernelTime;
UNICODE_STRING usName;
DWORD BasePriority;
DWORD dUniqueProcessId;
DWORD dInheritedFromUniqueProcessId;
DWORD dHandleCount;
DWORD dReserved07;
DWORD dReserved08;
VM_COUNTERS VmCounters;
DWORD dCommitCharge;
SYSTEM_THREAD Threads[1];
} SYSTEM_PROCESS_INFORMATION;

the thing is that when I call it I don't get any error code or null pointers but the structure's members are zeros.
the dNext member is not zero but I can't obtain the next pointer for another system_process_information because i get the invalid pointer error when I try this:

if (ProcessInfo->dNext!=0)
ProcessInfo=(SYSTEM_PROCESS_INFORMATION_DEF *)((ULONG *)ProcessInfo+ProcessInfo->dNext);



And I have another question.
How much space should I allocate for the ProcessInfo structure
i only allocate for one structure
SYSTEM_PROCESS_INFORMATION *ProcessInfo=(SYSTEM_PROCESS_INFORMATION *)malloc(sizeof(SYSTEM_PROCESS_INFORMATION));

or I shouldn't allocate at all. I will obtain a pointer to the structure anyway ?
here is the code I use:


HMODULE ntHinst;

ntHinst=LoadLibraryA(NTDLL);
if (ntHinst==NULL)
{
MessageBoxA(GetDesktopWindow(),"Error loading ntdll\nThe program will now end","ERROR",MB_ICONSTOP);
return 0;
}

_NtQuerySystemInformation=(NTQUERYSYSTEMINFORMATION)GetProcAddress(ntHinst,"NtQuerySystemInformation");
if(!_NtQuerySystemInformation)
{
MessageBoxA(GetDesktopWindow(),"Error obtaining function pointer\nThe program will now terminate","ERROR",MB_ICONSTOP);
return 0;
}


SYSTEM_PROCESS_INFORMATION *ProcessInfo=(SYSTEM_PROCESS_INFORMATION *)malloc(sizeof(SYSTEM_PROCESS_INFORMATION);
if (IsBadReadPtr(ProcessInfo,sizeof(SYSTEM_PROCESS_INFORMATION))||IsBadWritePtr(ProcessInfo,sizeof(SYSTEM_PROCESS_INFORMATION)))
return 0;

_NtQuerySystemInformation(SystemProcessInformation ,(PVOID)ProcessInfo,sizeof(SYSTEM_PROCESS_INFORMATION),&ret);

if (ret==0)
{
MessageBoxA(GetDesktopWindow(),"Function Call Failed: NtQuerySystemInformation\nThe program will now terminate","ERROR",MB_ICONSTOP);
return 0;
}
if(ProcessInfo==NULL)
{
MessageBoxA(GetDesktopWindow(),"Function Call Failed: NtQuerySystemInformation\nThe program will now terminate","ERROR",MB_ICONSTOP);
return 0;
}

while(ProcessInfo!=NULL)
{
//RtlUnicodeStringToOemString(usname,&ProcessInfo->usName,TRUE);
//MessageBoxA(0,usname->Buffer,"",MB_OK);
//RtlFreeOemString(usname);

HANDLE hProc;
hProc=OpenProcess(PROCESS_QUERY_INFORMATION,FALSE,ProcessInfo->dUniqueProcessId);
if (hProc!=NULL)
{
HMODULE hmods[300];
DWORD retv;
char fname[1024];

EnumProcessModules(hProc,hmods,sizeof(hmods),&retv);
retv=retv/sizeof(DWORD);
GetModuleFileNameA(*hmods,fname,sizeof(fname));
MessageBoxA(GetDesktopWindow(),fname,"Process Name",MB_OK);
}
else if (ProcessInfo->dNext!=0)
ProcessInfo=(SYSTEM_PROCESS_INFORMATION_DEF *)((ULONG *)ProcessInfo+ProcessInfo->dNext);
else
ProcessInfo=NULL;

if (ProcessInfo->dNext!=0)
ProcessInfo=(SYSTEM_PROCESS_INFORMATION_DEF *)((ULONG *)ProcessInfo+ProcessInfo->dNext);
else
ProcessInfo=NULL;

}

free(ProcessInfo);

So I get no errors durin calling. but I also get a structure full of zero's.
What is the pb ?
And another thing. Can I use NtQueryDirectoryFile in user mode or this function is only for kernel mode only ?

gabby
QuestionRibbon control Pin
Andre xxxxxxx6-Mar-06 10:38
Andre xxxxxxx6-Mar-06 10:38 
AnswerRe: Ribbon control Pin
PJ Arends6-Mar-06 15:22
professionalPJ Arends6-Mar-06 15:22 
GeneralRe: Ribbon control Pin
Andre xxxxxxx6-Mar-06 23:21
Andre xxxxxxx6-Mar-06 23:21 
QuestionPer-user per-machine registry Pin
Squirrel Twirler6-Mar-06 9:55
Squirrel Twirler6-Mar-06 9:55 
AnswerRe: Per-user per-machine registry Pin
Ryan Binns6-Mar-06 17:25
Ryan Binns6-Mar-06 17:25 
GeneralRe: Per-user per-machine registry Pin
Squirrel Twirler6-Mar-06 19:28
Squirrel Twirler6-Mar-06 19:28 
GeneralRe: Per-user per-machine registry Pin
Ryan Binns6-Mar-06 22:05
Ryan Binns6-Mar-06 22:05 
QuestionProject Includes settings. Pin
Maximilien6-Mar-06 8:39
Maximilien6-Mar-06 8:39 
QuestionNewcomer Guidance Pin
Greg Barnes6-Mar-06 7:53
Greg Barnes6-Mar-06 7:53 
AnswerRe: Newcomer Guidance Pin
Christian Graus6-Mar-06 8:14
protectorChristian Graus6-Mar-06 8:14 
GeneralRe: Newcomer Guidance Pin
Greg Barnes6-Mar-06 8:20
Greg Barnes6-Mar-06 8:20 
GeneralRe: Newcomer Guidance Pin
Chris Meech6-Mar-06 8:45
Chris Meech6-Mar-06 8:45 
AnswerRe: Newcomer Guidance Pin
Ryan Binns6-Mar-06 17:28
Ryan Binns6-Mar-06 17:28 
QuestionWhy? Pin
#realJSOP6-Mar-06 5:47
professional#realJSOP6-Mar-06 5:47 
AnswerRe: Why? Pin
Blake Miller6-Mar-06 5:49
Blake Miller6-Mar-06 5:49 
AnswerRe: Why? Pin
Michael Dunn6-Mar-06 8:03
sitebuilderMichael Dunn6-Mar-06 8:03 
QuestionHow? Pin
Lampros Giampouras6-Mar-06 5:35
Lampros Giampouras6-Mar-06 5:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.