mirror of https://github.com/x64dbg/zydis
				
				
				
			Minor bugfixes and cosmetical changes
This commit is contained in:
		
							parent
							
								
									ebf71d632f
								
							
						
					
					
						commit
						71a6d786d7
					
				| 
						 | 
					@ -73,9 +73,8 @@ enum ZydisDecodeGranularities
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @return  A zydis status code. 
 | 
					 * @return  A zydis status code. 
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
ZYDIS_EXPORT ZydisStatus ZydisDecode(ZydisOperatingMode operatingMode,
 | 
					ZYDIS_EXPORT ZydisStatus ZydisDecode(ZydisOperatingMode operatingMode, const void* buffer, 
 | 
				
			||||||
    const void* buffer, size_t bufferLen, uint64_t instructionPointer, 
 | 
					    size_t bufferLen, uint64_t instructionPointer, ZydisInstructionInfo* info);
 | 
				
			||||||
    ZydisInstructionInfo* info);
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * @brief   Decodes the instruction in the given input @c buffer.
 | 
					 * @brief   Decodes the instruction in the given input @c buffer.
 | 
				
			||||||
| 
						 | 
					@ -90,9 +89,9 @@ ZYDIS_EXPORT ZydisStatus ZydisDecode(ZydisOperatingMode operatingMode,
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @return  A zydis status code. 
 | 
					 * @return  A zydis status code. 
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
ZYDIS_EXPORT ZydisStatus ZydisDecodeEx(ZydisOperatingMode operatingMode,
 | 
					ZYDIS_EXPORT ZydisStatus ZydisDecodeEx(ZydisOperatingMode operatingMode, const void* buffer, 
 | 
				
			||||||
    const void* buffer, size_t bufferLen, uint64_t instructionPointer, 
 | 
					    size_t bufferLen, uint64_t instructionPointer, ZydisDecodeGranularity granularity, 
 | 
				
			||||||
    ZydisDecodeGranularity granularity, ZydisInstructionInfo* info);
 | 
					    ZydisInstructionInfo* info);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* ============================================================================================== */
 | 
					/* ============================================================================================== */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1575,8 +1575,8 @@ static ZydisStatus ZydisDecodeOperand(ZydisDecoderContext* ctx, ZydisInstruction
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @return  A zydis status code.
 | 
					 * @return  A zydis status code.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* ctx,
 | 
					static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* ctx, ZydisInstructionInfo* info, 
 | 
				
			||||||
    ZydisInstructionInfo* info, const ZydisOperandDefinition* operands, uint8_t operandCount)
 | 
					    const ZydisOperandDefinition* operands, uint8_t operandCount)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ZYDIS_ASSERT(ctx);
 | 
					    ZYDIS_ASSERT(ctx);
 | 
				
			||||||
    ZYDIS_ASSERT(info);
 | 
					    ZYDIS_ASSERT(info);
 | 
				
			||||||
