Last active
September 27, 2016 09:13
-
-
Save vuonghv/0562a004c9cd530c18b89be7d389e5df to your computer and use it in GitHub Desktop.
Get the start address of a Thread in windows
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
from ctypes import c_ulong, windll, byref, sizeof, c_void_p | |
ntdll = windll.ntdll | |
DWORD = c_ulong | |
HANDLE = c_void_p | |
# Defines THREADINFOCLASS enumeration | |
ThreadBasicInformation = 0 | |
ThreadTimes = 1 | |
ThreadPriority = 2 | |
ThreadBasePriority = 3 | |
ThreadAffinityMask = 4 | |
ThreadImpersonationToken = 5 | |
ThreadDescriptorTableEntry = 6 | |
ThreadEnableAlignmentFaultFixup = 7 | |
ThreadEventPair = 8 | |
ThreadQuerySetWin32StartAddress = 9 | |
ThreadZeroTlsCell = 10 | |
ThreadPerformanceCount = 11 | |
ThreadAmILastThread = 12 | |
ThreadIdealProcessor = 13 | |
ThreadPriorityBoost = 14 | |
ThreadSetTlsArrayAddress = 15 | |
ThreadIsIoPending = 16 | |
ThreadHideFromDebugger = 17 | |
STATUS_SUCCESS = 0 | |
def start_address(thread_handle): | |
"""Return the start address of the thread_handle""" | |
start_addr = DWORD(0) | |
status = ntdll.NtQueryInformationThread(thread_handle, | |
ThreadQuerySetWin32StartAddress, | |
byref(start_addr), | |
sizeof(DWORD), | |
None) | |
if status != STATUS_SUCCESS: | |
return None | |
return start_addr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment