From bd742af50fb3a33fef1fa75a0cffb94511e5d959 Mon Sep 17 00:00:00 2001
From: Jason Hiser <jdhiser@gmail.com>
Date: Fri, 8 Feb 2019 15:28:08 -0500
Subject: [PATCH] sdk factorying

---
 push64_relocs.cpp | 24 +++++++++---------------
 push64_relocs.h   | 27 ++++++++-------------------
 2 files changed, 17 insertions(+), 34 deletions(-)

diff --git a/push64_relocs.cpp b/push64_relocs.cpp
index 0b20a613d..3b8e9d6c7 100644
--- a/push64_relocs.cpp
+++ b/push64_relocs.cpp
@@ -29,32 +29,27 @@
  **************************************************************************/
 
 
-#include <zipr_sdk.h>
-#include <irdb-core>
 #include <string>
 #include <algorithm>
 #include "push64_relocs.h"
 
 using namespace IRDB_SDK;
-using namespace std;
 using namespace Zipr_SDK;
-using namespace ELFIO;
+using namespace std;
 
 #define ALLOF(a) begin(a), end(a)
 
 Push64Relocs_t::Push64Relocs_t(MemorySpace_t *p_ms,
-	elfio *p_elfio,
 	FileIR_t *p_firp,
 	InstructionLocationMap_t *p_fil) :
 		m_memory_space(*p_ms), 
-		m_elfio(*p_elfio),
 		m_firp(*p_firp),
 		final_insn_locations(*p_fil),
 		m_verbose("verbose")
 {
 }
-ZiprOptionsNamespace_t *Push64Relocs_t::RegisterOptions(ZiprOptionsNamespace_t *global) {
-	global->AddOption(&m_verbose);
+ZiprOptionsNamespace_t *Push64Relocs_t::registerOptions(ZiprOptionsNamespace_t *global) {
+	global->addOption(&m_verbose);
 	return NULL;
 }
 
@@ -298,9 +293,9 @@ void Push64Relocs_t::UpdatePush64Adds()
 			if (change_to_add)
 			{
 				char add = (char)0x04;
-				m_memory_space.PlopBytes(add_addr+rex_skip+1, (const char*)&add, 1);
+				m_memory_space.plopBytes(add_addr+rex_skip+1, (const char*)&add, 1);
 			}
-			m_memory_space.PlopBytes(add_addr+rex_skip+3, (const char*)&relocated_value, 4);
+			m_memory_space.plopBytes(add_addr+rex_skip+3, (const char*)&relocated_value, 4);
 		}
 	}
 }
@@ -309,9 +304,8 @@ extern "C"
 Zipr_SDK::ZiprPluginInterface_t* GetPluginInterface(
 	Zipr_SDK::Zipr_t* zipr_object)
 {
-	Zipr_SDK::MemorySpace_t *p_ms=zipr_object->GetMemorySpace(); 
-	ELFIO::elfio *p_elfio=zipr_object->getELFIO(); 
-	IRDB_SDK::FileIR_t *p_firp=zipr_object->getFileIR();
-	Zipr_SDK::InstructionLocationMap_t *p_fil=zipr_object->GetLocationMap(); 
-	return new Push64Relocs_t(p_ms,p_elfio,p_firp,p_fil);
+	auto *p_ms=zipr_object->getMemorySpace(); 
+	auto *p_firp=zipr_object->getFileIR();
+	auto *p_fil=zipr_object->getLocationMap(); 
+	return new Push64Relocs_t(p_ms,p_firp,p_fil);
 }
diff --git a/push64_relocs.h b/push64_relocs.h
index 636f08f53..7a6506095 100644
--- a/push64_relocs.h
+++ b/push64_relocs.h
@@ -32,20 +32,18 @@
 #define push_relocs_h
 
 #include <irdb-core>
+#include <zipr-sdk>
 
 class Push64Relocs_t : public Zipr_SDK::ZiprPluginInterface_t
 {
 	public:
 		Push64Relocs_t(Zipr_SDK::MemorySpace_t *p_ms,
-			ELFIO::elfio *p_elfio,
 			IRDB_SDK::FileIR_t *p_firp,
 			Zipr_SDK::InstructionLocationMap_t *p_fil);
-		virtual void PinningBegin()
-		{
-		}
-		virtual void PinningEnd()
+		virtual void doPinningEnd() override
 		{ 
-			if(m_elfio.get_type()==ET_EXEC)
+			// if(m_elfio.get_type()==ET_EXEC)
+			if(m_firp.getArchitecture()->getFileType()==IRDB_SDK::adftELFEXE)
 			{
 				std::cout<<"Push64_reloc: elide PinningEnd as type==ET_EXEC"<<std::endl;
 				return;
@@ -53,18 +51,10 @@ class Push64Relocs_t : public Zipr_SDK::ZiprPluginInterface_t
 			std::cout<<"Push64Plugin: Ending  pinning, applying push64 relocs."<<std::endl;
 			HandlePush64Relocs(); 
 		}
-		virtual void DollopBegin()
-		{
-		}
-		virtual void DollopEnd()
-		{
-		}
-		virtual void CallbackLinkingBegin()
-		{
-		}
-		virtual void CallbackLinkingEnd()
+		virtual void doCallbackLinkingEnd() override
 		{
-			if(m_elfio.get_type()==ET_EXEC)
+			// if(m_elfio.get_type()==ET_EXEC)
+			if(m_firp.getArchitecture()->getFileType()==IRDB_SDK::adftELFEXE)
 			{
 				std::cout<<"Push64_reloc: elide CallbackLinkingEnd as type==ET_EXEC"<<std::endl;
 				return;
@@ -73,7 +63,7 @@ class Push64Relocs_t : public Zipr_SDK::ZiprPluginInterface_t
 			UpdatePush64Adds(); 
 		}
 
-		virtual Zipr_SDK::ZiprOptionsNamespace_t *RegisterOptions(Zipr_SDK::ZiprOptionsNamespace_t *);
+		virtual Zipr_SDK::ZiprOptionsNamespace_t *registerOptions(Zipr_SDK::ZiprOptionsNamespace_t *) override;
 	private:
 		// main workhorses
 		void HandlePush64Relocs();
@@ -123,7 +113,6 @@ class Push64Relocs_t : public Zipr_SDK::ZiprPluginInterface_t
 
 		// references to input
 		Zipr_SDK::MemorySpace_t &m_memory_space;	
-		ELFIO::elfio&  m_elfio;
 		IRDB_SDK::FileIR_t& m_firp;
 		Zipr_SDK::InstructionLocationMap_t &final_insn_locations;
 
-- 
GitLab