iced
iced copied to clipboard
CodeAssembler ignores AsmMemoryOperand size mismatches
When trying to encode an invalid instruction the assembler "corrects" it rather than returning an error, which should probably be the defined behaviour given that every instruction already returns a Result by default.
use iced_x86::code_asm::{CodeAssembler, rax, eax, qword_ptr, dword_ptr};
fn main() {
let mut assembler = CodeAssembler::new(64).unwrap();
assembler.mov(eax, qword_ptr(rax)).unwrap();
assembler.mov(rax, dword_ptr(rax)).unwrap();
assembler.mov(qword_ptr(rax), eax).unwrap();
assembler.mov(dword_ptr(rax), rax).unwrap();
println!("{:x?}", assembler.assemble(0).unwrap());
// assembles to
// mov eax, dword ptr [rax]
// mov rax, qword ptr [rax]
// mov dword ptr [rax], eax
// mov qword ptr [rax], rax
}
This is not only the case with mov, but probably any instruction that uses MemOp and Regs
The memory size fns are just hints and only used when it's not possible to figure out which instruction should be used, eg. inc [rax], is that byte/word/dword/qword? if it's mov rax,[mem] we already know the size of the memory operand.
See https://github.com/icedland/iced/blob/master/src/rust/iced-x86/README.md#assemble-instructions