Skip to content
Snippets Groups Projects
Commit 1b82bd04 authored by jdh8d's avatar jdh8d
Browse files

Former-commit-id: cf0bb3bcd16382677f4126ee4b7fe236a6ef01ae
parent 7fed0e86
No related branches found
No related tags found
No related merge requests found
......@@ -215,6 +215,7 @@ libIRDB/include/core/icfs.hpp -text
libIRDB/include/core/instruction.hpp -text
libIRDB/include/core/pqxxdb.hpp -text
libIRDB/include/core/reloc.hpp -text
libIRDB/include/core/scoop.hpp -text
libIRDB/include/core/type.hpp -text
libIRDB/include/core/variantid.hpp -text
libIRDB/include/libIRDB-cfg.hpp -text
......
......@@ -41,7 +41,7 @@ class BaseObj_t
void SetDoipID(doip_t *dp) { doip=dp; }
void SetBaseID(db_id_t id) {base_id=id; }
static const db_id_t NOT_IN_DATABASE;
static const db_id_t NOT_IN_DATABASE;
protected:
static DBinterface_t *dbintr;
......
......@@ -23,8 +23,12 @@ class File_t : public BaseObj_t
{
public:
// create new item.
File_t(db_id_t file_id, db_id_t orig_fid, std::string url, std::string hash, std::string arch, int elfoid,
std::string atn, std::string ftn, std::string itn, std::string icfs, std::string icfs_map, std::string rtn, std::string typ, db_id_t doipid);
File_t( const db_id_t &file_id, const db_id_t &orig_fid, const std::string &url,
const std::string &hash, const std::string &arch, const int &elfoid,
const std::string &atn, const std::string &ftn, const std::string &itn,
const std::string &icfs, const std::string &icfs_map,
const std::string &rtn, const std::string &typ, const std::string &scoop,
const db_id_t &doipid);
File_t(db_id_t file_id) : BaseObj_t(NULL) { assert(0);} // read from DB
void WriteToDB() { assert(0); } // writes to DB ID is not -1.
......@@ -37,6 +41,7 @@ class File_t : public BaseObj_t
std::string GetICFSMapTableName() { return icfs_map_table_name; }
std::string GetRelocationsTableName() { return relocs_table_name; }
std::string GetTypesTableName() { return types_table_name; }
std::string GetScoopTableName() { return scoop_table_name; }
std::string GetURL() { return url; }
void CreateTables();
......@@ -69,5 +74,6 @@ class File_t : public BaseObj_t
std::string icfs_map_table_name;
std::string relocs_table_name;
std::string types_table_name;
std::string scoop_table_name;
int elfoid;
};
......@@ -42,6 +42,7 @@ class FileIR_t : public BaseObj_t
InstructionSet_t& GetInstructions() { return insns; }
AddressSet_t& GetAddresses() { return addrs; }
RelocationSet_t& GetRelocations() { return relocs; }
DataScoopSet_t& GetDataScoops() { return scoops; }
ICFSSet_t& GetAllICFS() { return icfs_set; }
// generate the spri rules into the output file, fout.
......@@ -93,6 +94,7 @@ class FileIR_t : public BaseObj_t
AddressSet_t addrs;
RelocationSet_t relocs;
TypeSet_t types;
DataScoopSet_t scoops;
VariantID_t progid;
ICFSSet_t icfs_set;
File_t* fileptr;
......
/*
* Copyright (c) 2016 - Zephyr Software LLC
*
* This file may be used and modified for non-commercial purposes as long as
* all copyright, permission, and nonwarranty notices are preserved.
* Redistribution is prohibited without prior written consent from Zephyr
* Software.
*
* Please contact the authors for restrictions applying to commercial use.
*
* THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* Author: Zephyr Software
* e-mail: jwd@zephyr-software.com
* URL : http://www.zephyr-software.com/
*
*/
#ifndef libirdb_data_scoop_hpp
#define libirdb_data_scoop_hpp
class DataScoop_t : public BaseObj_t
{
public:
DataScoop_t( libIRDB::db_id_t id,
std::string p_name,
libIRDB::AddressID_t* p_start,
libIRDB::AddressID_t* p_end,
libIRDB::Type_t* p_type,
int p_permissions)
:
BaseObj_t(NULL),
name(p_name),
start(p_start),
end(p_end),
type(p_type),
permissions(p_permissions)
{
SetBaseID(id);
}
std::string GetName() const { return name; }
libIRDB::AddressID_t* GetStart() const { return start; }
libIRDB::AddressID_t* GetEnd() const { return end; }
libIRDB::Type_t* GetType() const { return type; }
bool isReadable() const { return (permissions & permissions_r) == permissions_r; }
bool isWriteable() const { return (permissions & permissions_w) == permissions_w; };
bool isExecuteable() const { return (permissions & permissions_x) == permissions_x; };
void SetName(const std::string &n) { name=n; }
void SetStart( libIRDB::AddressID_t* addr) { start=addr; }
void SetEnd( libIRDB::AddressID_t* addr ) { end=addr; }
void SetType( libIRDB::Type_t* t) { type=t; }
void SetReadable() { permissions |= permissions_r; }
void SetWriteable() { permissions |= permissions_w; }
void SetExecuteable() { permissions |= permissions_x; }
void ClearReadable() { permissions &= ~permissions_r; }
void ClearWriteable() { permissions &= ~permissions_w; }
void ClearExecuteable() { permissions &= ~permissions_x; }
private:
const int permissions_r=4;
const int permissions_w=2;
const int permissions_x=1;
std::string name;
libIRDB::AddressID_t* start;
libIRDB::AddressID_t* end;
libIRDB::Type_t* type;
int permissions;
};
typedef std::set<DataScoop_t*> DataScoopSet_t;
#endif
......@@ -50,6 +50,7 @@ class Instruction_t; // forward decl for many classes
#include <core/variantid.hpp>
#include <core/archdesc.hpp>
#include <core/type.hpp>
#include <core/scoop.hpp>
#include <core/fileir.hpp>
#include <core/pqxxdb.hpp>
......
......@@ -31,11 +31,16 @@ using namespace std;
File_t::File_t(db_id_t myfile_id, db_id_t my_orig_fid, std::string myurl, std::string myhash, std::string myarch, int myoid,
std::string atn, std::string ftn, std::string itn, std::string icfs, std::string icfs_map, std::string rtn, std::string typ, db_id_t mydoipid) :
File_t::File_t(const db_id_t &myfile_id, const db_id_t &my_orig_fid, const std::string &myurl,
const std::string &myhash, const std::string &myarch, const int &myoid,
const std::string &atn, const std::string &ftn, const std::string &itn, const std::string &icfs,
const std::string &icfs_map, const std::string &rtn, const std::string &typ, const std::string &scoop,
const db_id_t &mydoipid)
:
BaseObj_t(NULL), url(myurl), hash(myhash), arch(myarch), elfoid(myoid),
address_table_name(atn), function_table_name(ftn), instruction_table_name(itn), icfs_table_name(icfs), icfs_map_table_name(icfs_map),
relocs_table_name(rtn), types_table_name(typ), orig_fid(my_orig_fid)
address_table_name(atn), function_table_name(ftn), instruction_table_name(itn),
icfs_table_name(icfs), icfs_map_table_name(icfs_map), relocs_table_name(rtn),
types_table_name(typ), scoop_table_name(scoop), orig_fid(my_orig_fid)
{
SetBaseID(myfile_id);
}
......@@ -57,6 +62,7 @@ void File_t::CreateTables()
icfs_map_table_name+" "+
relocs_table_name+" "+
types_table_name+" "+
scoop_table_name+" "+
tmpfile;
system(command.c_str());
......
......@@ -497,6 +497,7 @@ void FileIR_t::WriteToDB()
dbintr->IssueQuery(string("TRUNCATE TABLE ")+ fileptr->address_table_name + string(" cascade;"));
dbintr->IssueQuery(string("TRUNCATE TABLE ")+ fileptr->relocs_table_name + string(" cascade;"));
dbintr->IssueQuery(string("TRUNCATE TABLE ")+ fileptr->types_table_name + string(" cascade;"));
dbintr->IssueQuery(string("TRUNCATE TABLE ")+ fileptr->scoop_table_name + string(" cascade;"));
/* and now that everything has an ID, let's write to the DB */
......
......@@ -188,6 +188,7 @@ File_t* VariantID_t::CloneFile(File_t* fptr)
std::string icfs="icfsfid"+to_string(newfid);
std::string icfsmap="icfsmapfid"+to_string(newfid);
std::string rtn="rtnfid"+to_string(newfid);
std::string dtn="dtnfid"+to_string(newfid);
std::string typ="typfid"+to_string(newfid);
q ="update file_info set address_table_name='";
......@@ -204,13 +205,15 @@ File_t* VariantID_t::CloneFile(File_t* fptr)
q+=rtn;
q+="', types_table_name='";
q+=typ;
q+="', scoop_table_name='";
q+=dtn;
q+="' where file_id='";
q+=to_string(newfid);
q+="' ; ";
dbintr->IssueQuery(q);
File_t* newfile=new File_t(newfid, fptr->orig_fid, fptr->url, fptr->hash, fptr->arch, fptr->elfoid, atn, ftn, itn, icfs, icfsmap, rtn, typ, fptr->GetDoipID());
File_t* newfile=new File_t(newfid, fptr->orig_fid, fptr->url, fptr->hash, fptr->arch, fptr->elfoid, atn, ftn, itn, icfs, icfsmap, rtn, typ, dtn, fptr->GetDoipID());
newfile->CreateTables();
......@@ -250,6 +253,11 @@ File_t* VariantID_t::CloneFile(File_t* fptr)
q+=" ; ";
dbintr->IssueQuery(q);
q="drop table ";
q+=dtn;
q+=" ; ";
dbintr->IssueQuery(q);
// next issue SQL to clone each table
q="select * into ";
q+=atn;
......@@ -300,7 +308,13 @@ File_t* VariantID_t::CloneFile(File_t* fptr)
q+=" ;";
dbintr->IssueQuery(q);
// update the variant dependency table to represent the deep clone
q="select * into ";
q+=dtn;
q+=" from ";
q+=fptr->scoop_table_name;
q+=" ;";
dbintr->IssueQuery(q);
// update the variant dependency table to represent the deep clone
q = "update variant_dependency set file_id='" +
......@@ -381,8 +395,10 @@ File_t* VariantID_t::GetMainFile() const
void VariantID_t::ReadFilesFromDB()
{
std::string q= "select file_info.orig_file_id, file_info.address_table_name, file_info.instruction_table_name, file_info.icfs_table_name,file_info.icfs_map_table_name,"
" file_info.function_table_name, file_info.relocs_table_name, file_info.types_table_name, file_info.file_id, file_info.url, file_info.hash,"
std::string q= "select file_info.orig_file_id, file_info.address_table_name, "
" file_info.instruction_table_name, file_info.icfs_table_name,file_info.icfs_map_table_name, "
" file_info.function_table_name, file_info.relocs_table_name, file_info.types_table_name, "
" file_info.scoop_table_name, file_info.file_id, file_info.url, file_info.hash,"
" file_info.arch, file_info.type, file_info.elfoid, file_info.doip_id "
" from file_info,variant_dependency "
" where variant_dependency.variant_id = '" + to_string(GetBaseID()) + "' AND "
......@@ -404,13 +420,14 @@ void VariantID_t::ReadFilesFromDB()
std::string atn=(BaseObj_t::dbintr->GetResultColumn("address_table_name"));
std::string ftn=(BaseObj_t::dbintr->GetResultColumn("function_table_name"));
std::string itn=(BaseObj_t::dbintr->GetResultColumn("instruction_table_name"));
std::string dtn=(BaseObj_t::dbintr->GetResultColumn("scoop_table_name"));
std::string icfs=(BaseObj_t::dbintr->GetResultColumn("icfs_table_name"));
std::string icfs_map=(BaseObj_t::dbintr->GetResultColumn("icfs_map_table_name"));
std::string rtn=(BaseObj_t::dbintr->GetResultColumn("relocs_table_name"));
std::string typ=(BaseObj_t::dbintr->GetResultColumn("types_table_name"));
File_t *newfile=new File_t(file_id,orig_fid,url,hash,type,oid,atn,ftn,itn,icfs,icfs_map,rtn,typ,doipid);
File_t *newfile=new File_t(file_id,orig_fid,url,hash,type,oid,atn,ftn,itn,icfs,icfs_map,rtn,typ,dtn,doipid);
std::cout<<"Found file "<<file_id<<"."<<std::endl;
std::cout<<" atn: " << atn << " ftn: " << ftn << " rtn: " << rtn << " typ: " << typ << std::endl;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment