From c296c8308818fa67880c7d81e3511387f2ee824a Mon Sep 17 00:00:00 2001 From: Alex Cameron Date: Fri, 29 Jul 2022 02:13:31 +1000 Subject: [PATCH 1/2] Prevent the instruction category from being overwritten after a fused call/pop has been recognised --- lib/Arch/X86/Arch.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Arch/X86/Arch.cpp b/lib/Arch/X86/Arch.cpp index 3405f10a0..cee84e3aa 100644 --- a/lib/Arch/X86/Arch.cpp +++ b/lib/Arch/X86/Arch.cpp @@ -1230,7 +1230,9 @@ bool X86Arch::DecodeInstruction(uint64_t address, std::string_view inst_bytes, } } - inst.category = CreateCategory(xedd); + if (inst.category == Instruction::kCategoryInvalid) { + inst.category = CreateCategory(xedd); + } inst.next_pc = address + len + extra_len; // Fiddle with the size of the bytes. From 209db3b7e3f03d134dcbe054a95a0bc6be48382f Mon Sep 17 00:00:00 2001 From: Alex Cameron Date: Fri, 29 Jul 2022 02:21:25 +1000 Subject: [PATCH 2/2] Move assignment up and remove conditional --- lib/Arch/X86/Arch.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/Arch/X86/Arch.cpp b/lib/Arch/X86/Arch.cpp index cee84e3aa..de41f1ba2 100644 --- a/lib/Arch/X86/Arch.cpp +++ b/lib/Arch/X86/Arch.cpp @@ -1203,6 +1203,8 @@ bool X86Arch::DecodeInstruction(uint64_t address, std::string_view inst_bytes, return false; } + inst.category = CreateCategory(xedd); + // Look for instruction fusing opportunities. For now, just `call; pop`. const char *is_fused_call_pop = nullptr; if (len < inst_bytes.size() && @@ -1230,9 +1232,6 @@ bool X86Arch::DecodeInstruction(uint64_t address, std::string_view inst_bytes, } } - if (inst.category == Instruction::kCategoryInvalid) { - inst.category = CreateCategory(xedd); - } inst.next_pc = address + len + extra_len; // Fiddle with the size of the bytes.