Skip to content

Commit 561e2f3

Browse files
authored
Fix handling of variables with invalid ea (#100)
1 parent 1ea7b64 commit 561e2f3

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

lib/Analyze.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,13 @@ uint64_t XrefExprFolder::VisitSExt(llvm::Value *op, llvm::Type *type) {
515515
uint64_t XrefExprFolder::VisitTrunc(llvm::Value *op, llvm::Type *type) {
516516
auto ea = Visit(op);
517517
const auto dest_size = type->getPrimitiveSizeInBits();
518-
CHECK_LT(dest_size, 64u);
518+
519+
// return ea if dest type is not trucated
520+
if (dest_size == 64u) {
521+
return ea;
522+
}
523+
524+
CHECK_LE(dest_size, 64u);
519525
const auto mask = (1ull << dest_size) - 1ull;
520526
return (ea & mask);
521527
}

python/anvill/binja.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ def _collect_xrefs_from_inst(bv, inst, ref_eas, reftype=XrefType.XREF_NONE):
131131
if not isinstance(inst, bn.LowLevelILInstruction):
132132
return
133133

134-
assert not is_unimplemented(bv, inst)
135-
assert not is_undef(bv, inst)
134+
if is_unimplemented(bv, inst) or is_undef(bv, inst):
135+
return
136136

137137
if is_function_call(bv, inst) or is_jump(bv, inst):
138138
reftype = XrefType.XREF_CONTROL_FLOW
@@ -384,6 +384,10 @@ def visit(self, program, is_definition, add_refs_as_defs):
384384
# if the function is a declaration, then Anvill only needs to know its symbols and prototypes
385385
# if its a definition, then Anvill will perform analysis of the function and produce information for the func
386386
for ref_ea in ref_eas:
387+
# If ref_ea is an invalid address
388+
seg = program._bv.get_segment_at(ref_ea)
389+
if seg is None:
390+
continue
387391
program.try_add_referenced_entity(ref_ea, add_refs_as_defs)
388392

389393
def _extract_types_mlil(
@@ -514,6 +518,11 @@ def get_variable_impl(self, address):
514518
"""Given an address, return a `Variable` instance, or
515519
raise an `InvalidVariableException` exception."""
516520

521+
# raise exception if the variable has invalid address
522+
seg = self._bv.get_segment_at(address)
523+
if seg is None:
524+
raise InvalidVariableException("Invalid variable address")
525+
517526
arch = self._arch
518527
bn_var = self._bv.get_data_var_at(address)
519528
var_type = get_type(bn_var.type)

0 commit comments

Comments
 (0)