Browse Source

fix how the disassembler handles ja instructions

https://doc.rust-lang.org/std/fmt/trait.LowerHex.html says "For primitive signed integers (i8 to i128, and isize), negative values are formatted as the two’s complement representation."

As such, we can't rely on Rust's "+" formatting flag when writing instruction offsets.
ttlajus 3 years ago
parent
commit
e29a566a1c
1 changed files with 1 additions and 1 deletions
  1. 1 1
      src/disassembler.rs

+ 1 - 1
src/disassembler.rs

@@ -263,7 +263,7 @@ pub fn to_insn_vec(prog: &[u8]) -> Vec<HLInsn> {
             ebpf::ARSH64_REG => { name = "arsh64"; desc = alu_reg_str(name, &insn); },
 
             // BPF_JMP class
-            ebpf::JA         => { name = "ja";   desc = format!("{} {:+#x}", name, insn.off); },
+            ebpf::JA         => { name = "ja";   desc = if insn.off >= 0 { format!("{} +{:#x}", name, insn.off) } else { format!("{} -{:#x}", name, -insn.off) } },
             ebpf::JEQ_IMM    => { name = "jeq";  desc = jmp_imm_str(name, &insn); },
             ebpf::JEQ_REG    => { name = "jeq";  desc = jmp_reg_str(name, &insn); },
             ebpf::JGT_IMM    => { name = "jgt";  desc = jmp_imm_str(name, &insn); },