| 
						 | 
					@ -1663,8 +1663,7 @@ static ZydisStatus ZydisDecodeOperands(ZydisDecoderContext* ctx,
 | 
				
			||||||
 * @param   ctx     A pointer to the @c ZydisDecoderContext instance.
 | 
					 * @param   ctx     A pointer to the @c ZydisDecoderContext instance.
 | 
				
			||||||
 * @param   info    A pointer to the @c ZydisInstructionInfo struct.
 | 
					 * @param   info    A pointer to the @c ZydisInstructionInfo struct.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static void ZydisApplyInstructionDefinition(ZydisDecoderContext* ctx, 
 | 
					static void ZydisApplyInstructionDefinition(ZydisDecoderContext* ctx, ZydisInstructionInfo* info)
 | 
				
			||||||
    ZydisInstructionInfo* info)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ZYDIS_ASSERT(info);
 | 
					    ZYDIS_ASSERT(info);
 | 
				
			||||||
    ZYDIS_ASSERT(ctx->definition);
 | 
					    ZYDIS_ASSERT(ctx->definition);
 | 
				
			||||||
| 
						 | 
					@ -1836,15 +1835,15 @@ static ZydisStatus ZydisNodeHandlerOpcode(ZydisDecoderContext* ctx,
 | 
				
			||||||
                    case 0xC5:
 | 
					                    case 0xC5:
 | 
				
			||||||
                        // Decode vex-prefix
 | 
					                        // Decode vex-prefix
 | 
				
			||||||
                        info->encoding = ZYDIS_INSTRUCTION_ENCODING_VEX;
 | 
					                        info->encoding = ZYDIS_INSTRUCTION_ENCODING_VEX;
 | 
				
			||||||
                        ZYDIS_CHECK(
 | 
					                        ZYDIS_CHECK(ZydisDecodeVEX(
 | 
				
			||||||
                            ZydisDecodeVEX(ctx, info, info->opcode, prefixBytes[0], prefixBytes[1]));
 | 
					                            ctx, info, info->opcode, prefixBytes[0], prefixBytes[1]));
 | 
				
			||||||
                        info->opcodeMap = info->details.vex.m_mmmm;
 | 
					                        info->opcodeMap = info->details.vex.m_mmmm;
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    case 0x62:
 | 
					                    case 0x62:
 | 
				
			||||||
                        // Decode evex-prefix
 | 
					                        // Decode evex-prefix
 | 
				
			||||||
                        info->encoding = ZYDIS_INSTRUCTION_ENCODING_EVEX;
 | 
					                        info->encoding = ZYDIS_INSTRUCTION_ENCODING_EVEX;
 | 
				
			||||||
                        ZYDIS_CHECK(
 | 
					                        ZYDIS_CHECK(ZydisDecodeEVEX(
 | 
				
			||||||
                            ZydisDecodeEVEX(ctx, info, prefixBytes[0], prefixBytes[1], prefixBytes[2]));
 | 
					                            ctx, info, prefixBytes[0], prefixBytes[1], prefixBytes[2]));
 | 
				
			||||||
                        info->opcodeMap = info->details.evex.mm;
 | 
					                        info->opcodeMap = info->details.evex.mm;
 | 
				
			||||||
                        break;
 | 
					                        break;
 | 
				
			||||||
                    default:
 | 
					                    default:
 | 
				
			||||||
| 
						 | 
					@ -1945,8 +1944,7 @@ static ZydisStatus ZydisNodeHandlerXop(ZydisInstructionInfo* info, uint16_t* ind
 | 
				
			||||||
    return ZYDIS_STATUS_SUCCESS;   
 | 
					    return ZYDIS_STATUS_SUCCESS;   
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static ZydisStatus ZydisNodeHandlerMode(ZydisDecoderContext* ctx,
 | 
					static ZydisStatus ZydisNodeHandlerMode(ZydisDecoderContext* ctx, uint16_t* index)
 | 
				
			||||||
    uint16_t* index)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ZYDIS_ASSERT(ctx);
 | 
					    ZYDIS_ASSERT(ctx);
 | 
				
			||||||
    ZYDIS_ASSERT(index);
 | 
					    ZYDIS_ASSERT(index);
 | 
				
			||||||
| 
						 | 
					@ -1979,8 +1977,7 @@ static ZydisStatus ZydisNodeHandlerVex(ZydisInstructionInfo* info, uint16_t* ind
 | 
				
			||||||
    return ZYDIS_STATUS_SUCCESS;
 | 
					    return ZYDIS_STATUS_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static ZydisStatus ZydisNodeHandlerMandatoryPrefix(ZydisDecoderContext* ctx, 
 | 
					static ZydisStatus ZydisNodeHandlerMandatoryPrefix(ZydisDecoderContext* ctx, uint16_t* index)
 | 
				
			||||||
    uint16_t* index)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ZYDIS_ASSERT(index);
 | 
					    ZYDIS_ASSERT(index);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2120,8 +2117,8 @@ static ZydisStatus ZydisNodeHandlerAddressSize(ZydisDecoderContext* ctx,
 | 
				
			||||||
    return ZYDIS_STATUS_SUCCESS;   
 | 
					    return ZYDIS_STATUS_SUCCESS;   
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static ZydisStatus ZydisNodeHandlerRexW(ZydisDecoderContext* ctx,
 | 
					static ZydisStatus ZydisNodeHandlerRexW(ZydisDecoderContext* ctx, ZydisInstructionInfo* info, 
 | 
				
			||||||
    ZydisInstructionInfo* info, uint16_t* index)
 | 
					    uint16_t* index)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ZYDIS_ASSERT(info);
 | 
					    ZYDIS_ASSERT(info);
 | 
				
			||||||
    ZYDIS_ASSERT(index);
 | 
					    ZYDIS_ASSERT(index);
 | 
				
			||||||
| 
						 | 
					@ -2147,8 +2144,8 @@ static ZydisStatus ZydisNodeHandlerRexW(ZydisDecoderContext* ctx,
 | 
				
			||||||
    return ZYDIS_STATUS_SUCCESS;
 | 
					    return ZYDIS_STATUS_SUCCESS;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static ZydisStatus ZydisNodeHandlerVexL(ZydisDecoderContext* ctx, 
 | 
					static ZydisStatus ZydisNodeHandlerVexL(ZydisDecoderContext* ctx, ZydisInstructionInfo* info, 
 | 
				
			||||||
    ZydisInstructionInfo* info, uint16_t* index)
 | 
					    uint16_t* index)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ZYDIS_ASSERT(info);
 | 
					    ZYDIS_ASSERT(info);
 | 
				
			||||||
    ZYDIS_ASSERT(index);
 | 
					    ZYDIS_ASSERT(index);
 | 
				
			||||||
| 
						 | 
					@ -2202,8 +2199,7 @@ static ZydisStatus ZydisNodeHandlerEvexB(ZydisInstructionInfo* info, uint16_t* i
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * @return  A zydis decoder status code.
 | 
					 * @return  A zydis decoder status code.
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
static ZydisStatus ZydisDecodeOpcode(ZydisDecoderContext* ctx, 
 | 
					static ZydisStatus ZydisDecodeOpcode(ZydisDecoderContext* ctx, ZydisInstructionInfo* info)
 | 
				
			||||||
    ZydisInstructionInfo* info)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    ZYDIS_ASSERT(ctx);
 | 
					    ZYDIS_ASSERT(ctx);
 | 
				
			||||||
    ZYDIS_ASSERT(info);
 | 
					    ZYDIS_ASSERT(info);
 | 
				
			||||||
| 
						 | 
					@ -2350,18 +2346,16 @@ static ZydisStatus ZydisDecodeOpcode(ZydisDecoderContext* ctx,
 | 
				
			||||||
/* Exported functions                                                                             */
 | 
					/* Exported functions                                                                             */
 | 
				
			||||||
/* ============================================================================================== */
 | 
					/* ============================================================================================== */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ZydisStatus ZydisDecode(ZydisOperatingMode operatingMode,
 | 
					ZydisStatus ZydisDecode(ZydisOperatingMode operatingMode, const void* buffer, size_t bufferLen, 
 | 
				
			||||||
    const void* buffer, size_t bufferLen, uint64_t instructionPointer, 
 | 
					    uint64_t instructionPointer, ZydisInstructionInfo* info)
 | 
				
			||||||
    ZydisInstructionInfo* info)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    return ZydisDecodeEx(
 | 
					    return ZydisDecodeEx(
 | 
				
			||||||
        operatingMode, buffer, bufferLen, instructionPointer, 
 | 
					        operatingMode, buffer, bufferLen, instructionPointer, 
 | 
				
			||||||
        ZYDIS_DECODE_GRANULARITY_DEFAULT, info);
 | 
					        ZYDIS_DECODE_GRANULARITY_DEFAULT, info);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
ZydisStatus ZydisDecodeEx(ZydisOperatingMode operatingMode,
 | 
					ZydisStatus ZydisDecodeEx(ZydisOperatingMode operatingMode, const void* buffer, size_t bufferLen, 
 | 
				
			||||||
    const void* buffer, size_t bufferLen, uint64_t instructionPointer,
 | 
					    uint64_t instructionPointer, ZydisDecodeGranularity granularity, ZydisInstructionInfo* info)
 | 
				
			||||||
    ZydisDecodeGranularity granularity, ZydisInstructionInfo* info)
 | 
					 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    if ((operatingMode != ZYDIS_DISASSEMBLER_MODE_16BIT) &&
 | 
					    if ((operatingMode != ZYDIS_DISASSEMBLER_MODE_16BIT) &&
 | 
				
			||||||
        (operatingMode != ZYDIS_DISASSEMBLER_MODE_32BIT) &&
 | 
					        (operatingMode != ZYDIS_DISASSEMBLER_MODE_32BIT) &&
 | 
				
			||||||
| 
						 | 
					@ -2376,8 +2370,13 @@ ZydisStatus ZydisDecodeEx(ZydisOperatingMode operatingMode,
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ZydisDecoderContext ctx;
 | 
					    ZydisDecoderContext ctx;
 | 
				
			||||||
 | 
					    memset(&ctx.internal, 0, sizeof(ctx.internal));
 | 
				
			||||||
    ctx.operatingMode = operatingMode;
 | 
					    ctx.operatingMode = operatingMode;
 | 
				
			||||||
    ctx.granularity = granularity;
 | 
					    ctx.granularity = granularity;
 | 
				
			||||||
 | 
					    if (granularity == ZYDIS_DECODE_GRANULARITY_DEFAULT)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        ctx.granularity = ZYDIS_DECODE_GRANULARITY_FULL;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    ctx.input.buffer = (uint8_t*)buffer;
 | 
					    ctx.input.buffer = (uint8_t*)buffer;
 | 
				
			||||||
    ctx.input.bufferLen = bufferLen;
 | 
					    ctx.input.bufferLen = bufferLen;
 | 
				
			||||||
    ctx.hasUnusedPrefix66 = 0;
 | 
					    ctx.hasUnusedPrefix66 = 0;
 | 
				
			||||||
| 
						 | 
					@ -2399,8 +2398,7 @@ ZydisStatus ZydisDecodeEx(ZydisOperatingMode operatingMode,
 | 
				
			||||||
    // Set AVX-512 info
 | 
					    // Set AVX-512 info
 | 
				
			||||||
    if (info->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX)
 | 
					    if (info->encoding == ZYDIS_INSTRUCTION_ENCODING_EVEX)
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        const ZydisInstructionDefinition* definition = 
 | 
					        const ZydisInstructionDefinition* definition = (ZydisInstructionDefinition*)ctx.definition;
 | 
				
			||||||
            (ZydisInstructionDefinition*)ctx.definition;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
        switch (definition->evexContext)
 | 
					        switch (definition->evexContext)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue