VirtualBox

Ignore:
Timestamp:
Jul 1, 2014 6:14:02 PM (11 years ago)
Author:
vboxsync
Message:

Merged in iprt++ dev branch.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/VBox

  • trunk/src/VBox/Runtime/common/ldr/ldrEx.cpp

    r49044 r51770  
    3333#include "internal/iprt.h"
    3434
    35 #include <iprt/alloc.h>
    3635#include <iprt/assert.h>
     36#include <iprt/err.h>
    3737#include <iprt/log.h>
     38#include <iprt/md5.h>
     39#include <iprt/mem.h>
     40#include <iprt/sha.h>
    3841#include <iprt/string.h>
    39 #include <iprt/err.h>
    4042#include "internal/ldr.h"
    4143#include "internal/ldrMZ.h"
    4244
    43 
    44 /**
    45  * Open part with reader.
    46  *
    47  * @returns iprt status code.
    48  * @param   pReader     The loader reader instance which will provide the raw image bits.
    49  * @param   fFlags      Reserved, MBZ.
    50  * @param   enmArch     Architecture specifier.
    51  * @param   phMod       Where to store the handle.
    52  */
    53 int rtldrOpenWithReader(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phMod)
    54 {
     45#ifdef LDR_ONLY_PE
     46# undef LDR_WITH_PE
     47# undef LDR_WITH_KLDR
     48# undef LDR_WITH_ELF
     49# undef LDR_WITH_LX
     50# undef LDR_WITH_LE
     51# undef LDR_WITH_NE
     52# undef LDR_WITH_MZ
     53# undef LDR_WITH_AOUT
     54# define LDR_WITH_PE
     55#endif
     56
     57
     58RTDECL(int) RTLdrOpenWithReader(PRTLDRREADER pReader, uint32_t fFlags, RTLDRARCH enmArch, PRTLDRMOD phMod, PRTERRINFO pErrInfo)
     59{
     60    /*
     61     * Resolve RTLDRARCH_HOST.
     62     */
     63    if (enmArch == RTLDRARCH_HOST)
     64#if   defined(RT_ARCH_AMD64)
     65        enmArch = RTLDRARCH_AMD64;
     66#elif defined(RT_ARCH_X86)
     67        enmArch = RTLDRARCH_X86_32;
     68#else
     69        enmArch = RTLDRARCH_WHATEVER;
     70#endif
     71
    5572    /*
    5673     * Read and verify the file signature.
     
    105122    if (uSign.u32 == IMAGE_NT_SIGNATURE)
    106123#ifdef LDR_WITH_PE
    107         rc = rtldrPEOpen(pReader, fFlags, enmArch, offHdr, phMod);
     124        rc = rtldrPEOpen(pReader, fFlags, enmArch, offHdr, phMod, pErrInfo);
    108125#else
    109126        rc = VERR_PE_EXE_NOT_SUPPORTED;
     
    111128    else if (uSign.u32 == IMAGE_ELF_SIGNATURE)
    112129#if defined(LDR_WITH_ELF)
    113         rc = rtldrELFOpen(pReader, fFlags, enmArch, phMod);
     130        rc = rtldrELFOpen(pReader, fFlags, enmArch, phMod, pErrInfo);
    114131#else
    115132        rc = VERR_ELF_EXE_NOT_SUPPORTED;
     
    117134    else if (uSign.au16[0] == IMAGE_LX_SIGNATURE)
    118135#ifdef LDR_WITH_LX
    119         rc = rtldrLXOpen(pReader, fFlags, enmArch, offHdr, phMod);
     136        rc = rtldrLXOpen(pReader, fFlags, enmArch, offHdr, phMod, pErrInfo);
    120137#else
    121138        rc = VERR_LX_EXE_NOT_SUPPORTED;
     
    123140    else if (uSign.au16[0] == IMAGE_LE_SIGNATURE)
    124141#ifdef LDR_WITH_LE
    125         rc = rtldrLEOpen(pReader, fFlags, enmArch, phMod);
     142        rc = rtldrLEOpen(pReader, fFlags, enmArch, phMod, pErrInfo);
    126143#else
    127144        rc = VERR_LE_EXE_NOT_SUPPORTED;
     
    129146    else if (uSign.au16[0] == IMAGE_NE_SIGNATURE)
    130147#ifdef LDR_WITH_NE
    131         rc = rtldrNEOpen(pReader, fFlags, enmArch, phMod);
     148        rc = rtldrNEOpen(pReader, fFlags, enmArch, phMod, pErrInfo);
    132149#else
    133150        rc = VERR_NE_EXE_NOT_SUPPORTED;
     
    135152    else if (uSign.au16[0] == IMAGE_DOS_SIGNATURE)
    136153#ifdef LDR_WITH_MZ
    137         rc = rtldrMZOpen(pReader, fFlags, enmArch, phMod);
     154        rc = rtldrMZOpen(pReader, fFlags, enmArch, phMod, pErrInfo);
    138155#else
    139156        rc = VERR_MZ_EXE_NOT_SUPPORTED;
     
    143160             0)
    144161#ifdef LDR_WITH_AOUT
    145         rc = rtldrAOUTOpen(pReader, fFlags, enmArch, phMod);
     162        rc = rtldrAOUTOpen(pReader, fFlags, enmArch, phMod, pErrInfo);
    146163#else
    147164        rc = VERR_AOUT_EXE_NOT_SUPPORTED;
     
    158175    /* Try kLdr if it's a format we don't recognize. */
    159176    if (rc <= VERR_INVALID_EXE_SIGNATURE && rc > VERR_BAD_EXE_FORMAT)
    160         rc = rtldrkLdrOpen(pReader, fFlags, enmArch, phMod);
     177    {
     178        int rc2 = rtldrkLdrOpen(pReader, fFlags, enmArch, phMod, pErrInfo);
     179        if (rc2 == VERR_MZ_EXE_NOT_SUPPORTED) /* Quick fix for bad return code. */
     180            rc = rc;
     181    }
    161182#endif
    162183
     
    542563RTDECL(int) RTLdrQueryProp(RTLDRMOD hLdrMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf)
    543564{
     565    return RTLdrQueryPropEx(hLdrMod, enmProp, pvBuf, cbBuf, NULL);
     566}
     567RT_EXPORT_SYMBOL(RTLdrQueryProp);
     568
     569
     570RTDECL(int) RTLdrQueryPropEx(RTLDRMOD hLdrMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf, size_t *pcbRet)
     571{
    544572    AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), RTLDRENDIAN_INVALID);
    545573    PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
    546574
     575    AssertPtrNullReturn(pcbRet, VERR_INVALID_POINTER);
     576    size_t cbRet;
     577    if (!pcbRet)
     578        pcbRet = &cbRet;
     579
    547580    /*
    548581     * Do some pre screening of the input
     
    551584    {
    552585        case RTLDRPROP_UUID:
     586            *pcbRet = sizeof(RTUUID);
    553587            AssertReturn(cbBuf == sizeof(RTUUID), VERR_INVALID_PARAMETER);
    554588            break;
    555589        case RTLDRPROP_TIMESTAMP_SECONDS:
     590            *pcbRet = sizeof(int64_t);
    556591            AssertReturn(cbBuf == sizeof(int32_t) || cbBuf == sizeof(int64_t), VERR_INVALID_PARAMETER);
    557592            break;
     593        case RTLDRPROP_IS_SIGNED:
     594            *pcbRet = sizeof(bool);
     595            AssertReturn(cbBuf == sizeof(bool), VERR_INVALID_PARAMETER);
     596            break;
     597        case RTLDRPROP_PKCS7_SIGNED_DATA:
     598            *pcbRet = 0;
     599            break;
     600        case RTLDRPROP_SIGNATURE_CHECKS_ENFORCED:
     601            *pcbRet = sizeof(bool);
     602            AssertReturn(cbBuf == sizeof(bool), VERR_INVALID_PARAMETER);
     603            break;
     604
    558605        default:
    559606            AssertFailedReturn(VERR_INVALID_FUNCTION);
     
    566613    if (!pMod->pOps->pfnQueryProp)
    567614        return VERR_NOT_SUPPORTED;
    568     return pMod->pOps->pfnQueryProp(pMod, enmProp, pvBuf, cbBuf);
    569 }
    570 RT_EXPORT_SYMBOL(RTLdrQueryProp);
     615    return pMod->pOps->pfnQueryProp(pMod, enmProp, pvBuf, cbBuf, pcbRet);
     616}
     617RT_EXPORT_SYMBOL(RTLdrQueryPropEx);
     618
     619
     620RTDECL(int) RTLdrVerifySignature(RTLDRMOD hLdrMod, PFNRTLDRVALIDATESIGNEDDATA pfnCallback, void *pvUser, PRTERRINFO pErrInfo)
     621{
     622    AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
     623    PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
     624    AssertPtrReturn(pfnCallback, VERR_INVALID_POINTER);
     625
     626    /*
     627     * Call the image specific worker, if there is one.
     628     */
     629    if (!pMod->pOps->pfnVerifySignature)
     630        return VERR_NOT_SUPPORTED;
     631    return pMod->pOps->pfnVerifySignature(pMod, pfnCallback, pvUser, pErrInfo);
     632}
     633RT_EXPORT_SYMBOL(RTLdrVerifySignature);
     634
     635
     636RTDECL(int) RTLdrHashImage(RTLDRMOD hLdrMod, RTDIGESTTYPE enmDigest, char *pszDigest, size_t cbDigest)
     637{
     638    AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), VERR_INVALID_HANDLE);
     639    PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod;
     640
     641    /*
     642     * Make sure there is sufficient space for the wanted digest and that
     643     * it's supported.
     644     */
     645    switch (enmDigest)
     646    {
     647        case RTDIGESTTYPE_MD5:      AssertReturn(cbDigest >= RTMD5_DIGEST_LEN    + 1, VERR_BUFFER_OVERFLOW); break;
     648        case RTDIGESTTYPE_SHA1:     AssertReturn(cbDigest >= RTSHA1_DIGEST_LEN   + 1, VERR_BUFFER_OVERFLOW); break;
     649        case RTDIGESTTYPE_SHA256:   AssertReturn(cbDigest >= RTSHA256_DIGEST_LEN + 1, VERR_BUFFER_OVERFLOW); break;
     650        case RTDIGESTTYPE_SHA512:   AssertReturn(cbDigest >= RTSHA512_DIGEST_LEN + 1, VERR_BUFFER_OVERFLOW); break;
     651        default:
     652            if (enmDigest > RTDIGESTTYPE_INVALID && enmDigest < RTDIGESTTYPE_END)
     653                return VERR_NOT_SUPPORTED;
     654            AssertFailedReturn(VERR_INVALID_PARAMETER);
     655    }
     656    AssertPtrReturn(pszDigest, VERR_INVALID_POINTER);
     657
     658    /*
     659     * Call the image specific worker, if there is one.
     660     */
     661    if (!pMod->pOps->pfnHashImage)
     662        return VERR_NOT_SUPPORTED;
     663    return pMod->pOps->pfnHashImage(pMod, enmDigest, pszDigest, cbDigest);
     664}
     665RT_EXPORT_SYMBOL(RTLdrHashImage);
    571666
    572667
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette