-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmy_dll.c
More file actions
39 lines (33 loc) · 1.21 KB
/
Copy pathmy_dll.c
File metadata and controls
39 lines (33 loc) · 1.21 KB
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
/*
Name:
dllmain.c - the DLL to inject to other process.
to compile with gcc (two prompts one by another):
gcc -c -o my_dll.o my_dll.c
gcc -s -shared -o my_dll.dll my_dll.o -Wl,--subsystem,windows
Description:
File that contains the code for a simple DLL (dynamic linked library for windows OS.
When this DLL will be loaded by a process, a message box will pop on the screen.
When process loads a DLL it is considered DLL_PROCESS_ATTACH, and therefore all the code that is under that section will be executed by any process that load this DLL.
*/
#include <windows.h>
// this function contains all the code that will be executed by every process that loads this DLL.
// in this case, a message box will pop up.
void DLLCode()
{
MessageBoxA(NULL, TEXT("Hello there!"), TEXT("creative title name"), MB_OK);
}
// the entry point for the DLL.
// when a process loads this DLL, the DLL will start to run the code from this point.
BOOL APIENTRY DllMain( HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserved)
{
switch (ul_reason_for_call)
{
case DLL_PROCESS_ATTACH:
DLLCode();
case DLL_THREAD_ATTACH:
case DLL_THREAD_DETACH:
case DLL_PROCESS_DETACH:
break;
}
return TRUE;
}