diff --git a/.gitignore b/.gitignore index f96c1da9128b9a1a3baf4463249e0aad9dcf9f91..ebc2f29f0152cb43dfc3bdf5286fe818bf10c6c9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,6 @@ build *.swp +*.os +*.o +*.zpi diff --git a/SConscript b/SConscript index 22050cb8d38f541921d5033e6b3aa33f8407132a..8e2fa928e9b0ec2e131069a972a921cdf49a03a0 100644 --- a/SConscript +++ b/SConscript @@ -63,4 +63,5 @@ Default( pedi ) - +ret=pedi+lib +Return('ret') diff --git a/unpin.cpp b/unpin.cpp index b8cdd3bd827c07c076ed82bb4f85046b02a041ef..68a1ed425ec6b21911e513277da870008d7dd2c5 100644 --- a/unpin.cpp +++ b/unpin.cpp @@ -43,57 +43,6 @@ using namespace Zipr_SDK; #define ALLOF(a) begin(a),end(a) -static std::string findAndReplace(const std::string& in_str, const std::string& oldStr, const std::string& newStr) -{ - std::string str=in_str; - size_t pos = 0; - while((pos = str.find(oldStr, pos)) != std::string::npos) - { - str.replace(pos, oldStr.length(), newStr); - pos += newStr.length(); - } - return str; -} - -static bool has_cfi_reloc(Instruction_t* insn) -{ - for(auto reloc : insn->getRelocations()) - { - /* check for a nonce relocation */ - if ( reloc -> getType().find("cfi_nonce") != string::npos ) - { - return true; - } - } - return false; -} - -bool Unpin_t::should_cfi_pin(Instruction_t* insn) -{ - // add command line option that: - // 1) return false if !has_cfi_reloc(insn) - // 2) return true if option is on. - return *m_should_cfi_pin; -} - -#if 0 -ZiprOptionsNamespace_t *Unpin_t::registerOptions(ZiprOptionsNamespace_t *global) -{ - auto unpin_ns = new ZiprOptionsNamespace_t("unpin"); - global->addOption(&m_verbose); - - m_should_cfi_pin.setDescription("Pin CFI instructions."); - unpin_ns->addOption(&m_should_cfi_pin); - - m_on.setDescription("Turn unpin plugin on/off."); - unpin_ns->addOption(&m_on); - - m_max_unpins.setDescription("Set how many unpins are allowed, useful for debugging."); - unpin_ns->addOption(&m_max_unpins); - - return unpin_ns; -} -#endif // CAN BE DELETED, left in just for stats? (Would speed up zipr step to delete) void Unpin_t::DoUnpin() @@ -106,7 +55,7 @@ void Unpin_t::DoUnpin() // scan instructions and process instruction relocs that can be unpinned. void Unpin_t::DoUnpinForFixedCalls() { - if(*m_max_unpins != -1 && unpins>=*m_max_unpins) + if((int64_t)*m_max_unpins != (int64_t)-1 && (int64_t)unpins>=(int64_t)*m_max_unpins) return; auto insn_unpins=0; auto missed_unpins=0; @@ -130,7 +79,7 @@ void Unpin_t::DoUnpinForFixedCalls() unpins++; insn_unpins++; - if(*m_max_unpins != -1 && unpins>=*m_max_unpins) + if((int64_t)*m_max_unpins != (int64_t)-1 && (int64_t)unpins>=(int64_t)*m_max_unpins) return; } } @@ -143,8 +92,9 @@ void Unpin_t::DoUnpinForFixedCalls() // CAN BE DELETED, left in just for stats? void Unpin_t::DoUnpinForScoops() { - if(*m_max_unpins != -1 && unpins>=*m_max_unpins) + if((int64_t)*m_max_unpins != (int64_t)-1 && (int64_t)unpins>=(int64_t)*m_max_unpins) return; + auto missed_unpins=0; auto scoop_unpins=0; @@ -161,7 +111,7 @@ void Unpin_t::DoUnpinForScoops() unpins++; scoop_unpins++; - if(*m_max_unpins != -1 && unpins>=*m_max_unpins) + if((int64_t)*m_max_unpins != (int64_t)-1 && (int64_t)unpins>=(int64_t)*m_max_unpins) return; } } @@ -179,13 +129,11 @@ Zipr_SDK::ZiprPreference Unpin_t::retargetCallback( if(!*m_on) return Zipr_SDK::ZiprPluginInterface_t::retargetCallback(callback_address, callback_entry, target_address); unpins++;// unpinning a call to a scoop. - if(*m_max_unpins != -1 && unpins>=*m_max_unpins) + if((int64_t)*m_max_unpins != (int64_t)-1 && (int64_t)unpins>=(int64_t)*m_max_unpins) return Zipr_SDK::ZiprPluginInterface_t::retargetCallback(callback_address, callback_entry, target_address); - auto& ms=*zo->getMemorySpace(); auto insn = callback_entry->getInstruction(); - auto& locMap=*(zo->getLocationMap()); for(auto reloc : insn->getRelocations()) { if (reloc->getType()==string("callback_to_scoop")) diff --git a/unpin_aarch64.cpp b/unpin_aarch64.cpp index 86a985e4255f721faffc2d62362346abf50568dd..84ce9e1f9b408e61e0726130b72d6c4ea23cd595 100644 --- a/unpin_aarch64.cpp +++ b/unpin_aarch64.cpp @@ -58,7 +58,6 @@ void UnpinAarch64_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* re const auto insn_wrt=dynamic_cast<Instruction_t*>(reloc->getWRT()); assert(the_arg_it!=operands.end()); const auto the_arg=*the_arg_it; - const auto mt=firp.getArchitecture()->getMachineType(); // get the new insn addr const auto from_insn_location=(VirtualOffset_t)locMap[from_insn]; diff --git a/unpin_x86.cpp b/unpin_x86.cpp index c5c694a4977b53a0cac7b308901379724d8f64ea..a3658d297d401370a834ae58e4fbd05230d19239 100644 --- a/unpin_x86.cpp +++ b/unpin_x86.cpp @@ -102,7 +102,6 @@ void UnpinX86_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* reloc) const auto insn_wrt=dynamic_cast<Instruction_t*>(reloc->getWRT()); assert(the_arg_it!=operands.end()); const auto the_arg=*the_arg_it; - const auto mt=firp.getArchitecture()->getMachineType(); // get the new insn addr const auto from_insn_location=(VirtualOffset_t)locMap[from_insn]; @@ -133,7 +132,7 @@ void UnpinX86_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* reloc) const auto disp_offset=(int)disasm->getMemoryDisplacementOffset(the_arg.get(),from_insn); const auto disp_size=(int)the_arg->getMemoryDisplacementEncodingSize(); assert(disp_size==4); - assert(0<disp_offset && disp_offset<=from_insn->getDataBits().size() - disp_size); + assert(0<disp_offset && (int64_t)disp_offset<=(int64_t)from_insn->getDataBits().size() - disp_size); const auto new_disp=(int)(rel_addr1 + to_addr - from_insn->getDataBits().size()-from_insn_location); const auto newbits=from_insn->getDataBits().replace(disp_offset, disp_size, (char*)&new_disp, disp_size); @@ -158,12 +157,11 @@ void UnpinX86_t::HandleAbsptrReloc(Instruction_t* from_insn, Relocation_t* reloc assert(wrt); assert(the_arg_it!=operands.end()); const auto &the_arg=*the_arg_it; - VirtualOffset_t rel_addr1=the_arg->getMemoryDisplacement(); int disp_offset=disasm->getMemoryDisplacementOffset(the_arg.get(),from_insn); int disp_size=the_arg->getMemoryDisplacementEncodingSize(); assert(disp_size==4); - assert(0<disp_offset && disp_offset<=from_insn->getDataBits().size() - disp_size); + assert(0<disp_offset && (int64_t)disp_offset<=(int64_t)from_insn->getDataBits().size() - disp_size); assert(reloc->getWRT()); unsigned int new_disp=the_arg->getMemoryDisplacement() + wrt->getStart()->getVirtualOffset(); @@ -210,21 +208,17 @@ void UnpinX86_t::HandleImmedptrReloc(Instruction_t* from_insn, Relocation_t* rel void UnpinX86_t::HandleCallbackReloc(Instruction_t* from_insn, Relocation_t* reloc) { - DataScoop_t *wrt = dynamic_cast<DataScoop_t*>(reloc->getWRT()); - int addend = reloc->getAddend(); char bytes[]={(char)0x48, (char)0x8d, (char)0x64, (char)0x24, (char)(64/0x08)}; // lea rsp, [rsp+8] - uintptr_t call_addr = 0x0, at = 0x0; - uint32_t target_addr = 0x0; if (m_verbose) cout << "The call insn is " << from_insn->getDataBits().length() << " bytes long." << endl; - call_addr = locMap[from_insn]; + auto call_addr = locMap[from_insn]; if (m_verbose) { cout << "Unpin::callback_to_scoop: call_addr " @@ -234,8 +228,7 @@ void UnpinX86_t::HandleCallbackReloc(Instruction_t* from_insn, Relocation_t* rel /* * Put down the bogus pop. */ - at = call_addr + 1; - at = call_addr + from_insn->getDataBits().length(); + auto at = call_addr + from_insn->getDataBits().length(); ms.plopBytes(at, bytes, sizeof(bytes)); /*