added custom data source and made some fixes

- added "class" VXCustomDataSource allowing a user to write a custom data source
- increased warning level on MSVC to /W4 and resolved warnings arising from that
- added VX_UNUSED macro that allows shutting up unused-arg warnings explicitly when needed
This commit is contained in:
Ende! 2015-03-19 17:13:37 +01:00
parent 9e2cceb2be
commit f94792e4f9
12 changed files with 185 additions and 48 deletions

View File

@ -323,7 +323,7 @@ inline uint8_t VXStreamDataSource::internalInputPeek()
{
return 0;
}
return m_inputStream->peek();
return static_cast<uint8_t>(m_inputStream->peek());
}
inline uint8_t VXStreamDataSource::internalInputNext()
@ -332,7 +332,7 @@ inline uint8_t VXStreamDataSource::internalInputNext()
{
return 0;
}
return m_inputStream->get();
return static_cast<uint8_t>(m_inputStream->get());
}
inline bool VXStreamDataSource::isEndOfInput() const

View File

@ -16,7 +16,7 @@ if (NOT CONFIGURED_ONCE)
set(compiler_specific "-Werror")
set(compiler_specific_cxx "-std=c++0x")
elseif (MSVC)
set(compiler_specific "/WX /D_CRT_SECURE_NO_WARNINGS")
set(compiler_specific "/WX /W4 /D_CRT_SECURE_NO_WARNINGS")
endif ()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${compiler_specific} ${compiler_specific_cxx}"

View File

