-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathEWSPLugin.py
898 lines (653 loc) · 28.8 KB
/
EWSPLugin.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
#-----------------------------------
# EWS [ Emulation Wrapper System ]
#------------------------------------
import idaapi
import ida_kernwin
import idautils
import ida_idaapi
import ida_name
from EWS.utils import utils_ui
from EWS.utils.configuration import *
from EWS.ui import *
from EWS.ui.debug_view import *
from EWS.utils.utils import *
from EWS.utils.utils import logger,LogType, plug_mode
from EWS.utils.consts_ida import *
from EWS.ui.generic import FileSelector
from EWS.utils.configuration import saveconfig
from unicorn import UcError
def mode_default(func):
def check_mode(_s):
if _s.plug.mode == plug_mode.DEFAULT:
return func(_s)
ida_kernwin.warning("Feature not available in trace viewer mode.")
return
return check_mode
class menu_action_handler_t(idaapi.action_handler_t):
"""
Action handler for menu actions
"""
def __init__(self, action,plug):
idaapi.action_handler_t.__init__(self)
self.action = action
self.plug = plug
def activate(self, ctx):
if self.action == EMULLAUNCHER:
self.emul_launcher()
elif self.action == EMULF:
self.emul_func()
elif self.action == EMULSELECT:
self.emul_selection()
elif self.action == EMULINIT:
self.emul_init()
elif self.action == RESET:
self.reset()
elif self.action == EDITREG:
self.edit_registers()
elif self.action == TAGFUNC:
self.tag_func()
elif self.action == LOADCONF:
self.loadconf()
elif self.action == EDITCONF:
self.editconf()
elif self.action == SAVECONF:
self.saveconf()
elif self.action == PATCHFILE:
self.patch_file()
elif self.action == PATCHMEM:
self.patchmem()
elif self.action == DISPLAYMEM:
self.displaymem()
elif self.action == DISPLAYSTK:
self.displaystack()
elif self.action == DISPLAYADDR:
self.displayaddr()
elif self.action == IMPORTMEM:
self.mem_import()
elif self.action == EXPORTMEM:
self.mem_export()
elif self.action == STEPIN:
self.stepin()
elif self.action == STEPOVER:
self.stepover()
elif self.action == CONTINUE:
self.continuee()
elif self.action == ADDMAPPNG:
self.add_mapping()
elif self.action == WATCHPOINT:
self.watchpoint()
elif self.action == NSTUB:
self.add_nstub()
elif self.action == PATCH:
self.patch_insn()
elif self.action == LOADTRACE:
self.load_trace()
else:
logger.console(LogType.ERRR,"Function not yet implemented")
return 0
return 1
def update(self, ctx):
return idaapi.AST_ENABLE_ALWAYS
def reset(self):
if self.plug.emulator_initialized :
self.plug.emu.flush() ##FIXME is that necessary?
self.plug.emu.reset_color_graph()
self.plug.reset()
elif self.plug.config_initialized:
self.plug.config = None
self.plug.config_initialized = False
if self.plug.view_enabled:
self.plug.reset_view()
self.plug.mode = plug_mode.DEFAULT
logger.console(LogType.INFO,"Plugin was properly reset")
@mode_default
def emul_func(self):
"""
! Emulate current function
"""
if self.plug.config_initialized:
ida_kernwin.warning("Configuration Object already exist, please reset the plugin before using this function.")
return
s_ea, e_ea = utils_ui.get_func_boundaries()
self.plug.conf = utils_ui.get_conf_for_area(s_ea,e_ea)
logger.console(LogType.INFO, "Configuration generated for area [0x%x 0x%x] "%
(self.plug.conf.exec_saddr,self.plug.conf.exec_eaddr))
self.plug.config_initialized = True
@mode_default
def emul_selection(self):
"""
! Emulate the current selected assembly in UI_Hooks
"""
if self.plug.config_initialized:
ida_kernwin.warning("Configuration Object already exist, please reset the plugin before using this function.")
return
s_ea, e_ea = utils_ui.get_user_select()
self.plug.conf = utils_ui.get_conf_for_area(s_ea,e_ea)
logger.console(LogType.INFO, "Configuration generated for area [0x%x 0x%x] "%
(s_ea,e_ea))
self.plug.config_initialized = True
@mode_default
def emul_init(self):
"""
! Initialise the emulator and the debug views.
"""
if not self.plug.config_initialized:
logger.console(LogType.WARN,"Please init a configuration")
return
if self.plug.emulator_initialized:
ida_kernwin.warning('Emulator is already initialized. Please reset to load a new configuration')
return
try:
self.plug.emu = utils_ui.get_emul_from_conf(self.plug.conf)
except Exception as e:
logger.console(LogType.ERRR,"An error occured while initializing the emulator",
"\nReason is : %s"%str(e))
return
self.plug.emulator_initialized = True
if not self.plug.view_intialized:
self.plug.init_view()
if not self.plug.view_enabled:
self.plug.enable_view()
logger.console(LogType.INFO,"Emulator ready to run (Alt+Shift+{C,I})")
@mode_default
def emul_launcher(self):
"""
! Create a configuration from scratch.
"""
if self.plug.config_initialized == True:
ida_kernwin.warning("A configuration object is already instancied.\n\
Please use edit feature to edit the current config")
return
if self.plug.emulator_initialized == True:
ida_kernwin.warning("Emulator is already initialized.\n\
Please reset the emulator before using this feature")
return
try:
self.plug.conf = utils_ui.get_emul_conf()
self.config_initialized = True
except:
logger.console(LogType.ERRR,"Error occured while creating configuration object")
@mode_default
def edit_registers(self):
"""
! Edit registers.
"""
if not self.plug.config_initialized:
logger.console(LogType.WARN,"Please init the configuration before using this function")
return
regedit_func = utils_ui.get_regedit_func()
if not self.plug.emulator_initialized:
new_regs = regedit_func(self.plug.conf.registers)
self.plug.conf.registers = new_regs
else:
new_regs = regedit_func(self.plug.emu.get_regs())
if not new_regs is None:
self.plug.emu.setup_regs(new_regs)
@mode_default
def tag_func(self):
"""
!Tag a function when cursor is on call type insn (call/br 0x...)
"""
if not self.plug.emulator_initialized:
logger.console(LogType.ERRR,
"Please initiate an self.plug.emulator before using this function (Alt+Ctrl+I)")
return
tag_list = [ k for k in self.plug.emu.stubs.keys() ]
tag_name = utils_ui.get_tag_name(tag_list)
if tag_name == None:
logger.console(LogType.ERRR,'Invalid tag name')
# get the target of the call insn
# somehow, it does not work using insn.Op1
try:
ea=next(idautils.CodeRefsFrom(idc.get_screen_ea(),False))
except StopIteration:
logger.console(LogType.ERRR,
'Could not find valid function to tag')
return
if ea != None and ea != idaapi.BADADDR:
self.plug.emu.tag_func(ea,tag_name)
logger.console(LogType.INFO,
'Function at %x now tagger with %s'%(ea,tag_name))
@mode_default
def loadconf(self):
"""
! Load configuration from file.
"""
if self.plug.emulator_initialized or self.plug.config_initialized:
ida_kernwin.warning("Please reset plugin to load new configuration")
return
try:
self.plug.conf = utils_ui.loadconfig()
except:
ida_kernwin.warning('Config file does not exist')
return
self.plug.config_initialized = True
ida_kernwin.info("Config file has been loaded")
@mode_default
def saveconf(self):
"""
! saveconf
"""
if not self.plug.config_initialized:
ida_kernwin.warning('No configuration object available')
return
if self.plug.emulator_initialized:
conf_path =FileSelector.fillconfig()
config = self.plug.emu.extract_current_configuration()
saveconfig(config,conf_path)
else:
utils_ui.saveconfig(self.plug.conf)
@mode_default
def editconf(self):
"""
!editconf
"""
if self.plug.emulator_initialized:
ida_kernwin.warning("Configuration cannot be edited when emulator is initalized"
+"Advise: store current config (if necessary) and reset the plugin.")
uret = ida_kernwin.ask_yn(False,"Emulator being already instancied,"
+"editing configuration will extract current emulator state in a new"
+"configuration object and allow you to edit it. Is that what you want")
if uret == ida_kernwin.ASKBTN_YES:
conf = self.plug.emu.extract_current_configuration()
else:
return
elif not self.plug.config_initialized:
ida_kernwin.warning("Please create/load a configuration before using this function")
return
try:
new_conf = utils_ui.get_emul_conf(simplified=False,
conf=self.plug.conf)
self.plug.conf = new_conf
except Exception as e:
ida_kernwin("Something wrong happened while loading the config, please reset the plug and retry")
@mode_default
def patchmem(self):
"""
! Patch memory
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning("Please init the emulator before using this function")
if not utils_ui.patch_mem(self.plug.emu):
pass
@mode_default
def displaymem(self):
"""
! Display memory
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning("Nothing to display, init the emulator before using this function.")
return
utils_ui.display_section(self.plug.emu)
@mode_default
def displaystack(self):
"""
!Display the stack
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning("Nothing to display, init the emulator before using this function.")
return
utils_ui.display_stack(self.plug.emu)
@mode_default
def displayaddr(self):
"""
! Display a specific address.
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning("Nothing to display, init the emulator before using this function.")
return
utils_ui.display_addr(self.plug.emu)
@mode_default
def mem_import(self):
"""
! Import memory to emulator
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning("Init an emulator before using this function")
return
utils_ui.import_mem(self.plug.emu)
@mode_default
def mem_export(self):
"""
! Dump emulator memory in a file.
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning("Init an emulator before using this function")
return
utils_ui.export_mem(self.plug.emu)
@mode_default
def stepin(self):
"""
! Step in function
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning("Please initiate an self.plug.emulator before using this function")
return
try:
self.plug.emu.step_in()
except UcError as e:
ida_kernwin.warning('An error occured during the step. Reason: %s'%str(e))
finally:
self.plug.refresh_view()
@mode_default
def stepover(self):
"""
! Step over function
"""
if not self.plug.emulator_initialized:
logger.console(LogType.ERRR,
"Please initiate an self.plug.emulator before using this function (Alt+Ctrl+I)")
return
if self.plug.emu.is_running:
self.plug.emu.step_over()
self.refresh_view()
@mode_default
def continuee(self):
"""
! Run / Continue
"""
if not self.plug.config_initialized:
ida_kernwin.warning("A configuration is required to use this command")
if not self.plug.emulator_initialized:
self.plug.emu = utils_ui.get_emul_from_conf(self.plug.conf)
self.plug.emulator_initialized = True
if not self.plug.view_intialized:
self.plug.init_view()
if not self.plug.view_enabled:
self.plug.enable_view()
if self.plug.emu.is_running:
logger.console(LogType.INFO,"Exec continues")
try:
self.plug.emu.continuee()
except Exception as e:
logger.console(LogType.ERRR,"Execution run out of control.",
"Reason: %s"%e.__str__())
finally:
self.plug.refresh_view()
else:
logger.console(LogType.INFO,"Exec starts")
try:
self.plug.emu.start()
except Exception as e:
logger.console(LogType.ERRR,"Execution run out of control.",
"Reason: %s"%e.__str__())
finally:
self.plug.refresh_view()
@mode_default
def add_mapping(self):
"""
! Add a mapping and optionally init memory
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning("Require the emulator to be init")
return
new_mappings = utils_ui.get_add_mappings()
self.plug.conf.amap_conf+= new_mappings
if self.plug.emu != idaapi.BADADDR:
idaapi.show_wait_box("Adding mapping, could take time")
utils_ui.add_mapping(self.plug.emu,new_mappings)
idaapi.hide_wait_box()
@mode_default
def watchpoint(self):
"""
! Add read/write watchpoint.
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning("Could not set breakpoint. Require the emulator to be init")
return
utils_ui.watchpoint(self.plug.emu)
@mode_default
def add_nstub(self):
"""
! Add a null stub.
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning("Stubing require emulator init")
return
if not self.plug.emu.conf.s_conf.activate_stub_mechanism:
ida_kernwin.warning("Current config does not allow stubbing.")
return
cur_ea = ida_kernwin.get_screen_ea()
if (ida_kernwin.ask_yn(False,"Null-stub function %x"%cur_ea)):
self.plug.emu.add_null_stub(cur_ea)
logger.console(LogType.INFO,"Null stub added to function %s"%ida_name.get_name(cur_ea),
"at addr %x"%cur_ea)
@mode_default
def patch_insn(self):
"""
! Patch instructions
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning('Please init the emulator before using this function')
return
utils_ui.add_insn_patch(self.plug.emu)
@mode_default
def patch_file(self):
"""
! Patch file
"""
if not self.plug.emulator_initialized:
ida_kernwin.warning('Please init the emulator before using this function')
return
utils_ui.add_patch_file(self.plug.emu)
def load_trace(self):
make_idb_backup()
if self.plug.emulator_initialized or self.plug.config_initialized:
ida_kernwin.warning("Please reset the plugin before using this feature.")
return
#f_trace = ida_kernwin.ask_file(False,"/tmp","Trace File")
f_trace="/tmp/EWS_trace.txt"
with open(f_trace, 'r') as fin:
exec_trace = json.loads(fin.read(),cls=Exec_Trace_Deserializer)
#f_ct = ida_kernwin.ask_file(False,"/tmp","Call Tree")
f_ct = "/tmp/EWS_calltree.txt"
with open(f_ct, 'r') as fin:
call_tree = json.loads(fin.read(),cls=Call_Tree_Deserializer)
self.plug.conf = utils_ui.get_conf_for_area(exec_trace.content[0]['addr'],
exec_trace.content[exec_trace.count-1]['addr'])
self.plug.emu = utils_ui.get_emul_from_conf(self.plug.conf)
self.plug.emu.exec_trace = exec_trace
self.plug.emu.call_tree = call_tree
if not self.plug.view_intialized:
self.plug.init_view()
if not self.plug.view_enabled:
self.plug.enable_view()
self.plug.mode = plug_mode.TRACEVIEWER
class EWS_Plugin(idaapi.plugin_t, idaapi.UI_Hooks):
"""
Load EWS Plugin
"""
comment="Emulator Wrapper System"
help="Emulate code using your favorite emulator"
wanted_name="EWS"
wanted_hotkey="Ctrl-Alt+E"
flags= idaapi.PLUGIN_KEEP
def __init__(self):
self.emu=idaapi.BADADDR
self.conf=idaapi.BADADDR
self.debug_panel_regs = idaapi.BADADDR
self.trace_panel = idaapi.BADADDR
self.ct_panel = idaapi.BADADDR
self.emulator_initialized = False
self.config_initialized = False
self.view_intialized = False
self.view_enabled = False
self.mode = plug_mode.DEFAULT
idaapi.UI_Hooks.__init__(self)
self.menu_actions = [
idaapi.action_desc_t(EMULLAUNCHER, "Configure Emulation",
menu_action_handler_t(EMULLAUNCHER,self), 'Alt+Ctrl+L',
"S", 8),
idaapi.action_desc_t(LOADCONF, "Load Config",
menu_action_handler_t(LOADCONF,self), 'Alt+Shift+L',
"T", 12),
idaapi.action_desc_t(EDITCONF, "Edit Config",
menu_action_handler_t(EDITCONF,self), 'Alt+Ctrl+C',
"T", 12),
idaapi.action_desc_t(SAVECONF, "Save Config",
menu_action_handler_t(SAVECONF,self), 'Alt+Shift+D',
"T", 12),
idaapi.action_desc_t(EMULF, "Emulate Function",
menu_action_handler_t(EMULF,self), 'Alt+Ctrl+F',
"S", 9),
idaapi.action_desc_t(EMULSELECT, "Emulate Selection",
menu_action_handler_t(EMULSELECT,self), 'Alt+Ctrl+S',
"T", 10),
##########################################################################
idaapi.action_desc_t(EMULINIT, "Init Emulator",
menu_action_handler_t(EMULINIT,self), 'Alt+Ctrl+I',
"T", 10),
idaapi.action_desc_t(RESET, "Reset",
menu_action_handler_t(RESET,self), 'Alt+Shift+R',
"T", 10),
##########################################################################
idaapi.action_desc_t(EDITREG, "Edit registers",
menu_action_handler_t(EDITREG,self), 'Alt+Ctrl+R',
"T", 11),
idaapi.action_desc_t(NSTUB, "Null Stub function",
menu_action_handler_t(NSTUB,self), 'Alt+Shift+N',
"T", 12),
idaapi.action_desc_t(TAGFUNC, "Tag function",
menu_action_handler_t(TAGFUNC,self), 'Alt+Shift+T',
"T", 12),
idaapi.action_desc_t(PATCHMEM, "Patch Mem",
menu_action_handler_t(PATCHMEM,self), 'Alt+Ctrl+M',
"T", 12),
idaapi.action_desc_t(PATCHFILE, "Add Patch File",
menu_action_handler_t(PATCHFILE,self), '',
"T", 12),
idaapi.action_desc_t(DISPLAYMEM, "Display Segment",
menu_action_handler_t(DISPLAYMEM,self), 'Alt+Ctrl+D',
"T", 12),
idaapi.action_desc_t(DISPLAYSTK, "Display Stack",
menu_action_handler_t(DISPLAYSTK,self), 'Alt+Shift+S',
"T", 12),
idaapi.action_desc_t(DISPLAYADDR, "Display Addr",
menu_action_handler_t(DISPLAYADDR,self), 'Alt+Shift+M',
"T", 12),
idaapi.action_desc_t(IMPORTMEM, "Import Memory From File",
menu_action_handler_t(IMPORTMEM,self), 'Ctrl+Shift+I',
"T", 12),
idaapi.action_desc_t(EXPORTMEM, "Export Memory To File",
menu_action_handler_t(EXPORTMEM,self), 'Ctrl+Shift+E',
"T", 12),
idaapi.action_desc_t(STEPIN, "Start / Step IN",
menu_action_handler_t(STEPIN,self), 'Alt+Shift+I',
"T", 12),
idaapi.action_desc_t(STEPOVER, "Step OVER",
menu_action_handler_t(STEPOVER,self), 'Alt+Shift+O',
"T", 12),
idaapi.action_desc_t(CONTINUE, "Run/Continue",
menu_action_handler_t(CONTINUE,self), 'Alt+Shift+C',
"T", 12),
idaapi.action_desc_t(ADDMAPPNG, "Add Mapping",
menu_action_handler_t(ADDMAPPNG,self), 'Alt+Ctrl+A',
"T", 12),
idaapi.action_desc_t(WATCHPOINT, "Watchpoint",
menu_action_handler_t(WATCHPOINT,self), 'Alt+Ctrl+W',
"T", 12),
idaapi.action_desc_t(PATCH, "Patch Instruction",
menu_action_handler_t(PATCH,self), 'Alt+Ctrl+P',
"T", 12),
idaapi.action_desc_t(LOADTRACE, "Load Trace",
menu_action_handler_t(LOADTRACE,self), 'Alt+Ctrl+9',
"T", 12)
]
def init(self):
if not utils_ui.is_arch_supported():
return idaapi.PLUGIN_SKIP
for action in self.menu_actions:
idaapi.register_action(action)
ida_kernwin.UI_Hooks.hook(self)
return ida_idaapi.PLUGIN_OK
def run(self,arg):
logger.console(LogType.INFO,'[+] EWS Plugin Launched')
def term(self):
"""
TODO
here should be removed all plugin artefacts (color, ...)
"""
ida_kernwin.UI_Hooks.unhook(self)
def finish_populating_widget_popup(self, form, popup):
form_type = idaapi.get_widget_type(form)
if form_type == idaapi.BWN_DISASM or form_type == idaapi.BWN_DUMP:
# Configuration & Launch
idaapi.attach_action_to_popup(form, popup, EMULLAUNCHER,'%s/init/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, EMULF, '%s/init/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, EMULSELECT, '%s/init/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, EMULINIT, '%s/init/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, RESET, '%s/init/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, EXPORTMEM, '%s/init/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, IMPORTMEM, '%s/init/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, ADDMAPPNG, '%s/init/'%PLUGNAME)
# Configuration
idaapi.attach_action_to_popup(form, popup, LOADCONF, '%s/config/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, EDITCONF, '%s/config/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, SAVECONF, '%s/config/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, LOADTRACE, '%s/config/'%PLUGNAME)
# Debugging
idaapi.attach_action_to_popup(form, popup, CONTINUE, '%s/debug/'%PLUGNAME)
# idaapi.attach_action_to_popup(form, popup, RESTART, '%s/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, STEPIN, '%s/debug/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, STEPOVER, '%s/debug/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, WATCHPOINT, '%s/debug/'%PLUGNAME)
# Memory
idaapi.attach_action_to_popup(form, popup, EDITREG, '%s/memory/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, PATCHMEM, '%s/memory/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, PATCH, '%s/memory/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, DISPLAYMEM, '%s/memory/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, DISPLAYSTK, '%s/memory/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, DISPLAYADDR, '%s/memory/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, PATCHFILE, '%s/memory/'%PLUGNAME)
# Stubs
idaapi.attach_action_to_popup(form, popup, EDITSTUBCONF, '%s/stubs/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, NSTUB, '%s/stubs/'%PLUGNAME)
idaapi.attach_action_to_popup(form, popup, TAGFUNC, '%s/stubs/'%PLUGNAME)
def init_view(self):
self.debug_panel_regs = Debug_View_Registers("Registers",
self.emu,
width=50,
height=50)
self.trace_panel = Debug_View_Trace("Trace",
self.emu,
self.debug_panel_regs,
width=50,
height=50)
self.ct_panel= CallTree_View("Call Tree",
self.emu,
self.debug_panel_regs,
width=50,
height=50)
self.view_intialized = True
def enable_view(self):
if not self.view_intialized:
return
view_to_dock_with = idaapi.get_widget_title(idaapi.get_current_viewer())
self.debug_panel_regs.show()
idaapi.set_dock_pos('Registers',view_to_dock_with,idaapi.DP_RIGHT)
self.trace_panel.show()
idaapi.set_dock_pos('Trace','Registers',idaapi.DP_BOTTOM)
self.ct_panel.show()
idaapi.set_dock_pos('Call Tree','Trace',idaapi.DP_RIGHT)
self.view_enabled = True
def refresh_view(self):
self.debug_panel_regs.refresh()
self.trace_panel.refresh()
self.ct_panel.refresh()
def reset_view(self):
ida_kernwin.close_widget(idaapi.find_widget('Registers'),0)
ida_kernwin.close_widget(idaapi.find_widget('Trace'),0)
ida_kernwin.close_widget(idaapi.find_widget('Call Tree'),0)
self.trace_panel.Close()
self.trace_panel.flush() # FIXME is that necessary IDTS
self.debug_panel_regs = None
self.trace_panel = None
self.view_intialized = False
self.view_enabled = False
def reset(self):
self.emu = None
self.conf = None
self.emulator_initialized = False
self.config_initialized = False
def PLUGIN_ENTRY():
return EWS_Plugin()