From 99a37667bb1e479d6f40e35ce45d011547ff334f Mon Sep 17 00:00:00 2001 From: Hailey Somerville Date: Wed, 1 Apr 2026 22:34:57 +1100 Subject: [PATCH] Fix stack adjustment for x86 pop r16 Always pops operand size and then truncates to store in register --- arch/x86/il.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/arch/x86/il.cpp b/arch/x86/il.cpp index 2c1cbd83c..4a0193c50 100644 --- a/arch/x86/il.cpp +++ b/arch/x86/il.cpp @@ -3141,6 +3141,15 @@ bool GetLowLevelILForInstruction(Architecture* arch, const uint64_t addr, LowLev break; case XED_ICLASS_POP: + { + const unsigned int stackAdjustment = xed_decoded_inst_get_memory_operand_length(xedd, 0); + auto expr = il.Pop(stackAdjustment); + il.AddInstruction(WriteILOperand(il, xedd, addr, 0, 0, + opOneLen == stackAdjustment ? expr : + il.LowPart(opOneLen, expr))); + break; + } + case XED_ICLASS_POPP: il.AddInstruction( WriteILOperand(il, xedd, addr, 0, 0, @@ -3287,17 +3296,10 @@ bool GetLowLevelILForInstruction(Architecture* arch, const uint64_t addr, LowLev // https://stackoverflow.com/questions/43435764/64-bit-mode-does-not-support-32-bit-push-and-pop-instructions // for more details const unsigned int stackAdjustment = xed_decoded_inst_get_memory_operand_length(xedd, 0); - if (opOneLen != stackAdjustment) - { - il.AddInstruction( - il.Push(stackAdjustment, - il.ZeroExtend(stackAdjustment, - ReadILOperand(il, xedd, addr, 0, 0)))); - } - else - il.AddInstruction( - il.Push(stackAdjustment, - ReadILOperand(il, xedd, addr, 0, 0))); + auto expr = ReadILOperand(il, xedd, addr, 0, 0); + il.AddInstruction(il.Push(stackAdjustment, + opOneLen == stackAdjustment ? expr : + il.ZeroExtend(stackAdjustment, expr))); break; }