Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/rust/iced-x86/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44668,6 +44668,19 @@ impl Code {
(crate::info::info_table::TABLE[self as usize].1 & InfoFlags2::SAVE_RESTORE) != 0
}

/// Checks if it's a return instruction
#[must_use]
#[inline]
pub const fn is_return(self) -> bool {
return match self{
Code::Retnw | Code::Retnw_imm16 | Code::Retnd | Code::Retnd_imm16 | Code::Retnq | Code::Retnq_imm16 |
Code::Retfw | Code::Retfw_imm16 | Code::Retfd | Code::Retfd_imm16 | Code::Retfq | Code::Retfq_imm16 |
Code::Iretd | Code::Iretq | Code::Iretw | Code::Sysretd | Code::Sysretq | Code::Uiret |
Code::Sysexitd | Code::Sysexitq => true,
_ => false
}
}

/// Checks if it's a `Jcc NEAR` instruction
#[must_use]
#[inline]
Expand Down
7 changes: 7 additions & 0 deletions src/rust/iced-x86/src/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3464,6 +3464,13 @@ impl Instruction {
crate::info::rflags_table::FLAGS_MODIFIED[self.rflags_info() as usize] as u32
}

/// Checks if it's a return instruction
#[must_use]
#[inline]
pub const fn is_return(&self) -> bool {
self.code().is_return()
}

/// Checks if it's a `Jcc SHORT` or `Jcc NEAR` instruction
#[must_use]
#[inline]
Expand Down
18 changes: 18 additions & 0 deletions src/rust/iced-x86/src/test/instr_misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,3 +698,21 @@ fn verify_get_set_immediate() {
fn verify_instruction_size() {
const _: () = assert!(mem::size_of::<Instruction>() == INSTRUCTION_TOTAL_SIZE);
}

#[test]
fn checks_if_return_instruction(){
let machine_code: [u8; 9] = [0xc2, 0x90, 0x90, 0xc3, 0xca, 090, 0x90, 0xcb, 0xcf];
let bad: [u8; 5] = [0xcc, 0x90, 0x00, 0x00, 0xd7//xlatb];
let mut formatter: NasmFormatter = NasmFormatter::new();
let mut output: String = String::new();
let mut decoder: Decoder<'_> = Decoder::with_ip(32, &machine_code, 0x0000_0004_0000_0000, DecoderOptions::NONE);

for inst in &mut decoder{
assert_eq!(true, inst.is_return()); //Function added
};

decoder = Decoder::with_ip(32, &bad, 0x0000_0004_0000_0000, DecoderOptions::NONE);
for inst in &mut decoder{
assert_eq!(false, inst.is_return()); //Function added
};
}