pub struct XedState { /* private fields */ }Implementations§
source§impl XedState
impl XedState
sourcepub fn new(
machine_mode: XedMachineMode,
stack_address_width: XedAddressWidth
) -> Self
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());
}pub fn address_width(&self) -> XedAddressWidth
pub fn stack_address_width(&self) -> XedAddressWidth
pub fn machine_mode(&self) -> XedMachineMode
sourcepub fn decode(&self, buf: &[u8]) -> Result<DecodedInsn>
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());
}pub fn decode_iter<'a>(&self, buf: &'a [u8]) -> DecodeIter<'a> ⓘ
sourcepub fn encode(&self, insn: &Insn) -> Result<InsnBytes>
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());
}pub fn reg_largest_enclosing(&self, reg: Reg) -> Reg
pub fn reg_start_bit_index_in_largest_enclosing(&self, reg: Reg) -> u32
pub fn reg_width_in_bits(&self, reg: Reg) -> u32
pub fn disassamble( &self, insn: &Insn, insn_runtime_address: u64 ) -> Result<DisassembledInsn>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for XedState
impl RefUnwindSafe for XedState
impl Send for XedState
impl Sync for XedState
impl Unpin for XedState
impl UnwindSafe for XedState
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more