ldrEx.cpp revision 60a466065a08e0907b606a77fd46cbf6035f3b42
/* $Id$ */
/** @file
* innotek Portable Runtime - Binary Image Loader, Extended Features.
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License as published by the Free Software Foundation,
* in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
* distribution. VirtualBox OSE is distributed in the hope that it will
* be useful, but WITHOUT ANY WARRANTY of any kind.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_LDR
/**
* Open part with reader.
*
* @returns iprt status code.
* @param pReader The loader reader instance which will provide the raw image bits.
* @param phMod Where to store the handle.
*/
{
/*
* Read and verify the file signature.
*/
union
{
char ach[4];
} uSign;
if (RT_FAILURE(rc))
return rc;
#ifndef LDR_WITH_KLDR
{
Log(("rtldrOpenWithReader: %s: unknown magic %#x / '%.4s\n", pReader->pfnLogName(pReader), uSign.u32, &uSign.ach[0]));
return VERR_INVALID_EXE_SIGNATURE;
}
#endif
{
if (RT_FAILURE(rc))
return rc;
if (offHdr <= sizeof(IMAGE_DOS_HEADER))
{
Log(("rtldrOpenWithReader: %s: no new header / invalid offset %#RX32\n", pReader->pfnLogName(pReader), offHdr));
return VERR_INVALID_EXE_SIGNATURE;
}
if (RT_FAILURE(rc))
return rc;
{
Log(("rtldrOpenWithReader: %s: unknown new magic %#x / '%.4s\n", pReader->pfnLogName(pReader), uSign.u32, &uSign.ach[0]));
return VERR_INVALID_EXE_SIGNATURE;
}
}
/*
* Create image intepreter instance depending on the signature.
*/
#ifdef LDR_WITH_PE
#else
#endif
#if defined(LDR_WITH_ELF)
#else
#endif
#ifdef LDR_WITH_LX
#else
#endif
#ifdef LDR_WITH_LE
#else
#endif
#ifdef LDR_WITH_NE
#else
#endif
#ifdef LDR_WITH_MZ
#else
#endif
else if (/* uSign.u32 == IMAGE_AOUT_A_SIGNATURE
|| uSign.u32 == IMAGE_AOUT_Z_SIGNATURE*/ /** @todo find the aout magics in emx or binutils. */
0)
#ifdef LDR_WITH_AOUT
#else
#endif
else
{
#ifndef LDR_WITH_KLDR
Log(("rtldrOpenWithReader: %s: the format isn't implemented %#x / '%.4s\n", pReader->pfnLogName(pReader), uSign.u32, &uSign.ach[0]));
#endif
}
#ifdef LDR_WITH_KLDR
/* Try kLdr if it's a format we don't recognize. */
#endif
LogFlow(("rtldrOpenWithReader: %s: returns %Rrc *phMod=%p\n", pReader->pfnLogName(pReader), rc, *phMod));
return rc;
}
/**
* Gets the size of the loaded image.
* This is only supported for modules which has been opened using RTLdrOpen() and RTLdrOpenBits().
*
* @returns image size (in bytes).
* @returns ~(size_t)0 on if not opened by RTLdrOpen().
* @param hLdrMod Handle to the loader module.
* @remark Not supported for RTLdrLoad() images.
*/
{
/*
* Validate input.
*/
/*
* Do it.
*/
return cb;
}
/**
* Loads the image into a buffer provided by the user and applies fixups
* for the given base address.
*
* @returns iprt status code.
* @param hLdrMod The load module handle.
* @param pvBits Where to put the bits.
* Must be as large as RTLdrSize() suggests.
* @param BaseAddress The base address.
* @param pfnGetImport Callback function for resolving imports one by one.
* @param pvUser User argument for the callback.
* @remark Not supported for RTLdrLoad() images.
*/
RTDECL(int) RTLdrGetBits(RTLDRMOD hLdrMod, void *pvBits, RTUINTPTR BaseAddress, PFNRTLDRIMPORT pfnGetImport, void *pvUser)
{
LogFlow(("RTLdrGetBits: hLdrMod=%RTldrm pvBits=%p BaseAddress=%RTptr pfnGetImport=%p pvUser=%p\n",
/*
* Validate input.
*/
AssertMsgReturn(VALID_PTR(pfnGetImport), ("pfnGetImport=%p\n", pfnGetImport), VERR_INVALID_PARAMETER);
/*
* Do it.
*/
return rc;
}
/**
* Relocates bits after getting them.
* Useful for code which moves around a bit.
*
* @returns iprt status code.
* @param hLdrMod The loader module handle.
* @param pvBits Where the image bits are.
* Must've been passed to RTLdrGetBits().
* @param NewBaseAddress The new base address.
* @param OldBaseAddress The old base address.
* @param pfnGetImport Callback function for resolving imports one by one.
* @param pvUser User argument for the callback.
* @remark Not supported for RTLdrLoad() images.
*/
RTDECL(int) RTLdrRelocate(RTLDRMOD hLdrMod, void *pvBits, RTUINTPTR NewBaseAddress, RTUINTPTR OldBaseAddress,
{
LogFlow(("RTLdrRelocate: hLdrMod=%RTldrm pvBits=%p NewBaseAddress=%RTptr OldBaseAddress=%RTptr pfnGetImport=%p pvUser=%p\n",
/*
* Validate input.
*/
AssertMsgReturn(VALID_PTR(pfnGetImport), ("pfnGetImport=%p\n", pfnGetImport), VERR_INVALID_PARAMETER);
/*
* Do it.
*/
int rc = pMod->pOps->pfnRelocate(pMod, pvBits, NewBaseAddress, OldBaseAddress, pfnGetImport, pvUser);
return rc;
}
/**
* Gets the address of a named exported symbol.
*
* This function differs from the plain one in that it can deal with
* both GC and HC address sizes, and that it can calculate the symbol
* value relative to any given base address.
*
* @returns iprt status code.
* @param hLdrMod The loader module handle.
* @param pvBits Optional pointer to the loaded image.
* Set this to NULL if no RTLdrGetBits() processed image bits are available.
* Not supported for RTLdrLoad() images and must be NULL.
* @param BaseAddress Image load address.
* Not supported for RTLdrLoad() images and must be 0.
* @param pszSymbol Symbol name.
* @param pValue Where to store the symbol value.
*/
RTDECL(int) RTLdrGetSymbolEx(RTLDRMOD hLdrMod, const void *pvBits, RTUINTPTR BaseAddress, const char *pszSymbol, RTUINTPTR *pValue)
{
LogFlow(("RTLdrGetSymbolEx: hLdrMod=%RTldrm pvBits=%p BaseAddress=%RTptr pszSymbol=%p:{%s} pValue\n",
/*
* Validate input.
*/
//AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
/*
* Do it.
*/
int rc;
else if (!BaseAddress && !pvBits)
{
void *pvValue;
if (RT_SUCCESS(rc))
}
else
AssertMsgFailedReturn(("BaseAddress=%RTptr pvBits=%p\n", BaseAddress, pvBits), VERR_INVALID_FUNCTION);
return rc;
}
/**
* Enumerates all symbols in a module.
*
* @returns iprt status code.
* @param hLdrMod The loader module handle.
* @param fFlags Flags indicating what to return and such.
* @param pvBits Optional pointer to the loaded image.
* Set this to NULL if no RTLdrGetBits() processed image bits are available.
* @param BaseAddress Image load address.
* @param pfnCallback Callback function.
* @param pvUser User argument for the callback.
* @remark Not supported for RTLdrLoad() images.
*/
RTDECL(int) RTLdrEnumSymbols(RTLDRMOD hLdrMod, unsigned fFlags, const void *pvBits, RTUINTPTR BaseAddress, PFNRTLDRENUMSYMS pfnCallback, void *pvUser)
{
LogFlow(("RTLdrEnumSymbols: hLdrMod=%RTldrm fFlags=%#x pvBit=%p BaseAddress=%RTptr pfnCallback=%p pvUser=%p\n",
/*
* Validate input.
*/
//AssertMsgReturn(pMod->eState == LDR_STATE_OPENED, ("eState=%d\n", pMod->eState), VERR_WRONG_ORDER);
/*
* Do it.
*/
return rc;
}