-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathInstructions.qll
More file actions
1429 lines (1050 loc) · 42.6 KB
/
Instructions.qll
File metadata and controls
1429 lines (1050 loc) · 42.6 KB
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
/**
* Provides classes representing individual opcodes.
*
* See ECMA-335 (https://www.ecma-international.org/publications/files/ECMA-ST/ECMA-335.pdf)
* pages 32-101 for a detailed explanation of these instructions.
*/
private import CIL
private import semmle.code.dotnet.Variable as DotNet
module Opcodes {
/** An `ldc.i4.m1` instruction. */
class Ldc_i4_m1 extends IntLiteral, @cil_ldc_i4_m1 {
override string getOpcodeName() { result = "ldc.i4.m1" }
override string getValue() { result = "-1" }
}
/** An `ldc.i4.0` instruction. */
class Ldc_i4_0 extends IntLiteral, @cil_ldc_i4_0 {
override string getOpcodeName() { result = "ldc.i4.0" }
override string getValue() { result = "0" }
}
/** An `ldc.i4.1` instruction. */
class Ldc_i4_1 extends IntLiteral, @cil_ldc_i4_1 {
override string getOpcodeName() { result = "ldc.i4.1" }
override string getValue() { result = "1" }
}
/** An `ldc.i4.2` instruction. */
class Ldc_i4_2 extends IntLiteral, @cil_ldc_i4_2 {
override string getOpcodeName() { result = "ldc.i4.2" }
override string getValue() { result = "2" }
}
/** An `ldc.i4.3` instruction. */
class Ldc_i4_3 extends IntLiteral, @cil_ldc_i4_3 {
override string getOpcodeName() { result = "ldc.i4.3" }
override string getValue() { result = "3" }
}
/** An `ldc.i4.4` instruction. */
class Ldc_i4_4 extends IntLiteral, @cil_ldc_i4_4 {
override string getOpcodeName() { result = "ldc.i4.4" }
override string getValue() { result = "4" }
}
/** An `ldc.i4.5` instruction. */
class Ldc_i4_5 extends IntLiteral, @cil_ldc_i4_5 {
override string getOpcodeName() { result = "ldc.i4.5" }
override string getValue() { result = "5" }
}
/** An `ldc.i4.6` instruction. */
class Ldc_i4_6 extends IntLiteral, @cil_ldc_i4_6 {
override string getOpcodeName() { result = "ldc.i4.6" }
override string getValue() { result = "6" }
}
/** An `ldc.i4.7` instruction. */
class Ldc_i4_7 extends IntLiteral, @cil_ldc_i4_7 {
override string getOpcodeName() { result = "ldc.i4.7" }
override string getValue() { result = "7" }
}
/** An `ldc.i4.8` instruction. */
class Ldc_i4_8 extends IntLiteral, @cil_ldc_i4_8 {
override string getOpcodeName() { result = "ldc.i4.8" }
override string getValue() { result = "8" }
}
/** An `ldc.i4` instruction. */
class Ldc_i4 extends IntLiteral, @cil_ldc_i4 {
override string getOpcodeName() { result = "ldc.i4" }
override string getExtra() { result = getValue() }
}
/** An `ldc.i8` instruction. */
class Ldc_i8 extends IntLiteral, @cil_ldc_i8 {
override string getOpcodeName() { result = "ldc.i8" }
override string getExtra() { result = getValue() }
}
/** An `ldc.i4.s` instruction. */
class Ldc_i4_s extends IntLiteral, @cil_ldc_i4_s {
override string getOpcodeName() { result = "ldc.i4.s" }
override string getExtra() { result = getValue() }
}
/** An `ldnull` instruction. */
class Ldnull extends Literal, @cil_ldnull {
override string getOpcodeName() { result = "ldnull" }
override string getValue() { result = "null" }
override string getExtra() { none() }
override Type getType() { result instanceof ObjectType }
}
/** An `ldc.r4` instruction. */
class Ldc_r4 extends FloatLiteral, @cil_ldc_r4 {
override string getOpcodeName() { result = "ldc.r4" }
override string getExtra() { result = getValue() }
override Type getType() { result instanceof FloatType }
}
/** An `ldc.r8` instruction. */
class Ldc_r8 extends FloatLiteral, @cil_ldc_r8 {
override string getOpcodeName() { result = "ldc.r8" }
override string getExtra() { result = getValue() }
override Type getType() { result instanceof DoubleType }
}
/** An `add` instruction. */
class Add extends BinaryArithmeticExpr, @cil_add {
override string getOpcodeName() { result = "add" }
}
/** An `add.ovf` instruction. */
class Add_ovf extends BinaryArithmeticExpr, @cil_add_ovf {
override string getOpcodeName() { result = "add.ovf" }
}
/** An `add.ovf.un` instruction. */
class Add_ovf_un extends BinaryArithmeticExpr, @cil_add_ovf_un {
override string getOpcodeName() { result = "add.ovf.un" }
}
/** A `sub` instruction. */
class Sub extends BinaryArithmeticExpr, @cil_sub {
override string getOpcodeName() { result = "sub" }
}
/** A `sub.ovf` instruction. */
class Sub_ovf extends BinaryArithmeticExpr, @cil_sub_ovf {
override string getOpcodeName() { result = "sub.ovf" }
}
/** A `sub.ovf.un` instruction. */
class Sub_ovf_un extends BinaryArithmeticExpr, @cil_sub_ovf_un {
override string getOpcodeName() { result = "sub.ovf.un" }
}
/** A `mul` instruction. */
class Mul extends BinaryArithmeticExpr, @cil_mul {
override string getOpcodeName() { result = "mul" }
}
/** A `mul.ovf` instruction. */
class Mul_ovf extends BinaryArithmeticExpr, @cil_mul_ovf {
override string getOpcodeName() { result = "mul.ovf" }
}
/** A `mul.ovf.un` instruction. */
class Mul_ovf_un extends BinaryArithmeticExpr, @cil_mul_ovf_un {
override string getOpcodeName() { result = "mul.ovf.un" }
}
/** A `div` instruction. */
class Div extends BinaryArithmeticExpr, @cil_div {
override string getOpcodeName() { result = "div" }
}
/** A `div.un` instruction. */
class Div_un extends BinaryArithmeticExpr, @cil_div_un {
override string getOpcodeName() { result = "div.un" }
}
/** A `rem` instruction. */
class Rem extends BinaryArithmeticExpr, @cil_rem {
override string getOpcodeName() { result = "rem" }
}
/** A `rem.un` instruction. */
class Rem_un extends BinaryArithmeticExpr, @cil_rem_un {
override string getOpcodeName() { result = "rem.un" }
}
/** A `neg` instruction. */
class Neg extends UnaryExpr, @cil_neg {
override string getOpcodeName() { result = "neg" }
override NumericType getType() {
result = getOperand().getType()
or
getOperand().getType() instanceof Enum and result instanceof IntType
}
}
/** An `and` instruction. */
class And extends BinaryBitwiseOperation, @cil_and {
override string getOpcodeName() { result = "and" }
}
/** An `or` instruction. */
class Or extends BinaryBitwiseOperation, @cil_or {
override string getOpcodeName() { result = "or" }
}
/** An `xor` instruction. */
class Xor extends BinaryBitwiseOperation, @cil_xor {
override string getOpcodeName() { result = "xor" }
}
/** A `not` instruction. */
class Not extends UnaryBitwiseOperation, @cil_not {
override string getOpcodeName() { result = "not" }
}
/** A `shl` instruction. */
class Shl extends BinaryBitwiseOperation, @cil_shl {
override string getOpcodeName() { result = "shl" }
}
/** A `shr` instruction. */
class Shr extends BinaryBitwiseOperation, @cil_shr {
override string getOpcodeName() { result = "shr" }
}
/** A `shr.un` instruction. */
class Shr_un extends BinaryBitwiseOperation, @cil_shr_un {
override string getOpcodeName() { result = "shr.un" }
}
/** A `ceq` instruction. */
class Ceq extends ComparisonOperation, @cil_ceq {
override string getOpcodeName() { result = "ceq" }
}
/** A `pop` instruction. */
class Pop extends Instruction, @cil_pop {
override string getOpcodeName() { result = "pop" }
override int getPopCount() { result = 1 }
}
/** A `dup` instruction. */
class Dup extends Expr, @cil_dup {
override string getOpcodeName() { result = "dup" }
override int getPopCount() { result = 1 }
override int getPushCount() { result = 2 } // This is the only instruction that pushes 2 items
override Type getType() { result = getOperand(0).getType() }
}
/** A `ret` instruction. */
class Ret extends Return, @cil_ret {
override string getOpcodeName() { result = "ret" }
override predicate canFlowNext() { none() }
override int getPopCount() {
if getImplementation().getMethod().returnsVoid() then result = 0 else result = 1
}
}
/** A `nop` instruction. */
class Nop extends Instruction, @cil_nop {
override string getOpcodeName() { result = "nop" }
}
/** An `ldstr` instruction. */
class Ldstr extends StringLiteral, @cil_ldstr {
override string getOpcodeName() { result = "ldstr" }
override string getExtra() { result = "\"" + getValue() + "\"" }
override Type getType() { result instanceof StringType }
}
/** A `br` instruction. */
class Br extends UnconditionalBranch, @cil_br {
override string getOpcodeName() { result = "br" }
}
/** A `br.s` instruction. */
class Br_s extends UnconditionalBranch, @cil_br_s {
override string getOpcodeName() { result = "br.s" }
}
/** A `brfalse.s` instruction. */
class Brfalse_s extends UnaryBranch, @cil_brfalse_s {
override string getOpcodeName() { result = "brfalse.s" }
}
/** A `brfalse` instruction. */
class Brfalse extends UnaryBranch, @cil_brfalse {
override string getOpcodeName() { result = "brfalse" }
}
/** A `brtrue.s` instruction. */
class Brtrue_s extends UnaryBranch, @cil_brtrue_s {
override string getOpcodeName() { result = "brtrue.s" }
}
/** A `brtrue` instruction. */
class Brtrue extends UnaryBranch, @cil_brtrue {
override string getOpcodeName() { result = "brtrue" }
}
/** A `blt.s` instruction. */
class Blt_s extends BinaryBranch, @cil_blt_s {
override string getOpcodeName() { result = "blt.s" }
}
/** A `blt` instruction. */
class Blt extends BinaryBranch, @cil_blt {
override string getOpcodeName() { result = "blt" }
}
/** A `blt.un.s` instruction. */
class Blt_un_s extends BinaryBranch, @cil_blt_un_s {
override string getOpcodeName() { result = "blt.un.s" }
}
/** A `blt.un` instruction. */
class Blt_un extends BinaryBranch, @cil_blt_un {
override string getOpcodeName() { result = "blt.un" }
}
/** A `bgt.un` instruction. */
class Bgt_un extends BinaryBranch, @cil_bgt_un {
override string getOpcodeName() { result = "bgt.un" }
}
/** A `ble.un.s` instruction. */
class Ble_un_s extends BinaryBranch, @cil_ble_un_s {
override string getOpcodeName() { result = "ble.un.s" }
}
/** A `ble.un` instruction. */
class Ble_un extends BinaryBranch, @cil_ble_un {
override string getOpcodeName() { result = "ble.un" }
}
/** A `bge.s` instruction. */
class Bge_s extends BinaryBranch, @cil_bge_s {
override string getOpcodeName() { result = "bge.s" }
}
/** A `ble.un` instruction. */
class Bge_un extends BinaryBranch, @cil_bge_un {
override string getOpcodeName() { result = "bge.un" }
}
/** A `bge` instruction. */
class Bge extends BinaryBranch, @cil_bge {
override string getOpcodeName() { result = "bge" }
}
/** A `bne.un.s` instruction. */
class Bne_un_s extends BinaryBranch, @cil_bne_un_s {
override string getOpcodeName() { result = "bne.un.s" }
}
/** A `bne.un` instruction. */
class Bne_un extends BinaryBranch, @cil_bne_un {
override string getOpcodeName() { result = "bne.un" }
}
/** A `beq` instruction. */
class Beq extends BinaryBranch, @cil_beq {
override string getOpcodeName() { result = "beq" }
}
/** A `beq.s` instruction. */
class Beq_s extends BinaryBranch, @cil_beq_s {
override string getOpcodeName() { result = "beq.s" }
}
/** A `ble.s` instruction. */
class Ble_s extends BinaryBranch, @cil_ble_s {
override string getOpcodeName() { result = "ble.s" }
}
/** A `ble` instruction. */
class Ble extends BinaryBranch, @cil_ble {
override string getOpcodeName() { result = "ble" }
}
/** A `bgt.s` instruction. */
class Bgt_s extends BinaryBranch, @cil_bgt_s {
override string getOpcodeName() { result = "bgt.s" }
}
/** A `bgt` instruction. */
class Bgt extends BinaryBranch, @cil_bgt {
override string getOpcodeName() { result = "bgt" }
}
/** A `bgt.in.s` instruction. */
class Bgt_in_s extends BinaryBranch, @cil_bgt_un_s {
override string getOpcodeName() { result = "bgt.in.s" }
}
/** A `bge.in.s` instruction. */
class Bge_in_s extends BinaryBranch, @cil_bge_un_s {
override string getOpcodeName() { result = "bge.un.s" }
}
/** A `switch` instruction. */
class Switch extends ConditionalBranch, @cil_switch {
override string getOpcodeName() { result = "switch" }
/** Gets the `n`th jump target of this switch. */
Instruction getTarget(int n) { cil_switch(this, n, result) }
override Instruction getASuccessorType(FlowType t) {
t instanceof NormalFlow and
(result = getTarget(_) or result = getImplementation().getInstruction(getIndex() + 1))
}
override string getExtra() {
result = concat(int n | exists(getTarget(n)) | getTarget(n).getIndex() + ":", " ")
}
}
/** A `leave` instruction. */
class Leave_ extends Leave, @cil_leave {
override string getOpcodeName() { result = "leave" }
}
/** A `leave.s` instruction. */
class Leave_s extends Leave, @cil_leave_s {
override string getOpcodeName() { result = "leave.s" }
}
/** An `endfilter` instruction. */
class Endfilter extends Instruction, @cil_endfilter {
override string getOpcodeName() { result = "endfilter" }
}
/** An `endfinally` instruction. */
class Endfinally extends Instruction, @cil_endfinally {
override string getOpcodeName() { result = "endfinally" }
override predicate canFlowNext() { none() }
}
/** A `cgt.un` instruction. */
class Cgt_un extends ComparisonOperation, @cil_cgt_un {
override string getOpcodeName() { result = "cgt.un" }
}
/** A `cgt` instruction. */
class Cgt extends ComparisonOperation, @cil_cgt {
override string getOpcodeName() { result = "cgt" }
}
/** A `clt.un` instruction. */
class Clt_un extends ComparisonOperation, @cil_clt_un {
override string getOpcodeName() { result = "clt.un" }
}
/** A `clt` instruction. */
class Clt extends ComparisonOperation, @cil_clt {
override string getOpcodeName() { result = "clt" }
}
/** A `call` instruction. */
class Call_ extends Call, @cil_call {
override string getOpcodeName() { result = "call" }
}
/** A `calli` instruction. */
class Calli extends Call, @cil_calli {
override string getOpcodeName() { result = "calli" }
override Callable getTarget() { none() }
/** Gets the function pointer type targetted by this instruction. */
FunctionPointerType getTargetType() { cil_access(this, result) }
// The number of items popped/pushed from the stack depends on the target of
// the call. Also, we need to pop the function pointer itself too.
override int getPopCount() { result = getTargetType().getCallPopCount() + 1 }
override int getPushCount() { result = getTargetType().getCallPushCount() }
}
/** A `callvirt` instruction. */
class Callvirt extends Call, @cil_callvirt {
override string getOpcodeName() { result = "callvirt" }
override predicate isVirtual() { any() }
}
/** A `tail.` instruction. */
class Tail extends Instruction, @cil_tail {
override string getOpcodeName() { result = "tail." }
}
/** A `jmp` instruction. */
class Jmp extends Call, @cil_jmp {
override string getOpcodeName() { result = "jmp" }
override predicate isTailCall() { any() }
}
/** An `isinst` instruction. */
class Isinst extends UnaryExpr, @cil_isinst {
override string getOpcodeName() { result = "isinst" }
override BoolType getType() { exists(result) }
/** Gets the type that is being tested against. */
Type getTestedType() { result = getAccess() }
override string getExtra() { result = getTestedType().getQualifiedName() }
}
/** A `castclass` instruction. */
class Castclass extends UnaryExpr, @cil_castclass {
override string getOpcodeName() { result = "castclass" }
override Type getType() { result = getAccess() }
/** Gets the type that is being cast to. */
Type getTestedType() { result = getAccess() }
override string getExtra() { result = getTestedType().getQualifiedName() }
}
/** An `stloc.0` instruction. */
class Stloc_0 extends LocalVariableWriteAccess, @cil_stloc_0 {
override string getOpcodeName() { result = "stloc.0" }
override LocalVariable getTarget() { result = getImplementation().getLocalVariable(0) }
}
/** An `stloc.1` instruction. */
class Stloc_1 extends LocalVariableWriteAccess, @cil_stloc_1 {
override string getOpcodeName() { result = "stloc.1" }
override LocalVariable getTarget() { result = getImplementation().getLocalVariable(1) }
}
/** An `stloc.2` instruction. */
class Stloc_2 extends LocalVariableWriteAccess, @cil_stloc_2 {
override string getOpcodeName() { result = "stloc.2" }
override LocalVariable getTarget() { result = getImplementation().getLocalVariable(2) }
}
/** An `stloc.3` instruction. */
class Stloc_3 extends LocalVariableWriteAccess, @cil_stloc_3 {
override string getOpcodeName() { result = "stloc.3" }
override LocalVariable getTarget() { result = getImplementation().getLocalVariable(3) }
}
/** An `stloc.s` instruction. */
class Stloc_s extends LocalVariableWriteAccess, @cil_stloc_s {
override string getOpcodeName() { result = "stloc.s" }
override LocalVariable getTarget() { cil_access(this, result) }
}
/** An `stloc` instruction. */
class Stloc extends LocalVariableWriteAccess, @cil_stloc {
override string getOpcodeName() { result = "stloc" }
override LocalVariable getTarget() { cil_access(this, result) }
}
/** An `ldloc.0` instruction. */
class Ldloc_0 extends LocalVariableReadAccess, @cil_ldloc_0 {
override string getOpcodeName() { result = "ldloc.0" }
override LocalVariable getTarget() { result = getImplementation().getLocalVariable(0) }
}
/** An `ldloc.1` instruction. */
class Ldloc_1 extends LocalVariableReadAccess, @cil_ldloc_1 {
override string getOpcodeName() { result = "ldloc.1" }
override LocalVariable getTarget() { result = getImplementation().getLocalVariable(1) }
}
/** An `ldloc.2` instruction. */
class Ldloc_2 extends LocalVariableReadAccess, @cil_ldloc_2 {
override string getOpcodeName() { result = "ldloc.2" }
override LocalVariable getTarget() { result = getImplementation().getLocalVariable(2) }
}
/** An `ldloc.3` instruction. */
class Ldloc_3 extends LocalVariableReadAccess, @cil_ldloc_3 {
override string getOpcodeName() { result = "ldloc.3" }
override LocalVariable getTarget() { result = getImplementation().getLocalVariable(3) }
}
/** An `ldloc.s` instruction. */
class Ldloc_s extends LocalVariableReadAccess, @cil_ldloc_s {
override string getOpcodeName() { result = "ldloc.s" }
override LocalVariable getTarget() { cil_access(this, result) }
override string getExtra() { result = "L" + getTarget().getIndex() }
}
/** An `ldloca.s` instruction. */
class Ldloca_s extends LocalVariableReadAccess, ReadRefAccess, @cil_ldloca_s {
override string getOpcodeName() { result = "ldloca.s" }
override LocalVariable getTarget() { cil_access(this, result) }
override string getExtra() { result = "L" + getTarget().getIndex() }
}
/** An `ldloc` instruction. */
class Ldloc extends LocalVariableReadAccess, @cil_ldloc {
override string getOpcodeName() { result = "ldloc" }
override LocalVariable getTarget() { cil_access(this, result) }
override string getExtra() { result = "L" + getTarget().getIndex() }
}
/** An `ldarg.0` instruction. */
class Ldarg_0 extends ParameterReadAccess, @cil_ldarg_0 {
override string getOpcodeName() { result = "ldarg.0" }
override MethodParameter getTarget() {
result = getImplementation().getMethod().getRawParameter(0)
}
}
/** An `ldarg.1` instruction. */
class Ldarg_1 extends ParameterReadAccess, @cil_ldarg_1 {
override string getOpcodeName() { result = "ldarg.1" }
override MethodParameter getTarget() {
result = getImplementation().getMethod().getRawParameter(1)
}
}
/** An `ldarg.2` instruction. */
class Ldarg_2 extends ParameterReadAccess, @cil_ldarg_2 {
override string getOpcodeName() { result = "ldarg.2" }
override MethodParameter getTarget() {
result = getImplementation().getMethod().getRawParameter(2)
}
}
/** An `ldarg.3` instruction. */
class Ldarg_3 extends ParameterReadAccess, @cil_ldarg_3 {
override string getOpcodeName() { result = "ldarg.3" }
override MethodParameter getTarget() {
result = getImplementation().getMethod().getRawParameter(3)
}
}
/** An `ldarg.s` instruction. */
class Ldarg_s extends ParameterReadAccess, @cil_ldarg_s {
override string getOpcodeName() { result = "ldarg.s" }
override MethodParameter getTarget() { cil_access(this, result) }
override string getExtra() { result = this.getTarget().getIndex().toString() }
}
/** An `ldarg` instruction. */
class Ldarg extends ParameterReadAccess, @cil_ldarg {
override string getOpcodeName() { result = "ldarg" }
override MethodParameter getTarget() { cil_access(this, result) }
}
/** An `ldarga.s` instruction. */
class Ldarga_s extends ParameterReadAccess, ReadRefAccess, @cil_ldarga_s {
override string getOpcodeName() { result = "ldarga.s" }
override MethodParameter getTarget() { cil_access(this, result) }
}
/** An `starg.s` instruction. */
class Starg_s extends ParameterWriteAccess, @cil_starg_s {
override string getOpcodeName() { result = "starg.s" }
override MethodParameter getTarget() { cil_access(this, result) }
}
/** An `ldfld` instruction. */
class Ldfld extends FieldReadAccess, @cil_ldfld {
override string getOpcodeName() { result = "ldfld" }
override int getPopCount() { result = 1 }
override Expr getQualifier() { result = getOperand(0) }
}
/** An `ldflda` instruction. */
class Ldflda extends FieldReadAccess, ReadRefAccess, @cil_ldflda {
override string getOpcodeName() { result = "ldflda" }
override int getPopCount() { result = 1 }
override Expr getQualifier() { result = getOperand(0) }
}
/** An `ldsfld` instruction. */
class Ldsfld extends FieldReadAccess, @cil_ldsfld {
override string getOpcodeName() { result = "ldsfld" }
override int getPopCount() { result = 0 }
override Expr getQualifier() { none() }
}
/** An `ldsflda` instruction. */
class Ldsflda extends FieldReadAccess, ReadRefAccess, @cil_ldsflda {
override string getOpcodeName() { result = "ldsflda" }
override int getPopCount() { result = 0 }
override Expr getQualifier() { none() }
}
/** An `stfld` instruction. */
class Stfld extends FieldWriteAccess, @cil_stfld {
override string getOpcodeName() { result = "stfld" }
override int getPopCount() { result = 2 }
override Expr getQualifier() { result = getOperand(1) }
override Expr getExpr() { result = getOperand(0) }
}
/** An `stsfld` instruction. */
class Stsfld extends FieldWriteAccess, @cil_stsfld {
override string getOpcodeName() { result = "stsfld" }
override int getPopCount() { result = 1 }
override Expr getQualifier() { none() }
override Expr getExpr() { result = getOperand(0) }
}
/** A `newobj` instruction. */
class Newobj extends Call, @cil_newobj {
override string getOpcodeName() { result = "newobj" }
override int getPushCount() { result = 1 }
override int getPopCount() { result = count(this.getARawTargetParameter()) - 1 }
override Type getType() { result = this.getTarget().getDeclaringType() }
override Expr getArgument(int i) { result = getRawArgument(i) }
pragma[noinline]
private Parameter getARawTargetParameter() { result = this.getTarget().getARawParameter() }
override Expr getArgumentForParameter(DotNet::Parameter param) {
exists(int index |
result = this.getArgument(index) and
param = this.getTarget().getParameter(index)
)
}
}
/** An `initobj` instruction. */
class Initobj extends Instruction, @cil_initobj {
override string getOpcodeName() { result = "initobj" }
override int getPopCount() { result = 1 } // ??
}
/** A `box` instruction. */
class Box extends UnaryExpr, @cil_box {
override string getOpcodeName() { result = "box" }
override Type getType() { result = getAccess() }
}
/** An `unbox.any` instruction. */
class Unbox_any extends UnaryExpr, @cil_unbox_any {
override string getOpcodeName() { result = "unbox.any" }
override Type getType() { result = getAccess() }
}
/** An `unbox` instruction. */
class Unbox extends UnaryExpr, @cil_unbox {
override string getOpcodeName() { result = "unbox" }
override Type getType() { result = getAccess() }
}
/** An `ldobj` instruction. */
class Ldobj extends UnaryExpr, @cil_ldobj {
override string getOpcodeName() { result = "ldobj" }
/** Gets the type of the object. */
Type getTarget() { cil_access(this, result) }
override Type getType() { result = getAccess() }
}
/** An `ldtoken` instruction. */
class Ldtoken extends Expr, @cil_ldtoken {
override string getOpcodeName() { result = "ldtoken" }
// Not really sure what a type of a token is so use `object`.
override ObjectType getType() { exists(result) }
}
/** A `constrained.` instruction. */
class Constrained extends Instruction, @cil_constrained {
override string getOpcodeName() { result = "constrained." }
}
/** A `throw` instruction. */
class Throw_ extends Throw, @cil_throw {
override string getOpcodeName() { result = "throw" }
override int getPopCount() { result = 1 }
}
/** A `rethrow` instruction. */
class Rethrow extends Throw, @cil_rethrow {
override string getOpcodeName() { result = "rethrow" }
}
/** A `ldlen` instruction. */
class Ldlen extends UnaryExpr, @cil_ldlen {
override string getOpcodeName() { result = "ldlen" }
override IntType getType() { exists(result) }
}
/** A `newarr` instruction. */
class Newarr extends Expr, @cil_newarr {
override string getOpcodeName() { result = "newarr" }
override int getPushCount() { result = 1 }
override int getPopCount() { result = 1 }
override Type getType() {
// Note that this is technically wrong - it should be
// result.(ArrayType).getElementType() = getAccess()
// However the (ArrayType) may not be in the database.
result = getAccess()
}
override string getExtra() { result = getType().getQualifiedName() }
}
/** An `ldelem` instruction. */
class Ldelem extends ReadArrayElement, @cil_ldelem {
override string getOpcodeName() { result = "ldelem" }
override Type getType() { result = getAccess() }
}
/** An `ldelem.ref` instruction. */
class Ldelem_ref extends ReadArrayElement, @cil_ldelem_ref {
override string getOpcodeName() { result = "ldelem.ref" }
override Type getType() { result = getArray().getType() }
}
/** An `ldelema` instruction. */
class Ldelema extends ReadArrayElement, ReadRef, @cil_ldelema {
override string getOpcodeName() { result = "ldelema" }
override Type getType() { result = getAccess() }
}
/** An `stelem.ref` instruction. */
class Stelem_ref extends WriteArrayElement, @cil_stelem_ref {
override string getOpcodeName() { result = "stelem.ref" }
}
/** An `stelem` instruction. */
class Stelem extends WriteArrayElement, @cil_stelem {
override string getOpcodeName() { result = "stelem" }
}
/** An `stelem.i` instruction. */
class Stelem_i extends WriteArrayElement, @cil_stelem_i {
override string getOpcodeName() { result = "stelem.i" }
}
/** An `stelem.i1` instruction. */
class Stelem_i1 extends WriteArrayElement, @cil_stelem_i1 {
override string getOpcodeName() { result = "stelem.i1" }
}
/** An `stelem.i2` instruction. */
class Stelem_i2 extends WriteArrayElement, @cil_stelem_i2 {
override string getOpcodeName() { result = "stelem.i2" }
}
/** An `stelem.i4` instruction. */
class Stelem_i4 extends WriteArrayElement, @cil_stelem_i4 {
override string getOpcodeName() { result = "stelem.i4" }
}
/** An `stelem.i8` instruction. */
class Stelem_i8 extends WriteArrayElement, @cil_stelem_i8 {
override string getOpcodeName() { result = "stelem.i8" }
}
/** An `stelem.r4` instruction. */
class Stelem_r4 extends WriteArrayElement, @cil_stelem_r4 {
override string getOpcodeName() { result = "stelem.r4" }
}
/** An `stelem.r8` instruction. */
class Stelem_r8 extends WriteArrayElement, @cil_stelem_r8 {
override string getOpcodeName() { result = "stelem.r8" }
}
/** An `ldelem.i` instruction. */
class Ldelem_i extends ReadArrayElement, @cil_ldelem_i {
override string getOpcodeName() { result = "ldelem.i" }
override IntType getType() { exists(result) }
}
/** An `ldelem.i1` instruction. */
class Ldelem_i1 extends ReadArrayElement, @cil_ldelem_i1 {
override string getOpcodeName() { result = "ldelem.i1" }
override SByteType getType() { exists(result) }
}
/** An `ldelem.i2` instruction. */
class Ldelem_i2 extends ReadArrayElement, @cil_ldelem_i2 {
override string getOpcodeName() { result = "ldelem.i2" }
override ShortType getType() { exists(result) }
}
/** An `ldelem.i4` instruction. */
class Ldelem_i4 extends ReadArrayElement, @cil_ldelem_i4 {
override string getOpcodeName() { result = "ldelem.i4" }
override IntType getType() { exists(result) }
}
/** An `ldelem.i8` instruction. */
class Ldelem_i8 extends ReadArrayElement, @cil_ldelem_i8 {
override string getOpcodeName() { result = "ldelem.i8" }
override LongType getType() { exists(result) }
}
/** An `ldelem.r4` instruction. */
class Ldelem_r4 extends ReadArrayElement, @cil_ldelem_r4 {
override string getOpcodeName() { result = "ldelem.r4" }
override FloatType getType() { exists(result) }
}
/** An `ldelem.r8` instruction. */
class Ldelem_r8 extends ReadArrayElement, @cil_ldelem_r8 {
override string getOpcodeName() { result = "ldelem.r8" }
override DoubleType getType() { exists(result) }
}
/** An `ldelem.u1` instruction. */
class Ldelem_u1 extends ReadArrayElement, @cil_ldelem_u1 {
override string getOpcodeName() { result = "ldelem.u1" }
override ByteType getType() { exists(result) }
}
/** An `ldelem.u2` instruction. */
class Ldelem_u2 extends ReadArrayElement, @cil_ldelem_u2 {
override string getOpcodeName() { result = "ldelem.u2" }