How to use the archinfo.arch_soot.SootMethodDescriptor function in archinfo

To help you get started, we’ve selected a few archinfo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github angr / cle / cle / backends / java / soot.py View on Github external
def get_soot_method(self, thing, class_name=None, params=(), none_if_missing=False):
        """
        Get Soot method object.

        :param thing:           Descriptor or the method, or name of the method.
        :param str class_name:  Name of the class. If not specified, class name can be parsed from method_name.
        :return:                Soot method that satisfy the criteria.
        """

        # Step 1: Parse input
        if isinstance(thing, SootMethodDescriptor):
            method_description = {
                'class_name': thing.class_name,
                'name': thing.name,
                'params': thing.params,
            }

        elif isinstance(thing, (str, bytes)):
            method_name = thing

            # if class_name is not set, parse it from the method name
            if class_name is None:
                last_dot = method_name.rfind('.')
                if last_dot >= 0:
                    class_name = method_name[:last_dot]
                    method_name = method_name[last_dot + 1:]
                else:
github angr / cle / cle / backends / java / soot.py View on Github external
def get_method(self, thing, cls_name=None):
        """
        Get a Soot method object.

        :param thing:           Descriptor or the method, or name of the method.
        :param str class_name:  Name of the class. If not specified, class name can be parsed from method_name.
        :return:                An iterator of all SootMethod objects that satisfy the criteria.
        :rtype:                 iterator
        """

        if isinstance(thing, SootMethodDescriptor):
            cls_name = thing.class_name
            method_name = thing.name
            method_params = thing.params
        elif isinstance(thing, (str, unicode)):
            # parse the method name
            method_name = thing
            if cls_name is None:
                # parse the class name from method_name
                last_dot = method_name.rfind('.')
                if last_dot >= 0:
                    cls_name = method_name[ : last_dot ]
                    method_name = method_name[last_dot + 1 : ]
                else:
                    raise CLEError('Unknown class name for the method.')
            method_params = None
        else:
github angr / angr / angr / analyses / cfg / cfg_fast_soot.py View on Github external
def _soot_create_invoke_successors(self, stmt, addr, invoke_expr):

        method_class = invoke_expr.class_name
        method_name = invoke_expr.method_name
        method_params = invoke_expr.method_params
        method_desc = SootMethodDescriptor(method_class, method_name, method_params)

        callee_soot_method = self.project.loader.main_object.get_soot_method(method_desc, none_if_missing=True)
        caller_soot_method = self.project.loader.main_object.get_soot_method(addr.method)

        if callee_soot_method is None:
            # this means the called method is external
            return [(stmt.label, addr, SootAddressDescriptor(method_desc, 0, 0), 'Ijk_Call')]

        targets = self._soot_class_hierarchy.resolve_invoke(invoke_expr, callee_soot_method, caller_soot_method)

        successors = []
        for target in targets:
            target_desc = SootMethodDescriptor(target.class_name, target.name, target.params)
            successors.append((stmt.label, addr, SootAddressDescriptor(target_desc, 0, 0), 'Ijk_Call'))

        return successors
github angr / angr-doc / examples / java_androidnative1 / solve.py View on Github external
def test_androidnative1():
    sdk_path = os.path.join(os.path.expanduser("~"), "Android/Sdk/platforms/")
    if not os.path.exists(sdk_path):
        print("cannot run test_apk_loading since there is no Android SDK folder")
        return

    apk_location = os.path.join(file_dir, "androidnative1.apk")
    loading_opts = {'android_sdk': sdk_path,
                    'entry_point': 'com.angr.nativetest1.MainActivity.onCreate',
                    'entry_point_params': ('android.os.Bundle', ),
                    'supported_jni_archs': ['x86']}
    project = angr.Project(apk_location, main_opts=loading_opts)
    project.hook(SootMethodDescriptor(class_name="java.lang.String", name="valueOf", params=('int',)).address(), Dummy_String_valueOf())

    blank_state = project.factory.blank_state()
    a1 = SimSootValue_ThisRef.new_object(blank_state, 'com.angr.androidnative1.MainActivity')
    a2 = SimSootValue_ThisRef.new_object(blank_state, 'android.os.Bundle', symbolic = True)
    args = [SootArgument(arg, arg.type) for arg in [a1, a2]]
    entry = project.factory.entry_state(args = args)
    simgr = project.factory.simgr(entry)

    simgr.run()

    int_result = simgr.deadended[0].solver.eval(result)
    assert int_result == 221
github angr / archinfo / archinfo / arch_soot.py View on Github external
def __init__(self):
        dummy_method = SootMethodDescriptor("dummy", "dummy", tuple())
        super(SootAddressTerminator, self).__init__(dummy_method, 0, 0)
github angr / angr-doc / examples / ictf2017_javaisnotfun / solve.py View on Github external
simgr.move('active', 'stashed', lambda a: type(a.addr) == SootAddressDescriptor
                   and a.addr.method == SootMethodDescriptor("NotFun", "game", ()) and a.addr.block_idx == 30)
        simgr.move('active', 'pruned', lambda a: type(a.addr) == SootAddressDescriptor
github angr / archinfo / archinfo / arch_soot.py View on Github external
def __init__(self, method, block_idx, stmt_idx):

        if not isinstance(method, SootMethodDescriptor):
            raise ValueError('The parameter "method" must be an '
                             'instance of SootMethodDescriptor.')

        self.method = method
        self.block_idx = block_idx
        self.stmt_idx = stmt_idx
github angr / angr / angr / engines / soot / static_dispatcher.py View on Github external
# get all methods matching class- and method-name
        methods = list(jar.get_method(expr.method_name, expr.class_name))

    except CLEError:
        # No methods found
        # => We are executing code that is not in CLE (typically library code)
        # Fallback: use only infos from the invocation, so we can still use SimProcedures
        l.warning("Couldn't find method %s.%s" % (expr.method_name, expr.class_name))
        return SootMethodDescriptor(expr.class_name, expr.method_name, expr.method_params)

    else:
        if len(methods) != 1: 
            # Found several methods matching class- and method-name
            # TODO: use information about the function signature to find the right one
            l.warning("Function %s is ambiguous in class %s" % (expr.method_name, expr.class_name))
        return SootMethodDescriptor.from_soot_method(methods[0])