問題描述
我發現了類似的問題,但沒有找到我想要的答案.所以這里是:
I found similar questions but no answer to what I am looking for. So here goes:
對于本機 Win32 dll,是否有 Win32 API 來枚舉其導出函數名稱?
For a native Win32 dll, is there a Win32 API to enumerate its export function names?
推薦答案
dumpbin/exports
幾乎是您想要的,但這是一個開發人員工具,而不是 Win32 API.
dumpbin /exports
is pretty much what you want, but that's a developer tool, not a Win32 API.
LoadLibraryEx
和 DONT_RESOLVE_DLL_REFERENCES
被嚴重警告,但碰巧對這種特殊情況很有用它完成了將 DLL 映射到內存的繁重工作(但您實際上并不需要或不想使用庫中的任何內容),這使得您讀取頭文件變得微不足道:LoadLibraryEx<返回的模塊句柄/code> 指向它.
LoadLibraryEx
with DONT_RESOLVE_DLL_REFERENCES
is heavily cautioned against, but happens to be useful for this particular case – it does the heavy lifting of mapping the DLL into memory (but you don't actually need or want to use anything from the library), which makes it trivial for you to read the header: the module handle returned by LoadLibraryEx
points right at it.
#include <winnt.h>
HMODULE lib = LoadLibraryEx("library.dll", NULL, DONT_RESOLVE_DLL_REFERENCES);
assert(((PIMAGE_DOS_HEADER)lib)->e_magic == IMAGE_DOS_SIGNATURE);
PIMAGE_NT_HEADERS header = (PIMAGE_NT_HEADERS)((BYTE *)lib + ((PIMAGE_DOS_HEADER)lib)->e_lfanew);
assert(header->Signature == IMAGE_NT_SIGNATURE);
assert(header->OptionalHeader.NumberOfRvaAndSizes > 0);
PIMAGE_EXPORT_DIRECTORY exports = (PIMAGE_EXPORT_DIRECTORY)((BYTE *)lib + header->
OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
assert(exports->AddressOfNames != 0);
BYTE** names = (BYTE**)((int)lib + exports->AddressOfNames);
for (int i = 0; i < exports->NumberOfNames; i++)
printf("Export: %s
", (BYTE *)lib + (int)names[i]);
完全未經測試,但我認為它或多或少是正確的.(著名的遺言.)
Totally untested, but I think it's more or less correct. (Famous last words.)
這篇關于Win32 API 枚舉dll 導出函數?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!