Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • opensrc/zipr_unpin_plugin
1 result
Show changes
Commits on Source (5)
......@@ -30,6 +30,7 @@
#include <string>
#include <cstring>
#include <algorithm>
#include "unpin.h"
#include <memory>
......@@ -233,18 +234,25 @@ void Unpin_t::DoUpdateForScoops()
else
{
// determine how big the ptr is.
int ptrsize=zo->getFileIR()->getArchitectureBitWidth()/8;
const int ptrsize=zo->getFileIR()->getArchitectureBitWidth()/8;
char addr[ptrsize];
memset(addr,0,ptrsize);
// convert it to bytes.
switch(ptrsize)
{
case 4:
*(int*)addr=newLoc;
{
const auto newVal=(int)newLoc;
memcpy(addr,&newVal,ptrsize);
break;
}
case 8:
*(long long*)addr=newLoc;
{
const auto newVal=(long long)newLoc;
memcpy(addr,&newVal,ptrsize);
break;
}
default:
assert(0);
}
......@@ -263,9 +271,17 @@ void Unpin_t::DoUpdateForScoops()
const char* data=scoop_contents.c_str();
if(byte_width==4)
val_to_patch=*(int*)&data[reloc->getOffset()];
{
auto newVal=(int)0;
memcpy(&newVal, &data[reloc->getOffset()], byte_width);
val_to_patch=newVal;
}
else if(byte_width==8)
val_to_patch=*(long long*)&data[reloc->getOffset()];
{
auto newVal=(long long)0;
memcpy(&newVal, &data[reloc->getOffset()], byte_width);
val_to_patch=newVal;
}
else
assert(0);
......
......@@ -104,7 +104,8 @@ void UnpinAarch64_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* re
uint8_t insn_bytes[insn_bytes_len]; // compiler disallows init on some platforms.
// but memcpy should init it sufficiently.
memcpy(insn_bytes, from_insn->getDataBits().c_str(), insn_bytes_len);
const auto full_insn=*(uint32_t*)insn_bytes;
auto full_insn=(uint32_t)0;
memcpy(&full_insn,insn_bytes, sizeof(full_insn));
const auto op_byte=insn_bytes[3];
if(is_adrp_type || is_adr_type)
......
......@@ -73,7 +73,10 @@ void UnpinArm32_t::HandlePcrelReloc(Instruction_t* from_insn, Relocation_t* relo
uint8_t insn_bytes[insn_bytes_len]; // compiler disallows init on some platforms.
// but memcpy should init it sufficiently.
memcpy(insn_bytes, from_insn->getDataBits().c_str(), insn_bytes_len);
const auto full_insn=*(uint32_t*)insn_bytes;
auto full_insn=(uint32_t)0;
memcpy(&full_insn,insn_bytes, sizeof(full_insn));
const auto mask1 = (1<<1 )-1;
const auto mask4 = (1<<4 )-1;
const auto mask8 = (1<<8 )-1;
......
......@@ -72,7 +72,9 @@ void UnpinX86_t::HandleRetAddrReloc(Instruction_t* from_insn, Relocation_t* relo
unsigned char newpush[5];
newpush[0]=0x68;
*(int*)&newpush[1]=(int)wrt_insn_location;
const auto newVal=(int)wrt_insn_location;
// *(int*)&newpush[1]=(int)wrt_insn_location;
memcpy(&newpush[1],&newVal,sizeof(newVal));
cout<<"Unpin::Updating push32/push64-exe insn:"
<<dec<<from_insn->getBaseID()<<":"<<from_insn->getDisassembly()<<"@"<<hex<<from_insn_location<<" to point at "
......