1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
BOOL QueryProcessInformation( DWORD pid,
PROCESSINFOCLASS infoEnum,
void * pBuffer,
unsigned cbBuffer )
{
HANDLE hProcess = OpenProcess( PROCESS_QUERY_INFORMATION, FALSE, pid );
if ( !hProcess )
return FALSE;
// Zero the input buffer that NtQueryInformationProcess sees
memset( pBuffer, 0, cbBuffer );
DWORD retLen;
int retValue;
//Recup fonction NtQueryInformationProcess
HMODULE hModNt;
PROC pmNtQueryInformationProcess;
hModNt = ::LoadLibrary("NTDLL.DLL");
if (NULL != hModNt)
{
pmNtQueryInformationProcess = ::GetProcAddress(
hModNt, "NtQueryInformationProcess");
::FreeLibrary(hModNt);
}
PFNNTQUERYINFORMATIONPROCESS m_pmNtQueryInformationProcess;
HINSTANCE hInstLib = ::LoadLibrary("Ntdll.dll");
if ( hInstLib )
m_pmNtQueryInformationProcess = (PFNNTQUERYINFORMATIONPROCESS)
::GetProcAddress(hInstLib, "NtQueryInformationProcess");
if ( m_pmNtQueryInformationProcess )
retValue = (int)m_pmNtQueryInformationProcess(hProcess, infoEnum,
pBuffer, cbBuffer, &retLen );
::FreeLibrary(hInstLib);
CloseHandle( hProcess );
if ( retValue < 0 ) // NtQueryInformationProcess returns a negative
return FALSE; // value if it fails
return TRUE;
}
//---------------------------------------------------------------------------
// RecupNtQueryInformationProcess
//
// Recherche du parent process Id
//---------------------------------------------------------------------------
DWORD RecupNtQueryInformationProcess( DWORD pid)
{
PROCESS_BASIC_INFORMATION pbi;
if ( QueryProcessInformation( pid, ProcessBasicInformation,
&pbi, sizeof(pbi)) )
{
//printf( "Process Id UniqueProcessId: %d\n", pbi.UniqueProcessId );
//printf( "Parent Id InheritedFromProcessId: %d\n\n",
// pbi.InheritedFromUniqueProcessId );
return pbi.InheritedFromUniqueProcessId;
}
else
return 0;
} |
Partager