Skip to content

Instantly share code, notes, and snippets.

@Pamplemousse
Created November 4, 2020 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pamplemousse/9a6fd79845f5fc26657fb29b4cfc6fcf to your computer and use it in GitHub Desktop.
Save Pamplemousse/9a6fd79845f5fc26657fb29b4cfc6fcf to your computer and use it in GitHub Desktop.
Decorate function handlers in `angr`'s RDA to highlight definitions passed as parameter to external functions.
def tag_parameter_definitions(func):
"""
Add a `ParameterTag` to the definitions of the arguments of the function simulated by the handler.
"""
@functools.wraps(func)
def wrapper(self, state: 'ReachingDefinitionsState', codeloc: 'CodeLocation'):
arch = state.arch
tag = ParameterTag(
function = codeloc.ins_addr,
metadata = {'tagged_by': "%s.%s" % (self.__class__.__name__, func.__name__)}
)
handler_name = re.match(r"handle_(.*)$", func.__name__)[1]
cc = self._calling_convention_resolver.get_cc(handler_name)
if cc.args:
for arg in cc.args:
if isinstance(arg, SimRegArg):
reg_offset, reg_size = arch.registers[arg.reg_name]
atom = Register(reg_offset, reg_size)
elif isinstance(arg, SimStackArg):
atom = MemoryLocation(SpOffset(arch.bits, arg.stack_offset),
arg.size * arch.byte_width)
definitions = state.get_definitions(atom)
for definition in definitions:
definition.tags |= {tag}
return func(self, state, codeloc)
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment