Skip to content

Commit 5951538

Browse files
update project
1 parent 4631b97 commit 5951538

5 files changed

Lines changed: 23 additions & 10 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: CI
2+
23
on:
34
push:
45
branches: [ master ]
@@ -11,7 +12,7 @@ jobs:
1112
runs-on: ubuntu-latest
1213

1314
steps:
14-
- uses: actions/checkout@v4
15+
- uses: actions/checkout@v5
1516

1617
- name: Build project
1718
run: ./build.sh
@@ -20,7 +21,7 @@ jobs:
2021
runs-on: windows-latest
2122

2223
steps:
23-
- uses: actions/checkout@v4
24+
- uses: actions/checkout@v5
2425

2526
- name: Build project
2627
run: build.bat

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ ret = 48
6565
6666
handle = 0x7f79317921e0
6767
exampleFunction_original = 0x7f793178e120
68+
[+] done
6869
6970
exampleFunction(a=1, b=2, c=3)
7071
[+] org ret = 48

demo/module/include/module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#ifdef _WIN32
55
#define DLL_EXPORT __declspec(dllexport)
66
#else
7-
#define DLL_EXPORT __attribute__((visibility("default")))
7+
#define DLL_EXPORT [[gnu::visibility("default")]]
88
#endif
99

1010
extern "C" DLL_EXPORT int exampleFunction(int a, int b, int c);

hook/library.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifdef _WIN32
1111
#define DLL_EXPORT __declspec(dllexport)
1212
#else
13-
#define DLL_EXPORT __attribute__((visibility("default")))
13+
#define DLL_EXPORT [[gnu::visibility("default")]]
1414
#endif
1515

1616
typedef int (*exampleFunction_fptr_t)(int a, int b, int c);
@@ -35,13 +35,22 @@ extern "C" DLL_EXPORT void onStartup() {
3535
#endif
3636
printf("handle = %p\n", handle);
3737
#ifdef _WIN32
38-
exampleFunction_original = (exampleFunction_fptr_t) GetProcAddress((HMODULE) handle, "exampleFunction");
38+
exampleFunction_original = reinterpret_cast<exampleFunction_fptr_t>(
39+
GetProcAddress((HMODULE) handle, "exampleFunction")
40+
);
3941
#else
40-
exampleFunction_original = (exampleFunction_fptr_t) dlsym(handle, "exampleFunction");
42+
exampleFunction_original = reinterpret_cast<exampleFunction_fptr_t>(
43+
dlsym(handle, "exampleFunction")
44+
);
4145
#endif
42-
printf("exampleFunction_original = %p\n", (void *) exampleFunction_original);
46+
printf("exampleFunction_original = %p\n", reinterpret_cast<void *>(exampleFunction_original));
47+
48+
ret = funchook_prepare(
49+
funchook,
50+
reinterpret_cast<void **>(&exampleFunction_original),
51+
reinterpret_cast<void *>(exampleFunction_hook)
52+
);
4353

44-
ret = funchook_prepare(funchook, (void **) &exampleFunction_original, (void *) exampleFunction_hook);
4554
if (ret != 0) {
4655
printf("[-] funchook_prepare failed, ret = %d\n", ret);
4756
return;
@@ -52,4 +61,6 @@ extern "C" DLL_EXPORT void onStartup() {
5261
printf("[-] funchook_install failed, ret = %d\n", ret);
5362
return;
5463
}
64+
65+
printf("[+] done\n");
5566
}

scripts/script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
recv("input", function (message) {
2-
var libraryName = Module.load(message.library).name;
3-
var onStartup = new NativeFunction(Module.getExportByName(libraryName, "onStartup"), "void", []);
2+
var module = Module.load(message.library);
3+
var onStartup = new NativeFunction(module.getExportByName("onStartup"), "void", []);
44
onStartup();
55
send("done");
66
});

0 commit comments

Comments
 (0)