예제 #1
0
파일: app.py 프로젝트: ExiaHan/Dwarf
class App(QWidget):
    def __init__(self, app_window, flags=None, *args, **kwargs):
        super().__init__(flags, *args, **kwargs)

        self.app_window = app_window
        self.arch = ''
        self.pointer_size = 0

        self.box = QVBoxLayout()
        self.box.setContentsMargins(0, 0, 0, 0)

        self.welcome_ui = None
        self.session_ui = None

        self.contexts = []
        self.context_tid = 0

    def setup_ui(self):
        self.session_ui = SessionUi(self)
        self.welcome_ui = WelcomeUi(self)

        self.session_ui.hide()

        self.box.addWidget(self.welcome_ui)
        self.box.addWidget(self.session_ui)

        self.setLayout(self.box)

    def restart(self):
        self.dwarf_api('restart')
        self.resume()
        self.get_contexts_panel().setRowCount(0)

    def resume(self):
        self.get_contexts_panel().setRowCount(0)
        self.contexts.clear()
        self.get_registers_panel().setRowCount(0)
        self.get_backtrace_panel().setRowCount(0)
        self.dwarf_api('release')

    def clear(self):
        self.modules_panel.setRowCount(0)
        self.ranges_panel.setRowCount(0)
        self.session_ui.get_log_panel().clear()

    def set_modules(self, modules):
        self.session_ui.modules_panel.set_modules(modules)

    def set_ranges(self, ranges):
        self.session_ui.ranges_panel.set_ranges(ranges)

    def _apply_context(self, context):
        self.context_tid = context['tid']
        if 'modules' in context:
            self.set_modules(context['modules'])
        if 'ranges' in context:
            self.set_ranges(context['ranges'])
        if 'context' in context:
            is_java = context['is_java']
            self.get_registers_panel().set_context(context['ptr'], is_java,
                                                   context['context'])
            if is_java:
                self.get_java_explorer_panel().set_handle_arg(-1)

        if 'backtrace' in context:
            self.get_backtrace_panel().set_backtrace(context['backtrace'])

    def apply_context(self, context):
        threading.Thread(target=self._apply_context, args=(context, )).start()

    def dwarf_api(self, api, args=None):
        return self.get_dwarf().dwarf_api(api, args)

    def get_adb(self):
        return self.app_window.get_adb()

    def get_asm_panel(self):
        return self.session_ui.asm_panel

    def get_arch(self):
        return self.arch

    def get_backtrace_panel(self):
        return self.session_ui.backtrace_panel

    def get_context_tid(self):
        return self.context_tid

    def get_contexts(self):
        return self.contexts

    def get_contexts_panel(self):
        return self.session_ui.contexts_panel

    def get_data_panel(self):
        return self.session_ui.data_panel

    def get_dwarf(self):
        return self.app_window.get_dwarf()

    def get_hooks_panel(self):
        return self.session_ui.hooks_panel

    def get_java_classes_panel(self):
        return self.session_ui.java_class_panel

    def get_java_explorer_panel(self):
        return self.session_ui.java_explorer_panel

    def get_log_panel(self):
        return self.session_ui.log_panel

    def get_memory_panel(self):
        return self.session_ui.memory_panel

    def get_modules_panel(self):
        return self.session_ui.modules_panel

    def get_pointer_size(self):
        return self.pointer_size

    def get_ranges_panel(self):
        return self.session_ui.ranges_panel

    def get_registers_panel(self):
        return self.session_ui.registers_panel

    def get_session_ui(self):
        return self.session_ui

    def on_script_destroyed(self):
        self.session_ui.hide()
        self.session_ui.on_script_destroyed()

        self.welcome_ui.show()
        self.welcome_ui.update_device_ui()

    def on_script_loaded(self):
        self.session_ui.on_script_loaded()

        self.welcome_ui.hide()
        self.session_ui.show()

        # trigger this to clear lists
        self.welcome_ui.on_device_changed()

    def set_arch(self, arch):
        self.arch = arch
        self.get_session_ui().asm_panel.on_arch_changed()
예제 #2
0
class App(QWidget):
    def __init__(self, app_window, flags=None, *args, **kwargs):
        super().__init__(flags, *args, **kwargs)

        self.app_window = app_window

        self.box = QVBoxLayout()
        self.box.setContentsMargins(0, 0, 0, 0)

        self.welcome_ui = None
        self.session_ui = None

    def setup_ui(self):
        self.session_ui = SessionUi(self)
        self.welcome_ui = WelcomeUi(self)

        self.session_ui.hide()

        self.box.addWidget(self.welcome_ui)
        self.box.addWidget(self.session_ui)

        self.setLayout(self.box)

    def restart(self):
        self.dwarf_api('restart')
        self.resume()

    def resume(self, tid=0):
        if tid == 0:
            self.get_contexts_lists_panel().setRowCount(0)
            self.get_context_panel().setRowCount(0)
            self.get_backtrace_panel().setRowCount(0)
            self.get_memory_panel().clear_panel()
            self.get_dwarf().contexts.clear()
            if self.get_java_explorer_panel() is not None:
                self.get_java_explorer_panel().clear_panel()

        self.dwarf_api('release', tid)

    def on_tid_resumed(self, tid):
        if self.get_dwarf().context_tid == tid:
            self.get_context_panel().setRowCount(0)
            self.get_backtrace_panel().setRowCount(0)
            self.get_memory_panel().clear_panel()
            if self.get_java_explorer_panel() is not None:
                self.get_java_explorer_panel().clear_panel()

        self.get_contexts_lists_panel().resume_tid(tid)

    def clear(self):
        self.modules_panel.setRowCount(0)
        self.ranges_panel.setRowCount(0)
        self.session_ui.console_panel().clear()

    def set_modules(self, modules):
        self.session_ui.modules_panel.set_modules(modules)

    def set_ranges(self, ranges):
        self.session_ui.ranges_panel.set_ranges(ranges)

    def _apply_context(self, context):
        if 'modules' in context:
            self.set_modules(context['modules'])
        if 'ranges' in context:
            self.set_ranges(context['ranges'])
        if 'context' in context:
            is_java = context['is_java']
            if is_java:
                self.get_context_panel().set_context(context['ptr'], 1,
                                                     context['context'])
                self.get_java_explorer_panel().set_handle_arg(-1)
            else:
                self.get_context_panel().set_context(context['ptr'], 0,
                                                     context['context'])

    def apply_context(self, context):
        threading.Thread(target=self._apply_context, args=(context, )).start()

    def dwarf_api(self, api, args=None, tid=0):
        return self.get_dwarf().dwarf_api(api, args=args, tid=tid)

    def get_adb(self):
        return self.app_window.get_adb()

    def get_asm_panel(self):
        return self.session_ui.asm_panel

    def get_backtrace_panel(self):
        return self.session_ui.backtrace_panel

    def get_context_panel(self):
        return self.session_ui.context_panel

    def get_contexts_lists_panel(self):
        return self.session_ui.contexts_list_panel

    def get_data_panel(self):
        return self.session_ui.data_panel

    def get_dwarf(self):
        return self.app_window.get_dwarf()

    def get_emulator_panel(self):
        return self.session_ui.emulator_panel

    def get_ftrace_panel(self):
        return self.session_ui.ftrace_panel

    def get_hooks_panel(self):
        return self.session_ui.hooks_panel

    def get_java_classes_panel(self):
        return self.session_ui.java_class_panel

    def get_java_explorer_panel(self):
        return self.session_ui.java_explorer_panel

    def get_java_trace_panel(self):
        return self.session_ui.java_trace_panel

    def get_console_panel(self):
        return self.session_ui.console_panel

    def get_memory_panel(self):
        return self.session_ui.memory_panel

    def get_modules_panel(self):
        return self.session_ui.modules_panel

    def get_pointer_size(self):
        return self.pointer_size

    def get_ranges_panel(self):
        return self.session_ui.ranges_panel

    def get_session_ui(self):
        return self.session_ui

    def get_trace_panel(self):
        return self.session_ui.trace_panel

    def get_watchers_panel(self):
        return self.session_ui.watchers_panel

    def on_script_destroyed(self):
        self.session_ui.hide()
        self.session_ui.on_script_destroyed()

        self.welcome_ui.show()
        self.welcome_ui.update_device_ui()

    def on_script_loaded(self):
        self.session_ui.on_script_loaded()

        self.welcome_ui.hide()
        self.session_ui.show()

        # trigger this to clear lists
        self.welcome_ui.on_devices_updated()