Code Snippet of the Day

This function will print out a list of exports from a DLL. Note that this function for enumerating DLL exports requires imagehlp.lib and dbghelp.lib (and the corresponding dynamic libs).

void ListDLLFunctions(PCSTR pszDllName)

{

    _IMAGE_EXPORT_DIRECTORY *ImageExportDirectory;

    unsigned
long cDirSize;

    LOADED_IMAGE *pImage = ImageLoad(pszDllName, NULL);

    ImageExportDirectory = (_IMAGE_EXPORT_DIRECTORY *)ImageDirectoryEntryToData(pImage->MappedAddress, FALSE, IMAGE_DIRECTORY_ENTRY_EXPORT, &cDirSize);

    if (ImageExportDirectory != NULL)

    {

        DWORD* dwNameRVAs = (DWORD*)ImageRvaToVa(pImage->FileHeader, pImage->MappedAddress, ImageExportDirectory->AddressOfNames, NULL);

        for( DWORD i = 0; i < ImageExportDirectory->NumberOfNames; i++)

        {

            PCSTR pszName = (PCSTR)ImageRvaToVa(pImage->FileHeader, pImage->MappedAddress, dwNameRVAs[i], NULL);

            printf(“%s\n”, pszName);

        }

    }

}


 

Comments

  1. Tim says:

    The formatting sort of got mangled… I may have to figure out a better way to paste code in the future.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>