fscan的main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import "C"
...
//export haha
func haha() {
start := time.Now()
var Info common.HostInfo
common.Flag(&Info)
common.Parse(&Info)
Plugins.Scan(Info)
t := time.Now().Sub(start)
fmt.Printf("[*] 扫描结束,耗时: %s\n", t)
}
- 编译成dll
1
2
3
go build -o main.dll -buildmode=c-shared
//减小体积
go build -ldflags "-s -w" -o main.dll -buildmode=c-shared
- python调用
1
2
3
4
5
6
7
8
9
import time
from ctypes import cdll, c_char_p
start = time.time()
# 加载动态链接库
lib = cdll.LoadLibrary('./main.dll')
# 配置输出参数变量类型
lib.haha.restype = c_char_p
# 调用方法
rest = lib.haha()
- c++调用
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
#include <iostream>
#include <windows.h>
int main() {
// 加载DLL
HMODULE hDLL = LoadLibrary(L"main.dll");
if (hDLL == NULL) {
std::cerr << "无法加载 DLL" << std::endl;
return 1;
}
// 获取函数地址
typedef void (*FunctionPtr)();
FunctionPtr bFunction = (FunctionPtr)GetProcAddress(hDLL, "haha");
if (bFunction == NULL) {
std::cerr << "无法获取函数地址" << std::endl;
FreeLibrary(hDLL); // 卸载DLL
return 1;
}
// 调用函数
bFunction();
// 卸载DLL
FreeLibrary(hDLL);
return 0;
}