-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsfx.c
71 lines (60 loc) · 2.04 KB
/
jsfx.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <stdint.h>
#include "patched_bytes.h"
#define NSEEL_API_MAGIC 0x2985ac757f70b25c
// addresses defined in linker script
int NSEEL_addfunc_ret_type;
int NSEEL_addfunc_varparm_ex;
int NSEEL_PProc_RAM;
int NSEEL_PProc_THIS;
void *eel_gmem_attach;
int strcmp(const char *, const char *);
typedef struct {
uint64_t magic;
void *GetFunc;
void *NSEEL_PProc_RAM;
void *NSEEL_PProc_THIS;
void *NSEEL_addfunc_ret_type;
void *NSEEL_addfunc_varparm_ex;
void *eel_gmem_attach;
} NSEEL_API_t;
asm(
".global register_functions \n"
"register_functions: \n"
"call _register_functions \n"
register_functions_patched_bytes
);
void *GetFunc(char *name) {
if (strcmp(name, "eel_gmem_attach") == 0) {
return eel_gmem_attach;
} else {
return NULL;
}
}
typedef int (*JSFXRegister_t)(NSEEL_API_t *NSEEL_API);
void _register_functions() {
NSEEL_API_t NSEEL_API;
NSEEL_API.magic = NSEEL_API_MAGIC;
NSEEL_API.GetFunc = GetFunc;
NSEEL_API.NSEEL_PProc_RAM = &NSEEL_PProc_RAM;
NSEEL_API.NSEEL_PProc_THIS = &NSEEL_PProc_THIS;
NSEEL_API.NSEEL_addfunc_ret_type = &NSEEL_addfunc_ret_type;
NSEEL_API.NSEEL_addfunc_varparm_ex = &NSEEL_addfunc_varparm_ex;
NSEEL_API.eel_gmem_attach = eel_gmem_attach;
HMODULE kernel32 = GetModuleHandleA("kernel32.dll");
if (kernel32 == NULL) { return; }
BOOL (*EnumProcessModules)(HANDLE, HMODULE *, DWORD, LPDWORD) =
(BOOL (*)(HANDLE, HMODULE *, DWORD, LPDWORD))GetProcAddress(kernel32, "K32EnumProcessModules");
if (EnumProcessModules == NULL) { return; }
HMODULE modules[200];
DWORD cbNeeded;
if (EnumProcessModules(GetCurrentProcess(), modules, sizeof(modules), &cbNeeded) == 0) { return; }
if (cbNeeded > sizeof(modules)) { return; }
for (int i = 0; i < cbNeeded/sizeof(modules[0]); i++) {
JSFXRegister_t JSFXRegister = (JSFXRegister_t)GetProcAddress(modules[i], "JSFXRegister");
if (JSFXRegister != NULL) {
JSFXRegister(&NSEEL_API);
}
}
}