VirtualBox

Ignore:
Timestamp:
Jul 27, 2018 3:20:00 PM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
124005
Message:

RTLdrQueryPropEx: RTLDRPROP_UNWIND_TABLE and RTLDRPROP_UNWIND_INFO for getting PE unwind info.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Runtime/common/ldr/ldrPE.cpp

    r73375 r73387  
    472472    RTMemFree((void *)pvMem);
    473473}
     474
     475
     476/**
     477 * Reads a section of a PE image given by RVA + size.
     478 *
     479 * @returns IPRT status code.
     480 * @param   pThis               Pointer to the PE loader module structure.
     481 * @param   pvBits              Read only bits if available. NULL if not.
     482 * @param   uRva                The RVA to read at.
     483 * @param   cbMem               The number of bytes to read.
     484 * @param   pvDst               The destination buffer.
     485 */
     486static int rtldrPEReadPartByRvaInfoBuf(PRTLDRMODPE pThis, const void *pvBits, uint32_t uRva, uint32_t cbMem, void *pvDst)
     487{
     488    /** @todo consider optimizing this.   */
     489    const void *pvSrc = NULL;
     490    int rc = rtldrPEReadPartByRva(pThis, pvBits, uRva, cbMem, &pvSrc);
     491    if (RT_SUCCESS(rc))
     492    {
     493        memcpy(pvDst, pvSrc, cbMem);
     494        rtldrPEFreePart(pThis, NULL, pvSrc);
     495    }
     496    return rc;
     497}
     498
     499
     500
    474501
    475502
     
    19621989 *                          (or in case of VERR_BUFFER_OVERFLOW would have).
    19631990 */
    1964 static int rtLdrPE_QueryUnwindInfo(PRTLDRMODPE pThis, void const *pvBits, void *pvBuf, size_t cbBuf, size_t *pcbRet)
     1991static int rtLdrPE_QueryUnwindTable(PRTLDRMODPE pThis, void const *pvBits, void *pvBuf, size_t cbBuf, size_t *pcbRet)
    19651992{
    19661993    int rc;
     
    19711998        *pcbRet = cbSrc;
    19721999        if (cbBuf >= cbSrc)
    1973         {
    1974             void const *pvSrc = NULL;
    1975             rc = rtldrPEReadPartByRva(pThis, pvBits, pThis->ExceptionDir.VirtualAddress, cbSrc, &pvSrc);
    1976             if (RT_SUCCESS(rc))
    1977             {
    1978                 memcpy(pvBuf, pvSrc, cbSrc);
    1979                 rtldrPEFreePart(pThis, pvBits, pvSrc);
    1980             }
    1981         }
     2000            rc = rtldrPEReadPartByRvaInfoBuf(pThis, pvBits, pThis->ExceptionDir.VirtualAddress, cbSrc, pvBuf);
    19822001        else
    19832002            rc = VERR_BUFFER_OVERFLOW;
     
    20622081            return rtLdrPE_QueryInternalName(pModPe, pvBits, pvBuf, cbBuf, pcbRet);
    20632082
     2083        case RTLDRPROP_UNWIND_TABLE:
     2084            return rtLdrPE_QueryUnwindTable(pModPe, pvBits, pvBuf, cbBuf, pcbRet);
     2085
    20642086        case RTLDRPROP_UNWIND_INFO:
    2065             return rtLdrPE_QueryUnwindInfo(pModPe, pvBits, pvBuf, cbBuf, pcbRet);
     2087        {
     2088            uint32_t uRva = *(uint32_t const *)pvBuf;
     2089            if (uRva < pModPe->cbImage)
     2090            {
     2091                uint32_t cbLeft   = pModPe->cbImage - uRva;
     2092                uint32_t cbToRead = (uint32_t)RT_MIN(cbLeft, cbBuf);
     2093                *pcbRet = cbToRead;
     2094                return rtldrPEReadPartByRvaInfoBuf(pModPe, pvBits, uRva, cbToRead, pvBuf);
     2095            }
     2096            *pcbRet = 0;
     2097            return VINF_SUCCESS;
     2098        }
    20662099
    20672100        default:
Note: See TracChangeset for help on using the changeset viewer.

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