Пример #1
0
 def test_autocaps(self):
     self.editor.autocaps = True
     QTest.keyClicks(self.editor, 'thi!\' ')
     self.assertEqual(self.editor.textCursor().block().text(), 'The!\' ')
     QTest.keyClicks(self.editor, 'thi. the ')
     self.assertEqual(self.editor.textCursor().block().text(),
                      'The!\' The. The ')
Пример #2
0
    def test_cycling(self):
        text = 'e den '
        alt_text = 'i den '
        QTest.keyClicks(self.editor, text)
        self.editor.handle_mode_toggle()  # wordcheck mode

        cur = self.editor.textCursor()
        default_col = cur.charFormat().background().color().getRgb()
        cur.setPosition(0)
        self.editor.setTextCursor(cur)
        selection = self.editor.extraSelections()[0]
        col0 = selection.format.background().color().getRgb()

        QTest.keyClick(self.editor, Qt.Key_R)
        new_text = self.editor.toPlainText()
        selection = self.editor.extraSelections()[0]
        col1 = selection.format.background().color().getRgb()
        self.assertEqual(alt_text, new_text, msg="e to i")
        self.assertNotEqual(col1, default_col, msg="non-default color")
        self.assertNotEqual(col1, col0, msg="changed color")

        QTest.keyClick(self.editor, Qt.Key_E)
        new_text = self.editor.toPlainText()
        selection = self.editor.extraSelections()[0]
        col2 = selection.format.background().color().getRgb()
        self.assertEqual(text, new_text, msg="i to e")
        self.assertEqual(col2, col0, msg="back to same color")
Пример #3
0
 def test_ButtonClickOnInputX(self):
     """test the plotting of f(x)=x"""
     self.form.input_field.clear()
     QTest.keyClicks(self.form.input_field, "x")
     assert self.form.input_field.text() == "x"
     QTest.mouseClick(self.form.button, QtCore.Qt.LeftButton)
     assert self.form.canvas.figure is not None
Пример #4
0
    def test_index_preservation(self):
        text = 'e den '
        alt_text = 'i den '
        QTest.keyClicks(self.editor, text)
        self.editor.handle_mode_toggle()  # wordcheck mode

        cur = self.editor.textCursor()
        cur.setPosition(0)
        self.editor.setTextCursor(cur)

        QTest.keyClick(self.editor, Qt.Key_R)
        new_text = self.editor.toPlainText()
        self.assertEqual(alt_text, new_text, msg="e to i")

        # Move to other word and back.
        cur = self.editor.textCursor()
        cur.setPosition(4)
        self.editor.setTextCursor(cur)

        cur = self.editor.textCursor()
        cur.setPosition(0)
        self.editor.setTextCursor(cur)

        QTest.keyClick(self.editor, Qt.Key_R)
        QTest.keyClick(self.editor, Qt.Key_R)
        QTest.keyClick(self.editor, Qt.Key_R)
        new_text = self.editor.toPlainText()
        self.assertEqual(text, new_text, msg="i to e")
Пример #5
0
 def test_word_replace_trigger(self):
     QTest.keyClicks(self.editor, 'i')
     self.assertEqual(self.editor.textCursor().block().text(),
                      "i",
                      msg="plain i stays i")
     self.editor.document().clear()
     QTest.keyClicks(self.editor, 'e')
     self.assertEqual(self.editor.textCursor().block().text(),
                      "e",
                      msg="plain e stays e")
     self.editor.document().clear()
     # for whatever reason, python puts e before i, so e is default.
     QTest.keyClicks(self.editor, 'i ')
     self.assertEqual(self.editor.textCursor().block().text(),
                      "e ",
                      msg="space bar coersion")
     self.editor.document().clear()
     QTest.keyClicks(self.editor, 'i')
     QTest.keyClick(self.editor, Qt.Key_Return)
     self.assertEqual(self.editor.textCursor().block().previous().text(),
                      "e",
                      msg="return btn coersion")
     self.editor.document().clear()
     QTest.keyClicks(self.editor, 'i/')
     self.assertEqual(self.editor.textCursor().block().text(),
                      "e/",
                      msg="slash coersion")
Пример #6
0
 def test_ButtonClickOnInput_e_of_x(self):
     """test the plotting of f(x)=e(x)"""
     self.form.input_field.clear()
     QTest.keyClicks(self.form.input_field, "e(x)")
     assert self.form.input_field.text() == "e(x)"
     QTest.mouseClick(self.form.button, QtCore.Qt.LeftButton)
     assert self.form.msg.text() == 'Error'
Пример #7
0
    def keyClicks(self, widget, sequence, modifier=qt.Qt.NoModifier, delay=-1):
        """Simulate clicking a sequence of keys.

        See QTest.keyClick for details.
        """
        QTest.keyClicks(widget, sequence, modifier, delay)
        self.qWait(20)
Пример #8
0
 def test_typing(self):
     self.editor.handle_mode_toggle()
     QTest.keyClicks(self.editor, 'xza,.;')
     self.assertEqual(self.editor.textCursor().block().text(), ',.;,.;')
     self.editor.clear()
     QTest.keyClicks(self.editor, 'XZA<>:', modifier=Qt.ShiftModifier)
     self.assertEqual(self.editor.textCursor().block().text(), '<>:<>:')
     QTest.keyClick(self.editor, Qt.Key_Backspace, modifier=Qt.NoModifier)
     self.assertEqual(self.editor.textCursor().block().text(), '<>:<>')
Пример #9
0
 def test_browse_micrographs_updates_templatesBox(self):
     a = Main_window()
     import inspect
     test_file = inspect.getfile(os)
     QTest.mouseClick(a.templateBrowseButton, Qt.LeftButton)  #popup dialog
     a.browse_dialog.selectFile(test_file)  #select a file
     QTest.keyClicks(a.browse_dialog, '\r')  #return to close
     self.assertEqual(
         os.path.normpath(test_file).lower(),
         os.path.normpath(a.templatesBox.text().lower()))
Пример #10
0
 def test_modify_edit(self, data_instance, form, new_value):
     target = new_value(data_instance.value)
     assert target != data_instance.value
     for w in (form.edit, form.otheredit):
         w.clear()
         QTest.keyClicks(w, str(target))
         QTest.keyClick(w, Qt.Key_Enter)
         assert data_instance.value == form.edit.value()
         assert data_instance.value == form.otheredit.value()
         assert data_instance.value == target
Пример #11
0
    def test_resets_if_reset_true(self):
        input = TextField(
            'key', 'My label', default="default value", remember=False)

        QTest.keyClicks(input.widget, " and some more text")

        self.assertNotEqual(input.value(), "default value")

        input.init()

        self.assertEqual(input.value(), "default value")
Пример #12
0
    def test_reset_leaves_value_by_default(self):
        input = TextField('key', 'My label')
        input.init()

        QTest.keyClicks(input.widget, "My Input Text")

        self.assertEqual(input.value(), "My Input Text")

        input.init()

        self.assertEqual(input.value(), "My Input Text")
Пример #13
0
    def test_no_reset_as_default(self):
        input = TextField('key', 'My label', default="default value")

        QTest.keyClicks(input.widget, " and some more text")

        value = input.value()
        self.assertNotEqual(input.value(), "default value")

        input.init()

        # input value remains the same on calls to init
        self.assertEqual(input.value(), value)
Пример #14
0
    def test_missing_word(self):
        text = 'jkljkl e den '
        QTest.keyClicks(self.editor, text)
        self.editor.handle_mode_toggle()  # wordcheck mode

        cur = self.editor.textCursor()
        cur.setPosition(0)
        self.editor.setTextCursor(cur)

        QTest.keyClick(self.editor, Qt.Key_U)
        new_text = self.editor.toPlainText()
        self.assertEqual(text, new_text)
    def test_rename_a_function_in_disasm_and_pseudocode_views(self):
        main = self._open_a_project()

        func = main.workspace.instance.project.kb.functions['main']
        self.assertIsNotNone(func)

        # decompile the function
        disasm_view = main.workspace._get_or_create_disassembly_view()
        disasm_view._t_flow_graph_visible = True
        disasm_view.display_function(func)
        disasm_view.decompile_current_function()
        main.workspace.instance.join_all_jobs()
        pseudocode_view = main.workspace._get_or_create_pseudocode_view()

        # find the node for function
        for _, item in pseudocode_view.codegen.map_pos_to_node.items():
            if isinstance(
                    item.obj,
                    angr.analyses.decompiler.structured_codegen.c.CFunction):
                func_node = item.obj
                break
        else:
            self.fail("The CFunction instance is not found.")

        self.assertEqual(func_node.name, "main")

        # rename the function in the disassembly view
        rlabel = RenameLabel(disasm_view, func.addr, parent=None)
        rlabel._name_box.setText("")
        QTest.keyClicks(rlabel._name_box, "asdf")
        QTest.mouseClick(rlabel._ok_button, Qt.MouseButton.LeftButton)

        self.assertEqual(func.name, "asdf")
        self.assertEqual(func_node.name, "main")

        # rename the function in the pseudocode view
        rnode = RenameNode(code_view=pseudocode_view, node=func_node)
        rnode._name_box.setText("")
        QTest.keyClicks(rnode._name_box, "fdsa")
        QTest.mouseClick(rnode._ok_button, Qt.MouseButton.LeftButton)

        self.assertEqual(func.name, "fdsa")

        sleep(5)
        self.session = Slacrs(database=Conf.checrs_backend_str).session()
        function_rename = self.session.query(HumanActivity).filter(
            HumanActivity.project_md5 == self.project_md5,
            HumanActivity.category == HumanActivityEnum.FunctionRename,
            HumanActivity.old_name == "main",
            HumanActivity.new_name == "fdsa",
        ).one()
        self.session.close()
        self.assertIsNotNone(function_rename)
Пример #16
0
def config_and_connect(binsync_plugin, username, sync_dir_path, init=False):
    config = SyncConfig(binsync_plugin.controller,
                        open_magic_sync=False,
                        load_config=not init)
    config._user_edit.setText("")
    config._repo_edit.setText("")
    QTest.keyClicks(config._user_edit, username)
    QTest.keyClicks(config._repo_edit, sync_dir_path)
    # always init for first user
    if init:
        QTest.mouseClick(config._initrepo_checkbox, Qt.MouseButton.LeftButton)

    QTest.mouseClick(config._ok_button, Qt.MouseButton.LeftButton)
Пример #17
0
    def test_hot_word_replacement(self):
        # this test handles getting to "hi," from its default coersion to "hex"
        QTest.keyClicks(self.editor, 'hi, ')  # coerced to "hex"
        self.editor.handle_mode_toggle()

        cur = self.editor.textCursor()
        cur.setPosition(3)
        self.editor.setTextCursor(cur)
        QTest.keyClick(self.editor, Qt.Key_Backspace,
                       modifier=Qt.NoModifier)  # "he| " (| = cursor)

        QTest.keyClick(self.editor, Qt.Key_U)
        self.assertEqual(self.editor.textCursor().block().text(), 'hi ')
Пример #18
0
 def test_move_left_then_right(self):
     QTest.keyClicks(self.editor, 'the box')
     self.editor.handle_mode_toggle()
     QTest.keyClick(self.editor, Qt.Key_S)
     QTest.keyClick(self.editor, Qt.Key_H)
     self.assertEqual(self.editor.textCursor().position(),
                      0,
                      msg="move by word")
     QTest.keyClick(self.editor, Qt.Key_V)
     QTest.keyClick(self.editor, Qt.Key_M)
     self.assertEqual(self.editor.textCursor().position(),
                      2,
                      msg="move by char")
     self.assertEqual(self.editor.toPlainText(),
                      "the box",
                      msg="text modified")
Пример #19
0
    def test_function_name(self):
        proj = angr.Project(os.path.join(test_location, "x86_64", "fauxware"),
                            auto_load_libs=False)
        main = MainWindow(show=False)
        main.workspace.instance.project = proj

        cfg = proj.analyses.CFG()
        obj = QAddressInput(None, main.workspace)

        obj.setText("")
        QTest.keyClicks(obj, "main")
        self.assertEqual(obj.target, cfg.kb.functions['main'].addr)

        obj.setText("")
        QTest.keyClicks(obj, "main_1")
        self.assertIsNone(obj.target)
    def test_rename_a_function_in_disasm_and_pseudocode_views(self):
        main = MainWindow(show=False)
        binpath = os.path.join(test_location, "x86_64", "fauxware")
        main.workspace.instance.project.am_obj = angr.Project(
            binpath, auto_load_libs=False)
        main.workspace.instance.project.am_event()
        main.workspace.instance.join_all_jobs()

        func = main.workspace.instance.project.kb.functions['main']
        self.assertIsNotNone(func)

        # decompile the function
        disasm_view = main.workspace._get_or_create_disassembly_view()
        disasm_view._t_flow_graph_visible = True
        disasm_view.display_function(func)
        disasm_view.decompile_current_function()
        main.workspace.instance.join_all_jobs()
        pseudocode_view = main.workspace._get_or_create_pseudocode_view()

        # find the node for function
        for _, item in pseudocode_view.codegen.map_pos_to_node.items():
            if isinstance(
                    item.obj,
                    angr.analyses.decompiler.structured_codegen.c.CFunction):
                func_node = item.obj
                break
        else:
            self.fail("The CFunction instance is not found.")

        self.assertEqual(func_node.name, "main")

        # rename the function in the disassembly view
        rlabel = RenameLabel(disasm_view, func.addr, parent=None)
        rlabel._name_box.setText("")
        QTest.keyClicks(rlabel._name_box, "asdf")
        QTest.mouseClick(rlabel._ok_button, Qt.MouseButton.LeftButton)

        self.assertEqual(func.name, "asdf")
        self.assertEqual(func_node.name, "main")

        # rename the function in the pseudocode view
        rnode = RenameNode(code_view=pseudocode_view, node=func_node)
        rnode._name_box.setText("")
        QTest.keyClicks(rnode._name_box, "fdsa")
        QTest.mouseClick(rnode._ok_button, Qt.MouseButton.LeftButton)

        self.assertEqual(func.name, "fdsa")
Пример #21
0
    def test_basic(self):
        text = 'En '
        QTest.keyClicks(self.editor, text)
        self.editor.handle_mode_toggle()  # wordcheck mode

        cur = self.editor.textCursor()
        cur.setPosition(0)
        self.editor.setTextCursor(cur)

        QTest.keyClick(self.editor, Qt.Key_R)
        self.assertEqual(self.editor.toPlainText(),
                         "In ",
                         msg="upper case options maintained")
        QTest.keyClick(self.editor, Qt.Key_R)
        self.assertEqual(self.editor.toPlainText(),
                         "en ",
                         msg="lower case options maintained")
Пример #22
0
 def test_move_right_then_left(self):
     QTest.keyClicks(self.editor, 'the box is')
     self.editor.handle_mode_toggle()
     start_cur = self.editor.textCursor()
     start_cur.setPosition(0)
     self.editor.setTextCursor(start_cur)
     QTest.keyClick(self.editor, Qt.Key_G)
     QTest.keyClick(self.editor, Qt.Key_L)
     self.assertEqual(self.editor.textCursor().position(),
                      8,
                      msg="move by word")
     QTest.keyClick(self.editor, Qt.Key_C)
     QTest.keyClick(self.editor, Qt.Key_N)
     self.assertEqual(self.editor.textCursor().position(),
                      6,
                      msg="move by char")
     self.assertEqual(self.editor.toPlainText(),
                      "the box is",
                      msg="text modified")
