diff --git a/builtin_xforms/move_globals/mg_driver.cpp b/builtin_xforms/move_globals/mg_driver.cpp index ba927a661f6caca1bbf51515930c2beba17fc3d2..36a9346794b09c04403cd173b45dcdac678c0fa6 100644 --- a/builtin_xforms/move_globals/mg_driver.cpp +++ b/builtin_xforms/move_globals/mg_driver.cpp @@ -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; diff --git a/builtin_xforms/p1transform/PNMain.cpp b/builtin_xforms/p1transform/PNMain.cpp index 75c5475050f0c0cb8788a84f4ae1fddc72523ab6..1664d7b4021d5231708ca1fa13e77407db8d0943 100644 --- a/builtin_xforms/p1transform/PNMain.cpp +++ b/builtin_xforms/p1transform/PNMain.cpp @@ -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,7 +261,7 @@ int parseArgs(const vector<string> step_args) verbose_log = (verbose != nullptr); - progid = atoi(argv[0]); +// progid = atoi(argv[0]); char buf[]="libp1transform.so"; argv[0]=buf; @@ -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(); diff --git a/irdb-libs/ir_builders/fill_in_cfg.cpp b/irdb-libs/ir_builders/fill_in_cfg.cpp index c07f45e704fdc056fe56f65b83d62ba783642d25..0cc9c32206a9aaf8ebdb4a121563b9c6b2c1f2c6 100644 --- a/irdb-libs/ir_builders/fill_in_cfg.cpp +++ b/irdb-libs/ir_builders/fill_in_cfg.cpp @@ -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(); diff --git a/irdb-libs/ir_builders/fill_in_cfg.hpp b/irdb-libs/ir_builders/fill_in_cfg.hpp index b0cd24358041fe2d769723f32cf7511ceea89257..8af546a6a9c9ad8d46dccee1920dd4f2d75968ca 100644 --- a/irdb-libs/ir_builders/fill_in_cfg.hpp +++ b/irdb-libs/ir_builders/fill_in_cfg.hpp @@ -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 diff --git a/irdb-libs/ir_builders/fill_in_indtargs.cpp b/irdb-libs/ir_builders/fill_in_indtargs.cpp index 99d63250e5ef07c025cfc0fe40a02d83fd828d52..b75b879676e9f30d24f620e80820fab455d9679b 100644 --- a/irdb-libs/ir_builders/fill_in_indtargs.cpp +++ b/irdb-libs/ir_builders/fill_in_indtargs.cpp @@ -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 { diff --git a/irdb-libs/ir_builders/fix_calls.cpp b/irdb-libs/ir_builders/fix_calls.cpp index d9a041009ba7469d5acdd436fa401e47e3982e7a..5fd6a66dddbe1f2a0f8d86969430820f505d921b 100644 --- a/irdb-libs/ir_builders/fix_calls.cpp +++ b/irdb-libs/ir_builders/fix_calls.cpp @@ -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 diff --git a/irdb-libs/libIRDB-core/include/libIRDB-core.hpp b/irdb-libs/libIRDB-core/include/libIRDB-core.hpp index 681d93a330914a1953761dee21fb246b913d08b4..0d8d5f5ac23fcda5e001b8f3289587985529df44 100644 --- a/irdb-libs/libIRDB-core/include/libIRDB-core.hpp +++ b/irdb-libs/libIRDB-core/include/libIRDB-core.hpp @@ -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); diff --git a/irdb-libs/libIRDB-core/include/transform_step.h b/irdb-libs/libIRDB-core/include/transform_step.h deleted file mode 100644 index 7e6d40926b5d577d2fc61001834dde4a669c7424..0000000000000000000000000000000000000000 --- a/irdb-libs/libIRDB-core/include/transform_step.h +++ /dev/null @@ -1,32 +0,0 @@ - - -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); - diff --git a/irdb-libs/libIRDB-core/include/transform_step_state.hpp b/irdb-libs/libIRDB-core/include/transform_step_state.hpp new file mode 100644 index 0000000000000000000000000000000000000000..202a67ff173a71dfbce145a726ba4820d68c5eea --- /dev/null +++ b/irdb-libs/libIRDB-core/include/transform_step_state.hpp @@ -0,0 +1,24 @@ +#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 diff --git a/irdb-libs/libIRDB-core/src/SConscript b/irdb-libs/libIRDB-core/src/SConscript index ae16a37d191ab93f41864778c0244c4dfd6794cd..77ad98291c709b369b1fd1aad6de9c1dec1d5b12 100644 --- a/irdb-libs/libIRDB-core/src/SConscript +++ b/irdb-libs/libIRDB-core/src/SConscript @@ -29,6 +29,7 @@ files= ''' operand_csarm.cpp IRDB_Objects.cpp decode_base.cpp + transform_step.cpp ''' unused_files=''' decode_bea.cpp diff --git a/irdb-libs/libIRDB-core/src/transform_step.cpp b/irdb-libs/libIRDB-core/src/transform_step.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ee264c68b17f244f3e0f64de7230d7b23cc3bb83 --- /dev/null +++ b/irdb-libs/libIRDB-core/src/transform_step.cpp @@ -0,0 +1,48 @@ +#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; +} + diff --git a/irdb-libs/rida/rida.cpp b/irdb-libs/rida/rida.cpp index 49d64907a8bc9751d4cf7d17e5b22c59a45e8866..326eae89987f1e3b8f60574dcc9cbeb97d03c12f 100644 --- a/irdb-libs/rida/rida.cpp +++ b/irdb-libs/rida/rida.cpp @@ -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; } diff --git a/irdb-libs/thanos/thanos.cpp b/irdb-libs/thanos/thanos.cpp index 560adb3a405927856cd2cd0f5b8b55c585194cec..2df5b9c768e8d7adb0f3841fe9672c378b4c2e0f 100644 --- a/irdb-libs/thanos/thanos.cpp +++ b/irdb-libs/thanos/thanos.cpp @@ -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) { diff --git a/irdb-sdk b/irdb-sdk index 85a2d55a38c8880b1233e1068a8a878498cbf624..dd1ec536daf04863d614cabbfb7b07aabcc6643e 160000 --- a/irdb-sdk +++ b/irdb-sdk @@ -1 +1 @@ -Subproject commit 85a2d55a38c8880b1233e1068a8a878498cbf624 +Subproject commit dd1ec536daf04863d614cabbfb7b07aabcc6643e