예제 #1
0
파일: console.py 프로젝트: iGio90/Dwarf
class ConsoleWidget(QSplitter):
    def __init__(self, parent=None, *__args):
        super().__init__(*__args)
        self.parent = parent

        self.qtabs = QTabWidget()

        self.js_console = DwarfConsoleWidget(parent,
                                             input_placeholder='$>',
                                             function_box=True)
        self.js_console.onCommandExecute.connect(self.js_callback)

        self.py_console = DwarfConsoleWidget(parent, input_placeholder='>>>')
        self.py_console.onCommandExecute.connect(self.py_callback)

        self.qtabs.addTab(self.js_console, 'javascript')
        self.qtabs.addTab(self.py_console, 'python')

        self.events = DwarfConsoleWidget(parent, has_input=False)

        self.addWidget(self.qtabs)
        self.addWidget(self.events)

    def clear(self):
        self.js_console.clear()
        self.py_console.clear()

    def get_js_console(self):
        return self.js_console

    def get_py_console(self):
        return self.py_console

    def get_events_console(self):
        return self.events

    def show_console_tab(self, tab_name):
        tab_name = tab_name.join(tab_name.split()).lower()
        if tab_name == 'javascript':
            self.qtabs.setCurrentIndex(0)
        elif tab_name == 'python':
            self.qtabs.setCurrentIndex(1)
        else:
            self.qtabs.setCurrentIndex(0)

    def js_callback(self, text):
        # the output in the logs is handled in dwarf_api
        result = self.parent.dwarf.dwarf_api('evaluate', text)
        if result:
            time_prefix = len(str(result).split('\n')) < 2
            self.js_console.log(result, time_prefix=time_prefix)

    def py_callback(self, text):
        try:
            self.py_console.log(exec(text))
        except Exception as e:
            self.py_console.log(str(e))
예제 #2
0
    def __init__(self, parent=None, *__args):
        super().__init__(*__args)
        self.parent = parent

        self.qtabs = QTabWidget()

        self.js_console = DwarfConsoleWidget(parent, input_placeholder='$>', function_box=True)
        self.js_console.onCommandExecute.connect(self.js_callback)

        self.py_console = DwarfConsoleWidget(parent, input_placeholder='>>>')
        self.py_console.onCommandExecute.connect(self.py_callback)

        self.qtabs.addTab(self.js_console, 'javascript')
        self.qtabs.addTab(self.py_console, 'python')

        self.events = DwarfConsoleWidget(parent, has_input=False)

        self.addWidget(self.qtabs)
        self.addWidget(self.events)
예제 #3
0
    def __init__(self, plugin, *__args):
        super().__init__(*__args)

        self.plugin = plugin
        self.app = plugin.app

        self.console = DwarfConsoleWidget(self.app,
                                          input_placeholder='r2',
                                          completer=False)
        self.console.onCommandExecute.connect(self.on_r2_command)

        self.e_list = EVarsList(self.plugin)

        self.addWidget(self.console)
        self.addWidget(self.e_list)

        self.setStretchFactor(0, 4)
        self.setStretchFactor(1, 1)

        self.refresh_e_vars_list()
예제 #4
0
class R2Widget(QSplitter):
    def __init__(self, plugin, *__args):
        super().__init__(*__args)

        self.plugin = plugin
        self.app = plugin.app

        self.console = DwarfConsoleWidget(self.app,
                                          input_placeholder='r2',
                                          completer=False)
        self.console.onCommandExecute.connect(self.on_r2_command)

        self.e_list = EVarsList(self.plugin)

        self.addWidget(self.console)
        self.addWidget(self.e_list)

        self.setStretchFactor(0, 4)
        self.setStretchFactor(1, 1)

        self.refresh_e_vars_list()

    def refresh_e_vars_list(self):
        self.e_list.refresh_e_vars_list()

    def on_r2_command(self, cmd):
        if self.plugin.pipe is None:
            self.plugin._create_pipe()

        if cmd == 'clear' or cmd == 'clean':
            self.console.clear()
        else:
            if self.plugin._working:
                self.console.log('please wait for other works to finish',
                                 time_prefix=False)
            else:
                try:
                    result = self.plugin.pipe.cmd(cmd)
                    self.console.log(result, time_prefix=False)
                except BrokenPipeError:
                    self.console.log('pipe is broken. recreating...',
                                     time_prefix=False)
                    self.plugin._create_pipe()
                    self.plugin.pipe.cmd('s %s' % self.current_seek)