1
0
mirror of https://gitea.tendokyu.moe/Dniel97/segatools.git synced 2024-11-14 17:17:36 +01:00
segatools-dniel97/util/get_function_ordinal.c
Sanhei ceb2b63e8b Modify host header in HTTP requests to bypass domain censorship in China. (#34)
Co-authored-by: Sanheiii <35133371+Sanheiii@users.noreply.github.com>
Reviewed-on: https://gitea.tendokyu.moe/Dniel97/segatools/pulls/34
Co-authored-by: Sanhei <sanhei@noreply.gitea.tendokyu.moe>
Co-committed-by: Sanhei <sanhei@noreply.gitea.tendokyu.moe>
2024-11-11 16:24:33 +00:00

34 lines
1.1 KiB
C

#include "get_function_ordinal.h"
DWORD get_function_ordinal(const char* dllName, const char* functionName) {
HMODULE hModule = LoadLibraryA(dllName);
if (!hModule) {
dprintf("Failed to load DLL: %s\n", dllName);
return 0;
}
ULONG size;
PIMAGE_EXPORT_DIRECTORY exportDir = (PIMAGE_EXPORT_DIRECTORY)ImageDirectoryEntryToData(
hModule, TRUE, IMAGE_DIRECTORY_ENTRY_EXPORT, &size);
if (!exportDir) {
dprintf("Failed to get export table\n");
FreeLibrary(hModule);
return 0;
}
DWORD* functionNames = (DWORD*)((BYTE*)hModule + exportDir->AddressOfNames);
WORD* ordinals = (WORD*)((BYTE*)hModule + exportDir->AddressOfNameOrdinals);
for (DWORD i = 0; i < exportDir->NumberOfNames; ++i) {
char* name = (char*)((BYTE*)hModule + functionNames[i]);
if (strcmp(name, functionName) == 0) {
DWORD ordinal = ordinals[i] + exportDir->Base;
FreeLibrary(hModule);
return ordinal;
}
}
dprintf("Function not found: %s\n", functionName);
FreeLibrary(hModule);
return 0;
}