forked from korcankaraokcu/PINCE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PINCE.py
executable file
·5947 lines (5344 loc) · 287 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/>.
"""
import gi
# This fixes GTK version mismatch issues and crashes on gnome
# See #153 and #159 for more information
# This line can be deleted when GTK 4.0 properly runs on all supported systems
gi.require_version('Gtk', '3.0')
from typing import Final
from PyQt6.QtGui import QIcon, QMovie, QPixmap, QCursor, QKeySequence, QColor, QTextCharFormat, QBrush, QTextCursor, \
QKeyEvent, QRegularExpressionValidator, QShortcut, QColorConstants
from PyQt6.QtWidgets import QApplication, QMainWindow, QTableWidgetItem, QMessageBox, QDialog, QWidget, \
QKeySequenceEdit, QTabWidget, QMenu, QFileDialog, QAbstractItemView, QTreeWidgetItem, \
QTreeWidgetItemIterator, QCompleter, QLabel, QLineEdit, QComboBox, QDialogButtonBox, QCheckBox, QHBoxLayout, \
QPushButton, QFrame
from PyQt6.QtCore import Qt, QThread, pyqtSignal, QSize, QByteArray, QSettings, QEvent, QKeyCombination, \
QItemSelectionModel, QTimer, QModelIndex, QStringListModel, QRegularExpression, QRunnable, QThreadPool, pyqtSlot
from time import sleep, time
import os, sys, traceback, signal, re, copy, io, queue, collections, ast, 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.TrackSelectorDialog import Ui_Dialog as TrackSelectorDialog
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.HandleSignalsDialog import Ui_Dialog as HandleSignalsDialog
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.EditInstructionDialog import Ui_Dialog as EditInstructionDialog
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.RestoreInstructionsWidget import Ui_Form as RestoreInstructionsWidget
from GUI.CustomAbstractTableModels.HexModel import QHexModel
from GUI.CustomAbstractTableModels.AsciiModel import QAsciiModel
from GUI.CustomValidators.HexValidator import QHexValidator
from keyboard import add_hotkey, remove_hotkey
from operator import add as opAdd, sub as opSub
instances = [] # Holds temporary instances that will be deleted later on
# settings
current_settings_version = "master-22" # 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
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="", func=None, custom="", handle=None):
self.name = name
self.desc = desc
self.default = default
self.func = func
self.custom = custom
if default == "" or func is None:
self.handle = handle
else:
self.handle = add_hotkey(default, func)
def change_key(self, custom):
if self.handle is not None:
remove_hotkey(self.handle)
self.handle = None
self.custom = custom
if custom == '':
return
self.handle = add_hotkey(custom.lower(), self.func)
def change_func(self, func):
self.func = func
if self.handle is not None:
remove_hotkey(self.handle)
if self.custom != "":
self.handle = add_hotkey(self.custom, func)
elif self.default != "":
self.handle = add_hotkey(self.default, func)
def get_active_key(self):
if self.custom == "":
return self.default
return self.custom
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")
exact_scan_hotkey = Hotkey("exact_scan_hotkey", "Next Scan - Exact", "")
increased_scan_hotkey = Hotkey("increased_scan_hotkey", "Next Scan - Increased", "")
decreased_scan_hotkey = Hotkey("decreased_scan_hotkey", "Next Scan - Decreased", "")
changed_scan_hotkey = Hotkey("changed_scan_hotkey", "Next Scan - Changed", "")
unchanged_scan_hotkey = Hotkey("unchanged_scan_hotkey", "Next Scan - Unchanged", "")
@staticmethod
def get_hotkeys():
return Hotkeys.pause_hotkey, Hotkeys.break_hotkey, Hotkeys.continue_hotkey, Hotkeys.toggle_attach_hotkey, \
Hotkeys.exact_scan_hotkey, Hotkeys.increased_scan_hotkey, Hotkeys.decreased_scan_hotkey, \
Hotkeys.changed_scan_hotkey, Hotkeys.unchanged_scan_hotkey
code_injection_method = int
bring_disassemble_to_front = bool
instructions_per_scroll = int
gdb_path = str
gdb_logging = bool
ignored_signals = str
signal_list = ["SIGUSR1", "SIGPWR", "SIGSEGV"]
# represents the index of columns in instructions restore table
INSTR_ADDR_COL = 0
INSTR_AOB_COL = 1
INSTR_NAME_COL = 2
# 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 = QColorConstants.Blue
BOOKMARK_COLOUR = QColorConstants.Cyan
DEFAULT_COLOUR = QColorConstants.White
BREAKPOINT_COLOUR = QColorConstants.Red
REF_COLOUR = QColorConstants.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
# represents the index of columns in search results table
SEARCH_TABLE_ADDRESS_COL = 0
SEARCH_TABLE_VALUE_COL = 1
SEARCH_TABLE_PREVIOUS_COL = 2
# 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_OFFSET_COL = 2
MEMORY_REGIONS_PATH_COL = 3
# 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
Exiting = 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.get_active_key() + " to stop process" +
"\n\nGo to Settings->General to disable this dialog",)],
buttons=[QDialogButtonBox.StandardButton.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:
self.process_stopped.emit()
elif GDB_Engine.inferior_status == type_defs.INFERIOR_STATUS.INFERIOR_RUNNING:
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):
"""
Declare regular expressions for hexadecimal and decimal input
to be used in checkBox_Hex_stateChanged (or anywhere else that
they are needed).
"""
self.qRegExp_hex: Final[QRegularExpression] = QRegularExpression("(0x)?[A-Fa-f0-9]*$")
self.qRegExp_dec: Final[QRegularExpression] = QRegularExpression("-?[0-9]*")
super().__init__()
self.setupUi(self)
self.hotkey_to_shortcut = {}
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,
Hotkeys.exact_scan_hotkey: lambda: self.nextscan_hotkey_pressed(type_defs.SCAN_TYPE.EXACT),
Hotkeys.increased_scan_hotkey: lambda: self.nextscan_hotkey_pressed(type_defs.SCAN_TYPE.INCREASED),
Hotkeys.decreased_scan_hotkey: lambda: self.nextscan_hotkey_pressed(type_defs.SCAN_TYPE.DECREASED),
Hotkeys.changed_scan_hotkey: lambda: self.nextscan_hotkey_pressed(type_defs.SCAN_TYPE.CHANGED),
Hotkeys.unchanged_scan_hotkey: lambda: self.nextscan_hotkey_pressed(type_defs.SCAN_TYPE.UNCHANGED)
}
for hotkey, func in hotkey_to_func.items():
hotkey.change_func(func)
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)
self.tableWidget_valuesearchtable.setColumnWidth(SEARCH_TABLE_ADDRESS_COL, 110)
self.tableWidget_valuesearchtable.setColumnWidth(SEARCH_TABLE_VALUE_COL, 80)
app.setOrganizationName("PINCE")
app.setOrganizationDomain("github.com/korcankaraokcu/PINCE")
app.setApplicationName("PINCE")
QSettings.setPath(QSettings.Format.NativeFormat, QSettings.Scope.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)
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.StandardButton.Ok]).exec()
else:
self.apply_after_init()
# 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)
self.update_search_table_thread = Worker(self.update_search_table_loop)
self.freeze_thread = Worker(self.freeze_loop)
global threadpool
threadpool.start(self.update_address_table_thread)
threadpool.start(self.update_search_table_thread)
threadpool.start(self.freeze_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.scan_mode = type_defs.SCAN_MODE.NEW
self.pushButton_NewFirstScan_clicked()
self.comboBox_ScanScope_init()
self.comboBox_ValueType_init()
self.checkBox_Hex.stateChanged.connect(self.checkBox_Hex_stateChanged)
self.comboBox_ValueType.currentIndexChanged.connect(self.comboBox_ValueType_current_index_changed)
self.lineEdit_Scan.setValidator(
QRegularExpressionValidator(QRegularExpression("-?[0-9]*"), parent=self.lineEdit_Scan))
self.lineEdit_Scan2.setValidator(
QRegularExpressionValidator(QRegularExpression("-?[0-9]*"), parent=self.lineEdit_Scan2))
self.comboBox_ScanType.currentIndexChanged.connect(self.comboBox_ScanType_current_index_changed)
self.comboBox_ScanType_current_index_changed()
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.pushButton_NextScan.setEnabled(False)
self.pushButton_UndoScan.setEnabled(False)
self.flashAttachButton = True
self.flashAttachButtonTimer = QTimer()
self.flashAttachButtonTimer.timeout.connect(self.flash_attach_button)
self.flashAttachButton_gradiantState = 0
self.flashAttachButtonTimer.start(100)
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("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.setValue("ignored_signals", "1,1,0")
self.settings.endGroup()
self.settings.beginGroup("Misc")
self.settings.setValue("version", current_settings_version)
self.settings.endGroup()
self.apply_settings()
@GDB_Engine.execute_with_temporary_interruption
def apply_after_init(self):
global gdb_logging
global ignored_signals
gdb_logging = self.settings.value("Debug/gdb_logging", type=bool)
ignored_signals = self.settings.value("Debug/ignored_signals", type=str)
GDB_Engine.set_logging(gdb_logging)
for index, ignore_status in enumerate(ignored_signals.split(",")):
if ignore_status == "1":
GDB_Engine.ignore_signal(signal_list[index])
else:
GDB_Engine.unignore_signal(signal_list[index])
def apply_settings(self):
global update_table
global table_update_interval
global show_messagebox_on_exception
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 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)
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.change_key(self.settings.value("Hotkeys/" + hotkey.name))
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)
if GDB_Engine.gdb_initialized:
self.apply_after_init()
# 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 pid, _, name in SysUtils.get_process_list():
if compiled_re.search(name):
self.attach_to_pid(pid)
self.flashAttachButton = False
return
else:
for target in auto_attach_list.split(";"):
for pid, _, name in SysUtils.get_process_list():
if name.find(target) != -1:
self.attach_to_pid(pid)
self.flashAttachButton = False
return
# Keyboard package has an issue with exceptions, any trigger function that throws an exception stops the event loop
# Writing a custom event loop instead of ignoring exceptions could work as well but honestly, this looks cleaner
# Keyboard package does not play well with Qt, do not use anything Qt related with hotkeys
# Instead of using Qt functions, try to use their signals to prevent crashes
@SysUtils.ignore_exceptions
def pause_hotkey_pressed(self):
GDB_Engine.interrupt_inferior(type_defs.STOP_REASON.PAUSE)
@SysUtils.ignore_exceptions
def break_hotkey_pressed(self):
GDB_Engine.interrupt_inferior()
@SysUtils.ignore_exceptions
def continue_hotkey_pressed(self):
GDB_Engine.continue_inferior()
@SysUtils.ignore_exceptions
def toggle_attach_hotkey_pressed(self):
result = GDB_Engine.toggle_attach()
if not result:
print("Unable to toggle attach")
elif result == type_defs.TOGGLE_ATTACH.DETACHED:
self.on_status_detached()
@SysUtils.ignore_exceptions
def nextscan_hotkey_pressed(self, index):
if self.scan_mode == type_defs.SCAN_MODE.NEW:
return
self.comboBox_ScanType.setCurrentIndex(index)
self.pushButton_NextScan.clicked.emit()
def treeWidget_AddressTable_context_menu_event(self, event):
if self.treeWidget_AddressTable.topLevelItemCount() == 0:
return
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]")
show_hex = menu.addAction("Show as hexadecimal")
show_dec = menu.addAction("Show as decimal")
show_unsigned = menu.addAction("Show as unsigned")
show_signed = menu.addAction("Show as signed")
toggle_record = menu.addAction("Toggle selected records[Space]")
freeze_menu = menu.addMenu("Freeze")
freeze_default = freeze_menu.addAction("Default")
freeze_inc = freeze_menu.addAction("Incremental")
freeze_dec = freeze_menu.addAction("Decremental")
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(), show_hex, show_dec, show_unsigned, show_signed, toggle_record,
freeze_menu.menuAction(), browse_region, disassemble, what_writes, what_reads,
what_accesses]
GuiUtils.delete_menu_entries(menu, deletion_list)
else:
value_type = current_row.data(TYPE_COL, Qt.ItemDataRole.UserRole)
if type_defs.VALUE_INDEX.is_integer(value_type.value_index):
if value_type.value_repr is type_defs.VALUE_REPR.HEX:
GuiUtils.delete_menu_entries(menu, [show_unsigned, show_signed, show_hex])
elif value_type.value_repr is type_defs.VALUE_REPR.UNSIGNED:
GuiUtils.delete_menu_entries(menu, [show_unsigned, show_dec])
elif value_type.value_repr is type_defs.VALUE_REPR.SIGNED:
GuiUtils.delete_menu_entries(menu, [show_signed, show_dec])
if current_row.checkState(FROZEN_COL) == Qt.CheckState.Unchecked:
GuiUtils.delete_menu_entries(menu, [freeze_menu.menuAction()])
else:
GuiUtils.delete_menu_entries(menu, [show_hex, show_dec, show_unsigned, show_signed,
freeze_menu.menuAction()])
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,
show_hex: lambda: self.treeWidget_AddressTable_change_repr(type_defs.VALUE_REPR.HEX),
show_dec: lambda: self.treeWidget_AddressTable_change_repr(type_defs.VALUE_REPR.UNSIGNED),
show_unsigned: lambda: self.treeWidget_AddressTable_change_repr(type_defs.VALUE_REPR.UNSIGNED),
show_signed: lambda: self.treeWidget_AddressTable_change_repr(type_defs.VALUE_REPR.SIGNED),
toggle_record: self.toggle_selected_records,
freeze_default: lambda: self.change_freeze_type(type_defs.FREEZE_TYPE.DEFAULT),
freeze_inc: lambda: self.change_freeze_type(type_defs.FREEZE_TYPE.INCREMENT),
freeze_dec: lambda: self.change_freeze_type(type_defs.FREEZE_TYPE.DECREMENT),
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
@GDB_Engine.execute_with_temporary_interruption
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).strip("P->") # @todo Maybe rework address grabbing logic in the future
address_data = selected_row.data(ADDR_COL, Qt.ItemDataRole.UserRole)
if isinstance(address_data, type_defs.PointerType):
selection_dialog = TrackSelectorDialogForm()
selection_dialog.exec()
if not selection_dialog.selection:
return
if selection_dialog.selection == "pointer":
address = address_data.get_base_address()
value_type = selected_row.data(TYPE_COL, Qt.ItemDataRole.UserRole)
if type_defs.VALUE_INDEX.is_string(value_type.value_index):
value_text = selected_row.text(VALUE_COL)
encoding, option = type_defs.string_index_to_encoding_dict[value_type.value_index]
byte_len = len(value_text.encode(encoding, option))
elif value_type.value_index == type_defs.VALUE_INDEX.INDEX_AOB:
byte_len = value_type.length
else:
byte_len = type_defs.index_to_valuetype_dict[value_type.value_index][0]
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).strip("P->"), 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).strip("P->"),
append_to_travel_history=True):
self.memory_view_window.show()
self.memory_view_window.activateWindow()
def change_freeze_type(self, freeze_type):
for row in self.treeWidget_AddressTable.selectedItems():
frozen = row.data(FROZEN_COL, Qt.ItemDataRole.UserRole)
frozen.freeze_type = freeze_type
# TODO: Create a QWidget subclass with signals so freeze type can be changed by clicking on the cell
if freeze_type == type_defs.FREEZE_TYPE.DEFAULT:
row.setText(FROZEN_COL, "")
row.setForeground(FROZEN_COL, QBrush(QColor(0, 0, 0)))
elif freeze_type == type_defs.FREEZE_TYPE.INCREMENT:
row.setText(FROZEN_COL, "▲")
row.setForeground(FROZEN_COL, QBrush(QColor(0, 255, 0)))
elif freeze_type == type_defs.FREEZE_TYPE.DECREMENT:
row.setText(FROZEN_COL, "▼")
row.setForeground(FROZEN_COL, QBrush(QColor(255, 0, 0)))
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.CheckState.Checked if check_state == Qt.CheckState.Unchecked else Qt.CheckState.Unchecked
for row in self.treeWidget_AddressTable.selectedItems():
row.setCheckState(FROZEN_COL, new_check_state)
self.treeWidget_AddressTable_item_clicked(row, FROZEN_COL)
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, True) + ((),) 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.CheckState.Unchecked)
frozen = type_defs.Frozen("", type_defs.FREEZE_TYPE.DEFAULT)
row.setData(FROZEN_COL, Qt.ItemDataRole.UserRole, frozen)
# Deserialize the address_expr & value_type param
if type(rec[1]) in [list, tuple]:
address_expr = type_defs.PointerType(*rec[1])
else:
address_expr = rec[1]
value_type = type_defs.ValueType(*rec[2])
self.change_address_table_entries(row, rec[0], address_expr, value_type)
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 delete_selected_records(self):
root = self.treeWidget_AddressTable.invisibleRootItem()
for item in self.treeWidget_AddressTable.selectedItems():
(item.parent() or root).removeChild(item)
def treeWidget_AddressTable_key_press_event(self, event):
actions = type_defs.KeyboardModifiersTupleDict([
(QKeyCombination(Qt.KeyboardModifier.NoModifier, Qt.Key.Key_Delete), self.delete_selected_records),
(QKeyCombination(Qt.KeyboardModifier.ControlModifier, Qt.Key.Key_B), self.browse_region_for_selected_row),
(QKeyCombination(Qt.KeyboardModifier.ControlModifier, Qt.Key.Key_D), self.disassemble_selected_row),
(QKeyCombination(Qt.KeyboardModifier.NoModifier, Qt.Key.Key_R), self.update_address_table),
(QKeyCombination(Qt.KeyboardModifier.NoModifier, Qt.Key.Key_Space), self.toggle_selected_records),
(QKeyCombination(Qt.KeyboardModifier.ControlModifier, Qt.Key.Key_X), self.cut_selected_records),
(QKeyCombination(Qt.KeyboardModifier.ControlModifier, Qt.Key.Key_C), self.copy_selected_records),
(QKeyCombination(Qt.KeyboardModifier.NoModifier, Qt.Key.Key_X), self.cut_selected_records_recursively),
(QKeyCombination(Qt.KeyboardModifier.NoModifier, Qt.Key.Key_C), self.copy_selected_records_recursively),
(QKeyCombination(Qt.KeyboardModifier.ControlModifier, Qt.Key.Key_V),
lambda: self.paste_records(insert_after=False)),
(QKeyCombination(Qt.KeyboardModifier.NoModifier, Qt.Key.Key_V),
lambda: self.paste_records(insert_after=True)),
(QKeyCombination(Qt.KeyboardModifier.NoModifier, Qt.Key.Key_I),
lambda: self.paste_records(insert_inside=True)),
(QKeyCombination(Qt.KeyboardModifier.NoModifier, Qt.Key.Key_Return),
self.treeWidget_AddressTable_edit_value),
(QKeyCombination(Qt.KeyboardModifier.ControlModifier, Qt.Key.Key_Return),
self.treeWidget_AddressTable_edit_desc),
(QKeyCombination(Qt.KeyboardModifier.ControlModifier | Qt.KeyboardModifier.AltModifier, Qt.Key.Key_Return),
self.treeWidget_AddressTable_edit_address),
(
QKeyCombination(Qt.KeyboardModifier.AltModifier, Qt.Key.Key_Return), self.treeWidget_AddressTable_edit_type)
])
try:
actions[QKeyCombination(event.modifiers(), Qt.Key(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)
mem_handle = GDB_Engine.memory_handle()
address_expr_list = []
rows = []
while True:
row = it.value()
if not row:
break
it += 1
address_data = row.data(ADDR_COL, Qt.ItemDataRole.UserRole)
if isinstance(address_data, type_defs.PointerType):
pointer_address = GDB_Engine.read_pointer(address_data)
if pointer_address == None:
continue
address_expr_list.append(hex(pointer_address))
else:
address_expr_list.append(address_data)
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 index, row in enumerate(rows):
value_type = row.data(TYPE_COL, Qt.ItemDataRole.UserRole)
address = address_list[index]
signed = True if value_type.value_repr == type_defs.VALUE_REPR.SIGNED else False
value = GDB_Engine.read_memory(address, value_type.value_index, value_type.length,
value_type.zero_terminate, signed, mem_handle=mem_handle)
address_data = row.data(ADDR_COL, Qt.ItemDataRole.UserRole)
if isinstance(address_data, type_defs.PointerType):
address_text = f'P->{address}'
else:
address_text = address
row.setText(ADDR_COL, address_text or address_expr_list[index])
if value is None:
value = ""
elif value_type.value_repr == type_defs.VALUE_REPR.HEX:
value = hex(value)
else:
value = str(value)
row.setText(VALUE_COL, 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():
desc, address_expr, value_index, length, zero_terminate = manual_address_dialog.get_values()
self.add_entry_to_addresstable(desc, address_expr, value_index, 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"')