pub struct Instruction {
pub mnemonic: Mnemonic,
pub operand1: Option<Operand>,
pub operand2: Option<Operand>,
pub operand3: Option<Operand>,
pub operand4: Option<Operand>,
pub lock: bool,
pub rounding_mode: Option<RoundingMode>,
pub merge_mode: Option<MergeMode>,
pub sae: bool,
pub mask: Option<MaskReg>,
pub broadcast: Option<BroadcastMode>,
}
Fields§
§mnemonic: Mnemonic
§operand1: Option<Operand>
§operand2: Option<Operand>
§operand3: Option<Operand>
§operand4: Option<Operand>
§lock: bool
§rounding_mode: Option<RoundingMode>
§merge_mode: Option<MergeMode>
§sae: bool
§mask: Option<MaskReg>
§broadcast: Option<BroadcastMode>
Implementations§
Source§impl Instruction
impl Instruction
Sourcepub fn new0(mnemonic: Mnemonic) -> Instruction
pub fn new0(mnemonic: Mnemonic) -> Instruction
Examples found in repository?
examples/encode_function.rs (line 15)
6fn main() {
7 let buffer = Cursor::new(Vec::new());
8 let mut writer = InstructionWriter::new(buffer, Mode::Protected);
9
10 let instructions = &[
11 Instruction::new1(Mnemonic::PUSH, Operand::Direct(Reg::EBP)),
12 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBP), Operand::Direct(Reg::ESP)),
13 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EAX), Operand::IndirectDisplaced(Reg::EBP, 12, Some(OperandSize::Dword), None)),
14 Instruction::new2(Mnemonic::ADD, Operand::Direct(Reg::EAX), Operand::IndirectDisplaced(Reg::EBP, 8, Some(OperandSize::Dword), None)),
15 Instruction::new0(Mnemonic::LEAVE),
16 Instruction::new0(Mnemonic::RET),
17 ];
18
19 let mut bytes_written = 0;
20
21 for instr in instructions {
22 bytes_written += writer.write(instr).unwrap();
23 }
24
25 print!("Output ({} bytes): ", bytes_written);
26 for byte in writer.get_inner_writer_ref().get_ref().iter() {
27 print!("{:02X} ", byte);
28 }
29 println!("");
30}
Sourcepub fn new1(mnemonic: Mnemonic, operand1: Operand) -> Instruction
pub fn new1(mnemonic: Mnemonic, operand1: Operand) -> Instruction
Examples found in repository?
examples/encode_function.rs (line 11)
6fn main() {
7 let buffer = Cursor::new(Vec::new());
8 let mut writer = InstructionWriter::new(buffer, Mode::Protected);
9
10 let instructions = &[
11 Instruction::new1(Mnemonic::PUSH, Operand::Direct(Reg::EBP)),
12 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBP), Operand::Direct(Reg::ESP)),
13 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EAX), Operand::IndirectDisplaced(Reg::EBP, 12, Some(OperandSize::Dword), None)),
14 Instruction::new2(Mnemonic::ADD, Operand::Direct(Reg::EAX), Operand::IndirectDisplaced(Reg::EBP, 8, Some(OperandSize::Dword), None)),
15 Instruction::new0(Mnemonic::LEAVE),
16 Instruction::new0(Mnemonic::RET),
17 ];
18
19 let mut bytes_written = 0;
20
21 for instr in instructions {
22 bytes_written += writer.write(instr).unwrap();
23 }
24
25 print!("Output ({} bytes): ", bytes_written);
26 for byte in writer.get_inner_writer_ref().get_ref().iter() {
27 print!("{:02X} ", byte);
28 }
29 println!("");
30}
Sourcepub fn new2(
mnemonic: Mnemonic,
operand1: Operand,
operand2: Operand,
) -> Instruction
pub fn new2( mnemonic: Mnemonic, operand1: Operand, operand2: Operand, ) -> Instruction
Examples found in repository?
examples/encode_real.rs (line 15)
6fn main() {
7 let buffer = Cursor::new(Vec::new());
8 let mut writer = InstructionWriter::new(buffer, Mode::Real);
9
10 // mov ax, [bx+si]
11 // add ax, bx
12 // mov [bp+si], ax
13
14 let instructions = &[
15 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::AX), Operand::IndirectScaledIndexed(Reg::BX, Reg::SI, RegScale::One, Some(OperandSize::Word), None)), // mov ax, [bx+si]
16 Instruction::new2(Mnemonic::ADD, Operand::Direct(Reg::AX), Operand::Direct(Reg::BX)), // add ax, bx
17 Instruction::new2(Mnemonic::MOV, Operand::IndirectScaledIndexed(Reg::BX, Reg::SI, RegScale::One, Some(OperandSize::Word), None), Operand::Direct(Reg::AX)), // mov [bp+si]
18 ];
19
20 let mut bytes_written = 0;
21
22 for instr in instructions {
23 bytes_written += writer.write(instr).unwrap();
24 }
25
26 print!("Output ({} bytes): ", bytes_written);
27 for byte in writer.get_inner_writer_ref().get_ref().iter() {
28 print!("{:02X} ", byte);
29 }
30 println!("");
31}
More examples
examples/encode_function.rs (line 12)
6fn main() {
7 let buffer = Cursor::new(Vec::new());
8 let mut writer = InstructionWriter::new(buffer, Mode::Protected);
9
10 let instructions = &[
11 Instruction::new1(Mnemonic::PUSH, Operand::Direct(Reg::EBP)),
12 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBP), Operand::Direct(Reg::ESP)),
13 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EAX), Operand::IndirectDisplaced(Reg::EBP, 12, Some(OperandSize::Dword), None)),
14 Instruction::new2(Mnemonic::ADD, Operand::Direct(Reg::EAX), Operand::IndirectDisplaced(Reg::EBP, 8, Some(OperandSize::Dword), None)),
15 Instruction::new0(Mnemonic::LEAVE),
16 Instruction::new0(Mnemonic::RET),
17 ];
18
19 let mut bytes_written = 0;
20
21 for instr in instructions {
22 bytes_written += writer.write(instr).unwrap();
23 }
24
25 print!("Output ({} bytes): ", bytes_written);
26 for byte in writer.get_inner_writer_ref().get_ref().iter() {
27 print!("{:02X} ", byte);
28 }
29 println!("");
30}
examples/encode_long.rs (line 16)
6fn main() {
7 let buffer = Cursor::new(Vec::new());
8 let mut writer = InstructionWriter::new(buffer, Mode::Long);
9
10 // mov rax, qword ptr [rip+100]
11 // mov rbx, 500
12 // sub rax, rbx
13 // mov [rcx+rdx*4], rax
14
15 let instructions = &[
16 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::RAX), Operand::IndirectDisplaced(Reg::RIP, 100, Some(OperandSize::Qword), None)),
17 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::RBX), Operand::Literal32(500)),
18 Instruction::new2(Mnemonic::SUB, Operand::Direct(Reg::RAX), Operand::Direct(Reg::RBX)),
19 Instruction::new2(Mnemonic::MOV, Operand::IndirectScaledIndexed(Reg::RCX, Reg::RDX, RegScale::Four, Some(OperandSize::Qword), None), Operand::Direct(Reg::RAX)),
20 ];
21
22 let mut bytes_written = 0;
23
24 for instr in instructions {
25 bytes_written += writer.write(instr).unwrap();
26 }
27
28 print!("Output ({} bytes): ", bytes_written);
29 for byte in writer.get_inner_writer_ref().get_ref().iter() {
30 print!("{:02X} ", byte);
31 }
32 println!("");
33}
examples/addressing_modes.rs (line 11)
6fn main() {
7 let buffer = Cursor::new(Vec::new());
8 let mut writer = InstructionWriter::new(buffer, Mode::Protected);
9
10 let instructions = &[
11 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBX), Operand::Indirect(Reg::EAX, Some(OperandSize::Dword), None)), // mov ebx, dword ptr [eax]
12 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBX), Operand::IndirectDisplaced(Reg::EAX, 5, Some(OperandSize::Dword), None)), // mov ebx, dword ptr [eax+5]
13 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBX), Operand::IndirectScaledIndexed(Reg::EAX, Reg::ECX, RegScale::Two, Some(OperandSize::Dword), None)), // mov ebx, dword ptr [eax+ecx*2]
14 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBX), Operand::IndirectScaledIndexedDisplaced(Reg::EAX, Reg::ECX, RegScale::Two, 5, Some(OperandSize::Dword), None)), // mov ebx, dword ptr [eax+ecx*2+5]
15 Instruction::new2(Mnemonic::MOV, Operand::Direct(Reg::EBX), Operand::Memory(5, Some(OperandSize::Dword), None)), // mov ebx, dword ptr ds:5
16 ];
17
18 let mut bytes_written = 0;
19
20 for instr in instructions {
21 bytes_written += writer.write(instr).unwrap();
22 }
23
24 print!("Output ({} bytes): ", bytes_written);
25 for byte in writer.get_inner_writer_ref().get_ref().iter() {
26 print!("{:02X} ", byte);
27 }
28 println!("");
29}
pub fn new3( mnemonic: Mnemonic, operand1: Operand, operand2: Operand, operand3: Operand, ) -> Instruction
pub fn new4( mnemonic: Mnemonic, operand1: Operand, operand2: Operand, operand3: Operand, operand4: Operand, ) -> Instruction
pub fn operands(&self) -> [&Option<Operand>; 4]
pub fn encode<W>(
&self,
writer: &mut W,
mode: Mode,
) -> Result<usize, InstructionEncodingError>where
W: Write,
Trait Implementations§
Source§impl Clone for Instruction
impl Clone for Instruction
Source§fn clone(&self) -> Instruction
fn clone(&self) -> Instruction
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Instruction
impl Debug for Instruction
Source§impl Default for Instruction
impl Default for Instruction
Source§fn default() -> Instruction
fn default() -> Instruction
Returns the “default value” for a type. Read more
Source§impl PartialEq for Instruction
impl PartialEq for Instruction
impl Copy for Instruction
impl Eq for Instruction
Auto Trait Implementations§
impl Freeze for Instruction
impl RefUnwindSafe for Instruction
impl Send for Instruction
impl Sync for Instruction
impl Unpin for Instruction
impl UnwindSafe for Instruction
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