From 356757cf051c251f61d55bfc59bc5255b59f5d4a Mon Sep 17 00:00:00 2001 From: Jason Hiser <jdhiser@gmail.com> Date: Thu, 14 Feb 2019 10:01:58 -0500 Subject: [PATCH] refactored to deal with options better --- push64_relocs.cpp | 35 ++++++++++++++--------------------- push64_relocs.h | 9 ++++----- 2 files changed, 18 insertions(+), 26 deletions(-) diff --git a/push64_relocs.cpp b/push64_relocs.cpp index 653b1a66f..532ee7689 100644 --- a/push64_relocs.cpp +++ b/push64_relocs.cpp @@ -39,18 +39,14 @@ using namespace std; #define ALLOF(a) begin(a), end(a) -Push64Relocs_t::Push64Relocs_t(MemorySpace_t *p_ms, - FileIR_t *p_firp, - InstructionLocationMap_t *p_fil) : - m_memory_space(*p_ms), - m_firp(*p_firp), - final_insn_locations(*p_fil), - m_verbose("verbose") +Push64Relocs_t::Push64Relocs_t(Zipr_SDK::Zipr_t* zipr_object) + : + m_memory_space (*zipr_object->getMemorySpace()), + m_firp (*zipr_object->getFileIR()), + final_insn_locations(*zipr_object->getLocationMap()) { -} -ZiprOptionsNamespace_t *Push64Relocs_t::registerOptions(ZiprOptionsNamespace_t *global) { - global->addOption(&m_verbose); - return NULL; + auto global= zipr_object->getOptionsManager()->getNamespace("global"); + m_verbose = global->getBooleanOption("verbose"); } bool Push64Relocs_t::IsRelocationWithType(Relocation_t *reloc,std::string type) @@ -99,7 +95,7 @@ void Push64Relocs_t::HandlePush64Relocation(Instruction_t *insn, Relocation_t *r */ push_addr = *((VirtualOffset_t*)(&push_data_bits[1])); - if (m_verbose) + if (*m_verbose) cout << "push_addr: 0x" << std::hex << push_addr << endl; assert(push_addr != 0); @@ -149,7 +145,7 @@ void Push64Relocs_t::HandlePush64Relocation(Instruction_t *insn, Relocation_t *r */ auto add_reloc=m_firp.addNewRelocation(add_insn,push_addr,"add64"); - if (m_verbose) + if (*m_verbose) cout << "Adding an add/sub with reloc offset 0x" << std::hex << add_reloc->getOffset() << endl; @@ -173,7 +169,7 @@ void Push64Relocs_t::HandlePush64Relocs() // caution, side effect in if statement. if (reloc = FindPushRelocation(insn)) { - if (m_verbose) + if (*m_verbose) cout << "Found a Push relocation:" << insn->getDisassembly()<<endl; HandlePush64Relocation(insn,reloc); push64_relocations_count++; @@ -181,7 +177,7 @@ void Push64Relocs_t::HandlePush64Relocs() // caution, side effect in if statement. else if (reloc = FindPcrelRelocation(insn)) { - if (m_verbose) + if (*m_verbose) cout << "Found a pcrel relocation." << endl; plopped_relocs.insert(insn); pcrel_relocations_count++; @@ -199,7 +195,7 @@ void Push64Relocs_t::HandlePush64Relocs() void Push64Relocs_t::UpdatePush64Adds() { - if (m_verbose) + if (*m_verbose) cout << "push64:UpdatePush64Adds()" << endl; InstructionSet_t::iterator insn_it = plopped_relocs.begin(); for (insn_it; insn_it != plopped_relocs.end(); insn_it++) @@ -232,7 +228,7 @@ void Push64Relocs_t::UpdatePush64Adds() if (call_addr == 0 || add_addr == 0) { - if (m_verbose) + if (*m_verbose) cout << "push64:Call/Add pair not plopped?" << endl; continue; } @@ -291,8 +287,5 @@ extern "C" Zipr_SDK::ZiprPluginInterface_t* GetPluginInterface( Zipr_SDK::Zipr_t* zipr_object) { - 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); + return new Push64Relocs_t(zipr_object); } diff --git a/push64_relocs.h b/push64_relocs.h index 7a6506095..af5a60f2d 100644 --- a/push64_relocs.h +++ b/push64_relocs.h @@ -37,9 +37,8 @@ class Push64Relocs_t : public Zipr_SDK::ZiprPluginInterface_t { public: - Push64Relocs_t(Zipr_SDK::MemorySpace_t *p_ms, - IRDB_SDK::FileIR_t *p_firp, - Zipr_SDK::InstructionLocationMap_t *p_fil); + Push64Relocs_t(Zipr_SDK::Zipr_t* zipr_object); + virtual void doPinningEnd() override { // if(m_elfio.get_type()==ET_EXEC) @@ -63,7 +62,7 @@ class Push64Relocs_t : public Zipr_SDK::ZiprPluginInterface_t UpdatePush64Adds(); } - virtual Zipr_SDK::ZiprOptionsNamespace_t *registerOptions(Zipr_SDK::ZiprOptionsNamespace_t *) override; + // virtual Zipr_SDK::ZiprOptionsNamespace_t *registerOptions(Zipr_SDK::ZiprOptionsNamespace_t *) override; private: // main workhorses void HandlePush64Relocs(); @@ -119,7 +118,7 @@ class Push64Relocs_t : public Zipr_SDK::ZiprPluginInterface_t // local data. IRDB_SDK::InstructionSet_t plopped_relocs; - Zipr_SDK::ZiprBooleanOption_t m_verbose; + Zipr_SDK::ZiprBooleanOption_t *m_verbose; }; -- GitLab