From 89dfbb93547547009f4fdcbec5279b9b1f2a09c8 Mon Sep 17 00:00:00 2001
From: Jason Hiser <jdhiser@gmail.com>
Date: Fri, 25 Oct 2019 14:18:38 -0400
Subject: [PATCH] mips?!

---
 SConscript       |  1 +
 unpin.cpp        |  1 +
 unpin.h          | 19 ++++++++++++
 unpin_mips32.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 97 insertions(+)
 create mode 100644 unpin_mips32.cpp

diff --git a/SConscript b/SConscript
index ded65c9..d36c375 100644
--- a/SConscript
+++ b/SConscript
@@ -25,6 +25,7 @@ files=  '''
 	unpin.cpp
 	unpin_aarch64.cpp
 	unpin_arm32.cpp
+	unpin_mips32.cpp
 	unpin_x86.cpp
 	'''
 
diff --git a/unpin.cpp b/unpin.cpp
index 4e958e3..3f30cb5 100644
--- a/unpin.cpp
+++ b/unpin.cpp
@@ -320,5 +320,6 @@ Zipr_SDK::ZiprPluginInterface_t* GetPluginInterface(
 		mt==admtI386    ? (Unpin_t*)new UnpinX86_t    (zipr_object) :
 		mt==admtAarch64 ? (Unpin_t*)new UnpinAarch64_t(zipr_object) :
 		mt==admtArm32   ? (Unpin_t*)new UnpinArm32_t  (zipr_object) :
+		mt==admtMips32  ? (Unpin_t*)new UnpinMips32_t (zipr_object) :
 		throw invalid_argument("Cannot determine machine type");
 }
diff --git a/unpin.h b/unpin.h
index 3ee0bf5..9659800 100644
--- a/unpin.h
+++ b/unpin.h
@@ -168,5 +168,24 @@ class UnpinArm32_t : public Unpin_t
 		void HandleCallbackReloc(IRDB_SDK::Instruction_t* from_insn,IRDB_SDK::Relocation_t* reloc) override;
 
 
+};
+
+class UnpinMips32_t : public Unpin_t
+{
+	public:
+		UnpinMips32_t( Zipr_SDK::Zipr_t* zipr_object) 
+			: Unpin_t(zipr_object)
+
+		{ 
+		}
+	protected:
+		// designed for arch-specific override.
+		void HandleRetAddrReloc (IRDB_SDK::Instruction_t* from_insn, IRDB_SDK::Relocation_t* reloc) override;
+		void HandlePcrelReloc   (IRDB_SDK::Instruction_t* from_insn, IRDB_SDK::Relocation_t* reloc) override;
+		void HandleAbsptrReloc  (IRDB_SDK::Instruction_t* from_insn, IRDB_SDK::Relocation_t* reloc) override;
+		void HandleImmedptrReloc(IRDB_SDK::Instruction_t* from_insn, IRDB_SDK::Relocation_t* reloc) override;
+		void HandleCallbackReloc(IRDB_SDK::Instruction_t* from_insn, IRDB_SDK::Relocation_t* reloc) override;
+
+
 };
 #endif
diff --git a/unpin_mips32.cpp b/unpin_mips32.cpp
new file mode 100644
index 0000000..48c4fac
--- /dev/null
+++ b/unpin_mips32.cpp
@@ -0,0 +1,76 @@
+/***************************************************************************
+ * Copyright (c)  2014  Zephyr Software LLC. All rights reserved.
+ *
+ * This software is furnished under a license and/or other restrictive
+ * terms and may be used and copied only in accordance with such terms
+ * and the inclusion of the above copyright notice. This software or
+ * any other copies thereof may not be provided or otherwise made
+ * available to any other person without the express written consent
+ * of an authorized representative of Zephyr Software LCC. Title to,
+ * ownership of, and all rights in the software is retained by
+ * Zephyr Software LCC.
+ *
+ * Zephyr Software LLC. Proprietary Information
+ *
+ * Unless otherwise specified, the information contained in this
+ * directory, following this legend, and/or referenced herein is
+ * Zephyr Software LLC. (Zephyr) Proprietary Information.
+ *
+ * CONTACT
+ *
+ * For technical assistance, contact Zephyr Software LCC. at:
+ *
+ *
+ * Zephyr Software, LLC
+ * 2040 Tremont Rd
+ * Charlottesville, VA 22911
+ *
+ * E-mail: jwd@zephyr-software.com
+ **************************************************************************/
+
+
+#include <string>
+#include <algorithm>
+#include "unpin.h"
+#include <memory>
+#include <inttypes.h>
+#include <stdint.h>
+#include <limits.h>
+#include <irdb-util>
+
+
+using namespace IRDB_SDK;
+using namespace std;
+using namespace Zipr_SDK;
+
+static inline uint32_t rotr32 (uint32_t n, unsigned int c)
+{
+  const unsigned int mask = (CHAR_BIT*sizeof(n) - 1);
+
+  // assert ( (c<=mask) &&"rotate by type width or more");
+  c &= mask;
+  return (n>>c) | (n<<( (-c)&mask ));
+}
+
+
+#define ALLOF(a) begin(a),end(a)
+// per machine stuff
+void UnpinMips32_t::HandleRetAddrReloc(Instruction_t* from_insn, Relocation_t* reloc)
+{ assert(0); }
+
+void UnpinMips32_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* reloc)
+{ assert(0); }
+
+void UnpinMips32_t::HandleAbsptrReloc(Instruction_t* from_insn, Relocation_t* reloc)
+{ assert(0); } 
+
+
+void UnpinMips32_t::HandleImmedptrReloc(Instruction_t* from_insn, Relocation_t* reloc)
+{ assert(0); }
+
+void UnpinMips32_t::HandleCallbackReloc(Instruction_t* from_insn, Relocation_t* reloc)
+{ assert(0); }
+
+
+
+
-- 
GitLab