Skip to content

Zydis produces invalid MASM with INTEL_MASM #564

@FaerHack

Description

@FaerHack

Zydis incorrectly formats ret far instruction with INTEL_MASM

  1. CB instruction is formatted as ret far. Expected output: 'retf'
  2. 48 CB instruction is formatted as ret far. Expected output: 'retfq'

Example:

#include <assert.h>
#include <stdio.h>
#include <Zydis/Zydis.h>

int main(void)
{
	const ZyanU8 data[] = { 0xCB };
	const ZyanU8 data1[] = { 0x48, 0xCB };

	ZydisDecoder decoder;
	ZydisFormatter formatter;

	ZydisDecodedInstruction instruction;
	ZydisDecodedOperand operands[ZYDIS_MAX_OPERAND_COUNT];

	ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_STACK_WIDTH_64);
	ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL_MASM);

	assert(ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder,
		data,
		sizeof(data),
		&instruction,
		operands)));

	char buff[128]{ 0 };

	ZydisFormatterFormatInstruction(&formatter, &instruction, operands, instruction.operand_count_visible, buff, 127, 0, nullptr);
	printf("%s\n", buff);

	assert(ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder,
		data1,
		sizeof(data1),
		&instruction,
		operands)));

	ZydisFormatterFormatInstruction(&formatter, &instruction, operands, instruction.operand_count_visible, buff, 127, 0, nullptr);
	printf("%s\n", buff);

	return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions