Minor bugfixes

This commit is contained in:
flobernd 2015-05-21 21:42:06 +02:00
parent 26ab01bdfd
commit 02d0d84c68
6 changed files with 63 additions and 62 deletions

View File

@ -58,10 +58,10 @@ set(sources
"Zydis/ZydisSymbolResolver.cpp"
"Zydis/ZydisUtils.cpp")
if (BUILD_SHARED_LIBS AND WIN32)
set(sources ${sources}
"Zydis/Zydis.rc")
endif ()
if (BUILD_SHARED_LIBS AND WIN32)
set(sources ${sources}
"Zydis/VersionInfo.rc")
endif ()
if (BUILD_C_BINDINGS)
set(headers ${headers}

View File

@ -45,34 +45,10 @@ namespace Zydis
*/
class BaseInput
{
friend class InstructionDecoder;
private:
uint8_t m_currentInput;
protected:
/**
* @brief Override this method in your custom data source implementations.
* Reads the next byte from the data source. This method increases the current
* input position by one.
* @return The current input byte.
*/
virtual uint8_t internalInputPeek() = 0;
/**
* @brief Override this method in your custom data source implementations.
* Reads the next byte from the data source. This method does NOT increase the
* current input position.
* @return The current input byte.
*/
virtual uint8_t internalInputNext() = 0;
protected:
/**
* @brief Default constructor.
*/
BaseInput() { };
public:
/**
* @brief Destructor.
*/
virtual ~BaseInput() { };
public:
private:
/**
* @brief Reads the next byte from the data source. This method does NOT increase the
* current input position or the @c length field of the @c info parameter.
@ -111,6 +87,31 @@ public:
* @return The current input byte.
*/
uint8_t inputCurrent() const;
protected:
/**
* @brief Override this method in your custom data source implementations.
* Reads the next byte from the data source. This method increases the current
* input position by one.
* @return The current input byte.
*/
virtual uint8_t internalInputPeek() = 0;
/**
* @brief Override this method in your custom data source implementations.
* Reads the next byte from the data source. This method does NOT increase the
* current input position.
* @return The current input byte.
*/
virtual uint8_t internalInputNext() = 0;
protected:
/**
* @brief Default constructor.
*/
BaseInput() { };
public:
/**
* @brief Destructor.
*/
virtual ~BaseInput() { };
public:
/**
* @brief Override this method in your custom data source implementations.
@ -175,7 +176,7 @@ inline T BaseInput::inputNext(InstructionInfo& info)
for (unsigned i = 0; i < (sizeof(T) / sizeof(uint8_t)); ++i)
{
T b = inputNext(info);
if (!b&& (info.flags& IF_ERROR_MASK))
if (!b && (info.flags & IF_ERROR_MASK))
{
return 0;
}

View File

@ -39,7 +39,7 @@ namespace Zydis
/* BaseInstructionFormatter ================================================================ */
const char *BaseInstructionFormatter::m_registerStrings[] =
const char* BaseInstructionFormatter::m_registerStrings[] =
{
/* 8 bit general purpose registers */
"al", "cl", "dl", "bl",
@ -237,13 +237,13 @@ void BaseInstructionFormatter::outputAppendAddress(const InstructionInfo& info,
}
} else
{
if (info.flags& IF_DISASSEMBLER_MODE_16)
if (info.flags & IF_DISASSEMBLER_MODE_16)
{
outputAppendFormatted("%.4X", address);
} else if (info.flags& IF_DISASSEMBLER_MODE_32)
} else if (info.flags & IF_DISASSEMBLER_MODE_32)
{
outputAppendFormatted("%.8lX", address);
} else if (info.flags& IF_DISASSEMBLER_MODE_64)
} else if (info.flags & IF_DISASSEMBLER_MODE_64)
{
outputAppendFormatted("%.16llX", address);
} else
@ -293,7 +293,7 @@ void BaseInstructionFormatter::outputAppendImmediate(const InstructionInfo& info
}
}
uint64_t offset = 0;
const char *name = nullptr;
const char* name = nullptr;
if (resolveSymbols)
{
name = resolveSymbol(info, value, offset);
@ -316,7 +316,7 @@ void BaseInstructionFormatter::outputAppendImmediate(const InstructionInfo& info
void BaseInstructionFormatter::outputAppendDisplacement(const OperandInfo& operand)
{
assert(operand.offset > 0);
if ((operand.base == Register::NONE)&& (operand.index == Register::NONE))
if ((operand.base == Register::NONE) && (operand.index == Register::NONE))
{
// Assume the displacement value is unsigned
assert(operand.scale == 0);
@ -408,7 +408,7 @@ void IntelInstructionFormatter::formatOperand(const InstructionInfo& info,
outputAppend(registerToString(operand.base));
break;
case OperandType::MEMORY:
if (info.flags& IF_PREFIX_SEGMENT)
if (info.flags & IF_PREFIX_SEGMENT)
{
outputAppendFormatted("%s:", registerToString(info.segment));
}
@ -480,14 +480,14 @@ void IntelInstructionFormatter::formatOperand(const InstructionInfo& info,
void IntelInstructionFormatter::internalFormatInstruction(const InstructionInfo& info)
{
// Append string prefixes
if (info.flags& IF_PREFIX_LOCK)
if (info.flags & IF_PREFIX_LOCK)
{
outputAppend("lock ");
}
if (info.flags& IF_PREFIX_REP)
if (info.flags & IF_PREFIX_REP)
{
outputAppend("rep ");
} else if (info.flags& IF_PREFIX_REPNE)
} else if (info.flags & IF_PREFIX_REPNE)
{
outputAppend("repne ");
}
@ -506,7 +506,7 @@ void IntelInstructionFormatter::internalFormatInstruction(const InstructionInfo&
(info.operand[0].size != info.operand[1].size))
{
cast = true;
} else if (info.operand[1].type == OperandType::REGISTER&&
} else if (info.operand[1].type == OperandType::REGISTER &&
info.operand[1].base == Register::CL)
{
switch (info.mnemonic)
@ -536,14 +536,14 @@ void IntelInstructionFormatter::internalFormatInstruction(const InstructionInfo&
{
outputAppend(", ");
bool cast = false;
if (info.operand[1].type == OperandType::MEMORY&&
info.operand[0].size != info.operand[1].size&&
if (info.operand[1].type == OperandType::MEMORY &&
info.operand[0].size != info.operand[1].size &&
((info.operand[0].type != OperandType::REGISTER) ||
((info.operand[0].base != Register::ES)&&
(info.operand[0].base != Register::CS)&&
(info.operand[0].base != Register::SS)&&
(info.operand[0].base != Register::DS)&&
(info.operand[0].base != Register::FS)&&
((info.operand[0].base != Register::ES) &&
(info.operand[0].base != Register::CS) &&
(info.operand[0].base != Register::SS) &&
(info.operand[0].base != Register::DS) &&
(info.operand[0].base != Register::FS) &&
(info.operand[0].base != Register::GS))))
{
cast = true;
@ -559,7 +559,7 @@ void IntelInstructionFormatter::internalFormatInstruction(const InstructionInfo&
{
outputAppend(", ");
bool cast = false;
if (info.operand[2].type == OperandType::MEMORY&&
if (info.operand[2].type == OperandType::MEMORY &&
(info.operand[2].size != info.operand[1].size))
{
cast = true;

View File

@ -1607,7 +1607,7 @@ extern const char* instrMnemonicStrings[];
*/
inline OpcodeTreeNodeType GetOpcodeNodeType(OpcodeTreeNode node)
{
return static_cast<OpcodeTreeNodeType>((node >> 12)& 0x0F);
return static_cast<OpcodeTreeNodeType>((node >> 12) & 0x0F);
}
/**
@ -1617,7 +1617,7 @@ inline OpcodeTreeNodeType GetOpcodeNodeType(OpcodeTreeNode node)
*/
inline uint16_t GetOpcodeNodeValue(OpcodeTreeNode node)
{
return (node& 0x0FFF);
return (node & 0x0FFF);
}
/**
@ -1698,7 +1698,7 @@ inline OpcodeTreeNode GetOpcodeTreeChild(OpcodeTreeNode parent, uint16_t index)
inline const InstructionDefinition* GetInstructionDefinition(OpcodeTreeNode node)
{
assert(GetOpcodeNodeType(node) == OpcodeTreeNodeType::INSTRUCTION_DEFINITION);
return& instrDefinitions[node& 0x0FFF];
return& instrDefinitions[node & 0x0FFF];
}
/**
@ -1735,7 +1735,7 @@ inline uint16_t GetSimpleOperandSize(DefinedOperandSize operandSize)
*/
inline DefinedOperandSize GetComplexOperandMemSize(DefinedOperandSize operandSize)
{
return static_cast<DefinedOperandSize>(static_cast<uint8_t>(operandSize)& 0x0F);
return static_cast<DefinedOperandSize>(static_cast<uint8_t>(operandSize) & 0x0F);
}
/**
@ -1745,7 +1745,7 @@ inline DefinedOperandSize GetComplexOperandMemSize(DefinedOperandSize operandSiz
*/
inline DefinedOperandSize GetComplexOperandRegSize(DefinedOperandSize operandSize)
{
return static_cast<DefinedOperandSize>((static_cast<uint8_t>(operandSize) >> 4)& 0x0F);
return static_cast<DefinedOperandSize>((static_cast<uint8_t>(operandSize) >> 4) & 0x0F);
}
}

View File

@ -37,33 +37,33 @@ namespace Zydis
uint64_t CalcAbsoluteTarget(const InstructionInfo& info, const OperandInfo& operand)
{
assert((operand.type == OperandType::REL_IMMEDIATE) ||
((operand.type == OperandType::MEMORY)&& (operand.base == Register::RIP)));
((operand.type == OperandType::MEMORY) && (operand.base == Register::RIP)));
uint64_t truncMask = 0xFFFFFFFFFFFFFFFFull;
if (!(info.flags& IF_DISASSEMBLER_MODE_64))
if (!(info.flags & IF_DISASSEMBLER_MODE_64))
{
truncMask >>= (64 - info.operand_mode);
}
uint16_t size = operand.size;
if ((operand.type == OperandType::MEMORY)&& (operand.base == Register::RIP))
if ((operand.type == OperandType::MEMORY) && (operand.base == Register::RIP))
{
size = operand.offset;
}
switch (size)
{
case 8:
return (info.instrPointer + operand.lval.sbyte)& truncMask;
return (info.instrPointer + operand.lval.sbyte) & truncMask;
case 16:
{
uint32_t delta = operand.lval.sword& truncMask;
uint32_t delta = operand.lval.sword & truncMask;
if ((info.instrPointer + delta) > 0xFFFF)
{
return (info.instrPointer& 0xF0000) + ((info.instrPointer + delta)& 0xFFFF);
return (info.instrPointer& 0xF0000) + ((info.instrPointer + delta) & 0xFFFF);
}
return info.instrPointer + delta;
}
case 32:
return (info.instrPointer + operand.lval.sdword)& truncMask;
return (info.instrPointer + operand.lval.sdword) & truncMask;
default:
assert(0);
}