Пример #23
0
    def test_highlighting_colors_different(self):
        QTest.keyClicks(self.editor, 'i x i')  # Don't coerce ending `i`
        self.editor.handle_mode_toggle()  # wordcheck mode

        cur = self.editor.textCursor()
        default_col = cur.charFormat().background().color().getRgb()
        cur.setPosition(0)
        self.editor.setTextCursor(cur)

        selection = self.editor.extraSelections()[0]
        col0 = selection.format.background().color().getRgb()
        self.assertNotEqual(default_col, col0)

        cur = self.editor.textCursor()
        cur.setPosition(1)
        self.editor.setTextCursor(cur)
        selection = self.editor.extraSelections()[0]
        col1 = selection.format.background().color().getRgb()
        self.assertEqual(col0, col1)

        cur = self.editor.textCursor()
        cur.setPosition(2)
        self.editor.setTextCursor(cur)
        selection = self.editor.extraSelections()[0]
        col2 = selection.format.background().color().getRgb()
        self.assertNotEqual(col0, col2)
        self.assertNotEqual(default_col, col2)

        cur = self.editor.textCursor()
        cur.setPosition(4)
        self.editor.setTextCursor(cur)
        selection = self.editor.extraSelections()[0]
        col4 = selection.format.background().color().getRgb()
        self.assertNotEqual(col0, col4)
        self.assertNotEqual(col2, col4)
        self.assertNotEqual(default_col, col4)

        cur = self.editor.textCursor()
        cur.setPosition(5)
        self.editor.setTextCursor(cur)
        selection = self.editor.extraSelections()[0]
        col5 = selection.format.background().color().getRgb()
        self.assertEqual(col4, col5)
Пример #24
0
    def test_resets_children(self):
        input1 = TextField("key1", "label", default="default", remember=False)
        input2 = TextField("key2", "label", default="default", remember=True)

        self.children = [input1, input2]
        self.instance()

        # type into fields
        for child in self.children:
            QTest.keyClicks(child.widget, " some text")

        ok_button = find_QPushButton(self.run_create_view, 'ok')
        button_callback(method=self.run_create_view.show, button=ok_button)

        values = self.run_create_view.data()

        self.assertEqual(values, {
            'key1': 'default',
            'key2': 'default some text'
        })
    def test_rename_a_variable_in_pseudocode_view(self):
        main = self._open_a_project()

        func = main.workspace.instance.project.kb.functions['main']
        self.assertIsNotNone(func)

        # decompile the function
        disasm_view = main.workspace._get_or_create_disassembly_view()
        disasm_view._t_flow_graph_visible = True
        disasm_view.display_function(func)
        disasm_view.decompile_current_function()
        main.workspace.instance.join_all_jobs()
        pseudocode_view = main.workspace._get_or_create_pseudocode_view()

        # find an arbitrary node for a variable
        for _, item in pseudocode_view.codegen.map_pos_to_node.items():
            if isinstance(item.obj, angr.analyses.decompiler.structured_codegen.c.CVariable) \
                    and item.obj.unified_variable is not None:
                variable_node = item.obj
                break
        else:
            self.fail("Cannot find a testing variable.")

        # rename the variable in the pseudocode view
        rnode = RenameNode(code_view=pseudocode_view, node=variable_node)
        rnode._name_box.setText("")
        QTest.keyClicks(rnode._name_box, "fdsa")
        QTest.mouseClick(rnode._ok_button, Qt.MouseButton.LeftButton)

        self.assertEqual(variable_node.unified_variable.name, "fdsa")

        sleep(5)
        self.session = Slacrs(database=Conf.checrs_backend_str).session()
        variable_rename = self.session.query(HumanActivity).filter(
            HumanActivity.project_md5 == self.project_md5,
            HumanActivity.new_name == "fdsa",
        ).one()
        self.session.close()
        self.assertIsNotNone(variable_rename)
