rizinorg / rizin

UNIX-like reverse engineering framework and command-line toolset.
https://rizin.re
GNU Lesser General Public License v3.0
2.69k stars 361 forks source link

Assembly of `lea rXX, XXX` instructions produces wrong machine code. #1724

Open Semnodime opened 3 years ago

Semnodime commented 3 years ago

Environment information

Describe the bug Assembly of lea rXX, XXX instructions produces wrong machine code (the second nibble is wrong): For rXX = r8...r15, rXX gets wrongly turned into rax, rcx, rdx, rbx, rsp, rbp, rsi, rdi. e.g. lea r12, [rsp+0x10] -> 488d642410 (which is correctly disassembled to lea rsp, [rsp + 0x10].

To Reproduce Steps to reproduce the behavior:

  1. Open Cutter with any elf64 x86
  2. Disassembly Tab -> Right click on any line of machine code -> Edit -> Instruction -> e.g. lea r12, [rsp+0x10]
  3. See error

Expected behavior Correct assembly: e.g. lea r12, [rsp+0x10] -> 4c8d642410

ret2libc commented 3 years ago

This is very likely an issue for Rizin. I'm moving it there. Also, it seems to be in the x86 internal assembler. I bet x86.ks plugin (keystone) can disassemble this correctly.