Last active
October 23, 2020 15:03
-
-
Save Little-Ki/78f458283a5958f6d344502ee9002508 to your computer and use it in GitHub Desktop.
[Code] [Kernel] Enum thread which in process
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Enum thread which in process | |
struct Thread_t { | |
ULONG64 tid; | |
ULONG64 base; | |
} | |
NTSTATUS EnumProcessThread( HANDLE pid, std::vector<Thread_t> & list ) | |
{ | |
PSYSTEM_PROCESS_INFORMATION pProcess; | |
ULONG needSize; | |
PEPROCESS pEProcess; | |
NTSTATUS status = PsLookupProcessByProcessId( pid, &pEProcess ); | |
if ( !NT_SUCCESS( status ) ) | |
{ | |
returnstatus; | |
} | |
ObReferenceObject( pEProcess ); | |
ZwQuerySystemInformation( 5, NULL, 0, &needSize ); | |
std::vector<char> tmpBuf; | |
tmpBuf.resize( needSize ); | |
ZwQuerySystemInformation( 5, tmpBuf.data(), needSize, &needSize ); | |
pProcess = (PSYSTEM_PROCESS_INFORMATION) tmpBuf.data(); | |
status = STATUS_NOT_FOUND; | |
do | |
{ | |
if ( pProcess->ProcessId == PsGetProcessId( pEProcess ) ) | |
{ | |
status = STATUS_SUCCESS; | |
break; | |
} | |
pProcess = (PSYSTEM_PROCESS_INFORMATION) ( (PUCHAR) pProcess + pProcess->NextEntryOffset); | |
} | |
while ( pProcess->NextEntryOffset != 0 ); | |
if ( !NT_SUCCESS( status ) ) | |
{ | |
ObDereferenceObject( pEProcess ); | |
return status; | |
} | |
for ( ULONGi = 0; i < pProcess->NumberOfThreads; i++ ) | |
{ | |
list.push_back( { | |
(ULONG64) pProcess->Threads[i].ClientId.UniqueThread, | |
(ULONG64) pProcess->Threads[i].StartAddress | |
} ); | |
} | |
ObDereferenceObject( pEProcess ); | |
return status; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment