-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDllInjector.cpp
82 lines (64 loc) · 1.69 KB
/
DllInjector.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <windows.h>
extern HWND chWnd;
extern BOOL bWantInjection;
BOOL bInstalled = FALSE;
void Install(HWND hWnd, DWORD pid)
{
HANDLE hProcess = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ,
FALSE, pid);
if (hProcess != NULL)
{
HANDLE hThread;
char szLibPath [_MAX_PATH];
void* pLibRemote = 0;
DWORD hLibModule = 0;
HMODULE hKernel32 = ::GetModuleHandle("Kernel32");
strcpy(szLibPath, "taskhook.dll");
pLibRemote = ::VirtualAllocEx( hProcess, NULL, sizeof(szLibPath), MEM_COMMIT, PAGE_READWRITE );
if (pLibRemote == NULL)
return;
::WriteProcessMemory(hProcess, pLibRemote, (void*)szLibPath,sizeof(szLibPath),NULL);
hThread = ::CreateRemoteThread( hProcess, NULL, 0,
(LPTHREAD_START_ROUTINE) ::GetProcAddress(hKernel32,"LoadLibraryA"),
pLibRemote, 0, NULL );
if( hThread != NULL )
{
::SendMessage(chWnd, 0x7053, (WPARAM)0, (LPARAM)0);
bInstalled = TRUE;
::WaitForSingleObject( hThread, INFINITE );
::GetExitCodeThread( hThread, &hLibModule );
::CloseHandle( hThread );
}
}
}
BOOL CALLBACK EnumProc(HWND hWnd, LPARAM p)
{
char szTitle[24];
::GetWindowText(hWnd, szTitle, sizeof(szTitle));
if (strcmp(szTitle, "Windows Task Manager") == 0)
{
DWORD pid;
GetWindowThreadProcessId(hWnd, &pid);
Install(hWnd, pid);
}
return TRUE;
}
DWORD WINAPI GetTaskManagerThread(LPVOID p)
{
while (bWantInjection == TRUE)
{
// if (bInstalled == FALSE)
// {
EnumWindows(EnumProc, (LPARAM)p);
::Sleep(100);
// }
// else
// ::Sleep(100);
}
return 0;
}
void StartItUp(void)
{
DWORD tid;
CreateThread(NULL, 0, GetTaskManagerThread, NULL, 0, &tid);
}