Skip to content
Snippets Groups Projects
Commit a65d9996 authored by Jason Hiser's avatar Jason Hiser :tractor:
Browse files

refactoring libirdb-util and libirdb-syscall

parent 87299dec
No related branches found
No related tags found
No related merge requests found
......@@ -3,53 +3,58 @@ namespace IRDB_SDK
using namespace std;
// enums
enum ADFileType {
adftELF,
adftCGC,
adftPE,
adftNone
};
using ADFileType_t = enum ADFileType
{
adftELF,
adftCGC,
adftPE,
adftNone
};
enum ADMachineType {
admtAarch64,
admtX86_64,
admtI386,
admtNone
};
using ADMachineType_t = enum ADMachineType
{
admtAarch64,
admtX86_64,
admtI386,
admtNone
};
enum DatabaseErrorType {
detVariantNotInDatabase,
detVariantTableNotRegistered
};
using DatabaseErrorType_t = enum DatabaseErrorType
{
detVariantNotInDatabase,
detVariantTableNotRegistered
};
enum ICFSAnalysisStatus {
iasAnalysisIncomplete,
iasAnalysisModuleComplete,
iasAnalysisComplete
};
using ICFSAnalysisStatus_t = enum ICFSAnalysisStatus
{
iasAnalysisIncomplete,
iasAnalysisModuleComplete,
iasAnalysisComplete
};
enum IRDBType {
itUnknown,
itNumeric,
itPointer,
itVoid,
itVariadic,
itInt,
itChar,
itFloat,
itDouble,
itTypedef,
itSubtype,
itFunc,
itAggregate
};
using IRDBType_t = 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;
//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;
......
......@@ -21,7 +21,7 @@ namespace IRDB_SDK
virtual bool isPointerType() const = 0;
virtual bool isNumericType() const = 0;
virtual void setTypeID(IRDBType t) = 0;
virtual void setTypeID(IRDBType_t ty) = 0;
virtual void setName(const string& newname) = 0;
};
......
namespace IRDB_SDK
{
using namespace std;
using SyscallNumber_t = enum SyscallNumber
{
sntUnknown=-1,
};
class SyscallSite_t
{
protected:
SyscallSite_t() { }
SyscallSite_t(const SyscallSite_t& copy) = delete;
public:
virtual ~SyscallSite_t() { }
virtual Instruction_t* getSyscallSite() const = 0 ;
virtual Instruction_t* getSite() const = 0 ;
virtual SyscallNumber_t getSyscallNumber() const = 0 ;
};
using SyscallSiteSet_t = set<SyscallSite_t*>;
class Syscalls_t
{
protected:
Syscalls_t() { }
Syscalls_t(const Syscalls_t& copy) = delete;
public:
virtual ~Syscalls_t() { }
// getters
virtual const SyscallSiteSet_t& getSyscalls() const = 0;
// factories
static unique_ptr<Syscalls_t> factory(FileIR_t *the_firp);
};
}
namespace IRDB_SDK
{
class IBTProvenance_t
{
public:
IBTProvenance_t() {}
IBTProvenance_t(const IBTProvenance_t& copy) = delete;
public:
virtual ~IBTProvenance_t() {}
static unique_ptr<IBTProvenance_t> factory(const FileIR_t* f=NULL);
virtual const Provenance_t& getProvenance(const Instruction_t* i) const = 0 ;
virtual const Provenance_t& operator[] (const Instruction_t* i) const = 0 ;
};
}
namespace IRDB_SDK
{
using namespace std;
class Provenance_t
{
protected:
Provenance_t() {}
Provenance_t(const Provenance_t& copy) = delete;
public:
virtual ~Provenance_t() {}
virtual bool hasReturn() const = 0;
virtual bool hasIndirectJump() const = 0;
virtual bool hasIndirectCall() const = 0;
};
}
namespace IRDB_SDK
{
class InstructionPredecessors_t
{
protected:
InstructionPredecessors_t() { }
InstructionPredecessors_t(const InstructionPredecessors_t& copy) = delete;
public:
virtual ~InstructionPredecessors_t() { }
// getters
virtual const InstructionSet_t& getPredecessors(const Instruction_t* i) const = 0;
virtual const InstructionSet_t& operator[] (const Instruction_t* i) const = 0;
// factories
static unique_ptr<InstructionPredecessors_t> factory(FileIR_t* firp=nullptr);
};
}
namespace IRDB_SDK
{
extern bool isParameterWrite(const FileIR_t *firp, Instruction_t* insn, std::string& output_dst);
extern bool callFollows(const FileIR_t *firp, Instruction_t* insn, const std::string& arg_str, const std::string & = "");
extern bool leaFlowsIntoCall(const FileIR_t *firp, Instruction_t* insn);
extern bool leaFlowsIntoPrintf(const FileIR_t *firp, Instruction_t* insn);
extern bool flowsIntoCall(const FileIR_t *firp, Instruction_t* insn);
}
namespace IRDB_SDK
{
using namespace std;
template <class T>
inline string to_hex_string (const T& t)
{
auto ss=stringstream();
ss << hex << t;
return ss.str();
}
template<class T> inline T strtoint(const string& s)
{
auto str=stringstream(s);
auto off=T();
str >> off;
return off;
}
// nb: relies on srand() being previously set
template <typename IterType, typename Funct>
inline Funct for_randomOrder_each(const IterType &b, const IterType & e, const Funct &callback)
{
auto m=map<int,const typename iterator_traits<IterType>::value_type *>();
for_each(b,e, [&](const typename iterator_traits<IterType>::value_type & o)
{
while(true)
{
auto rn=rand();
if(m.find(rn)==m.end())
{
m[rn]=&o;
break;
}
}
});
for_each(m.begin(), m.end(), [&](const pair<int,const typename iterator_traits<IterType>::value_type *> &p)
{
callback(*p.second);
});
return callback;
}
}
/*
* 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 <irdb-core>
#include <vector>
#include <set>
......
......@@ -22,13 +22,13 @@
#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/Provenance.hpp>
#include <inc-util/IBT_Provenance.hpp>
#include <inc-util/params.hpp>
#include <inc-util/utils.hpp>
#endif
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