jak-project/test/test_zydis.cpp
Tyler Wilding 637b043293
deps: update zydis to latest commit (#3306)
Updates Zydis to it's latest commit, this should fix building the
project on intel macs with a more recent version of macOS. This likely
needs some sanity checks that the debugger stuff still works as
expected.
2024-01-15 16:56:14 -05:00

33 lines
1.2 KiB
C++

#include "common/common_types.h"
#include "gtest/gtest.h"
#include "third-party/zydis/include/Zydis/Zydis.h"
TEST(Zydis, Basic) {
// int3, return
u8 code[] = {0xcc, 0xc3};
ZydisDecoder decoder;
ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_64, ZYDIS_STACK_WIDTH_64);
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
ZydisDecodedInstruction instr;
ZydisDecodedOperand op[ZYDIS_MAX_OPERAND_COUNT];
// should get first instruction
EXPECT_TRUE(ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder, code, 2, &instr, op)));
char result[256];
ZydisFormatterFormatInstruction(&formatter, &instr, op, instr.operand_count_visible, result,
sizeof(result), 0, ZYAN_NULL);
EXPECT_EQ(std::string("int3"), result);
EXPECT_EQ(1, instr.length);
// should get second instruction
EXPECT_TRUE(ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder, code + 1, 1, &instr, op)));
ZydisFormatterFormatInstruction(&formatter, &instr, op, instr.operand_count_visible, result,
sizeof(result), 0, ZYAN_NULL);
EXPECT_EQ(std::string("ret"), result);
EXPECT_EQ(1, instr.length);
}