Skip to content

Commit

Permalink
deps: update zydis to latest commit (#3306)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xTVaser committed Jan 15, 2024
1 parent 46db6a3 commit 637b043
Show file tree
Hide file tree
Showing 165 changed files with 24,871 additions and 18,692 deletions.
24 changes: 9 additions & 15 deletions goalc/debugger/disassemble.cpp
Expand Up @@ -16,17 +16,15 @@ std::string disassemble_x86(u8* data, int len, u64 base_addr) {
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
ZydisDecodedInstruction instr;
ZydisDecodedOperand op[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
ZydisDecodedOperand op[ZYDIS_MAX_OPERAND_COUNT];

constexpr int print_buff_size = 512;
char print_buff[print_buff_size];
int offset = 0;
while (ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder, data + offset, len - offset, &instr, op,
ZYDIS_MAX_OPERAND_COUNT_VISIBLE,
ZYDIS_DFLAG_VISIBLE_OPERANDS_ONLY))) {
while (ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder, data + offset, len - offset, &instr, op))) {
result += fmt::format("[0x{:x}] ", base_addr);
ZydisFormatterFormatInstruction(&formatter, &instr, op, instr.operand_count_visible, print_buff,
print_buff_size, base_addr);
print_buff_size, base_addr, ZYAN_NULL);
result += print_buff;
result += "\n";

Expand All @@ -44,7 +42,7 @@ std::string disassemble_x86(u8* data, int len, u64 base_addr, u64 highlight_addr
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
ZydisDecodedInstruction instr;
ZydisDecodedOperand op[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
ZydisDecodedOperand op[ZYDIS_MAX_OPERAND_COUNT];

constexpr int print_buff_size = 512;
char print_buff[print_buff_size];
Expand All @@ -54,12 +52,10 @@ std::string disassemble_x86(u8* data, int len, u64 base_addr, u64 highlight_addr
int mark_offset = int(highlight_addr - base_addr);
while (offset < len) {
char prefix = (offset == mark_offset) ? '-' : ' ';
if (ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder, data + offset, len - offset, &instr, op,
ZYDIS_MAX_OPERAND_COUNT_VISIBLE,
ZYDIS_DFLAG_VISIBLE_OPERANDS_ONLY))) {
if (ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder, data + offset, len - offset, &instr, op))) {
result += fmt::format("{:c} [0x{:x}] ", prefix, base_addr);
ZydisFormatterFormatInstruction(&formatter, &instr, op, instr.operand_count_visible,
print_buff, print_buff_size, base_addr);
print_buff, print_buff_size, base_addr, ZYAN_NULL);
result += print_buff;
result += "\n";
offset += instr.length;
Expand Down Expand Up @@ -97,7 +93,7 @@ std::string disassemble_x86_function(
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
ZydisDecodedInstruction instr;
ZydisDecodedOperand op[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
ZydisDecodedOperand op[ZYDIS_MAX_OPERAND_COUNT];

constexpr int print_buff_size = 512;
char print_buff[print_buff_size];
Expand All @@ -118,9 +114,7 @@ std::string disassemble_x86_function(
int mark_offset = int(highlight_addr - base_addr);
while (offset < len) {
char prefix = (offset == mark_offset) ? '-' : ' ';
if (ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder, data + offset, len - offset, &instr, op,
ZYDIS_MAX_OPERAND_COUNT_VISIBLE,
ZYDIS_DFLAG_VISIBLE_OPERANDS_ONLY))) {
if (ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder, data + offset, len - offset, &instr, op))) {
bool warn_messed_up = false;
bool print_ir = false;
// we should have a next instruction.
Expand Down Expand Up @@ -190,7 +184,7 @@ std::string disassemble_x86_function(
}

ZydisFormatterFormatInstruction(&formatter, &instr, op, instr.operand_count_visible,
print_buff, print_buff_size, base_addr);
print_buff, print_buff_size, base_addr, ZYAN_NULL);
line += print_buff;

if (print_ir && current_ir_idx >= 0 && current_ir_idx < int(ir_strings.size())) {
Expand Down
2 changes: 1 addition & 1 deletion test/goalc/test_with_game.cpp
Expand Up @@ -783,7 +783,7 @@ TEST_F(WithGameTests, StaticTypeArray) {
{"matched!\n0\n"});
}

TEST_F(WithGameTests, StaticArraySubtypeDraft) {
TEST_F(WithGameTests, StaticArraySubtype) {
shared_compiler->runner.run_static_test(testCategory, "test-static-array-subtype.gc",
{"length - 2\ntest\n1\n0\n"});
}
Expand Down
14 changes: 5 additions & 9 deletions test/test_zydis.cpp
Expand Up @@ -13,24 +13,20 @@ TEST(Zydis, Basic) {
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);

ZydisDecodedInstruction instr;
ZydisDecodedOperand op[ZYDIS_MAX_OPERAND_COUNT_VISIBLE];
ZydisDecodedOperand op[ZYDIS_MAX_OPERAND_COUNT];

// should get first instruction
EXPECT_TRUE(ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder, code, 2, &instr, op,
ZYDIS_MAX_OPERAND_COUNT_VISIBLE,
ZYDIS_DFLAG_VISIBLE_OPERANDS_ONLY)));
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);
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,
ZYDIS_MAX_OPERAND_COUNT_VISIBLE,
ZYDIS_DFLAG_VISIBLE_OPERANDS_ONLY)));
EXPECT_TRUE(ZYAN_SUCCESS(ZydisDecoderDecodeFull(&decoder, code + 1, 1, &instr, op)));
ZydisFormatterFormatInstruction(&formatter, &instr, op, instr.operand_count_visible, result,
sizeof(result), 0);
sizeof(result), 0, ZYAN_NULL);
EXPECT_EQ(std::string("ret"), result);
EXPECT_EQ(1, instr.length);
}
7 changes: 6 additions & 1 deletion third-party/zydis/.gitattributes

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions third-party/zydis/.github/workflows/doc.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

73 changes: 37 additions & 36 deletions third-party/zydis/.github/workflows/main.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 637b043

Please sign in to comment.