@ -39,6 +39,8 @@ using namespace Verteron;
int main(int argc, char* argv[])
{
(void)argc; (void)argv;
uint8_t data32[] =
{
0x8B, 0xFF, 0x55, 0x8B, 0xEC, 0x6A, 0xFE, 0x68, 0xD8, 0x18, 0x09, 0x77, 0x68, 0x85, 0xD2,

View File

@ -6,9 +6,9 @@
Remarks : Freeware, Copyright must be included
Original Author : Florian Bernd
Modifications :
Modifications : athre0z
Last change : 29. October 2014
Last change : 19. March 2015
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -30,8 +30,12 @@
**************************************************************************************************/
#include <VXDisassembler.h>
int main(int argc, char* argv[])
{
VX_UNUSED(argc); VX_UNUSED(argv);
// TODO:
return 0;
}

View File

@ -6,9 +6,9 @@
Remarks : Freeware, Copyright must be included
Original Author : Florian Bernd
Modifications :
Modifications : athre0z
Last change : 29. October 2014
Last change : 19. March 2015
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -30,8 +30,12 @@
**************************************************************************************************/
#include <VXDisassembler.h>
int main(int argc, char* argv[])
{
VX_UNUSED(argc); VX_UNUSED(argv);
// TODO:
return 0;
}

View File

@ -6,9 +6,9 @@
Remarks : Freeware, Copyright must be included
Original Author : Florian Bernd
Modifications :
Modifications : athre0z
Last change : 29. October 2014
Last change : 19. March 2015
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -35,6 +35,8 @@
int main(int argc, char* argv[])
{
VX_UNUSED(argc); VX_UNUSED(argv);
// TODO: port to C
/*

View File

@ -8,7 +8,7 @@
Original Author : Florian Bernd
Modifications : athre0z
Last change : 13. March 2015
Last change : 19. March 2015
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -42,13 +42,6 @@
/* VXBaseDataSource ---------------------------------------------------------------------------- */
typedef void(*VXBaseDataSource_DestructionCallback)(VXBaseDataSourceContext *ctx);
typedef uint8_t(*VXBaseDataSource_InputCallback)(VXBaseDataSourceContext *ctx);
typedef bool(*VXBaseDataSource_IsEndOfInputCallback)(const VXBaseDataSourceContext *ctx);
typedef uint64_t(*VXBaseDataSource_GetPositionCallback)(const VXBaseDataSourceContext *ctx);
typedef bool(*VXBaseDataSource_SetPositionCallback)(
VXBaseDataSourceContext *ctx, uint64_t position);
typedef struct _VXBaseDataSource
{
uint8_t currentInput;
@ -128,6 +121,38 @@ static uint64_t VXMemoryDataSource_GetPosition(const VXBaseDataSourceContext *ct
*/
static bool VXMemoryDataSource_SetPosition(VXBaseDataSourceContext *ctx, uint64_t position);
/* VXCustomDataSource -------------------------------------------------------------------------- */
typedef struct _VXCustomDataSource
{
VXBaseDataSource super;
VXBaseDataSource_DestructionCallback userDestruct; // may be NULL
} VXCustomDataSource;
/**
* @brief Constructor.
* @param ctx The context.
* @param inputPeekCb The callback peeking the next input byte.
* @param inputNextCb The callback consuming the next input byte.
* @param isEndOfInputCb The callback determining if the end of input was reached.
* @param getPositionCb The callback obtaining the current input position.
* @param setPositionCb The callback setting the current input position.
* @param destructionCb The destruction callback. May be @c NULL.
*/
static void VXCustomDataSource_Construct(VXBaseDataSourceContext *ctx,
VXBaseDataSource_InputCallback inputPeekCb,
VXBaseDataSource_InputCallback inputNextCb,
VXBaseDataSource_IsEndOfInputCallback isEndOfInputCb,
VXBaseDataSource_GetPositionCallback getPositionCb,
VXBaseDataSource_SetPositionCallback setPositionCb,
VXBaseDataSource_DestructionCallback destructionCb);
/**
* @brief Destructor.
* @param The context.
*/
static void VXCustomDataSource_Destruct(VXBaseDataSourceContext *ctx);
/* VXInstructionDecoder ------------------------------------------------------------------------ */
typedef struct _VXInstructionDecoder
@ -367,7 +392,7 @@ static void VXBaseDataSource_Construct(VXBaseDataSourceContext *ctx)
static void VXBaseDataSource_Destruct(VXBaseDataSourceContext *ctx)
{
VX_UNUSED(ctx);
}
void VXBaseDataSource_Release(VXBaseDataSourceContext *ctx)
@ -543,6 +568,61 @@ static bool VXMemoryDataSource_SetPosition(VXBaseDataSourceContext *ctx, uint64_
return thiz->super.isEndOfInput(ctx);
}
/* VXCustomDataSource -------------------------------------------------------------------------- */
static void VXCustomDataSource_Construct(VXBaseDataSourceContext *ctx,
VXBaseDataSource_InputCallback inputPeekCb,
VXBaseDataSource_InputCallback inputNextCb,
VXBaseDataSource_IsEndOfInputCallback isEndOfInputCb,
VXBaseDataSource_GetPositionCallback getPositionCb,
VXBaseDataSource_SetPositionCallback setPositionCb,
VXBaseDataSource_DestructionCallback destructionCb)
{
VXBaseDataSource_Construct(ctx);
VXCustomDataSource *thiz = VXCustomDataSource_thiz(ctx);
thiz->super.destruct = &VXCustomDataSource_Destruct;
thiz->super.internalInputPeek = inputPeekCb;
thiz->super.internalInputNext = inputNextCb;
thiz->super.isEndOfInput = isEndOfInputCb;
thiz->super.getPosition = getPositionCb;
thiz->super.setPosition = setPositionCb;
thiz->userDestruct = destructionCb;
}
static void VXCustomDataSource_Destruct(VXBaseDataSourceContext *ctx)
{
VXCustomDataSource *thiz = VXCustomDataSource_thiz(ctx);
if (thiz->userDestruct)
{
thiz->userDestruct(ctx);
}
VXBaseDataSource_Destruct(ctx);
}
VXBaseDataSourceContext* VXCustomDataSource_Create(
VXBaseDataSource_InputCallback inputPeekCb,
VXBaseDataSource_InputCallback inputNextCb,
VXBaseDataSource_IsEndOfInputCallback isEndOfInputCb,
VXBaseDataSource_GetPositionCallback getPositionCb,
VXBaseDataSource_SetPositionCallback setPositionCb,
VXBaseDataSource_DestructionCallback destructionCb)
{
VXCustomDataSource *thiz = malloc(sizeof(VXCustomDataSource));
VXBaseDataSourceContext *ctx = malloc(sizeof(VXBaseDataSourceContext));
ctx->d.type = TYPE_CUSTOMDATASOURCE;
ctx->d.ptr = thiz;
VXCustomDataSource_Construct(ctx, inputPeekCb, inputNextCb, isEndOfInputCb, getPositionCb,
setPositionCb, destructionCb);
return ctx;
}
/* VXInstructionDecoder ------------------------------------------------------------------------ */
void VXInstructionDecoder_Construct(VXInstructionDecoderContext *ctx,
@ -559,7 +639,7 @@ void VXInstructionDecoder_Construct(VXInstructionDecoderContext *ctx,
void VXInstructionDecoder_Destruct(VXInstructionDecoderContext *ctx)
{
VX_UNUSED(ctx);
}
VXInstructionDecoderContext* VXInstructionDecoder_Create(void)
@ -1377,7 +1457,7 @@ static bool VXInstructionDecoder_DecodeOperand(VXInstructionDecoderContext *ctx,
case DOT_R6:
case DOT_R7:
return VXInstructionDecoder_DecodeRegisterOperand(ctx, info, operand, RC_GENERAL_PURPOSE,
((info->eff_rexvex_b << 3) | operandType - DOT_R0), operandSize);
(uint8_t)((info->eff_rexvex_b << 3) | operandType - DOT_R0), operandSize);
case DOT_AL:
case DOT_AX:
case DOT_EAX:
@ -1411,7 +1491,7 @@ static bool VXInstructionDecoder_DecodeOperand(VXInstructionDecoderContext *ctx,
}
}
operand->type = OPTYPE_REGISTER;
operand->base = operandType - DOT_ES + REG_ES;
operand->base = (uint16_t)(operandType - DOT_ES + REG_ES);
operand->size = 16;
break;
case DOT_ST0:
@ -1423,7 +1503,7 @@ static bool VXInstructionDecoder_DecodeOperand(VXInstructionDecoderContext *ctx,
case DOT_ST6:
case DOT_ST7:
operand->type = OPTYPE_REGISTER;
operand->base = operandType - DOT_ST0 + REG_ST0;
operand->base = (uint16_t)(operandType - DOT_ST0 + REG_ST0);
operand->size = 80;
break;
default:
@ -1472,6 +1552,8 @@ static void VXInstructionDecoder_ResolveOperandAndAddressMode(
static void VXInstructionDecoder_CalculateEffectiveRexVexValues(
const VXInstructionDecoderContext *ctx, VXInstructionInfo *info)
{
VX_UNUSED(ctx);
assert(info->instrDefinition);
uint8_t rex = info->rex;
if (info->flags & IF_PREFIX_VEX)

View File

@ -48,6 +48,13 @@ extern "C"
typedef struct _VXBaseDataSourceContext { VXContextDescriptor d; } VXBaseDataSourceContext;
typedef void(*VXBaseDataSource_DestructionCallback)(VXBaseDataSourceContext *ctx);
typedef uint8_t(*VXBaseDataSource_InputCallback)(VXBaseDataSourceContext *ctx);
typedef bool(*VXBaseDataSource_IsEndOfInputCallback)(const VXBaseDataSourceContext *ctx);
typedef uint64_t(*VXBaseDataSource_GetPositionCallback)(const VXBaseDataSourceContext *ctx);
typedef bool(*VXBaseDataSource_SetPositionCallback)(
VXBaseDataSourceContext *ctx, uint64_t position);
/**
* @brief Releases a data source.
* @param ctx The context to release.
@ -150,11 +157,32 @@ VX_EXPORT bool VXBaseDataSource_SetPosition(
* @return @c NULL if it fails, else a data source context.
* @see VXBaseDataSource_Release
*/
// TODO: verify return value
VX_EXPORT VXBaseDataSourceContext* VXMemoryDataSource_Create(
const void* buffer,
size_t bufferLen);
/* VXCustomDataSource ========================================================================== */
/**
* @brief Creates a custom daat source.
* @param ctx The context.
* @param inputPeekCb The callback peeking the next input byte.
* @param inputNextCb The callback consuming the next input byte.
* @param isEndOfInputCb The callback determining if the end of input was reached.
* @param getPositionCb The callback obtaining the current input position.
* @param setPositionCb The callback setting the current input position.
* @param destructionCb The destruction callback. May be @c NULL.
* @return @c NULL if it fails, else a data source context.
* @see VXBaseDataSource_Release
*/
VX_EXPORT VXBaseDataSourceContext* VXCustomDataSource_Create(
VXBaseDataSource_InputCallback inputPeekCb,
VXBaseDataSource_InputCallback inputNextCb,
VXBaseDataSource_IsEndOfInputCallback isEndOfInputCb,
VXBaseDataSource_GetPositionCallback getPositionCb,
VXBaseDataSource_SetPositionCallback setPositionCb,
VXBaseDataSource_DestructionCallback destructionCb);
/* Enums ======================================================================================= */
/**

View File

@ -8,7 +8,7 @@
Original Author : Florian Bernd
Modifications : athre0z
Last change : 14. March 2014
Last change : 19. March 2014
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -183,12 +183,10 @@ static void VXBaseInstructionFormatter_OutputAppendImmediate(
/**
* @brief Appends a formatted memory displacement value to the output string buffer.
* @param ctx The context.
* @param info The instruction info.
* @param operand The memory operand.
*/
static void VXBaseInstructionFormatter_OutputAppendDisplacement(
VXBaseInstructionFormatterContext *ctx, const VXInstructionInfo *info,
const VXOperandInfo *operand);
VXBaseInstructionFormatterContext *ctx, const VXOperandInfo *operand);
/* VXCustomSymbolResolver ---------------------------------------------------------------------- */
@ -245,12 +243,10 @@ static void VXIntelInstructionFormatter_Destruct(VXBaseInstructionFormatterConte
/**
* @brief Appends an operand cast to the output string buffer.
* @param ctx The context.
* @param info The instruction info.
* @param operand The operand.
*/
static void VXIntelInstructionFormatter_OutputAppendOperandCast(
VXBaseInstructionFormatterContext *ctx, const VXInstructionInfo *info,
const VXOperandInfo *operand);
VXBaseInstructionFormatterContext *ctx, const VXOperandInfo *operand);
/**
* @brief Formats the specified operand and appends it to the output buffer.
@ -278,7 +274,7 @@ void VXBaseSymbolResolver_Construct(VXBaseSymbolResolverContext *ctx)
void VXBaseSymbolResolver_Destruct(VXBaseSymbolResolverContext *ctx)
{
VX_UNUSED(ctx);
}
void VXBaseSymbolResolver_Release(VXBaseSymbolResolverContext *ctx)
@ -454,6 +450,8 @@ static void VXBaseInstructionFormatter_OutputSetUppercase(VXBaseInstructionForma
static char const* VXBaseInstructionFormatter_RegisterToString(
const VXBaseInstructionFormatterContext *ctx, VXRegister reg)
{
VX_UNUSED(ctx);
if (reg == REG_NONE)
{
return "error";
@ -553,7 +551,7 @@ static void VXBaseInstructionFormatter_OutputAppend(
{
for (size_t i = offset; i < thiz->outputStringLen - 1; ++i)
{
thiz->outputBuffer[i] = toupper(thiz->outputBuffer[i]);
thiz->outputBuffer[i] = (char)toupper(thiz->outputBuffer[i]);
}
}
}
@ -605,7 +603,7 @@ static void VXBaseInstructionFormatter_OutputAppendFormatted(
{
for (size_t i = offset; i < thiz->outputStringLen - 1; ++i)
{
thiz->outputBuffer[i] = toupper(thiz->outputBuffer[i]);
thiz->outputBuffer[i] = (char)toupper(thiz->outputBuffer[i]);
}
}
@ -725,8 +723,7 @@ static void VXBaseInstructionFormatter_OutputAppendImmediate(
}
static void VXBaseInstructionFormatter_OutputAppendDisplacement(
VXBaseInstructionFormatterContext *ctx, const VXInstructionInfo *info,
const VXOperandInfo *operand)
VXBaseInstructionFormatterContext *ctx, const VXOperandInfo *operand)
{
assert(operand->offset > 0);
if ((operand->base == REG_NONE) && (operand->index == REG_NONE))
@ -821,8 +818,7 @@ VXBaseInstructionFormatterContext* VXIntelInstructionFormatter_CreateEx(
}
static void VXIntelInstructionFormatter_OutputAppendOperandCast(
VXBaseInstructionFormatterContext *ctx, const VXInstructionInfo *info,
const VXOperandInfo *operand)
VXBaseInstructionFormatterContext *ctx, const VXOperandInfo *operand)
{
switch(operand->size)
{
@ -895,7 +891,7 @@ static void VXIntelInstructionFormatter_FormatOperand(VXBaseInstructionFormatter
if (operand->offset)
{
VXBaseInstructionFormatter_OutputAppendDisplacement(ctx, info, operand);
VXBaseInstructionFormatter_OutputAppendDisplacement(ctx, operand);
}
}
VXBaseInstructionFormatter_OutputAppend(ctx, "]");
@ -996,7 +992,7 @@ static void VXIntelInstructionFormatter_InternalFormatInstruction(
if (cast)
{
VXIntelInstructionFormatter_OutputAppendOperandCast(ctx, info, &info->operand[0]);
VXIntelInstructionFormatter_OutputAppendOperandCast(ctx, &info->operand[0]);
}
VXIntelInstructionFormatter_FormatOperand(ctx, info, &info->operand[0]);
}
@ -1021,7 +1017,7 @@ static void VXIntelInstructionFormatter_InternalFormatInstruction(
if (cast)
{
VXIntelInstructionFormatter_OutputAppendOperandCast(ctx, info, &info->operand[1]);
VXIntelInstructionFormatter_OutputAppendOperandCast(ctx, &info->operand[1]);
}
VXIntelInstructionFormatter_FormatOperand(ctx, info, &info->operand[1]);
}
@ -1039,7 +1035,7 @@ static void VXIntelInstructionFormatter_InternalFormatInstruction(
if (cast)
{
VXIntelInstructionFormatter_OutputAppendOperandCast(ctx, info, &info->operand[2]);
VXIntelInstructionFormatter_OutputAppendOperandCast(ctx, &info->operand[2]);
}
VXIntelInstructionFormatter_FormatOperand(ctx, info, &info->operand[2]);

View File

@ -45,4 +45,6 @@
# define VX_INLINE static inline
#endif
#define VX_UNUSED(x) ((void)x)
#endif /* _VDE_VXINTERNALCONFIG_H_ */

View File

@ -8,7 +8,7 @@
Original Author : athre0z
Modifications :
Last change : 13. March 2015
Last change : 19. March 2015
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -45,6 +45,7 @@ typedef enum _VXTypeId
{
TYPE_BASEDATASOURCE,
TYPE_MEMORYDATASOURCE,
TYPE_CUSTOMDATASOURCE,
TYPE_INSTRUCTIONDECODER,
TYPE_BASESYMBOLRESOLVER,
TYPE_CUSTOMSYMBOLRESOLVER,
@ -58,7 +59,8 @@ VX_INLINE struct _VXBaseDataSource* VXBaseDataSource_thiz(
VXBaseDataSourceContext *ctx)
{
assert(ctx->d.type == TYPE_BASEDATASOURCE
|| ctx->d.type == TYPE_MEMORYDATASOURCE);
|| ctx->d.type == TYPE_MEMORYDATASOURCE
|| ctx->d.type == TYPE_CUSTOMDATASOURCE);
return (struct _VXBaseDataSource*)ctx->d.ptr;
}
@ -66,7 +68,8 @@ VX_INLINE const struct _VXBaseDataSource* VXBaseDataSource_cthiz(
const VXBaseDataSourceContext *ctx)
{
assert(ctx->d.type == TYPE_BASEDATASOURCE
|| ctx->d.type == TYPE_MEMORYDATASOURCE);
|| ctx->d.type == TYPE_MEMORYDATASOURCE
|| ctx->d.type == TYPE_CUSTOMDATASOURCE);
return (const struct _VXBaseDataSource*)ctx->d.ptr;
}
@ -84,6 +87,20 @@ VX_INLINE const struct _VXMemoryDataSource* VXMemoryDataSource_cthiz(
return (const struct _VXMemoryDataSource*)ctx->d.ptr;
}
VX_INLINE struct _VXCustomDataSource* VXCustomDataSource_thiz(
VXBaseDataSourceContext *ctx)
{
assert(ctx->d.type == TYPE_CUSTOMDATASOURCE);
return (struct _VXCustomDataSource*)ctx->d.ptr;
}
VX_INLINE const struct _VXCustomDataSource* VXCustomDataSource_cthiz(
const VXBaseDataSourceContext *ctx)
{
assert(ctx->d.type == TYPE_CUSTOMDATASOURCE);
return (const struct _VXCustomDataSource*)ctx->d.ptr;
}
VX_INLINE struct _VXInstructionDecoder* VXInstructionDecoder_thiz(
VXInstructionDecoderContext *ctx)
{

View File

@ -5,10 +5,10 @@
Remarks : Freeware, Copyright must be included
Original Author : athre0z
Modifications :
Original Author : Florian Bernd
Modifications : athre0z
Last change : 14. March 2015
Last change : 19. March 2015
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@ -285,7 +285,7 @@ VX_INLINE uint16_t VXGetSimpleOperandSize(VXDefinedOperandSize operandSize)
8, 16, 32, 64, 80, 12, 128, 256
};
uint16_t index = operandSize - DOS_B;
uint16_t index = (uint16_t)(operandSize - DOS_B);
assert(index < 8);
return operandSizes[index];
}