summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter LaFosse <peter@vector35.com>2018-08-16 22:30:15 -0400
committerPeter LaFosse <peter@vector35.com>2018-08-16 22:30:15 -0400
commit00fc6c96d415bd31ee5ecbec70a8e4de141674cd (patch)
tree0a6ed958eb313fa54727fb8bc0d3afdcef4d83cd
parent1ce780cd6a66a289b0422298871d61392ad3ec2a (diff)
Adding EXTERN_PTR type
-rw-r--r--binaryninjaapi.h4
-rw-r--r--binaryninjacore.h6
-rw-r--r--examples/llil_parser/src/llil_parser.cpp8
-rw-r--r--examples/mlil_parser/src/mlil_parser.cpp8
-rw-r--r--lowlevelilinstruction.cpp19
-rw-r--r--lowlevelilinstruction.h17
-rw-r--r--mediumlevelilinstruction.cpp9
-rw-r--r--mediumlevelilinstruction.h6
-rw-r--r--python/lowlevelil.py4
-rw-r--r--python/mediumlevelil.py1
10 files changed, 67 insertions, 15 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index ecf55e98..c89dd0b9 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -1000,6 +1000,7 @@ namespace BinaryNinja
bool autoDiscovered;
};
+ class Relocation;
class Segment: public CoreRefCountObject<BNSegment, BNNewSegmentReference, BNFreeSegment>
{
public:
@@ -1015,6 +1016,7 @@ namespace BinaryNinja
std::vector<std::pair<uint64_t, uint64_t>> GetRelocationRanges() const;
std::vector<std::pair<uint64_t, uint64_t>> GetRelocationRangesAtAddress(uint64_t addr) const;
+ std::vector<Ref<Relocation>> GetRelocationsInRange(uint64_t addr, uint64_t size) const;
uint64_t GetRelocationsCount() const;
void SetStart(uint64_t newSegmentBase);
@@ -2814,6 +2816,7 @@ namespace BinaryNinja
uint32_t reg, const ILSourceLocation& loc = ILSourceLocation());
ExprId Const(size_t size, uint64_t val, const ILSourceLocation& loc = ILSourceLocation());
ExprId ConstPointer(size_t size, uint64_t val, const ILSourceLocation& loc = ILSourceLocation());
+ ExprId ExternPointer(size_t size, uint64_t val, uint64_t offset, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatConstRaw(size_t size, uint64_t val, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatConstSingle(float val, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatConstDouble(double val, const ILSourceLocation& loc = ILSourceLocation());
@@ -3146,6 +3149,7 @@ namespace BinaryNinja
const ILSourceLocation& loc = ILSourceLocation());
ExprId Const(size_t size, uint64_t val, const ILSourceLocation& loc = ILSourceLocation());
ExprId ConstPointer(size_t size, uint64_t val, const ILSourceLocation& loc = ILSourceLocation());
+ ExprId ExternPointer(size_t size, uint64_t val, uint64_t offset, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatConstRaw(size_t size, uint64_t val, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatConstSingle(float val, const ILSourceLocation& loc = ILSourceLocation());
ExprId FloatConstDouble(double val, const ILSourceLocation& loc = ILSourceLocation());
diff --git a/binaryninjacore.h b/binaryninjacore.h
index e7eb3922..9b50c7e3 100644
--- a/binaryninjacore.h
+++ b/binaryninjacore.h
@@ -232,7 +232,8 @@ extern "C"
LocalVariableToken = 66,
ImportToken = 67,
AddressDisplayToken = 68,
- IndirectImportToken = 69
+ IndirectImportToken = 69,
+ ExternalSymbolToken = 70
};
enum BNInstructionTextTokenContext
@@ -312,7 +313,7 @@ extern "C"
LLIL_REG_STACK_FREE_REL, // Not valid in SSA from (see LLIL_REG_STACK_FREE_REL_SSA)
LLIL_CONST,
LLIL_CONST_PTR,
- LLIL_RELOC_PTR,
+ LLIL_EXTERN_PTR,
LLIL_FLOAT_CONST,
LLIL_FLAG, // Not valid in SSA form (see LLIL_FLAG_SSA)
LLIL_FLAG_BIT, // Not valid in SSA form (see LLIL_FLAG_BIT_SSA)
@@ -831,6 +832,7 @@ extern "C"
MLIL_ADDRESS_OF_FIELD,
MLIL_CONST,
MLIL_CONST_PTR,
+ MLIL_EXTERN_PTR,
MLIL_FLOAT_CONST,
MLIL_IMPORT,
MLIL_ADD,
diff --git a/examples/llil_parser/src/llil_parser.cpp b/examples/llil_parser/src/llil_parser.cpp
index 3b9bfe3c..da5f81dc 100644
--- a/examples/llil_parser/src/llil_parser.cpp
+++ b/examples/llil_parser/src/llil_parser.cpp
@@ -56,7 +56,7 @@ static void PrintOperation(BNLowLevelILOperation operation)
ENUM_PRINTER(LLIL_REG)
ENUM_PRINTER(LLIL_CONST)
ENUM_PRINTER(LLIL_CONST_PTR)
- ENUM_PRINTER(LLIL_RELOC_PTR)
+ ENUM_PRINTER(LLIL_EXTERN_PTR)
ENUM_PRINTER(LLIL_FLAG)
ENUM_PRINTER(LLIL_FLAG_BIT)
ENUM_PRINTER(LLIL_ADD)
@@ -379,7 +379,7 @@ int main(int argc, char *argv[])
{
case LLIL_CONST:
case LLIL_CONST_PTR:
- case LLIL_RELOC_PTR:
+ case LLIL_EXTERN_PTR:
printf(" Found constant 0x%" PRIx64 "\n", expr.GetConstant());
return false; // Done parsing this
default:
@@ -399,10 +399,10 @@ int main(int argc, char *argv[])
expr.GetSourceExpr<LLIL_LOAD>().GetConstant<LLIL_CONST_PTR>());
return false; // Done parsing this
}
- else if (expr.GetSourceExpr<LLIL_LOAD>().operation == LLIL_RELOC_PTR)
+ else if (expr.GetSourceExpr<LLIL_LOAD>().operation == LLIL_EXTERN_PTR)
{
printf(" Loading from address 0x%" PRIx64 "\n",
- expr.GetSourceExpr<LLIL_LOAD>().GetConstant<LLIL_RELOC_PTR>());
+ expr.GetSourceExpr<LLIL_LOAD>().GetConstant<LLIL_EXTERN_PTR>());
return false; // Done parsing this
}
break;
diff --git a/examples/mlil_parser/src/mlil_parser.cpp b/examples/mlil_parser/src/mlil_parser.cpp
index 0e621ead..a4c10f61 100644
--- a/examples/mlil_parser/src/mlil_parser.cpp
+++ b/examples/mlil_parser/src/mlil_parser.cpp
@@ -59,6 +59,7 @@ static void PrintOperation(BNMediumLevelILOperation operation)
ENUM_PRINTER(MLIL_ADDRESS_OF_FIELD)
ENUM_PRINTER(MLIL_CONST)
ENUM_PRINTER(MLIL_CONST_PTR)
+ ENUM_PRINTER(MLIL_EXTERN_PTR)
ENUM_PRINTER(MLIL_ADD)
ENUM_PRINTER(MLIL_ADC)
ENUM_PRINTER(MLIL_SUB)
@@ -326,6 +327,7 @@ int main(int argc, char *argv[])
{
case MLIL_CONST:
case MLIL_CONST_PTR:
+ case MLIL_EXTERN_PTR:
printf(" Found constant 0x%" PRIx64 "\n", expr.GetConstant());
return false; // Done parsing this
default:
@@ -345,6 +347,12 @@ int main(int argc, char *argv[])
expr.GetSourceExpr<MLIL_LOAD>().GetConstant<MLIL_CONST_PTR>());
return false; // Done parsing this
}
+ else if (expr.GetSourceExpr<MLIL_LOAD>().operation == MLIL_EXTERN_PTR)
+ {
+ printf(" Loading from address 0x%" PRIx64 "\n",
+ expr.GetSourceExpr<MLIL_LOAD>().GetConstant<MLIL_EXTERN_PTR>());
+ return false; // Done parsing this
+ }
break;
default:
break;
diff --git a/lowlevelilinstruction.cpp b/lowlevelilinstruction.cpp
index 4e0901f3..1522596b 100644
--- a/lowlevelilinstruction.cpp
+++ b/lowlevelilinstruction.cpp
@@ -171,7 +171,7 @@ unordered_map<BNLowLevelILOperation, vector<LowLevelILOperandUsage>>
{LLIL_MEM_PHI, {DestMemoryVersionLowLevelOperandUsage, SourceMemoryVersionsLowLevelOperandUsage}},
{LLIL_CONST, {ConstantLowLevelOperandUsage}},
{LLIL_CONST_PTR, {ConstantLowLevelOperandUsage}},
- {LLIL_RELOC_PTR, {ConstantLowLevelOperandUsage}},
+ {LLIL_EXTERN_PTR, {ConstantLowLevelOperandUsage, OffsetLowLevelOperandUsage}},
{LLIL_FLOAT_CONST, {ConstantLowLevelOperandUsage}},
{LLIL_ADD, {LeftExprLowLevelOperandUsage, RightExprLowLevelOperandUsage}},
{LLIL_SUB, {LeftExprLowLevelOperandUsage, RightExprLowLevelOperandUsage}},
@@ -2114,8 +2114,8 @@ ExprId LowLevelILInstruction::CopyTo(LowLevelILFunction* dest,
return dest->Const(size, GetConstant<LLIL_CONST>(), *this);
case LLIL_CONST_PTR:
return dest->ConstPointer(size, GetConstant<LLIL_CONST_PTR>(), *this);
- case LLIL_RELOC_PTR:
- return dest->ConstPointer(size, GetConstant<LLIL_RELOC_PTR>(), *this);
+ case LLIL_EXTERN_PTR:
+ return dest->ExternPointer(size, GetConstant<LLIL_EXTERN_PTR>(), GetOffset<LLIL_EXTERN_PTR>(), *this);
case LLIL_FLOAT_CONST:
return dest->FloatConstRaw(size, GetConstant<LLIL_FLOAT_CONST>(), *this);
case LLIL_POP:
@@ -2492,6 +2492,15 @@ int64_t LowLevelILInstruction::GetConstant() const
}
+uint64_t LowLevelILInstruction::GetOffset() const
+{
+ size_t operandIndex;
+ if (GetOperandIndexForUsage(OffsetLowLevelOperandUsage, operandIndex))
+ return GetRawOperandAsInteger(operandIndex);
+ throw LowLevelILInstructionAccessException();
+}
+
+
int64_t LowLevelILInstruction::GetVector() const
{
size_t operandIndex;
@@ -2897,9 +2906,9 @@ ExprId LowLevelILFunction::ConstPointer(size_t size, uint64_t val, const ILSourc
}
-ExprId LowLevelILFunction::RelocationPointer(size_t size, uint64_t val, const ILSourceLocation& loc)
+ExprId LowLevelILFunction::ExternPointer(size_t size, uint64_t val, uint64_t offset, const ILSourceLocation& loc)
{
- return AddExprWithLocation(LLIL_RELOC_PTR, loc, size, 0, val);
+ return AddExprWithLocation(LLIL_EXTERN_PTR, loc, size, 0, val, offset);
}
diff --git a/lowlevelilinstruction.h b/lowlevelilinstruction.h
index 2d1429c9..09cae9f4 100644
--- a/lowlevelilinstruction.h
+++ b/lowlevelilinstruction.h
@@ -218,7 +218,8 @@ namespace BinaryNinja
OutputSSARegisterOrFlagListLowLevelOperandUsage,
SourceMemoryVersionsLowLevelOperandUsage,
TargetListLowLevelOperandUsage,
- RegisterStackAdjustmentsLowLevelOperandUsage
+ RegisterStackAdjustmentsLowLevelOperandUsage,
+ OffsetLowLevelOperandUsage
};
}
@@ -711,6 +712,7 @@ namespace BinaryNinja
template <BNLowLevelILOperation N> SSARegister GetLowSSARegister() const { return As<N>().GetLowSSARegister(); }
template <BNLowLevelILOperation N> uint32_t GetIntrinsic() const { return As<N>().GetIntrinsic(); }
template <BNLowLevelILOperation N> int64_t GetConstant() const { return As<N>().GetConstant(); }
+ template <BNLowLevelILOperation N> uint64_t GetOffset() const { return As<N>().GetOffset(); }
template <BNLowLevelILOperation N> int64_t GetVector() const { return As<N>().GetVector(); }
template <BNLowLevelILOperation N> size_t GetStackAdjustment() const { return As<N>().GetStackAdjustment(); }
template <BNLowLevelILOperation N> size_t GetTarget() const { return As<N>().GetTarget(); }
@@ -775,6 +777,7 @@ namespace BinaryNinja
SSARegister GetLowSSARegister() const;
uint32_t GetIntrinsic() const;
int64_t GetConstant() const;
+ uint64_t GetOffset() const;
int64_t GetVector() const;
size_t GetStackAdjustment() const;
size_t GetTarget() const;
@@ -870,6 +873,11 @@ namespace BinaryNinja
int64_t GetConstant() const { return GetRawOperandAsInteger(0); }
};
+ struct LowLevelILOffsetInstruction: public LowLevelILInstructionBase
+ {
+ int64_t GetOffset() const { return GetRawOperandAsInteger(1); }
+ };
+
struct LowLevelILOneOperandInstruction: public LowLevelILInstructionBase
{
LowLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); }
@@ -1216,6 +1224,12 @@ namespace BinaryNinja
LowLevelILIndexList GetSourceMemoryVersions() const { return GetRawOperandAsIndexList(1); }
};
+ template <> struct LowLevelILInstructionAccessor<LLIL_EXTERN_PTR>: public LowLevelILConstantInstruction
+ {
+ size_t GetConstant() const { return GetRawOperandAsIndex(0); }
+ size_t GetOffset() const { return GetRawOperandAsIndex(1); }
+ };
+
template <> struct LowLevelILInstructionAccessor<LLIL_NOP>: public LowLevelILInstructionBase {};
template <> struct LowLevelILInstructionAccessor<LLIL_POP>: public LowLevelILInstructionBase {};
template <> struct LowLevelILInstructionAccessor<LLIL_NORET>: public LowLevelILInstructionBase {};
@@ -1226,7 +1240,6 @@ namespace BinaryNinja
template <> struct LowLevelILInstructionAccessor<LLIL_CONST>: public LowLevelILConstantInstruction {};
template <> struct LowLevelILInstructionAccessor<LLIL_CONST_PTR>: public LowLevelILConstantInstruction {};
- template <> struct LowLevelILInstructionAccessor<LLIL_RELOC_PTR>: public LowLevelILConstantInstruction {};
template <> struct LowLevelILInstructionAccessor<LLIL_FLOAT_CONST>: public LowLevelILConstantInstruction {};
template <> struct LowLevelILInstructionAccessor<LLIL_ADD>: public LowLevelILTwoOperandInstruction {};
diff --git a/mediumlevelilinstruction.cpp b/mediumlevelilinstruction.cpp
index 9cf82b08..17ef88e7 100644
--- a/mediumlevelilinstruction.cpp
+++ b/mediumlevelilinstruction.cpp
@@ -168,6 +168,7 @@ unordered_map<BNMediumLevelILOperation, vector<MediumLevelILOperandUsage>>
{MLIL_MEM_PHI, {DestMemoryVersionMediumLevelOperandUsage, SourceMemoryVersionsMediumLevelOperandUsage}},
{MLIL_CONST, {ConstantMediumLevelOperandUsage}},
{MLIL_CONST_PTR, {ConstantMediumLevelOperandUsage}},
+ {MLIL_EXTERN_PTR, {ConstantMediumLevelOperandUsage}},
{MLIL_FLOAT_CONST, {ConstantMediumLevelOperandUsage}},
{MLIL_IMPORT, {ConstantMediumLevelOperandUsage}},
{MLIL_ADD, {LeftExprMediumLevelOperandUsage, RightExprMediumLevelOperandUsage}},
@@ -1686,6 +1687,8 @@ ExprId MediumLevelILInstruction::CopyTo(MediumLevelILFunction* dest,
return dest->Const(size, GetConstant<MLIL_CONST>(), *this);
case MLIL_CONST_PTR:
return dest->ConstPointer(size, GetConstant<MLIL_CONST_PTR>(), *this);
+ case MLIL_EXTERN_PTR:
+ return dest->ExternPointer(size, GetConstant<MLIL_EXTERN_PTR>(), GetOffset<MLIL_EXTERN_PTR>(), *this);
case MLIL_FLOAT_CONST:
return dest->FloatConstRaw(size, GetConstant<MLIL_FLOAT_CONST>(), *this);
case MLIL_IMPORT:
@@ -2248,6 +2251,12 @@ ExprId MediumLevelILFunction::ConstPointer(size_t size, uint64_t val, const ILSo
}
+ExprId MediumLevelILFunction::ExternPointer(size_t size, uint64_t val, uint64_t offset, const ILSourceLocation& loc)
+{
+ return AddExprWithLocation(MLIL_EXTERN_PTR, loc, size, val, offset);
+}
+
+
ExprId MediumLevelILFunction::FloatConstRaw(size_t size, uint64_t val, const ILSourceLocation& loc)
{
return AddExprWithLocation(MLIL_FLOAT_CONST, loc, size, val);
diff --git a/mediumlevelilinstruction.h b/mediumlevelilinstruction.h
index b37b8832..ec8a8371 100644
--- a/mediumlevelilinstruction.h
+++ b/mediumlevelilinstruction.h
@@ -989,6 +989,12 @@ namespace BinaryNinja
MediumLevelILIndexList GetSourceMemoryVersions() const { return GetRawOperandAsIndexList(1); }
};
+ template <> struct MediumLevelILInstructionAccessor<MLIL_EXTERN_PTR>: public MediumLevelILConstantInstruction
+ {
+ int64_t GetConstant() const { return GetRawOperandAsInteger(0); }
+ int64_t GetOffset() const { return GetRawOperandAsInteger(1); }
+ };
+
template <> struct MediumLevelILInstructionAccessor<MLIL_NOP>: public MediumLevelILInstructionBase {};
template <> struct MediumLevelILInstructionAccessor<MLIL_NORET>: public MediumLevelILInstructionBase {};
template <> struct MediumLevelILInstructionAccessor<MLIL_BP>: public MediumLevelILInstructionBase {};
diff --git a/python/lowlevelil.py b/python/lowlevelil.py
index ceae1617..c156f99e 100644
--- a/python/lowlevelil.py
+++ b/python/lowlevelil.py
@@ -223,7 +223,7 @@ class LowLevelILInstruction(object):
LowLevelILOperation.LLIL_REG_STACK_FREE_REL: [("stack", "reg_stack"), ("dest", "expr")],
LowLevelILOperation.LLIL_CONST: [("constant", "int")],
LowLevelILOperation.LLIL_CONST_PTR: [("constant", "int")],
- LowLevelILOperation.LLIL_RELOC_PTR: [("constant", "int")],
+ LowLevelILOperation.LLIL_EXTERN_PTR: [("constant", "int"), ("offset", "int")],
LowLevelILOperation.LLIL_FLOAT_CONST: [("constant", "float")],
LowLevelILOperation.LLIL_FLAG: [("src", "flag")],
LowLevelILOperation.LLIL_FLAG_BIT: [("src", "flag"), ("bit", "int")],
@@ -1101,7 +1101,7 @@ class LowLevelILFunction(object):
:return: A constant expression of given value and size
:rtype: LowLevelILExpr
"""
- return self.expr(LowLevelILOperation.LLIL_RELOC_PTR, value, size=size)
+ return self.expr(LowLevelILOperation.LLIL_EXTERN_PTR, value, size=size)
def float_const_raw(self, size, value):
"""
diff --git a/python/mediumlevelil.py b/python/mediumlevelil.py
index 100795fe..70dfb08b 100644
--- a/python/mediumlevelil.py
+++ b/python/mediumlevelil.py
@@ -91,6 +91,7 @@ class MediumLevelILInstruction(object):
MediumLevelILOperation.MLIL_ADDRESS_OF_FIELD: [("src", "var"), ("offset", "int")],
MediumLevelILOperation.MLIL_CONST: [("constant", "int")],
MediumLevelILOperation.MLIL_CONST_PTR: [("constant", "int")],
+ MediumLevelILOperation.MLIL_EXTERN_PTR: [("constant", "int"), ("offset", "int")],
MediumLevelILOperation.MLIL_FLOAT_CONST: [("constant", "float")],
MediumLevelILOperation.MLIL_IMPORT: [("constant", "int")],
MediumLevelILOperation.MLIL_ADD: [("left", "expr"), ("right", "expr")],