|
42 | 42 | import com.reandroid.dex.smali.SmaliReader; |
43 | 43 | import com.reandroid.dex.smali.SmaliWriter; |
44 | 44 | import com.reandroid.dex.smali.model.SmaliInstruction; |
45 | | -import com.reandroid.utils.collection.CollectionUtil; |
46 | | -import com.reandroid.utils.collection.ComputeIterator; |
47 | | -import com.reandroid.utils.collection.EmptyIterator; |
48 | | -import com.reandroid.utils.collection.FilterIterator; |
49 | | -import com.reandroid.utils.collection.IterableIterator; |
| 45 | +import com.reandroid.utils.collection.*; |
50 | 46 |
|
51 | 47 | import java.io.IOException; |
52 | 48 | import java.util.Iterator; |
@@ -399,12 +395,41 @@ public DexDeclaration findDeclaration() { |
399 | 395 | } |
400 | 396 | return null; |
401 | 397 | } |
| 398 | + public DexInstruction getTargetInstruction() { |
| 399 | + return DexInstruction.create(getDexMethod(), getIns().getTargetIns()); |
| 400 | + } |
| 401 | + public boolean hasTargetingInstructions() { |
| 402 | + return getIns().getForcedExtraLines(Ins.class).hasNext(); |
| 403 | + } |
| 404 | + public boolean hasTargetingInstructionsIfOpcode(Predicate<Opcode<?>> predicate) { |
| 405 | + return FilterIterator.of(getIns().getForcedExtraLines(Ins.class), |
| 406 | + ins -> predicate.test(ins.getOpcode())).hasNext(); |
| 407 | + } |
| 408 | + public Iterator<DexInstruction> getTargetingInstructions() { |
| 409 | + return DexInstruction.createAll(getDexMethod(), |
| 410 | + CollectionUtil.copyOf(getIns().getForcedExtraLines(Ins.class))); |
| 411 | + } |
| 412 | + public Iterator<DexInstruction> getTargetingInstructionsIfOpcode(Predicate<Opcode<?>> predicate) { |
| 413 | + Iterator<Ins> iterator = CollectionUtil.copyOf(getIns().getForcedExtraLines(Ins.class)); |
| 414 | + if (!iterator.hasNext()) { |
| 415 | + return EmptyIterator.of(); |
| 416 | + } |
| 417 | + iterator = FilterIterator.of(iterator, ins -> predicate.test(ins.getOpcode())); |
| 418 | + return DexInstruction.createAll(getDexMethod(), iterator); |
| 419 | + } |
402 | 420 | public DexInstruction getNext() { |
403 | 421 | return getDexMethod().getInstruction(getIndex() + 1); |
404 | 422 | } |
| 423 | + public Iterator<DexInstruction> getNextInstructions() { |
| 424 | + return LinkedIterator.of(this, DexInstruction::getNext); |
| 425 | + } |
405 | 426 | public DexInstruction getPrevious() { |
406 | 427 | return getDexMethod().getInstruction(getIndex() - 1); |
407 | 428 | } |
| 429 | + public Iterator<DexInstruction> getPreviousInstructions() { |
| 430 | + return LinkedIterator.of(this, DexInstruction::getPrevious); |
| 431 | + } |
| 432 | + |
408 | 433 | public DexInstruction getPreviousReader(int register) { |
409 | 434 | return getPreviousReader(register, CollectionUtil.getAcceptAll()); |
410 | 435 | } |
@@ -499,8 +524,8 @@ public String toString() { |
499 | 524 | return getIns().toString(); |
500 | 525 | } |
501 | 526 |
|
502 | | - public static Iterator<DexInstruction> create(DexMethod dexMethod, Iterator<Ins> iterator) { |
503 | | - if (dexMethod == null) { |
| 527 | + public static Iterator<DexInstruction> createAll(DexMethod dexMethod, Iterator<Ins> iterator) { |
| 528 | + if (dexMethod == null || !iterator.hasNext()) { |
504 | 529 | return EmptyIterator.of(); |
505 | 530 | } |
506 | 531 | return ComputeIterator.of(iterator, ins -> create(dexMethod, ins)); |
|
0 commit comments