Changeset 51770 in vbox for trunk/src/VBox/Runtime/common/ldr/ldrEx.cpp
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/bird/hardenedwindows (added) merged: 92692-94610
- Property svn:mergeinfo changed
-
trunk/src/VBox
- Property svn:mergeinfo changed
/branches/bird/hardenedwindows/src/VBox (added) merged: 92692-94610
- Property svn:mergeinfo changed
-
trunk/src/VBox/Runtime/common/ldr/ldrEx.cpp
r49044 r51770 33 33 #include "internal/iprt.h" 34 34 35 #include <iprt/alloc.h>36 35 #include <iprt/assert.h> 36 #include <iprt/err.h> 37 37 #include <iprt/log.h> 38 #include <iprt/md5.h> 39 #include <iprt/mem.h> 40 #include <iprt/sha.h> 38 41 #include <iprt/string.h> 39 #include <iprt/err.h>40 42 #include "internal/ldr.h" 41 43 #include "internal/ldrMZ.h" 42 44 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 58 RTDECL(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 55 72 /* 56 73 * Read and verify the file signature. … … 105 122 if (uSign.u32 == IMAGE_NT_SIGNATURE) 106 123 #ifdef LDR_WITH_PE 107 rc = rtldrPEOpen(pReader, fFlags, enmArch, offHdr, phMod );124 rc = rtldrPEOpen(pReader, fFlags, enmArch, offHdr, phMod, pErrInfo); 108 125 #else 109 126 rc = VERR_PE_EXE_NOT_SUPPORTED; … … 111 128 else if (uSign.u32 == IMAGE_ELF_SIGNATURE) 112 129 #if defined(LDR_WITH_ELF) 113 rc = rtldrELFOpen(pReader, fFlags, enmArch, phMod );130 rc = rtldrELFOpen(pReader, fFlags, enmArch, phMod, pErrInfo); 114 131 #else 115 132 rc = VERR_ELF_EXE_NOT_SUPPORTED; … … 117 134 else if (uSign.au16[0] == IMAGE_LX_SIGNATURE) 118 135 #ifdef LDR_WITH_LX 119 rc = rtldrLXOpen(pReader, fFlags, enmArch, offHdr, phMod );136 rc = rtldrLXOpen(pReader, fFlags, enmArch, offHdr, phMod, pErrInfo); 120 137 #else 121 138 rc = VERR_LX_EXE_NOT_SUPPORTED; … … 123 140 else if (uSign.au16[0] == IMAGE_LE_SIGNATURE) 124 141 #ifdef LDR_WITH_LE 125 rc = rtldrLEOpen(pReader, fFlags, enmArch, phMod );142 rc = rtldrLEOpen(pReader, fFlags, enmArch, phMod, pErrInfo); 126 143 #else 127 144 rc = VERR_LE_EXE_NOT_SUPPORTED; … … 129 146 else if (uSign.au16[0] == IMAGE_NE_SIGNATURE) 130 147 #ifdef LDR_WITH_NE 131 rc = rtldrNEOpen(pReader, fFlags, enmArch, phMod );148 rc = rtldrNEOpen(pReader, fFlags, enmArch, phMod, pErrInfo); 132 149 #else 133 150 rc = VERR_NE_EXE_NOT_SUPPORTED; … … 135 152 else if (uSign.au16[0] == IMAGE_DOS_SIGNATURE) 136 153 #ifdef LDR_WITH_MZ 137 rc = rtldrMZOpen(pReader, fFlags, enmArch, phMod );154 rc = rtldrMZOpen(pReader, fFlags, enmArch, phMod, pErrInfo); 138 155 #else 139 156 rc = VERR_MZ_EXE_NOT_SUPPORTED; … … 143 160 0) 144 161 #ifdef LDR_WITH_AOUT 145 rc = rtldrAOUTOpen(pReader, fFlags, enmArch, phMod );162 rc = rtldrAOUTOpen(pReader, fFlags, enmArch, phMod, pErrInfo); 146 163 #else 147 164 rc = VERR_AOUT_EXE_NOT_SUPPORTED; … … 158 175 /* Try kLdr if it's a format we don't recognize. */ 159 176 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 } 161 182 #endif 162 183 … … 542 563 RTDECL(int) RTLdrQueryProp(RTLDRMOD hLdrMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf) 543 564 { 565 return RTLdrQueryPropEx(hLdrMod, enmProp, pvBuf, cbBuf, NULL); 566 } 567 RT_EXPORT_SYMBOL(RTLdrQueryProp); 568 569 570 RTDECL(int) RTLdrQueryPropEx(RTLDRMOD hLdrMod, RTLDRPROP enmProp, void *pvBuf, size_t cbBuf, size_t *pcbRet) 571 { 544 572 AssertMsgReturn(rtldrIsValid(hLdrMod), ("hLdrMod=%p\n", hLdrMod), RTLDRENDIAN_INVALID); 545 573 PRTLDRMODINTERNAL pMod = (PRTLDRMODINTERNAL)hLdrMod; 546 574 575 AssertPtrNullReturn(pcbRet, VERR_INVALID_POINTER); 576 size_t cbRet; 577 if (!pcbRet) 578 pcbRet = &cbRet; 579 547 580 /* 548 581 * Do some pre screening of the input … … 551 584 { 552 585 case RTLDRPROP_UUID: 586 *pcbRet = sizeof(RTUUID); 553 587 AssertReturn(cbBuf == sizeof(RTUUID), VERR_INVALID_PARAMETER); 554 588 break; 555 589 case RTLDRPROP_TIMESTAMP_SECONDS: 590 *pcbRet = sizeof(int64_t); 556 591 AssertReturn(cbBuf == sizeof(int32_t) || cbBuf == sizeof(int64_t), VERR_INVALID_PARAMETER); 557 592 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 558 605 default: 559 606 AssertFailedReturn(VERR_INVALID_FUNCTION); … … 566 613 if (!pMod->pOps->pfnQueryProp) 567 614 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 } 617 RT_EXPORT_SYMBOL(RTLdrQueryPropEx); 618 619 620 RTDECL(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 } 633 RT_EXPORT_SYMBOL(RTLdrVerifySignature); 634 635 636 RTDECL(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 } 665 RT_EXPORT_SYMBOL(RTLdrHashImage); 571 666 572 667
Note:
See TracChangeset
for help on using the changeset viewer.