2424import com .reandroid .dex .id .IdItem ;
2525import com .reandroid .dex .id .MethodId ;
2626import com .reandroid .dex .id .StringId ;
27- import com .reandroid .dex .ins .ConstNumber ;
28- import com .reandroid .dex .ins .ConstNumberLong ;
29- import com .reandroid .dex .ins .Ins ;
30- import com .reandroid .dex .ins .InsConstStringJumbo ;
31- import com .reandroid .dex .ins .Label ;
32- import com .reandroid .dex .ins .Opcode ;
33- import com .reandroid .dex .ins .RegistersSet ;
34- import com .reandroid .dex .ins .SizeXIns ;
27+ import com .reandroid .dex .ins .*;
3528import com .reandroid .dex .key .FieldKey ;
3629import com .reandroid .dex .key .Key ;
3730import com .reandroid .dex .key .MethodKey ;
@@ -311,6 +304,15 @@ public boolean isMethodInvokeInterface() {
311304 public boolean isMethodInvoke () {
312305 return getOpcode ().isMethodInvoke ();
313306 }
307+ public boolean isMove () {
308+ return getOpcode ().isMove ();
309+ }
310+ public boolean isMoveResult () {
311+ return getOpcode ().isMoveResult ();
312+ }
313+ public boolean hasOutRegisters () {
314+ return getOpcode ().hasOutRegisters ();
315+ }
314316 public int getTargetAddress () {
315317 Ins ins = getIns ();
316318 if (ins instanceof Label ) {
@@ -536,6 +538,36 @@ public Iterator<DexInstruction> getTargetingInstructionsIfOpcode(Predicate<Opcod
536538 iterator = FilterIterator .of (iterator , ins -> predicate .test (ins .getOpcode ()));
537539 return DexInstruction .createAll (getDexMethod (), iterator );
538540 }
541+ // for switch payload instruction
542+ public Iterator <DexInstruction > getTargetSwitchCases () {
543+ Ins ins = getIns ();
544+ if (!(ins instanceof InsSwitchPayload )) {
545+ return EmptyIterator .of ();
546+ }
547+ InsSwitchPayload <? extends SwitchEntry > payload = (InsSwitchPayload <? extends SwitchEntry >) ins ;
548+ Iterator <? extends SwitchEntry > switchEntryIterator = payload .iterator ();
549+ if (!switchEntryIterator .hasNext ()) {
550+ return EmptyIterator .of ();
551+ }
552+ Iterator <Ins > iterator = ComputeIterator .of (switchEntryIterator , SwitchEntry ::getTargetIns );
553+ iterator = CollectionUtil .copyOfUniqueOf (iterator );
554+ return DexInstruction .createAll (getDexMethod (), iterator );
555+ }
556+ public DexInstruction getTargetingSwitch () {
557+ return CollectionUtil .getFirst (getTargetingSwitches (null ));
558+ }
559+ public Iterator <DexInstruction > getTargetingSwitches (Opcode <? extends InsSwitch > switchOpcode ) {
560+ Iterator <SwitchEntry > switchEntryIterator = getIns ().getForcedExtraLines (SwitchEntry .class );
561+ if (!switchEntryIterator .hasNext ()) {
562+ return EmptyIterator .of ();
563+ }
564+ Iterator <InsSwitch > iterator = ComputeIterator .of (switchEntryIterator , SwitchEntry ::getInsSwitch );
565+ if (switchOpcode != null ) {
566+ iterator = FilterIterator .of (iterator , ins -> ins .getOpcode () == switchOpcode );
567+ }
568+ iterator = CollectionUtil .copyOfUniqueOf (iterator );
569+ return DexInstruction .createAll (getDexMethod (), iterator );
570+ }
539571 public DexInstruction getNext () {
540572 return getDexMethod ().getInstruction (getIndex () + 1 );
541573 }
@@ -548,6 +580,16 @@ public DexInstruction getPrevious() {
548580 public Iterator <DexInstruction > getPreviousInstructions () {
549581 return LinkedIterator .of (this , DexInstruction ::getPrevious );
550582 }
583+ public DexInstruction getMoveResult () {
584+ if (!hasOutRegisters ()) {
585+ return null ;
586+ }
587+ DexInstruction next = getNext ();
588+ if (next != null && next .isMoveResult ()) {
589+ return next ;
590+ }
591+ return null ;
592+ }
551593
552594 public DexInstruction getPreviousReader (int register ) {
553595 return getPreviousReader (register , CollectionUtil .getAcceptAll ());
@@ -643,7 +685,7 @@ public String toString() {
643685 return getIns ().toString ();
644686 }
645687
646- public static Iterator <DexInstruction > createAll (DexMethod dexMethod , Iterator <Ins > iterator ) {
688+ public static Iterator <DexInstruction > createAll (DexMethod dexMethod , Iterator <? extends Ins > iterator ) {
647689 if (dexMethod == null || !iterator .hasNext ()) {
648690 return EmptyIterator .of ();
649691 }
0 commit comments