1818import com .reandroid .common .ByteSource ;
1919import com .reandroid .common .Origin ;
2020import com .reandroid .common .TextPosition ;
21+ import com .reandroid .dex .key .Key ;
2122import com .reandroid .utils .HexUtil ;
2223import com .reandroid .utils .NumbersUtil ;
2324import com .reandroid .utils .io .IOUtil ;
2627import java .io .IOException ;
2728import java .io .InputStream ;
2829import java .nio .charset .StandardCharsets ;
30+ import java .util .HashSet ;
31+ import java .util .Set ;
2932
3033public class SmaliReader {
3134
@@ -34,6 +37,8 @@ public class SmaliReader {
3437
3538 private Origin origin ;
3639
40+ private Set <Key > internedItems ;
41+
3742 public SmaliReader (ByteSource byteSource ) {
3843 this .byteSource = byteSource ;
3944 }
@@ -43,6 +48,7 @@ public SmaliReader(byte[] bytes) {
4348
4449 public void reset () {
4550 this .position (0 );
51+ this .internedItems = null ;
4652 }
4753 public int position () {
4854 return position ;
@@ -448,9 +454,15 @@ public void skip(int amount) {
448454 public Origin getCurrentOrigin () {
449455 return getOrigin (position ());
450456 }
457+ public Origin getCurrentOrigin (boolean withDescription ) {
458+ return getOrigin (position (), withDescription );
459+ }
451460 public Origin getOrigin (int position ) {
461+ return getOrigin (position , true );
462+ }
463+ public Origin getOrigin (int position , boolean withDescription ) {
452464 Origin origin = this .getOrigin ();
453- origin = origin .createChild (new SmaliTextPosition (byteSource , position ));
465+ origin = origin .createChild (new SmaliTextPosition (byteSource , position , withDescription ));
454466 return origin ;
455467 }
456468 public Origin getOrigin () {
@@ -464,6 +476,17 @@ public Origin getOrigin() {
464476 public void setOrigin (Origin origin ) {
465477 this .origin = origin ;
466478 }
479+ public boolean checkInterned (Key key ) {
480+ if (key == null ) {
481+ return false ;
482+ }
483+ Set <Key > internedItems = this .internedItems ;
484+ if (internedItems == null ) {
485+ internedItems = new HashSet <>();
486+ this .internedItems = internedItems ;
487+ }
488+ return !internedItems .add (key );
489+ }
467490
468491 @ Override
469492 public String toString () {
@@ -619,10 +642,12 @@ static class SmaliTextPosition extends TextPosition {
619642
620643 private ByteSource byteSource ;
621644 private final int position ;
645+ private final boolean withDescription ;
622646
623- public SmaliTextPosition (ByteSource byteSource , int position ) {
647+ public SmaliTextPosition (ByteSource byteSource , int position , boolean withDescription ) {
624648 this .byteSource = byteSource ;
625649 this .position = position ;
650+ this .withDescription = withDescription ;
626651 }
627652
628653 @ Override
@@ -662,6 +687,9 @@ private void computeValues() {
662687 this .byteSource = null ;
663688 }
664689 private String computePositionDescription (ByteSource byteSource ) {
690+ if (!withDescription ) {
691+ return null ;
692+ }
665693 int pos = this .position ;
666694 if (pos >= byteSource .length ()) {
667695 return "EOF" ;
0 commit comments