forked from facebook/redex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShow.cpp
1009 lines (972 loc) · 27 KB
/
Show.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
/**
* Copyright (c) 2016-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
#include "Show.h"
#include <sstream>
#include "DexClass.h"
#include "DexAnnotation.h"
#include "DexOpcode.h"
#include "DexDebugOpcode.h"
#include "DexIdx.h"
#include "Creators.h"
#include "Transform.h"
#include "DexUtil.h"
namespace {
std::string humanize(std::string const& type) {
if (type.compare("B") == 0) {
return "byte";
} else if (type.compare("C") == 0) {
return "char";
} else if (type.compare("D") == 0) {
return "double";
} else if (type.compare("F") == 0) {
return "float";
} else if (type.compare("I") == 0) {
return "int";
} else if (type.compare("J") == 0) {
return "long";
} else if (type.compare("S") == 0) {
return "short";
} else if (type.compare("Z") == 0) {
return "boolean";
} else if (type[0] == '[') {
std::stringstream ss;
ss << humanize(type.substr(1)) << "[]";
return ss.str();
} else if (type[0] == 'L') {
auto cls = type.substr(1, type.size() - 2);
std::replace(cls.begin(), cls.end(), '/', '.');
return cls;
}
return "unknonw";
}
// TODO: make sure names reported handles collisions correctly.
// i.e. ACC_VOLATILE and ACC_BRIDGE etc.
std::string accessibility(uint32_t acc, bool method = false) {
std::stringstream ss;
if (acc & DexAccessFlags::ACC_PUBLIC) {
ss << "public ";
}
if (acc & DexAccessFlags::ACC_PRIVATE) {
ss << "private ";
}
if (acc & DexAccessFlags::ACC_PROTECTED) {
ss << "protected ";
}
if (acc & DexAccessFlags::ACC_STATIC) {
ss << "static ";
}
if (acc & DexAccessFlags::ACC_FINAL) {
ss << "final ";
}
if (acc & DexAccessFlags::ACC_INTERFACE) {
ss << "interface ";
} else if (acc & DexAccessFlags::ACC_ABSTRACT) {
ss << "abstract ";
}
if (acc & DexAccessFlags::ACC_ENUM) {
ss << "enum ";
}
if (acc & DexAccessFlags::ACC_SYNCHRONIZED) {
ss << "synchronized ";
}
if (acc & DexAccessFlags::ACC_VOLATILE) {
if (method)
ss << "bridge ";
else
ss << "volatile ";
}
if (acc & DexAccessFlags::ACC_NATIVE) {
ss << "native ";
}
if (acc & DexAccessFlags::ACC_TRANSIENT) {
if (method)
ss << "vararg ";
else
ss << "transient ";
}
return ss.str();
}
std::string show(DexAnnotationVisibility vis) {
switch (vis) {
case DAV_BUILD:
return "build";
case DAV_RUNTIME:
return "runtime";
case DAV_SYSTEM:
return "system";
}
not_reached();
}
std::string show_opcode(const DexOpcode* op) {
if (!op) return "";
std::stringstream ss;
auto opcode = op->opcode();
switch (opcode) {
case OPCODE_NOP:
return "nop";
case OPCODE_MOVE:
return "move";
case OPCODE_MOVE_WIDE:
return "move-wide";
case OPCODE_MOVE_OBJECT:
return "move-object";
case OPCODE_MOVE_RESULT:
return "move-result";
case OPCODE_MOVE_RESULT_WIDE:
return "move-result-wide";
case OPCODE_MOVE_RESULT_OBJECT:
return "move-result-object";
case OPCODE_MOVE_EXCEPTION:
return "move-exception";
case OPCODE_RETURN_VOID:
return "return-void";
case OPCODE_RETURN:
return "return";
case OPCODE_RETURN_WIDE:
return "return-wide";
case OPCODE_RETURN_OBJECT:
return "return-object";
case OPCODE_CONST_4:
return "const/4";
case OPCODE_MONITOR_ENTER:
return "monitor-enter";
case OPCODE_MONITOR_EXIT:
return "monitor-exit";
case OPCODE_THROW:
return "throw";
case OPCODE_GOTO:
return "goto";
case OPCODE_NEG_INT:
return "neg-int";
case OPCODE_NOT_INT:
return "not-int";
case OPCODE_NEG_LONG:
return "neg-long";
case OPCODE_NOT_LONG:
return "not-long";
case OPCODE_NEG_FLOAT:
return "neg-float";
case OPCODE_NEG_DOUBLE:
return "neg-double";
case OPCODE_INT_TO_LONG:
return "int-to-long";
case OPCODE_INT_TO_FLOAT:
return "int-to-float";
case OPCODE_INT_TO_DOUBLE:
return "int-to-double";
case OPCODE_LONG_TO_INT:
return "long-to-int";
case OPCODE_LONG_TO_FLOAT:
return "long-to-float";
case OPCODE_LONG_TO_DOUBLE:
return "long-to-double";
case OPCODE_FLOAT_TO_INT:
return "float-to-int";
case OPCODE_FLOAT_TO_LONG:
return "float-to-long";
case OPCODE_FLOAT_TO_DOUBLE:
return "float-to-double";
case OPCODE_DOUBLE_TO_INT:
return "double-to-int";
case OPCODE_DOUBLE_TO_LONG:
return "double-to-long";
case OPCODE_DOUBLE_TO_FLOAT:
return "double-to-float";
case OPCODE_INT_TO_BYTE:
return "int-to-byte";
case OPCODE_INT_TO_CHAR:
return "int-to-char";
case OPCODE_INT_TO_SHORT:
return "int-to-short";
case OPCODE_ADD_INT_2ADDR:
return "add-int/2addr";
case OPCODE_SUB_INT_2ADDR:
return "sub-int/2addr";
case OPCODE_MUL_INT_2ADDR:
return "mul-int/2addr";
case OPCODE_DIV_INT_2ADDR:
return "div-int/2addr";
case OPCODE_REM_INT_2ADDR:
return "rem-int/2addr";
case OPCODE_AND_INT_2ADDR:
return "and-int/2addr";
case OPCODE_OR_INT_2ADDR:
return "or-int/2addr";
case OPCODE_XOR_INT_2ADDR:
return "xor-int/2addr";
case OPCODE_SHL_INT_2ADDR:
return "shl-int/2addr";
case OPCODE_SHR_INT_2ADDR:
return "shr-int/2addr";
case OPCODE_USHR_INT_2ADDR:
return "ushr-int/2addr";
case OPCODE_ADD_LONG_2ADDR:
return "add-long/2addr";
case OPCODE_SUB_LONG_2ADDR:
return "sub-long/2addr";
case OPCODE_MUL_LONG_2ADDR:
return "mul-long/2addr";
case OPCODE_DIV_LONG_2ADDR:
return "div-long/2addr";
case OPCODE_REM_LONG_2ADDR:
return "rem-long/2addr";
case OPCODE_AND_LONG_2ADDR:
return "and-long/2addr";
case OPCODE_OR_LONG_2ADDR:
return "or-long/2addr";
case OPCODE_XOR_LONG_2ADDR:
return "xor-long/2addr";
case OPCODE_SHL_LONG_2ADDR:
return "shl-long/2addr";
case OPCODE_SHR_LONG_2ADDR:
return "shr-long/2addr";
case OPCODE_USHR_LONG_2ADDR:
return "ushr-long/2addr";
case OPCODE_ADD_FLOAT_2ADDR:
return "add-float/2addr";
case OPCODE_SUB_FLOAT_2ADDR:
return "sub-float/2addr";
case OPCODE_MUL_FLOAT_2ADDR:
return "mul-float/2addr";
case OPCODE_DIV_FLOAT_2ADDR:
return "div-float/2addr";
case OPCODE_REM_FLOAT_2ADDR:
return "rem-float/2addr";
case OPCODE_ADD_DOUBLE_2ADDR:
return "add-double/2addr";
case OPCODE_SUB_DOUBLE_2ADDR:
return "sub-double/2addr";
case OPCODE_MUL_DOUBLE_2ADDR:
return "mul-double/2addr";
case OPCODE_DIV_DOUBLE_2ADDR:
return "div-double/2addr";
case OPCODE_REM_DOUBLE_2ADDR:
return "rem-double/2addr";
case OPCODE_ARRAY_LENGTH:
return "array-length";
case OPCODE_MOVE_FROM16:
return "move/from16";
case OPCODE_MOVE_WIDE_FROM16:
return "move-wide/from16";
case OPCODE_MOVE_OBJECT_FROM16:
return "move-object/from16";
case OPCODE_CONST_16:
return "const/16";
case OPCODE_CONST_HIGH16:
return "const/high16";
case OPCODE_CONST_WIDE_16:
return "const-wide/16";
case OPCODE_CONST_WIDE_HIGH16:
return "const-wide/high16";
case OPCODE_GOTO_16:
return "goto/16";
case OPCODE_CMPL_FLOAT:
return "cpml-float";
case OPCODE_CMPG_FLOAT:
return "cpmg-float";
case OPCODE_CMPL_DOUBLE:
return "cpml-double";
case OPCODE_CMPG_DOUBLE:
return "cpmg-double";
case OPCODE_CMP_LONG:
return "cpm-long";
case OPCODE_IF_EQ:
return "if-eq";
case OPCODE_IF_NE:
return "if-ne";
case OPCODE_IF_LT:
return "if-lt";
case OPCODE_IF_GE:
return "if-ge";
case OPCODE_IF_GT:
return "if-gt";
case OPCODE_IF_LE:
return "if-le";
case OPCODE_IF_EQZ:
return "if-eqz";
case OPCODE_IF_NEZ:
return "if-nez";
case OPCODE_IF_LTZ:
return "if-ltz";
case OPCODE_IF_GEZ:
return "if-gez";
case OPCODE_IF_GTZ:
return "if-gtz";
case OPCODE_IF_LEZ:
return "if-lez";
case OPCODE_AGET:
return "aget";
case OPCODE_AGET_WIDE:
return "aget-wide";
case OPCODE_AGET_OBJECT:
return "aget-object";
case OPCODE_AGET_BOOLEAN:
return "aget-boolean";
case OPCODE_AGET_BYTE:
return "aget-byte";
case OPCODE_AGET_CHAR:
return "aget-char";
case OPCODE_AGET_SHORT:
return "aget-short";
case OPCODE_APUT:
return "aput";
case OPCODE_APUT_WIDE:
return "aput-wide";
case OPCODE_APUT_OBJECT:
return "aput-object";
case OPCODE_APUT_BOOLEAN:
return "aput-boolean";
case OPCODE_APUT_BYTE:
return "aput-byte";
case OPCODE_APUT_CHAR:
return "aput-char";
case OPCODE_APUT_SHORT:
return "aput-short";
case OPCODE_ADD_INT:
return "add-int";
case OPCODE_SUB_INT:
return "sub-int";
case OPCODE_MUL_INT:
return "mul-int";
case OPCODE_DIV_INT:
return "div-int";
case OPCODE_REM_INT:
return "rem-int";
case OPCODE_AND_INT:
return "and-int";
case OPCODE_OR_INT:
return "or-int";
case OPCODE_XOR_INT:
return "xor-int";
case OPCODE_SHL_INT:
return "shl-int";
case OPCODE_SHR_INT:
return "shr-int";
case OPCODE_USHR_INT:
return "ushr-int";
case OPCODE_ADD_LONG:
return "add-long";
case OPCODE_SUB_LONG:
return "sub-long";
case OPCODE_MUL_LONG:
return "mul-long";
case OPCODE_DIV_LONG:
return "div-long";
case OPCODE_REM_LONG:
return "rem-long";
case OPCODE_AND_LONG:
return "and-long";
case OPCODE_OR_LONG:
return "or-long";
case OPCODE_XOR_LONG:
return "xor-long";
case OPCODE_SHL_LONG:
return "shl-long";
case OPCODE_SHR_LONG:
return "shr-long";
case OPCODE_USHR_LONG:
return "ushr-long";
case OPCODE_ADD_FLOAT:
return "add-float";
case OPCODE_SUB_FLOAT:
return "sub-float";
case OPCODE_MUL_FLOAT:
return "mul-float";
case OPCODE_DIV_FLOAT:
return "div-float";
case OPCODE_REM_FLOAT:
return "rem-float";
case OPCODE_ADD_DOUBLE:
return "add-double";
case OPCODE_SUB_DOUBLE:
return "sub-double";
case OPCODE_MUL_DOUBLE:
return "mul-double";
case OPCODE_DIV_DOUBLE:
return "div-double";
case OPCODE_REM_DOUBLE:
return "rem-double";
case OPCODE_ADD_INT_LIT16:
return "add-int/lit16";
case OPCODE_RSUB_INT:
return "rsub-int";
case OPCODE_MUL_INT_LIT16:
return "mul-int/lit16";
case OPCODE_DIV_INT_LIT16:
return "div-int/lit16";
case OPCODE_REM_INT_LIT16:
return "rem-int/lit16";
case OPCODE_AND_INT_LIT16:
return "and-int/lit16";
case OPCODE_OR_INT_LIT16:
return "or-int/lit16";
case OPCODE_XOR_INT_LIT16:
return "xor-int/lit16";
case OPCODE_ADD_INT_LIT8:
return "add-int/lit8";
case OPCODE_RSUB_INT_LIT8:
return "rsub-int/lit8";
case OPCODE_MUL_INT_LIT8:
return "mul-int/lit8";
case OPCODE_DIV_INT_LIT8:
return "div-int/lit8";
case OPCODE_REM_INT_LIT8:
return "rem-int/lit8";
case OPCODE_AND_INT_LIT8:
return "and-int/lit8";
case OPCODE_OR_INT_LIT8:
return "or-int/lit8";
case OPCODE_XOR_INT_LIT8:
return "xor-int/lit8";
case OPCODE_SHL_INT_LIT8:
return "shl-int/lit8";
case OPCODE_SHR_INT_LIT8:
return "shr-int/lit8";
case OPCODE_USHR_INT_LIT8:
return "ushr-int/lit8";
case OPCODE_MOVE_16:
return "move/16";
case OPCODE_MOVE_WIDE_16:
return "move-wide/16";
case OPCODE_MOVE_OBJECT_16:
return "move-object/16";
case OPCODE_CONST:
return "const";
case OPCODE_CONST_WIDE_32:
return "const-wide/32";
case OPCODE_FILL_ARRAY_DATA:
return "fill-array-data";
case OPCODE_GOTO_32:
return "goto/32";
case OPCODE_PACKED_SWITCH:
return "packed-switch";
case OPCODE_SPARSE_SWITCH:
return "sparse-switch";
case OPCODE_CONST_WIDE:
return "const-wide";
// field opcode
case OPCODE_IGET:
ss << "iget " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IGET_WIDE:
ss << "iget-wide " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IGET_OBJECT:
ss << "iget-object " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IGET_BOOLEAN:
ss << "iget-boolean " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IGET_BYTE:
ss << "iget-byte " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IGET_CHAR:
ss << "iget-char " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IGET_SHORT:
ss << "iget-short " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IPUT:
ss << "iput " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IPUT_WIDE:
ss << "iput-wide " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IPUT_OBJECT:
ss << "iput-object " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IPUT_BOOLEAN:
ss << "iput-boolean " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IPUT_BYTE:
ss << "iput-byte " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IPUT_CHAR:
ss << "iput-char " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_IPUT_SHORT:
ss << "iput-short " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SGET:
ss << "sget " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SGET_WIDE:
ss << "sget-wide " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SGET_OBJECT:
ss << "sget-object " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SGET_BOOLEAN:
ss << "sget-boolean " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SGET_BYTE:
ss << "sget-byte " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SGET_CHAR:
ss << "sget-char " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SGET_SHORT:
ss << "sget-short " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SPUT:
ss << "sput " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SPUT_WIDE:
ss << "sput-wide " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SPUT_OBJECT:
ss << "sput-object " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SPUT_BOOLEAN:
ss << "sput-boolean " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SPUT_BYTE:
ss << "sput-byte " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SPUT_CHAR:
ss << "sput-char " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_SPUT_SHORT:
ss << "sput-short " << show(((DexOpcodeField*)op)->field());
return ss.str();
case OPCODE_INVOKE_VIRTUAL:
ss << "invoke-virtual " << show(((DexOpcodeMethod*)op)->get_method());
return ss.str();
case OPCODE_INVOKE_SUPER:
ss << "invoke-super " << show(((DexOpcodeMethod*)op)->get_method());
return ss.str();
case OPCODE_INVOKE_DIRECT:
ss << "invoke-direct " << show(((DexOpcodeMethod*)op)->get_method());
return ss.str();
case OPCODE_INVOKE_STATIC:
ss << "invoke-static " << show(((DexOpcodeMethod*)op)->get_method());
return ss.str();
case OPCODE_INVOKE_INTERFACE:
ss << "invoke-interface " << show(((DexOpcodeMethod*)op)->get_method());
return ss.str();
case OPCODE_INVOKE_VIRTUAL_RANGE:
ss << "invoke-virtual/range " << show(((DexOpcodeMethod*)op)->get_method());
return ss.str();
case OPCODE_INVOKE_SUPER_RANGE:
ss << "invoke-super/range " << show(((DexOpcodeMethod*)op)->get_method());
return ss.str();
case OPCODE_INVOKE_DIRECT_RANGE:
ss << "invoke-direct/range " << show(((DexOpcodeMethod*)op)->get_method());
return ss.str();
case OPCODE_INVOKE_STATIC_RANGE:
ss << "invoke-static/range " << show(((DexOpcodeMethod*)op)->get_method());
return ss.str();
case OPCODE_INVOKE_INTERFACE_RANGE:
ss << "invoke-interface/range "
<< show(((DexOpcodeMethod*)op)->get_method());
return ss.str();
case OPCODE_CONST_STRING:
ss << "const-string " << show(((DexOpcodeString*)op)->get_string());
return ss.str();
case OPCODE_CONST_STRING_JUMBO:
ss << "const-string/jumbo " << show(((DexOpcodeString*)op)->get_string());
return ss.str();
case OPCODE_CONST_CLASS:
ss << "const-class " << show(((DexOpcodeType*)op)->get_type());
return ss.str();
case OPCODE_CHECK_CAST:
ss << "check-cast " << show(((DexOpcodeType*)op)->get_type());
return ss.str();
case OPCODE_INSTANCE_OF:
ss << "instance-of " << show(((DexOpcodeType*)op)->get_type());
return ss.str();
case OPCODE_NEW_INSTANCE:
ss << "new-instance " << show(((DexOpcodeType*)op)->get_type());
return ss.str();
case OPCODE_NEW_ARRAY:
ss << "new-array " << show(((DexOpcodeType*)op)->get_type());
return ss.str();
case OPCODE_FILLED_NEW_ARRAY:
ss << "filled-new-array " << show(((DexOpcodeType*)op)->get_type());
return ss.str();
case OPCODE_FILLED_NEW_ARRAY_RANGE:
ss << "filled-new-array/range " << show(((DexOpcodeType*)op)->get_type());
return ss.str();
case FOPCODE_PACKED_SWITCH:
ss << "packed-switch";
return ss.str();
case FOPCODE_SPARSE_SWITCH:
ss << "sparse-switch";
return ss.str();
case FOPCODE_FILLED_ARRAY:
ss << "filled-array";
return ss.str();
default:
return "unknown_op_code";
}
}
}
std::string show(const DexString* p) {
if (!p) return "";
return std::string(p->m_cstr);
}
std::string show(const DexType* p) {
if (!p) return "";
return show(p->m_name);
}
std::string show(const DexField* p) {
if (!p) return "";
std::stringstream ss;
ss << accessibility(p->m_access) << humanize(show(p->m_type)) << " "
<< humanize(show(p->m_class)) << "." << show(p->m_name);
if (p->m_anno) {
ss << "\n annotations:" << show(p->m_anno);
}
return ss.str();
}
std::string show(const DexTypeList* p) {
if (!p) return "";
std::stringstream ss;
for (auto const type : p->m_list) {
ss << show(type);
}
return ss.str();
}
std::string show(const DexProto* p) {
if (!p) return "";
std::stringstream ss;
ss << "(" << show(p->m_args) << ")" << show(p->m_rtype);
return ss.str();
}
std::string show(const DexCode* code) {
if (!code) return "";
std::stringstream ss;
ss << "regs: " << code->m_registers_size << ", ins: " << code->m_ins_size
<< ", outs: " << code->m_outs_size << "\n";
for (auto insn : code->m_insns) {
ss << show(insn) << "\n";
}
return ss.str();
}
std::string show(const DexMethod* p) {
if (!p) return "";
std::stringstream ss;
ss << accessibility(p->m_access, true) << humanize(show(p->m_class)) << "."
<< show(p->m_name) << show(p->m_proto);
if (p->m_anno) {
ss << "\n annotations:" << show(p->m_anno);
}
bool first = true;
for (auto const pair : p->m_param_anno) {
if (first) {
ss << "\n param annotations:"
<< "\n";
first = false;
}
ss << " " << pair.first << ": " << show(pair.second) << "\n";
}
return ss.str();
}
std::string show(const DexClass* p) {
if (!p) return "";
std::stringstream ss;
ss << accessibility(p->get_access()) << humanize(show(p->m_self))
<< " extends " << humanize(show(p->m_super_class));
if (p->m_interfaces) {
ss << " implements ";
bool first = true;
for (auto const type : p->m_interfaces->get_type_list()) {
if (first)
first = false;
else
ss << ", ";
ss << humanize(show(type));
}
}
if (p->m_anno) {
ss << "\n annotations:" << show(p->m_anno);
}
return ss.str();
}
std::string show(const DexEncodedValue* value) {
if (!value) return "";
return value->show();
}
std::string DexEncodedValue::show() const {
std::stringstream ss;
ss << m_value;
return ss.str();
}
std::string DexEncodedValueArray::show() const {
std::stringstream ss;
ss << (m_static_val ? "(static) " : "");
if (m_evalues) {
bool first = true;
for (auto const evalue : *m_evalues) {
if (!first) ss << ' ';
ss << evalue->show();
first = false;
}
}
return ss.str();
}
std::string DexEncodedValueAnnotation::show() const {
std::stringstream ss;
ss << "type:" << ::show(m_type) << " annotations:" << ::show(m_annotations);
return ss.str();
}
std::string show(const EncodedAnnotations* annos) {
if (!annos) return "";
std::stringstream ss;
bool first = true;
for (auto const pair : *annos) {
if (!first) ss << ", ";
ss << show(pair.string) << ":" << pair.encoded_value->show();
first = false;
}
return ss.str();
}
std::string show(const DexAnnotation* p) {
if (!p) return "";
std::stringstream ss;
ss << "type:" << show(p->m_type) << " visibility:" << show(p->m_viz)
<< " annotations:" << show(&p->m_anno_elems);
return ss.str();
}
std::string show(const DexAnnotationSet* p) {
if (!p) return "";
std::stringstream ss;
bool first = true;
for (auto const anno : p->m_annotations) {
if (!first) ss << ", ";
ss << show(anno);
first = false;
}
return ss.str();
}
std::string show(const DexAnnotationDirectory* p) {
if (!p) return "";
std::stringstream ss;
if (p->m_class) {
ss << "class annotations:\n" << show(p->m_class) << "\n";
}
if (p->m_field) {
ss << "field annotations:\n";
for (auto const pair : *p->m_field) {
ss << show(pair.first->get_name()) << ": " << show(pair.second) << "\n";
}
}
if (p->m_method) {
ss << "method annotations:\n";
for (auto const pair : *p->m_method) {
ss << show(pair.first->get_name()) << ": " << show(pair.second) << "\n";
}
}
if (p->m_method_param) {
ss << "method parameter annotations:\n";
for (auto const pair : *p->m_method_param) {
ss << show(pair.first->get_name());
for (auto const parampair : *pair.second) {
ss << " " << parampair.first << ": " << show(parampair.second) << "\n";
}
}
}
return ss.str();
}
std::string show(DexCodeItemOpcode opcode) {
switch (opcode) {
#define OP(op, ...) \
case OPCODE_##op: \
return #op;
OPS
#undef OP
case FOPCODE_PACKED_SWITCH : return "PACKED_SWITCH_DATA";
case FOPCODE_SPARSE_SWITCH:
return "SPARSE_SWITCH_DATA";
case FOPCODE_FILLED_ARRAY:
return "FILLED_ARRAY_DATA";
}
always_assert_log(false, "Unknown opcode");
return "";
}
std::string show(const DexOpcode* op) {
if (!op) return "";
std::stringstream ss;
ss << show_opcode(op);
bool first = true;
if (op->dests_size()) {
ss << " v" << op->dest();
first = false;
}
for (unsigned i = 0; i < op->srcs_size(); ++i) {
if (!first) ss << ",";
ss << " v" << op->src(i);
first = false;
}
return ss.str();
}
std::string show(const DexDebugOpcode* op) {
if (!op) return "";
std::stringstream ss;
switch (op->opcode()) {
case DBG_END_SEQUENCE:
ss << "DBG_END_SEQUENCE";
break;
case DBG_ADVANCE_PC:
ss << "DBG_ADVANCE_PC " << op->uvalue();
break;
case DBG_ADVANCE_LINE:
ss << "DBG_ADVANCE_LINE " << op->value();
break;
case DBG_START_LOCAL: {
auto sl = static_cast<const DexDebugOpcodeStartLocal*>(op);
ss << "DBG_START_LOCAL v" << sl->uvalue() << " " << show(sl->name())
<< ":" << show(sl->type());
break;
}
case DBG_START_LOCAL_EXTENDED: {
auto sl = static_cast<const DexDebugOpcodeStartLocal*>(op);
ss << "DBG_START_LOCAL v" << sl->uvalue() << " " << show(sl->name())
<< ":" << show(sl->type()) << ";" << show(sl->sig());
break;
}
case DBG_END_LOCAL:
ss << "DBG_END_LOCAL v" << op->uvalue();
break;
case DBG_RESTART_LOCAL:
ss << "DBG_RESTART_LOCAL v" << op->uvalue();
break;
case DBG_SET_PROLOGUE_END:
ss << "DBG_SET_PROLOGUE_END";
break;
case DBG_SET_EPILOGUE_BEGIN:
ss << "DBG_SET_EPILOGUE_BEGIN";
break;
case DBG_SET_FILE: {
auto sf = static_cast<const DexDebugOpcodeSetFile*>(op);
ss << "DBG_SET_FILE " << show(sf->file());
break;
}
default: {
constexpr int DBG_FIRST_SPECIAL = 0x0a;
constexpr int DBG_LINE_BASE = -4;
constexpr int DBG_LINE_RANGE = 15;
auto adjusted_opcode = op->opcode() - DBG_FIRST_SPECIAL;
auto line = DBG_LINE_BASE + (adjusted_opcode % DBG_LINE_RANGE);
auto address = (adjusted_opcode / DBG_LINE_RANGE);
ss << "DBG_SPECIAL line+=" << line << " addr+=" << address;
}
}
return ss.str();
}
std::string show(TryEntryType t) {
switch (t) {
case TRY_START:
return "TRY_START";
case TRY_END:
return "TRY_END";
case TRY_CATCH:
return "TRY_CATCH";
}
not_reached();
}
std::string show(const MethodItemEntry& mei) {
std::stringstream ss;
switch (mei.type) {
case MFLOW_OPCODE:
ss << "OPCODE: [" << mei.op << "] " << show(mei.op);
return ss.str();
case MFLOW_TARGET:
if (mei.target->type == BRANCH_MULTI) {
ss << "TARGET MULTI: " << mei.target->src->op;
} else {
ss << "TARGET SIMPLE: " << mei.target->src->op;
}
return ss.str();
case MFLOW_TRY:
ss << "TRY: " << show(mei.tentry->type);
return ss.str();
case MFLOW_DEBUG:
ss << "DEBUG: " << show(mei.dbgop);
return ss.str();
case MFLOW_FALLTHROUGH:
return "FALLTHROUGH:";
}
not_reached();
}
std::string show(const FatMethod* fm) {
std::string ret;
for (auto const& mei : *fm) {
ret += show(mei);
ret += "\n";
}
return ret;
}
std::string show(const std::vector<Block*>& blocks) {
std::stringstream ss;
ss << "CFG:\n";
for (auto& b : blocks) {
ss << "B" << b->m_id << " succs:";
for (auto& s : b->m_succs) {
ss << " B" << s->m_id;
}
ss << " preds:";
for (auto& p : b->m_preds) {
ss << " B" << p->m_id;
}
ss << "\n";
}
for (auto const& b : blocks) {
ss << " Block B" << b->m_id << ":\n";
for (auto const& mei : *b) {
ss << " " << show(mei) << "\n";
}
}
return ss.str();
}
std::string show(const MethodCreator* mc) {
if (!mc) return "";
std::stringstream ss;
ss << "MethodCode for " << SHOW(mc->method) << "\n";
ss << "locals: ";
for (auto& loc : mc->locals) {
ss << "[" << loc.get_reg() << "] " << SHOW(loc.get_type());
}
ss << "\ninstructions:\n";
ss << show(mc->main_block);
return ss.str();
}
std::string show(const MethodBlock* block) {
if (!block) return "";
std::stringstream ss;
return ss.str();
}
std::string show(DexIdx* p) {
std::stringstream ss;
ss << "----------------------------------------\n"
<< "strings\n"
<< "----------------------------------------\n";
for (uint32_t i = 0; i < p->m_string_ids_size; i++) {
ss << show(p->m_string_cache[i]) << "\n";
}
ss << "----------------------------------------\n"
<< "types\n"
<< "----------------------------------------\n";
for (uint32_t i = 0; i < p->m_type_ids_size; i++) {
ss << show(p->m_type_cache[i]) << "\n";
}
ss << "----------------------------------------\n"
<< "fields\n"
<< "----------------------------------------\n";
for (uint32_t i = 0; i < p->m_field_ids_size; i++) {
ss << show(p->m_field_cache[i]) << "\n";
}