tstLdr-3.cpp revision 643ac6d84030a2ec7e6d6f536f2b547a8a196858
/* $Id$ */
/** @file
* IPRT - Testcase for parts of RTLdr*, manual inspection.
*/
/*
* Copyright (C) 2006-2007 Oracle Corporation
*
* 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 (GPL) 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.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <iprt/initterm.h>
/*******************************************************************************
* Global Variables *
*******************************************************************************/
static RTUINTPTR g_uLoadAddr;
static void *g_pvBits;
/**
* Current nearest symbol.
*/
typedef struct TESTNEARSYM
{
struct TESTSYM
{
unsigned uSymbol;
char szName[512];
} aSyms[2];
} TESTNEARSYM, *PTESTNEARSYM;
/**
* Enumeration callback function used by RTLdrEnumSymbols().
*
* @returns iprt status code. Failure will stop the enumeration.
* @param hLdrMod The loader module handle.
* @param pszSymbol Symbol name. NULL if ordinal only.
* @param uSymbol Symbol ordinal, ~0 if not used.
* @param Value Symbol value.
* @param pvUser The user argument specified to RTLdrEnumSymbols().
*/
static DECLCALLBACK(int) testEnumSymbol2(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol, RTUINTPTR Value, void *pvUser)
{
/* less or equal */
&& pszSymbol
&& *pszSymbol
)
)
)
{
if (pszSymbol)
}
/* above */
&& pszSymbol
&& *pszSymbol
)
)
)
{
if (pszSymbol)
}
return VINF_SUCCESS;
}
{
int rc = RTLdrEnumSymbols(g_hLdrMod, RTLDR_ENUM_SYMBOL_FLAGS_ALL, g_pvBits, g_uLoadAddr, testEnumSymbol2, pNearSym);
if (RT_FAILURE(rc))
return rc;
}
void *pvUser)
{
|| uAddress < g_uLoadAddr)
return VERR_SYMBOL_NOT_FOUND;
if (RT_FAILURE(rc))
return rc;
return VINF_SUCCESS;
}
/**
* @callback_method_impl{FNDISREADBYTES}
*/
static DECLCALLBACK(int) MyReadBytes(PDISCPUSTATE pDisState, uint8_t *pbDst, RTUINTPTR uSrcAddr, uint32_t cbToRead)
{
return VINF_SUCCESS;
}
{
int32_t i = 0;
while (i < cbMax)
{
bool fQuiet = RTAssertSetQuiet(true);
bool fMayPanic = RTAssertSetMayPanic(false);
char szOutput[256];
unsigned cbInstr;
if (RT_FAILURE(rc))
return false;
DIS_FMT_FLAGS_RELATIVE_BRANCH | DIS_FMT_FLAGS_BYTES_RIGHT | DIS_FMT_FLAGS_ADDR_LEFT | DIS_FMT_FLAGS_BYTES_SPACED,
MyGetSymbol, NULL);
RTPrintf("^^^^^^^^\n");
/* next */
i += cbInstr;
}
return true;
}
/**
* Resolve an external symbol during RTLdrGetBits().
*
* @returns iprt status code.
* @param hLdrMod The loader module handle.
* @param pszModule Module name.
* @param pszSymbol Symbol name, NULL if uSymbol should be used.
* @param uSymbol Symbol ordinal, ~0 if pszSymbol should be used.
* @param pValue Where to store the symbol value (address).
* @param pvUser User argument.
*/
static DECLCALLBACK(int) testGetImport(RTLDRMOD hLdrMod, const char *pszModule, const char *pszSymbol, unsigned uSymbol, RTUINTPTR *pValue, void *pvUser)
{
#if 1
#else
#endif
if (g_cBits == 32)
*pValue &= UINT32_MAX;
return VINF_SUCCESS;
}
/**
* Enumeration callback function used by RTLdrEnumSymbols().
*
* @returns iprt status code. Failure will stop the enumeration.
* @param hLdrMod The loader module handle.
* @param pszSymbol Symbol name. NULL if ordinal only.
* @param uSymbol Symbol ordinal, ~0 if not used.
* @param Value Symbol value.
* @param pvUser The user argument specified to RTLdrEnumSymbols().
*/
static DECLCALLBACK(int) testEnumSymbol1(RTLDRMOD hLdrMod, const char *pszSymbol, unsigned uSymbol, RTUINTPTR Value, void *pvUser)
{
return VINF_SUCCESS;
}
{
if (RT_FAILURE(rc))
return rc;
RTPrintf("tstLdr-3: Addr=%RTptr\n"
"%RTptr %s (%d) - %RTptr %s (%d)\n",
{
#ifdef RT_ARCH_X86 /** @todo select according to the module type. */
#else
#endif
}
return VINF_SUCCESS;
}
{
int rcRet = 0;
if (argc <= 2)
{
return 1;
}
/*
* Load the module.
*/
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_SUCCESS(rc))
{
if ( argc == 4
{
/*
* Wildcard address mode.
*/
if (!uIncrements)
uIncrements = 0x1000;
}
else if (argc > 3)
{
/*
* User specified addresses within the module.
*/
for (int i = 3; i < argc; i++)
{
if (RT_FAILURE(rc))
rcRet++;
}
}
else
{
/*
* Enumerate symbols.
*/
rc = RTLdrEnumSymbols(g_hLdrMod, RTLDR_ENUM_SYMBOL_FLAGS_ALL, g_pvBits, g_uLoadAddr, testEnumSymbol1, NULL);
if (RT_FAILURE(rc))
{
rcRet++;
}
}
}
else
{
rcRet++;
}
/*
* Test result summary.
*/
if (!rcRet)
RTPrintf("tstLdr-3: SUCCESS\n");
else
return !!rcRet;
}