From 9ca5adc847098d6f74f49707b94ed0df23626c18 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sat, 30 Mar 2019 15:27:25 -0700 Subject: fix incorrect sign tests and decode oddities --- src/display.rs | 2 +- src/lib.rs | 13 +++++++++++-- test/test.rs | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/display.rs b/src/display.rs index daa2c34..6846174 100644 --- a/src/display.rs +++ b/src/display.rs @@ -162,7 +162,7 @@ impl Colorize for Operand { colors.register(base), colors.register(index), colors.number(scale), - colors.number(format!("{:#x}", scale)) + colors.number(format!("{:#x}", disp)) ) }, &Operand::Nothing => { Ok(()) }, diff --git a/src/lib.rs b/src/lib.rs index 4665f28..f2e19c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1342,9 +1342,18 @@ fn read_E>(bytes_iter: &mut T, prefixes: &Prefixes, m: u8, } else { let index_reg = RegSpec::gp_from_parts(index, prefixes.rex().x(), addr_width, prefixes.rex().present()); if disp == 0 { - *result = Operand::RegIndexBaseScale(base_reg, index_reg, 1u8 << ss); + if ss == 0 { + *result = Operand::RegIndexBase(base_reg, index_reg) + } else { + *result = Operand::RegIndexBaseScale(base_reg, index_reg, 1u8 << ss); + } } else { - *result = Operand::RegIndexBaseScaleDisp(base_reg, index_reg, 1u8 << ss, disp as i32); + if ss == 0 { + + *result = Operand::RegIndexBaseDisp(base_reg, index_reg, disp as i32); + } else { + *result = Operand::RegIndexBaseScaleDisp(base_reg, index_reg, 1u8 << ss, disp as i32); + } } } } diff --git a/test/test.rs b/test/test.rs index 7f00432..df94aeb 100644 --- a/test/test.rs +++ b/test/test.rs @@ -92,9 +92,9 @@ fn test_control_flow() { #[test] fn test_test_cmp() { - test_display(&[0x48, 0x3d, 0x01, 0xf0, 0xff, 0xff], "cmp rax, 0xfffffffffffff001"); - test_display(&[0x3d, 0x01, 0xf0, 0xff, 0xff], "cmp eax, 0xfffff001"); - test_display(&[0x48, 0x83, 0xf8, 0xff], "cmp rax, 0xffffffffffffffff"); + test_display(&[0x48, 0x3d, 0x01, 0xf0, 0xff, 0xff], "cmp rax, -0xfff"); + test_display(&[0x3d, 0x01, 0xf0, 0xff, 0xff], "cmp eax, -0xfff"); + test_display(&[0x48, 0x83, 0xf8, 0xff], "cmp rax, -0x1"); test_display(&[0x48, 0x39, 0xc6], "cmp rsi, rax"); } -- cgit v1.1