Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect encoding of long memory operands. #4

Open
purpleposeidon opened this issue Sep 24, 2018 · 0 comments
Open

Incorrect encoding of long memory operands. #4

purpleposeidon opened this issue Sep 24, 2018 · 0 comments

Comments

@purpleposeidon
Copy link

This fails:

extern crate x86asm;

fn main() {
    use x86asm::*;
    use std::io::{Cursor, Write};
    let mut out = Vec::new();
    let i = Instruction::new2(Mnemonic::MOV, Operand::Memory(0xB0_B1_B2_B3_B4_B5, Some(OperandSize::Qword), None), Operand::Direct(Reg::RAX));
    {
        let mut asm = InstructionWriter::new(&mut out, Mode::Long);
        asm.write(&i).unwrap();
    }
    for x in &out {
        print!("{:02X} ", x);
    }
    println!();
    println!("Expect:");
    println!("{:#?}", i);
    {
        use x86asm::*;
        let mut asm = InstructionReader::new(Cursor::new(&out), Mode::Long);
        let got = asm.read().unwrap();
        println!("Actual:");
        println!("{:#?}", got);
        assert_eq!(i, got);
        assert_eq!(asm.read(), Err(InstructionDecodingError::EndOfStream));
    }
}

Output:

48 89 04 05 B5 B4 B3 B2
Instruction {
    mnemonic: MOV,
    operand1: Some(
        Memory(
            194277253821621,
            Some(
                Qword
            ),
            None
        )
    ),
    operand2: Some(
        Direct(
            RAX
        )
    ),
    operand3: None,
    operand4: None,
    lock: false,
    rounding_mode: None,
    merge_mode: None,
    sae: false,
    mask: None,
    broadcast: None
}
Actual:
Instruction {
    mnemonic: MOV,
    operand1: Some(
        IndirectScaledDisplaced(
            RAX,
            One,
            2998121653,
            Some(
                Qword
            ),
            None
        )
    ),
    operand2: Some(
        Direct(
            RAX
        )
    ),
    operand3: None,
    operand4: None,
    lock: false,
    rounding_mode: None,
    merge_mode: None,
    sae: false,
    mask: None,
    broadcast: None
}

(Well, using my fork https://github.com/purpleposeidon/rust-x86asm, ahem.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant