开发者

Listing the exported functions of a DLL

开发者 https://www.devze.com 2023-01-28 03:06 出处:网络
I\'m looking for a w开发者_如何学运维ay (in C++/Windows) to list the exported functions of a DLL (and maybe even methods which are not exported) using dbgHelp.

I'm looking for a w开发者_如何学运维ay (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?


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.


There is code here to do this. I have cleaned it up a bit and it worked in the scenario shown below, retrieving function names from 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;   
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号