-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patha.cpp
More file actions
43 lines (38 loc) · 1.28 KB
/
a.cpp
File metadata and controls
43 lines (38 loc) · 1.28 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
39
40
41
42
43
/**
* @file a.cpp
* @brief 示例DLL源代码
*
* 本DLL演示了如何编写一个可以被反射注入器调用的DLL。
* 编译命令: g++ -shared -o a.dll a.cpp -fPIC "-Wl,--image-base,0x10000000"
*/
#include <windows.h>
// 使用 extern "C" 防止C++编译器对函数名进行name mangling
// 这样可以让反射注入器通过函数名准确找到导出的函数
extern "C" {
/**
* @brief 导出函数:显示一个消息框
*
* 这是示例导出函数,被injector调用后会弹出一个消息框。
* 使用 __declspec(dllexport) 将此函数标记为导出函数,
* 使其可以被外部进程调用。
*/
__declspec(dllexport) void ShowMessageBox() {
// MessageBoxA: Win32 API,用于显示一个模态对话框
// 参数1: 父窗口句柄 (NULL = 无父窗口)
// 参数2: 显示的消息内容
// 参数3: 对话框标题
// 参数4: 按钮和图标类型 (MB_OK = 确定按钮, MB_ICONINFORMATION = 信息图标)
MessageBoxA(NULL, "Hello from DLL!", "DLL Injection", MB_OK | MB_ICONINFORMATION);
}
/**
* @brief 导出函数:简单的加法运算
*
* 演示带参数的导出函数。
* @param a 第一个整数
* @param b 第二个整数
* @return 两个数的和
*/
__declspec(dllexport) int Add(int a, int b) {
return a + b;
}
}