From b52dd7a453e041ca79f0c440dcd657e0b9225828 Mon Sep 17 00:00:00 2001 From: iximeow Date: Sun, 5 Mar 2023 08:36:41 -0800 Subject: add `Opcode::is_jcc`, `Opcode::is_setcc`, and `Opcode::is_cmovcc` helpers this request/suggestion comes from [github](https://github.com/iximeow/yaxpeax-x86/issues/29)! thank you! --- src/real_mode/mod.rs | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) (limited to 'src/real_mode') diff --git a/src/real_mode/mod.rs b/src/real_mode/mod.rs index 1f6614e..676f9b6 100644 --- a/src/real_mode/mod.rs +++ b/src/real_mode/mod.rs @@ -4149,6 +4149,77 @@ impl AnnotatingDecoder for InstDecoder { } impl Opcode { + /// check if the instruction is one of x86's sixteen conditional jump instructions. use this + /// rather than `opcode.to_string().starts_with("j") && opcode != Opcode::JMP`, thank you. + pub fn is_jcc(&self) -> bool { + match self { + Opcode::JO | + Opcode::JNO | + Opcode::JB | + Opcode::JNB | + Opcode::JZ | + Opcode::JNZ | + Opcode::JA | + Opcode::JNA | + Opcode::JS | + Opcode::JNS | + Opcode::JP | + Opcode::JNP | + Opcode::JL | + Opcode::JGE | + Opcode::JG | + Opcode::JLE => true, + _ => false, + } + } + + /// check if the instruction is one of x86's sixteen conditional move instructions. + pub fn is_cmovcc(&self) -> bool { + match self { + Opcode::CMOVO | + Opcode::CMOVNO | + Opcode::CMOVB | + Opcode::CMOVNB | + Opcode::CMOVZ | + Opcode::CMOVNZ | + Opcode::CMOVA | + Opcode::CMOVNA | + Opcode::CMOVS | + Opcode::CMOVNS | + Opcode::CMOVP | + Opcode::CMOVNP | + Opcode::CMOVL | + Opcode::CMOVGE | + Opcode::CMOVG | + Opcode::CMOVLE => true, + _ => false, + } + } + + /// check if the instruction is one of x86's sixteen conditional set instructions. + pub fn is_setcc(&self) -> bool { + match self { + Opcode::SETO | + Opcode::SETNO | + Opcode::SETB | + Opcode::SETAE | + Opcode::SETZ | + Opcode::SETNZ | + Opcode::SETA | + Opcode::SETBE | + Opcode::SETS | + Opcode::SETNS | + Opcode::SETP | + Opcode::SETNP | + Opcode::SETL | + Opcode::SETGE | + Opcode::SETG | + Opcode::SETLE => true, + _ => false + } + + } + /// get the [`ConditionCode`] for this instruction, if it is in fact conditional. x86's /// conditional instructions are `Jcc`, `CMOVcc`, andd `SETcc`. pub fn condition(&self) -> Option { -- cgit v1.1