windows 列出 DLL 的导出函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4353116/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Listing the exported functions of a DLL
提问by Idov
I'm looking for a way (in C++/Windows) to list the exported functions of a DLL (and maybe even methods which are not exported) using dbgHelp.
Does anybody know which method can do it?
我正在寻找一种方法(在 C++/Windows 中)使用 dbgHelp 列出 DLL 的导出函数(甚至可能是未导出的方法)。
有人知道哪种方法可以做到吗?
回答by Cheers and hth. - Alf
If you're content with other tools then there are a number that do list exported functions. One is Microsoft's dumpbin
, use the /exports
option.
如果您对其他工具感到满意,那么有许多工具会列出导出的函数。一个是微软的dumpbin
,使用/exports
选项。
回答by Steve Townsend
There is code hereto do this. I have cleaned it up a bit and it worked in the scenario shown below, retrieving function names from Kernel32.Dll
.
有代码在这里做到这一点。我已经清理了一下,它在下面显示的场景中工作,从Kernel32.Dll
.
#include "imagehlp.h"
void ListDLLFunctions(string sADllName, vector<string>& slListOfDllFunctions)
{
DWORD *dNameRVAs(0);
_IMAGE_EXPORT_DIRECTORY *ImageExportDirectory;
unsigned long cDirSize;
_LOADED_IMAGE LoadedImage;
string sName;
slListOfDllFunctions.clear();
if (MapAndLoad(sADllName.c_str(), NULL, &LoadedImage, TRUE, TRUE))
{
ImageExportDirectory = (_IMAGE_EXPORT_DIRECTORY*)
ImageDirectoryEntryToData(LoadedImage.MappedAddress,
false, IMAGE_DIRECTORY_ENTRY_EXPORT, &cDirSize);
if (ImageExportDirectory != NULL)
{
dNameRVAs = (DWORD *)ImageRvaToVa(LoadedImage.FileHeader,
LoadedImage.MappedAddress,
ImageExportDirectory->AddressOfNames, NULL);
for(size_t i = 0; i < ImageExportDirectory->NumberOfNames; i++)
{
sName = (char *)ImageRvaToVa(LoadedImage.FileHeader,
LoadedImage.MappedAddress,
dNameRVAs[i], NULL);
slListOfDllFunctions.push_back(sName);
}
}
UnMapAndLoad(&LoadedImage);
}
}
int main(int argc, char* argv[])
{
vector<string> names;
ListDLLFunctions("KERNEL32.DLL", names);
return 0;
}