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 (4)
Showing
with 144 additions and 92 deletions
......@@ -55,23 +55,26 @@ int parseArgs(const vector<string> step_args)
auto argv = vector<char*>();
transform(ALLOF(step_args), back_inserter(argv), [](const string &s) -> char* { return const_cast<char*>(s.c_str()); } );
const auto argc = step_args.size();
auto strtolError = (char*) nullptr;
/*
* Check that we've been called correctly:
* <program> <variant id> <annotation file>
*/
#if 0
if(argc < 1)
{
usage(programName);
return 2;
}
#endif
#if 0
variantID = strtol(step_args[0].c_str(), &strtolError, 10);
if (*strtolError != '\0')
{
cerr << "Invalid variantID: " << step_args[0] << endl;
return 1;
}
#endif
// Parse some options for the transform
const static struct option long_options[] = {
......@@ -144,8 +147,10 @@ int parseArgs(const vector<string> step_args)
}
int executeStep(IRDBObjects_t *const irdb_objects)
int executeStep()
{
variantID=getVariantID();
auto irdb_objects=getIRDBObjects();
auto exit_code = (int) 0;
......
......@@ -58,8 +58,7 @@ PNOptions *pn_options;
enum
{
VARIANT_ID_OPTION = CHAR_MAX+1,
BED_SCRIPT_OPTION,
BED_SCRIPT_OPTION = CHAR_MAX+1,
BLACKLIST_OPTION,
COVERAGE_FILE_OPTION,
PN_THRESHOLD_OPTION,
......@@ -88,7 +87,6 @@ enum
static struct option const long_options[] =
{
{"variant_id",required_argument, nullptr, VARIANT_ID_OPTION},
{"bed_script",required_argument, nullptr, BED_SCRIPT_OPTION},
{"blacklist",required_argument, nullptr, BLACKLIST_OPTION},
{"coverage_file",required_argument, nullptr, COVERAGE_FILE_OPTION},
......@@ -263,9 +261,9 @@ int parseArgs(const vector<string> step_args)
verbose_log = (verbose != nullptr);
progid = atoi(argv[0]);
char buf[]="libp1transform.so";
argv[0]=buf;
// progid = atoi(argv[0]);
// char buf[]="libp1transform.so";
// argv[0]=buf;
int c=0;
......@@ -276,11 +274,6 @@ int parseArgs(const vector<string> step_args)
{
switch(c)
{
case VARIANT_ID_OPTION:
{
progid = atoi(optarg);
break;
}
case BED_SCRIPT_OPTION:
{
BED_script = optarg;
......@@ -488,8 +481,10 @@ int parseArgs(const vector<string> step_args)
}
int executeStep(IRDBObjects_t *const irdb_objects)
int executeStep()
{
progid=getVariantID();
auto irdb_objects=getIRDBObjects();
//setup the interface to the sql server
const auto pqxx_interface=irdb_objects->getDBInterface();
......
......@@ -639,13 +639,15 @@ void PopulateCFG::fill_in_landing_pads(FileIR_t *firp)
int PopulateCFG::parseArgs(const vector<string> step_args)
{
#if 0
if(step_args.size()<1)
{
cerr<<"Usage: <id> [--fix-landing-pads | --no-fix-landing-pads]"<<endl;
cerr<<"Usage: [--fix-landing-pads | --no-fix-landing-pads]"<<endl;
return -1;
}
#endif
variant_id = stoi(step_args[0]);
// variant_id = stoi(step_args[0]);
for (unsigned int i = 1; i < step_args.size(); ++i)
{
......@@ -677,8 +679,10 @@ void PopulateCFG::rename_start(FileIR_t *firp)
}
}
int PopulateCFG::executeStep(IRDBObjects_t *const irdb_objects)
int PopulateCFG::executeStep()
{
variant_id=getVariantID();
auto irdb_objects=getIRDBObjects();
try
{
const auto pqxx_interface = irdb_objects->getDBInterface();
......
......@@ -39,7 +39,7 @@ class PopulateCFG : public IRDB_SDK::TransformStep_t
return std::string("fill_in_cfg");
}
int parseArgs(const std::vector<std::string> step_args) override;
int executeStep(IRDB_SDK::IRDBObjects_t *const) override;
int executeStep() override;
private: // methods
......
......@@ -3587,13 +3587,15 @@ set<VirtualOffset_t> forced_pins;
int parseArgs(const vector<string> step_args)
{
#if 0
if(step_args.size()<1)
{
cerr<<"Usage: <id> [--[no-]split-eh-frame] [--[no-]unpin] [addr,...]"<<endl;
exit(-1);
}
#endif
variant_id=stoi(step_args[0]);
// variant_id=stoi(step_args[0]);
cout<<"Parsing parameters with argc= " << step_args.size()<<endl;
// parse dash-style options.
......@@ -3660,10 +3662,10 @@ int parseArgs(const vector<string> step_args)
}
int executeStep(IRDBObjects_t *const irdb_objects)
int executeStep()
{
//VariantID_t *pidp=nullptr;
//FileIR_t * firp=nullptr;
variant_id=getVariantID();
auto irdb_objects=getIRDBObjects();
try
{
......
......@@ -951,6 +951,7 @@ bool do_eh_frame=true;
int parseArgs(const vector<string> step_args)
{
#if 0
if(step_args.size()<1)
{
cerr<<"Usage: <id> [--fix-all | --no-fix-all ] [--eh-frame | --no-ehframe] "<<endl;
......@@ -962,6 +963,7 @@ int parseArgs(const vector<string> step_args)
cerr<<" --no-fix-icalls Convert (or don't) indirect calls."<<endl;
exit(-1);
}
#endif
for(unsigned int argc_iter=1; argc_iter<step_args.size(); argc_iter++)
{
......@@ -1006,15 +1008,17 @@ int parseArgs(const vector<string> step_args)
if(getenv("FIX_CALLS_FIX_ALL_CALLS"))
fix_all=true;
variant_id=stoi(step_args[0]);
// variant_id=stoi(step_args[0]);
return 0;
}
DatabaseID_t variant_id=BaseObj_t::NOT_IN_DATABASE;
int executeStep(IRDBObjects_t *const irdb_objects)
int executeStep()
{
variant_id=getVariantID();
auto irdb_objects=getIRDBObjects();
cout<<"Reading variant "<<variant_id<<" from database." << endl;
try
......
......@@ -52,7 +52,6 @@
#include <fileir.hpp>
#include <pqxxdb.hpp>
#include <IRDB_Objects.hpp>
#include <transform_step.h>
#include <decode.hpp>
int command_to_stream(const std::string& command, std::ostream& stream);
......
namespace libIRDB
{
class TransformStep_t : virtual public IRDB_SDK::TransformStep_t
{
public:
// Step names must be unique, allows arguments to
// be directed to their matching transform steps.
virtual std::string getStepName(void) const = 0;
// Allows all steps to parse args before any step takes time to execute
virtual int parseArgs(const std::vector<std::string> step_args)
{
return 0; // success
}
virtual int executeStep(IRDB_SDK::IRDBObjects_t *const irdb_objects)
{
return 0; // success
}
virtual ~TransformStep_t(void)
{
// do nothing
}
};
}
extern "C"
std::shared_ptr<IRDB_SDK::TransformStep_t> GetTransformStep(void);
#ifndef TSS_H
#define TSS_H
class IRDB_SDK::TransformStepState_t
{
public:
TransformStepState_t(DatabaseID_t v, IRDBObjects_t* i)
:
vid(v),
irdb_objects(i)
{
}
DatabaseID_t vid;
IRDBObjects_t* irdb_objects;
};
#endif
......@@ -29,6 +29,7 @@ files= '''
operand_csarm.cpp
IRDB_Objects.cpp
decode_base.cpp
transform_step.cpp
'''
unused_files='''
decode_bea.cpp
......
#include <irdb-core>
#include <transform_step_state.hpp>
using namespace IRDB_SDK;
File_t* TransformStep_t::getMainFile()
{
auto variantID=getVariantID();
auto irdb_objects=m_state->irdb_objects;
/* setup the interface to the sql server */
auto &pqxx_interface=*irdb_objects->getDBInterface();;
BaseObj_t::setInterface(&pqxx_interface);
const auto pidp = irdb_objects->addVariant(variantID);
assert(pidp->isRegistered()==true);
auto this_file=pidp->getMainFile();
return this_file;
}
FileIR_t* TransformStep_t::getMainFileIR()
{
auto variantID=getVariantID();
auto irdb_objects=m_state->irdb_objects;
auto this_file=getMainFile();
auto firp = irdb_objects->addFileIR(variantID, this_file->getBaseID());
return firp;
}
DatabaseID_t TransformStep_t::getVariantID()
{
auto variantID=m_state->vid;
return variantID;
}
void TransformStep_t::setState(TransformStepState_t* p_state)
{
m_state=p_state;
}
IRDB_SDK::IRDBObjects_t*const TransformStep_t::getIRDBObjects()
{
return m_state->irdb_objects;
}
......@@ -37,7 +37,6 @@ class CreateFunctions_t
public:
Range_t(const Address_t &a, const Address_t &b) : pair<Address_t,Address_t>(a,b) { }
bool contains(const Address_t &c) const { return first <= c && c<second; }
};
using RangeSet_t = set<Range_t>;
set < RangeSet_t > sccs;
......@@ -76,15 +75,15 @@ class CreateFunctions_t
const auto cs_mode=
machine_type==mtAarch64 ? CS_MODE_LITTLE_ENDIAN :
file_class==ELF64 ? CS_MODE_64 :
file_class==ELF32 ? CS_MODE_32 :
throw std::runtime_error("Cannot handle ELF class");
file_class==ELF64 ? CS_MODE_64 :
file_class==ELF32 ? CS_MODE_32 :
throw std::runtime_error("Cannot handle ELF class");
const auto my_cs_arch =
machine_type == mtX86_64 ? CS_ARCH_X86 :
machine_type == mtI386 ? CS_ARCH_X86 :
machine_type == mtX86_64 ? CS_ARCH_X86 :
machine_type == mtI386 ? CS_ARCH_X86 :
machine_type == mtAarch64 ? CS_ARCH_ARM64 :
throw std::runtime_error("Cannot handle architecture");
throw std::runtime_error("Cannot handle architecture");
if (cs_open(my_cs_arch, cs_mode , &cshandle) != CS_ERR_OK)
{
......@@ -146,30 +145,21 @@ class CreateFunctions_t
auto unnamedFunctions=0U;
auto functions=0U;
const auto entryPointAddress=exeio.get_entry();
// set default names
for(const auto &func: sccs)
{
assert(func.begin() != func.end());
const auto first_range=*(func.begin());
const auto startAddr=first_range.first;
std::stringstream ss;
ss << "sub_" << hex << startAddr;
const auto name = ss.str();
functions++;
if(entryPointAddress == startAddr)
{
// override the elf entry point to be called _start
funcNames[func]="_start";
namedFunctions++;
}
else if(funcNames[func]=="") // destructive test OK, next line sets if empty.
if(funcNames[func]=="") // destructive test OK, next line sets if empty.
{
std::stringstream ss;
ss << "sub_" << hex << startAddr;
const auto name = ss.str();
funcNames[func]=name;
unnamedFunctions++;
funcNames[func]=name;
}
else
{
......@@ -437,12 +427,21 @@ class CreateFunctions_t
if(gotPltSec==NULL)
return;
// both 32- and 64-bit, entries are 6 bytes, with 2 bytes of padding.
const auto gotPltEntrySize=8;
const auto gotPltRangeSize=6;
const auto gotPltStartAddr=gotPltSec->get_address();
auto gotpltEntries=0U;
const auto gotPltRange_it=find_if(ALLOF(sccs), [&](const RangeSet_t& s)
{
return find_if(ALLOF(s), [&](const Range_t& r) { return r.contains(gotPltStartAddr); }) != s.end();
});
// erase startAddr if found.
if(gotPltRange_it!=sccs.end())
sccs.erase(gotPltRange_it); // invalidates all iterators
auto gotpltEntries=0U;
for(auto i=0U; i + gotPltRangeSize < (size_t)gotPltSec->get_size(); i+=gotPltEntrySize)
{
addRange(gotPltStartAddr+i,gotPltRangeSize);
......@@ -483,6 +482,7 @@ class CreateFunctions_t
}
void doBelongTos(const RangeSet_t &scc)
{
const auto min=*scc.begin();
......@@ -536,8 +536,10 @@ class CreateFunctions_t
};
ostream& operator<<(ostream& os, const CreateFunctions_t::RangeSet_t& rs)
{
for(const auto r : rs)
......@@ -547,6 +549,8 @@ ostream& operator<<(ostream& os, const CreateFunctions_t::RangeSet_t& rs)
return os;
}
int main(int argc, char* argv[])
{
......@@ -611,5 +615,6 @@ int main(int argc, char* argv[])
create_funcs.calculate();
create_funcs.writeAnnotations();
return 0;
}
......@@ -12,6 +12,7 @@
#include <ctime>
#include <ext/stdio_filebuf.h>
#include <transform_step_state.hpp>
using namespace std;
......@@ -42,7 +43,7 @@ static string getFileStem(const string& filePath)
return tmp;
}
class ThanosPlugin_t
class IRDB_SDK::ThanosPlugin_t
{
public:
static unique_ptr<ThanosPlugin_t> pluginFactory(const string plugin_details);
......@@ -238,15 +239,6 @@ unique_ptr<ThanosPlugin_t> ThanosPlugin_t::pluginFactory(const string plugin_det
int ThanosPlugin_t::runPlugin()
{
#if 0
static const char *const base_path = getenv("SECURITY_TRANSFORMS_HOME");
if(base_path == NULL)
{
*thanos_log << "Environment variables not set." << endl;
return -1;
}
static const auto plugin_path (string(base_path).append("/plugins_install/"));
#endif
const auto short_step_name = string(getFileStem(step_name).c_str()+3);
void *const dlhdl = dlopen(step_name.c_str(), RTLD_NOW);
if(dlhdl == NULL)
......@@ -347,7 +339,8 @@ int ThanosPlugin_t::executeStep(TransformStep_t& the_step, const bool are_debugg
tidyIR();
const int parse_retval = the_step.parseArgs(step_args);
const auto vid=atoi(step_args[0].c_str());
const int parse_retval = the_step.parseArgs(vector<string>(begin(step_args)+1,end(step_args)));
if(parse_retval != 0)
{
*real_cout<<"Done. Command failed! ***************************************"<<endl;
......@@ -374,7 +367,10 @@ int ThanosPlugin_t::executeStep(TransformStep_t& the_step, const bool are_debugg
}
}
const int step_error = the_step.executeStep(shared_objects.get());
auto the_step_state=TransformStepState_t(vid,shared_objects.get());
the_step.setState(&the_step_state);
const int step_error = the_step.executeStep();
if(step_error)
{
......
Subproject commit 85a2d55a38c8880b1233e1068a8a878498cbf624
Subproject commit dd1ec536daf04863d614cabbfb7b07aabcc6643e
......@@ -7,6 +7,7 @@ export IDASDK=$PEASOUP_HOME/idaproCur_sdk
export ZIPR_HOME=$PEASOUP_HOME/zipr
export ZIPR_SDK=$PEASOUP_HOME/zipr-sdk
export IRDB_SDK=$PEASOUP_HOME/irdb-sdk
export IRDB_LIBS=$PEASOUP_HOME/irdb-libs/lib
export ZEST_RUNTIME=$PEASOUP_HOME/zest_runtime
......