diff options
| -rw-r--r-- | binaryninjaapi.h | 6 | ||||
| -rw-r--r-- | highlevelilinstruction.cpp | 55 | ||||
| -rw-r--r-- | highlevelilinstruction.h | 6 | ||||
| -rw-r--r-- | python/highlevelil.py | 10 |
4 files changed, 57 insertions, 20 deletions
diff --git a/binaryninjaapi.h b/binaryninjaapi.h index 19143c13..ea74a466 100644 --- a/binaryninjaapi.h +++ b/binaryninjaapi.h @@ -4079,18 +4079,18 @@ __attribute__ ((format (printf, 1, 2))) const ILSourceLocation& loc = ILSourceLocation()); ExprId MemPhi(size_t dest, const std::vector<size_t>& sources, const ILSourceLocation& loc = ILSourceLocation()); - ExprId StructField(size_t size, ExprId src, uint64_t offset, + ExprId StructField(size_t size, ExprId src, uint64_t offset, size_t memberIndex, const ILSourceLocation& loc = ILSourceLocation()); ExprId ArrayIndex(size_t size, ExprId src, ExprId idx, const ILSourceLocation& loc = ILSourceLocation()); ExprId ArrayIndexSSA(size_t size, ExprId src, size_t srcMemVersion, ExprId idx, const ILSourceLocation& loc = ILSourceLocation()); ExprId Split(size_t size, ExprId high, ExprId low, const ILSourceLocation& loc = ILSourceLocation()); ExprId Deref(size_t size, ExprId src, const ILSourceLocation& loc = ILSourceLocation()); - ExprId DerefField(size_t size, ExprId src, uint64_t offset, + ExprId DerefField(size_t size, ExprId src, uint64_t offset, size_t memberIndex, const ILSourceLocation& loc = ILSourceLocation()); ExprId DerefSSA(size_t size, ExprId src, size_t srcMemVersion, const ILSourceLocation& loc = ILSourceLocation()); - ExprId DerefFieldSSA(size_t size, ExprId src, size_t srcMemVersion, uint64_t offset, + ExprId DerefFieldSSA(size_t size, ExprId src, size_t srcMemVersion, uint64_t offset, size_t memberIndex, const ILSourceLocation& loc = ILSourceLocation()); ExprId AddressOf(ExprId src, const ILSourceLocation& loc = ILSourceLocation()); ExprId Const(size_t size, uint64_t val, const ILSourceLocation& loc = ILSourceLocation()); diff --git a/highlevelilinstruction.cpp b/highlevelilinstruction.cpp index 80d30a92..65b51ac4 100644 --- a/highlevelilinstruction.cpp +++ b/highlevelilinstruction.cpp @@ -54,6 +54,7 @@ unordered_map<HighLevelILOperandUsage, HighLevelILOperandType> {HighExprHighLevelOperandUsage, ExprHighLevelOperand}, {LowExprHighLevelOperandUsage, ExprHighLevelOperand}, {OffsetHighLevelOperandUsage, IntegerHighLevelOperand}, + {MemberIndexHighLevelOperandUsage, IndexHighLevelOperand}, {ConstantHighLevelOperandUsage, IntegerHighLevelOperand}, {VectorHighLevelOperandUsage, IntegerHighLevelOperand}, {IntrinsicHighLevelOperandUsage, IntrinsicHighLevelOperand}, @@ -104,16 +105,18 @@ unordered_map<BNHighLevelILOperation, vector<HighLevelILOperandUsage>> {HLIL_VAR_SSA, {SSAVariableHighLevelOperandUsage}}, {HLIL_VAR_PHI, {DestSSAVariableHighLevelOperandUsage, SourceSSAVariablesHighLevelOperandUsage}}, {HLIL_MEM_PHI, {DestMemoryVersionHighLevelOperandUsage, SourceMemoryVersionsHighLevelOperandUsage}}, - {HLIL_STRUCT_FIELD, {SourceExprHighLevelOperandUsage, OffsetHighLevelOperandUsage}}, + {HLIL_STRUCT_FIELD, {SourceExprHighLevelOperandUsage, OffsetHighLevelOperandUsage, + MemberIndexHighLevelOperandUsage}}, {HLIL_ARRAY_INDEX, {SourceExprHighLevelOperandUsage, IndexExprHighLevelOperandUsage}}, {HLIL_ARRAY_INDEX_SSA, {SourceExprHighLevelOperandUsage, SourceMemoryVersionHighLevelOperandUsage, IndexExprHighLevelOperandUsage}}, {HLIL_SPLIT, {HighExprHighLevelOperandUsage, LowExprHighLevelOperandUsage}}, {HLIL_DEREF, {SourceExprHighLevelOperandUsage}}, - {HLIL_DEREF_FIELD, {SourceExprHighLevelOperandUsage, OffsetHighLevelOperandUsage}}, + {HLIL_DEREF_FIELD, {SourceExprHighLevelOperandUsage, OffsetHighLevelOperandUsage, + MemberIndexHighLevelOperandUsage}}, {HLIL_DEREF_SSA, {SourceExprHighLevelOperandUsage, SourceMemoryVersionHighLevelOperandUsage}}, {HLIL_DEREF_FIELD_SSA, {SourceExprHighLevelOperandUsage, SourceMemoryVersionHighLevelOperandUsage, - OffsetHighLevelOperandUsage}}, + OffsetHighLevelOperandUsage, MemberIndexHighLevelOperandUsage}}, {HLIL_ADDRESS_OF, {SourceExprHighLevelOperandUsage}}, {HLIL_CALL, {DestExprHighLevelOperandUsage, ParameterExprsHighLevelOperandUsage}}, {HLIL_SYSCALL, {ParameterExprsHighLevelOperandUsage}}, @@ -1155,7 +1158,7 @@ ExprId HighLevelILInstruction::CopyTo(HighLevelILFunction* dest, return dest->MemPhi(GetDestMemoryVersion<HLIL_MEM_PHI>(), GetSourceMemoryVersions<HLIL_MEM_PHI>(), *this); case HLIL_STRUCT_FIELD: return dest->StructField(size, subExprHandler(GetSourceExpr<HLIL_STRUCT_FIELD>()), - GetOffset<HLIL_STRUCT_FIELD>(), *this); + GetOffset<HLIL_STRUCT_FIELD>(), GetMemberIndex<HLIL_STRUCT_FIELD>(), *this); case HLIL_ARRAY_INDEX: return dest->ArrayIndex(size, subExprHandler(GetSourceExpr<HLIL_ARRAY_INDEX>()), subExprHandler(GetIndexExpr<HLIL_ARRAY_INDEX>()), *this); @@ -1170,13 +1173,14 @@ ExprId HighLevelILInstruction::CopyTo(HighLevelILFunction* dest, return dest->Deref(size, subExprHandler(GetSourceExpr<HLIL_DEREF>()), *this); case HLIL_DEREF_FIELD: return dest->DerefField(size, subExprHandler(GetSourceExpr<HLIL_DEREF_FIELD>()), - GetOffset<HLIL_DEREF_FIELD>(), *this); + GetOffset<HLIL_DEREF_FIELD>(), GetMemberIndex<HLIL_DEREF_FIELD>(), *this); case HLIL_DEREF_SSA: return dest->DerefSSA(size, subExprHandler(GetSourceExpr<HLIL_DEREF_SSA>()), GetSourceMemoryVersion<HLIL_DEREF_SSA>(), *this); case HLIL_DEREF_FIELD_SSA: return dest->DerefFieldSSA(size, subExprHandler(GetSourceExpr<HLIL_DEREF_FIELD_SSA>()), - GetSourceMemoryVersion<HLIL_DEREF_FIELD_SSA>(), GetOffset<HLIL_DEREF_FIELD_SSA>(), *this); + GetSourceMemoryVersion<HLIL_DEREF_FIELD_SSA>(), GetOffset<HLIL_DEREF_FIELD_SSA>(), + GetMemberIndex<HLIL_DEREF_FIELD_SSA>(), *this); case HLIL_ADDRESS_OF: return dest->AddressOf(subExprHandler(GetSourceExpr<HLIL_ADDRESS_OF>()), *this); case HLIL_CALL: @@ -1474,7 +1478,11 @@ bool HighLevelILInstruction::operator<(const HighLevelILInstruction& other) cons return true; if (other.GetSourceExpr<HLIL_STRUCT_FIELD>() < GetSourceExpr<HLIL_STRUCT_FIELD>()) return false; - return GetOffset<HLIL_STRUCT_FIELD>() < other.GetOffset<HLIL_STRUCT_FIELD>(); + if (GetOffset<HLIL_STRUCT_FIELD>() < other.GetOffset<HLIL_STRUCT_FIELD>()) + return true; + if (other.GetOffset<HLIL_STRUCT_FIELD>() < GetOffset<HLIL_STRUCT_FIELD>()) + return false; + return GetMemberIndex<HLIL_STRUCT_FIELD>() < other.GetMemberIndex<HLIL_STRUCT_FIELD>(); case HLIL_ARRAY_INDEX: if (size < other.size) return true; @@ -1518,7 +1526,11 @@ bool HighLevelILInstruction::operator<(const HighLevelILInstruction& other) cons return true; if (other.GetSourceExpr<HLIL_DEREF_FIELD>() < GetSourceExpr<HLIL_DEREF_FIELD>()) return false; - return GetOffset<HLIL_DEREF_FIELD>() < other.GetOffset<HLIL_DEREF_FIELD>(); + if (GetOffset<HLIL_DEREF_FIELD>() < other.GetOffset<HLIL_DEREF_FIELD>()) + return true; + if (other.GetOffset<HLIL_DEREF_FIELD>() < GetOffset<HLIL_DEREF_FIELD>()) + return false; + return GetMemberIndex<HLIL_DEREF_FIELD>() < other.GetMemberIndex<HLIL_DEREF_FIELD>(); case HLIL_DEREF_SSA: if (size < other.size) return true; @@ -1542,6 +1554,10 @@ bool HighLevelILInstruction::operator<(const HighLevelILInstruction& other) cons return true; if (other.GetOffset<HLIL_DEREF_FIELD_SSA>() < GetOffset<HLIL_DEREF_FIELD_SSA>()) return false; + if (GetMemberIndex<HLIL_DEREF_FIELD_SSA>() < other.GetMemberIndex<HLIL_DEREF_FIELD_SSA>()) + return true; + if (other.GetMemberIndex<HLIL_DEREF_FIELD_SSA>() < GetMemberIndex<HLIL_DEREF_FIELD_SSA>()) + return false; return GetSourceMemoryVersion<HLIL_DEREF_FIELD_SSA>() < other.GetSourceMemoryVersion<HLIL_DEREF_FIELD_SSA>(); case HLIL_ADDRESS_OF: return GetSourceExpr<HLIL_ADDRESS_OF>() < other.GetSourceExpr<HLIL_ADDRESS_OF>(); @@ -1958,6 +1974,15 @@ uint64_t HighLevelILInstruction::GetOffset() const } +size_t HighLevelILInstruction::GetMemberIndex() const +{ + size_t operandIndex; + if (GetOperandIndexForUsage(MemberIndexHighLevelOperandUsage, operandIndex)) + return GetRawOperandAsIndex(operandIndex); + throw HighLevelILInstructionAccessException(); +} + + int64_t HighLevelILInstruction::GetConstant() const { size_t operandIndex; @@ -2233,9 +2258,10 @@ ExprId HighLevelILFunction::MemPhi(size_t dest, const vector<size_t>& sources, c } -ExprId HighLevelILFunction::StructField(size_t size, ExprId src, uint64_t offset, const ILSourceLocation& loc) +ExprId HighLevelILFunction::StructField(size_t size, ExprId src, uint64_t offset, size_t memberIndex, + const ILSourceLocation& loc) { - return AddExprWithLocation(HLIL_STRUCT_FIELD, loc, size, src, offset); + return AddExprWithLocation(HLIL_STRUCT_FIELD, loc, size, src, offset, memberIndex); } @@ -2264,9 +2290,10 @@ ExprId HighLevelILFunction::Deref(size_t size, ExprId src, const ILSourceLocatio } -ExprId HighLevelILFunction::DerefField(size_t size, ExprId src, uint64_t offset, const ILSourceLocation& loc) +ExprId HighLevelILFunction::DerefField(size_t size, ExprId src, uint64_t offset, size_t memberIndex, + const ILSourceLocation& loc) { - return AddExprWithLocation(HLIL_DEREF_FIELD, loc, size, src, offset); + return AddExprWithLocation(HLIL_DEREF_FIELD, loc, size, src, offset, memberIndex); } @@ -2277,9 +2304,9 @@ ExprId HighLevelILFunction::DerefSSA(size_t size, ExprId src, size_t srcMemVersi ExprId HighLevelILFunction::DerefFieldSSA(size_t size, ExprId src, size_t srcMemVersion, - uint64_t offset, const ILSourceLocation& loc) + uint64_t offset, size_t memberIndex, const ILSourceLocation& loc) { - return AddExprWithLocation(HLIL_DEREF_FIELD_SSA, loc, size, src, srcMemVersion, offset); + return AddExprWithLocation(HLIL_DEREF_FIELD_SSA, loc, size, src, srcMemVersion, offset, memberIndex); } diff --git a/highlevelilinstruction.h b/highlevelilinstruction.h index 6c249d94..cfc917e8 100644 --- a/highlevelilinstruction.h +++ b/highlevelilinstruction.h @@ -85,6 +85,7 @@ namespace BinaryNinja HighExprHighLevelOperandUsage, LowExprHighLevelOperandUsage, OffsetHighLevelOperandUsage, + MemberIndexHighLevelOperandUsage, ConstantHighLevelOperandUsage, VectorHighLevelOperandUsage, IntrinsicHighLevelOperandUsage, @@ -390,6 +391,7 @@ namespace BinaryNinja template <BNHighLevelILOperation N> HighLevelILInstruction GetHighExpr() const { return As<N>().GetHighExpr(); } template <BNHighLevelILOperation N> HighLevelILInstruction GetLowExpr() const { return As<N>().GetLowExpr(); } template <BNHighLevelILOperation N> uint64_t GetOffset() const { return As<N>().GetOffset(); } + template <BNHighLevelILOperation N> size_t GetMemberIndex() const { return As<N>().GetMemberIndex(); } template <BNHighLevelILOperation N> int64_t GetConstant() const { return As<N>().GetConstant(); } template <BNHighLevelILOperation N> int64_t GetVector() const { return As<N>().GetVector(); } template <BNHighLevelILOperation N> uint32_t GetIntrinsic() const { return As<N>().GetIntrinsic(); } @@ -443,6 +445,7 @@ namespace BinaryNinja HighLevelILInstruction GetHighExpr() const; HighLevelILInstruction GetLowExpr() const; uint64_t GetOffset() const; + size_t GetMemberIndex() const; int64_t GetConstant() const; int64_t GetVector() const; uint32_t GetIntrinsic() const; @@ -628,11 +631,13 @@ namespace BinaryNinja { HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } + size_t GetMemberIndex() const { return GetRawOperandAsIndex(2); } }; template <> struct HighLevelILInstructionAccessor<HLIL_DEREF_FIELD>: public HighLevelILInstructionBase { HighLevelILInstruction GetSourceExpr() const { return GetRawOperandAsExpr(0); } uint64_t GetOffset() const { return GetRawOperandAsInteger(1); } + size_t GetMemberIndex() const { return GetRawOperandAsIndex(2); } }; template <> struct HighLevelILInstructionAccessor<HLIL_DEREF_SSA>: public HighLevelILInstructionBase { @@ -646,6 +651,7 @@ namespace BinaryNinja size_t GetSourceMemoryVersion() const { return GetRawOperandAsIndex(1); } void SetSourceMemoryVersion(size_t version) { UpdateRawOperand(1, version); } uint64_t GetOffset() const { return GetRawOperandAsInteger(2); } + size_t GetMemberIndex() const { return GetRawOperandAsIndex(3); } }; template <> struct HighLevelILInstructionAccessor<HLIL_ARRAY_INDEX>: public HighLevelILInstructionBase { diff --git a/python/highlevelil.py b/python/highlevelil.py index a4140f85..505b2b97 100644 --- a/python/highlevelil.py +++ b/python/highlevelil.py @@ -102,14 +102,14 @@ class HighLevelILInstruction(object): HighLevelILOperation.HLIL_VAR_SSA: [("var", "var_ssa")], HighLevelILOperation.HLIL_VAR_PHI: [("dest", "var_ssa"), ("src", "var_ssa_list")], HighLevelILOperation.HLIL_MEM_PHI: [("dest", "int"), ("src", "int_list")], - HighLevelILOperation.HLIL_STRUCT_FIELD: [("src", "expr"), ("offset", "int")], + HighLevelILOperation.HLIL_STRUCT_FIELD: [("src", "expr"), ("offset", "int"), ("member_index", "member_index")], HighLevelILOperation.HLIL_ARRAY_INDEX: [("src", "expr"), ("index", "expr")], HighLevelILOperation.HLIL_ARRAY_INDEX_SSA: [("src", "expr"), ("src_memory", "int"), ("index", "expr")], HighLevelILOperation.HLIL_SPLIT: [("high", "expr"), ("low", "expr")], HighLevelILOperation.HLIL_DEREF: [("src", "expr")], - HighLevelILOperation.HLIL_DEREF_FIELD: [("src", "expr"), ("offset", "int")], + HighLevelILOperation.HLIL_DEREF_FIELD: [("src", "expr"), ("offset", "int"), ("member_index", "member_index")], HighLevelILOperation.HLIL_DEREF_SSA: [("src", "expr"), ("src_memory", "int")], - HighLevelILOperation.HLIL_DEREF_FIELD_SSA: [("src", "expr"), ("src_memory", "int"), ("offset", "int")], + HighLevelILOperation.HLIL_DEREF_FIELD_SSA: [("src", "expr"), ("src_memory", "int"), ("offset", "int"), ("member_index", "member_index")], HighLevelILOperation.HLIL_ADDRESS_OF: [("src", "expr")], HighLevelILOperation.HLIL_CONST: [("constant", "int")], HighLevelILOperation.HLIL_CONST_PTR: [("constant", "int")], @@ -257,6 +257,10 @@ class HighLevelILInstruction(object): value.append(mediumlevelil.SSAVariable(function.Variable.from_identifier(self._function.source_function, var_id), var_version)) core.BNHighLevelILFreeOperandList(operand_list) + elif operand_type == "member_index": + value = instr.operands[i] + if (value & (1 << 63)) != 0: + value = None self._operands.append(value) self.__dict__[name] = value i += 1 |