Пример #26
0
    def rename_stack_variable(self, main, func, var_offset, new_var_name):
        """
        Renames a stack variable at a given function and offset
        """
        disasm_view = main.workspace._get_or_create_disassembly_view()
        disasm_view._t_flow_graph_visible = True
        disasm_view.display_function(func)
        disasm_view.decompile_current_function()
        main.workspace.instance.join_all_jobs()
        pseudocode_view = main.workspace._get_or_create_pseudocode_view()
        for _, item in pseudocode_view.codegen.map_pos_to_node.items():
            if isinstance(item.obj, angr.analyses.decompiler.structured_codegen.c.CVariable) and \
                    isinstance(item.obj.variable, angr.sim_variable.SimStackVariable) and \
                    item.obj.variable.offset == var_offset:
                var_node = item.obj
                break
        else:
            self.fail("The CVariable _instance is not found.")

        rnode = RenameNode(code_view=pseudocode_view, node=var_node)
        rnode._name_box.setText("")
        QTest.keyClicks(rnode._name_box, new_var_name)
        QTest.mouseClick(rnode._ok_button, Qt.MouseButton.LeftButton)
Пример #27
0
 def rename_function(self, main, func, new_function_name):
     """
     Renames a given function
     """
     disasm_view = main.workspace._get_or_create_disassembly_view()
     disasm_view._t_flow_graph_visible = True
     disasm_view.display_function(func)
     disasm_view.decompile_current_function()
     main.workspace.instance.join_all_jobs()
     pseudocode_view = main.workspace._get_or_create_pseudocode_view()
     for _, item in pseudocode_view.codegen.map_pos_to_node.items():
         if isinstance(
                 item.obj,
                 angr.analyses.decompiler.structured_codegen.c.CFunction):
             func_node = item.obj
             break
     else:
         self.fail("The CFunction _instance is not found.")
     rnode = RenameNode(code_view=pseudocode_view, node=func_node)
     rnode._name_box.setText("")
     QTest.keyClicks(rnode._name_box, new_function_name)
     QTest.mouseClick(rnode._ok_button, Qt.MouseButton.LeftButton)
     self.assertEqual(func.name, new_function_name)
Пример #28
0
 def test_end_of_word_letter_maps(self):
     QTest.keyClicks(self.editor, ';, ')
     self.assertEqual(self.editor.textCursor().block().text(), "ax ")
     self.editor.document().clear()
     QTest.keyClicks(self.editor, ';,, ')
     self.assertEqual(self.editor.textCursor().block().text(), "ax, ")
     self.editor.document().clear()
     QTest.keyClicks(self.editor, 'axAx ')
     self.assertEqual(self.editor.textCursor().block().text(),
                      "ax:, ",
                      msg="for lefties")
Пример #29
0
    def test_address_conversion(self):
        main = MainWindow(show=False)
        main.workspace.instance.project = load_shellcode(b'X', 'amd64')
        main.workspace.instance.project.kb.functions.function(addr=0x1234,
                                                              name='foo',
                                                              create=True)

        obj = QAddressInput(None, main.workspace)

        obj.setText("")
        QTest.keyClicks(obj, "4321")
        self.assertEqual(obj.target, 0x4321)

        obj.setText("")
        QTest.keyClicks(obj, "foo")
        self.assertEqual(obj.target, 0x1234)

        obj.setText("")
        QTest.keyClicks(obj, "12x3")
        self.assertIsNone(obj.target)
Пример #30
0
 def test_handles_contractions(self):
     QTest.keyClicks(self.editor, 'iy\'lAzx ')
     self.assertEqual(self.editor.textCursor().block().text(), "it\'s:., ")