aboutsummaryrefslogtreecommitdiff
path: root/src/long_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/long_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/long_mode')
-rw-r--r--src/long_mode/mod.rs71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/long_mode/mod.rs b/src/long_mode/mod.rs
index a89d673..ba6f410 100644
--- a/src/long_mode/mod.rs
+++ b/src/long_mode/mod.rs
@@ -4197,6 +4197,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> {