Created
November 4, 2020 17:22
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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