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
  • whh8b/zipr
2 results
Show changes
Commits on Source (3)
......@@ -9,7 +9,6 @@ myenv=env.Clone()
cpppath='''
$SECURITY_TRANSFORMS_HOME/third_party/elfio-code
$PEASOUP_HOME/irdb-libs/libStructDiv/include
$PEASOUP_HOME/irdb-libs/libEXEIO/include
$IRDB_SDK/include
'''
......
......@@ -4,7 +4,6 @@
#include <assert.h>
#include <stdexcept>
#include <unistd.h>
#include <libStructDiv.h>
#include <memory>
#include <inttypes.h>
#include <algorithm>
......@@ -17,7 +16,6 @@
using namespace std;
using namespace IRDB_SDK;
using namespace libStructDiv;
using namespace EXEIO;
#define ALLOF(s) begin(s), end(s)
......@@ -96,7 +94,6 @@ MoveGlobals_t<T_Sym,T_Rela,T_Rel,T_Dyn,T_Extractor>::MoveGlobals_t(
const bool p_use_stars)
:
Transform_t(p_variantIR),
struct_div(NULL),
exe_reader(NULL),
tied_unpinned(0),
tied_pinned(0),
......
......@@ -8,7 +8,6 @@
#include <set>
#include <tuple>
#include <libStructDiv.h>
#include <exeio.h>
#include <elfio/elfio.hpp>
......@@ -67,8 +66,6 @@ class MoveGlobals_t : public IRDB_SDK::Transform_t
bool AreScoopsAdjacent(const IRDB_SDK::DataScoop_t *a, const IRDB_SDK::DataScoop_t *b) const;
libStructDiv::StructuredDiversity_t *struct_div;
std::vector<T_Sym> static_symbols;
std::vector<T_Sym> dynamic_symbols;
EXEIO::exeio* exe_reader;
......
......@@ -109,6 +109,16 @@ set<Instruction_t*> already_unpinned;
long total_unpins=0;
/*
* Convert a reg id to a lower-case string
*/
string registerToSearchString(const RegisterID_t& reg)
{
auto str=registerToString(reg);
transform(ALLOF(str), begin(str), ::tolower);
return str;
}
void range(VirtualOffset_t start, VirtualOffset_t end)
{
pair<VirtualOffset_t,VirtualOffset_t> foo(start,end);
......@@ -1813,19 +1823,35 @@ Note: Here the operands of the add are reversed, so lookup code was not finding
const auto d7=DecodedInstruction_t::factory(I7);
// Check if lea instruction is being used as add (scale=1, disp=0)
if(strstr(d7->getMnemonic().c_str(), "lea"))
if(d7->getMnemonic() == "lea")
{
if(!(d7->getOperand(1)->isMemory() ))
return;
if(!(d7->getOperand(1)->getScaleValue() == 1 && d7->getOperand(1)->getMemoryDisplacement() == 0))
return;
}
// calculate the registers we need for the I6 backup.
const auto I7_reg0 = d7->getMnemonic() == "lea" ? d7->getOperand(1)->getBaseRegister() : d7->getOperand(0)->getRegNumber();
const auto I7_reg0_32_str = registerToSearchString(RegisterID_t(rn_EAX+I7_reg0));
const auto I7_reg0_64_str = registerToSearchString(RegisterID_t(rn_RAX+I7_reg0));
const auto I7_reg1 = d7->getMnemonic() == "lea" ? d7->getOperand(1)->getIndexRegister() : d7->getOperand(1)->getRegNumber();
const auto I7_reg1_32_str = registerToSearchString(RegisterID_t(rn_EAX+I7_reg1));
const auto I7_reg1_64_str = registerToSearchString(RegisterID_t(rn_RAX+I7_reg1));
const auto I6_reg_str = string() + "(" + I7_reg0_32_str + "|"
+ I7_reg0_64_str + "|"
+ I7_reg1_32_str + "|"
+ I7_reg1_64_str + ")";
// backup and find the instruction that's an movsxd before I7
/*
* This instruction will contain the register names for
* the index and the address of the base of the table
*/
if(!backup_until("(mov|movsxd)", I6, I7))
if(!backup_until("(mov|movsxd) "+I6_reg_str+",", I6, I7,string()+"^"+I6_reg_str+"$"))
return;
string lea_string="lea ";
......@@ -1918,7 +1944,7 @@ Note: Here the operands of the add are reversed, so lookup code was not finding
// instruction address (and include the instruction's size, etc.
// but, fix_calls has already removed this oddity so we can relocate
// the instruction.
VirtualOffset_t D1=strtol(d5.getOperand(1)->getString().c_str(), nullptr, 0);
auto D1=VirtualOffset_t(strtol(d5.getOperand(1)->getString().c_str(), nullptr, 0));
D1+=I5_cur->getAddress()->getVirtualOffset();
// sometimes the lea only points at the image base, and the displacement field here is used for
......@@ -2074,13 +2100,10 @@ Note: Here the operands of the add are reversed, so lookup code was not finding
// hack approved by an7s to convert a field from the index register to the actual 32-bit register from RegID_t
const auto ireg_no = RegisterID_t(rn_EAX + d6_memop->getIndexRegister());
auto ireg_str = registerToString(ireg_no);
transform(ALLOF(ireg_str), begin(ireg_str), ::tolower);
const auto ireg_str = registerToSearchString(ireg_no);
const auto I6_2_opcode_str = string() + "movzx " + ireg_str + ",";
const auto stopif_reg_no = RegisterID_t(rn_RAX + d6_memop->getIndexRegister());
auto stopif_reg_str = registerToString(stopif_reg_no);
transform(ALLOF(stopif_reg_str), begin(stopif_reg_str), ::tolower);
const auto stopif_reg_str = registerToSearchString(stopif_reg_no);
const auto stop_if = string() + "^" + stopif_reg_str + "$";
auto I6_2 = (Instruction_t*)nullptr;
......
Subproject commit b7d340e26d8c80b09fc31e0c9bb1d5e9ff1b62c5
Subproject commit 1f7395bbff14c7f0b1764bc53860d07122bedb28