Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ULONG ProcessNameOffset = 0;
- void GetProcessNameOffset ( void )
- {
- PEPROCESS PeProcess = PsGetCurrentProcess ();
- ULONG Index;
- if ( !PeProcess )
- {
- DbgPrint ( "ERROR! GetProcessNameOffset failed! [#1]\n" );
- return;
- }
- for ( Index = 0; Index < PAGE_SIZE * 3; Index++ )
- {
- if ( !strncmp ( "System", (PCCHAR)PeProcess + Index, strlen ( "System" ) ) )
- {
- ProcessNameOffset = Index;
- DbgPrint ( "ProcessNameOffset = 0x%X\n", ProcessNameOffset );
- break;
- }
- }
- }
- HANDLE GetProcessId ( const char* Name )
- {
- PEPROCESS PeProcess = PsGetCurrentProcess ();
- ULONG Index = 0;
- HANDLE ProcessId = (HANDLE)-1;
- NTSTATUS Status = STATUS_SUCCESS;
- PCHAR ProcessName = 0;
- if ( PeProcess != 0 )
- {
- for ( Index = 0 ; Index < PAGE_SIZE * 3; Index++ )
- {
- Status = PsLookupProcessByProcessId ( (HANDLE)Index, &PeProcess );
- if ( Status != STATUS_SUCCESS )
- continue;
- if ( PeProcess <= 0 )
- continue;
- ProcessName = (PCHAR)( (PUCHAR)PeProcess + ProcessNameOffset );
- if ( ProcessName )
- {
- if ( !strncmp ( Name, ProcessName, strlen ( Name ) ) )
- {
- ProcessId = (HANDLE)Index;
- break;
- }
- }
- }
- }
- return ProcessId;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement