about summary refs log tree commit diff
path: root/src/instructionhandler.cpp
diff options
context:
space:
mode:
authorYour Name <you@example.com>2020-07-20 02:54:22 +0200
committerYour Name <you@example.com>2020-07-20 02:54:22 +0200
commitc69f053c29faa47d0600f5b147835e970d9cf654 (patch)
treed97af2f279114c72c3db81ffb489c316fb3f6dd6 /src/instructionhandler.cpp
downloadAARM64-Disassembler-c69f053c29faa47d0600f5b147835e970d9cf654.tar.gz
AARM64-Disassembler-c69f053c29faa47d0600f5b147835e970d9cf654.tar.bz2
AARM64-Disassembler-c69f053c29faa47d0600f5b147835e970d9cf654.zip
Initial Commit HEAD master
Half-added some basic AARM64 instructions such as ADD, RET, MOV, NOP...
Diffstat (limited to 'src/instructionhandler.cpp')
-rw-r--r--src/instructionhandler.cpp49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/instructionhandler.cpp b/src/instructionhandler.cpp
new file mode 100644
index 0000000..13c6ed8
--- /dev/null
+++ b/src/instructionhandler.cpp
@@ -0,0 +1,49 @@
+#include "include/instructionhandler.hpp"
+
+static bool cmpInstruction(uint8_t* bits, std::string mask)
+{
+    for(int i = 0; i < 32; i++)
+    {
+        if(bits[i] != mask.at(i) && mask.at(i) != 'x')
+            return false;
+    }
+    return true;
+}
+
+std::tuple<std::string, std::string, InstructionType> InstructionHanlder::getTpl(Instruction* instr)
+{
+    for(std::tuple<std::string, std::string, InstructionType>  tpl : array)
+    {
+        if(cmpInstruction(instr->bits, std::get<0>(tpl)))
+            return tpl;
+    }
+    return {"", "NULL", InstructionType::NUL};
+}
+
+InstructionType InstructionHanlder::getInstruction(Instruction *instr)
+{
+    return std::get<2>(getTpl(instr));
+}
+
+std::string InstructionHanlder::getInstructionString(Instruction *instr)
+{
+    std::string res;
+    res.append(std::get<1>(getTpl(instr)));
+
+    return res;
+}
+
+std::tuple<std::string, std::string, InstructionType> InstructionHanlder::array[6] =
+{
+  { "10010001xxxxxxxxxxxxxxxxxxxxxxxx", "ADD", InstructionType::ADD },
+  { "10001011xx0xxxxxxxxxxxxxxxxxxxxx", "ADD", InstructionType::ADD_SHIFTED_REG },
+  { "10101010000xxxxx00000011111xxxxx", "MOV", InstructionType::MOV},
+  { "110100101xxxxxxxxxxxxxxxxxxxxxxx", "MOV", InstructionType::MOVZ},
+  { "1101011001011111000000xxxxx00000", "RET", InstructionType::RET},
+  { "11010101000000110010000000011111", "NOP", InstructionType::NOP}
+};
+
+/* MAYBE MAKE SUBCLASSES oF INSTR TYPES, I THINK THERE ARE 4
+ *
+ *
+ * THAT WAY WE HAVE ACCESS TO REGS AND SHIT*/