From 0cf59807fa364b11de65dc3f1e1c2d2bc7dd87a2 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Fri, 8 May 2020 05:26:56 -0400 Subject: Modifications for supporting jemalloc in the core --- highlevelilinstruction.cpp | 8 ++-- highlevelilinstruction.h | 80 ++++++++++++++++++------------- json/json.h | 2 +- json/jsoncpp.cpp | 4 +- lowlevelilinstruction.cpp | 4 +- lowlevelilinstruction.h | 87 ++++++++++++++++++++-------------- mediumlevelilinstruction.cpp | 2 + mediumlevelilinstruction.h | 109 +++++++++++++++++++++++++------------------ 8 files changed, 176 insertions(+), 120 deletions(-) diff --git a/highlevelilinstruction.cpp b/highlevelilinstruction.cpp index 88f833e0..d7d1c6aa 100644 --- a/highlevelilinstruction.cpp +++ b/highlevelilinstruction.cpp @@ -30,7 +30,9 @@ using namespace BinaryNinjaCore; using namespace BinaryNinja; #endif +#ifndef BINARYNINJACORE_LIBRARY using namespace std; +#endif unordered_map @@ -2320,7 +2322,7 @@ ExprId HighLevelILFunction::Nop(const ILSourceLocation& loc) } -ExprId HighLevelILFunction::Block(const std::vector& exprs, const ILSourceLocation& loc) +ExprId HighLevelILFunction::Block(const vector& exprs, const ILSourceLocation& loc) { return AddExprWithLocation(HLIL_BLOCK, loc, 0, exprs.size(), AddOperandList(exprs)); } @@ -2373,7 +2375,7 @@ ExprId HighLevelILFunction::ForSSA(ExprId initExpr, ExprId conditionPhi, ExprId } -ExprId HighLevelILFunction::Switch(ExprId condition, ExprId defaultExpr, const std::vector& cases, +ExprId HighLevelILFunction::Switch(ExprId condition, ExprId defaultExpr, const vector& cases, const ILSourceLocation& loc) { return AddExprWithLocation(HLIL_SWITCH, loc, 0, condition, defaultExpr, @@ -2381,7 +2383,7 @@ ExprId HighLevelILFunction::Switch(ExprId condition, ExprId defaultExpr, const s } -ExprId HighLevelILFunction::Case(const std::vector& values, ExprId expr, const ILSourceLocation& loc) +ExprId HighLevelILFunction::Case(const vector& values, ExprId expr, const ILSourceLocation& loc) { return AddExprWithLocation(HLIL_CASE, loc, 0, values.size(), AddOperandList(values), expr); } diff --git a/highlevelilinstruction.h b/highlevelilinstruction.h index fd140e24..497cf122 100644 --- a/highlevelilinstruction.h +++ b/highlevelilinstruction.h @@ -142,6 +142,16 @@ namespace BinaryNinjaCore namespace BinaryNinja #endif { +#ifdef BINARYNINJACORE_LIBRARY +#define _STD_VECTOR vector +#define _STD_SET set +#define _STD_UNORDERED_MAP unordered_map +#else +#define _STD_VECTOR std::vector +#define _STD_SET std::set +#define _STD_UNORDERED_MAP std::unordered_map +#endif + class HighLevelILInstructionAccessException: public std::exception { public: @@ -181,7 +191,7 @@ namespace BinaryNinja size_t size() const; uint64_t operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class HighLevelILIndexList @@ -208,7 +218,7 @@ namespace BinaryNinja size_t size() const; size_t operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class HighLevelILInstructionList @@ -240,7 +250,7 @@ namespace BinaryNinja size_t size() const; const HighLevelILInstruction operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class HighLevelILSSAVariableList @@ -267,7 +277,7 @@ namespace BinaryNinja size_t size() const; const SSAVariable operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; struct HighLevelILInstructionBase: public BNHighLevelILInstruction @@ -280,11 +290,11 @@ namespace BinaryNinja size_t exprIndex, instructionIndex; bool ast; - static std::unordered_map operandTypeForUsage; - static std::unordered_map> operationOperandUsage; - static std::unordered_map> operationOperandIndex; + static _STD_UNORDERED_MAP operandTypeForUsage; + static _STD_UNORDERED_MAP> operationOperandUsage; + static _STD_UNORDERED_MAP> operationOperandIndex; HighLevelILOperandList GetOperands() const; @@ -299,13 +309,13 @@ namespace BinaryNinja void UpdateRawOperand(size_t operandIndex, ExprId value); void UpdateRawOperandAsInteger(size_t operandIndex, uint64_t value); - void UpdateRawOperandAsSSAVariableList(size_t operandIndex, const std::vector& vars); - void UpdateRawOperandAsExprList(size_t operandIndex, const std::vector& exprs); - void UpdateRawOperandAsExprList(size_t operandIndex, const std::vector& exprs); + void UpdateRawOperandAsSSAVariableList(size_t operandIndex, const _STD_VECTOR& vars); + void UpdateRawOperandAsExprList(size_t operandIndex, const _STD_VECTOR& exprs); + void UpdateRawOperandAsExprList(size_t operandIndex, const _STD_VECTOR& exprs); RegisterValue GetValue() const; - PossibleValueSet GetPossibleValues(const std::set& options = - std::set()) const; + PossibleValueSet GetPossibleValues(const _STD_SET& options = + _STD_SET()) const; Confidence> GetType() const; size_t GetMediumLevelILExprIndex() const; @@ -426,17 +436,17 @@ namespace BinaryNinja template void SetSSAVersion(size_t version) { As().SetSSAVersion(version); } template void SetDestSSAVersion(size_t version) { As().SetDestSSAVersion(version); } - template void SetParameterExprs(const std::vector& params) { As().SetParameterExprs(params); } - template void SetParameterExprs(const std::vector& params) { As().SetParameterExprs(params); } - template void SetSourceExprs(const std::vector& params) { As().SetSourceExprs(params); } - template void SetSourceExprs(const std::vector& params) { As().SetSourceExprs(params); } - template void SetDestExprs(const std::vector& params) { As().SetDestExprs(params); } - template void SetDestExprs(const std::vector& params) { As().SetDestExprs(params); } - template void SetBlockExprs(const std::vector& params) { As().SetBlockExprs(params); } - template void SetBlockExprs(const std::vector& params) { As().SetBlockExprs(params); } - template void SetCases(const std::vector& params) { As().SetCases(params); } - template void SetCases(const std::vector& params) { As().SetCases(params); } - template void SetSourceSSAVariables(const std::vector& vars) { As().SetSourceSSAVariables(vars); } + template void SetParameterExprs(const _STD_VECTOR& params) { As().SetParameterExprs(params); } + template void SetParameterExprs(const _STD_VECTOR& params) { As().SetParameterExprs(params); } + template void SetSourceExprs(const _STD_VECTOR& params) { As().SetSourceExprs(params); } + template void SetSourceExprs(const _STD_VECTOR& params) { As().SetSourceExprs(params); } + template void SetDestExprs(const _STD_VECTOR& params) { As().SetDestExprs(params); } + template void SetDestExprs(const _STD_VECTOR& params) { As().SetDestExprs(params); } + template void SetBlockExprs(const _STD_VECTOR& params) { As().SetBlockExprs(params); } + template void SetBlockExprs(const _STD_VECTOR& params) { As().SetBlockExprs(params); } + template void SetCases(const _STD_VECTOR& params) { As().SetCases(params); } + template void SetCases(const _STD_VECTOR& params) { As().SetCases(params); } + template void SetSourceSSAVariables(const _STD_VECTOR& vars) { As().SetSourceSSAVariables(vars); } template void SetSourceMemoryVersion(size_t version) { return As().SetSourceMemoryVersion(version); } template void SetDestMemoryVersion(size_t version) { return As().SetDestMemoryVersion(version); } template void SetTarget(uint64_t target) { As().SetTarget(target); } @@ -513,7 +523,7 @@ namespace BinaryNinja struct ListIterator { const HighLevelILOperandList* owner; - std::vector::const_iterator pos; + _STD_VECTOR::const_iterator pos; bool operator==(const ListIterator& a) const { return pos == a.pos; } bool operator!=(const ListIterator& a) const { return pos != a.pos; } bool operator<(const ListIterator& a) const { return pos < a.pos; } @@ -522,22 +532,22 @@ namespace BinaryNinja }; HighLevelILInstruction m_instr; - const std::vector& m_usageList; - const std::unordered_map& m_operandIndexMap; + const _STD_VECTOR& m_usageList; + const _STD_UNORDERED_MAP& m_operandIndexMap; public: typedef ListIterator const_iterator; HighLevelILOperandList(const HighLevelILInstruction& instr, - const std::vector& usageList, - const std::unordered_map& operandIndexMap); + const _STD_VECTOR& usageList, + const _STD_UNORDERED_MAP& operandIndexMap); const_iterator begin() const; const_iterator end() const; size_t size() const; const HighLevelILOperand operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; struct HighLevelILConstantInstruction: public HighLevelILInstructionBase @@ -638,7 +648,7 @@ namespace BinaryNinja template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { HighLevelILInstructionList GetSourceExprs() const { return GetRawOperandAsExprList(0); } - void SetSourceExprs(const std::vector& exprs) { UpdateRawOperandAsExprList(0, exprs); } + void SetSourceExprs(const _STD_VECTOR& exprs) { UpdateRawOperandAsExprList(0, exprs); } }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase @@ -742,7 +752,7 @@ namespace BinaryNinja { SSAVariable GetDestSSAVariable() const { return GetRawOperandAsSSAVariable(0); } HighLevelILSSAVariableList GetSourceSSAVariables() const { return GetRawOperandAsSSAVariableList(2); } - void SetSourceSSAVariables(const std::vector& vars) { UpdateRawOperandAsSSAVariableList(2, vars); } + void SetSourceSSAVariables(const _STD_VECTOR& vars) { UpdateRawOperandAsSSAVariableList(2, vars); } }; template <> struct HighLevelILInstructionAccessor: public HighLevelILInstructionBase { @@ -897,4 +907,8 @@ namespace BinaryNinja template <> struct HighLevelILInstructionAccessor: public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor: public HighLevelILOneOperandInstruction {}; template <> struct HighLevelILInstructionAccessor: public HighLevelILOneOperandInstruction {}; + +#undef _STD_VECTOR +#undef _STD_SET +#undef _STD_UNORDERED_MAP } diff --git a/json/json.h b/json/json.h index 51a38e65..da91470a 100644 --- a/json/json.h +++ b/json/json.h @@ -308,7 +308,7 @@ typedef UInt64 LargestUInt; std::basic_istringstream, \ Json::SecureAllocator > #define JSONCPP_ISTREAM std::istream -#else +#elif !defined(JSONCPP_STRING) #define JSONCPP_STRING std::string #define JSONCPP_OSTRINGSTREAM std::ostringstream #define JSONCPP_OSTREAM std::ostream diff --git a/json/jsoncpp.cpp b/json/jsoncpp.cpp index c2a949d3..4154200b 100644 --- a/json/jsoncpp.cpp +++ b/json/jsoncpp.cpp @@ -71,7 +71,9 @@ license you like. - +#ifdef BINARYNINJACORE_LIBRARY +#include "binaryninjacore_global.h" +#endif #include "json/json.h" diff --git a/lowlevelilinstruction.cpp b/lowlevelilinstruction.cpp index f55d15f0..faaa79a9 100644 --- a/lowlevelilinstruction.cpp +++ b/lowlevelilinstruction.cpp @@ -30,7 +30,9 @@ using namespace BinaryNinjaCore; using namespace BinaryNinja; #endif +#ifndef BINARYNINJACORE_LIBRARY using namespace std; +#endif unordered_map @@ -3262,7 +3264,7 @@ ExprId LowLevelILFunction::Call(ExprId dest, const ILSourceLocation& loc) ExprId LowLevelILFunction::CallStackAdjust(ExprId dest, int64_t adjust, - const std::map& regStackAdjust, const ILSourceLocation& loc) + const map& regStackAdjust, const ILSourceLocation& loc) { vector list; for (auto& i : regStackAdjust) diff --git a/lowlevelilinstruction.h b/lowlevelilinstruction.h index 0fcc36eb..183ce10b 100644 --- a/lowlevelilinstruction.h +++ b/lowlevelilinstruction.h @@ -316,6 +316,18 @@ namespace BinaryNinjaCore namespace BinaryNinja #endif { +#ifdef BINARYNINJACORE_LIBRARY +#define _STD_VECTOR vector +#define _STD_SET set +#define _STD_UNORDERED_MAP unordered_map +#define _STD_MAP map +#else +#define _STD_VECTOR std::vector +#define _STD_SET std::set +#define _STD_UNORDERED_MAP std::unordered_map +#define _STD_MAP std::map +#endif + class LowLevelILInstructionAccessException: public std::exception { public: @@ -356,7 +368,7 @@ namespace BinaryNinja size_t size() const; uint64_t operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class LowLevelILIndexList @@ -383,7 +395,7 @@ namespace BinaryNinja size_t size() const; size_t operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class LowLevelILIndexMap @@ -410,7 +422,7 @@ namespace BinaryNinja size_t size() const; size_t operator[](uint64_t value) const; - operator std::map() const; + operator _STD_MAP() const; }; class LowLevelILInstructionList @@ -440,7 +452,7 @@ namespace BinaryNinja size_t size() const; const LowLevelILInstruction operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class LowLevelILRegisterOrFlagList @@ -467,7 +479,7 @@ namespace BinaryNinja size_t size() const; const RegisterOrFlag operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class LowLevelILSSARegisterList @@ -494,7 +506,7 @@ namespace BinaryNinja size_t size() const; const SSARegister operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class LowLevelILSSARegisterStackList @@ -521,7 +533,7 @@ namespace BinaryNinja size_t size() const; const SSARegisterStack operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class LowLevelILSSAFlagList @@ -548,7 +560,7 @@ namespace BinaryNinja size_t size() const; const SSAFlag operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class LowLevelILSSARegisterOrFlagList @@ -575,7 +587,7 @@ namespace BinaryNinja size_t size() const; const SSARegisterOrFlag operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; struct LowLevelILInstructionBase: public BNLowLevelILInstruction @@ -587,11 +599,11 @@ namespace BinaryNinja #endif size_t exprIndex, instructionIndex; - static std::unordered_map operandTypeForUsage; - static std::unordered_map> operationOperandUsage; - static std::unordered_map> operationOperandIndex; + static _STD_UNORDERED_MAP operandTypeForUsage; + static _STD_UNORDERED_MAP> operationOperandUsage; + static _STD_UNORDERED_MAP> operationOperandIndex; LowLevelILOperandList GetOperands() const; @@ -612,15 +624,15 @@ namespace BinaryNinja LowLevelILSSARegisterStackList GetRawOperandAsSSARegisterStackList(size_t operand) const; LowLevelILSSAFlagList GetRawOperandAsSSAFlagList(size_t operand) const; LowLevelILSSARegisterOrFlagList GetRawOperandAsSSARegisterOrFlagList(size_t operand) const; - std::map GetRawOperandAsRegisterStackAdjustments(size_t operand) const; + _STD_MAP GetRawOperandAsRegisterStackAdjustments(size_t operand) const; void UpdateRawOperand(size_t operandIndex, ExprId value); - void UpdateRawOperandAsSSARegisterList(size_t operandIndex, const std::vector& regs); - void UpdateRawOperandAsSSARegisterOrFlagList(size_t operandIndex, const std::vector& outputs); + void UpdateRawOperandAsSSARegisterList(size_t operandIndex, const _STD_VECTOR& regs); + void UpdateRawOperandAsSSARegisterOrFlagList(size_t operandIndex, const _STD_VECTOR& outputs); RegisterValue GetValue() const; - PossibleValueSet GetPossibleValues(const std::set& options = - std::set()) const; + PossibleValueSet GetPossibleValues(const _STD_SET& options = + _STD_SET()) const; RegisterValue GetRegisterValue(uint32_t reg); RegisterValue GetRegisterValueAfter(uint32_t reg); @@ -762,7 +774,7 @@ namespace BinaryNinja template LowLevelILSSARegisterOrFlagList GetOutputSSARegisterOrFlagList() const { return As().GetOutputSSARegisterOrFlagList(); } template LowLevelILIndexList GetSourceMemoryVersions() const { return As().GetSourceMemoryVersions(); } template LowLevelILIndexMap GetTargets() const { return As().GetTargets(); } - template std::map GetRegisterStackAdjustments() const { return As().GetRegisterStackAdjustments(); } + template _STD_MAP GetRegisterStackAdjustments() const { return As().GetRegisterStackAdjustments(); } template void SetDestSSAVersion(size_t version) { As().SetDestSSAVersion(version); } template void SetSourceSSAVersion(size_t version) { As().SetSourceSSAVersion(version); } @@ -772,8 +784,8 @@ namespace BinaryNinja template void SetTopSSAVersion(size_t version) { As().SetTopSSAVersion(version); } template void SetDestMemoryVersion(size_t version) { As().SetDestMemoryVersion(version); } template void SetSourceMemoryVersion(size_t version) { As().SetSourceMemoryVersion(version); } - template void SetOutputSSARegisters(const std::vector& regs) { As().SetOutputSSARegisters(regs); } - template void SetOutputSSARegisterOrFlagList(const std::vector& outputs) { As().SetOutputSSARegisterOrFlagList(outputs); } + template void SetOutputSSARegisters(const _STD_VECTOR& regs) { As().SetOutputSSARegisters(regs); } + template void SetOutputSSARegisterOrFlagList(const _STD_VECTOR& outputs) { As().SetOutputSSARegisterOrFlagList(outputs); } bool GetOperandIndexForUsage(LowLevelILOperandUsage usage, size_t& operandIndex) const; @@ -827,7 +839,7 @@ namespace BinaryNinja LowLevelILSSARegisterOrFlagList GetOutputSSARegisterOrFlagList() const; LowLevelILIndexList GetSourceMemoryVersions() const; LowLevelILIndexMap GetTargets() const; - std::map GetRegisterStackAdjustments() const; + _STD_MAP GetRegisterStackAdjustments() const; }; class LowLevelILOperand @@ -865,7 +877,7 @@ namespace BinaryNinja LowLevelILSSAFlagList GetSSAFlagList() const; LowLevelILRegisterOrFlagList GetRegisterOrFlagList() const; LowLevelILSSARegisterOrFlagList GetSSARegisterOrFlagList() const; - std::map GetRegisterStackAdjustments() const; + _STD_MAP GetRegisterStackAdjustments() const; }; class LowLevelILOperandList @@ -873,7 +885,7 @@ namespace BinaryNinja struct ListIterator { const LowLevelILOperandList* owner; - std::vector::const_iterator pos; + _STD_VECTOR::const_iterator pos; bool operator==(const ListIterator& a) const { return pos == a.pos; } bool operator!=(const ListIterator& a) const { return pos != a.pos; } bool operator<(const ListIterator& a) const { return pos < a.pos; } @@ -882,22 +894,22 @@ namespace BinaryNinja }; LowLevelILInstruction m_instr; - const std::vector& m_usageList; - const std::unordered_map& m_operandIndexMap; + const _STD_VECTOR& m_usageList; + const _STD_UNORDERED_MAP& m_operandIndexMap; public: typedef ListIterator const_iterator; LowLevelILOperandList(const LowLevelILInstruction& instr, - const std::vector& usageList, - const std::unordered_map& operandIndexMap); + const _STD_VECTOR& usageList, + const _STD_UNORDERED_MAP& operandIndexMap); const_iterator begin() const; const_iterator end() const; size_t size() const; const LowLevelILOperand operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; struct LowLevelILConstantInstruction: public LowLevelILInstructionBase @@ -1145,7 +1157,7 @@ namespace BinaryNinja { LowLevelILInstruction GetDestExpr() const { return GetRawOperandAsExpr(0); } int64_t GetStackAdjustment() const { return GetRawOperandAsInteger(1); } - std::map GetRegisterStackAdjustments() const { return GetRawOperandAsRegisterStackAdjustments(2); } + _STD_MAP GetRegisterStackAdjustments() const { return GetRawOperandAsRegisterStackAdjustments(2); } }; template <> struct LowLevelILInstructionAccessor: public LowLevelILInstructionBase { @@ -1193,7 +1205,7 @@ namespace BinaryNinja void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { GetRawOperandAsExpr(2).UpdateRawOperand(2, version); } void SetStackSSAVersion(size_t version) { GetRawOperandAsExpr(2).UpdateRawOperand(1, version); } - void SetOutputSSARegisters(const std::vector& regs) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSARegisterList(1, regs); } + void SetOutputSSARegisters(const _STD_VECTOR& regs) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSARegisterList(1, regs); } }; template <> struct LowLevelILInstructionAccessor: public LowLevelILInstructionBase { @@ -1205,7 +1217,7 @@ namespace BinaryNinja void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { GetRawOperandAsExpr(1).UpdateRawOperand(2, version); } void SetStackSSAVersion(size_t version) { GetRawOperandAsExpr(1).UpdateRawOperand(1, version); } - void SetOutputSSARegisters(const std::vector& regs) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSARegisterList(1, regs); } + void SetOutputSSARegisters(const _STD_VECTOR& regs) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSARegisterList(1, regs); } }; template <> struct LowLevelILInstructionAccessor: public LowLevelILInstructionBase { @@ -1218,7 +1230,7 @@ namespace BinaryNinja void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { GetRawOperandAsExpr(2).UpdateRawOperand(2, version); } void SetStackSSAVersion(size_t version) { GetRawOperandAsExpr(2).UpdateRawOperand(1, version); } - void SetOutputSSARegisters(const std::vector& regs) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSARegisterList(1, regs); } + void SetOutputSSARegisters(const _STD_VECTOR& regs) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSARegisterList(1, regs); } }; template <> struct LowLevelILInstructionAccessor: public LowLevelILInstructionBase @@ -1232,7 +1244,7 @@ namespace BinaryNinja LowLevelILSSARegisterOrFlagList GetOutputSSARegisterOrFlagList() const { return GetRawOperandAsSSARegisterOrFlagList(0); } uint32_t GetIntrinsic() const { return GetRawOperandAsRegister(2); } LowLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExpr(3).GetRawOperandAsExprList(0); } - void SetOutputSSARegisterOrFlagList(const std::vector& outputs) { UpdateRawOperandAsSSARegisterOrFlagList(0, outputs); } + void SetOutputSSARegisterOrFlagList(const _STD_VECTOR& outputs) { UpdateRawOperandAsSSARegisterOrFlagList(0, outputs); } }; template <> struct LowLevelILInstructionAccessor: public LowLevelILInstructionBase @@ -1343,4 +1355,9 @@ namespace BinaryNinja template <> struct LowLevelILInstructionAccessor: public LowLevelILOneOperandInstruction {}; template <> struct LowLevelILInstructionAccessor: public LowLevelILOneOperandInstruction {}; template <> struct LowLevelILInstructionAccessor: public LowLevelILOneOperandInstruction {}; + +#undef _STD_VECTOR +#undef _STD_SET +#undef _STD_UNORDERED_MAP +#undef _STD_MAP } diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp index 0ff7323e..3779eb90 100644 --- a/mediumlevelilinstruction.cpp +++ b/mediumlevelilinstruction.cpp @@ -30,7 +30,9 @@ using namespace BinaryNinjaCore; using namespace BinaryNinja; #endif +#ifndef BINARYNINJACORE_LIBRARY using namespace std; +#endif unordered_map diff --git a/mediumlevelilinstruction.h b/mediumlevelilinstruction.h index 76b4ae61..f3b3062a 100644 --- a/mediumlevelilinstruction.h +++ b/mediumlevelilinstruction.h @@ -179,6 +179,18 @@ namespace BinaryNinjaCore namespace BinaryNinja #endif { +#ifdef BINARYNINJACORE_LIBRARY +#define _STD_VECTOR vector +#define _STD_SET set +#define _STD_UNORDERED_MAP unordered_map +#define _STD_MAP map +#else +#define _STD_VECTOR std::vector +#define _STD_SET std::set +#define _STD_UNORDERED_MAP std::unordered_map +#define _STD_MAP std::map +#endif + class MediumLevelILInstructionAccessException: public std::exception { public: @@ -219,7 +231,7 @@ namespace BinaryNinja size_t size() const; uint64_t operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class MediumLevelILIndexList @@ -246,7 +258,7 @@ namespace BinaryNinja size_t size() const; size_t operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class MediumLevelILIndexMap @@ -273,7 +285,7 @@ namespace BinaryNinja size_t size() const; size_t operator[](uint64_t) const; - operator std::map() const; + operator _STD_MAP() const; }; class MediumLevelILVariableList @@ -300,7 +312,7 @@ namespace BinaryNinja size_t size() const; const Variable operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class MediumLevelILSSAVariableList @@ -327,7 +339,7 @@ namespace BinaryNinja size_t size() const; const SSAVariable operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; class MediumLevelILInstructionList @@ -357,7 +369,7 @@ namespace BinaryNinja size_t size() const; const MediumLevelILInstruction operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; struct MediumLevelILInstructionBase: public BNMediumLevelILInstruction @@ -369,11 +381,11 @@ namespace BinaryNinja #endif size_t exprIndex, instructionIndex; - static std::unordered_map operandTypeForUsage; - static std::unordered_map> operationOperandUsage; - static std::unordered_map> operationOperandIndex; + static _STD_UNORDERED_MAP operandTypeForUsage; + static _STD_UNORDERED_MAP> operationOperandUsage; + static _STD_UNORDERED_MAP> operationOperandIndex; MediumLevelILOperandList GetOperands() const; @@ -390,13 +402,13 @@ namespace BinaryNinja MediumLevelILInstructionList GetRawOperandAsExprList(size_t operand) const; void UpdateRawOperand(size_t operandIndex, ExprId value); - void UpdateRawOperandAsSSAVariableList(size_t operandIndex, const std::vector& vars); - void UpdateRawOperandAsExprList(size_t operandIndex, const std::vector& exprs); - void UpdateRawOperandAsExprList(size_t operandIndex, const std::vector& exprs); + void UpdateRawOperandAsSSAVariableList(size_t operandIndex, const _STD_VECTOR& vars); + void UpdateRawOperandAsExprList(size_t operandIndex, const _STD_VECTOR& exprs); + void UpdateRawOperandAsExprList(size_t operandIndex, const _STD_VECTOR& exprs); RegisterValue GetValue() const; - PossibleValueSet GetPossibleValues(const std::set& options = - std::set()) const; + PossibleValueSet GetPossibleValues(const _STD_SET& options = + _STD_SET()) const; Confidence> GetType() const; size_t GetSSAVarVersion(const Variable& var); @@ -421,7 +433,7 @@ namespace BinaryNinja BNILBranchDependence GetBranchDependence(size_t branchInstr); BNILBranchDependence GetBranchDependence(const MediumLevelILInstruction& branch); - std::unordered_map GetAllBranchDependence(); + _STD_UNORDERED_MAP GetAllBranchDependence(); size_t GetSSAInstructionIndex() const; size_t GetNonSSAInstructionIndex() const; @@ -539,12 +551,12 @@ namespace BinaryNinja template void SetLowSSAVersion(size_t version) { As().SetLowSSAVersion(version); } template void SetDestMemoryVersion(size_t version) { As().SetDestMemoryVersion(version); } template void SetSourceMemoryVersion(size_t version) { As().SetSourceMemoryVersion(version); } - template void SetOutputSSAVariables(const std::vector& vars) { As().SetOutputSSAVariables(vars); } - template void SetParameterSSAVariables(const std::vector& vars) { As().SetParameterSSAVariables(vars); } - template void SetParameterExprs(const std::vector& params) { As().SetParameterExprs(params); } - template void SetParameterExprs(const std::vector& params) { As().SetParameterExprs(params); } - template void SetSourceExprs(const std::vector& params) { As().SetSourceExprs(params); } - template void SetSourceExprs(const std::vector& params) { As().SetSourceExprs(params); } + template void SetOutputSSAVariables(const _STD_VECTOR& vars) { As().SetOutputSSAVariables(vars); } + template void SetParameterSSAVariables(const _STD_VECTOR& vars) { As().SetParameterSSAVariables(vars); } + template void SetParameterExprs(const _STD_VECTOR& params) { As().SetParameterExprs(params); } + template void SetParameterExprs(const _STD_VECTOR& params) { As().SetParameterExprs(params); } + template void SetSourceExprs(const _STD_VECTOR& params) { As().SetSourceExprs(params); } + template void SetSourceExprs(const _STD_VECTOR& params) { As().SetSourceExprs(params); } bool GetOperandIndexForUsage(MediumLevelILOperandUsage usage, size_t& operandIndex) const; @@ -617,7 +629,7 @@ namespace BinaryNinja struct ListIterator { const MediumLevelILOperandList* owner; - std::vector::const_iterator pos; + _STD_VECTOR::const_iterator pos; bool operator==(const ListIterator& a) const { return pos == a.pos; } bool operator!=(const ListIterator& a) const { return pos != a.pos; } bool operator<(const ListIterator& a) const { return pos < a.pos; } @@ -626,22 +638,22 @@ namespace BinaryNinja }; MediumLevelILInstruction m_instr; - const std::vector& m_usageList; - const std::unordered_map& m_operandIndexMap; + const _STD_VECTOR& m_usageList; + const _STD_UNORDERED_MAP& m_operandIndexMap; public: typedef ListIterator const_iterator; MediumLevelILOperandList(const MediumLevelILInstruction& instr, - const std::vector& usageList, - const std::unordered_map& operandIndexMap); + const _STD_VECTOR& usageList, + const _STD_UNORDERED_MAP& operandIndexMap); const_iterator begin() const; const_iterator end() const; size_t size() const; const MediumLevelILOperand operator[](size_t i) const; - operator std::vector() const; + operator _STD_VECTOR() const; }; struct MediumLevelILConstantInstruction: public MediumLevelILInstructionBase @@ -896,9 +908,9 @@ namespace BinaryNinja size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(4); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(4, version); } - void SetOutputSSAVariables(const std::vector& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } - void SetParameterExprs(const std::vector& params) { UpdateRawOperandAsExprList(2, params); } - void SetParameterExprs(const std::vector& params) { UpdateRawOperandAsExprList(2, params); } + void SetOutputSSAVariables(const _STD_VECTOR& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } + void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); } + void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); } }; template <> struct MediumLevelILInstructionAccessor: public MediumLevelILInstructionBase { @@ -910,8 +922,8 @@ namespace BinaryNinja MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(3); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { GetRawOperandAsExpr(2).UpdateRawOperand(0, version); } - void SetOutputSSAVariables(const std::vector& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } - void SetParameterSSAVariables(const std::vector& vars) { GetRawOperandAsExpr(2).UpdateRawOperandAsSSAVariableList(1, vars); } + void SetOutputSSAVariables(const _STD_VECTOR& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } + void SetParameterSSAVariables(const _STD_VECTOR& vars) { GetRawOperandAsExpr(2).UpdateRawOperandAsSSAVariableList(1, vars); } }; template <> struct MediumLevelILInstructionAccessor: public MediumLevelILInstructionBase { @@ -921,9 +933,9 @@ namespace BinaryNinja size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(3); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(3, version); } - void SetOutputSSAVariables(const std::vector& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } - void SetParameterExprs(const std::vector& params) { UpdateRawOperandAsExprList(1, params); } - void SetParameterExprs(const std::vector& params) { UpdateRawOperandAsExprList(1, params); } + void SetOutputSSAVariables(const _STD_VECTOR& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } + void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(1, params); } + void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(1, params); } }; template <> struct MediumLevelILInstructionAccessor: public MediumLevelILInstructionBase { @@ -934,8 +946,8 @@ namespace BinaryNinja MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(2); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { GetRawOperandAsExpr(1).UpdateRawOperand(0, version); } - void SetOutputSSAVariables(const std::vector& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } - void SetParameterSSAVariables(const std::vector& vars) { GetRawOperandAsExpr(1).UpdateRawOperandAsSSAVariableList(1, vars); } + void SetOutputSSAVariables(const _STD_VECTOR& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } + void SetParameterSSAVariables(const _STD_VECTOR& vars) { GetRawOperandAsExpr(1).UpdateRawOperandAsSSAVariableList(1, vars); } }; template <> struct MediumLevelILInstructionAccessor: public MediumLevelILInstructionBase { @@ -946,9 +958,9 @@ namespace BinaryNinja size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(4); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(4, version); } - void SetOutputSSAVariables(const std::vector& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } - void SetParameterExprs(const std::vector& params) { UpdateRawOperandAsExprList(2, params); } - void SetParameterExprs(const std::vector& params) { UpdateRawOperandAsExprList(2, params); } + void SetOutputSSAVariables(const _STD_VECTOR& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } + void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); } + void SetParameterExprs(const _STD_VECTOR& params) { UpdateRawOperandAsExprList(2, params); } }; template <> struct MediumLevelILInstructionAccessor: public MediumLevelILInstructionBase { @@ -960,14 +972,14 @@ namespace BinaryNinja MediumLevelILInstruction GetStackExpr() const { return GetRawOperandAsExpr(3); } void SetDestMemoryVersion(size_t version) { GetRawOperandAsExpr(0).UpdateRawOperand(0, version); } void SetSourceMemoryVersion(size_t version) { GetRawOperandAsExpr(2).UpdateRawOperand(0, version); } - void SetOutputSSAVariables(const std::vector& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } - void SetParameterSSAVariables(const std::vector& vars) { GetRawOperandAsExpr(2).UpdateRawOperandAsSSAVariableList(1, vars); } + void SetOutputSSAVariables(const _STD_VECTOR& vars) { GetRawOperandAsExpr(0).UpdateRawOperandAsSSAVariableList(1, vars); } + void SetParameterSSAVariables(const _STD_VECTOR& vars) { GetRawOperandAsExpr(2).UpdateRawOperandAsSSAVariableList(1, vars); } }; template <> struct MediumLevelILInstructionAccessor: public MediumLevelILInstructionBase { MediumLevelILInstructionList GetSourceExprs() const { return GetRawOperandAsExprList(0); } - void SetSourceExprs(const std::vector& exprs) { UpdateRawOperandAsExprList(0, exprs); } + void SetSourceExprs(const _STD_VECTOR& exprs) { UpdateRawOperandAsExprList(0, exprs); } }; template <> struct MediumLevelILInstructionAccessor: public MediumLevelILInstructionBase @@ -992,7 +1004,7 @@ namespace BinaryNinja MediumLevelILSSAVariableList GetOutputSSAVariables() const { return GetRawOperandAsSSAVariableList(0); } uint32_t GetIntrinsic() const { return (uint32_t)GetRawOperandAsInteger(2); } MediumLevelILInstructionList GetParameterExprs() const { return GetRawOperandAsExprList(3); } - void SetOutputSSAVariables(const std::vector& vars) { UpdateRawOperandAsSSAVariableList(0, vars); } + void SetOutputSSAVariables(const _STD_VECTOR& vars) { UpdateRawOperandAsSSAVariableList(0, vars); } }; template <> struct MediumLevelILInstructionAccessor: public MediumLevelILInstructionBase @@ -1108,4 +1120,9 @@ namespace BinaryNinja template <> struct MediumLevelILInstructionAccessor: public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor: public MediumLevelILOneOperandInstruction {}; template <> struct MediumLevelILInstructionAccessor: public MediumLevelILOneOperandInstruction {}; + +#undef _STD_VECTOR +#undef _STD_SET +#undef _STD_UNORDERED_MAP +#undef _STD_MAP } -- cgit v1.3.1