Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Listing the exported functions of a DLL

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?

like image 257
Idov Avatar asked Dec 04 '10 10:12

Idov


People also ask

How do I see exported functions in a DLL?

The exports table of a DLL can be viewed by using the DUMPBIN tool with the /EXPORTS option. You can export functions from a DLL using two methods: Create a module definition (. def) file and use the .

What are the functions of DLL?

The use of DLLs helps promote modularization of code, code reuse, efficient memory usage, and reduced disk space. So, the operating system and the programs load faster, run faster, and take less disk space on the computer. When a program uses a DLL, an issue that is called dependency may cause the program not to run.

What are the functions in user32 DLL?

USER32. DLL implements the Windows USER component that creates and manipulates the standard elements of the Windows user interface, such as the desktop, windows, and menus. It thus enables programs to implement a graphical user interface (GUI) that matches the Windows look and feel.


2 Answers

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.

like image 76
Cheers and hth. - Alf Avatar answered Sep 28 '22 07:09

Cheers and hth. - Alf


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;   
}
like image 34
Steve Townsend Avatar answered Sep 28 '22 05:09

Steve Townsend