diff --git a/.gitattributes b/.gitattributes index 3d6caa0d943381eb204924f13ecbe3e6482ef0b4..37744e7c3d4a9f867a5a0bf880ea1243ebe20789 100644 --- a/.gitattributes +++ b/.gitattributes @@ -145,6 +145,7 @@ examples/Makefile -text examples/dumbledore.c -text examples/dumbledore_cmd.c -text examples/test1.c -text +libIRDB/Makefile -text libIRDB/include/address.hpp -text libIRDB/include/baseobj.hpp -text libIRDB/include/basetypes.hpp -text @@ -159,19 +160,27 @@ libIRDB/include/utils.hpp -text libIRDB/include/variantid.hpp -text libIRDB/include/variantir.hpp -text libIRDB/src/Makefile -text +libIRDB/src/address.cpp -text libIRDB/src/all.hpp -text libIRDB/src/baseobj.cpp -text libIRDB/src/dbinterface.cpp -text libIRDB/src/file.cpp -text libIRDB/src/function.cpp -text +libIRDB/src/instruction.cpp -text libIRDB/src/pqxxdb.cpp -text libIRDB/src/variantid.cpp -text libIRDB/src/variantir.cpp -text libIRDB/test/Makefile -text +libIRDB/test/clone.cpp -text libIRDB/test/create_variant.cpp -text libIRDB/test/create_variantir.cpp -text +libIRDB/test/drop_variant.cpp -text +libIRDB/test/fill_in_cfg.cpp -text +libIRDB/test/generate_spri.cpp -text +libIRDB/test/ilr.cpp -text libIRDB/test/list_programs.cpp -text libIRDB/test/print_variant.cpp -text +libIRDB/test/read_variantir.cpp -text tools/Makefile -text tools/cover/Makefile -text tools/cover/cover.cpp -text diff --git a/libIRDB/Makefile b/libIRDB/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..1b6cf62bbaf714d00bc58b07e046f0a18c5aef14 --- /dev/null +++ b/libIRDB/Makefile @@ -0,0 +1,8 @@ + +all: + cd src;make + cd test;make + +clean: + cd src;make clean + cd test;make clean diff --git a/libIRDB/include/address.hpp b/libIRDB/include/address.hpp index 3fef593307b3edaa633284c1bb02822c96e86226..e33d6b346fa53eba8aa6eec6448c8511af30cf77 100644 --- a/libIRDB/include/address.hpp +++ b/libIRDB/include/address.hpp @@ -5,20 +5,27 @@ typedef int virtual_offset_t; class AddressID_t : public BaseObj_t { public: + AddressID_t() : BaseObj_t(NULL), fileID(NOT_IN_DATABASE), virtual_offset(0) + { SetBaseID(NOT_IN_DATABASE); } AddressID_t(db_id_t myid, db_id_t myfileID, virtual_offset_t voff) : BaseObj_t(NULL), fileID(myfileID), virtual_offset(voff) { SetBaseID(myid); } - int GetFileID() const { return fileID; } + db_id_t GetFileID() const { return fileID; } void SetFileID(int thefileID) { fileID=thefileID; } virtual_offset_t GetVirtualOffset() { return virtual_offset; } void SetVirtualOffset(virtual_offset_t voff) { virtual_offset=voff; } void WriteToDB() { assert(0); } + std::string WriteToDB(VariantID_t *vid, db_id_t newid); + private: db_id_t fileID; // The ID of the file virtual_offset_t virtual_offset; // the virtual address(offset) into the file. // May be 0 if this insn doesn't exist // within a file. + + void Register(VariantID_t *vid); + }; diff --git a/libIRDB/include/function.hpp b/libIRDB/include/function.hpp index c32a1ec94ad68c68c6901e5efc10bd4a0b4b19e0..cbe96999c57e8898147e5f63cd459aa5384dd92f 100644 --- a/libIRDB/include/function.hpp +++ b/libIRDB/include/function.hpp @@ -5,7 +5,7 @@ class Function_t : public BaseObj_t Function_t() : BaseObj_t(NULL) {} // create a new function not in the db - Function_t(db_id_t id, std::string name, int size); // create a function that's already in the DB + Function_t(db_id_t id, std::string name, int size, File_t *file); // create a function that's already in the DB std::set<Instruction_t*>& GetInstructions() { return my_insns; } @@ -15,9 +15,15 @@ class Function_t : public BaseObj_t void SetStackFrameSize(int size) { stack_frame_size=size; } void SetName(std::string newname) { name=newname; } - void WriteToDB(); + void SetFile(File_t* file) {my_file=file;} + File_t* GetFile() { return my_file;} + + void WriteToDB(); // we need the variant ID to write into a program. + std::string WriteToDB(VariantID_t *vid, db_id_t newid); + private: + File_t *my_file; std::set<Instruction_t*> my_insns; int stack_frame_size; std::string name; diff --git a/libIRDB/include/instruction.hpp b/libIRDB/include/instruction.hpp index c466cdf120d5242003c776b42bccf3a3472c9a11..d826e3cd2bf59240cf5267e661b7444e7ea1ef7e 100644 --- a/libIRDB/include/instruction.hpp +++ b/libIRDB/include/instruction.hpp @@ -9,16 +9,17 @@ class Instruction_t : public BaseObj_t { public: - Instruction_t(db_id_t id, AddressID_t *addr, Function_t *func, db_id_t orig_id, + Instruction_t(db_id_t id, AddressID_t *addr, Function_t *func, db_id_t file_id, db_id_t orig_id, std::string data, std::string comment, db_id_t doip_id); - AddressID_t* GetAddress() {assert(0);} - Function_t* GetFunction() {assert(0);} - AddressID_t GetOriginalAddressID() {assert(0);} - Instruction_t* &GetFallthrough() {assert(0);} - Instruction_t* GetDataBits() {assert(0);} + AddressID_t* GetAddress() { return my_address; } + Function_t* GetFunction() { return my_function; } + db_id_t GetOriginalAddressID() { return orig_address_id; } + Instruction_t* GetFallthrough() { return fallthrough; } + Instruction_t* GetTarget() { return target; } + std::string GetDataBits() { return data; } - void SetAddress(AddressID_t* ) {assert(0); } + void SetAddress(AddressID_t* newaddr) { my_address=newaddr; } void SetFunction(Function_t*) {assert(0); } void SetOriginalAddressID(AddressID_t ) {assert(0); } void SetFallthrough(Instruction_t* i) {fallthrough=i;} @@ -26,12 +27,16 @@ class Instruction_t : public BaseObj_t void SetDataBits(std::string orig ) {assert(0); } void WriteToDB() { assert(0); } + std::string WriteToDB(VariantID_t *vid, db_id_t newid); + private: AddressID_t *my_address; Function_t *my_function; + db_id_t file_id; // const, should not change. db_id_t orig_address_id; // const, should not change. Instruction_t* fallthrough; Instruction_t* target; std::string data; + std::string comment; }; diff --git a/libIRDB/include/libIRDB.hpp b/libIRDB/include/libIRDB.hpp index 940302eadbc6fc0cd050b6d10facb9f06359c725..72881ad3aab4742b88d8d9db8da1dc9b1e32ad3e 100644 --- a/libIRDB/include/libIRDB.hpp +++ b/libIRDB/include/libIRDB.hpp @@ -9,15 +9,17 @@ namespace libIRDB { +class VariantID_t; // forward decl for many classes + #include <basetypes.hpp> #include <dbinterface.hpp> #include <doip.hpp> #include <baseobj.hpp> #include <address.hpp> #include <instruction.hpp> +#include <file.hpp> #include <function.hpp> #include <variantid.hpp> -#include <file.hpp> #include <variantir.hpp> #include <pqxxdb.hpp> diff --git a/libIRDB/include/variantid.hpp b/libIRDB/include/variantid.hpp index e03f67f8e7fa9233a495bd20e03e429a9505f0ae..371f181bf566040c31bbb7c89df9c4488b1fba03 100644 --- a/libIRDB/include/variantid.hpp +++ b/libIRDB/include/variantid.hpp @@ -10,14 +10,20 @@ class VariantID_t : public BaseObj_t bool IsRegistered(); bool Register(); // accesses DB - VariantID_t Clone(); // accesses DB + VariantID_t* Clone(); // accesses DB void WriteToDB(); + void DropFromDB(); + void SetName(std::string newname) { name=newname;} friend std::ostream& libIRDB::operator<<(std::ostream& out, const VariantID_t& pid); friend class VariantIR_t; + friend class Function_t; + friend class AddressID_t; + friend class Instruction_t; + private: schema_version_t schema_ver; db_id_t orig_pid; // matches pid if this is an "original" diff --git a/libIRDB/src/Makefile b/libIRDB/src/Makefile index d083dea2080cb9a7593f28da6d13da95574608a6..8a9272a71de36f5f99d0c0c68d86dc6e7631633a 100644 --- a/libIRDB/src/Makefile +++ b/libIRDB/src/Makefile @@ -2,7 +2,7 @@ LIB=../lib/libIRDB.a -OBJS=baseobj.o variantid.o pqxxdb.o dbinterface.o function.o variantir.o file.o instruction.o +OBJS=baseobj.o variantid.o pqxxdb.o dbinterface.o function.o variantir.o file.o instruction.o address.o all: $(OBJS) diff --git a/libIRDB/src/address.cpp b/libIRDB/src/address.cpp new file mode 100644 index 0000000000000000000000000000000000000000..18bb13eda8e672a056ee0ee87bbc01bc96ed13e2 --- /dev/null +++ b/libIRDB/src/address.cpp @@ -0,0 +1,28 @@ + +#include <libIRDB.hpp> +#include <utils.hpp> +#include <stdlib.h> +using namespace libIRDB; +using namespace std; + + +string AddressID_t::WriteToDB(VariantID_t *vid, db_id_t newid) +{ + assert(vid); + + if(GetBaseID()==NOT_IN_DATABASE) + SetBaseID(newid); + + string q=string("insert into ")+vid->address_table_name + + string("(address_id , file_id , vaddress_offset , doip_id)") + + string(" values ") + + string("(") + + string("'") + to_string(GetBaseID()) + string("', ") + + string("'") + to_string(fileID) + string("', ") + + string("'") + to_string(virtual_offset) + string("', ") + + string("'") + to_string(GetDoipID()) + string("' ") + + string(");"); + + return q; +} + diff --git a/libIRDB/src/function.cpp b/libIRDB/src/function.cpp index d3e5888e5e49792ac01e7ef7afdc2549d58a1b30..905d35622e979911526ef778298f19c5b3f097e4 100644 --- a/libIRDB/src/function.cpp +++ b/libIRDB/src/function.cpp @@ -2,11 +2,12 @@ #include <utils.hpp> #include <stdlib.h> using namespace libIRDB; +using namespace std; -Function_t::Function_t(db_id_t id, std::string myname, int size) - : BaseObj_t(NULL) +Function_t::Function_t(db_id_t id, std::string myname, int size, File_t* file) + : BaseObj_t(NULL), my_file(file) { SetBaseID(id); name=myname; @@ -16,5 +17,25 @@ Function_t::Function_t(db_id_t id, std::string myname, int size) void Function_t::WriteToDB() { -assert(0); + assert(0); +} + +string Function_t::WriteToDB(VariantID_t *vid, db_id_t newid) +{ + assert(vid); + assert(my_file); + + if(GetBaseID()==NOT_IN_DATABASE) + SetBaseID(newid); + + string q=string("insert into ")+vid->function_table_name + + string(" (function_id, file_id, name, stack_frame_size, doip_id) ")+ + string(" VALUES (") + + string("'") + to_string(GetBaseID()) + string("', ") + + string("'") + to_string(my_file->GetBaseID()) + string("', ") + + string("'") + name + string("', ") + + string("'") + to_string(stack_frame_size) + string("', ") + + string("'") + to_string(GetDoipID()) + string("') ; ") ; + + return q; } diff --git a/libIRDB/src/instruction.cpp b/libIRDB/src/instruction.cpp new file mode 100644 index 0000000000000000000000000000000000000000..55033e5d58938656d6c1f3ca2cab973d538c221c --- /dev/null +++ b/libIRDB/src/instruction.cpp @@ -0,0 +1,69 @@ + +#include <libIRDB.hpp> +#include <utils.hpp> +#include <stdlib.h> +using namespace libIRDB; +using namespace std; + +Instruction_t::Instruction_t(db_id_t id, + AddressID_t *addr, + Function_t *func, + db_id_t my_file_id, + db_id_t orig_id, + std::string thedata, + std::string my_comment, + db_id_t doip_id) : + + BaseObj_t(NULL), + data(thedata), + comment(my_comment), + file_id(my_file_id) +{ + SetBaseID(id); + my_address=addr; + my_function=func; + orig_address_id=orig_id; + fallthrough=NULL; + target=NULL; +} + + +string Instruction_t::WriteToDB(VariantID_t *vid, db_id_t newid) +{ + assert(vid); + assert(my_address); + + if(GetBaseID()==NOT_IN_DATABASE) + SetBaseID(newid); + + db_id_t func_id=NOT_IN_DATABASE; + if(my_function) + func_id=my_function->GetBaseID(); + + db_id_t ft_id=NOT_IN_DATABASE; + if(fallthrough) + ft_id=fallthrough->GetBaseID(); + + db_id_t targ_id=NOT_IN_DATABASE; + if(target) + targ_id=target->GetBaseID(); + + string q= + string("insert into ")+vid->instruction_table_name + + string(" (instruction_id, address_id, parent_function_id, file_id, orig_address_id, fallthrough_address_id, target_address_id, data, comment, doip_id) ")+ + string(" VALUES (") + + string("'") + to_string(GetBaseID()) + string("', ") + + string("'") + to_string(my_address->GetBaseID()) + string("', ") + + string("'") + to_string(func_id) + string("', ") + + string("'") + to_string(file_id) + string("', ") + + string("'") + to_string(orig_address_id) + string("', ") + + string("'") + to_string(ft_id) + string("', ") + + string("'") + to_string(targ_id) + string("', ") + + string("E'") + pqxx::escape_binary(data) + "'::bytea" + string(" , ") + // no ticks for this field + // also need to append ::bytea + string("'") + comment + string("', ") + + string("'") + to_string(GetDoipID()) + string("') ; ") ; + + return q; +} + diff --git a/libIRDB/src/pqxxdb.cpp b/libIRDB/src/pqxxdb.cpp index f122d6e92ebd2eaccb69bbd2a45641edf898bd56..64ed9448e7b5cb106d0fb067943530dd26fa40f9 100644 --- a/libIRDB/src/pqxxdb.cpp +++ b/libIRDB/src/pqxxdb.cpp @@ -4,6 +4,7 @@ #include <string> using namespace libIRDB; +using namespace std; pqxxDB_t::pqxxDB_t() : DBinterface_t(), conn(), txn(conn) { @@ -22,7 +23,14 @@ void pqxxDB_t::MoveToNextRow() } std::string pqxxDB_t::GetResultColumn(std::string colname) { - return results_iter[colname].as<std::string>(); + if(results_iter[colname].is_null()) + return std::string(""); + + pqxx::binarystring bin_str(results_iter[colname]); + + return bin_str.str(); + +// return results_iter[colname].as<std::string>(); } bool pqxxDB_t::IsDone() { diff --git a/libIRDB/src/variantid.cpp b/libIRDB/src/variantid.cpp index 1ed0554a66b02628515bfaa0018f7685b31ad24e..3119624b24e25841ef53def27263266fc2f3bbf5 100644 --- a/libIRDB/src/variantid.cpp +++ b/libIRDB/src/variantid.cpp @@ -4,6 +4,7 @@ #include <utils.hpp> #include <stdlib.h> using namespace libIRDB; +using namespace std; /* @@ -27,9 +28,9 @@ void VariantID_t::CreateTables() dbintr->IssueQuery( "CREATE TABLE " + address_table_name + " ( " - " address_id integer PRIMARY KEY, " + " address_id SERIAL PRIMARY KEY, " " file_id integer REFERENCES file_info, " - " vaddress_offset text, " + " vaddress_offset integer, " " doip_id integer DEFAULT -1 " ");" ); @@ -37,7 +38,7 @@ void VariantID_t::CreateTables() dbintr->IssueQuery( "CREATE TABLE " + function_table_name + " ( " - " function_id integer PRIMARY KEY, " + " function_id SERIAL PRIMARY KEY, " " file_id integer REFERENCES file_info, " " name text, " " stack_frame_size integer, " @@ -48,6 +49,7 @@ void VariantID_t::CreateTables() dbintr->IssueQuery( "CREATE TABLE " + instruction_table_name + " ( " + "instruction_id SERIAL PRIMARY KEY, " "address_id integer REFERENCES " + address_table_name + ", " + "parent_function_id integer, " "file_id integer REFERENCES file_info, " @@ -137,13 +139,75 @@ bool VariantID_t::Register() CreateTables(); } -VariantID_t VariantID_t::Clone() +VariantID_t* VariantID_t::Clone() { assert(IsRegistered()); // cannot clone something that's not registered - VariantID_t ret; - ret.orig_pid=orig_pid; - ret.name=name+"_cloneof"+to_string(GetBaseID()); + // create the new program id + VariantID_t *ret=new VariantID_t; + + // set the inhereted fields + ret->SetName(name+"_cloneof"+to_string(GetBaseID())); + ret->orig_pid=orig_pid; + + // register the new VID to the database. + ret->Register(); + // and write it to the database + ret->WriteToDB(); + + // clone the tables + std::string q; + + // first drop the old values + q="drop table "; + q+=ret->instruction_table_name; + q+=" ; "; + dbintr->IssueQuery(q); + + q="drop table "; + q+=ret->address_table_name; + q+=" ; "; + dbintr->IssueQuery(q); + + q="drop table "; + q+=ret->function_table_name; + q+=" ; "; + dbintr->IssueQuery(q); + + + // next issue SQL to clone each table + q="select * into "; + q+=ret->address_table_name; + q+=" from "; + q+=address_table_name; + q+=" ;"; + dbintr->IssueQuery(q); + + q="select * into "; + q+=ret->instruction_table_name; + q+=" from "; + q+=instruction_table_name; + q+=" ;"; + dbintr->IssueQuery(q); + + q="select * into "; + q+=ret->function_table_name; + q+=" from "; + q+=function_table_name; + q+=" ;"; + dbintr->IssueQuery(q); + + + // lastly update the variant_dependency table to make a copy of the rows in which + // the old variant depended upon. The new rows will indicate that the + // new variant also depends on those files + q="insert into variant_dependency (variant_id, file_id, doip_id) select '"; + q+=to_string(ret->GetBaseID()); + q+="', file_id, doip_id from variant_dependency where variant_id='"; + q+=to_string(GetBaseID()); + q+="';"; + dbintr->IssueQuery(q); + return ret; } @@ -164,7 +228,6 @@ void VariantID_t::WriteToDB() dbintr->IssueQuery(q); } - std::ostream& libIRDB::operator<<(std::ostream& out, const VariantID_t& pid) { @@ -179,3 +242,23 @@ std::ostream& libIRDB::operator<<(std::ostream& out, const VariantID_t& pid) return out; } + +void VariantID_t::DropFromDB() +{ + assert(IsRegistered()); + + string q; + + q =string("drop table ")+instruction_table_name + string(" cascade;"); + q+=string("drop table ")+address_table_name + string(" cascade;"); + q+=string("drop table ")+function_table_name + string(" cascade;"); + q+=string("delete from variant_dependency where variant_id = '") + to_string(GetBaseID()) + string("';"); + q+=string("delete from variant_info where variant_id = '") + to_string(GetBaseID()) + string("';"); + + dbintr->IssueQuery(q); + + SetBaseID(NOT_IN_DATABASE); + orig_pid=NOT_IN_DATABASE; + name=instruction_table_name=address_table_name=function_table_name=string(""); + schema_ver=CURRENT_SCHEMA; +} diff --git a/libIRDB/src/variantir.cpp b/libIRDB/src/variantir.cpp index 010f9b97c2c37c35afccb78991e38984e3e6713e..4331417155cb93d26be94f0d05562fa10db1995e 100644 --- a/libIRDB/src/variantir.cpp +++ b/libIRDB/src/variantir.cpp @@ -4,6 +4,7 @@ #include <stdlib.h> #include <map> using namespace libIRDB; +using namespace std; // Create a Variant from the database VariantIR_t::VariantIR_t(VariantID_t newprogid) : BaseObj_t(NULL) @@ -38,15 +39,15 @@ std::map<db_id_t,File_t*> VariantIR_t::ReadFilesFromDB() { // file_info.file_id, file_info.url, file_info.hash, file_info.arch, file_info.type, file_info.doip_id - db_id_t file_id=atoi(dbintr->GetResultColumn("file_info.file_id").c_str()); - std::string url=dbintr->GetResultColumn("file_info.url"); - std::string hash=dbintr->GetResultColumn("file_info.hash"); - std::string type=dbintr->GetResultColumn("file_info.type"); - db_id_t doipid=atoi(dbintr->GetResultColumn("file_info.doip_id").c_str()); + db_id_t file_id=atoi(dbintr->GetResultColumn("file_id").c_str()); + std::string url=dbintr->GetResultColumn("url"); + std::string hash=dbintr->GetResultColumn("hash"); + std::string type=dbintr->GetResultColumn("type"); + db_id_t doipid=atoi(dbintr->GetResultColumn("doip_id").c_str()); File_t *newfile=new File_t(file_id,url,hash,type,doipid); -std::cout<<"Found file "<<file_id<<"."<<std::endl; +//std::cout<<"Found file "<<file_id<<"."<<std::endl; idMap[file_id]=newfile; @@ -80,9 +81,9 @@ std::map<db_id_t,Function_t*> VariantIR_t::ReadFuncsFromDB int sfsize=atoi(dbintr->GetResultColumn("stack_frame_size").c_str()); db_id_t doipid=atoi(dbintr->GetResultColumn("doip_id").c_str()); - Function_t *newfunc=new Function_t(fid,name,sfsize); + Function_t *newfunc=new Function_t(fid,name,sfsize, fileMap[file_id]); -std::cout<<"Found function "<<name<<"."<<std::endl; +//std::cout<<"Found function "<<name<<"."<<std::endl; idMap[fid]=newfunc; @@ -119,7 +120,7 @@ std::map<db_id_t,AddressID_t*> VariantIR_t::ReadAddrsFromDB ( std::map< AddressID_t *newaddr=new AddressID_t(aid,file_id,vaddr); -std::cout<<"Found address "<<aid<<"."<<std::endl; +//std::cout<<"Found address "<<aid<<"."<<std::endl; idMap[aid]=newaddr; @@ -141,7 +142,7 @@ std::map<db_id_t,Instruction_t*> VariantIR_t::ReadInsnsFromDB ( std::map<db std::map<db_id_t,db_id_t> fallthroughs; std::map<db_id_t,db_id_t> targets; - std::string q= "select * from " + progid.address_table_name + " ; "; + std::string q= "select * from " + progid.instruction_table_name + " ; "; dbintr->IssueQuery(q); @@ -166,7 +167,7 @@ std::map<db_id_t,Instruction_t*> VariantIR_t::ReadInsnsFromDB ( std::map<db db_id_t file_id=atoi(dbintr->GetResultColumn("file_id").c_str()); db_id_t orig_address_id=atoi(dbintr->GetResultColumn("orig_address_id").c_str()); db_id_t fallthrough_address_id=atoi(dbintr->GetResultColumn("fallthrough_address_id").c_str()); - db_id_t targ_address_id=atoi(dbintr->GetResultColumn("targ_address_id").c_str()); + db_id_t targ_address_id=atoi(dbintr->GetResultColumn("target_address_id").c_str()); std::string data=(dbintr->GetResultColumn("data")); std::string comment=(dbintr->GetResultColumn("comment")); db_id_t doipid=atoi(dbintr->GetResultColumn("doip_id").c_str()); @@ -174,13 +175,14 @@ std::map<db_id_t,Instruction_t*> VariantIR_t::ReadInsnsFromDB ( std::map<db Instruction_t *newinsn=new Instruction_t(instruction_id, addrMap[aid], funcMap[parent_func_id], + file_id, orig_address_id, data, comment, doipid); if(funcMap[parent_func_id]) funcMap[parent_func_id]->GetInstructions().insert(newinsn); -std::cout<<"Found address "<<aid<<"."<<std::endl; +//std::cout<<"Found address "<<aid<<"."<<std::endl; idMap[instruction_id]=newinsn; fallthroughs[instruction_id]=fallthrough_address_id; @@ -209,6 +211,27 @@ std::cout<<"Found address "<<aid<<"."<<std::endl; void VariantIR_t::WriteToDB() { + + dbintr->IssueQuery(string("TRUNCATE TABLE ")+ progid.instruction_table_name + string(" cascade;")); + dbintr->IssueQuery(string("TRUNCATE TABLE ")+ progid.function_table_name + string(" cascade;")); + dbintr->IssueQuery(string("TRUNCATE TABLE ")+ progid.address_table_name + string(" cascade;")); + + + string q=string(""); + db_id_t j=0; + for(std::set<Function_t*>::const_iterator i=funcs.begin(); i!=funcs.end(); ++i, ++j) + q+=(*i)->WriteToDB(&progid,j); + dbintr->IssueQuery(q); + + q=string(""); + for(std::set<AddressID_t*>::const_iterator i=addrs.begin(); i!=addrs.end(); ++i,++j) + q+=(*i)->WriteToDB(&progid,j); + dbintr->IssueQuery(q); + + q=string(""); + for(std::set<Instruction_t*>::const_iterator i=insns.begin(); i!=insns.end(); ++i,++j) + q+=(*i)->WriteToDB(&progid,j); + dbintr->IssueQuery(q); } diff --git a/libIRDB/test/Makefile b/libIRDB/test/Makefile index 2afb67fc0c2ee66be4b125d6b907aed67f81a21c..7264cf049783b085c5b6d92a8979d28fadd9d5a5 100644 --- a/libIRDB/test/Makefile +++ b/libIRDB/test/Makefile @@ -1,14 +1,14 @@ .SUFFIXES: .exe .cpp -PROGS=print_variant.exe list_programs.exe create_variant.exe create_variantir.exe +PROGS=print_variant.exe list_programs.exe create_variant.exe create_variantir.exe read_variantir.exe clone.exe ilr.exe drop_variant.exe generate_spri.exe fill_in_cfg.exe all: $(PROGS) $(PROGS): ../lib/libIRDB.a .cpp.exe: $< ../lib/libIRDB.a - g++ -g $< -I../include/ -L ../lib/ -lIRDB -lpqxx -o $@ + g++ -g $< -I../include/ -I../../beaengine/include -L ../lib/ -lIRDB -lpqxx -L ../../beaengine/lib/Linux.gnu.Debug -lBeaEngine_s_d -o $@ #print_variant: print_variant.cpp ../lib/libIRDB.a # g++ -g print_variant.cpp -I../include/ -L ../lib/ -lIRDB -lpqxx -o print_variant diff --git a/libIRDB/test/clone.cpp b/libIRDB/test/clone.cpp new file mode 100644 index 0000000000000000000000000000000000000000..24c3d965fd1a117fbbfbf5f0ab7234922ba6ae5d --- /dev/null +++ b/libIRDB/test/clone.cpp @@ -0,0 +1,51 @@ + + +#include <libIRDB.hpp> +#include <iostream> +#include <stdlib.h> + +using namespace libIRDB; +using namespace std; + +main(int argc, char* argv[]) +{ + + if(argc!=2) + { + cerr<<"Usage: clone <vid>"<<endl; + exit(-1); + } + + + /* setup the interface to the sql server */ + pqxxDB_t pqxx_interface; + BaseObj_t::SetInterface(&pqxx_interface); + + + VariantID_t *pidp=NULL; + VariantID_t *newpidp=NULL; + try + { + pidp=new VariantID_t(atoi(argv[1])); + + assert(pidp->IsRegistered()==true); + + newpidp=pidp->Clone(); + + assert(newpidp->IsRegistered()==true); + + cout<<"Cloned Variant is: "<<*newpidp << endl; + + // commit the changes to the db if all went well + pqxx_interface.Commit(); + + } + catch (DatabaseError_t pnide) + { + cout<<"Unexpected database error: "<<pnide<<endl; + exit(-1); + } + + delete pidp; + delete newpidp; +} diff --git a/libIRDB/test/drop_variant.cpp b/libIRDB/test/drop_variant.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b8e6712cd5ca188694f31fb2f6f6b395aa5a414e --- /dev/null +++ b/libIRDB/test/drop_variant.cpp @@ -0,0 +1,49 @@ + + +#include <libIRDB.hpp> +#include <iostream> +#include <stdlib.h> + +using namespace libIRDB; +using namespace std; + +main(int argc, char* argv[]) +{ + + if(argc!=2) + { + cerr<<"Usage: simple (<pid>)"<<endl; + exit(-1); + } + + + /* setup the interface to the sql server */ + pqxxDB_t pqxx_interface; + BaseObj_t::SetInterface(&pqxx_interface); + + + VariantID_t *pidp=NULL; + try + { + pidp=new VariantID_t(atoi(argv[1])); + cout<<"Variant "<< argv[1]<< " found in db: "<<*pidp << ". Dropping..."<< endl; + pidp->DropFromDB(); + pqxx_interface.Commit(); + } + catch (DatabaseError_t pnide) + { + if(pnide.GetErrorCode()==DatabaseError_t::VariantNotInDatabase) + { + cout<<"Variant "<< argv[1]<< " not found in db"<<endl; + exit(-2); + } + else + { + cout<<"Unexpected database error: "<<pnide<<endl; + exit(-1); + } + } + + cout<<"Done!"<<endl; + delete pidp; +} diff --git a/libIRDB/test/fill_in_cfg.cpp b/libIRDB/test/fill_in_cfg.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2a80985f2857fffebd3b56f6c56fa173c2db1ca1 --- /dev/null +++ b/libIRDB/test/fill_in_cfg.cpp @@ -0,0 +1,244 @@ + + +#include <libIRDB.hpp> +#include <iostream> +#include <stdlib.h> +#include <string.h> +#include <map> +#include <assert.h> + +#include "beaengine/BeaEngine.h" + +int odd_target_count=0; +int bad_target_count=0; +int bad_fallthrough_count=0; + +using namespace libIRDB; +using namespace std; + +void populate_instruction_map + ( + map< pair<db_id_t,virtual_offset_t>, Instruction_t*> &insnMap, + VariantIR_t *virp + ) +{ + for( + set<Instruction_t*>::const_iterator it=virp->GetInstructions().begin(); + it!=virp->GetInstructions().end(); + ++it + ) + { + Instruction_t *insn=*it; + db_id_t fileID=insn->GetAddress()->GetFileID(); + virtual_offset_t vo=insn->GetAddress()->GetVirtualOffset(); + + pair<db_id_t,virtual_offset_t> p(fileID,vo); + + assert(insnMap[p]==NULL); + insnMap[p]=insn; + } + +} + +void set_fallthrough + ( + map< pair<db_id_t,virtual_offset_t>, Instruction_t*> &insnMap, + DISASM *disasm, Instruction_t *insn, VariantIR_t *virp + ) +{ + assert(disasm); + assert(insn); + + if(insn->GetFallthrough()) + return; + + // check for branches with targets + if( + (disasm->Instruction.BranchType==JmpType) || // it is a unconditional branch + (disasm->Instruction.BranchType==RetType) // or a return + ) + { + // this is a branch with no fallthrough instruction + return; + } + + /* get the address of the next instrution */ + + int virtual_offset=insn->GetAddress()->GetVirtualOffset() + insn->GetDataBits().size(); + + /* create a pair of offset/file */ + pair<db_id_t,virtual_offset_t> p(insn->GetAddress()->GetFileID(),virtual_offset); + + /* lookup the target insn from the map */ + Instruction_t *fallthrough_insn=insnMap[p]; + + /* sanity, note we may see odd control transfers to 0x0 */ + if(fallthrough_insn==NULL && virtual_offset!=0) + { + cout<<"Cannot set fallthrough for "<<std::hex<<insn->GetAddress()->GetVirtualOffset()<<"."<<endl; + bad_fallthrough_count++; + } + + /* set the target for this insn */ + if(fallthrough_insn!=0) + insn->SetFallthrough(fallthrough_insn); + +} + + +void set_target + ( + map< pair<db_id_t,virtual_offset_t>, Instruction_t*> &insnMap, + DISASM *disasm, Instruction_t *insn, VariantIR_t *virp + ) +{ + + assert(insn); + assert(disasm); + + if(insn->GetTarget()) + return; + + // check for branches with targets + if( + (disasm->Instruction.BranchType!=0) && // it is a branch + (disasm->Instruction.BranchType!=RetType) && // and not a return + (disasm->Argument1.ArgType & CONSTANT_TYPE)!=0 // and has a constant argument type 1 + ) + { +// cout<<"Found direct jump with addr=" << insn->GetAddress()->GetVirtualOffset() << +// " disasm="<<disasm->CompleteInstr<<" ArgMnemonic="<< +// disasm->Argument1.ArgMnemonic<<"."<<endl; + + /* get the offset */ + int virtual_offset=strtoul(disasm->Argument1.ArgMnemonic, NULL, 16); + + /* create a pair of offset/file */ + pair<db_id_t,virtual_offset_t> p(insn->GetAddress()->GetFileID(),virtual_offset); + + /* lookup the target insn from the map */ + Instruction_t *target_insn=insnMap[p]; + + /* sanity, note we may see odd control transfers to 0x0 */ + if(target_insn==NULL && virtual_offset!=0) + { + unsigned char first_byte=0; + if(insn->GetFallthrough()) + first_byte=(insn->GetFallthrough()->GetDataBits().c_str())[0]; + int jump_dist=virtual_offset-(insn->GetAddress()->GetVirtualOffset()+(insn->GetDataBits()).size()); + if( + // jump 1 byte forward + jump_dist == 1 && + + // and we calculated the fallthrough + insn->GetFallthrough()!=NULL && + + // and the fallthrough starts with a lock prefix + first_byte==0xf0 + ) + { + odd_target_count++; + } + else + { + cout<<"Cannot set target for "<<std::hex<<insn->GetAddress()->GetVirtualOffset()<<"."<<endl; + bad_target_count++; + } + } + + /* set the target for this insn */ + if(target_insn!=0) + insn->SetTarget(target_insn); + + } +} + +void fill_in_cfg(VariantIR_t *virp) +{ + + map< pair<db_id_t,virtual_offset_t>, Instruction_t*> insnMap; + populate_instruction_map(insnMap, virp); + + cout << "Found "<<virp->GetInstructions().size()<<" instructions." <<endl; + + for( + set<Instruction_t*>::const_iterator it=virp->GetInstructions().begin(); + it!=virp->GetInstructions().end(); + ++it + ) + { + Instruction_t *insn=*it; + DISASM disasm; + memset(&disasm, 0, sizeof(DISASM)); + + disasm.Options = NasmSyntax + PrefixedNumeral; + disasm.Archi = 32; + disasm.EIP = (UIntPtr) insn->GetDataBits().c_str(); + disasm.VirtualAddr = insn->GetAddress()->GetVirtualOffset(); + int instr_len = Disasm(&disasm); + + assert(instr_len==insn->GetDataBits().size()); + + set_fallthrough(insnMap, &disasm, insn, virp); + set_target(insnMap, &disasm, insn, virp); + + } + if(bad_target_count>0) + cout<<std::dec<<"Found "<<bad_target_count<<" bad targets."<<endl; + if(bad_target_count>0) + cout<<"Found "<<bad_fallthrough_count<<" bad fallthroughs."<<endl; + if(odd_target_count>0) + cout<<std::dec<<"Found "<<odd_target_count<<" odd targets (to jump over lock prefix)."<<endl; + +} + +main(int argc, char* argv[]) +{ + + if(argc!=2) + { + cerr<<"Usage: create_variant <id>"<<endl; + exit(-1); + } + + + + + VariantID_t *pidp=NULL; + VariantIR_t * virp=NULL; + + try + { + /* setup the interface to the sql server */ + pqxxDB_t pqxx_interface; + BaseObj_t::SetInterface(&pqxx_interface); + + pidp=new VariantID_t(atoi(argv[1])); + + assert(pidp->IsRegistered()==true); + + cout<<"New Variant, after reading registration, is: "<<*pidp << endl; + + // read the db + virp=new VariantIR_t(*pidp); + + + fill_in_cfg(virp); + + // write the DB back and commit our changes + virp->WriteToDB(); + pqxx_interface.Commit(); + + } + catch (DatabaseError_t pnide) + { + cout<<"Unexpected database error: "<<pnide<<endl; + exit(-1); + } + + assert(virp && pidp); + + + delete pidp; + delete virp; +} diff --git a/libIRDB/test/generate_spri.cpp b/libIRDB/test/generate_spri.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1d0b7711d99599cbe65f925247b53473235dada4 --- /dev/null +++ b/libIRDB/test/generate_spri.cpp @@ -0,0 +1,73 @@ + + +#include <libIRDB.hpp> +#include <iostream> +#include <stdlib.h> + +using namespace libIRDB; +using namespace std; + +main(int argc, char* argv[]) +{ + + if(argc!=2) + { + cerr<<"Usage: ilr <id>"<<endl; + exit(-1); + } + + VariantID_t *pidp=NULL; + VariantIR_t *virp=NULL; + + /* setup the interface to the sql server */ + pqxxDB_t pqxx_interface; + BaseObj_t::SetInterface(&pqxx_interface); + + cout<<"Reading variant "<<string(argv[1])<<" from database." << endl; + try + { + + pidp=new VariantID_t(atoi(argv[1])); + + assert(pidp->IsRegistered()==true); + + // read the db + virp=new VariantIR_t(*pidp); + + + } + catch (DatabaseError_t pnide) + { + cout<<"Unexpected database error: "<<pnide<<endl; + exit(-1); + } + + assert(virp && pidp); + + cout<<"Applying ILR to variant "<<*pidp<< "." <<endl; + + set<AddressID_t*> newaddressset; + for( + set<Instruction_t*>::const_iterator it=virp->GetInstructions().begin(); + it!=virp->GetInstructions().end(); + ++it + ) + { + Instruction_t* insn=*it; + AddressID_t *newaddr=new AddressID_t; + newaddr->SetFileID(insn->GetAddress()->GetFileID()); + insn->SetAddress(newaddr); + newaddressset.insert(newaddr); + } + + virp->GetAddresses()=newaddressset; + + cout<<"Writing variant "<<*pidp<<" back to database." << endl; + virp->WriteToDB(); + + pqxx_interface.Commit(); + cout<<"Done!"<<endl; + + delete pidp; + delete virp; +} diff --git a/libIRDB/test/ilr.cpp b/libIRDB/test/ilr.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1d0b7711d99599cbe65f925247b53473235dada4 --- /dev/null +++ b/libIRDB/test/ilr.cpp @@ -0,0 +1,73 @@ + + +#include <libIRDB.hpp> +#include <iostream> +#include <stdlib.h> + +using namespace libIRDB; +using namespace std; + +main(int argc, char* argv[]) +{ + + if(argc!=2) + { + cerr<<"Usage: ilr <id>"<<endl; + exit(-1); + } + + VariantID_t *pidp=NULL; + VariantIR_t *virp=NULL; + + /* setup the interface to the sql server */ + pqxxDB_t pqxx_interface; + BaseObj_t::SetInterface(&pqxx_interface); + + cout<<"Reading variant "<<string(argv[1])<<" from database." << endl; + try + { + + pidp=new VariantID_t(atoi(argv[1])); + + assert(pidp->IsRegistered()==true); + + // read the db + virp=new VariantIR_t(*pidp); + + + } + catch (DatabaseError_t pnide) + { + cout<<"Unexpected database error: "<<pnide<<endl; + exit(-1); + } + + assert(virp && pidp); + + cout<<"Applying ILR to variant "<<*pidp<< "." <<endl; + + set<AddressID_t*> newaddressset; + for( + set<Instruction_t*>::const_iterator it=virp->GetInstructions().begin(); + it!=virp->GetInstructions().end(); + ++it + ) + { + Instruction_t* insn=*it; + AddressID_t *newaddr=new AddressID_t; + newaddr->SetFileID(insn->GetAddress()->GetFileID()); + insn->SetAddress(newaddr); + newaddressset.insert(newaddr); + } + + virp->GetAddresses()=newaddressset; + + cout<<"Writing variant "<<*pidp<<" back to database." << endl; + virp->WriteToDB(); + + pqxx_interface.Commit(); + cout<<"Done!"<<endl; + + delete pidp; + delete virp; +} diff --git a/libIRDB/test/read_variantir.cpp b/libIRDB/test/read_variantir.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8960624815f6654329c64c617c7a2e0d49bbd920 --- /dev/null +++ b/libIRDB/test/read_variantir.cpp @@ -0,0 +1,62 @@ + + +#include <libIRDB.hpp> +#include <iostream> +#include <stdlib.h> + +using namespace libIRDB; +using namespace std; + +main(int argc, char* argv[]) +{ + + if(argc!=2) + { + cerr<<"Usage: create_variant <id>"<<endl; + exit(-1); + } + + + + + VariantID_t *pidp=NULL; + VariantIR_t * virp=NULL; + try + { + /* setup the interface to the sql server */ + pqxxDB_t pqxx_interface; + BaseObj_t::SetInterface(&pqxx_interface); + + pidp=new VariantID_t(atoi(argv[1])); + + assert(pidp->IsRegistered()==true); + + cout<<"New Variant, after reading registration, is: "<<*pidp << endl; + + // read the db + virp=new VariantIR_t(*pidp); + + + } + catch (DatabaseError_t pnide) + { + cout<<"Unexpected database error: "<<pnide<<endl; + exit(-1); + } + + assert(virp && pidp); + + for( + set<Instruction_t*>::const_iterator it=virp->GetInstructions().begin(); + it!=virp->GetInstructions().end(); + ++it + ) + { + Instruction_t* insn=*it; + cout<<"Found insn at addr:" << std::hex << insn->GetAddress()->GetVirtualOffset() << endl; + } + + + delete pidp; + delete virp; +} diff --git a/tools/meds2pdb/Makefile b/tools/meds2pdb/Makefile index f90be8e889aca8f67b9a5397a97bbf09a4b879a5..ec1b2cf6d5461954876b924ea25bf088eb684b84 100644 --- a/tools/meds2pdb/Makefile +++ b/tools/meds2pdb/Makefile @@ -33,5 +33,5 @@ clean: rm -f *.o core meds2pdb meds2pdb: $(OBJS) meds2pdb.cpp - $(CC) -o meds2pdb $(INCLUDE) meds2pdb.cpp $(OBJS) $(LIBS) + $(CC) $(CFLAGS) -o meds2pdb $(INCLUDE) meds2pdb.cpp $(OBJS) $(LIBS) diff --git a/tools/meds2pdb/meds2pdb.cpp b/tools/meds2pdb/meds2pdb.cpp index c90d0e1bd30edce49a21c0c01a892d6675f36330..19e55142c36814d0f9615ffc801a0fd2a086c824 100644 --- a/tools/meds2pdb/meds2pdb.cpp +++ b/tools/meds2pdb/meds2pdb.cpp @@ -39,7 +39,7 @@ void insert_instructions(string programName, int fileID, vector<wahoo::Instructi // (1) get address, insert into address table // (2) populate instruction table - const int STRIDE = 40; + const int STRIDE = 1000; int count = 0; for (int i = 0; i < instructions.size(); i += STRIDE) @@ -51,7 +51,7 @@ void insert_instructions(string programName, int fileID, vector<wahoo::Instructi string instructionTable = programName + "_" + "instruction"; string query2 = "INSERT INTO " + instructionTable; - query2 += " (address_id, parent_function_id, file_id, orig_address_id, data, asm) VALUES "; + query2 += " (address_id, parent_function_id, file_id, orig_address_id, data, comment) VALUES "; for (int j = i; j < i + STRIDE; ++j) { @@ -66,7 +66,7 @@ void insert_instructions(string programName, int fileID, vector<wahoo::Instructi query += "("; query += txn.quote(j) + ","; query += txn.quote(fileID) + ","; - sprintf(buf,"0x%08X", addr); + sprintf(buf,"%d", addr); query += txn.quote(string(buf)); query += ")"; @@ -136,6 +136,7 @@ int main(int argc, char **argv) char *elfFile = argv[2]; char *md5hash = argv[3]; char *annotFile = argv[4]; + char *spriFile=strdup("spri.out"); cout << "program name:" << programName << endl; cout << "elf file:" << elfFile << endl; @@ -145,7 +146,7 @@ int main(int argc, char **argv) connection conn; work txn(conn); - Rewriter *rewriter = new Rewriter(elfFile, annotFile, "spri.out"); + Rewriter *rewriter = new Rewriter(elfFile, annotFile, spriFile); int fileID = get_file_id(programName, md5hash); if (fileID < 0) @@ -182,7 +183,6 @@ int main(int argc, char **argv) int functionSize = f->getSize(); int function_id = j; - cout << functionName << " size: " << functionSize << endl; if (j != i) query += ","; query += "("; query += txn.quote(function_id) + ","; diff --git a/xform/rewriter.cpp b/xform/rewriter.cpp index 47d1344a49e82cf73a2a57ce47fd088a51e4a33d..2f5737688bd782f52df289ed9b214e348e0b9bb8 100644 --- a/xform/rewriter.cpp +++ b/xform/rewriter.cpp @@ -17,6 +17,7 @@ Rewriter::Rewriter(char *p_elfPath, char *p_annotationFilePath, char *p_spriFile // parse file and build up all the data structures readAnnotationFile(p_annotationFilePath); + readElfFile(p_elfPath); } Rewriter::~Rewriter() @@ -279,6 +280,14 @@ void Rewriter::readAnnotationFile(char p_filename[]) assert(strcmp(scope,"LOCAL")==0); + if (!m_instructions[addr]) + { + // unknown size, unknown function + wahoo::Instruction* instr = new wahoo::Instruction(addr, -1, NULL); + m_instructions[addr] = instr; + } + + switch(annot_type) { /* No Meta Data Updates */ @@ -529,6 +538,32 @@ any esp access outside this region (esp + K) >= (esp + size) can be xformed fclose(fin); // for each instruction in a function, dissassemble and stash away assembly string + dissassemble(); +} + +/* +* Read MEDS annotation file and populate relevant hash table & data structures +*/ +void Rewriter::readElfFile(char p_filename[]) +{ + char buf[1000]; + sprintf(buf, "objdump -d --prefix-addresses %s | grep \"^[0-9]\"", p_filename); + FILE* pin=popen(buf, "r"); + int addr; + + assert(pin); + + fscanf(pin, "%x", &addr); + fgets(buf,sizeof(buf),pin); + do + { + if(m_instructions[addr]==NULL) + m_instructions[addr]=new wahoo::Instruction(addr,-1,NULL); + fscanf(pin,"%x", &addr); + fgets(buf,sizeof(buf),pin); + } while(!feof(pin)); + + pclose(pin); dissassemble(); } @@ -539,42 +574,31 @@ any esp access outside this region (esp + K) >= (esp + size) can be xformed */ void Rewriter::dissassemble() { - // for every instruction, grab from ELF - // disassemble + // for every instruction, grab from ELF + // disassemble - fprintf(stderr,"Rewriter::dissassemble(): #functions: %d 0x%x\n", m_functions.size(), (int*)&m_functions); - for (map<app_iaddr_t, wahoo::Function*>::iterator it = m_functions.begin(); it != m_functions.end(); ++it) - { - app_iaddr_t addr = it->first; - wahoo::Function* f = it->second; + vector<wahoo::Instruction*> instructions=getAllInstructions(); - for (int j = 0; j < f->getInstructions().size(); ++j) - { - wahoo::Instruction *instr = f->getInstructions()[j]; + for (int j = 0; j < instructions.size(); ++j) + { + wahoo::Instruction *instr = instructions[j]; - // disassemble using BeaEngine - DISASM disasm; - memset(&disasm, 0, sizeof(DISASM)); + // disassemble using BeaEngine + DISASM disasm; + memset(&disasm, 0, sizeof(DISASM)); -// disasm.Options = Tabulation + NasmSyntax + PrefixedNumeral; - disasm.Options = NasmSyntax + PrefixedNumeral; - disasm.Archi = 32; -// disasm.EIP = (int) getElfReader()->getInstructionBuffer(instr->getAddress()); - disasm.EIP = (UIntPtr) getElfReader()->getInstructionBuffer(instr->getAddress()); - disasm.VirtualAddr = addr; - int instr_len = Disasm(&disasm); + disasm.Options = NasmSyntax + PrefixedNumeral; + disasm.Archi = 32; + disasm.EIP = (UIntPtr) getElfReader()->getInstructionBuffer(instr->getAddress()); + disasm.VirtualAddr = instr->getAddress(); - instr->setAsm(string(disasm.CompleteInstr)); + int instr_len = Disasm(&disasm); + instr->setAsm(string(disasm.CompleteInstr)); -// if (instr->getSize() <= 0) // MEDS plugin didn't record the size - instr->setSize(instr_len); - instr->setData((void*)disasm.EIP); -// instr->setData((void*)disasm.EIP, instr_len); - -// fprintf(stderr,"0x%08x: %s\n", addr, instr->getAsm().c_str()); - } - } + instr->setSize(instr_len); + instr->setData((void*)disasm.EIP); + } } void Rewriter::addSimpleRewriteRule(wahoo::Function* p_func, char *p_origInstr, int p_origSize, app_iaddr_t p_origAddress, char *p_newInstr) diff --git a/xform/rewriter.h b/xform/rewriter.h index ea6f56ecb166977f53410d86ad4c5eae1e919114..ce8466f99a3221223551e07b63b360de67047ff1 100644 --- a/xform/rewriter.h +++ b/xform/rewriter.h @@ -20,6 +20,7 @@ class Rewriter protected: void readAnnotationFile(char []); + void readElfFile(char []); ElfReader *getElfReader() { return m_elfReader; } FILE* getAsmSpri() { return m_spri; }; void setAsmSpri(FILE *p_spri) { m_spri = p_spri; };