@@ -174,7 +174,6 @@ static bool OpenTargetThread(t_HijackData *data) {
174174
175175static 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