Struct xed::XedState

source ·
pub struct XedState { /* private fields */ }

Implementations§

source§

impl XedState

source

pub fn new( machine_mode: XedMachineMode, stack_address_width: XedAddressWidth ) -> Self

Examples found in repository?
examples/basic.rs (lines 51-54)
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
fn encode_test() {
    let xed_state = XedState::new(
        XedMachineMode::XED_MACHINE_MODE_LONG_64,
        XedAddressWidth::XED_ADDRESS_WIDTH_64b,
    );
    let insn = Insn {
        iclass: XedInsnIClass::XED_ICLASS_ADD,
        effective_operand_width_in_bits: 64,
        operands: [
            Operand::Reg(Reg::XED_REG_RAX),
            Operand::Mem(MemOperand {
                base: None,
                width_in_bits: 64,
                seg: None,
                sib: None,
                displacement: Some(MemOperandDisplacement {
                    displacement: -5,
                    width_in_bits: 32,
                }),
                address_width_in_bits: 64,
            }),
        ]
        .into_iter()
        .collect(),
    };
    let result = xed_state.encode(&insn).unwrap();
    let output_file_path = "/tmp/.xed_enc_test";
    std::fs::write(output_file_path, result.as_slice()).unwrap();
    let exit_code = Command::new("objdump")
        .args("-Mintel -D -b binary -Mx86-64 -mi386:x86-64".split(' '))
        .arg(output_file_path)
        .spawn()
        .unwrap()
        .wait()
        .unwrap();
    assert!(exit_code.success());
    let decoded = xed_state.decode(&result).unwrap();
    assert_eq!(decoded.insn, insn);
}

fn decode_test() {
    let stdin = std::io::stdin();
    let mut input = String::new();
    loop {
        input.clear();
        stdin.read_line(&mut input).unwrap();

        dump_operands(&input);
    }
}

fn dump_operands(assembly_line: &str) {
    let bytes = nasm_assemble(&format!("bits 64\n{}", assembly_line));
    let xed_state = XedState::new(
        XedMachineMode::XED_MACHINE_MODE_LONG_64,
        XedAddressWidth::XED_ADDRESS_WIDTH_64b,
    );
    let decoded_insn = xed_state.decode(&bytes).unwrap();
    println!("{:#?}", decoded_insn);
    let encoded = xed_state.encode(&decoded_insn.insn).unwrap();
    assert_eq!(encoded.as_slice(), bytes.as_slice());
}
source

pub fn address_width(&self) -> XedAddressWidth

source

pub fn stack_address_width(&self) -> XedAddressWidth

source

pub fn machine_mode(&self) -> XedMachineMode

source

pub fn decode(&self, buf: &[u8]) -> Result<DecodedInsn>

Examples found in repository?
examples/basic.rs (line 86)
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
fn encode_test() {
    let xed_state = XedState::new(
        XedMachineMode::XED_MACHINE_MODE_LONG_64,
        XedAddressWidth::XED_ADDRESS_WIDTH_64b,
    );
    let insn = Insn {
        iclass: XedInsnIClass::XED_ICLASS_ADD,
        effective_operand_width_in_bits: 64,
        operands: [
            Operand::Reg(Reg::XED_REG_RAX),
            Operand::Mem(MemOperand {
                base: None,
                width_in_bits: 64,
                seg: None,
                sib: None,
                displacement: Some(MemOperandDisplacement {
                    displacement: -5,
                    width_in_bits: 32,
                }),
                address_width_in_bits: 64,
            }),
        ]
        .into_iter()
        .collect(),
    };
    let result = xed_state.encode(&insn).unwrap();
    let output_file_path = "/tmp/.xed_enc_test";
    std::fs::write(output_file_path, result.as_slice()).unwrap();
    let exit_code = Command::new("objdump")
        .args("-Mintel -D -b binary -Mx86-64 -mi386:x86-64".split(' '))
        .arg(output_file_path)
        .spawn()
        .unwrap()
        .wait()
        .unwrap();
    assert!(exit_code.success());
    let decoded = xed_state.decode(&result).unwrap();
    assert_eq!(decoded.insn, insn);
}

