Skip to content
Snippets Groups Projects
Commit f4e35989 authored by mc2zk's avatar mc2zk
Browse files

Bringing up to date with trunk

parents 540ff0df 82129585
No related branches found
No related tags found
No related merge requests found
......@@ -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,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment