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

static int kldrModPEGetImport ( PKLDRMOD  pMod,
const void *  pvBits,
KU32  iImport,
char *  pszName,
KSIZE  cchName 
) [static]

Get the name of an import module by ordinal number.

Returns:
0 and name in pszName on success. On buffer overruns KERR_BUFFER_OVERFLOW will be returned. On other failures and appropriate error code is returned.
Parameters:
pMod The module.
pvBits Optional pointer to bits returned by kLdrModGetBits(). This can be used by some module interpreters to reduce memory consumption.
iImport The import module ordinal number.
pszName Where to store the name.
cchName The size of the name buffer.

Definition at line 1027 of file kLdrModPE.c.

References KLDRMODPE::Hdrs, KERR_BUFFER_OVERFLOW, KLDR_ERR_IMPORT_ORDINAL_OUT_OF_BOUNDS, KLDRMODPE_RVA2TYPE, kldrModPEBitsAndBaseAddress(), kldrModPENumberOfImports(), KSIZE, NULL, and KLDRMOD::pvData.

{
    PKLDRMODPE                      pModPE = (PKLDRMODPE)pMod->pvData;
    const IMAGE_IMPORT_DESCRIPTOR  *pImpDesc;
    const char                     *pszImportName;
    KSIZE                           cchImportName;
    int                             rc;

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

    /*
     * Simple bounds check.
     */
    if (iImport >= (KU32)kldrModPENumberOfImports(pMod, pvBits))
        return KLDR_ERR_IMPORT_ORDINAL_OUT_OF_BOUNDS;

    /*
     * Get the name.
     */
    pImpDesc = KLDRMODPE_RVA2TYPE(pvBits,
                                  pModPE->Hdrs.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress
                                  + sizeof(IMAGE_IMPORT_DESCRIPTOR) * iImport,
                                  const IMAGE_IMPORT_DESCRIPTOR *);
    pszImportName = KLDRMODPE_RVA2TYPE(pvBits, pImpDesc->Name, const char *);
    cchImportName = kHlpStrLen(pszImportName);
    if (cchImportName < cchName)
    {
        kHlpMemCopy(pszName, pszImportName, cchImportName + 1);
        rc = 0;
    }
    else
    {
        kHlpMemCopy(pszName, pszImportName, cchName);
        if (cchName)
            pszName[cchName - 1] = '\0';
        rc = KERR_BUFFER_OVERFLOW;
    }

    return rc;
}


Generated by  Doxygen 1.6.0   Back to index