tstDisasm-2.cpp revision 7bf0220c3332700233120b513c9b4ba20a0caa9b
/* $Id$ */
/** @file
* Testcase - Generic Disassembler Tool.
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
typedef struct MYDISSTATE
{
int rc; /**< Set if we hit EOF. */
} MYDISSTATE;
typedef MYDISSTATE *PMYDISSTATE;
/**
* Default style.
*
* @param pState The disassembler state.
*/
{
}
/**
* Yasm style.
*
* @param pState The disassembler state.
*/
{
}
/**
* Masm style.
*
* @param pState The disassembler state.
*/
{
}
/**
* Callback for reading bytes.
*/
static DECLCALLBACK(int) MyDisasInstrRead(RTUINTPTR uSrcAddr, uint8_t *pbDst, uint32_t cbRead, void *pvDisCpu)
{
{
/*
* Straight forward reading.
*/
if (cbRead == 1)
{
}
else
{
}
}
else
{
/*
* Jumping up the stream.
*/
if (offReq64 < 32)
{
{
return VERR_EOF;
}
/* reset the stream. */
/* skip ahead. */
/* do the reading. */
{
}
else
{
{
}
return VERR_EOF;
}
}
else
{
return VERR_INTERNAL_ERROR;
}
}
return VINF_SUCCESS;
}
/**
* Disassembles a block of memory.
*
* @returns VBox status code.
* @param argv0 Program name (for errors and warnings).
* @param enmCpuMode The cpu mode to disassemble in.
* @param uAddress The address we're starting to disassemble at.
* @param pbFile Where to start disassemble.
* @param cbFile How much to disassemble.
* @param enmStyle The assembly output style.
* @param fListing Whether to print in a listing like mode.
*/
static int MyDisasmBlock(const char *argv0, DISCPUMODE enmCpuMode, uint64_t uAddress, uint8_t *pbFile, size_t cbFile,
{
/*
* Initialize the CPU context.
*/
switch (enmStyle)
{
case kAsmStyle_Default:
break;
case kAsmStyle_yasm:
break;
case kAsmStyle_masm:
break;
default:
}
/*
* The loop.
*/
int rcRet = VINF_SUCCESS;
{
/*
* Disassemble it.
*/
if (RT_SUCCESS(rc))
{
}
else
{
else
{
break;
}
}
/* next */
}
return rcRet;
}
/**
* Prints usage info.
*
* @returns 1.
* @param argv0 The program name.
*/
{
"usage: %s [options] <file1> [file2..fileN]\n"
" or: %s <--help|-h>\n"
"\n"
"Options:\n"
" --address|-a <address>\n"
" The base address. Default: 0\n"
" --max-bytes|-b <bytes>\n"
" The maximum number of bytes to disassemble. Default: 1GB\n"
" --cpumode|-c <16|32|64>\n"
" The cpu mode. Default: 32\n"
" --listing|-l, --no-listing|-L\n"
" Enables or disables listing mode. Default: --no-listing\n"
" --offset|-o <offset>\n"
" The file offset at which to start disassembling. Default: 0\n"
" --style|-s <default|yasm|masm>\n"
" The assembly output style. Default: default\n"
return 1;
}
{
RTR3Init();
/* options */
bool fListing = true;
/*
* Parse arguments.
*/
static const RTOPTIONDEF g_aOptions[] =
{
{ "--help", 'h', 0 },
{ "--listing", 'l', 0 },
{ "--no-listing", 'L', 0 },
};
int ch;
int iArg = 1;
{
switch (ch)
{
case 'a':
break;
case 'b':
cbMax = ValueUnion.i;
break;
case 'c':
else
{
return 1;
}
break;
case 'h':
case 'l':
fListing = true;
break;
case 'L':
fListing = false;
break;
case 'o':
off = ValueUnion.i;
break;
case 's':
{
return 1;
}
else
{
return 1;
}
break;
default:
return 1;
}
}
/*
* Process the files.
*/
int rc = VINF_SUCCESS;
{
/*
* Read the file into memory.
*/
void *pvFile;
if (RT_FAILURE(rc))
{
break;
}
/*
* Disassemble it.
*/
if (RT_FAILURE(rc))
break;
}
}