Skip to content

Commit 9771065

Browse files
committed
Remove dead code.
1 parent 74606e3 commit 9771065

File tree

1 file changed

+0
-78
lines changed

1 file changed

+0
-78
lines changed

source/metacall.c

-78
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ int load_normal_executable() {
9393
}
9494

9595
int load_node_dynamic(void) {
96-
// #ifndef WIN32
9796
plthook_t *plthook_node_loader;
98-
// #endif
9997
dyn_handle_t libnode, node_loader;
10098

10199
printf("METACALL load from node compiled dynamically to libnode\n");
@@ -133,40 +131,6 @@ int load_node_dynamic(void) {
133131
// assert(dyn_sym(libnode, "string_function2", (void (**)(void))&string_fp2) == 0);
134132

135133
// 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*/
170134
{
171135
if (plthook_open_by_handle(&plthook_node_loader, node_loader) != 0) {
172136
printf("plthook_open error: %s\n", plthook_error());
@@ -203,27 +167,22 @@ int load_node_dynamic(void) {
203167
// We should have a hash map of all the symbols of each library dependency of node_loader
204168
}
205169
}
206-
// #endif
207170

208171
// Execute the code
209172
char *str = node_loader_fp();
210173
printf("NODE DYNAMIC executing string_function from: %s\n", str);
211174
assert(strcmp(str, "node-dynamic") == 0);
212175

213176
// Destroy everything
214-
// #ifndef WIN32
215177
plthook_close(plthook_node_loader);
216-
// #endif
217178
dyn_close(node_loader);
218179
dyn_close(libnode);
219180

220181
return 0;
221182
}
222183

223184
int load_node_static(char *(*string_function_static)(void)) {
224-
// #ifndef WIN32
225185
plthook_t *plthook_node_loader;
226-
// #endif
227186
dyn_handle_t current_process, node_loader;
228187

229188
// 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)) {
270229
// assert(dyn_sym(current_process, "string_function2", (void (**)(void))&string_fp2) == 0);
271230

272231
// 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*/
307232
{
308233
if (plthook_open_by_handle(&plthook_node_loader, node_loader) != 0) {
309234
printf("plthook_open error: %s\n", plthook_error());
@@ -340,17 +265,14 @@ int load_node_static(char *(*string_function_static)(void)) {
340265
// We should have a hash map of all the symbols of each library dependency of node_loader
341266
}
342267
}
343-
// #endif
344268

345269
// Execute the code
346270
char *str = node_loader_fp();
347271
printf("NODE STATIC executing string_function from: %s\n", str);
348272
assert(strcmp(str, "node-static") == 0);
349273

350274
// Destroy everything
351-
// #ifndef WIN32
352275
plthook_close(plthook_node_loader);
353-
// #endif
354276
dyn_close(node_loader);
355277

356278
return 0;

0 commit comments

Comments
 (0)