-
Notifications
You must be signed in to change notification settings - Fork 27
/
postgresql_tables.sql
executable file
·4998 lines (4295 loc) · 176 KB
/
postgresql_tables.sql
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
-- Setup a binnavi compatible database
SET check_function_bodies = false;
SET default_tablespace = '';
SET default_with_oids = false;
CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
-- COMMENT ON EXTENSION plpgsql
-- IS 'PL/pgSQL procedural language';
--
-- Types section
--
--
-- address_reference_type
--
DROP TYPE IF EXISTS address_reference_type CASCADE;
CREATE TYPE address_reference_type AS ENUM (
'conditional_true',
'conditional_false',
'unconditional',
'switch',
'call_direct',
'call_indirect',
'call_virtual',
'data',
'data_string'
);
COMMENT ON TYPE address_reference_type
IS 'The address_reference_type defines all possible address reference types.';
--
-- architecture_type
--
DROP TYPE IF EXISTS architecture_type CASCADE;
CREATE TYPE architecture_type AS ENUM (
'x86-32',
'x86-64',
'ARM-32',
'PowerPC-32',
'PowerPC-64',
'MIPS-32',
'MIPS-64',
'GENERIC-32',
'GENERIC-64',
'REIL',
'RREIL'
);
COMMENT ON TYPE architecture_type
IS 'The architecture_type defines all architectures known to BinNavi.
Unknown architectures used the generic type.';
--
-- edge_type
--
DROP TYPE IF EXISTS edge_type CASCADE;
CREATE TYPE edge_type AS ENUM (
'jump_conditional_true',
'jump_conditional_false',
'jump_unconditional',
'jump_switch',
'jump_conditional_true_loop',
'jump_conditional_false_loop',
'jump_unconditional_loop',
'enter_inlined_function',
'leave_inlined_function',
'inter_module',
'inter_addressspace_edge',
'textnode_edge',
'dummy'
);
COMMENT ON TYPE edge_type
IS 'The edge_type defines all possible types of an edge.
This type is used in BinNavi to enable specific functions for an edge.';
--
-- function_type
--
DROP TYPE IF EXISTS function_type CASCADE;
CREATE TYPE function_type AS ENUM (
'normal',
'library',
'import',
'thunk',
'adjustor_thunk',
'invalid'
);
COMMENT ON TYPE function_type
IS 'The function_type defines all possible function types.
This type is used in BinNavi to enable specific functions for a function.';
--
-- node_type
--
DROP TYPE IF EXISTS node_type CASCADE;
CREATE TYPE node_type AS ENUM (
'code',
'function',
'group',
'text'
);
COMMENT ON TYPE node_type
IS 'The node_type defines all possible node type.
The type is used in BinNavi to enable specific functions for a node.';
--
-- permission type
--
DROP TYPE IF EXISTS permission_type CASCADE;
CREATE TYPE permission_type AS ENUM (
'READ',
'WRITE',
'EXECUTE',
'READ_WRITE',
'READ_EXECUTE',
'READ_WRITE_EXECUTE',
'WRITE_EXECUTE'
);
COMMENT ON TYPE permission_type
IS 'The permission_type is used to describe the permission a section has.
This information can either come from the exporter or from the debugger.';
--
-- tag_type
--
DROP TYPE IF EXISTS tag_type CASCADE;
CREATE TYPE tag_type AS ENUM (
'view_tag',
'node_tag'
);
COMMENT ON TYPE tag_type
IS 'The tag_type defines to which taggable instance the tags belongs.
A tag can either be a view tag or a node tag.';
--
-- view_type
--
DROP TYPE IF EXISTS view_type CASCADE;
CREATE TYPE view_type AS ENUM (
'native',
'non-native'
);
COMMENT ON TYPE view_type
IS 'The view_type defines where a view comes from.
Native views come from the export / disassembler.
Non-native views have been generated in BinNavi.
Native views are immutable.';
--
-- type_cagetory
--
DROP TYPE IF EXISTS type_category CASCADE;
CREATE TYPE type_category AS ENUM (
'atomic',
'array',
'pointer',
'struct',
'union',
'function_pointer'
);
COMMENT ON TYPE type_category
IS 'The type_category enum specifies the category of a given base type as defined in a C type system.';
--
-- Begin trigger section.
--
--
-- bn_sections_trigger()
--
CREATE OR REPLACE FUNCTION bn_sections_trigger()
RETURNS trigger AS
$$
BEGIN
IF ( TG_OP = 'INSERT' ) THEN
PERFORM pg_notify('section_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.id );
RETURN NEW;
ELSIF ( TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('section_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.id );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('section_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.module_id || ' ' || OLD.id );
RETURN OLD;
END IF;
END;
$$ LANGUAGE plpgsql VOLATILE
COST 100;
COMMENT ON FUNCTION bn_sections_trigger()
IS 'The bn_sections_trigger is called for all altering operations on the bn_sections table and will perform a pg_notify with the altered information.
This information will be used in BinNavi to provide synchronisation between multiple instances of BinNavi';
--
-- bn_types_trigger()
--
CREATE OR REPLACE FUNCTION bn_types_trigger()
RETURNS trigger AS
$$
BEGIN
IF ( TG_OP = 'INSERT' ) THEN
PERFORM pg_notify('types_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.id );
RETURN NEW;
ELSIF ( TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('types_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.id );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('types_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.module_id || ' ' || OLD.id );
RETURN OLD;
END IF;
END;
$$
LANGUAGE plpgsql VOLATILE COST 100;
COMMENT ON FUNCTION bn_types_trigger() IS 'The bn_types_trigger is called for all altering operations on the bn_types table and will perform a pg_notify with the altered information.
This information will be used in BinNavi to provide synchronisation between multiple instances of BinNavi';
--
-- bn_base_types_trigger()
--
CREATE OR REPLACE FUNCTION bn_base_types_trigger()
RETURNS trigger AS
$$
BEGIN
IF ( TG_OP = 'INSERT' ) THEN
PERFORM pg_notify('types_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.id );
RETURN NEW;
ELSIF ( TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('types_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.id );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('types_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.module_id || ' ' || OLD.id );
RETURN OLD;
END IF;
END;
$$
LANGUAGE plpgsql VOLATILE COST 100;
COMMENT ON FUNCTION bn_base_types_trigger() IS 'The bn_base_types_trigger is called for all altering operations on the bn_base_types table and will perform a pg_notify with the altered information.
This information will be used in BinNavi to provide synchronisation between multiple instances of BinNavi';
--
-- bn_type_instances_trigger()
--
CREATE OR REPLACE FUNCTION bn_type_instances_trigger()
RETURNS trigger AS
$BODY$
BEGIN
IF ( TG_OP = 'INSERT' ) THEN
PERFORM pg_notify('type_instances_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.id );
RETURN NEW;
ELSIF ( TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('type_instances_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.id );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('type_instances_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.module_id || ' ' || OLD.id );
RETURN OLD;
END IF;
END;
$BODY$
LANGUAGE plpgsql VOLATILE COST 100;
COMMENT ON FUNCTION bn_type_instances_trigger() IS 'The bn_expression_type_instances_trigger is called for all altering operations on the bn_expression_type_instances table and will perform a pg_notify with the altered information.
This information will be used in BinNavi to provide synchronisation between multiple instances of BinNavi.';
--
-- bn_type_instances_comment_trigger()
--
CREATE OR REPLACE FUNCTION bn_type_instances_comment_trigger()
RETURNS trigger AS
$$
DECLARE
comment text;
BEGIN
IF ( TG_OP = 'UPDATE') THEN
IF ( NEW.comment_id is null) THEN
comment = 'null';
ELSE
comment = CAST(NEW.comment_id AS TEXT);
END IF;
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.id || ' ' || comment );
RETURN NEW;
END IF;
END;
$$
LANGUAGE plpgsql VOLATILE COST 100;
COMMENT ON FUNCTION bn_type_instances_comment_trigger() IS 'The bn_type_instances_comment_trigger is called for UPDATE operations on the bn_type_instances table an will perform a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of comments associated to type instances between multiple instances of BinNavi.';
--
-- bn_expression_types_trigger()
--
CREATE OR REPLACE FUNCTION bn_expression_types_trigger()
RETURNS trigger AS
$$
BEGIN
IF ( TG_OP = 'INSERT' ) THEN
PERFORM pg_notify('types_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.address || ' ' || NEW."position" || ' ' || NEW.expression_id);
RETURN NEW;
ELSIF ( TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('types_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.address || ' ' || NEW."position" || ' ' || NEW.expression_id);
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('types_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.module_id || ' ' || OLD.address || ' ' || OLD."position" || ' ' || OLD.expression_id);
RETURN OLD;
END IF;
END;
$$
LANGUAGE plpgsql VOLATILE COST 100;
COMMENT ON FUNCTION bn_expression_types_trigger() IS 'The bn_expression_types_trigger is called for all altering operations on the bn_expression_types table and will perform a pg_notify with the altered information.
This information will be used in BinNavi to provide synchronization between multiple instances of BinNavi';
--
-- bn_ecpression_type_instances_trigger()
--
CREATE OR REPLACE FUNCTION bn_expression_type_instances_trigger()
RETURNS trigger AS
$BODY$
BEGIN
IF ( TG_OP = 'INSERT' ) THEN
PERFORM pg_notify('type_instances_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.address || ' ' || NEW."position" || ' ' || NEW.expression_id || ' ' || NEW.type_instance_id);
RETURN NEW;
ELSIF ( TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('type_instances_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.address || ' ' || NEW."position" || ' ' || NEW.expression_id || ' ' || NEW.type_instance_id);
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('type_instances_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.module_id || ' ' || OLD.address || ' ' || OLD."position" || ' ' || OLD.expression_id || ' ' || OLD.type_instance_id);
RETURN OLD;
END IF;
END;
$BODY$
LANGUAGE plpgsql VOLATILE COST 100;
COMMENT ON FUNCTION bn_expression_type_instances_trigger() IS 'The bn_expression_type_instances_trigger is called for all operations on the bn_expression_type_instances table an will perform a pg_notify with the altered information.
This information is used in BinNavi to provide synchronization of type instances associated to type instances between multiple instances of BinNavi.';
--
-- bn_functions_trigger()
--
CREATE OR REPLACE FUNCTION bn_functions_trigger()
RETURNS trigger AS
$$
BEGIN
IF ( TG_OP = 'INSERT' ) THEN
PERFORM pg_notify('function_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.address );
RETURN NEW;
ELSIF ( TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('function_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.address );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('function_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.module_id || ' ' || OLD.address );
RETURN OLD;
END IF;
END;
$$
LANGUAGE plpgsql VOLATILE
COST 100;
COMMENT ON FUNCTION bn_functions_trigger()
IS 'The bn_functions_trigger is called for all altering operations on the bn_functions table and will perform a pg_notify with the altered information.
This information will be used in BinNavi to provide synchronisation between multiple instances of BinNavi';
--
-- bn_module_views_trigger()
--
CREATE OR REPLACE FUNCTION bn_module_views_trigger()
RETURNS trigger AS
$$
BEGIN
IF ( TG_OP = 'INSERT' ) THEN
PERFORM pg_notify('view_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.view_id || ' ' || NEW.module_id );
RETURN NEW;
ELSIF ( TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('view_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.view_id || ' ' || NEW.module_id );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('view_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.view_id || ' ' || OLD.module_id );
RETURN OLD;
END IF;
END;
$$
LANGUAGE plpgsql VOLATILE
COST 100;
COMMENT ON FUNCTION bn_module_views_trigger()
IS 'The bn_module_views_trigger is called for all altering operations on the bn_module_views table and will perform a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of module views between multiple instances of BinNavi.';
--
-- bn_project_views_trigger()
--
CREATE OR REPLACE FUNCTION bn_project_views_trigger()
RETURNS trigger AS
$$
BEGIN
IF ( TG_OP = 'INSERT' ) THEN
PERFORM pg_notify('view_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.view_id || ' ' || NEW.project_id );
RETURN NEW;
ELSIF ( TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('view_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.view_id || ' ' || NEW.project_id );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('view_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.view_id || ' ' || OLD.project_id );
RETURN OLD;
END IF;
END;
$$
LANGUAGE plpgsql VOLATILE
COST 100;
COMMENT ON FUNCTION bn_project_views_trigger()
IS 'The bn_project_views_trigger is called for all altering operations on the bn_project_views table and will perform a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of project views between multiple instances of BinNavi.';
--
-- bn_views_trigger()
--
CREATE OR REPLACE FUNCTION bn_views_trigger()
RETURNS trigger AS
$$
BEGIN
IF ( TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('view_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.id );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('view_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.id );
RETURN OLD;
END IF;
END;
$$
LANGUAGE plpgsql VOLATILE
COST 100;
COMMENT ON FUNCTION bn_views_trigger()
IS 'The bn_views_trigger is called for UPDATE and DELETE operations on the bn_views table and will perform a pg_notify with the altered information.
This infromation is used in BinNavi to provide synchronisation of views between multiple instances of BinNavi.';
--
-- bn_comments_trigger()
--
CREATE OR REPLACE FUNCTION bn_comments_trigger()
RETURNS trigger
LANGUAGE plpgsql
AS
$$
DECLARE
comment text;
parentid text;
BEGIN
IF ( TG_OP = 'UPDATE') THEN
IF ( NEW.comment_text IS NULL) THEN
comment = 'null';
ELSE
comment = CAST(NEW.comment_text AS TEXT);
END IF;
IF( NEW.parent_id IS NULL) THEN
parentid = 'null';
ELSE
parentid = CAST(NEW.parent_id AS TEXT);
END IF;
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.id || ' ' || parentid || ' ' || NEW.user_id || ' ' || comment );
RETURN NEW;
ELSIF (TG_OP = 'DELETE') THEN
IF ( OLD.comment_text IS NULL) THEN
comment = 'null';
ELSE
comment = CAST(OLD.comment_text AS TEXT);
END IF;
IF( OLD.parent_id IS NULL) THEN
parentid = 'null';
ELSE
parentid = CAST(OLD.parent_id AS TEXT);
END IF;
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.id || ' ' || parentid || ' ' || OLD.user_id || ' ' || comment );
RETURN OLD;
END IF;
END;
$$;
COMMENT ON FUNCTION bn_comments_trigger()
IS 'The bn_comments_trigger is called for UPDATE and DELETE operations on the bn_comments table and will perform a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of comments between multiple instances of BinNavi.';
--
-- bn_code_node_comment_trigger()
--
CREATE OR REPLACE FUNCTION bn_code_node_comment_trigger() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
comment text;
BEGIN
IF ( TG_OP = 'UPDATE') THEN
IF ( NEW.comment_id is null) THEN
comment = 'null';
ELSE
comment = CAST(NEW.comment_id AS TEXT);
END IF;
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.node_id || ' ' || NEW.parent_function || ' ' || comment );
RETURN NEW;
END IF;
END;
$$;
COMMENT ON FUNCTION bn_code_node_comment_trigger()
IS 'The bn_bn_code_node_comment_trigger is called for UPDATE operations on the bn_code_nodes table an will perform a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of local comments associated to code nodes between multiple instances of BinNavi.';
--
-- bn_codenode_instructions_comment_trigger()
--
CREATE OR REPLACE FUNCTION bn_codenode_instructions_comment_trigger() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
comment text;
BEGIN
IF ( TG_OP = 'UPDATE') THEN
IF ( NEW.comment_id is null) THEN
comment = 'null';
ELSE
comment = CAST(NEW.comment_id AS TEXT);
END IF;
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.node_id || ' ' || NEW.position || ' ' || NEW.address || ' ' || comment );
RETURN NEW;
END IF;
END;
$$;
COMMENT ON FUNCTION bn_codenode_instructions_comment_trigger()
IS 'The bn_codenode_instructions_comment_trigger is called for UPDATE operations on the bn_codenode_instructions table and will perform a pg_notify with the altered information
This information is used in BinNavi to provide synchronisation of local comments associated to instructions between multiple instances of BinNavi.';
--
-- bn_comments_audit_logger()
--
CREATE OR REPLACE FUNCTION bn_comments_audit_logger() RETURNS trigger
LANGUAGE plpgsql
AS $$
BEGIN
--
-- Create a row in bn_comments_audit to reflect the operation performed on bn_comments,
--
IF (TG_OP = 'DELETE') THEN
INSERT INTO bn_comments_audit SELECT 'D', now(), OLD.id, OLD.parent_id, OLD.user_id, OLD.comment_text;
RETURN OLD;
ELSIF (TG_OP = 'UPDATE') THEN
INSERT INTO bn_comments_audit SELECT 'U', now(), NEW.id, NEW.parent_id, NEW.user_id, NEW.comment_text;
RETURN NEW;
ELSIF (TG_OP = 'INSERT') THEN
INSERT INTO bn_comments_audit SELECT 'I', now(), NEW.id, NEW.parent_id, NEW.user_id, NEW.comment_text;
RETURN NEW;
END IF;
RETURN NULL;
END;
$$;
COMMENT ON FUNCTION bn_comments_audit_logger()
IS 'The bn_comments_audit_logger is called for all operations performed on the bn_comments table and saves the operation with the altered information in the table
bn_comments_audit. This information can be used to track changes to comments which have been performed to a database over time.';
--
-- bn_edges_comment_trigger()
--
CREATE OR REPLACE FUNCTION bn_edges_comment_trigger() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
comment text;
BEGIN
IF ( TG_OP = 'UPDATE') THEN
IF ( NEW.comment_id is null) THEN
comment = 'null';
ELSE
comment = CAST(NEW.comment_id AS TEXT);
END IF;
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.id || ' ' || comment );
RETURN NEW;
END IF;
END;
$$;
COMMENT ON FUNCTION bn_edges_comment_trigger()
IS 'The bn_edges_comment_trigger is called for UPDATE operations on the bn_edges table and will perfrom a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of local comments associated to edges between multiple instances of BinNavi.';
--
-- bn_function_nodes_comment_trigger()
--
CREATE OR REPLACE FUNCTION bn_function_nodes_comment_trigger() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
comment text;
BEGIN
IF ( TG_OP = 'UPDATE') THEN
IF ( NEW.comment_id is null) THEN
comment = 'null';
ELSE
comment = CAST(NEW.comment_id AS TEXT);
END IF;
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.node_id || ' ' || NEW.function || ' ' || comment );
RETURN NEW;
END IF;
END;
$$;
COMMENT ON FUNCTION bn_function_nodes_comment_trigger()
IS 'The bn_function_nodes_comment_trigger is called for UPDATE operations on the bn_function_nodes table and will perfrom a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of comments associated to function nodes between multiple instances of BinNavi.';
--
-- bn_functions_comment_trigger()
--
CREATE OR REPLACE FUNCTION bn_functions_comment_trigger() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
comment text;
BEGIN
IF ( TG_OP = 'UPDATE') THEN
IF ( NEW.comment_id is null) THEN
comment = 'null';
ELSE
comment = CAST(NEW.comment_id AS TEXT);
END IF;
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.address || ' ' || comment );
RETURN NEW;
END IF;
END;
$$;
COMMENT ON FUNCTION bn_functions_comment_trigger()
IS 'The bn_functions_comment_trigger is called for UPDATE operations on the bn_function table and will perfrom a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of comments associated to functions between multiple instances of BinNavi.';
--
-- bn_global_edge_comments_trigger()
--
CREATE OR REPLACE FUNCTION bn_global_edge_comments_trigger() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
IF ( TG_OP = 'INSERT' OR TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.src_module_id || ' ' || NEW.dst_module_id || ' ' || NEW.src_address || ' ' || NEW.dst_address || ' ' || NEW.comment_id );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.src_module_id || ' ' || OLD.dst_module_id || ' ' || OLD.src_address || ' ' || OLD.dst_address);
RETURN OLD;
END IF;
END;
$$;
COMMENT ON FUNCTION bn_global_edge_comments_trigger()
IS 'The bn_global_edge_comments_trigger is called for all operations on the bn_global_edge_comments table and will perfrom a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of global comments associated to edges between multiple instances of BinNavi.';
--
-- bn_global_node_comments_trigger()
--
CREATE OR REPLACE FUNCTION bn_global_node_comments_trigger() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
BEGIN
IF ( TG_OP = 'INSERT' OR TG_OP = 'UPDATE' ) THEN
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.address || ' ' || NEW.comment_id );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.module_id || ' ' || OLD.address);
RETURN OLD;
END IF;
END;
$$;
COMMENT ON FUNCTION bn_global_node_comments_trigger()
IS 'The bn_global_node_comments_trigger is called for all operations on the bn_global_node_comments table and will perfrom a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of global comments associated to nodes between multiple instances of BinNavi.';
--
-- bn_group_nodes_comment_trigger()
--
CREATE OR REPLACE FUNCTION bn_group_nodes_comment_trigger() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
comment text;
BEGIN
IF ( TG_OP = 'INSERT' OR TG_OP = 'UPDATE' ) THEN
IF ( NEW.comment_id is null) THEN
comment = 'null';
ELSE
comment = CAST(NEW.comment_id AS TEXT);
END IF;
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.node_id || ' ' || comment );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.node_id);
RETURN OLD;
END IF;
END;
$$;
COMMENT ON FUNCTION bn_group_nodes_comment_trigger()
IS 'The bn_group_nodes_comment_trigger is called for all operations on the bn_group_nodes table and will perfrom a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of comments associated to group nodes between multiple instances of BinNavi.';
--
-- bn_instructions_comment_trigger()
--
CREATE OR REPLACE FUNCTION bn_instructions_comment_trigger() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
comment text;
BEGIN
IF ( TG_OP = 'UPDATE') THEN
IF ( NEW.comment_id is null) THEN
comment = 'null';
ELSE
comment = CAST(NEW.comment_id AS TEXT);
END IF;
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.module_id || ' ' || NEW.address || ' ' || comment );
RETURN NEW;
END IF;
END;
$$;
COMMENT ON FUNCTION bn_instructions_comment_trigger()
IS 'The bn_instructions_comment_trigger is called for UPDATE operations on the bn_instructions table and will perfrom a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of global comments associated to instructions between multiple instances of BinNavi.';
--
-- bn_text_nodes_comment_trigger()
--
CREATE OR REPLACE FUNCTION bn_text_nodes_comment_trigger() RETURNS trigger
LANGUAGE plpgsql
AS $$
DECLARE
comment text;
BEGIN
IF ( TG_OP = 'INSERT' OR TG_OP = 'UPDATE' ) THEN
IF ( NEW.comment_id is null) THEN
comment = 'null';
ELSE
comment = CAST(NEW.comment_id AS TEXT);
END IF;
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || NEW.node_id || ' ' || comment );
RETURN NEW;
ELSIF ( TG_OP = 'DELETE' ) THEN
PERFORM pg_notify('comment_changes', TG_TABLE_NAME || ' ' || TG_OP || ' ' || OLD.node_id);
RETURN OLD;
END IF;
END;
$$;
COMMENT ON FUNCTION bn_text_nodes_comment_trigger()
IS 'The bn_text_nodes_comment_trigger is called for all operations on the bn_text_nodes table and will perfrom a pg_notify with the altered information.
This information is used in BinNavi to provide synchronisation of comments associated to text nodes between multiple instances of BinNavi.';
--
-- Table section
--
--
-- bn_debuggers
--
CREATE SEQUENCE bn_debuggers_id_seq;
COMMENT ON SEQUENCE bn_debuggers_id_seq
IS 'This sequence is used by the table bn_debuggers id field.';
CREATE TABLE bn_debuggers (
id integer NOT NULL PRIMARY KEY DEFAULT nextval('bn_debuggers_id_seq'::regclass),
name text NOT NULL,
host text NOT NULL,
port integer NOT NULL
);
COMMENT ON TABLE bn_debuggers IS 'This table contains all information to connect to a debug client.';
COMMENT ON COLUMN bn_debuggers.id IS 'Id of the debug client.';
COMMENT ON COLUMN bn_debuggers.name IS 'Name of the debug client.';
COMMENT ON COLUMN bn_debuggers.host IS 'Host name of the debug client.';
COMMENT ON COLUMN bn_debuggers.port IS 'Port number of the debug client.';
ALTER SEQUENCE bn_debuggers_id_seq OWNED BY bn_debuggers.id;
--
-- bn_modules
--
CREATE SEQUENCE bn_modules_id_seq;
COMMENT ON SEQUENCE bn_modules_id_seq
IS 'This sequence is used in the table bn_modules id field.';
CREATE TABLE bn_modules (
id integer NOT NULL PRIMARY KEY DEFAULT nextval('bn_modules_id_seq'::regclass),
raw_module_id integer, --REFERENCES modules(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
name text NOT NULL,
description text NOT NULL,
md5 character(32) NOT NULL,
sha1 character(40) NOT NULL,
debugger_id integer REFERENCES bn_debuggers(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
image_base bigint DEFAULT 0 NOT NULL,
file_base bigint DEFAULT 0 NOT NULL,
import_time timestamp without time zone DEFAULT now() NOT NULL,
modification_date timestamp without time zone DEFAULT now() NOT NULL,
data bytea,
stared boolean DEFAULT false NOT NULL,
initialization_state integer DEFAULT 0 NOT NULL
);
COMMENT ON TABLE bn_modules IS 'This table holds the information about a BinNavi module.';
COMMENT ON COLUMN bn_modules.id IS 'The id of the module.';
COMMENT ON COLUMN bn_modules.raw_module_id IS 'The id of the corresponding raw module.';
COMMENT ON COLUMN bn_modules.name IS 'The name of the module.';
COMMENT ON COLUMN bn_modules.description IS 'The description of the module.';
COMMENT ON COLUMN bn_modules.md5 IS 'The md5 hash of the binary which corresponds to this module.';
COMMENT ON COLUMN bn_modules.sha1 IS 'The sha1 has of the binary which corresponds to this module.';
COMMENT ON COLUMN bn_modules.debugger_id IS 'The id of the debugger currently active for this module.';
COMMENT ON COLUMN bn_modules.image_base IS 'The image base of the executable represented by the module.';
COMMENT ON COLUMN bn_modules.file_base IS 'The file base of the executable represented by the module.';
COMMENT ON COLUMN bn_modules.import_time IS 'The time of import.';
COMMENT ON COLUMN bn_modules.modification_date IS 'The time when the database was last updated.';
COMMENT ON COLUMN bn_modules.data IS 'The data of binary represented by the module.';
COMMENT ON COLUMN bn_modules.stared IS 'Flags if the module has been stared.';
COMMENT ON COLUMN bn_modules.initialization_state IS 'Indicates the initialization state of the module';
ALTER SEQUENCE bn_modules_id_seq OWNED BY bn_modules.id;
CREATE INDEX bn_modules_raw_module_id_idx
ON bn_modules USING btree (raw_module_id);
--
-- bn_address_references
--
CREATE TABLE bn_address_references (
module_id integer NOT NULL REFERENCES bn_modules(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
address bigint NOT NULL,
"position" integer NOT NULL,
expression_id integer NOT NULL,
type address_reference_type NOT NULL,
target bigint NOT NULL,
CONSTRAINT bn_address_references_pkey PRIMARY KEY (module_id, address, "position", expression_id, type, target)
);
COMMENT ON TABLE bn_address_references IS 'This table stores all address references.';
COMMENT ON COLUMN bn_address_references.module_id IS 'The module id the address reference is associated to.';
COMMENT ON COLUMN bn_address_references.address IS 'The address where the reference is associated to.';
COMMENT ON COLUMN bn_address_references."position" IS 'The position of the operand tree to which the address reference is associated to.';
COMMENT ON COLUMN bn_address_references.expression_id IS 'The id of the expression in the operand tree the address reference is associated to.';
COMMENT ON COLUMN bn_address_references.type IS 'The type of the address reference see the address_reference_type type for details.';
COMMENT ON COLUMN bn_address_references.target IS 'The target where address reference points to.';
CREATE INDEX bn_address_references_module_id_address_position_expression_id_
ON bn_address_references USING btree (module_id, address, "position", expression_id);
CREATE INDEX bn_address_references_module_id_idx
ON bn_address_references USING btree (module_id);
CREATE INDEX bn_address_references_target_idx
ON bn_address_references USING btree (target);
CREATE INDEX bn_address_references_type_idx
ON bn_address_references USING btree (type);
--
-- bn_projects
--
CREATE SEQUENCE bn_projects_id_seq;
COMMENT ON SEQUENCE bn_projects_id_seq
IS 'This sequence is used by the table bn_projects id field.';
CREATE TABLE bn_projects (
id integer NOT NULL PRIMARY KEY DEFAULT nextval('bn_projects_id_seq'::regclass),
name text NOT NULL,
description text NOT NULL,
creation_date timestamp without time zone DEFAULT now() NOT NULL,
modification_date timestamp without time zone DEFAULT now() NOT NULL,
stared boolean DEFAULT false NOT NULL
);
COMMENT ON TABLE bn_projects IS 'This table stores all information about a project.';
COMMENT ON COLUMN bn_projects.id IS 'The id of the project. Backed by bn_projects_id_seq';
COMMENT ON COLUMN bn_projects.name IS 'The name of the project.';
COMMENT ON COLUMN bn_projects.description IS 'The description of the project.';
COMMENT ON COLUMN bn_projects.creation_date IS 'The creation date of the project.';
COMMENT ON COLUMN bn_projects.modification_date IS 'The modification date of the project.';
COMMENT ON COLUMN bn_projects.stared IS 'Flag which indicates if the project is stared.';
ALTER SEQUENCE bn_projects_id_seq OWNED BY bn_projects.id;
--
-- bn_address_spaces
--
CREATE SEQUENCE bn_address_spaces_id_seq;
COMMENT ON SEQUENCE bn_address_spaces_id_seq
IS 'This sequence is used by the table bn_address_spaces id field.';
CREATE TABLE bn_address_spaces (
id integer NOT NULL PRIMARY KEY DEFAULT nextval('bn_address_spaces_id_seq'::regclass),
project_id integer NOT NULL REFERENCES bn_projects(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
debugger_id integer REFERENCES bn_debuggers(id) ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED,
name text NOT NULL,
description text NOT NULL,
creation_date timestamp without time zone DEFAULT now() NOT NULL,
modification_date timestamp without time zone DEFAULT now() NOT NULL
);
COMMENT ON TABLE bn_address_spaces IS 'This table stores the information about address spaces associated to a project.';
COMMENT ON COLUMN bn_address_spaces.id IS 'The id of the address space which is backed by the sequence bn_address_spaces_id_seq';
COMMENT ON COLUMN bn_address_spaces.project_id IS 'The id of the project the address space is associated to.';
COMMENT ON COLUMN bn_address_spaces.debugger_id IS 'The id of the current debugger of the address space.';
COMMENT ON COLUMN bn_address_spaces.name IS 'The name of the address space.';
COMMENT ON COLUMN bn_address_spaces.description IS 'The description of the address space.';
COMMENT ON COLUMN bn_address_spaces.creation_date IS 'The creation date of the address space.';
COMMENT ON COLUMN bn_address_spaces.modification_date IS 'The modification date of the address space.';
ALTER SEQUENCE bn_address_spaces_id_seq OWNED BY bn_address_spaces.id;
--
-- bn_base_types
--
CREATE SEQUENCE bn_base_types_id_seq;
COMMENT ON SEQUENCE bn_base_types_id_seq
IS 'This sequence is used by the table bn_base_types id field.';
CREATE TABLE bn_base_types (
module_id integer NOT NULL,
id integer NOT NULL,
name text NOT NULL,
size integer NOT NULL,
pointer integer,
signed boolean,
category type_category NOT NULL,
CONSTRAINT bn_base_types_pkey PRIMARY KEY (module_id, id),
CONSTRAINT bn_base_types_pointer_fkey
FOREIGN KEY (module_id, pointer)
REFERENCES bn_base_types(module_id, id)
ON DELETE CASCADE DEFERRABLE INITIALLY DEFERRED
);
COMMENT ON TABLE bn_base_types IS 'This table stores all base types for the type system used in BinNavi.';
COMMENT ON COLUMN bn_base_types.module_id IS 'The module id the base type is associated to.';
COMMENT ON COLUMN bn_base_types.id IS 'The id of the base type.';
COMMENT ON COLUMN bn_base_types.name IS 'The name of the base type.';
COMMENT ON COLUMN bn_base_types.size IS 'The size of the base type in bits.';
COMMENT ON COLUMN bn_base_types.pointer IS 'A flag that indicates if the base type is a pointer or not.';
COMMENT ON COLUMN bn_base_types.signed IS 'A flag that indicates if the base type id signed or not.';
COMMENT ON COLUMN bn_base_types.category IS 'An enum that describes the category of this base type.';
ALTER SEQUENCE bn_base_types_id_seq OWNED BY bn_base_types.id;
CREATE TRIGGER bn_base_types_trigger
AFTER INSERT OR UPDATE OR DELETE
ON bn_base_types
FOR EACH ROW EXECUTE
PROCEDURE bn_base_types_trigger();
--
-- bn_nodes
--
CREATE SEQUENCE bn_nodes_id_seq;
COMMENT ON SEQUENCE bn_nodes_id_seq
IS 'This sequence is used by the table bn_nodes id field.';
CREATE TABLE bn_nodes (
id integer NOT NULL PRIMARY KEY DEFAULT nextval('bn_nodes_id_seq'::regclass),
view_id integer NOT NULL,
parent_id integer,
type node_type NOT NULL,
x double precision NOT NULL,
y double precision NOT NULL,
width double precision NOT NULL,
height double precision NOT NULL,
color integer NOT NULL,
bordercolor integer DEFAULT 0 NOT NULL,
selected boolean NOT NULL,
visible boolean NOT NULL
);
COMMENT ON TABLE bn_nodes IS 'This table holds the information representing a base node.';
COMMENT ON COLUMN bn_nodes.id IS 'The id of the node.';
COMMENT ON COLUMN bn_nodes.view_id IS 'The id of the view the node belongs to.';