2 * Copyright (C) 2010 gonzoj
4 * Please check the CREDITS file for further information.
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #define FUNC(r, a, f, p) typedef r a (*f##_t)p; f##_t f = (f##_t) NULL; char *str_##f = #f;
28 FUNC(void *, __attribute__((stdcall)), GetProcAddress
, (void *module
, int function
))
29 FUNC(void *, __attribute__((stdcall)), GetModuleHandleA
, (const char *module
))
30 FUNC(void *, __attribute__((stdcall)), LoadLibraryA
, (const char *module
))
31 FUNC(void *, __attribute__((stdcall)), CreateToolhelp32Snapshot
, (int flags
, long pid
))
32 FUNC(void *, __attribute__((stdcall)), OpenThread
, (int access
, int inherit_handle
, int thread_id
))
33 FUNC(int, __attribute__((stdcall)), SuspendThread
, (void *thread
))
34 FUNC(int, __attribute__((stdcall)), ResumeThread
, (void *thread
))
35 FUNC(int, __attribute__((stdcall)), Thread32First
, (void *snap_thread
, THREADENTRY32
*thread_entry
))
36 FUNC(int, __attribute__((stdcall)), Thread32Next
, (void *snap_thread
, THREADENTRY32
*thread_entry
))
37 FUNC(int, __attribute__((stdcall)), GetCurrentThreadId
, ())
38 FUNC(int, __attribute__((stdcall)), GetCurrentProcessId
, ())
39 FUNC(void *, __attribute__((stdcall)), CreateThread
, (void *sa
, size_t stack
, void *func
, void *param
, int flags
, void *tid
))
44 manage_threads(int __attribute__((stdcall))
45 (*manage_thread
)(void *thread
))
47 DWORD pid
= GetCurrentProcessId();
48 void *snap_thread
= CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD
, pid
);
49 THREADENTRY32 thread_entry
;
50 DEBUG_DO(printf("managing threads... ");)
51 DWORD self
= GetCurrentThreadId();
53 if (Thread32First(snap_thread
, &thread_entry
))
58 if (thread_entry
.th32OwnerProcessID
!= pid
)
62 if (thread_entry
.th32ThreadID
== self
)
67 if ((th
= OpenThread(THREAD_SUSPEND_RESUME
, 0,
68 thread_entry
.th32ThreadID
)) == NULL
)
70 printf("err: could not open thread\n");
73 if (manage_thread(th
) == -1)
75 printf("err: could not suspend/resume thread\n");
79 while (Thread32Next(snap_thread
, &thread_entry
));
81 DEBUG_DO(printf("done (%i)\n", i
));