@@ -93,9 +93,7 @@ int load_normal_executable() {
93
93
}
94
94
95
95
int load_node_dynamic (void ) {
96
- // #ifndef WIN32
97
96
plthook_t * plthook_node_loader ;
98
- // #endif
99
97
dyn_handle_t libnode , node_loader ;
100
98
101
99
printf ("METACALL load from node compiled dynamically to libnode\n" );
@@ -133,40 +131,6 @@ int load_node_dynamic(void) {
133
131
// assert(dyn_sym(libnode, "string_function2", (void (**)(void))&string_fp2) == 0);
134
132
135
133
// Patch the node_loader
136
- /*#ifdef WIN32
137
- {
138
- HMODULE lib = node_loader;
139
- PIMAGE_DOS_HEADER dos = (PIMAGE_DOS_HEADER)lib;
140
- PIMAGE_NT_HEADERS nt = (PIMAGE_NT_HEADERS)((uintptr_t)lib + dos->e_lfanew);
141
- PIMAGE_DELAYLOAD_DESCRIPTOR dload = (PIMAGE_DELAYLOAD_DESCRIPTOR)((uintptr_t)lib +
142
- nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress);
143
- while (dload->DllNameRVA)
144
- {
145
- char* dll = (char*)((uintptr_t)lib + dload->DllNameRVA);
146
- if (!strcmp(dll, "libnode2.dll")) {
147
- PIMAGE_THUNK_DATA firstthunk = (PIMAGE_THUNK_DATA)((uintptr_t)lib + dload->ImportNameTableRVA);
148
- PIMAGE_THUNK_DATA functhunk = (PIMAGE_THUNK_DATA)((uintptr_t)lib + dload->ImportAddressTableRVA);
149
- while (firstthunk->u1.AddressOfData)
150
- {
151
- if (firstthunk->u1.Ordinal & IMAGE_ORDINAL_FLAG) {}
152
- else {
153
- PIMAGE_IMPORT_BY_NAME byName = (PIMAGE_IMPORT_BY_NAME)((uintptr_t)lib + firstthunk->u1.AddressOfData);
154
- if (!strcmp((char*)byName->Name, "string_function")) {
155
- DWORD oldProtect;
156
- DWORD tmp;
157
- VirtualProtect(&functhunk->u1.Function, sizeof(uintptr_t), PAGE_EXECUTE_READWRITE, &oldProtect);
158
- functhunk->u1.Function = (uintptr_t)string_fp;
159
- VirtualProtect(&functhunk->u1.Function, sizeof(uintptr_t), oldProtect, &tmp);
160
- }
161
- }
162
- functhunk++;
163
- firstthunk++;
164
- }
165
- }
166
- dload++;
167
- }
168
- }
169
- #else*/
170
134
{
171
135
if (plthook_open_by_handle (& plthook_node_loader , node_loader ) != 0 ) {
172
136
printf ("plthook_open error: %s\n" , plthook_error ());
@@ -203,27 +167,22 @@ int load_node_dynamic(void) {
203
167
// We should have a hash map of all the symbols of each library dependency of node_loader
204
168
}
205
169
}
206
- // #endif
207
170
208
171
// Execute the code
209
172
char * str = node_loader_fp ();
210
173
printf ("NODE DYNAMIC executing string_function from: %s\n" , str );
211
174
assert (strcmp (str , "node-dynamic" ) == 0 );
212
175
213
176
// Destroy everything
214
- // #ifndef WIN32
215
177
plthook_close (plthook_node_loader );
216
- // #endif
217
178
dyn_close (node_loader );
218
179
dyn_close (libnode );
219
180
220
181
return 0 ;
221
182
}
222
183
223
184
int load_node_static (char * (* string_function_static )(void )) {
224
- // #ifndef WIN32
225
185
plthook_t * plthook_node_loader ;
226
- // #endif
227
186
dyn_handle_t current_process , node_loader ;
228
187
229
188
// TODO: In theory we should test linking against libmetacall.a, but I think there won't be
@@ -270,40 +229,6 @@ int load_node_static(char *(*string_function_static)(void)) {
270
229
// assert(dyn_sym(current_process, "string_function2", (void (**)(void))&string_fp2) == 0);
271
230
272
231
// Patch the node_loader
273
- /*#ifdef WIN32
274
- {
275
- HMODULE lib = node_loader;
276
- PIMAGE_DOS_HEADER dos = (PIMAGE_DOS_HEADER)lib;
277
- PIMAGE_NT_HEADERS nt = (PIMAGE_NT_HEADERS)((uintptr_t)lib + dos->e_lfanew);
278
- PIMAGE_DELAYLOAD_DESCRIPTOR dload = (PIMAGE_DELAYLOAD_DESCRIPTOR)((uintptr_t)lib +
279
- nt->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_DELAY_IMPORT].VirtualAddress);
280
- while (dload->DllNameRVA)
281
- {
282
- char* dll = (char*)((uintptr_t)lib + dload->DllNameRVA);
283
- if (!strcmp(dll, "libnode2.dll")) {
284
- PIMAGE_THUNK_DATA firstthunk = (PIMAGE_THUNK_DATA)((uintptr_t)lib + dload->ImportNameTableRVA);
285
- PIMAGE_THUNK_DATA functhunk = (PIMAGE_THUNK_DATA)((uintptr_t)lib + dload->ImportAddressTableRVA);
286
- while (firstthunk->u1.AddressOfData)
287
- {
288
- if (firstthunk->u1.Ordinal & IMAGE_ORDINAL_FLAG) {}
289
- else {
290
- PIMAGE_IMPORT_BY_NAME byName = (PIMAGE_IMPORT_BY_NAME)((uintptr_t)lib + firstthunk->u1.AddressOfData);
291
- if (!strcmp((char*)byName->Name, "string_function")) {
292
- DWORD oldProtect;
293
- DWORD tmp;
294
- VirtualProtect(&functhunk->u1.Function, sizeof(uintptr_t), PAGE_EXECUTE_READWRITE, &oldProtect);
295
- functhunk->u1.Function = (uintptr_t)string_fp;
296
- VirtualProtect(&functhunk->u1.Function, sizeof(uintptr_t), oldProtect, &tmp);
297
- }
298
- }
299
- functhunk++;
300
- firstthunk++;
301
- }
302
- }
303
- dload++;
304
- }
305
- }
306
- #else*/
307
232
{
308
233
if (plthook_open_by_handle (& plthook_node_loader , node_loader ) != 0 ) {
309
234
printf ("plthook_open error: %s\n" , plthook_error ());
@@ -340,17 +265,14 @@ int load_node_static(char *(*string_function_static)(void)) {
340
265
// We should have a hash map of all the symbols of each library dependency of node_loader
341
266
}
342
267
}
343
- // #endif
344
268
345
269
// Execute the code
346
270
char * str = node_loader_fp ();
347
271
printf ("NODE STATIC executing string_function from: %s\n" , str );
348
272
assert (strcmp (str , "node-static" ) == 0 );
349
273
350
274
// Destroy everything
351
- // #ifndef WIN32
352
275
plthook_close (plthook_node_loader );
353
- // #endif
354
276
dyn_close (node_loader );
355
277
356
278
return 0 ;
0 commit comments