aboutsummaryrefslogtreecommitdiff
path: root/src/real_mode
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2023-03-05 08:36:41 -0800
committeriximeow <me@iximeow.net>2023-03-05 08:36:41 -0800
commitb52dd7a453e041ca79f0c440dcd657e0b9225828 (patch)
tree785631b2c58e2dad4bf3f6a11ab55ee28e109bd4 /src/real_mode
parent72f8f6677719a8ad7c8e61e4d629f47deef746cc (diff)
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!
Diffstat (limited to 'src/real_mode')
-rw-r--r--src/real_mode/mod.rs71
1 files changed, 71 insertions, 0 deletions
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<Arch> 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<ConditionCode> {