MCPcopy Create free account
hub / github.com/NoMercy-ac/NoMercy / GetThreadIdFromAddress

Method GetThreadIdFromAddress

Source/Client/NM_Engine/ThreadFunctions.cpp:127–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125
126
127DWORD CThreadFunctions::GetThreadIdFromAddress(DWORD dwAddress)
128{
129 auto hSnap = g_winapiApiTable->CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, NULL);
130 if (!IS_VALID_HANDLE(hSnap))
131 {
132 DEBUG_LOG(LL_ERR, "CreateToolhelp32Snapshot fail! Error: %u", g_winapiApiTable->GetLastError());
133 return 0;
134 }
135
136 THREADENTRY32 ti = { 0 };
137 ti.dwSize = sizeof(ti);
138
139 if (g_winapiApiTable->Thread32First(hSnap, &ti))
140 {
141 do {
142 if (ti.th32OwnerProcessID == g_winapiApiTable->GetCurrentProcessId())
143 {
144 auto hThread = g_winapiApiTable->OpenThread(THREAD_QUERY_INFORMATION, false, ti.th32ThreadID);
145 if (IS_VALID_HANDLE(hThread))
146 {
147 auto dwStartAddress = GetThreadStartAddress(hThread);
148 if (dwStartAddress == dwAddress)
149 {
150 g_winapiApiTable->CloseHandle(hThread);
151 g_winapiApiTable->CloseHandle(hSnap);
152
153 return ti.th32ThreadID;
154 }
155 g_winapiApiTable->CloseHandle(hThread);
156 }
157 }
158 } while (g_winapiApiTable->Thread32Next(hSnap, &ti));
159 }
160
161 g_winapiApiTable->CloseHandle(hSnap);
162 return 0;
163}
164
165HANDLE CThreadFunctions::CreateThread(int iCustomThreadCode, LPTHREAD_START_ROUTINE pFunc, LPVOID lpParam, LPDWORD pdwThreadId)
166{

Callers

nothing calls this directly

Calls 2

OpenThreadMethod · 0.80
CloseHandleMethod · 0.80

Tested by

no test coverage detected