Logo Search packages:      
Sourcecode: virtualbox-ose version File versions  Download package

static int kldrModPEEnumSymbols ( PKLDRMOD  pMod,
const void *  pvBits,
KLDRADDR  BaseAddress,
KU32  fFlags,
PFNKLDRMODENUMSYMS  pfnCallback,
void *  pvUser 
) [static]

Enumerate the symbols in the module.

Returns:
0 on success and non-zero a status code on failure.
Parameters:
pMod The module which symbols should be enumerated.
pvBits Optional pointer to bits returned by kLdrModGetBits() currently located at BaseAddress. This can be used by some module interpreters to reduce memory consumption.
BaseAddress The module base address to use when calculating the symbol values. There are two special values that could be can: KLDRMOD_BASEADDRESS_LINK and KLDRMOD_BASEADDRESS_MAP.
fFlags The enumeration flags. A combination of the KLDRMOD_ENUM_SYMS_FLAGS_* #defines.
pfnCallback The enumeration callback function.
pvUser The user argument to the callback function.

Definition at line 945 of file kLdrModPE.c.

References KLDRMODPE::Hdrs, KLDRMODPE_RVA2TYPE, kldrModPEBitsAndBaseAddress(), KLDRSYMKIND_32BIT, KLDRSYMKIND_64BIT, KLDRSYMKIND_FORWARDER, KLDRSYMKIND_NO_TYPE, NULL, and KLDRMOD::pvData.

{
    PKLDRMODPE                      pModPE = (PKLDRMODPE)pMod->pvData;
    const KU32                     *paFunctions;
    const IMAGE_EXPORT_DIRECTORY   *pExpDir;
    const KU32                     *paRVANames;
    const KU16                     *paOrdinals;
    KU32                            iFunction;
    KU32                            cFunctions;
    KU32                            cNames;
    int                             rc;

    /*
     * Make sure we've got mapped bits and resolve any base address aliases.
     */
    rc = kldrModPEBitsAndBaseAddress(pModPE, &pvBits, &BaseAddress);
    if (rc)
        return rc;

    if (    pModPE->Hdrs.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size
        <   sizeof(IMAGE_EXPORT_DIRECTORY))
        return 0; /* no exports to enumerate, return success. */

    pExpDir = KLDRMODPE_RVA2TYPE(pvBits,
                                 pModPE->Hdrs.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress,
                                 PIMAGE_EXPORT_DIRECTORY);

    /*
     * Enumerate the ordinal exports.
     */
    paRVANames = KLDRMODPE_RVA2TYPE(pvBits, pExpDir->AddressOfNames, const KU32 *);
    paOrdinals = KLDRMODPE_RVA2TYPE(pvBits, pExpDir->AddressOfNameOrdinals, const KU16 *);
    paFunctions = KLDRMODPE_RVA2TYPE(pvBits, pExpDir->AddressOfFunctions, const KU32 *);
    cFunctions = pExpDir->NumberOfFunctions;
    cNames = pExpDir->NumberOfNames;
    for (iFunction = 0; iFunction < cFunctions; iFunction++)
    {
        unsigned        fFoundName;
        KU32            iName;
        const KU32      uRVA = paFunctions[iFunction];
        const KLDRADDR  uValue = BaseAddress + uRVA;
        KU32            fKind = (pModPE->Hdrs.FileHeader.SizeOfOptionalHeader == sizeof(IMAGE_OPTIONAL_HEADER32)
                              ? KLDRSYMKIND_32BIT : KLDRSYMKIND_64BIT)
                              | KLDRSYMKIND_NO_TYPE;
        if (    uRVA - pModPE->Hdrs.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress
            <   pModPE->Hdrs.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].Size)
            fKind |= KLDRSYMKIND_FORWARDER;

        /*
         * Any symbol names?
         */
        fFoundName = 0;
        for (iName = 0; iName < cNames; iName++)
        {
            const char *pszName;
            if (paOrdinals[iName] != iFunction)
                continue;
            fFoundName = 1;
            pszName = KLDRMODPE_RVA2TYPE(pvBits, paRVANames[iName], const char *);
            rc = pfnCallback(pMod, iFunction + pExpDir->Base, pszName, kHlpStrLen(pszName), NULL,
                             uValue, fKind, pvUser);
            if (rc)
                return rc;
        }

        /*
         * If no names, call once with the ordinal only.
         */
        if (!fFoundName)
        {
            rc = pfnCallback(pMod, iFunction + pExpDir->Base, NULL, 0, NULL, uValue, fKind, pvUser);
            if (rc)
                return rc;
        }
    }

    return 0;
}


Generated by  Doxygen 1.6.0   Back to index