Skip to content

Commit 356b4e8

Browse files
committed
fix: fix inlining synthetic accessors
1 parent 1b08779 commit 356b4e8

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class InsnNode extends LineAttrNode {
3030

3131
private RegisterArg result;
3232
private final List<InsnArg> arguments;
33+
private final List<InsnArg> unmodifiableArgs;
3334
protected int offset;
3435

3536
public InsnNode(InsnType type, int argsCount) {
@@ -39,6 +40,7 @@ public InsnNode(InsnType type, int argsCount) {
3940
public InsnNode(InsnType type, List<InsnArg> args) {
4041
this.insnType = type;
4142
this.arguments = args;
43+
this.unmodifiableArgs = Collections.unmodifiableList(arguments);
4244
this.offset = -1;
4345
for (InsnArg arg : args) {
4446
attachArg(arg);
@@ -91,8 +93,8 @@ public RegisterArg getResult() {
9193
return result;
9294
}
9395

94-
public Iterable<InsnArg> getArguments() {
95-
return arguments;
96+
public List<InsnArg> getArguments() {
97+
return unmodifiableArgs;
9698
}
9799

98100
public int getArgsCount() {

jadx-core/src/main/java/jadx/core/dex/visitors/MarkMethodsForInline.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6+
import jadx.core.utils.ListUtils;
67
import org.jetbrains.annotations.Nullable;
78

89
import jadx.api.plugins.input.data.AccessFlags;
@@ -113,9 +114,13 @@ private static boolean isSyntheticAccessPattern(MethodNode mth, InsnNode firstIn
113114
&& firstInsn.getArg(0).isSameVar(mthRegs.get(0));
114115

115116
case INVOKE:
116-
return !mthRegs.isEmpty()
117-
&& firstInsn.getArg(0).isSameVar(mthRegs.get(0))
118-
&& retInsn.getArg(0).isSameVar(firstInsn.getResult());
117+
if (!retInsn.getArg(0).isSameVar(firstInsn.getResult())) {
118+
return false;
119+
}
120+
121+
return ListUtils.orderedEquals(
122+
mth.getArgRegs(), firstInsn.getArguments(),
123+
(mthArg, insnArg) -> insnArg.isSameVar(mthArg));
119124
default:
120125
return false;
121126
}

jadx-core/src/main/java/jadx/core/utils/ListUtils.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
import java.util.Arrays;
55
import java.util.Collection;
66
import java.util.Collections;
7+
import java.util.Iterator;
78
import java.util.LinkedHashSet;
89
import java.util.List;
910
import java.util.Objects;
1011
import java.util.Set;
1112
import java.util.TreeSet;
13+
import java.util.function.BiPredicate;
1214
import java.util.function.Function;
1315
import java.util.function.Predicate;
1416

17+
import org.jetbrains.annotations.NotNull;
1518
import org.jetbrains.annotations.Nullable;
1619

1720
public class ListUtils {
@@ -30,6 +33,34 @@ public static <T> boolean unorderedEquals(List<T> first, List<T> second) {
3033
return first.containsAll(second);
3134
}
3235

36+
public static <T, U> boolean orderedEquals(
37+
@NotNull List<T> list1,
38+
@NotNull List<U> list2,
39+
@NotNull BiPredicate<T, U> comparer) {
40+
41+
if (list1 == list2) {
42+
return true;
43+
}
44+
45+
if (list1.size() != list2.size()) {
46+
return false;
47+
}
48+
49+
final Iterator<T> iter1 = list1.iterator();
50+
final Iterator<U> iter2 = list2.iterator();
51+
52+
while (iter1.hasNext() && iter2.hasNext()) {
53+
final T item1 = iter1.next();
54+
final U item2 = iter2.next();
55+
56+
if (!comparer.test(item1, item2)) {
57+
return false;
58+
}
59+
}
60+
61+
return !iter1.hasNext() && !iter2.hasNext();
62+
}
63+
3364
public static <T, R> List<R> map(Collection<T> list, Function<T, R> mapFunc) {
3465
if (list == null || list.isEmpty()) {
3566
return Collections.emptyList();

0 commit comments

Comments
 (0)