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

static int kldrModPEDoImports32Bit ( PKLDRMODPE  pModPE,
void *  pvMapping,
const IMAGE_IMPORT_DESCRIPTOR *  pImpDesc,
PFNKLDRMODGETIMPORT  pfnGetImport,
void *  pvUser 
) [static]

Resolves imports, 32-bit image.

Returns:
0 on success, non-zero kLdr status code on failure.
Parameters:
pModPE The PE module interpreter instance.
pvMapping The mapping which imports should be resolved.
pImpDesc Pointer to the first import descriptor.
pfnGetImport The callback for resolving an imported symbol.
pvUser User argument to the callback.

Definition at line 1580 of file kLdrModPE.c.

References KLDRMODPE::cImportModules, KLDR_ERR_ADDRESS_OVERFLOW, KLDR_ERR_PE_BAD_IMPORT, KLDRMODPE_ASSERT, KLDRMODPE_RVA2TYPE, KLDRMODPE_VALID_RVA, KLDRSYMKIND_REQ_FLAT, NIL_KLDRMOD_SYM_ORDINAL, NULL, and KLDRMODPE::pMod.

Referenced by kldrModPEDoImports().

{
    PKLDRMOD pMod = pModPE->pMod;
    KU32 iImp;

    /*
     * Iterate the import descriptors.
     */
    for (iImp = 0; iImp < pModPE->cImportModules; iImp++, pImpDesc++)
    {
        PIMAGE_THUNK_DATA32         pFirstThunk = KLDRMODPE_RVA2TYPE(pvMapping, pImpDesc->FirstThunk, PIMAGE_THUNK_DATA32);
        const IMAGE_THUNK_DATA32   *pThunk = pImpDesc->u.OriginalFirstThunk
            ? KLDRMODPE_RVA2TYPE(pvMapping, pImpDesc->u.OriginalFirstThunk, const IMAGE_THUNK_DATA32 *)
            : KLDRMODPE_RVA2TYPE(pvMapping, pImpDesc->FirstThunk, const IMAGE_THUNK_DATA32 *);

        /* Iterate the thunks. */
        while (pThunk->u1.Ordinal != 0)
        {
            KLDRADDR    Value;
            KU32        fKind = KLDRSYMKIND_REQ_FLAT;
            int         rc;

            /* Ordinal or name import? */
            if (IMAGE_SNAP_BY_ORDINAL32(pThunk->u1.Ordinal))
                rc = pfnGetImport(pMod, iImp, IMAGE_ORDINAL32(pThunk->u1.Ordinal), NULL, 0, NULL, &Value, &fKind, pvUser);
            else if (KLDRMODPE_VALID_RVA(pModPE, pThunk->u1.Ordinal))
            {
                const IMAGE_IMPORT_BY_NAME *pName = KLDRMODPE_RVA2TYPE(pvMapping, pThunk->u1.Ordinal, const IMAGE_IMPORT_BY_NAME *);
                rc = pfnGetImport(pMod, iImp, NIL_KLDRMOD_SYM_ORDINAL, (const char *)pName->Name,
                                  kHlpStrLen((const char *)pName->Name), NULL, &Value, &fKind, pvUser);
            }
            else
            {
                KLDRMODPE_ASSERT(!"bad 32-bit import");
                return KLDR_ERR_PE_BAD_IMPORT;
            }
            if (rc)
                return rc;

            /* Apply it. */
            pFirstThunk->u1.Function = (KU32)Value;
            if (pFirstThunk->u1.Function != Value)
            {
                KLDRMODPE_ASSERT(!"overflow");
                return KLDR_ERR_ADDRESS_OVERFLOW;
            }

            /* next */
            pThunk++;
            pFirstThunk++;
        }
    }

    return 0;
}


Generated by  Doxygen 1.6.0   Back to index