-
Notifications
You must be signed in to change notification settings - Fork 21
/
collab_hooks.cpp
2630 lines (2491 loc) · 80.9 KB
/
collab_hooks.cpp
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
/*
IDA Pro Collaboration/Synchronization Plugin
Copyright (C) 2018 Chris Eagle <cseagle at gmail d0t com>
Copyright (C) 2018 Tim Vidas <tvidas at gmail d0t com>
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 2 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, write to the Free Software Foundation, Inc., 59 Temple
Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* This is the collabREate plugin
*
* It is known to compile with
*
* Microsoft Visual C++
* g++/make
*
*/
/*
* Functions in this file are responsible for handling notifications
* generated by IDA
*/
#include "collabreate.h"
#include <pro.h>
#include <ida.hpp>
#include <idp.hpp>
#include <bytes.hpp>
#include <loader.hpp>
#include <kernwin.hpp>
#include <netnode.hpp>
#include <typeinf.hpp>
#include <struct.hpp>
#if IDA_SDK_VERSION >= 700
#include <range.hpp>
#else
#include <area.hpp>
#endif
#include <frame.hpp>
#include <segment.hpp>
#include <enum.hpp>
#include <xref.hpp>
#include <nalt.hpp>
#include <offset.hpp>
#include <auto.hpp>
#include <json-c/json.h>
#include <map>
#include <string>
using std::map;
using std::string;
#if IDA_SDK_VERSION < 560
#define opinfo_t typeinfo_t
#endif
#ifndef DEBUG
//#define DEBUG 1
#endif
const char *idp_messages[] = {
#if IDA_SDK_VERSION < 700
//enum idp_notify
"init", //0
"term", //1
"newprc",//2
"newasm",//3
"newfile",//4
"oldfile",//5
"newbinary",//6
"endbinary",//7
"newseg",//8
"assemble",//9
"obsolete_makemicro",//10
"outlabel",//11
"rename",//12
"may_show_sreg",//13
"closebase",//14
"load_idasgn",//15
"coagulate",//16
"auto_empty",//17
"auto_queue_empty",//18
"func_bounds",//19
"may_be_func",//20
"is_sane_insn",//21
"is_jump_func",//22
"gen_regvar_def",//23
"setsgr",//24
"set_compiler",//25
"is_basic_block_end",//26
"reglink",//27
"get_vxd_name",//28
"custom_ana",//29
"custom_out",//30
"custom_emu",//31
"custom_outop",//32
"custom_mnem",//33
"undefine",//34
"make_code",//35
"make_data",//36
"moving_segm",//37
"move_segm",//38
"is_call_insn",//39
"is_ret_insn",//40
"get_stkvar_scale_factor",//41
"create_flat_group",//42
"kernel_config_loaded",//43
"might_change_sp",//44
"is_alloca_probe",//45
"out_3byte",//46
"get_reg_name",//47
"savebase",//48
"gen_asm_or_lst",//49
"out_src_file_lnnum",//50
"get_autocmt",//51
"is_insn_table_jump",//52
"auto_empty_finally",//53
"loader_finished",//54
"loader_elf_machine",//55
"is_indirect_jump",//56
"verify_noreturn",//57
"verify_sp",//58
"renamed",//59
"add_func",//60
"del_func",//61
"set_func_start",//62
"set_func_end",//63
"treat_hindering_item",//64
"str2reg",//65
"create_switch_xrefs",//66
"calc_switch_cases",//67
"determined_main",//68
"preprocess_chart",//69
"get_bg_color",//70
"validate_flirt_func",//71
"get_operand_string",//72
"add_cref",//73
"add_dref",//74
"del_cref",//75
"del_dref",//76
"coagulate_dref",//77
"register_custom_fixup",//78
"custom_refinfo",//79
"set_proc_options",//80
"adjust_libfunc_ea",//81
"extlang_changed",//82
"delay_slot_insn",//83
"adjust_refinfo",//84
"last_cb_before_debugger",//85
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
#ifdef NO_OBSOLETE_FUNCS
"obsolete_get_operand_info",//100
#else
"get_operand_info",//100
#endif
"get_reg_info",//101
#ifdef NO_OBSOLETE_FUNCS
"next_exec_insn",//102
#else
"get_jump_target",//102
#endif
"calc_step_over",//103
"get_macro_insn_head",//104
"get_dbr_opnum",//105
"insn_reads_tbit",//106
#ifdef NO_OBSOLETE_FUNCS
"get_operand_info",//107
#else
"reserved_entry",//107
#endif
"calc_next_eas",//108
"clean_tbit",//109
"get_reg_info2"//110
/*
"decorate_name",//500
"setup_til",//501
"based_ptr",//502
"max_ptr_size",//503
"get_default_enum_size",//504
"OBSOLETE(calc_arglocs)",//505
"use_stkarg_type",//506
"OBSOLETE(use_regarg_type)",//507
"OBSOLETE(use_arg_types)",//508
"OBSOLETE(get_fastcall_regs)",//509
"OBSOLETE(get_thiscall_regs)",//510
"OBSOLETE(calc_cdecl_purged_bytes)",//511
"OBSOLETE(get_stkarg_offset)",//512
"calc_purged_bytes",//513
"calc_arglocs2",//514
"calc_retloc",//515
"calc_varglocs",//516
"OBSOLETE(get_varcall_regs)",//517
"use_regarg_type2",//518
"use_arg_types2",//519
"get_fastcall_regs2",//520
"get_thiscall_regs2",//521
"get_varcall_regs2",//522
"calc_cdecl_purged_bytes2",//523
"get_stkarg_offset2",//524
"til_for_file",//525
"equal_reglocs",//526
"decorate_name3",//527
"calc_retloc3",//528
"calc_varglocs3",//529
"calc_arglocs3",//530
"use_stkarg_type3",//531
"use_regarg_type3",//532
"use_arg_types3",//533
"calc_purged_bytes3",//534
"shadow_args_size",//535
"get_varcall_regs3",//536
"get_fastcall_regs3",//537
"get_thiscall_regs3",//538
"loader=1000",//1000
*/
#else
"ev_init",
"ev_term",
"ev_newprc",
"ev_newasm",
"ev_newfile",
"ev_oldfile",
"ev_newbinary",
"ev_endbinary",
"ev_set_idp_options",
"ev_set_proc_options",
"ev_ana_insn",
"ev_emu_insn",
"ev_out_header",
"ev_out_footer",
"ev_out_segstart",
"ev_out_segend",
"ev_out_assumes",
"ev_out_insn",
"ev_out_mnem",
"ev_out_operand",
"ev_out_data",
"ev_out_label",
"ev_out_special_item",
"ev_gen_stkvar_def",
"ev_gen_regvar_def",
"ev_gen_src_file_lnnum",
"ev_creating_segm",
"ev_moving_segm",
"ev_coagulate",
"ev_undefine",
"ev_treat_hindering_item",
"ev_rename",
"ev_is_far_jump",
"ev_is_sane_insn",
"ev_is_cond_insn",
"ev_is_call_insn",
"ev_is_ret_insn",
"ev_may_be_func",
"ev_is_basic_block_end",
"ev_is_indirect_jump",
"ev_is_insn_table_jump",
"ev_is_switch",
"ev_calc_switch_cases",
"ev_create_switch_xrefs",
"ev_is_align_insn",
"ev_is_alloca_probe",
"ev_delay_slot_insn",
"ev_is_sp_based",
"ev_can_have_type",
"ev_cmp_operands",
"ev_adjust_refinfo",
"ev_get_operand_string",
"ev_get_reg_name",
"ev_str2reg",
"ev_get_autocmt",
"ev_get_bg_color",
"ev_is_jump_func",
"ev_func_bounds",
"ev_verify_sp",
"ev_verify_noreturn",
"ev_create_func_frame",
"ev_get_frame_retsize",
"ev_get_stkvar_scale_factor",
"ev_demangle_name",
"ev_add_cref",
"ev_add_dref",
"ev_del_cref",
"ev_del_dref",
"ev_coagulate_dref",
"ev_may_show_sreg",
"ev_loader_elf_machine",
"ev_auto_queue_empty",
"ev_validate_flirt_func",
"ev_adjust_libfunc_ea",
"ev_assemble",
"ev_extract_address",
"ev_realcvt",
"ev_gen_asm_or_lst",
"ev_gen_map_file",
"ev_create_flat_group",
"ev_getreg",
"ev_last_cb_before_debugger",
"ev_next_exec_insn", //1000
"ev_calc_step_over",
"ev_calc_next_eas",
"ev_get_macro_insn_head",
"ev_get_dbr_opnum",
"ev_insn_reads_tbit",
"ev_clean_tbit",
"ev_get_idd_opinfo",
"ev_get_reg_info",
"ev_last_cb_before_type_callbacks",
"ev_setup_til", //2000
"ev_get_abi_info",
"ev_max_ptr_size",
"ev_get_default_enum_size",
"ev_get_cc_regs",
"ev_get_stkarg_offset",
"ev_shadow_args_size",
"ev_get_simd_types",
"ev_calc_cdecl_purged_bytes",
"ev_calc_purged_bytes",
"ev_calc_retloc",
"ev_calc_arglocs",
"ev_calc_varglocs",
"ev_adjust_argloc",
"ev_lower_func_type",
"ev_equal_reglocs",
"ev_use_stkarg_type",
"ev_use_regarg_type",
"ev_use_arg_types",
"ev_arg_addrs_ready",
"ev_decorate_name",
"ev_loader" //3000
#endif
};
static unsigned int num_idp = (sizeof(idp_messages) / sizeof(const char*));
const char *idb_messages[] = {
//enum event_code_t
#if IDA_SDK_VERSION < 700
"byte_patched", //0
"cmt_changed", //1
"ti_changed", //2
"op_ti_changed", //3
"op_type_changed", //4
"enum_created", //5
"enum_deleted", //6
"enum_bf_changed", //7
"enum_renamed", //8
"enum_cmt_changed", //9
#ifndef NO_OBSOLETE_FUNCS
"enum_const_created", //10
"enum_const_deleted", //11
#else
"enum_member_created", //10
"enum_member_deleted", //11
#endif
"struc_created", //12
"struc_deleted", //13
"struc_renamed", //14
"struc_expanded", //15
"struc_cmt_changed", //16
"struc_member_created", //17
"struc_member_deleted", //18
"struc_member_renamed", //19
"struc_member_changed", //20
"thunk_func_created", //21
"func_tail_appended", //22
"func_tail_removed", //23
"tail_owner_changed", //24
"func_noret_changed", //25
"segm_added", //26
"segm_deleted", //27
"segm_start_changed", //28
"segm_end_changed", //29
"segm_moved", //30
"area_cmt_changed", //31
"changing_cmt", //32
"changing_ti", //33
"changing_op_ti", //34
"changing_op_type", //35
"deleting_enum", //36
"changing_enum_bf", //37
"renaming_enum", //38
"changing_enum_cmt", //39
#ifndef NO_OBSOLETE_FUNCS
"deleting_enum_const", //40
#else
"deleting_enum_member", //40
#endif
"deleting_struc", //41
"renaming_struc", //42
"expanding_struc", //43
"changing_struc_cmt", //44
"deleting_struc_member", //45
"renaming_struc_member", //46
"changing_struc_member", //47
"removing_func_tail", //48
"deleting_segm", //49
"changing_segm_start", //50
"changing_segm_end", //51
"changing_area_cmt", //52
"changing_segm_name", //53
"changing_segm_class", //54
"segm_name_changed", //55
"segm_class_changed", //56
"destroyed_items", //57
"changed_stkpnts", //58
"extra_cmt_changed", //59
"changing_struc", //60
"changed_struc", //61
"local_types_changed", //62
"segm_attrs_changed" //63
#else //IDA_SDK_VERSION >= 700
"closebase",
"savebase",
"upgraded",
"auto_empty",
"auto_empty_finally",
"determined_main",
"local_types_changed",
"extlang_changed",
"idasgn_loaded",
"kernel_config_loaded",
"loader_finished",
"flow_chart_created",
"compiler_changed",
"changing_ti",
"ti_changed",
"changing_op_ti",
"op_ti_changed",
"changing_op_type",
"op_type_changed",
"enum_created",
"deleting_enum",
"enum_deleted",
"renaming_enum",
"enum_renamed",
"changing_enum_bf",
"enum_bf_changed",
"changing_enum_cmt",
"enum_cmt_changed",
"enum_member_created",
"deleting_enum_member",
"enum_member_deleted",
"struc_created",
"deleting_struc",
"struc_deleted",
"changing_struc_align",
"struc_align_changed",
"renaming_struc",
"struc_renamed",
"expanding_struc",
"struc_expanded",
"struc_member_created",
"deleting_struc_member",
"struc_member_deleted",
"renaming_struc_member",
"struc_member_renamed",
"changing_struc_member",
"struc_member_changed",
"changing_struc_cmt",
"struc_cmt_changed",
"segm_added",
"deleting_segm",
"segm_deleted",
"changing_segm_start",
"segm_start_changed",
"changing_segm_end",
"segm_end_changed",
"changing_segm_name",
"segm_name_changed",
"changing_segm_class",
"segm_class_changed",
"segm_attrs_updated",
"segm_moved",
"allsegs_moved",
"func_added",
"func_updated",
"set_func_start",
"set_func_end",
"deleting_func",
"frame_deleted",
"thunk_func_created",
"func_tail_appended",
"deleting_func_tail",
"func_tail_deleted",
"tail_owner_changed",
"func_noret_changed",
"stkpnts_changed",
"updating_tryblks",
"tryblks_updated",
"deleting_tryblks",
"sgr_changed",
"make_code",
"make_data",
"destroyed_items",
"renamed",
"byte_patched",
"changing_cmt",
"cmt_changed",
"changing_range_cmt",
"range_cmt_changed",
"extra_cmt_changed"
#endif
};
static unsigned int num_idb = (sizeof(idb_messages) / sizeof(const char*));
//Given a frame pointer, determine which if any function owns it.
//This is a reverse lookup on stack frame structures
func_t *func_from_frame(struc_t *frame) {
size_t qty = get_func_qty();
for (size_t i = 0; i < qty; i++) {
func_t *f = getn_func(i);
if (f->frame == frame->id) return f;
}
return NULL;
}
void idp_undefine(ea_t ea) {
//send address to server
json_object *obj = json_object_new_object();
if (send_json(ea, COMMAND_UNDEFINE, obj) == 0) {
qstring s;
format_llx(ea, s);
msg(PLUGIN_NAME": send error on undefine 0x%s\n", s.c_str());
}
}
void idp_make_code(ea_t ea, asize_t len) {
//send address and length to server
json_object *obj = json_object_new_object();
append_json_uint64_val(obj, "length", (uint64_t)len);
if (send_json(ea, COMMAND_MAKE_CODE, obj) == 0) {
qstring s;
format_llx(ea, s);
msg(PLUGIN_NAME": send error on make_code 0x%s, %d\n", s.c_str(), (int)len);
}
}
void idp_make_data(ea_t ea, flags_t f, tid_t t, asize_t len) {
//send all to server
json_object *obj = json_object_new_object();
append_json_uint64_val(obj, "length", (uint64_t)len);
append_json_uint64_val(obj, "flags", (uint64_t)f);
if (t != BADNODE) {
#if IDA_SDK_VERSION < 680
char name[MAXNAMESIZE];
get_struc_name(t, name, sizeof(name));
#else
qstring name;
get_struc_name(&name, t);
#endif
append_json_string_val(obj, "struc", name);
}
if (send_json(ea, COMMAND_MAKE_DATA, obj) == 0) {
qstring s;
format_llx(ea, s);
msg(PLUGIN_NAME": send error on make_data 0x%s, %x, %x, %d\n", s.c_str(), f, (uint32_t)t, (int)len);
}
}
void idp_move_segm(ea_t ea, segment_t *seg) {
json_object *obj = json_object_new_object();
append_json_ea_val(obj, "from", ea);
append_json_ea_val(obj, "to", seg->start_ea);
if (send_json(COMMAND_MOVE_SEGM, obj) == 0) {
qstring a1, a2;
format_llx(ea, a1);
format_llx(seg->start_ea, a2);
msg(PLUGIN_NAME": send error on move_segm 0x%s, 0x%s\n", a1.c_str(), a2.c_str());
}
}
void idp_renamed(ea_t ea, const char *new_name, bool is_local) {
//send all to server
json_object *obj = json_object_new_object();
append_json_bool_val(obj, "local", (json_bool)is_local);
append_json_string_val(obj, "name", new_name);
if (send_json(ea, COMMAND_RENAMED, obj) == 0) {
qstring a1;
format_llx(ea, a1);
msg(PLUGIN_NAME": send error on rename 0x%s, %s, %d\n", a1.c_str(), new_name, is_local);
}
}
void idp_add_func(func_t *pfn) {
//send start, end address, name, flags (bp etc), purged, locals, delta, args
json_object *obj = json_object_new_object();
append_json_ea_val(obj, "startea", pfn->start_ea);
append_json_ea_val(obj, "endea", pfn->end_ea);
send_json(COMMAND_ADD_FUNC, obj);
/*
if (send_data(b) == -1) {
qstring a1;
format_llx(pfn->start_ea, a1);
msg(PLUGIN_NAME": send error on add_func 0x%s\n", a1.c_str());
}
*/
}
void idp_del_func(func_t *pfn) {
//send start, end address, name, flags (bp etc), purged, locals, delta, args
json_object *obj = json_object_new_object();
send_json(pfn->start_ea, COMMAND_DEL_FUNC, obj);
/*
if (send_data(b) == -1) {
qstring a1;
format_llx(pfn->start_ea, a1);
msg(PLUGIN_NAME": send error on del_func 0x%s\n", a1.c_str());
}
*/
}
void idp_set_func_start(func_t *pfn, ea_t ea) {
//send pfn->start_ea and ea to server
json_object *obj = json_object_new_object();
append_json_ea_val(obj, "old_start", pfn->start_ea);
append_json_ea_val(obj, "new_start", ea);
send_json(COMMAND_SET_FUNC_START, obj);
/*
if (send_data(b) == -1) {
qstring a1, a2;
format_llx(pfn->start_ea, a1);
format_llx(ea, a2);
msg(PLUGIN_NAME": send error on set_func_start 0x%s, 0x%s\n", a1.c_str(), a2.c_str());
}
*/
}
void idp_set_func_end(func_t *pfn, ea_t ea) {
//send pfn->start_ea and ea to server
json_object *obj = json_object_new_object();
append_json_ea_val(obj, "startea", pfn->start_ea);
append_json_ea_val(obj, "endea", ea);
send_json(COMMAND_SET_FUNC_END, obj);
/*
if (send_data(b) == -1) {
qstring a1, a2;
format_llx(pfn->start_ea, a1);
format_llx(ea, a2);
msg(PLUGIN_NAME": send error on set_func_end 0x%s, 0x%s\n", a1.c_str(), a2.c_str());
}
*/
}
void idp_validate_flirt(ea_t ea, const char *name) {
//send ea and name to server, apply name and set library func flag on remote side
json_object *obj = json_object_new_object();
append_json_string_val(obj, "name", name);
append_json_ea_val(obj, "startea", ea);
func_t *f = get_func(ea);
if (f) {
append_json_ea_val(obj, "endea", f->end_ea);
}
send_json(COMMAND_VALIDATE_FLIRT_FUNC, obj);
/*
if (send_data(b) == -1) {
qstring a1;
format_llx(ea, a1);
msg(PLUGIN_NAME": send error on validate_flirt 0x%s, %s\n", a1.c_str(), name);
}
*/
}
void idp_add_cref(ea_t from, ea_t to, cref_t type) {
json_object *obj = json_object_new_object();
append_json_ea_val(obj, "from", from);
append_json_ea_val(obj, "to", to);
append_json_uint64_val(obj, "reftype", (uint64_t)type);
send_json(COMMAND_ADD_CREF, obj);
/*
if (send_data(b) == -1) {
qstring a1, a2;
format_llx(from, a1);
format_llx(to, a2);
msg(PLUGIN_NAME": send error on add_cref 0x%s, 0x%s, %x\n", a1.c_str(), a2.c_str(), type);
}
*/
}
void idp_add_dref(ea_t from, ea_t to, dref_t type) {
json_object *obj = json_object_new_object();
append_json_ea_val(obj, "from", from);
append_json_ea_val(obj, "to", to);
append_json_uint64_val(obj, "reftype", (uint64_t)type);
send_json(COMMAND_ADD_DREF, obj);
/*
if (send_data(b) == -1) {
qstring a1, a2;
format_llx(from, a1);
format_llx(to, a2);
msg(PLUGIN_NAME": send error on add_dref 0x%s, 0x%s, %x\n", a1.c_str(), a2.c_str(), type);
}
*/
}
void idp_del_cref(ea_t from, ea_t to, bool expand) {
json_object *obj = json_object_new_object();
append_json_ea_val(obj, "from", from);
append_json_ea_val(obj, "to", to);
append_json_bool_val(obj, "expand", (json_bool)expand);
send_json(COMMAND_DEL_CREF, obj);
/*
if (send_data(b) == -1) {
qstring a1, a2;
format_llx(from, a1);
format_llx(to, a2);
msg(PLUGIN_NAME": send error on del_cref 0x%s, 0x%s, %x\n", a1.c_str(), a2.c_str(), expand);
}
*/
}
void idp_del_dref(ea_t from, ea_t to) {
json_object *obj = json_object_new_object();
append_json_ea_val(obj, "from", from);
append_json_ea_val(obj, "to", to);
send_json(COMMAND_DEL_DREF, obj);
/*
if (send_data(b) == -1) {
qstring a1, a2;
format_llx(from, a1);
format_llx(to, a2);
msg(PLUGIN_NAME": send error on del_dref 0x%s, 0x%s\n", a1.c_str(), a2.c_str());
}
*/
}
void byte_patched(ea_t ea) {
json_object *obj = json_object_new_object();
uint32_t val = (uint32_t)get_byte(ea);
//send value to server
append_json_uint32_val(obj, "value", val);
send_json(ea, COMMAND_BYTE_PATCHED, obj);
/*
if (send_data(b) == -1) {
qstring a1;
format_llx(ea, a1);
msg(PLUGIN_NAME": send error on byte_patched 0x%s, %x\n", a1.c_str(), val);
}
*/
}
void comment_changed(ea_t ea, bool rep) {
#if IDA_SDK_VERSION < 700
ssize_t ssz = get_cmt(ea, rep, NULL, 0) + 1;
if (ssz != -1) {
size_t sz = (size_t)ssz;
char *cmt = (char*) qalloc(sz + 1);
if (cmt || sz == 0) {
if (sz) {
get_cmt(ea, rep, cmt, sz);
}
else {
cmt[0] = 0;
}
//send comment to server
json_object *obj = json_object_new_object();
append_json_string_val(obj, "text", cmt);
append_json_bool_val(obj, "rep", (json_bool)rep);
send_json(ea, COMMAND_CMT_CHANGED, obj);
/*
if (send_data(b) == -1) {
qstring a1;
format_llx(ea, a1);
msg(PLUGIN_NAME": send error on comment_changed 0x%s, %s\n", a1.c_str(), cmt);
}
*/
qfree(cmt);
}
}
#else
qstring cmt;
ssize_t ssz = get_cmt(&cmt, ea, rep);
if (ssz != -1) {
//send comment to server
json_object *obj = json_object_new_object();
append_json_string_val(obj, "text", cmt);
append_json_bool_val(obj, "rep", (json_bool)rep);
send_json(ea, COMMAND_CMT_CHANGED, obj);
}
#endif
}
void change_ti(ea_t ea, const type_t *type, const p_list *fnames) {
json_object *obj = json_object_new_object();
append_json_hex_val(obj, "ti", (const uint8_t*)type);
if (fnames) {
append_json_hex_val(obj, "fnames", (const uint8_t*)fnames);
}
send_json(ea, COMMAND_TI_CHANGED, obj);
/*
if (send_data(b) == -1) {
qstring a1;
format_llx(ea, a1);
msg(PLUGIN_NAME": send error on change_ti 0x%s\n", a1.c_str());
}
*/
}
void change_op_ti(ea_t ea, int n, const type_t *type, const p_list *fnames) {
json_object *obj = json_object_new_object();
append_json_hex_val(obj, "ti", (const uint8_t*)type);
if (fnames) {
append_json_hex_val(obj, "fnames", (const uint8_t*)fnames);
}
append_json_int32_val(obj, "opnum", n);
send_json(ea, COMMAND_OP_TI_CHANGED, obj);
/*
if (send_data(b) == -1) {
qstring a1;
format_llx(ea, a1);
msg(PLUGIN_NAME": send error on change_op_ti 0x%s\n", a1.c_str());
}
*/
}
//lookup structure offset info about operand n at address ea and
//add the information into the provided buffer
void gatherStructOffsetInfo(json_object *obj, ea_t ea, int n) {
json_object *jpath = json_object_new_array();
tid_t path[MAXSTRUCPATH];
adiff_t delta;
#if IDA_SDK_VERSION >= 700
int path_len = get_stroff_path(path, &delta, ea, n);
#else
int path_len = get_stroff_path(ea, n, path, &delta);
#endif
append_json_uint64_val(obj, "delta", (uint64_t)delta);
//iterate over the structure path, adding the name of each struct
//the the provided path. We pass names here rather than tid
//because different versions of IDA may assign different tid values
//the the same struct type
for (int i = 0; i < path_len; i++) {
#if IDA_SDK_VERSION < 680
char name[MAXNAMESIZE];
/*ssize_t sz =*/ get_struc_name(path[i], name, sizeof(name));
json_object *jname = json_object_new_string(name);
#else
qstring name;
/*ssize_t sz =*/ get_struc_name(&name, path[i]);
json_object *jname = json_object_new_string(name.c_str());
#endif
json_object_array_add(jpath, jname);
}
json_object_object_add_ex(obj, "path", jpath, JSON_NEW_CONST_KEY);
}
//lookup enum type info about operand n at address ea and
//add the information into the provided buffer
void gatherEnumInfo(json_object *obj, ea_t ea, int n) {
uchar serial;
#if IDA_SDK_VERSION >= 700
enum_t id = get_enum_id(&serial, ea, n);
#else
enum_t id = get_enum_id(ea, n, &serial);
#endif
#if IDA_SDK_VERSION < 680
char name[MAXNAMESIZE];
ssize_t len = get_enum_name(id, name, sizeof(name));
#else
qstring name;
ssize_t len = get_enum_name(&name, id);
#endif
if (len > 0) {
//We pass a name here rather than enum_t because different
//versions of IDA may assign different enum_t values
//the the same enum type
append_json_string_val(obj, "ename", name);
append_json_uint32_val(obj, "serial", serial);
}
}
void gatherRefInfo(json_object *obj, refinfo_t &ri) {
append_json_uint32_val(obj, "reft_and_flags", (uint32_t)ri.flags);
append_json_ea_val(obj, "target", (ea_t)ri.target);
append_json_ea_val(obj, "base", (ea_t)ri.base);
append_json_uint64_val(obj, "delta", (uint64_t)ri.tdelta);
}
/* FINISH ME */
void change_op_type(ea_t ea, int opnum) {
json_object *obj = json_object_new_object();
//send value to server
flags_t f = get_flags_novalue(ea);
if (opnum) {
if (opnum != 1) {
msg("change_op_type opnum == %d unexpected\n", opnum);
return;
}
f = get_optype_flags1(f);
if (isEnum1(f)) {
//need to figure out what enum it is
gatherEnumInfo(obj, ea, opnum);
}
else if (isStroff1(f)) {
//need to figure out what struct it is
gatherStructOffsetInfo(obj, ea, opnum);
}
else if (isOff1(f)) {
refinfo_t ri;
#if IDA_SDK_VERSION >= 700
if (!get_refinfo(&ri, ea, opnum)) {
#else
if (!get_refinfo(ea, opnum, &ri)) {
#endif
msg(PLUGIN_NAME": missing refinfo on offset in change_op_type %x, %x", (uint32_t)ea, opnum);
return;
}
if (ri.type() != REF_OFF32 || ri.target != BADADDR ||
ri.base != 0 || ri.tdelta != 0) {
gatherRefInfo(obj, ri);
}
}
}
else {
f = get_optype_flags0(f);
if (isEnum0(f)) {
//need to figure out what enum it is
gatherEnumInfo(obj, ea, opnum);
}
else if (isStroff0(f)) {
//need to figure out what struct it is
gatherStructOffsetInfo(obj, ea, opnum);
}
else if (isOff0(f)) {
refinfo_t ri;
#if IDA_SDK_VERSION >= 700
if (!get_refinfo(&ri, ea, opnum)) {
#else
if (!get_refinfo(ea, opnum, &ri)) {
#endif
msg(PLUGIN_NAME": missing refinfo on offset in change_op_type %x, %x", (uint32_t)ea, opnum);
return;
}
if (ri.type() != REF_OFF32 || ri.target != BADADDR ||
ri.base != 0 || ri.tdelta != 0) {
gatherRefInfo(obj, ri);
}
}
}
append_json_uint32_val(obj, "opnum", opnum);
append_json_uint32_val(obj, "flags", f);
send_json(ea, COMMAND_OP_TYPE_CHANGED, obj);
/*
if (send_data(b) == -1) {
qstring a1;
format_llx(ea, a1);
msg(PLUGIN_NAME": send error on change_op_type 0x%s, %x, %x\n", a1.c_str(), opnum, f);
}
*/
}
void create_enum(enum_t id) {
//get enum name (and fields?) and send to server
#if IDA_SDK_VERSION < 680
char name[MAXNAMESIZE];
ssize_t sz = get_enum_name(id, name, sizeof(name));
#else
qstring name;
ssize_t sz = get_enum_name(&name, id);
#endif
if (sz > 0) {
json_object *obj = json_object_new_object();
append_json_string_val(obj, "enum_name", name);
send_json(COMMAND_ENUM_CREATED, obj);
#if IDA_SDK_VERSION < 680
/*
if (send_data(b) == -1) {
msg(PLUGIN_NAME": send error on create_enum %s\n", name);
}
*/
cnn.supset(id, name, 0, COLLABREATE_ENUMS_TAG);
#else