-
Notifications
You must be signed in to change notification settings - Fork 44
/
pmbase.h
2984 lines (2526 loc) · 122 KB
/
pmbase.h
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
/*
* A Generic processor module base class.
*
* Author: Willem Hengeveld <[email protected]>
*
*/
#include <pro.h>
#include <idp.hpp>
#include <auto.hpp>
#include <name.hpp>
#include <loader.hpp>
#include <typeinf.hpp>
// a baseclass for processor modules.
//
// how to use:
// * create a subclass implementing at least:
// ana_insn, emu_insn, out_insn, out_operand
// * define a variable for your subclass
// * in LPH for the notifyhook use: &cpu.staticnotifyhook,
std::map<int,const char*> eventnames = {
{0, "init"},
{1, "term"},
{2, "newprc"},
{3, "newasm"},
{4, "newfile"},
{5, "oldfile"},
{6, "newbinary"},
{7, "endbinary"},
{8, "set_idp_options"},
{9, "set_proc_options"},
{10, "ana_insn"},
{11, "emu_insn"},
{12, "out_header"},
{13, "out_footer"},
{14, "out_segstart"},
{15, "out_segend"},
{16, "out_assumes"},
{17, "out_insn"},
{18, "out_mnem"},
{19, "out_operand"},
{20, "out_data"},
{21, "out_label"},
{22, "out_special_item"},
{23, "gen_stkvar_def"},
{24, "gen_regvar_def"},
{25, "gen_src_file_lnnum"},
{26, "creating_segm"},
{27, "moving_segm"},
{28, "coagulate"},
{29, "undefine"},
{30, "treat_hindering_item"},
{31, "rename"},
{32, "is_far_jump"},
{33, "is_sane_insn"},
{34, "is_cond_insn"},
{35, "is_call_insn"},
{36, "is_ret_insn"},
{37, "may_be_func"},
{38, "is_basic_block_end"},
{39, "is_indirect_jump"},
{40, "is_insn_table_jump"},
{41, "is_switch"},
{42, "calc_switch_cases"},
{43, "create_switch_xrefs"},
{44, "is_align_insn"},
{45, "is_alloca_probe"},
{46, "delay_slot_insn"},
{47, "is_sp_based"},
{48, "can_have_type"},
{49, "cmp_operands"},
{50, "adjust_refinfo"},
{51, "get_operand_string"},
{52, "get_reg_name"},
{53, "str2reg"},
{54, "get_autocmt"},
{55, "get_bg_color"},
{56, "is_jump_func"},
{57, "func_bounds"},
{58, "verify_sp"},
{59, "verify_noreturn"},
{60, "create_func_frame"},
{61, "get_frame_retsize"},
{62, "get_stkvar_scale_factor"},
{63, "demangle_name"},
{64, "add_cref"},
{65, "add_dref"},
{66, "del_cref"},
{67, "del_dref"},
{68, "coagulate_dref"},
{69, "may_show_sreg"},
{70, "loader_elf_machine"},
{71, "auto_queue_empty"},
{72, "validate_flirt_func"},
{73, "adjust_libfunc_ea"},
{74, "assemble"},
{75, "extract_address"},
{76, "realcvt"},
{77, "gen_asm_or_lst"},
{78, "gen_map_file"},
{79, "create_flat_group"},
{80, "getreg"},
{81, "analyze_prolog"},
{82, "calc_spdelta"},
{83, "calcrel"},
{84, "find_reg_value"},
{85, "find_op_value"},
{86, "replaying_undo"},
{87, "ending_undo"},
{88, "set_code16_mode"},
{89, "get_code16_mode"},
{90, "get_procmod"},
{91, "asm_installed"},
{92, "get_reg_accesses"},
{93, "is_control_flow_guard"},
{94, "broadcast"},
{95, "create_merge_handlers"},
{96, "privrange_changed"},
{97, "last_cb_before_debugger"},
{1000, "next_exec_insn"},
{1001, "calc_step_over"},
{1002, "calc_next_eas"},
{1003, "get_macro_insn_head"},
{1004, "get_dbr_opnum"},
{1005, "insn_reads_tbit"},
{1006, "clean_tbit"},
{1007, "get_idd_opinfo"},
{1008, "get_reg_info"},
{1009, "update_call_stack"},
{1010, "last_cb_before_type_callbacks"},
{2000, "setup_til"},
{2001, "get_abi_info"},
{2002, "max_ptr_size"},
{2003, "get_default_enum_size"},
{2004, "get_cc_regs"},
{2005, "obsolete1"},
{2006, "obsolete2"},
{2007, "get_simd_types"},
{2008, "calc_cdecl_purged_bytes"},
{2009, "calc_purged_bytes"},
{2010, "calc_retloc"},
{2011, "calc_arglocs"},
{2012, "calc_varglocs"},
{2013, "adjust_argloc"},
{2014, "lower_func_type"},
{2015, "equal_reglocs"},
{2016, "use_stkarg_type"},
{2017, "use_regarg_type"},
{2018, "use_arg_types"},
{2019, "arg_addrs_ready"},
{2020, "decorate_name"},
{2021, "arch_changed"},
{2022, "get_stkarg_area_info"},
{2023, "last_cb_before_loader"},
{3000, "loader"},
};
const char*eventname(int id)
{
auto i = eventnames.find(id);
if (i==eventnames.end())
return "unknown";
return i->second;
}
struct leavenotify {
// help in logging the entry/exit of this function with stack level.
inline static int _level;
int notification_code;
ssize_t &rc;
leavenotify(int notification_code, ssize_t &rc)
: notification_code(notification_code), rc(rc)
{
hextracelog("%*sENTER hexagon:notify msgid=%2d:%s: ", _level*3, "", notification_code, eventname(notification_code));
_level++;
}
~leavenotify() {
_level--;
hextracelog("%*sLEAVE hexagon:notify msgid=%2d:%s - rc=%d\n", _level*3, "", notification_code, eventname(notification_code), (int)rc);
}
};
/*
* argument types:
* - using const (ref|ptr) when the object pointed to shall not be modified
* - using ref when the object must be specified
* - using ptr when the object is optional.
* - use ptr when an array of values is pointed to
*
* - ptr to simple types, and qstring will be passed as ptr, not ref.
*
*/
class processor_module : public procmod_t {
public:
virtual ssize_t idaapi on_event(ssize_t notification_code, va_list va) override
{
ssize_t rc = 0;
leavenotify eventlogger(notification_code, rc);
switch(notification_code)
{
case processor_t::ev_init:
{
///< The IDP module is just loaded.
auto idp_modname = va_arg(va, const char *); // processor module name
///< \return <0 on failure
hextracelog("modname='%s'\n", idp_modname);
rc = init(idp_modname);
}
break;
case processor_t::ev_term:
{
///< The IDP module is being unloaded
hextracelog("\n");
term();
#ifdef TRACELOG
if (g_log) {
qfclose(g_log);
g_log= NULL;
}
#endif
}
break;
case processor_t::ev_newprc:
{
///< Before changing processor type.
auto pnum = va_arg(va, int); // processor number in the array of processor names
auto keep_cfg = va_argi(va, bool); // true: do not modify kernel configuration
///< \retval 1 ok
///< \retval <0 prohibit
hextracelog("pnum=%d, keep=%d\n", pnum, keep_cfg);
rc = newprc(pnum, keep_cfg);
}
break;
case processor_t::ev_newasm:
{
///< Before setting a new assembler.
auto asmnum = va_arg(va, int);
hextracelog("asmnum=%d\n", asmnum);
newasm(asmnum);
rc = 1;
}
break;
case processor_t::ev_newfile:
{
///< A new file has been loaded.
auto fname = va_arg(va, char *); // input file name
hextracelog("fname='%s'\n", fname);
newfile(fname);
rc = 1;
}
break;
case processor_t::ev_oldfile:
{
///< An old file has been loaded.
auto fname = va_arg(va, char *); // input file name
hextracelog("fname='%s'\n", fname);
oldfile(fname);
rc = 1;
}
break;
case processor_t::ev_newbinary:
{
///< IDA is about to load a binary file.
auto filename = va_arg(va, char *); // binary file name
auto fileoff = va_arg(va, ::qoff64_t); // offset in the file
auto basepara = va_arg(va, ::ea_t); // base loading paragraph
auto binoff = va_arg(va, ::ea_t); // loader offset
auto nbytes = va_arg(va, ::uint64); // number of bytes to load
hextracelog("fname='%s', off=%llx, base=%08llx, binoff=%08llx, nb=%08llx\n", filename, fileoff, uint64_t(basepara), uint64_t(binoff), nbytes);
newbinary(filename, fileoff, basepara, binoff, nbytes);
rc = 1;
}
break;
case processor_t::ev_endbinary:
{
///< IDA has loaded a binary file.
auto ok = va_argi(va, bool); // file loaded successfully?
hextracelog("ok=%d\n", ok);
endbinary(ok);
rc = 1;
}
break;
case processor_t::ev_set_idp_options:
{
///< Set IDP-specific configuration option
///< Also see set_options_t above
auto keyword = va_arg(va, const char *);
auto value_type = va_arg(va, int);
auto value = va_arg(va, const void *);
auto errbuf = va_arg(va, const char **); // - a error message will be returned here (can be NULL)
///< \return 1 ok
///< \return 0 not implemented
///< \return -1 error (and message in errbuf)
hextracelog("kw='%s', vt=%d, val=%p", keyword, value_type, value);
rc = set_idp_options(keyword, value_type, value, errbuf);
hextracelog(" -> err='%s'\n", errbuf ? *errbuf : "");
}
break;
case processor_t::ev_set_proc_options:
{
///< Called if the user specified an option string in the command line:
///< -p<processor name>:<options>.
///< Can be used for setting a processor subtype.
///< Also called if option string is passed to set_processor_type()
///< and IDC's SetProcessorType().
auto options = va_arg(va, const char *);
auto confidence = va_arg(va, int);
///< 0: loader's suggestion
///< 1: user's decision
///< \return < 0 if bad option string
hextracelog("opt='%s', conf=%d\n", options, confidence);
rc = set_proc_options(options, confidence);
}
break;
case processor_t::ev_ana_insn:
{
///< Analyze one instruction and fill 'out' structure.
///< This function shouldn't change the database, flags or anything else.
///< All these actions should be performed only by emu_insn() function.
///< \insn_t{ea} contains address of instruction to analyze.
auto out = va_arg(va, ::insn_t *);
///< \return length of the instruction in bytes, 0 if instruction can't be decoded.
///< \return 0 if instruction can't be decoded.
hextracelog("ea=%08x\n", out->ea);
rc = ana_insn(*out);
}
break;
case processor_t::ev_emu_insn:
{
///< Emulate instruction, create cross-references, plan to analyze
///< subsequent instructions, modify flags etc. Upon entrance to this function,
///< all information about the instruction is in 'insn' structure.
auto insn = va_arg(va, const ::insn_t *);
///< \return 1 ok
///< \return -1 the kernel will delete the instruction
hextracelog("ea=%08x\n", insn->ea);
rc = emu_insn(*insn);
}
break;
case processor_t::ev_out_header:
{
///< Function to produce start of disassembled text
auto outctx = va_arg(va, ::outctx_t *);
///< \return void
hextracelog("ea=%08x\n", outctx->insn.ea);
out_header(*outctx);
rc = 1;
}
break;
case processor_t::ev_out_footer:
{
///< Function to produce end of disassembled text
auto outctx = va_arg(va, ::outctx_t *);
///< \return void
hextracelog("ea=%08x\n", outctx->insn.ea);
out_footer(*outctx);
rc = 1;
}
break;
case processor_t::ev_out_segstart:
{
///< Function to produce start of segment
auto outctx = va_arg(va, ::outctx_t *);
auto seg = va_arg(va, ::segment_t *);
///< \return 1 ok
///< \return 0 not implemented
hextracelog("ea=%08x, seg=%08x\n", outctx->insn.ea, seg->start_ea);
rc = out_segstart(*outctx, *seg);
}
break;
case processor_t::ev_out_segend:
{
///< Function to produce end of segment
auto outctx = va_arg(va, ::outctx_t *);
auto seg = va_arg(va, ::segment_t *);
///< \return 1 ok
///< \return 0 not implemented
hextracelog("ea=%08x, seg=%08x\n", outctx->insn.ea, seg->start_ea);
rc = out_segend(*outctx, *seg);
}
break;
case processor_t::ev_out_assumes:
{
///< Function to produce assume directives
///< when segment register value changes.
auto outctx = va_arg(va, ::outctx_t *);
///< \return 1 ok
///< \return 0 not implemented
hextracelog("ea=%08x\n", outctx->insn.ea);
rc = out_assumes(*outctx);
}
break;
case processor_t::ev_out_insn:
{
///< Generate text representation of an instruction in 'ctx.insn'
///< outctx_t provides functions to output the generated text.
///< This function shouldn't change the database, flags or anything else.
///< All these actions should be performed only by emu_insn() function.
auto outctx = va_arg(va, ::outctx_t *);
///< \return void
hextracelog("ea=%08x\n", outctx->insn.ea);
out_insn(*outctx);
rc = 1;
}
break;
case processor_t::ev_out_mnem:
{
///< Generate instruction mnemonics.
///< This callback should append the colored mnemonics to ctx.outbuf
///< Optional notification, if absent, out_mnem will be called.
auto outctx = va_arg(va, ::outctx_t *);
///< \return 1 if appended the mnemonics
///< \return 0 not implemented
hextracelog("ea=%08x\n", outctx->insn.ea);
rc = out_mnem(*outctx);
}
break;
case processor_t::ev_out_operand:
{
///< Generate text representation of an instruction operand
///< outctx_t provides functions to output the generated text.
///< All these actions should be performed only by emu_insn() function.
auto outctx = va_arg(va, ::outctx_t *);
auto op = va_arg(va, const ::op_t *);
///< \return 1 ok
///< \return -1 operand is hidden
hextracelog("ea=%08x, op=%d:%d\n", outctx->insn.ea, op->n, op->type);
rc = out_operand(*outctx, *op);
}
break;
case processor_t::ev_out_data:
{
///< Generate text representation of data items
///< This function may change the database and create cross-references
///< if analyze_only is set
auto outctx = va_arg(va, ::outctx_t *);
auto analyze_only = va_argi(va, bool);
///< \return 1 ok
///< \return 0 not implemented
hextracelog("ea=%08x, ana=%d\n", outctx->insn.ea, analyze_only );
rc = out_data(*outctx, analyze_only);
}
break;
case processor_t::ev_out_label:
{
///< The kernel is going to generate an instruction
///< label line or a function header.
auto outctx = va_arg(va, ::outctx_t *);
auto colored_name = va_arg(va, const char *);
///< \return <0 if the kernel should not generate the label
///< \return 0 not implemented or continue
hextracelog("ea=%08x cname='%s'\n", outctx->insn.ea, colored_name);
rc = out_label(*outctx, colored_name);
}
break;
case processor_t::ev_out_special_item:
{
///< Generate text representation of an item in a special segment
///< i.e. absolute symbols, externs, communal definitions etc
auto outctx = va_arg(va, ::outctx_t *);
auto segtype = va_argi(va, uchar);
///< \return 1 ok
///< \return 0 not implemented
///< \return -1 overflow
hextracelog("ea=%08x segtyp=%d\n", outctx->insn.ea, segtype);
rc = out_special_item(*outctx, segtype);
}
break;
case processor_t::ev_gen_stkvar_def:
{
///< Generate stack variable definition line
///< Default line is
///< varname = type ptr value,
///< where 'type' is one of byte,word,dword,qword,tbyte
auto outctx = va_arg(va, ::outctx_t *);
auto mptr = va_arg(va, const ::member_t *);
auto v = va_arg(va, sval_t);
///< \return 1 - ok
///< \return 0 - not implemented
hextracelog("ea=%08x mptr=%p, v=%d\n", outctx->insn.ea, mptr, v);
rc = gen_stkvar_def(*outctx, *mptr, v);
}
break;
case processor_t::ev_gen_regvar_def:
{
///< Generate register variable definition line.
auto outctx = va_arg(va, ::outctx_t *);
auto v = va_arg(va, ::regvar_t *);
///< \retval >0 ok, generated the definition text
///< \return 0 - not implemented
hextracelog("ea=%08x v=%p\n", outctx->insn.ea, v);
rc = gen_regvar_def(*outctx, *v);
}
break;
case processor_t::ev_gen_src_file_lnnum:
{
///< Callback: generate analog of:
///<
///< #line "file.c" 123
///<
///< directive.
auto outctx = va_arg(va, ::outctx_t *); // output context
auto file = va_arg(va, const char *); // source file (may be NULL)
auto lnnum = va_arg(va, size_t); // line number
///< \retval 1 directive has been generated
///< \return 0 - not implemented
hextracelog("ea=%08x file='%s', line=%lu\n", outctx->insn.ea, file, lnnum);
rc = gen_src_file_lnnum(*outctx, file, lnnum);
}
break;
case processor_t::ev_creating_segm:
{
///< A new segment is about to be created.
auto seg = va_arg(va, ::segment_t *);
///< \retval 1 ok
///< \retval <0 segment should not be created
hextracelog("seg=%08x\n", seg->start_ea);
rc = creating_segm(*seg);
}
break;
case processor_t::ev_moving_segm:
{
///< May the kernel move the segment?
auto seg = va_arg(va, ::segment_t *); // segment to move
auto to = va_arg(va, ::ea_t); // new segment start address
auto flags = va_arg(va, int); // combination of \ref MSF_
///< \retval 0 yes
///< \retval <0 the kernel should stop
hextracelog("seg=%08x -> %08x, fl=%08x\n", seg->start_ea, to, flags);
rc = moving_segm(*seg, to, flags);
}
break;
case processor_t::ev_coagulate:
{
///< Try to define some unexplored bytes.
///< This notification will be called if the
///< kernel tried all possibilities and could
///< not find anything more useful than to
///< convert to array of bytes.
///< The module can help the kernel and convert
///< the bytes into something more useful.
auto start_ea = va_arg(va, ::ea_t);
///< \return number of converted bytes
hextracelog("ea=%08x\n", start_ea);
rc = coagulate(start_ea);
}
break;
case processor_t::ev_undefine:
{
///< An item in the database (insn or data) is being deleted.
auto ea = va_arg(va, ea_t);
///< \return 1 do not delete srranges at the item end
///< \return 0 srranges can be deleted
hextracelog("ea=%08x\n", ea);
rc = undefine(ea);
}
break;
case processor_t::ev_treat_hindering_item:
{
///< An item hinders creation of another item.
auto hindering_item_ea = va_arg(va, ::ea_t);
auto new_item_flags = va_arg(va, ::flags_t); // (0 for code)
auto new_item_ea = va_arg(va, ::ea_t);
auto new_item_length = va_arg(va, ::asize_t);
///< \retval 0 no reaction
///< \retval !=0 the kernel may delete the hindering item
hextracelog("item=%08x, newflag=%08x, newea=%08x, newlen=%d\n", hindering_item_ea, new_item_flags, new_item_ea, new_item_length);
rc = treat_hindering_item(hindering_item_ea, new_item_flags, new_item_ea, new_item_length);
}
break;
case processor_t::ev_rename:
{
///< The kernel is going to rename a byte.
auto ea = va_arg(va, ::ea_t);
auto new_name = va_arg(va, const char *);
auto flags = va_arg(va, int); // \ref SN_
///< \return <0 if the kernel should not rename it.
///< \return 2 to inhibit the notification. I.e.,
///< the kernel should not rename, but
///< 'set_name()' should return 'true'.
///< also see \idpcode{renamed}
///< the return value is ignored when kernel is going to delete name
hextracelog("ea=%08x, newname='%s', fl=%08x\n",ea, new_name, flags);
rc = rename(ea, new_name, flags);
}
break;
case processor_t::ev_is_far_jump:
{
///< is indirect far jump or call instruction?
///< meaningful only if the processor has 'near' and 'far' reference types
auto icode = va_arg(va, int);
///< \return 0 not implemented
///< \return 1 yes
///< \return -1 no
hextracelog("icode=%d\n", icode);
rc = is_far_jump(icode);
}
break;
case processor_t::ev_is_sane_insn:
{
///< Is the instruction sane for the current file type?.
auto insn = va_arg(va, const ::insn_t*); // the instruction
auto no_crefs = va_arg(va, int);
///< 1: the instruction has no code refs to it.
///< ida just tries to convert unexplored bytes
///< to an instruction (but there is no other
///< reason to convert them into an instruction)
///< 0: the instruction is created because
///< of some coderef, user request or another
///< weighty reason.
///< \retval >=0 ok
///< \retval <0 no, the instruction isn't
///< likely to appear in the program
hextracelog("ea=%08x, nocref=%d\n", insn->ea, no_crefs);
rc = is_sane_insn(*insn, no_crefs);
}
break;
case processor_t::ev_is_cond_insn:
{
///< Is conditional instruction?
auto insn = va_arg(va, const ::insn_t *); // instruction address
///< \retval 1 yes
///< \retval -1 no
///< \retval 0 not implemented or not instruction
hextracelog("ea=%08x\n", insn->ea);
rc = is_cond_insn(*insn);
}
break;
case processor_t::ev_is_call_insn:
{
///< Is the instruction a "call"?
auto insn = va_arg(va, const ::insn_t *); // instruction
///< \retval 0 unknown
///< \retval <0 no
///< \retval 1 yes
hextracelog("ea=%08x\n", insn->ea);
rc = is_call_insn(*insn);
}
break;
case processor_t::ev_is_ret_insn:
{
///< Is the instruction a "return"?
auto insn = va_arg(va, const ::insn_t *); // instruction
auto strict = va_argi(va, bool);
///< 1: report only ret instructions
///< 0: include instructions like "leave"
///< which begins the function epilog
///< \retval 0 unknown
///< \retval <0 no
///< \retval 1 yes
hextracelog("ea=%08x strict=%d\n", insn->ea, strict);
rc = is_ret_insn(*insn, strict);
}
break;
case processor_t::ev_may_be_func:
{
///< Can a function start here?
auto insn = va_arg(va, const ::insn_t*); // the instruction
auto state = va_arg(va, int); // autoanalysis phase
///< 0: creating functions
///< 1: creating chunks
///< \return probability 0..100
hextracelog("ea=%08x state=%d\n", insn->ea, state);
rc = may_be_func(*insn, state);
}
break;
case processor_t::ev_is_basic_block_end:
{
///< Is the current instruction end of a basic block?.
///< This function should be defined for processors
///< with delayed jump slots.
auto insn = va_arg(va, const ::insn_t*); // the instruction
auto call_insn_stops_block = va_argi(va, bool);
///< \retval 0 unknown
///< \retval <0 no
///< \retval 1 yes
hextracelog("ea=%08x callstopsblock=%d\n", insn->ea, call_insn_stops_block);
rc = is_basic_block_end(*insn, call_insn_stops_block);
}
break;
case processor_t::ev_is_indirect_jump:
{
///< Determine if instruction is an indirect jump.
///< If #CF_JUMP bit can not describe all jump types
///< jumps, please define this callback.
auto insn = va_arg(va, const ::insn_t*); // the instruction
///< \retval 0 use #CF_JUMP
///< \retval 1 no
///< \retval 2 yes
hextracelog("ea=%08x\n", insn->ea);
rc = is_indirect_jump(*insn);
}
break;
case processor_t::ev_is_insn_table_jump:
{
///< Determine if instruction is a table jump or call.
///< If #CF_JUMP bit can not describe all kinds of table
///< jumps, please define this callback.
///< It will be called for insns with #CF_JUMP bit set.
auto insn = va_arg(va, const ::insn_t*); // the instruction
///< \retval 0 yes
///< \retval <0 no
hextracelog("ea=%08x\n", insn->ea);
rc = is_insn_table_jump(*insn);
}
break;
case processor_t::ev_is_switch:
{
///< Find 'switch' idiom.
///< It will be called for instructions marked with #CF_JUMP.
auto si = va_arg(va, switch_info_t *); // out
auto insn = va_arg(va, const ::insn_t *); // instruction possibly belonging to a switch
///< \retval 1 switch is found, 'si' is filled
///< \retval 0 no switch found or not implemented
hextracelog("si=%p, ea=%08x\n", si, insn->ea);
rc = is_switch(*si, *insn);
}
break;
case processor_t::ev_calc_switch_cases:
{
///< Calculate case values and targets for a custom jump table.
auto casevec = va_arg(va, ::casevec_t *); // vector of case values (may be NULL)
auto targets = va_arg(va, ::eavec_t *); // corresponding target addresses (my be NULL)
auto insn_ea = va_arg(va, ::ea_t); // address of the 'indirect jump' instruction
auto si = va_arg(va, ::switch_info_t *); // switch information
///< \retval 1 ok
///< \retval <=0 failed
hextracelog("cvec=%p, target=%p, ea=%08x, si=%p\n", casevec, targets, insn_ea, si);
rc = calc_switch_cases(casevec, targets, insn_ea, *si);
}
break;
case processor_t::ev_create_switch_xrefs:
{
///< Create xrefs for a custom jump table.
auto jumpea = va_arg(va, ::ea_t); // address of the jump insn
auto si = va_arg(va, const ::switch_info_t *); // switch information
///< \return must return 1
///< Must be implemented if module uses custom jump tables, \ref SWI_CUSTOM
hextracelog("jumpea=%08x, si=%p\n", jumpea, si);
rc = create_switch_xrefs(jumpea, *si);
}
break;
case processor_t::ev_is_align_insn:
{
///< Is the instruction created only for alignment purposes?.
/// Do not directly call this function, use ::is_align_insn()
auto ea = va_arg(va, ea_t); // - instruction address
///< \retval number of bytes in the instruction
hextracelog("ea=%08x\n", ea);
rc = is_align_insn(ea);
}
break;
case processor_t::ev_is_alloca_probe:
{
///< Does the function at 'ea' behave as __alloca_probe?
auto ea = va_arg(va, ::ea_t);
///< \retval 1 yes
///< \retval 0 no
hextracelog("ea=%08x\n", ea);
rc = is_alloca_probe(ea);
}
break;
case processor_t::ev_delay_slot_insn:
{
///< Get delay slot instruction
auto ea = va_arg(va, ::ea_t *); // instruction address in question,
///< if answer is positive then set 'ea' to
///< the delay slot insn address
auto bexec = va_arg(va, bool *); // execute slot if jumping,
///< initially set to 'true'
auto fexec = va_arg(va, bool *); // execute slot if not jumping,
///< initally set to 'true'
///< \retval 1 positive answer
///< \retval <=0 ordinary insn
///< \note Input 'ea' may point to the instruction with a delay slot or
///< to the delay slot instruction itself.
hextracelog("ea=%p:%08x f=%p, b=%p", ea, *ea, bexec, fexec);
rc = delay_slot_insn(ea, bexec, fexec);
hextracelog(" -> ea=%08x bexec=%d, fexec=%d", *ea, *bexec, *fexec);
}
break;
case processor_t::ev_is_sp_based:
{
///< Check whether the operand is relative to stack pointer or frame pointer
///< This event is used to determine how to output a stack variable
///< If not implemented, then all operands are sp based by default.
///< Implement this event only if some stack references use frame pointer
///< instead of stack pointer.
auto mode = va_arg(va, int *); // out, combination of \ref OP_FP_SP
auto insn = va_arg(va, const insn_t *);
auto op = va_arg(va, const op_t *);
///< \return 0 not implemented
///< \return 1 ok
hextracelog("mode=%p, insn=%08x, op=%d.%d", mode, insn->ea, op->n, op->type);
rc = is_sp_based(mode, *insn, *op);
hextracelog(" -> mode=%d\n", *mode);
}
break;
case processor_t::ev_can_have_type:
{
///< Can the operand have a type as offset, segment, decimal, etc?
///< (for example, a register AX can't have a type, meaning that the user can't
///< change its representation. see bytes.hpp for information about types and flags)
auto op = va_arg(va, const ::op_t *);
///< \retval 0 unknown
///< \retval <0 no
///< \retval 1 yes
hextracelog("op=%d.%d", op->n, op->type);
rc = can_have_type(*op);
}
break;
case processor_t::ev_cmp_operands:
{
///< Compare instruction operands
auto op1 = va_arg(va, const ::op_t*);
auto op2 = va_arg(va, const ::op_t*);
///< \retval 1 equal
///< \retval -1 not equal
///< \retval 0 not implemented
hextracelog("op1=%d.%d, op2=%d.%d", op1->n, op1->type, op2->n, op2->type);
rc = cmp_operands(*op1, *op2);
}
break;
case processor_t::ev_adjust_refinfo:
{
///< Called from apply_fixup before converting operand to reference.
///< Can be used for changing the reference info.
auto ri = va_arg(va, refinfo_t *);
auto ea = va_arg(va, ::ea_t); // instruction address
auto n = va_arg(va, int); // operand number
auto fd = va_arg(va, const fixup_data_t *);
///< \return < 0 - do not create an offset
///< \return 0 - not implemented or refinfo adjusted
hextracelog("ri=%p, ea=%08x, n=%d, fd=%p\n", ri, ea, n, fd);
rc = adjust_refinfo(*ri, ea, n, *fd);
}
break;
case processor_t::ev_get_operand_string:
{
///< Request text string for operand (cli, java, ...).
auto buf = va_arg(va, qstring *);
auto insn = va_arg(va, const ::insn_t*); // the instruction
auto opnum = va_arg(va, int); // operand number, -1 means any string operand
///< \return 0 no string (or empty string)
///< >0 original string length without terminating zero
hextracelog("buf=%p, insn=%08x, n=%d", buf, insn->ea, opnum);
rc = get_operand_string(buf, *insn, opnum);
hextracelog(" -> buf='%s'\n", buf->c_str());