forked from korcankaraokcu/PINCE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PINCE.py
executable file
·5152 lines (4616 loc) · 249 KB
/
PINCE.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (C) 2016-2017 Korcan Karaokçu <[email protected]>
Copyright (C) 2016-2017 Çağrı Ulaş <[email protected]>
Copyright (C) 2016-2017 Jakob Kreuze <[email protected]>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
from PyQt5.QtGui import QIcon, QMovie, QPixmap, QCursor, QKeySequence, QColor, QTextCharFormat, QBrush, QTextCursor, \
QKeyEvent, QRegExpValidator
from PyQt5.QtWidgets import QApplication, QMainWindow, QTableWidgetItem, QMessageBox, QDialog, QWidget, \
QShortcut, QKeySequenceEdit, QTabWidget, QMenu, QFileDialog, QAbstractItemView, QTreeWidgetItem, \
QTreeWidgetItemIterator, QCompleter, QLabel, QLineEdit, QComboBox, QDialogButtonBox
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QSize, QByteArray, QSettings, QEvent, \
QItemSelectionModel, QTimer, QModelIndex, QStringListModel, QRegExp, QRunnable, QThreadPool, pyqtSlot
from time import sleep, time
import os, sys, traceback, signal, re, copy, io, queue, collections, ast, psutil, pexpect
from libPINCE import GuiUtils, SysUtils, GDB_Engine, type_defs
from libPINCE.libscanmem.scanmem import Scanmem
from GUI.MainWindow import Ui_MainWindow as MainWindow
from GUI.SelectProcess import Ui_MainWindow as ProcessWindow
from GUI.AddAddressManuallyDialog import Ui_Dialog as ManualAddressDialog
from GUI.EditTypeDialog import Ui_Dialog as EditTypeDialog
from GUI.LoadingDialog import Ui_Dialog as LoadingDialog
from GUI.InputDialog import Ui_Dialog as InputDialog
from GUI.TextEditDialog import Ui_Dialog as TextEditDialog
from GUI.SettingsDialog import Ui_Dialog as SettingsDialog
from GUI.ConsoleWidget import Ui_Form as ConsoleWidget
from GUI.AboutWidget import Ui_TabWidget as AboutWidget
# If you are going to change the name "Ui_MainWindow_MemoryView", review GUI/CustomLabels/RegisterLabel.py as well
from GUI.MemoryViewerWindow import Ui_MainWindow_MemoryView as MemoryViewWindow
from GUI.BookmarkWidget import Ui_Form as BookmarkWidget
from GUI.FloatRegisterWidget import Ui_TabWidget as FloatRegisterWidget
from GUI.StackTraceInfoWidget import Ui_Form as StackTraceInfoWidget
from GUI.BreakpointInfoWidget import Ui_TabWidget as BreakpointInfoWidget
from GUI.TrackWatchpointWidget import Ui_Form as TrackWatchpointWidget
from GUI.TrackBreakpointWidget import Ui_Form as TrackBreakpointWidget
from GUI.TraceInstructionsPromptDialog import Ui_Dialog as TraceInstructionsPromptDialog
from GUI.TraceInstructionsWaitWidget import Ui_Form as TraceInstructionsWaitWidget
from GUI.TraceInstructionsWindow import Ui_MainWindow as TraceInstructionsWindow
from GUI.FunctionsInfoWidget import Ui_Form as FunctionsInfoWidget
from GUI.HexEditDialog import Ui_Dialog as HexEditDialog
from GUI.LibPINCEReferenceWidget import Ui_Form as LibPINCEReferenceWidget
from GUI.LogFileWidget import Ui_Form as LogFileWidget
from GUI.SearchOpcodeWidget import Ui_Form as SearchOpcodeWidget
from GUI.MemoryRegionsWidget import Ui_Form as MemoryRegionsWidget
from GUI.DissectCodeDialog import Ui_Dialog as DissectCodeDialog
from GUI.ReferencedStringsWidget import Ui_Form as ReferencedStringsWidget
from GUI.ReferencedCallsWidget import Ui_Form as ReferencedCallsWidget
from GUI.ExamineReferrersWidget import Ui_Form as ExamineReferrersWidget
from GUI.CustomAbstractTableModels.HexModel import QHexModel
from GUI.CustomAbstractTableModels.AsciiModel import QAsciiModel
from GUI.CustomValidators.HexValidator import QHexValidator
instances = [] # Holds temporary instances that will be deleted later on
# settings
current_settings_version = "master-18" # Increase version by one if you change settings. Format: branch_name-version
update_table = bool
table_update_interval = int
FreezeInterval = int
show_messagebox_on_exception = bool
show_messagebox_on_toggle_attach = bool
gdb_output_mode = tuple
auto_attach_list = str
auto_attach_regex = bool
logo_path = str
class Hotkeys:
class Hotkey:
def __init__(self, name="", desc="", default="", value="", context=Qt.ApplicationShortcut):
self.name = name
self.desc = desc
self.default = default
self.value = value
self.context = context
pause_hotkey = Hotkey("pause_hotkey", "Pause the process", "F1")
break_hotkey = Hotkey("break_hotkey", "Break the process", "F2")
continue_hotkey = Hotkey("continue_hotkey", "Continue the process", "F3")
toggle_attach_hotkey = Hotkey("toggle_attach_hotkey", "Toggle attach/detach", "Shift+F10")
@staticmethod
def get_hotkeys():
return Hotkeys.pause_hotkey, Hotkeys.break_hotkey, Hotkeys.continue_hotkey, Hotkeys.toggle_attach_hotkey
code_injection_method = int
bring_disassemble_to_front = bool
instructions_per_scroll = int
gdb_path = str
gdb_logging = bool
# represents the index of columns in breakpoint table
BREAK_NUM_COL = 0
BREAK_TYPE_COL = 1
BREAK_DISP_COL = 2
BREAK_ENABLED_COL = 3
BREAK_ADDR_COL = 4
BREAK_SIZE_COL = 5
BREAK_ON_HIT_COL = 6
BREAK_HIT_COUNT_COL = 7
BREAK_COND_COL = 8
# row colours for disassemble qtablewidget
PC_COLOUR = Qt.blue
BOOKMARK_COLOUR = Qt.cyan
DEFAULT_COLOUR = Qt.white
BREAKPOINT_COLOUR = Qt.red
REF_COLOUR = Qt.lightGray
# represents the index of columns in address table
FROZEN_COL = 0 # Frozen
DESC_COL = 1 # Description
ADDR_COL = 2 # Address
TYPE_COL = 3 # Type
VALUE_COL = 4 # Value
# roles used to store hidden information inside address table
ADDR_EXPR_ROLE = Qt.UserRole
# represents the index of columns in disassemble table
DISAS_ADDR_COL = 0
DISAS_BYTES_COL = 1
DISAS_OPCODES_COL = 2
DISAS_COMMENT_COL = 3
# represents the index of columns in floating point table
FLOAT_REGISTERS_NAME_COL = 0
FLOAT_REGISTERS_VALUE_COL = 1
# represents the index of columns in stacktrace table
STACKTRACE_RETURN_ADDRESS_COL = 0
STACKTRACE_FRAME_ADDRESS_COL = 1
# represents the index of columns in stack table
STACK_POINTER_ADDRESS_COL = 0
STACK_VALUE_COL = 1
STACK_POINTS_TO_COL = 2
# represents row and column counts of Hex table
HEX_VIEW_COL_COUNT = 16
HEX_VIEW_ROW_COUNT = 42 # J-JUST A COINCIDENCE, I SWEAR!
# represents the index of columns in track watchpoint table(what accesses this address thingy)
TRACK_WATCHPOINT_COUNT_COL = 0
TRACK_WATCHPOINT_ADDR_COL = 1
# represents the index of columns in track breakpoint table(which addresses this instruction accesses thingy)
TRACK_BREAKPOINT_COUNT_COL = 0
TRACK_BREAKPOINT_ADDR_COL = 1
TRACK_BREAKPOINT_VALUE_COL = 2
TRACK_BREAKPOINT_SOURCE_COL = 3
# represents the index of columns in function info table
FUNCTIONS_INFO_ADDR_COL = 0
FUNCTIONS_INFO_SYMBOL_COL = 1
# represents the index of columns in libPINCE reference resources table
LIBPINCE_REFERENCE_ITEM_COL = 0
LIBPINCE_REFERENCE_VALUE_COL = 1
# represents the index of columns in search opcode table
SEARCH_OPCODE_ADDR_COL = 0
SEARCH_OPCODE_OPCODES_COL = 1
# represents the index of columns in memory regions table
MEMORY_REGIONS_ADDR_COL = 0
MEMORY_REGIONS_PERM_COL = 1
MEMORY_REGIONS_SIZE_COL = 2
MEMORY_REGIONS_PATH_COL = 3
MEMORY_REGIONS_RSS_COL = 4
MEMORY_REGIONS_PSS_COL = 5
MEMORY_REGIONS_SHRCLN_COL = 6
MEMORY_REGIONS_SHRDRTY_COL = 7
MEMORY_REGIONS_PRIVCLN_COL = 8
MEMORY_REGIONS_PRIVDRTY_COL = 9
MEMORY_REGIONS_REF_COL = 10
MEMORY_REGIONS_ANON_COL = 11
MEMORY_REGIONS_SWAP_COL = 12
# represents the index of columns in dissect code table
DISSECT_CODE_ADDR_COL = 0
DISSECT_CODE_PATH_COL = 1
# represents the index of columns in referenced strings table
REF_STR_ADDR_COL = 0
REF_STR_COUNT_COL = 1
REF_STR_VAL_COL = 2
# represents the index of columns in referenced calls table
REF_CALL_ADDR_COL = 0
REF_CALL_COUNT_COL = 1
# used for automatically updating the values in the saved address tree widget
# see UpdateAddressTableThread
saved_addresses_changed_list = list()
# vars for communication/storage with the non blocking threads
# see treeWidget_AddressTable_item_clicked
Exiting = 0
FreezeVars = {}
FreezeStop = 0
ProgressRun = 0
threadpool = QThreadPool()
# Placeholder number, may have to be changed in the future
threadpool.setMaxThreadCount(10)
class Worker(QRunnable):
def __init__(self, fn, *args, **kwargs):
super(Worker, self).__init__()
self.fn = fn
self.args = args
self.kwargs = kwargs
@pyqtSlot()
def run(self):
self.fn(*self.args, **self.kwargs)
def except_hook(exception_type, value, tb):
if show_messagebox_on_exception:
focused_widget = app.focusWidget()
if focused_widget:
if exception_type == type_defs.GDBInitializeException:
QMessageBox.information(focused_widget, "Error", "GDB isn't initialized yet")
elif exception_type == type_defs.InferiorRunningException:
error_dialog = InputDialogForm(item_list=[(
"Process is running" + "\nPress " + Hotkeys.break_hotkey.value + " to stop process" +
"\n\nGo to Settings->General to disable this dialog",)], buttons=[QDialogButtonBox.Ok])
error_dialog.exec_()
traceback.print_exception(exception_type, value, tb)
# From version 5.5 and onwards, PyQT calls qFatal() when an exception has been encountered
# So, we must override sys.excepthook to avoid calling of qFatal()
sys.excepthook = except_hook
def signal_handler(signal, frame):
GDB_Engine.cancel_last_command()
raise KeyboardInterrupt
signal.signal(signal.SIGINT, signal_handler)
# Checks if the inferior has been terminated
class AwaitProcessExit(QThread):
process_exited = pyqtSignal()
def run(self):
while True:
with GDB_Engine.process_exited_condition:
GDB_Engine.process_exited_condition.wait()
self.process_exited.emit()
# Await async output from gdb
class AwaitAsyncOutput(QThread):
async_output_ready = pyqtSignal(str)
def __init__(self):
super(AwaitAsyncOutput, self).__init__()
self.queue_active = True
def run(self):
async_output_queue = GDB_Engine.gdb_async_output.register_queue()
while self.queue_active:
try:
async_output = async_output_queue.get(timeout=5)
except queue.Empty:
pass
else:
self.async_output_ready.emit(async_output)
GDB_Engine.gdb_async_output.delete_queue(async_output_queue)
def stop(self):
self.queue_active = False
class CheckInferiorStatus(QThread):
process_stopped = pyqtSignal()
process_running = pyqtSignal()
def run(self):
while True:
with GDB_Engine.status_changed_condition:
GDB_Engine.status_changed_condition.wait()
if GDB_Engine.inferior_status == type_defs.INFERIOR_STATUS.INFERIOR_STOPPED and GDB_Engine.temporary_execution_bool != True:
print("execute condition: " + str(GDB_Engine.temporary_execution_bool))
self.process_stopped.emit()
elif GDB_Engine.inferior_status == type_defs.INFERIOR_STATUS.INFERIOR_RUNNING and GDB_Engine.temporary_execution_bool != True:
self.process_running.emit()
# TODO undo scan, we would probably need to make some data structure we
# could pass to scanmem which then would set the current matches
# the mainwindow
class MainForm(QMainWindow, MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.hotkey_to_shortcut = {} # Dict[str:QShortcut]-->Dict[Hotkey.name:QShortcut(QKeySequence(Hotkey.value)]
hotkey_to_func = {
Hotkeys.pause_hotkey: self.pause_hotkey_pressed,
Hotkeys.break_hotkey: self.break_hotkey_pressed,
Hotkeys.continue_hotkey: self.continue_hotkey_pressed,
Hotkeys.toggle_attach_hotkey: self.toggle_attach_hotkey_pressed
}
for hotkey, func in hotkey_to_func.items():
current_shortcut = QShortcut(QKeySequence(hotkey.value), self)
current_shortcut.activated.connect(func)
current_shortcut.setContext(hotkey.context)
self.hotkey_to_shortcut[hotkey.name] = current_shortcut
GuiUtils.center(self)
self.treeWidget_AddressTable.setColumnWidth(FROZEN_COL, 50)
self.treeWidget_AddressTable.setColumnWidth(DESC_COL, 150)
self.treeWidget_AddressTable.setColumnWidth(ADDR_COL, 150)
self.treeWidget_AddressTable.setColumnWidth(TYPE_COL, 150)
app.setOrganizationName("PINCE")
app.setOrganizationDomain("github.com/korcankaraokcu/PINCE")
app.setApplicationName("PINCE")
QSettings.setPath(QSettings.NativeFormat, QSettings.UserScope,
SysUtils.get_user_path(type_defs.USER_PATHS.CONFIG_PATH))
self.settings = QSettings()
if not SysUtils.is_path_valid(self.settings.fileName()):
self.set_default_settings()
try:
settings_version = self.settings.value("Misc/version", type=str)
except Exception as e:
print("An exception occurred while reading settings version\n", e)
settings_version = None
if settings_version != current_settings_version:
print("Settings version mismatch, rolling back to the default configuration")
self.settings.clear()
self.set_default_settings()
try:
self.apply_settings()
except Exception as e:
print("An exception occurred while trying to load settings, rolling back to the default configuration\n", e)
self.settings.clear()
self.set_default_settings()
try:
GDB_Engine.init_gdb(gdb_path=gdb_path)
except pexpect.EOF:
text = "Unable to initialize GDB\n" \
"You might want to reinstall GDB or use the system GDB\n" \
"To change the current GDB path, check Settings->Debug"
InputDialogForm(item_list=[(text, None)], buttons=[QDialogButtonBox.Ok]).exec_()
else:
GDB_Engine.set_logging(gdb_logging)
# this should be changed, only works if you use the current directory, fails if you for example install it to some place like bin
libscanmem_path = os.path.join(os.getcwd(), "libPINCE", "libscanmem", "libscanmem.so")
self.backend = Scanmem(libscanmem_path)
self.backend.send_command("option noptrace 1")
self.memory_view_window = MemoryViewWindowForm(self)
self.about_widget = AboutWidgetForm()
self.await_exit_thread = AwaitProcessExit()
self.await_exit_thread.process_exited.connect(self.on_inferior_exit)
self.await_exit_thread.start()
self.check_status_thread = CheckInferiorStatus()
self.check_status_thread.process_stopped.connect(self.on_status_stopped)
self.check_status_thread.process_running.connect(self.on_status_running)
self.check_status_thread.process_stopped.connect(self.memory_view_window.process_stopped)
self.check_status_thread.process_running.connect(self.memory_view_window.process_running)
self.check_status_thread.start()
self.update_address_table_thread = Worker(self.update_address_table_loop)
global threadpool; threadpool.start(self.update_address_table_thread)
self.shortcut_open_file = QShortcut(QKeySequence("Ctrl+O"), self)
self.shortcut_open_file.activated.connect(self.pushButton_Open_clicked)
GuiUtils.append_shortcut_to_tooltip(self.pushButton_Open, self.shortcut_open_file)
self.shortcut_save_file = QShortcut(QKeySequence("Ctrl+S"), self)
self.shortcut_save_file.activated.connect(self.pushButton_Save_clicked)
GuiUtils.append_shortcut_to_tooltip(self.pushButton_Save, self.shortcut_save_file)
# Saving the original function because super() doesn't work when we override functions like this
self.treeWidget_AddressTable.keyPressEvent_original = self.treeWidget_AddressTable.keyPressEvent
self.treeWidget_AddressTable.keyPressEvent = self.treeWidget_AddressTable_key_press_event
self.treeWidget_AddressTable.contextMenuEvent = self.treeWidget_AddressTable_context_menu_event
self.pushButton_AttachProcess.clicked.connect(self.pushButton_AttachProcess_clicked)
self.pushButton_Open.clicked.connect(self.pushButton_Open_clicked)
self.pushButton_Save.clicked.connect(self.pushButton_Save_clicked)
self.pushButton_NewFirstScan.clicked.connect(self.pushButton_NewFirstScan_clicked)
self.pushButton_NextScan.clicked.connect(self.pushButton_NextScan_clicked)
self.pushButton_NextScan.setEnabled(False)
self.checkBox_Hex.stateChanged.connect(self.checkBox_Hex_stateChanged)
self.comboBox_ValueType.currentTextChanged.connect(self.comboBox_ValueType_textChanged)
self.lineEdit_Scan.setValidator(QRegExpValidator(QRegExp("-?[0-9]*"), parent=self.lineEdit_Scan))
self.comboBox_ScanType.addItems(
["Exact Match", "Increased", "Decreased", "Less Than", "More than", "Changed", "Unchanged",
"Unknown Initial"])
self.pushButton_Settings.clicked.connect(self.pushButton_Settings_clicked)
self.pushButton_Console.clicked.connect(self.pushButton_Console_clicked)
self.pushButton_Wiki.clicked.connect(self.pushButton_Wiki_clicked)
self.pushButton_About.clicked.connect(self.pushButton_About_clicked)
self.pushButton_AddAddressManually.clicked.connect(self.pushButton_AddAddressManually_clicked)
self.pushButton_MemoryView.clicked.connect(self.pushButton_MemoryView_clicked)
self.pushButton_RefreshAdressTable.clicked.connect(self.update_address_table)
self.pushButton_CopyToAddressTable.clicked.connect(self.copy_to_address_table)
self.pushButton_CleanAddressTable.clicked.connect(self.delete_address_table_contents)
self.tableWidget_valuesearchtable.cellDoubleClicked.connect(
self.tableWidget_valuesearchtable_cell_double_clicked)
self.treeWidget_AddressTable.itemClicked.connect(self.treeWidget_AddressTable_item_clicked)
self.treeWidget_AddressTable.itemDoubleClicked.connect(self.treeWidget_AddressTable_item_double_clicked)
self.treeWidget_AddressTable.expanded.connect(self.resize_address_table)
self.treeWidget_AddressTable.collapsed.connect(self.resize_address_table)
icons_directory = GuiUtils.get_icons_directory()
current_dir = SysUtils.get_current_script_directory()
self.pushButton_AttachProcess.setIcon(QIcon(QPixmap(icons_directory + "/monitor.png")))
self.pushButton_Open.setIcon(QIcon(QPixmap(icons_directory + "/folder.png")))
self.pushButton_Save.setIcon(QIcon(QPixmap(icons_directory + "/disk.png")))
self.pushButton_Settings.setIcon(QIcon(QPixmap(icons_directory + "/wrench.png")))
self.pushButton_CopyToAddressTable.setIcon(QIcon(QPixmap(icons_directory + "/arrow_down.png")))
self.pushButton_CleanAddressTable.setIcon(QIcon(QPixmap(icons_directory + "/bin_closed.png")))
self.pushButton_RefreshAdressTable.setIcon(QIcon(QPixmap(icons_directory + "/table_refresh.png")))
self.pushButton_Console.setIcon(QIcon(QPixmap(icons_directory + "/application_xp_terminal.png")))
self.pushButton_Wiki.setIcon(QIcon(QPixmap(icons_directory + "/book_open.png")))
self.pushButton_About.setIcon(QIcon(QPixmap(icons_directory + "/information.png")))
self.auto_attach()
def set_default_settings(self):
self.settings.beginGroup("General")
self.settings.setValue("auto_update_address_table", True)
self.settings.setValue("address_table_update_interval", 500)
self.settings.setValue("freeze_interval", 100)
self.settings.setValue("show_messagebox_on_exception", True)
self.settings.setValue("show_messagebox_on_toggle_attach", True)
self.settings.setValue("gdb_output_mode", type_defs.gdb_output_mode(True, True, True))
self.settings.setValue("auto_attach_list", "")
self.settings.setValue("logo_path", "ozgurozbek/pince_small_transparent.png")
self.settings.setValue("auto_attach_regex", False)
self.settings.endGroup()
self.settings.beginGroup("Hotkeys")
for hotkey in Hotkeys.get_hotkeys():
self.settings.setValue(hotkey.name, hotkey.default)
self.settings.endGroup()
self.settings.beginGroup("CodeInjection")
self.settings.setValue("code_injection_method", type_defs.INJECTION_METHOD.SIMPLE_DLOPEN_CALL)
self.settings.endGroup()
self.settings.beginGroup("Disassemble")
self.settings.setValue("bring_disassemble_to_front", False)
self.settings.setValue("instructions_per_scroll", 2)
self.settings.endGroup()
self.settings.beginGroup("Debug")
self.settings.setValue("gdb_path", type_defs.PATHS.GDB_PATH)
self.settings.setValue("gdb_logging", False)
self.settings.endGroup()
self.settings.beginGroup("Misc")
self.settings.setValue("version", current_settings_version)
self.settings.endGroup()
self.apply_settings()
def apply_settings(self):
global update_table
global table_update_interval
global show_messagebox_on_exception
global show_messagebox_on_toggle_attach
global gdb_output_mode
global auto_attach_list
global logo_path
global auto_attach_regex
global code_injection_method
global bring_disassemble_to_front
global instructions_per_scroll
global gdb_path
global gdb_logging
global FreezeInterval
update_table = self.settings.value("General/auto_update_address_table", type=bool)
table_update_interval = self.settings.value("General/address_table_update_interval", type=int)
FreezeInterval = self.settings.value("General/freeze_interval", type=int)
show_messagebox_on_exception = self.settings.value("General/show_messagebox_on_exception", type=bool)
show_messagebox_on_toggle_attach = self.settings.value("General/show_messagebox_on_toggle_attach", type=bool)
gdb_output_mode = self.settings.value("General/gdb_output_mode", type=tuple)
auto_attach_list = self.settings.value("General/auto_attach_list", type=str)
logo_path = self.settings.value("General/logo_path", type=str)
app.setWindowIcon(QIcon(os.path.join(SysUtils.get_logo_directory(), logo_path)))
auto_attach_regex = self.settings.value("General/auto_attach_regex", type=bool)
GDB_Engine.set_gdb_output_mode(gdb_output_mode)
for hotkey in Hotkeys.get_hotkeys():
hotkey.value = self.settings.value("Hotkeys/" + hotkey.name)
self.hotkey_to_shortcut[hotkey.name].setKey(QKeySequence(hotkey.value))
try:
self.memory_view_window.set_dynamic_debug_hotkeys()
except AttributeError:
pass
code_injection_method = self.settings.value("CodeInjection/code_injection_method", type=int)
bring_disassemble_to_front = self.settings.value("Disassemble/bring_disassemble_to_front", type=bool)
instructions_per_scroll = self.settings.value("Disassemble/instructions_per_scroll", type=int)
gdb_path = self.settings.value("Debug/gdb_path", type=str)
gdb_logging = self.settings.value("Debug/gdb_logging", type=bool)
if GDB_Engine.gdb_initialized:
GDB_Engine.set_logging(gdb_logging)
# Check if any process should be attached to automatically
# Patterns at former positions have higher priority if regex is off
def auto_attach(self):
if not auto_attach_list:
return
if auto_attach_regex:
try:
compiled_re = re.compile(auto_attach_list)
except:
print("Auto-attach failed: " + auto_attach_list + " isn't a valid regex")
return
for process in SysUtils.iterate_processes():
try:
name = process.name()
except psutil.NoSuchProcess:
continue
if compiled_re.search(name):
self.attach_to_pid(process.pid)
return
else:
for target in auto_attach_list.split(";"):
for process in SysUtils.iterate_processes():
try:
name = process.name()
except psutil.NoSuchProcess:
continue
if name.find(target) != -1:
self.attach_to_pid(process.pid)
return
def pause_hotkey_pressed(self):
GDB_Engine.interrupt_inferior(type_defs.STOP_REASON.PAUSE)
def break_hotkey_pressed(self):
GDB_Engine.interrupt_inferior()
def continue_hotkey_pressed(self):
GDB_Engine.continue_inferior()
def toggle_attach_hotkey_pressed(self):
result = GDB_Engine.toggle_attach()
if not result:
dialog_text = "Unable to toggle attach"
elif result == type_defs.TOGGLE_ATTACH.DETACHED:
self.on_status_detached()
dialog_text = "GDB is detached from the process"
else:
dialog_text = "GDB is attached back to the process"
if show_messagebox_on_toggle_attach:
dialog = InputDialogForm(item_list=[(
dialog_text + "\n\nGo to Settings->General to disable this dialog",)], buttons=[QDialogButtonBox.Ok])
dialog.exec_()
def treeWidget_AddressTable_context_menu_event(self, event):
current_row = GuiUtils.get_current_item(self.treeWidget_AddressTable)
menu = QMenu()
edit_menu = menu.addMenu("Edit")
edit_desc = edit_menu.addAction("Description[Ctrl+Enter]")
edit_address = edit_menu.addAction("Address[Ctrl+Alt+Enter]")
edit_type = edit_menu.addAction("Type[Alt+Enter]")
edit_value = edit_menu.addAction("Value[Enter]")
# TODO: Implement toggling of records
toggle_record = menu.addAction("Toggle selected records[Space] (not implemented yet)")
menu.addSeparator()
browse_region = menu.addAction("Browse this memory region[Ctrl+B]")
disassemble = menu.addAction("Disassemble this address[Ctrl+D]")
menu.addSeparator()
cut_record = menu.addAction("Cut selected records[Ctrl+X]")
copy_record = menu.addAction("Copy selected records[Ctrl+C]")
cut_record_recursively = menu.addAction("Cut selected records (recursive)[X]")
copy_record_recursively = menu.addAction("Copy selected records (recursive)[C]")
paste_record_before = menu.addAction("Paste selected records before[Ctrl+V]")
paste_record_after = menu.addAction("Paste selected records after[V]")
paste_record_inside = menu.addAction("Paste selected records inside[I]")
delete_record = menu.addAction("Delete selected records[Del]")
menu.addSeparator()
what_writes = menu.addAction("Find out what writes to this address")
what_reads = menu.addAction("Find out what reads this address")
what_accesses = menu.addAction("Find out what accesses this address")
if current_row is None:
deletion_list = [edit_menu.menuAction(), toggle_record, browse_region, disassemble, what_writes, what_reads,
what_accesses]
GuiUtils.delete_menu_entries(menu, deletion_list)
font_size = self.treeWidget_AddressTable.font().pointSize()
menu.setStyleSheet("font-size: " + str(font_size) + "pt;")
action = menu.exec_(event.globalPos())
actions = {
edit_desc: self.treeWidget_AddressTable_edit_desc,
edit_address: self.treeWidget_AddressTable_edit_address,
edit_type: self.treeWidget_AddressTable_edit_type,
edit_value: self.treeWidget_AddressTable_edit_value,
toggle_record: self.toggle_selected_records,
browse_region: self.browse_region_for_selected_row,
disassemble: self.disassemble_selected_row,
cut_record: self.cut_selected_records,
copy_record: self.copy_selected_records,
cut_record_recursively: self.cut_selected_records_recursively,
copy_record_recursively: self.copy_selected_records_recursively,
paste_record_before: lambda: self.paste_records(insert_after=False),
paste_record_after: lambda: self.paste_records(insert_after=True),
paste_record_inside: lambda: self.paste_records(insert_inside=True),
delete_record: self.delete_selected_records,
what_writes: lambda: self.exec_track_watchpoint_widget(type_defs.WATCHPOINT_TYPE.WRITE_ONLY),
what_reads: lambda: self.exec_track_watchpoint_widget(type_defs.WATCHPOINT_TYPE.READ_ONLY),
what_accesses: lambda: self.exec_track_watchpoint_widget(type_defs.WATCHPOINT_TYPE.BOTH)
}
try:
actions[action]()
except KeyError:
pass
def exec_track_watchpoint_widget(self, watchpoint_type):
selected_row = GuiUtils.get_current_item(self.treeWidget_AddressTable)
if not selected_row:
return
address = selected_row.text(ADDR_COL)
value_type_text = selected_row.text(TYPE_COL)
index, length, zero_terminate, byte_len = GuiUtils.text_to_valuetype(value_type_text)
if byte_len == -1:
value_text = selected_row.text(VALUE_COL)
encoding, option = type_defs.string_index_to_encoding_dict[index]
byte_len = len(value_text.encode(encoding, option))
TrackWatchpointWidgetForm(address, byte_len, watchpoint_type, self).show()
def browse_region_for_selected_row(self):
row = GuiUtils.get_current_item(self.treeWidget_AddressTable)
if row:
self.memory_view_window.hex_dump_address(int(row.text(ADDR_COL), 16))
self.memory_view_window.show()
self.memory_view_window.activateWindow()
def disassemble_selected_row(self):
row = GuiUtils.get_current_item(self.treeWidget_AddressTable)
if row:
if self.memory_view_window.disassemble_expression(row.text(ADDR_COL), append_to_travel_history=True):
self.memory_view_window.show()
self.memory_view_window.activateWindow()
def toggle_selected_records(self):
row = GuiUtils.get_current_item(self.treeWidget_AddressTable)
if row:
check_state = row.checkState(FROZEN_COL)
new_check_state = Qt.Checked if check_state == Qt.Unchecked else Qt.Unchecked
for row in self.treeWidget_AddressTable.selectedItems():
row.setCheckState(FROZEN_COL, new_check_state)
def cut_selected_records(self):
# Flat cut, does not preserve structure
self.copy_selected_records()
self.delete_selected_records()
def copy_selected_records(self):
# Flat copy, does not preserve structure
app.clipboard().setText(repr([self.read_address_table_entries(selected_row) + ((),) for selected_row in
self.treeWidget_AddressTable.selectedItems()]))
# each element in the list has no children
def cut_selected_records_recursively(self):
self.copy_selected_records_recursively()
self.delete_selected_records()
def copy_selected_records_recursively(self):
# Recursive copy
items = self.treeWidget_AddressTable.selectedItems()
def index_of(item):
"""Returns the index used to access the given QTreeWidgetItem
as a list of ints."""
result = []
while True:
parent = item.parent()
if parent:
result.append(parent.indexOfChild(item))
item = parent
else:
result.append(item.treeWidget().indexOfTopLevelItem(item))
return result[::-1]
# First, order the items by their indices in the tree widget.
# Store the indices for later usage.
index_items = [(index_of(item), item) for item in items]
index_items.sort(key=lambda x: x[0]) # sort by index
# Now filter any selected items that is a descendant of another selected items.
items = []
last_index = [-1] # any invalid list of indices are fine
for index, item in index_items:
if index[:len(last_index)] == last_index:
continue # this item is a descendant of the last item
items.append(item)
last_index = index
app.clipboard().setText(repr([self.read_address_table_recursively(item) for item in items]))
def insert_records(self, records, parent_row, insert_index):
# parent_row should be a QTreeWidgetItem in treeWidget_AddressTable
# records should be an iterable of valid output of read_address_table_recursively
assert isinstance(parent_row, QTreeWidgetItem)
rows = []
for rec in records:
row = QTreeWidgetItem()
row.setCheckState(FROZEN_COL, Qt.Unchecked)
self.change_address_table_entries(row, *rec[:-1])
self.insert_records(rec[-1], row, 0)
rows.append(row)
parent_row.insertChildren(insert_index, rows)
def paste_records(self, insert_after=None, insert_inside=False):
try:
records = ast.literal_eval(app.clipboard().text())
except (SyntaxError, ValueError):
QMessageBox.information(self, "Error", "Invalid clipboard content")
return
insert_row = GuiUtils.get_current_item(self.treeWidget_AddressTable)
root = self.treeWidget_AddressTable.invisibleRootItem()
if not insert_row: # this is common when the treeWidget_AddressTable is empty
self.insert_records(records, root, self.treeWidget_AddressTable.topLevelItemCount())
elif insert_inside:
self.insert_records(records, insert_row, 0)
else:
parent = insert_row.parent() or root
self.insert_records(records, parent, parent.indexOfChild(insert_row) + insert_after)
self.update_address_table()
def check_if_address_exists(self, address):
root = self.treeWidget_AddressTable.invisibleRootItem()
child_count = root.childCount()
for i in range(child_count):
item = root.child(i)
if item.text(ADDR_COL) == address:
return True
return False
def delete_selected_records(self):
root = self.treeWidget_AddressTable.invisibleRootItem()
for item in self.treeWidget_AddressTable.selectedItems():
(item.parent() or root).removeChild(item)
if not self.check_if_address_exists(item.text(ADDR_COL)):
del FreezeVars[item.text(ADDR_COL)]
def treeWidget_AddressTable_key_press_event(self, event):
actions = type_defs.KeyboardModifiersTupleDict([
((Qt.NoModifier, Qt.Key_Delete), self.delete_selected_records),
((Qt.ControlModifier, Qt.Key_B), self.browse_region_for_selected_row),
((Qt.ControlModifier, Qt.Key_D), self.disassemble_selected_row),
((Qt.NoModifier, Qt.Key_R), self.update_address_table),
((Qt.NoModifier, Qt.Key_Space), self.toggle_selected_records),
((Qt.ControlModifier, Qt.Key_X), self.cut_selected_records),
((Qt.ControlModifier, Qt.Key_C), self.copy_selected_records),
((Qt.NoModifier, Qt.Key_X), self.cut_selected_records_recursively),
((Qt.NoModifier, Qt.Key_C), self.copy_selected_records_recursively),
((Qt.ControlModifier, Qt.Key_V), lambda: self.paste_records(insert_after=False)),
((Qt.NoModifier, Qt.Key_V), lambda: self.paste_records(insert_after=True)),
((Qt.NoModifier, Qt.Key_I), lambda: self.paste_records(insert_inside=True)),
((Qt.NoModifier, Qt.Key_Return), self.treeWidget_AddressTable_edit_value),
((Qt.ControlModifier, Qt.Key_Return), self.treeWidget_AddressTable_edit_desc),
((Qt.ControlModifier | Qt.AltModifier, Qt.Key_Return), self.treeWidget_AddressTable_edit_address),
((Qt.AltModifier, Qt.Key_Return), self.treeWidget_AddressTable_edit_type)
])
try:
actions[event.modifiers(), event.key()]()
except KeyError:
self.treeWidget_AddressTable.keyPressEvent_original(event)
def update_address_table(self):
if GDB_Engine.currentpid == -1 or self.treeWidget_AddressTable.topLevelItemCount() == 0:
return
it = QTreeWidgetItemIterator(self.treeWidget_AddressTable)
table_contents = []
address_expr_list = []
value_type_list = []
rows = []
while True:
row = it.value()
if not row:
break
it += 1
address_expr_list.append(row.data(ADDR_COL, ADDR_EXPR_ROLE))
value_type_list.append(row.text(TYPE_COL))
rows.append(row)
try:
address_list = [item.address for item in GDB_Engine.examine_expressions(address_expr_list)]
except type_defs.InferiorRunningException:
address_list = address_expr_list
for address, value_type in zip(address_list, value_type_list):
index, length, zero_terminate, byte_len = GuiUtils.text_to_valuetype(value_type)
table_contents.append((address, index, length, zero_terminate))
new_table_contents = GDB_Engine.read_memory_multiple(table_contents)
for row, address, address_expr, value in zip(rows, address_list, address_expr_list, new_table_contents):
row.setText(ADDR_COL, address or address_expr)
row.setText(VALUE_COL, "" if value is None else str(value))
def resize_address_table(self):
self.treeWidget_AddressTable.resizeColumnToContents(FROZEN_COL)
# gets the information from the dialog then adds it to addresstable
def pushButton_AddAddressManually_clicked(self):
manual_address_dialog = ManualAddressDialogForm()
if manual_address_dialog.exec_():
description, address_expr, address_type, length, zero_terminate = manual_address_dialog.get_values()
self.add_entry_to_addresstable(description, address_expr, address_type, length, zero_terminate)
def pushButton_MemoryView_clicked(self):
self.memory_view_window.showMaximized()
self.memory_view_window.activateWindow()
def pushButton_Wiki_clicked(self):
SysUtils.execute_shell_command_as_user('python3 -m webbrowser "https://github.com/korcankaraokcu/PINCE/wiki"')
def pushButton_About_clicked(self):
self.about_widget.show()
self.about_widget.activateWindow()
def pushButton_Settings_clicked(self):
settings_dialog = SettingsDialogForm(self.set_default_settings)
if settings_dialog.exec_():
self.apply_settings()
def pushButton_Console_clicked(self):
console_widget = ConsoleWidgetForm()
console_widget.showMaximized()
def checkBox_Hex_stateChanged(self, state):
if state == Qt.Checked:
# allows only things that are hex, can also start with 0x
self.lineEdit_Scan.setValidator(QRegExpValidator(QRegExp("(0x)?[A-Fa-f0-9]*$"), parent=self.lineEdit_Scan))
else:
# sets it back to integers only
self.lineEdit_Scan.setValidator(QRegExpValidator(QRegExp("-?[0-9]*"), parent=self.lineEdit_Scan))
# TODO add a damn keybind for this...
def pushButton_NewFirstScan_clicked(self):
if self.pushButton_NextScan.isEnabled():
self.backend.send_command("reset")
self.tableWidget_valuesearchtable.setRowCount(0)
self.comboBox_ValueType.setEnabled(True)
self.pushButton_NextScan.setEnabled(False)
self.progressBar.setValue(0)
else:
print(self.lineEdit_Scan.text())
self.comboBox_ValueType.setEnabled(False)
self.pushButton_NextScan.setEnabled(True)
self.pushButton_NextScan_clicked() # makes code a little simpler to just implement everything in nextscan
return
# :doc:
# adds things like 0x when searching for etc, basically just makes the line valid for scanmem
# this should cover most things, more things might be added later if need be
def validate_search(self, search_for):
current_index = self.comboBox_ScanType.currentIndex()
if current_index != 0:
index_to_symbol = {
1: "+", # increased
2: "-", # decreased
3: "<", # less than
4: ">", # more than
5: "!=", # changed
6: "=", # unchanged
7: "snapshot" # unknown initial
}
return index_to_symbol[current_index]
# none of theese should be possible to be true at the same time
# TODO refactor later to use current index, and compare to type_defs constant
if self.comboBox_ValueType.currentText() == "float":
search_for.replace(".",
",") # this is odd, since when searching for floats from command line it uses `.` and not `,`
elif self.comboBox_ValueType.currentText() == "string":
search_for = "\" " + search_for
elif self.checkBox_Hex.isChecked():
if not search_for.startswith("0x"):
search_for = "0x" + search_for
return search_for
def pushButton_NextScan_clicked(self):
global ProgressRun
line_edit_text = self.lineEdit_Scan.text()
search_for = self.validate_search(line_edit_text)
#ProgressBar
global threadpool; threadpool.start(Worker(self.update_progress_bar))
# TODO add some validation for the search command
self.backend.send_command(search_for)
matches = self.backend.matches()
ProgressRun = 0
self.label_MatchCount.setText("Match count: {}".format(self.backend.get_match_count()))
self.tableWidget_valuesearchtable.setRowCount(0)
for n, address, offset, region_type, value, t in matches:
n = int(n)
self.tableWidget_valuesearchtable.insertRow(
self.tableWidget_valuesearchtable.rowCount())
self.tableWidget_valuesearchtable.setItem(n, 0, QTableWidgetItem("0x" + address))
self.tableWidget_valuesearchtable.setItem(n, 1, QTableWidgetItem(value))
self.tableWidget_valuesearchtable.setItem(n, 2, QTableWidgetItem(value))
return
@GDB_Engine.execute_with_temporary_interruption
def tableWidget_valuesearchtable_cell_double_clicked(self, row, col):
addr = self.tableWidget_valuesearchtable.item(row, 0).text()
self.add_entry_to_addresstable("", addr, self.comboBox_ValueType.currentIndex())
def comboBox_ValueType_textChanged(self, text):
# used for making our types in the combo box into what scanmem uses
PINCE_TYPES_TO_SCANMEM = {
"Byte": "int8",
"2 Bytes": "int16",
"4 Bytes": "int32",
"8 Bytes": "int64",
"Float": "float32",
"Double": "float64",
"String": "string",
"Array of bytes": "bytearray"
}
validator_map = {
"int": QRegExpValidator(QRegExp("-?[0-9]*"), parent=self.lineEdit_Scan), # integers
"float": QRegExpValidator(QRegExp("-?[0-9]+[.,]?[0-9]*")),
# floats, should work fine with the small amount of testing I did
"bytearray": QRegExpValidator(QRegExp("^(([A-Fa-f0-9]{2} +)+)$"), parent=self.lineEdit_Scan),
# array of bytes
"string": None
}
scanmem_type = PINCE_TYPES_TO_SCANMEM[text]
validator_str = scanmem_type # used to get the correct validator
# TODO this can probably be made to look nicer, though it doesn't really matter
if "int" in validator_str:
validator_str = "int"
self.checkBox_Hex.setEnabled(True)
else:
self.checkBox_Hex.setChecked(False)
self.checkBox_Hex.setEnabled(False)
if "float" in validator_str:
validator_str = "float"
self.lineEdit_Scan.setValidator(validator_map[validator_str])
self.backend.send_command("option scan_data_type {}".format(scanmem_type))
# according to scanmem instructions you should always do `reset` after changing type
self.backend.send_command("reset")
# shows the process select window
def pushButton_AttachProcess_clicked(self):
self.processwindow = ProcessForm(self)
self.processwindow.show()
def pushButton_Open_clicked(self):
pct_file_path = SysUtils.get_user_path(type_defs.USER_PATHS.CHEAT_TABLES_PATH)
file_paths = QFileDialog.getOpenFileNames(self, "Open PCT file(s)", pct_file_path,
"PINCE Cheat Table (*.pct);;All files (*)")[0]
if not file_paths:
return
if self.treeWidget_AddressTable.topLevelItemCount() > 0:
if InputDialogForm(item_list=[("Clear existing address table?",)]).exec_():
self.treeWidget_AddressTable.clear()
for file_path in file_paths:
content = SysUtils.load_file(file_path)
if content is None:
QMessageBox.information(self, "Error", "File " + file_path + " does not exist, " +
"is inaccessible or contains invalid content. Terminating...")
break
self.insert_records(content, self.treeWidget_AddressTable.invisibleRootItem(),
self.treeWidget_AddressTable.topLevelItemCount())
def pushButton_Save_clicked(self):
pct_file_path = SysUtils.get_user_path(type_defs.USER_PATHS.CHEAT_TABLES_PATH)
file_path = QFileDialog.getSaveFileName(self, "Save PCT file", pct_file_path,
"PINCE Cheat Table (*.pct);;All files (*)")[0]
if not file_path:
return
content = [self.read_address_table_recursively(self.treeWidget_AddressTable.topLevelItem(i))
for i in range(self.treeWidget_AddressTable.topLevelItemCount())]
file_path = SysUtils.append_file_extension(file_path, "pct")
if not SysUtils.save_file(content, file_path):
QMessageBox.information(self, "Error", "Cannot save to file")
# Returns: a bool value indicates whether the operation succeeded.
def attach_to_pid(self, pid):