Esempio n. 1
0
    def stop(self):
        result = self._script.exports.stop()

        modules = dict(
            (int(module_id),
             Module(m['name'], int(m['base'], 16), m['size'], m['path']))
            for module_id, m in result['modules'].items())

        module_functions = {}
        dynamic_functions = []
        for module_id, name, visibility, raw_address, count in result[
                'targets']:
            address = int(raw_address, 16)

            if module_id != 0:
                module = modules[module_id]
                exported = visibility == 'e'
                function = ModuleFunction(module, name,
                                          address - module.base_address,
                                          exported)

                functions = module_functions.get(module, [])
                if len(functions) == 0:
                    module_functions[module] = functions
                functions.append((function, count))
            else:
                function = Function(name, address)

                dynamic_functions.append((function, count))

        self._ui.on_sample_result(module_functions, dynamic_functions)
Esempio n. 2
0
    def resolve(self, session, runtime, log_handler=None):
        script = session.create_script(name="profile-resolver",
                                       source=self._create_resolver_script(),
                                       runtime=runtime)
        script.set_log_handler(log_handler)

        def on_message(message, data):
            print(message)

        script.on('message', on_message)
        script.load()
        try:
            data = script.exports.resolve(self._spec)
        finally:
            script.unload()

        modules = {}
        for module_id, m in data['modules'].items():
            module = Module(m['name'], int(m['base'], 16), m['size'],
                            m['path'])
            modules[int(module_id)] = module

        working_set = []
        for target in data['targets']:
            objc = target.get('objc')
            if objc is not None:
                method = objc['method']
                of = ObjCMethod(method['type'], objc['className'],
                                method['name'], int(target['address'], 16))
                working_set.append(of)
            else:
                name = target['name']
                absolute_address = int(target['address'], 16)
                module_id = target.get('module')
                if module_id is not None:
                    module = modules[module_id]
                    relative_address = absolute_address - module.base_address
                    exported = not target.get('private', False)
                    mf = ModuleFunction(module, name, relative_address,
                                        exported)
                    if not self._is_blacklisted(mf):
                        working_set.append(mf)
                else:
                    f = Function(name, absolute_address)
                    working_set.append(f)
        return working_set