diff --git a/push64_relocs.cpp b/push64_relocs.cpp index bc84773457a858177e8f834670705924b2c62386..87dac6683d5e91422be17fe9e12b0367a530c393 100644 --- a/push64_relocs.cpp +++ b/push64_relocs.cpp @@ -30,6 +30,7 @@ #include <zipr_sdk.h> +#include <libIRDB-core.hpp> #include <string> #include <algorithm> #include "utils.hpp" @@ -41,16 +42,19 @@ using namespace std; using namespace Zipr_SDK; using namespace ELFIO; +#define ALLOF(a) begin(a), end(a) +/* bool arg_has_relative(const ARGTYPE &arg) { - /* if it's relative memory, watch out! */ + // if it's relative memory, watch out! if(arg.ArgType&MEMORY_TYPE) if(arg.ArgType&RELATIVE_) return true; return false; } +*/ Push64Relocs_t::Push64Relocs_t(MemorySpace_t *p_ms, elfio *p_elfio, @@ -317,8 +321,8 @@ void Push64Relocs_t::UpdatePush64Adds() int existing_offset_size = 0; uint8_t *insn_bytes = NULL; int insn_bytes_len = 0; - DISASM d; - ARGTYPE *arg=NULL; + //DISASM d; + //ARGTYPE *arg=NULL; #if 1 insn_addr = final_insn_locations[insn]; if (insn_addr == 0) @@ -333,7 +337,8 @@ void Push64Relocs_t::UpdatePush64Adds() insn_bytes=(uint8_t*)malloc(insn_bytes_len); memcpy(insn_bytes, insn->GetDataBits().c_str(), insn_bytes_len); - insn->Disassemble(d); + DecodedInstruction_t d(insn); + /* Disassemble(insn,d); if(arg_has_relative(d.Argument1)) arg=&d.Argument1; @@ -341,11 +346,15 @@ void Push64Relocs_t::UpdatePush64Adds() arg=&d.Argument2; if(arg_has_relative(d.Argument3)) arg=&d.Argument3; - assert(arg); - - memory_offset = arg->Memory.DisplacementAddr-d.EIP; - existing_offset_size = arg->Memory.DisplacementSize; + */ + const auto operands=d.getOperands(); + const auto arg_it=find_if(ALLOF(operands),[](const DecodedOperand_t& op) { return op.isMemory() && op.isPcrel(); }); + assert(arg_it!=operands.end()); + const auto arg=*arg_it; + + memory_offset = d.getMemoryDisplacementOffset(arg, insn); // arg->Memory.DisplacementAddr-d.EIP; + existing_offset_size = arg.getMemoryDisplacementEncodingSize(); // arg->Memory.DisplacementSize; assert(memory_offset>=0 && memory_offset <=15 && (existing_offset_size==1 || existing_offset_size==2 || @@ -362,7 +371,7 @@ void Push64Relocs_t::UpdatePush64Adds() << std::hex << existing_offset << " existing offset at 0x" << insn_addr << "." << endl - << "Based on: " << d.CompleteInstr << endl + << "Based on: " << d.getDisassembly() /*CompleteInstr*/ << endl << "New address: 0x" << std::hex << new_offset << endl; m_memory_space.PlopBytes(insn_addr+memory_offset,