fn decode_test() {
    let stdin = std::io::stdin();
    let mut input = String::new();
    loop {
        input.clear();
        stdin.read_line(&mut input).unwrap();

        dump_operands(&input);
    }
}

fn dump_operands(assembly_line: &str) {
    let bytes = nasm_assemble(&format!("bits 64\n{}", assembly_line));
    let xed_state = XedState::new(
        XedMachineMode::XED_MACHINE_MODE_LONG_64,
        XedAddressWidth::XED_ADDRESS_WIDTH_64b,
    );
    let decoded_insn = xed_state.decode(&bytes).unwrap();
    println!("{:#?}", decoded_insn);
    let encoded = xed_state.encode(&decoded_insn.insn).unwrap();
    assert_eq!(encoded.as_slice(), bytes.as_slice());
}
source

pub fn decode_iter<'a>(&self, buf: &'a [u8]) -> DecodeIter<'a>

source

pub fn encode(&self, insn: &Insn) -> Result<InsnBytes>

Examples found in repository?
examples/basic.rs (line 75)
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
fn encode_test() {
    let xed_state = XedState::new(
        XedMachineMode::XED_MACHINE_MODE_LONG_64,
        XedAddressWidth::XED_ADDRESS_WIDTH_64b,
    );
    let insn = Insn {
        iclass: XedInsnIClass::XED_ICLASS_ADD,
        effective_operand_width_in_bits: 64,
        operands: [
            Operand::Reg(Reg::XED_REG_RAX),
            Operand::Mem(MemOperand {
                base: None,
                width_in_bits: 64,
                seg: None,
                sib: None,
                displacement: Some(MemOperandDisplacement {
                    displacement: -5,
                    width_in_bits: 32,
                }),
                address_width_in_bits: 64,
            }),
        ]
        .into_iter()
        .collect(),
    };
    let result = xed_state.encode(&insn).unwrap();
    let output_file_path = "/tmp/.xed_enc_test";
    std::fs::write(output_file_path, result.as_slice()).unwrap();
    let exit_code = Command::new("objdump")
        .args("-Mintel -D -b binary -Mx86-64 -mi386:x86-64".split(' '))
        .arg(output_file_path)
        .spawn()
        .unwrap()
        .wait()
        .unwrap();
    assert!(exit_code.success());
    let decoded = xed_state.decode(&result).unwrap();
    assert_eq!(decoded.insn, insn);
}

fn decode_test() {
    let stdin = std::io::stdin();
    let mut input = String::new();
    loop {
        input.clear();
        stdin.read_line(&mut input).unwrap();

        dump_operands(&input);
    }
}

fn dump_operands(assembly_line: &str) {
    let bytes = nasm_assemble(&format!("bits 64\n{}", assembly_line));
    let xed_state = XedState::new(
        XedMachineMode::XED_MACHINE_MODE_LONG_64,
        XedAddressWidth::XED_ADDRESS_WIDTH_64b,
    );
    let decoded_insn = xed_state.decode(&bytes).unwrap();
    println!("{:#?}", decoded_insn);
    let encoded = xed_state.encode(&decoded_insn.insn).unwrap();
    assert_eq!(encoded.as_slice(), bytes.as_slice());
}
source

pub fn reg_largest_enclosing(&self, reg: Reg) -> Reg

source

pub fn reg_start_bit_index_in_largest_enclosing(&self, reg: Reg) -> u32

source

pub fn reg_width_in_bits(&self, reg: Reg) -> u32

source

pub fn disassamble( &self, insn: &Insn, insn_runtime_address: u64 ) -> Result<DisassembledInsn>

Trait Implementations§

source§

impl Clone for XedState

source§

fn clone(&self) -> XedState

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.