Use "OpenThread" to get the required handle.
PHP Code:
;=================================================================================================
; Function: GetAllThreadsStartAddress($ProcessId)
; Description: Retrieves a list of threads.
; Return Value(s): On Success - Returns an array of matching thread identifiers and handles.
; On Failure - Returns false
; @Error: 0 = No error.
; 1 = Failed to open 'ntdll.dll'.
; 2 = Failed to open 'Kernel32.dll'.
; 3 = Failed to create a snapshot.
; 4 = Failed to copie the first entry of the thread list.
; 5 = Failed to open a thread.
; 6 = Failed to get the start address.
; 7 = Failed to close the opened thread.
; 8 = Failed to copie the next entry of the thread list.
; 7 = Failed to close the created snapshot.
; Author(s): KillerDeluxe
;=================================================================================================
Func GetAllThreadsStartAddress($ProcessId)
$StartAddress = DllStructCreate("DWORD")
$TE32 = DllStructCreate("DWORD;DWORD;DWORD;DWORD;LONG;LONG;DWORD")
DllStructSetData($TE32, 1, DllStructGetSize($TE32))
$ntdll = DllOpen("ntdll.dll")
If @error Then Return SetError(1, "", False)
$Kernel32 = DllOpen("Kernel32.dll")
If @error Then Return SetError(2, "", False)
$hSnapshot = DllCall($Kernel32, "HANDLE", "CreateToolhelp32Snapshot", "int", 4, "DWORD", $ProcessId)
If @error Then Return SetError(3, "", False)
DllCall($Kernel32, "int", "Thread32First", "HANDLE", $hSnapshot[0], "ptr", DllStructGetPtr($TE32))
If @error Then Return SetError(4, "", False)
$ThreadCount = 1
Dim $ReturnArray[2][2]
While True
If DllStructGetData($TE32, 4) == $ProcessId Then
$ReturnArray[0][0] = $ThreadCount
$ReturnArray[0][1] = $ThreadCount
$hThread = DllCall($Kernel32, "HANDLE", "OpenThread", "int", 0x60, "bool", False, "DWORD", DllStructGetData($TE32, 3))
If @error Then Return SetError(5, "", False)
DllCall($ntdll, "none", "NtQueryInformationThread", "HANDLE", $hThread[0], "int", 9, "ptr", DllStructGetPtr($StartAddress), "int", 4, "int", 0)
If @error Then Return SetError(6, "", False)
ReDim $ReturnArray[$ThreadCount + 1][2]
$ReturnArray[$ThreadCount][0] = DllStructGetData($TE32, 3)
$ReturnArray[$ThreadCount][1] = Hex(DllStructGetData($StartAddress, 1))
$ThreadCount += 1
DllCall($Kernel32, "int", "CloseHandle", "HANDLE", $hThread[0])
If @error Then Return SetError(7, "", False)
EndIf
$ret = DllCall($Kernel32, "int", "Thread32Next", "HANDLE", $hSnapshot[0], "ptr", DllStructGetPtr($TE32))
If @error Then Return SetError(8, "", False)
If Not $ret[0] Then ExitLoop
WEnd
DllCall($Kernel32, "int", "CloseHandle", "HANDLE", $hSnapshot[0])
If @error Then Return SetError(9, "", False)
DllClose($ntdll)
DllClose($Kernel32)
Return SetError(0, "", $ReturnArray)
EndFunc
You have to compile the script as a 32 bit application. Otherwise the returned StartAddress will be 0.