diff --git a/README.md b/README.md index 2fd9f9570028dac87fd50b6dd37124d915c8b441..e5992e231eef9abbc782c9d79a6fb92fdd68ed74 100644 --- a/README.md +++ b/README.md @@ -1 +1,7 @@ -TBD \ No newline at end of file + +This is the IRDB SDK. Include only files in include/, other files shall be included indirectly. + + +All of the interface is in the IRDB_SDK namespace. + +Include file "irdb-<foo> needs to be linked against libIRDB-foo. diff --git a/include/inc-core/address.hpp b/include/inc-core/address.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6aad94a23938d3c3582e1973f8b306e3997dbd8c --- /dev/null +++ b/include/inc-core/address.hpp @@ -0,0 +1,19 @@ +namespace IRDB_SDK +{ + class AddressID_t : virtual public BaseObj_t + { + protected: + AddressID_t() {} + AddressID_t(const AddressID_t& copy)=delete; + + public: + virtual ~AddressID_t() {} + + virtual DatabaseID_t getFileID() const = 0; + virtual VirtualOffset_t getVirtualOffset() const = 0; + + virtual void setFileID(DatabaseID_t thefileID) = 0; + virtual void setVirtualOffset(VirtualOffset_t voff) = 0; + }; + +} diff --git a/include/inc-core/archdesc.hpp b/include/inc-core/archdesc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3eb1eee4d015fc369d64c08c318e9654d9f8252d --- /dev/null +++ b/include/inc-core/archdesc.hpp @@ -0,0 +1,22 @@ +namespace IRDB_SDK +{ + + class ArchitectureDescription_t + { + protected: + ArchitectureDescription_t() {} + ArchitectureDescription_t(const ArchitectureDescription_t& copy) = delete; + public: + ~ArchitectureDescription_t() {} + + virtual int getBitWidth() const = 0; + virtual ADFileType_t getFileType() const = 0; + virtual ADMachineType_t getMachineType() const = 0; + + virtual void setFileType(const ADFileType_t t) = 0; + virtual void setBitWidth(const int _bits) = 0; + virtual void setMachineType(const ADMachineType_t t) = 0; + + }; + +} diff --git a/include/inc-core/baseobj.hpp b/include/inc-core/baseobj.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7db336243b1b05889d13cf4bf1df034cdf3dad5e --- /dev/null +++ b/include/inc-core/baseobj.hpp @@ -0,0 +1,25 @@ +namespace IRDB_SDK +{ + class BaseObj_t + { + protected: + BaseObj_t() {} + BaseObj_t(const BaseObj_t& copy) = delete; + + public: + virtual ~BaseObj_t() {} + + virtual DatabaseID_t getBaseID() const = 0; + virtual DatabaseID_t getDoipID() const = 0; + virtual const RelocationSet_t& getRelocations() const = 0; + + virtual void setRelocations(const RelocationSet_t& rels) = 0; + virtual void setDoipID(Doip_t *p_dp) = 0; + virtual void setBaseID(DatabaseID_t p_id) = 0; + + const static int NOT_IN_DATABASE; + static void setInterface(DBinterface_t *dbintr); + + }; + +} diff --git a/include/inc-core/basetypes.hpp b/include/inc-core/basetypes.hpp new file mode 100644 index 0000000000000000000000000000000000000000..d42be7ece026b37c90248d209b93859f71d75061 --- /dev/null +++ b/include/inc-core/basetypes.hpp @@ -0,0 +1,105 @@ +namespace IRDB_SDK +{ + using namespace std; + + // enums + enum ADFileType { + adftELF, + adftCGC, + adftPE, + adftNone + }; + + enum ADMachineType { + admtAarch64, + admtX86_64, + admtI386, + admtNone + }; + + enum DatabaseErrorType { + detVariantNotInDatabase, + detVariantTableNotRegistered + }; + + enum ICFSAnalysisStatus { + iasAnalysisIncomplete, + iasAnalysisModuleComplete, + iasAnalysisComplete + }; + + enum IRDBType { + itUnknown, + itNumeric, + itPointer, + itVoid, + itVariadic, + itInt, + itChar, + itFloat, + itDouble, + itTypedef, + itSubtype, + itFunc, + itAggregate + }; + + // enum renames + using ADFileType_t = enum ADFileType; + using ADMachineType_t = enum ADMachineType; + using DatabaseErrorType_t = enum DatabaseErrorType; + using ICFSAnalysisStatus_t = enum ICFSAnalysisStatus; + using IRDBType_t = enum IRDBType; + + + + // forward decls; + class AddressID_t; + class ArchitectureDescription_t; + class BaseObj_t; + class DatabaseError_t; + class DBinterface_t; + class DecodedInstruction_t; + class DecodedOperand_t; + class Doip_t; + class EhProgram_t; + class EhCallSite_t; + class File_t; + class FileIR_t; + class Function_t; + class ICFS_t; + class Instruction_t; + class IRDBObjects_t; + class pqxxDB_t; + class Relocation_t; + class DataScoop_t; + class Type_t; + class BasicType_t; + class PointerType_t; + class AggregateType_t; + class FuncType_t; + class VariantID_t; + + // typedefs + using VirtualOffset_t = uintptr_t; + using DatabaseID_t = int32_t; + using SchemaVersionID_t = int32_t; + using EhProgramInstruction_t = string; + using EhProgramListing_t = vector<EhProgramInstruction_t>; + using EhProgramSet_t = set<EhProgram_t*>; + using TTOrderVector_t = vector<int>; + using EhCallSiteSet_t = set<EhCallSite_t*>; + using FunctionSet_t = set<Function_t*>; + using AddressSet_t = set<AddressID_t*>; + using ICFSSet_t = set<ICFS_t*>; + using RelocationSet_t = set<Relocation_t*>; + using InstructionSet_t = set<Instruction_t*>; + using DataScoopSet_t = set<DataScoop_t*>; + using TypeSet_t = set<Type_t*>; + using TypeVector_t = vector<Type_t*>; + using FileSet_t = set<File_t*>; + using DecodedOperandVector_t = vector<shared_ptr < DecodedOperand_t > >; + + + +} diff --git a/include/inc-core/dbinterface.hpp b/include/inc-core/dbinterface.hpp new file mode 100644 index 0000000000000000000000000000000000000000..250ee9b5336005a337f3bea063c4ef32d8827673 --- /dev/null +++ b/include/inc-core/dbinterface.hpp @@ -0,0 +1,33 @@ +namespace IRDB_SDK +{ + + using namespace std; + + class DatabaseError_t : virtual public exception + { + protected: + public: + enum DatabaseErrorType_t {VariantNotInDatabase, VariantTableNotRegistered}; + }; + + ostream& operator<<(ostream& output, const DatabaseError_t& p); + + + // an interface to a database + class DBinterface_t + { + protected: + DBinterface_t() {} + DBinterface_t(const DBinterface_t& copy) = delete; + public: + virtual ~DBinterface_t() {}; + + virtual void issueQuery(string query) = 0; + virtual void moveToNextRow() = 0; + virtual string getResultColumn(string colname) = 0; + virtual bool isDone() = 0; + virtual void commit() = 0; + + }; + +} diff --git a/include/inc-core/decode.hpp b/include/inc-core/decode.hpp new file mode 100644 index 0000000000000000000000000000000000000000..81cca2bc01a7c577c38d6a90547d04e36d956a38 --- /dev/null +++ b/include/inc-core/decode.hpp @@ -0,0 +1,92 @@ +namespace IRDB_SDK +{ + + using namespace std; + + class DecodedInstruction_t + { + protected: + DecodedInstruction_t() {}; + DecodedInstruction_t(const DecodedInstruction_t& copy) = delete; + public: + + virtual ~DecodedInstruction_t() {} + + virtual string getDisassembly() const = 0; + virtual bool valid() const = 0; + virtual uint32_t length() const = 0; + virtual bool isBranch() const = 0; + virtual bool isCall() const = 0; + virtual bool isUnconditionalBranch() const = 0; + virtual bool isConditionalBranch() const = 0; + virtual bool isReturn() const = 0; + virtual string getMnemonic() const = 0; + virtual int64_t getImmediate() const = 0; + virtual VirtualOffset_t + getAddress() const = 0; + virtual bool setsStackPointer() const = 0; + virtual uint32_t getPrefixCount() const = 0; + virtual bool hasRelevantRepPrefix() const = 0; + virtual bool hasRelevantRepnePrefix() const = 0; + virtual bool hasRelevantOperandSizePrefix() const = 0; + virtual bool hasRexWPrefix() const = 0; + virtual bool hasImplicitlyModifiedRegs() const = 0; + virtual bool hasOperand(const int op_num) const = 0; + virtual shared_ptr<DecodedOperand_t> + getOperand(const int op_num) const = 0; + virtual DecodedOperandVector_t + getOperands() const = 0; + virtual VirtualOffset_t + getMemoryDisplacementOffset( + const DecodedOperand_t* t, + const Instruction_t* insn + ) const = 0; + + // factories + static unique_ptr<DecodedInstruction_t> factory(const Instruction_t* p_in); + static unique_ptr<DecodedInstruction_t> factory(const VirtualOffset_t start_addr, const void *data, uint32_t max_len); + static unique_ptr<DecodedInstruction_t> factory(const VirtualOffset_t start_addr, const void *data, const void* endptr); + + + }; + + class DecodedOperand_t + { + protected: + DecodedOperand_t() {} + DecodedOperand_t(const DecodedOperand_t& copy) = delete; + public: + virtual ~DecodedOperand_t() {} + + virtual bool isConstant() const = 0; + virtual uint64_t getConstant() const = 0; + virtual string getString() const = 0; + virtual bool isRegister() const = 0; + virtual bool isGeneralPurposeRegister() const = 0; + virtual bool isMmxRegister() const = 0; + virtual bool isFpuRegister() const = 0; + virtual bool isSseRegister() const = 0; + virtual bool isAvxRegister() const = 0; + virtual bool isZmmRegister() const = 0; + virtual bool isSpecialRegister() const = 0; + virtual bool isSegmentRegister() const = 0; + virtual uint32_t getRegNumber() const = 0; + virtual bool isMemory() const = 0; + virtual bool hasSegmentRegister() const = 0; + virtual uint32_t getSegmentRegister() const = 0; + virtual bool hasBaseRegister() const = 0; + virtual bool hasIndexRegister() const = 0; + virtual uint32_t getBaseRegister() const = 0; + virtual uint32_t getIndexRegister() const = 0; + virtual bool hasMemoryDisplacement() const = 0; + virtual VirtualOffset_t getMemoryDisplacement() const = 0; + virtual bool isPcrel() const = 0; + virtual uint32_t getScaleValue() const = 0; + virtual uint32_t getMemoryDisplacementEncodingSize() const = 0; + virtual uint32_t getArgumentSizeInBytes() const = 0; + virtual uint32_t getArgumentSizeInBits() const = 0; + virtual bool isRead() const = 0; + virtual bool isWritten() const = 0; + + }; +} diff --git a/include/inc-core/doip.hpp b/include/inc-core/doip.hpp new file mode 100644 index 0000000000000000000000000000000000000000..75cad9fbaf7e6ad1a3defedf7f8aa379dfd606b3 --- /dev/null +++ b/include/inc-core/doip.hpp @@ -0,0 +1,12 @@ +namespace IRDB_SDK +{ + class Doip_t + { + protected: + Doip_t() {} + Doip_t(const Doip_t& copy) = delete; + public: + virtual DatabaseID_t GetBaseID() const = 0; + + }; +} diff --git a/include/inc-core/eh.hpp b/include/inc-core/eh.hpp new file mode 100644 index 0000000000000000000000000000000000000000..99cc954f89e0ac807c3e67a36ce61f79717eab16 --- /dev/null +++ b/include/inc-core/eh.hpp @@ -0,0 +1,49 @@ +namespace IRDB_SDK +{ + + using namespace std; + + class EhProgram_t : virtual public BaseObj_t + { + protected: + EhProgram_t() { } + EhProgram_t(const EhProgram_t& copy) = delete; + public: + + virtual ~EhProgram_t() { } + virtual const EhProgramListing_t& getCIEProgram() const = 0; + virtual const EhProgramListing_t& getFDEProgram() const = 0; + virtual uint64_t getCodeAlignmentFactor() const = 0; + virtual int64_t getDataAlignmentFactor() const = 0; + virtual int64_t getReturnRegNumber() const = 0; + virtual uint8_t getPointerSize() const = 0; + + virtual void setCodeAlignmentFactor(const uint64_t caf) = 0; + virtual void setDataAlignmentFactor(const int64_t daf) = 0; + virtual void setReturnRegNumber (const uint8_t rr ) = 0; + + // helpers + virtual void print() const = 0; + }; + + class EhCallSite_t : virtual public BaseObj_t + { + protected: + EhCallSite_t() { } ; + EhCallSite_t(const EhCallSite_t& copy)=delete; + public: + + virtual ~EhCallSite_t() { } ; + virtual uint64_t getTTEncoding() const = 0; + virtual const TTOrderVector_t& getTTOrderVector() const = 0; + virtual Instruction_t* getLandingPad() const = 0; + virtual bool getHasCleanup() const = 0; + + virtual void setTTEncoding(const uint64_t p_tt) = 0; + virtual void setLandingPad(Instruction_t* lp) = 0; + virtual void setHasCleanup(bool p_has_cleanup=true) = 0; + virtual void setTTOrderVector(const TTOrderVector_t& ) = 0; + + }; + +} diff --git a/include/inc-core/file.hpp b/include/inc-core/file.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6ccdbc1aac3c29ec999d554825c94c3c8308add6 --- /dev/null +++ b/include/inc-core/file.hpp @@ -0,0 +1,31 @@ + +namespace IRDB_SDK +{ + + using namespace std; + + class File_t : virtual public BaseObj_t + { + protected: + File_t() { }; + File_t(const File_t& copy) = delete; + public: + virtual ~File_t() { }; + + virtual string getAddressTableName() const = 0; + virtual string getFunctionTableName() const = 0; + virtual string getInstructionTableName() const = 0; + virtual string getICFSTableName() const = 0; + virtual string getICFSMapTableName() const = 0; + virtual string getRelocationsTableName() const = 0; + virtual string getTypesTableName() const = 0; + virtual string getScoopTableName() const = 0; + virtual string getEhProgramTableName() const = 0; + virtual string getEhCallSiteTableName() const = 0; + virtual string getURL() const = 0; + virtual int getELFOID() const = 0; + virtual DatabaseID_t getFileID() const = 0; + + }; + +} diff --git a/include/inc-core/fileir.hpp b/include/inc-core/fileir.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0f2973c21e05c785dcfd9857f4c1a8c38b192835 --- /dev/null +++ b/include/inc-core/fileir.hpp @@ -0,0 +1,104 @@ +namespace IRDB_SDK +{ + + using namespace std; + + class FileIR_t : virtual public BaseObj_t + { + protected: + FileIR_t(){} + FileIR_t(const FileIR_t& p_copy) = delete; + public: + virtual ~FileIR_t() {} + + // accessors + virtual const FunctionSet_t& getFunctions() const = 0; + virtual const InstructionSet_t& getInstructions() const = 0; + virtual const AddressSet_t& getAddresses() const = 0; + virtual const RelocationSet_t& getRelocations() const = 0; + virtual const DataScoopSet_t& getDataScoops() const = 0; + virtual const ICFSSet_t& getAllICFS() const = 0; + virtual const EhProgramSet_t& getAllEhPrograms() const = 0; + virtual const EhCallSiteSet_t& getAllEhCallSites() const = 0; + virtual File_t* getFile() const = 0; + virtual DatabaseID_t getMaxBaseID() const = 0; + virtual DataScoop_t* findScoop( + const VirtualOffset_t &p_addr) const = 0; + + virtual void setBaseIDS() = 0; + virtual void assembleRegistry() = 0; + virtual void registerAssembly(Instruction_t *p_instr, string p_assembly) = 0; + virtual void unregisterAssembly(Instruction_t *p_instr) = 0; + virtual string lookupAssembly(Instruction_t *p_instr) = 0; + virtual void changeRegistryKey( + Instruction_t* p_orig, Instruction_t* p_updated) = 0; + virtual void splitScoop( + DataScoop_t *p_to_split, + const VirtualOffset_t &p_addr, + size_t p_size, + DataScoop_t* &p_before, + DataScoop_t* &p_containing, + DataScoop_t* &p_after, + DatabaseID_t *p_max_id=NULL + ) = 0; + + virtual void writeToDB(std::ostream *verbose_logging=&std::cerr) = 0; + + virtual EhCallSite_t* addEhCallSite_t(Instruction_t* for_insn, const uint64_t enc=0, Instruction_t* lp=nullptr) = 0; + virtual Relocation_t* addNewRelocation( + BaseObj_t* from_obj, + int32_t _offset, + string _type, + BaseObj_t* p_wrt_obj=nullptr, + int32_t p_addend=0 + ) = 0; + + virtual EhProgram_t* addEhProgram( + Instruction_t* insn=nullptr, + const uint64_t caf=1, + const int64_t daf=1, + const uint8_t rr=1, + const uint8_t p_ptrsize=8, + const EhProgramListing_t& p_cie_program={}, + const EhProgramListing_t& p_fde_program={} + ) = 0; + + virtual AddressID_t* addNewAddress(const DatabaseID_t& myfileID, const VirtualOffset_t& voff) =0 ; + virtual ICFS_t* addNewICFS (Instruction_t* insn=nullptr, const InstructionSet_t& targets={}, const ICFSAnalysisStatus_t& status=iasAnalysisIncomplete) = 0; + + virtual Instruction_t* addNewInstruction( + AddressID_t* addr=nullptr, + Function_t* func=nullptr, + const string& bits="", + const string& comment="user-added", + AddressID_t* indTarg=nullptr + ) =0; + virtual DataScoop_t* addNewDataScoop( + const string& p_name="user-added", + AddressID_t* p_start=nullptr, + AddressID_t* p_end=nullptr, + Type_t* p_type=nullptr, + uint8_t p_permissions=0, + bool p_is_relro=false, + const string &p_contents="", + DatabaseID_t id=BaseObj_t::NOT_IN_DATABASE + ) = 0; + + + + virtual void removeScoop(DataScoop_t* s) = 0; + virtual void moveRelocation(Relocation_t* reloc, Instruction_t* from, Instruction_t* to) = 0; + + + // static methods + static uint32_t getArchitectureBitWidth() ; + static const IRDB_SDK::ArchitectureDescription_t* getArchitecture() ; + + + // factories: + static unique_ptr<FileIR_t> factory(VariantID_t *p_progid, File_t* p_fid=nullptr); + + + }; + +} diff --git a/include/inc-core/function.hpp b/include/inc-core/function.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3e6cfb0defbe1e92a79d1ce03db1548f22201a2d --- /dev/null +++ b/include/inc-core/function.hpp @@ -0,0 +1,36 @@ + + +namespace IRDB_SDK +{ + + using namespace std; + + class Function_t : virtual public BaseObj_t + { + protected: + Function_t() {} + Function_t(const Function_t©) = delete; + + public: + // getters + virtual const InstructionSet_t& getInstructions() const = 0; + virtual const int getStackFrameSize() const = 0; + virtual const string& getName() const = 0; + virtual uint32_t getOutArgsRegionSize() const = 0; + virtual Instruction_t* getEntryPoint() const = 0; + virtual bool getUseFramePointer() const = 0; + virtual int getNumArguments() const = 0; + virtual FuncType_t* getType() const = 0; + virtual bool isSafe() const = 0; + + // muttators + virtual void setStackFrameSize(int size) = 0; + virtual void setName(string newname) = 0; + virtual void setOutArgsRegionSize(uint32_t oa_size) = 0; + virtual void setEntryPoint(Instruction_t *insn) = 0; + virtual void setUseFramePointer(bool useFP) = 0; + virtual void setSafe(bool safe) = 0; + virtual void setType(FuncType_t *t) = 0; + }; + +} diff --git a/include/inc-core/icfs.hpp b/include/inc-core/icfs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4d451f1644d7a4b4993a668a3ef23e6498ddf1e1 --- /dev/null +++ b/include/inc-core/icfs.hpp @@ -0,0 +1,26 @@ +namespace IRDB_SDK +{ + + using namespace std; + + class ICFS_t : virtual public InstructionSet_t, virtual public BaseObj_t + { + protected: + ICFS_t() {}; + ICFS_t(const ICFS_t& copy) = delete; + public: + + // getters + virtual bool isIncomplete() const = 0; + virtual bool isComplete() const = 0; + virtual bool isModuleComplete() const = 0; + virtual ICFSAnalysisStatus_t getAnalysisStatus() const = 0; + + // mutators + virtual void setTargets(const InstructionSet_t &other) = 0; + virtual void addTargets(const InstructionSet_t &other) = 0; + virtual void setAnalysisStatus(const ICFSAnalysisStatus_t p_status) = 0; + + }; + +} diff --git a/include/inc-core/instruction.hpp b/include/inc-core/instruction.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f1d551f64ebe53fd90816260c6747382b1613ab1 --- /dev/null +++ b/include/inc-core/instruction.hpp @@ -0,0 +1,42 @@ +namespace IRDB_SDK +{ + using namespace std; + + class Instruction_t : virtual public BaseObj_t + { + protected: + Instruction_t() {} + Instruction_t(const Instruction_t& copy) = delete; + public: + + virtual AddressID_t* getAddress() const = 0; + virtual Function_t* getFunction() const = 0; + virtual DatabaseID_t getOriginalAddressID() const = 0; + virtual Instruction_t* getFallthrough() const = 0; + virtual Instruction_t* getTarget() const = 0; + virtual ICFS_t* getIBTargets() const = 0; + virtual string getDataBits() const = 0; + virtual string getCallback() const = 0; + virtual string getComment() const = 0; + virtual EhProgram_t* getEhProgram() const = 0; + virtual EhCallSite_t* getEhCallSite() const = 0; + virtual AddressID_t* getIndirectBranchTargetAddress() const = 0; + virtual bool isFunctionExit() const = 0; + virtual string getDisassembly() const = 0; + + virtual void setAddress(AddressID_t* newaddr) = 0; + virtual void setFunction(Function_t* func ) = 0; + virtual void setOriginalAddressID(DatabaseID_t origid) = 0; + virtual void setFallthrough(Instruction_t* i) = 0; + virtual void setTarget(Instruction_t* i) = 0; + virtual void setIBTargets(ICFS_t *p_icfs) = 0; + virtual void setDataBits(string orig) = 0; + virtual void setCallback(string orig) = 0; + virtual void setComment(string orig) = 0; + virtual void setEhProgram(EhProgram_t* orig) = 0; + virtual void setEhCallSite(EhCallSite_t* orig) = 0; + virtual void setIndirectBranchTargetAddress(AddressID_t* myIndTarg) = 0; + virtual bool assemble(string assembly) = 0; + + }; +} diff --git a/include/inc-core/irdbobjs.hpp b/include/inc-core/irdbobjs.hpp new file mode 100644 index 0000000000000000000000000000000000000000..3bebb6f34c75ebe48e90b3a66b36e5e1ad59ba4b --- /dev/null +++ b/include/inc-core/irdbobjs.hpp @@ -0,0 +1,27 @@ +namespace IRDB_SDK +{ + using namespace std; + + class IRDBObjects_t + { + protected: + IRDBObjects_t() {} + IRDBObjects_t(const IRDBObjects_t& copy) = delete; + public: + virtual ~IRDBObjects_t() {} + virtual FileIR_t* addFileIR(const DatabaseID_t variant_id, const DatabaseID_t file_id) = 0; + virtual void deleteFileIR(const DatabaseID_t file_id) = 0; + virtual VariantID_t* addVariant(const DatabaseID_t variant_id) = 0; + virtual void deleteVariant(DatabaseID_t variant_id) = 0; + virtual pqxxDB_t* getDBInterface() const = 0; + virtual pqxxDB_t* resetDBInterface() = 0; + virtual int writeBackFileIR(const DatabaseID_t file_id, ostream *verbose_logging=nullptr) = 0; + virtual int writeBackVariant(const DatabaseID_t variant_id) = 0; + virtual int writeBackAll(ostream* verbose_logging=nullptr) = 0; + virtual void deleteAll(void) = 0; + virtual void tidyIR() = 0; + }; + +} + + diff --git a/include/inc-core/pqxxdb.hpp b/include/inc-core/pqxxdb.hpp new file mode 100644 index 0000000000000000000000000000000000000000..de79f176f241a00e76186e06821b7bc8eccc55f9 --- /dev/null +++ b/include/inc-core/pqxxdb.hpp @@ -0,0 +1,27 @@ + +namespace IRDB_SDK +{ + using namespace std; + + class pqxxDB_t : virtual public DBinterface_t + { + protected: + pqxxDB_t() {} + pqxxDB_t(const pqxxDB_t& copy) = delete; + public: + virtual ~pqxxDB_t() { }; + + virtual void issueQuery(string query) = 0; + virtual void issueQuery(stringstream & query) = 0; + virtual void moveToNextRow() = 0; + virtual string getResultColumn(string colname) = 0; + virtual bool isDone() = 0; + virtual void commit() = 0; + virtual pqxx::connection& + getConnection() = 0; + virtual pqxx::work& getTransaction() = 0; + + static unique_ptr<pqxxDB_t> factory(); + + }; +} diff --git a/include/inc-core/reloc.hpp b/include/inc-core/reloc.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f8e0a85b7a313ec69fd9eb3cc77dd8276564fe3a --- /dev/null +++ b/include/inc-core/reloc.hpp @@ -0,0 +1,26 @@ + +namespace IRDB_SDK +{ + using namespace std; + + class Relocation_t : virtual public BaseObj_t + { + protected: + Relocation_t() { } + Relocation_t(const Relocation_t& copy) = delete; + + public: + virtual ~Relocation_t() { } + + virtual int getOffset() const = 0; + virtual string getType() const = 0; + virtual uint32_t getAddend() const = 0; + virtual BaseObj_t* getWRT() const = 0; + + virtual void setOffset(int off) = 0; + virtual void setType(string ty) = 0; + virtual void setAddend(uint32_t p_addend) = 0; + virtual void setWRT(BaseObj_t* WRT) = 0; + + }; +} diff --git a/include/inc-core/scoop.hpp b/include/inc-core/scoop.hpp new file mode 100644 index 0000000000000000000000000000000000000000..706cfcd7846f939e4554edfcaf13719d9226e5d2 --- /dev/null +++ b/include/inc-core/scoop.hpp @@ -0,0 +1,42 @@ +namespace IRDB_SDK +{ + using namespace std; + + class DataScoop_t : virtual public BaseObj_t + { + + protected: + DataScoop_t() {} + DataScoop_t(const DataScoop_t& copy) = delete; + public: + virtual ~DataScoop_t() { } + + virtual const string getName() const = 0; + virtual const string& getContents() const = 0; + virtual AddressID_t* getStart() const = 0; + virtual AddressID_t* getEnd() const = 0; + virtual Type_t* getType() const = 0; + virtual VirtualOffset_t getSize() const = 0; + virtual bool isReadable() const = 0; + virtual bool isWriteable() const = 0; + virtual bool isExecuteable() const = 0; + virtual bool isRelRo() const = 0; + virtual uint8_t getRawPerms() const = 0; + + virtual void setName(const string &n) = 0; + virtual void setContents(const string &n) = 0; + virtual void setStart( AddressID_t* addr) = 0; + virtual void setEnd( AddressID_t* addr ) = 0; + virtual void setType( Type_t* t) = 0; + virtual void setReadable() = 0; + virtual void setWriteable() = 0; + virtual void setExecuteable() = 0; + virtual void setRelRo() = 0; + virtual void clearReadable() = 0; + virtual void clearWriteable() = 0; + virtual void clearExecuteable() = 0; + virtual void clearRelRo() = 0; + virtual void setRawPerms(int newperms) = 0; + + }; +} diff --git a/include/inc-core/transform_step.h b/include/inc-core/transform_step.h new file mode 100644 index 0000000000000000000000000000000000000000..e8f3617fff86c01d73fa9e7211fad85d9872456d --- /dev/null +++ b/include/inc-core/transform_step.h @@ -0,0 +1,26 @@ +namespace IRDB_SDK +{ + using namespace std; + class TransformStep_t + { + protected: + TransformStep_t() { } + public: + virtual ~TransformStep_t(void) { } + + virtual string getStepName(void) const = 0; + + virtual int parseArgs(const vector<string> step_args) = 0; + virtual int executeStep(IRDBObjects_t *const irdb_objects) = 0; + }; + +} + + +// Must also declare a getTransformStep global function in your thanos-enabled .so file +// so that thanos can use it as a factory to create your transform class. It must +// follow this signature: +// +// extern "C" std::shared_ptr<TransformStep_t> getTransformStep(void); + + diff --git a/include/inc-core/type.hpp b/include/inc-core/type.hpp new file mode 100644 index 0000000000000000000000000000000000000000..df9ea1e2ac3fbaceda350e8cfd4da40708434d74 --- /dev/null +++ b/include/inc-core/type.hpp @@ -0,0 +1,86 @@ +namespace IRDB_SDK +{ + + using namespace std; + + class Type_t : virtual public BaseObj_t + { + protected: + Type_t() {} + Type_t(const Type_t& copy) = delete; + public: + virtual ~Type_t() {} + + virtual string getName() const = 0; + virtual IRDBType_t getTypeID() const = 0; + virtual bool isUnknownType() const = 0; + virtual bool isVariadicType() const = 0; + virtual bool isAggregateType() const = 0; + virtual bool isFuncType() const = 0; + virtual bool isBasicType() const = 0; + virtual bool isPointerType() const = 0; + virtual bool isNumericType() const = 0; + + virtual void setTypeID(IRDBType t) = 0; + virtual void setName(const string& newname) = 0; + + }; + + class BasicType_t : virtual public Type_t + { + protected: + BasicType_t() {} + BasicType_t(const BasicType_t& copy) = delete; + public: + virtual ~BasicType_t() {} + + virtual bool isBasicType() const = 0; + virtual bool isNumericType() const = 0; + }; + + class PointerType_t : virtual public Type_t + { + protected: + PointerType_t() {} + PointerType_t(const PointerType_t& copy) = delete; + public: + virtual ~PointerType_t() {} + + virtual bool isPointerType() const = 0; + virtual Type_t* getReferentType() const = 0; + + virtual void setReferentType(Type_t* r) = 0; + }; + + class AggregateType_t : virtual public Type_t + { + protected: + AggregateType_t() { } + AggregateType_t(const AggregateType_t& copy) = delete; + public: + virtual ~AggregateType_t() {} + + virtual bool isAggregateType() const = 0; + virtual size_t getNumAggregatedTypes() const = 0; + virtual Type_t* getAggregatedType(unsigned int pos) const = 0; + + virtual void addAggregatedType(Type_t *t, int pos) = 0; + }; + + class FuncType_t : virtual public Type_t + { + protected: + FuncType_t() {} + FuncType_t(const FuncType_t& copy) = delete; + public: + virtual ~FuncType_t() {} + + virtual bool isFuncType() const = 0; + virtual Type_t* getReturnType() const = 0; + virtual AggregateType_t* getArgumentsType() const = 0; + + virtual void setReturnType(Type_t *t) = 0; + virtual void setArgumentsType(AggregateType_t *t) = 0; + + }; +} diff --git a/include/inc-core/variantid.hpp b/include/inc-core/variantid.hpp new file mode 100644 index 0000000000000000000000000000000000000000..b7087c71f6fa6d846402d1e5f3d322d7ed5a04de --- /dev/null +++ b/include/inc-core/variantid.hpp @@ -0,0 +1,36 @@ +namespace IRDB_SDK +{ + + using namespace std; + + class VariantID_t : virtual public BaseObj_t + { + + protected: + VariantID_t() { } + + public: + virtual ~VariantID_t() { } + + virtual bool isRegistered() const = 0; + virtual const FileSet_t& getFiles() const = 0; + virtual File_t* getMainFile() const = 0; + virtual DatabaseID_t getOriginalVariantID() const = 0; + virtual string getName() const = 0; + + + + virtual bool registerID() = 0; + virtual void setName(string newname) = 0; + virtual VariantID_t* clone(bool deep=true) = 0; + + // factories: + static unique_ptr<VariantID_t> factory(const DatabaseID_t& id); + + + }; + + ostream& operator<<(ostream& out, const VariantID_t& pid); + +} + diff --git a/include/irdb-cfg b/include/irdb-cfg new file mode 100644 index 0000000000000000000000000000000000000000..6251c732cf142efb2bda840dd0d2a95ee49906b1 --- /dev/null +++ b/include/irdb-cfg @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2014 - 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 IRDB_SDK_cfg +#define IRDB_SDK_cfg + + +/* Building a CFG depends on core functionality */ +#include <IRDB_SDK-core.hpp> + +#include <vector> +#include <set> +#include <map> +#include <ostream> + +#include <inc-cfg/BasicBlock.hpp> +#include <inc-cfg/CFG.hpp> +#include <inc-cfg/callgraph.hpp> +#include <inc-cfg/domgraph.hpp> +#include <inc-cfg/criticaledge.hpp> + + +#endif diff --git a/include/irdb-core b/include/irdb-core new file mode 100644 index 0000000000000000000000000000000000000000..e22f5646a2c997aed438cbdad55ddf1cdda6838e --- /dev/null +++ b/include/irdb-core @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2014 - 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 IRDB_SDK_core +#define IRDB_SDK_core + +#include <string> +#include <vector> +#include <set> +#include <assert.h> +#include <string.h> +#include <iostream> +#include <pqxx/pqxx> +#include <ctime> +#include <stdint.h> +#include <exception> +#include <memory> + +#include <inc-core/basetypes.hpp> +#include <inc-core/dbinterface.hpp> +#include <inc-core/doip.hpp> +#include <inc-core/baseobj.hpp> +#include <inc-core/reloc.hpp> +#include <inc-core/address.hpp> +#include <inc-core/icfs.hpp> +#include <inc-core/instruction.hpp> +#include <inc-core/file.hpp> +#include <inc-core/function.hpp> +#include <inc-core/variantid.hpp> +#include <inc-core/archdesc.hpp> +#include <inc-core/type.hpp> +#include <inc-core/scoop.hpp> +#include <inc-core/eh.hpp> +#include <inc-core/fileir.hpp> +#include <inc-core/pqxxdb.hpp> +#include <inc-core/irdbobjs.hpp> +#include <inc-core/transform_step.h> +#include <inc-core/decode.hpp> + +#endif diff --git a/include/irdb-syscall b/include/irdb-syscall new file mode 100644 index 0000000000000000000000000000000000000000..8710b77713570fbfcceb765d90e85bb898bc9047 --- /dev/null +++ b/include/irdb-syscall @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2014 - 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 IRDB_SDK_syscall +#define IRDB_SDK_syscall + + +/* Building a CFG depends on core functionality */ +#include <IRDB_SDK-core.hpp> +#include <IRDB_SDK-util.hpp> + +#include <vector> +#include <set> +#include <map> +#include <ostream> + +#include <inc-syscall/syscall.hpp> + +#endif diff --git a/include/irdb-util b/include/irdb-util new file mode 100644 index 0000000000000000000000000000000000000000..17def90cd3574d2f2bdf009a22e4d55bbcc20db3 --- /dev/null +++ b/include/irdb-util @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2014 - 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 IRDB_SDK_util +#define IRDB_SDK_util + +/* Building a CFG depends on core functionality */ +#include <IRDB_SDK-core.hpp> +#include <vector> +#include <set> +#include <map> +#include <ostream> +#include <inc-util/insn_preds.hpp> +#include <inc-util/IBT_Provenance.hpp> +#include <inc-util/params.hpp> + +#endif