forked from angr/angr-management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_rename_functions.py
67 lines (51 loc) · 2.35 KB
/
test_rename_functions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import os
import sys
import unittest
from PySide2.QtTest import QTest
from PySide2.QtCore import Qt
import angr
from angrmanagement.ui.main_window import MainWindow
from angrmanagement.ui.dialogs.rename_label import RenameLabel
from angrmanagement.ui.dialogs.rename_node import RenameNode
from common import setUp, test_location
class TestRenameFunctions(unittest.TestCase):
def setUp(self):
setUp()
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")
if __name__ == "__main__":
unittest.main(argv=sys.argv)