Commit 28d348b3 authored by Skylot's avatar Skylot

fix: additional checks for synthetic methods remove, rename and inline (#452)

parent 91691fbd
...@@ -95,10 +95,10 @@ public class Jadx { ...@@ -95,10 +95,10 @@ public class Jadx {
passes.add(new SimplifyVisitor()); passes.add(new SimplifyVisitor());
passes.add(new CheckRegions()); passes.add(new CheckRegions());
passes.add(new MethodInlineVisitor());
passes.add(new ExtractFieldInit()); passes.add(new ExtractFieldInit());
passes.add(new FixAccessModifiers()); passes.add(new FixAccessModifiers());
passes.add(new ClassModifier()); passes.add(new ClassModifier());
passes.add(new MethodInlineVisitor());
passes.add(new EnumVisitor()); passes.add(new EnumVisitor());
passes.add(new PrepareForCodeGen()); passes.add(new PrepareForCodeGen());
passes.add(new LoopRegionVisitor()); passes.add(new LoopRegionVisitor());
......
...@@ -97,11 +97,11 @@ public class ClsSet { ...@@ -97,11 +97,11 @@ public class ClsSet {
} }
private static NClass getCls(String fullName, Map<String, NClass> names) { private static NClass getCls(String fullName, Map<String, NClass> names) {
NClass id = names.get(fullName); NClass cls = names.get(fullName);
if (id == null && !names.containsKey(fullName)) { if (cls == null) {
LOG.debug("Class not found: {}", fullName); LOG.debug("Class not found: {}", fullName);
} }
return id; return cls;
} }
void save(File output) throws IOException { void save(File output) throws IOException {
......
...@@ -7,7 +7,7 @@ public class NClass { ...@@ -7,7 +7,7 @@ public class NClass {
private final String name; private final String name;
private NClass[] parents; private NClass[] parents;
private int id; private final int id;
public NClass(String name, int id) { public NClass(String name, int id) {
this.name = name; this.name = name;
...@@ -22,10 +22,6 @@ public class NClass { ...@@ -22,10 +22,6 @@ public class NClass {
return id; return id;
} }
public void setId(int id) {
this.id = id;
}
public NClass[] getParents() { public NClass[] getParents() {
return parents; return parents;
} }
......
...@@ -63,12 +63,7 @@ public class AnnotationGen { ...@@ -63,12 +63,7 @@ public class AnnotationGen {
} }
for (Annotation a : aList.getAll()) { for (Annotation a : aList.getAll()) {
String aCls = a.getAnnotationClass(); String aCls = a.getAnnotationClass();
if (aCls.startsWith(Consts.DALVIK_ANNOTATION_PKG)) { if (!aCls.startsWith(Consts.DALVIK_ANNOTATION_PKG)) {
// skip
if (Consts.DEBUG) {
code.startLine("// " + a);
}
} else {
code.startLine(); code.startLine();
formatAnnotation(code, a); formatAnnotation(code, a);
} }
......
...@@ -11,6 +11,7 @@ import org.jetbrains.annotations.Nullable; ...@@ -11,6 +11,7 @@ import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import jadx.core.Consts;
import jadx.core.dex.attributes.AFlag; import jadx.core.dex.attributes.AFlag;
import jadx.core.dex.attributes.AType; import jadx.core.dex.attributes.AType;
import jadx.core.dex.attributes.nodes.FieldReplaceAttr; import jadx.core.dex.attributes.nodes.FieldReplaceAttr;
...@@ -637,6 +638,11 @@ public class InsnGen { ...@@ -637,6 +638,11 @@ public class InsnGen {
break; break;
case SUPER: case SUPER:
ClassInfo superCallCls = getClassForSuperCall(code, callMth);
if (superCallCls != null) {
useClass(code, superCallCls);
code.add('.');
}
// use 'super' instead 'this' in 0 arg // use 'super' instead 'this' in 0 arg
code.add("super").add('.'); code.add("super").add('.');
k++; k++;
...@@ -658,6 +664,36 @@ public class InsnGen { ...@@ -658,6 +664,36 @@ public class InsnGen {
generateMethodArguments(code, insn, k, callMthNode); generateMethodArguments(code, insn, k, callMthNode);
} }
@Nullable
private ClassInfo getClassForSuperCall(CodeWriter code, MethodInfo callMth) {
ClassNode useCls = mth.getParentClass();
ClassInfo insnCls = useCls.getAlias();
ClassInfo declClass = callMth.getDeclClass();
if (insnCls.equals(declClass)) {
return null;
}
ClassNode topClass = useCls.getTopParentClass();
if (topClass.getClassInfo().equals(declClass)) {
return declClass;
}
// search call class
ClassNode nextParent = useCls;
do {
ClassInfo nextClsInfo = nextParent.getClassInfo();
if (nextClsInfo.equals(declClass)
|| ArgType.isInstanceOf(mth.dex(), nextClsInfo.getType(), declClass.getType())) {
if (nextParent == useCls) {
return null;
}
return nextClsInfo;
}
nextParent = nextParent.getParentClass();
} while (nextParent != null && nextParent != topClass);
// search failed, just return parent class
return useCls.getParentClass().getClassInfo();
}
void generateMethodArguments(CodeWriter code, InsnNode insn, int startArgNum, void generateMethodArguments(CodeWriter code, InsnNode insn, int startArgNum,
@Nullable MethodNode callMth) throws CodegenException { @Nullable MethodNode callMth) throws CodegenException {
int k = startArgNum; int k = startArgNum;
...@@ -748,6 +784,9 @@ public class InsnGen { ...@@ -748,6 +784,9 @@ public class InsnGen {
return false; return false;
} }
InsnNode inl = mia.getInsn(); InsnNode inl = mia.getInsn();
if (Consts.DEBUG) {
code.add("/* inline method: ").add(callMthNode.toString()).add("*/").startLine();
}
if (callMthNode.getMethodInfo().getArgumentsTypes().isEmpty()) { if (callMthNode.getMethodInfo().getArgumentsTypes().isEmpty()) {
makeInsn(inl, code, Flags.BODY_ONLY); makeInsn(inl, code, Flags.BODY_ONLY);
} else { } else {
......
...@@ -43,8 +43,12 @@ public final class MethodInfo { ...@@ -43,8 +43,12 @@ public final class MethodInfo {
} }
public String makeSignature(boolean includeRetType) { public String makeSignature(boolean includeRetType) {
return makeSignature(false, includeRetType);
}
public String makeSignature(boolean useAlias, boolean includeRetType) {
StringBuilder signature = new StringBuilder(); StringBuilder signature = new StringBuilder();
signature.append(name); signature.append(useAlias ? alias : name);
signature.append('('); signature.append('(');
for (ArgType arg : args) { for (ArgType arg : args) {
signature.append(TypeGen.signature(arg)); signature.append(TypeGen.signature(arg));
......
...@@ -38,12 +38,12 @@ import jadx.core.utils.exceptions.JadxRuntimeException; ...@@ -38,12 +38,12 @@ import jadx.core.utils.exceptions.JadxRuntimeException;
import static jadx.core.dex.nodes.ProcessState.UNLOADED; import static jadx.core.dex.nodes.ProcessState.UNLOADED;
public class ClassNode extends LineAttrNode implements ILoadable, IDexNode { public class ClassNode extends LineAttrNode implements ILoadable, ICodeNode {
private static final Logger LOG = LoggerFactory.getLogger(ClassNode.class); private static final Logger LOG = LoggerFactory.getLogger(ClassNode.class);
private final DexNode dex; private final DexNode dex;
private final ClassInfo clsInfo; private final ClassInfo clsInfo;
private final AccessInfo accessFlags; private AccessInfo accessFlags;
private ArgType superClass; private ArgType superClass;
private List<ArgType> interfaces; private List<ArgType> interfaces;
private Map<ArgType, List<ArgType>> genericMap; private Map<ArgType, List<ArgType>> genericMap;
...@@ -409,11 +409,17 @@ public class ClassNode extends LineAttrNode implements ILoadable, IDexNode { ...@@ -409,11 +409,17 @@ public class ClassNode extends LineAttrNode implements ILoadable, IDexNode {
return null; return null;
} }
@Override
public AccessInfo getAccessFlags() { public AccessInfo getAccessFlags() {
return accessFlags; return accessFlags;
} }
@Override @Override
public void setAccessFlags(AccessInfo accessFlags) {
this.accessFlags = accessFlags;
}
@Override
public DexNode dex() { public DexNode dex() {
return dex; return dex;
} }
......
...@@ -8,11 +8,11 @@ import jadx.core.dex.info.AccessInfo.AFType; ...@@ -8,11 +8,11 @@ import jadx.core.dex.info.AccessInfo.AFType;
import jadx.core.dex.info.FieldInfo; import jadx.core.dex.info.FieldInfo;
import jadx.core.dex.instructions.args.ArgType; import jadx.core.dex.instructions.args.ArgType;
public class FieldNode extends LineAttrNode { public class FieldNode extends LineAttrNode implements ICodeNode {
private final ClassNode parent; private final ClassNode parent;
private final FieldInfo fieldInfo; private final FieldInfo fieldInfo;
private final AccessInfo accFlags; private AccessInfo accFlags;
private ArgType type; // store signature private ArgType type; // store signature
...@@ -32,10 +32,16 @@ public class FieldNode extends LineAttrNode { ...@@ -32,10 +32,16 @@ public class FieldNode extends LineAttrNode {
return fieldInfo; return fieldInfo;
} }
@Override
public AccessInfo getAccessFlags() { public AccessInfo getAccessFlags() {
return accFlags; return accFlags;
} }
@Override
public void setAccessFlags(AccessInfo accFlags) {
this.accFlags = accFlags;
}
public String getName() { public String getName() {
return fieldInfo.getName(); return fieldInfo.getName();
} }
...@@ -57,6 +63,21 @@ public class FieldNode extends LineAttrNode { ...@@ -57,6 +63,21 @@ public class FieldNode extends LineAttrNode {
} }
@Override @Override
public String typeName() {
return "field";
}
@Override
public DexNode dex() {
return parent.dex();
}
@Override
public RootNode root() {
return parent.root();
}
@Override
public int hashCode() { public int hashCode() {
return fieldInfo.hashCode(); return fieldInfo.hashCode();
} }
......
package jadx.core.dex.nodes;
import jadx.core.dex.attributes.IAttributeNode;
import jadx.core.dex.info.AccessInfo;
public interface ICodeNode extends IDexNode, IAttributeNode {
AccessInfo getAccessFlags();
void setAccessFlags(AccessInfo newAccessFlags);
}
...@@ -46,7 +46,7 @@ import jadx.core.utils.exceptions.JadxRuntimeException; ...@@ -46,7 +46,7 @@ import jadx.core.utils.exceptions.JadxRuntimeException;
import static jadx.core.utils.Utils.lockList; import static jadx.core.utils.Utils.lockList;
public class MethodNode extends LineAttrNode implements ILoadable, IDexNode { public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode {
private static final Logger LOG = LoggerFactory.getLogger(MethodNode.class); private static final Logger LOG = LoggerFactory.getLogger(MethodNode.class);
private final MethodInfo mthInfo; private final MethodInfo mthInfo;
...@@ -595,12 +595,14 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode { ...@@ -595,12 +595,14 @@ public class MethodNode extends LineAttrNode implements ILoadable, IDexNode {
return sVars; return sVars;
} }
@Override
public AccessInfo getAccessFlags() { public AccessInfo getAccessFlags() {
return accFlags; return accFlags;
} }
public void setAccFlags(AccessInfo accFlags) { @Override
this.accFlags = accFlags; public void setAccessFlags(AccessInfo newAccessFlags) {
this.accFlags = newAccessFlags;
} }
public Region getRegion() { public Region getRegion() {
......
...@@ -5,6 +5,7 @@ import java.util.Objects; ...@@ -5,6 +5,7 @@ import java.util.Objects;
import com.android.dx.rop.code.AccessFlags; import com.android.dx.rop.code.AccessFlags;
import jadx.core.Consts;
import jadx.core.dex.attributes.AFlag; import jadx.core.dex.attributes.AFlag;
import jadx.core.dex.attributes.AType; import jadx.core.dex.attributes.AType;
import jadx.core.dex.attributes.nodes.FieldReplaceAttr; import jadx.core.dex.attributes.nodes.FieldReplaceAttr;
...@@ -15,6 +16,7 @@ import jadx.core.dex.info.MethodInfo; ...@@ -15,6 +16,7 @@ import jadx.core.dex.info.MethodInfo;
import jadx.core.dex.instructions.IndexInsnNode; import jadx.core.dex.instructions.IndexInsnNode;
import jadx.core.dex.instructions.InsnType; import jadx.core.dex.instructions.InsnType;
import jadx.core.dex.instructions.InvokeNode; import jadx.core.dex.instructions.InvokeNode;
import jadx.core.dex.instructions.InvokeType;
import jadx.core.dex.instructions.args.ArgType; import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg; import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.InsnWrapArg; import jadx.core.dex.instructions.args.InsnWrapArg;
...@@ -140,7 +142,11 @@ public class ClassModifier extends AbstractVisitor { ...@@ -140,7 +142,11 @@ public class ClassModifier extends AbstractVisitor {
return; return;
} }
if (removeBridgeMethod(cls, mth)) { if (removeBridgeMethod(cls, mth)) {
mth.add(AFlag.DONT_GENERATE); if (Consts.DEBUG) {
mth.addAttr(AType.COMMENTS, "Removed as synthetic bridge method");
} else {
mth.add(AFlag.DONT_GENERATE);
}
return; return;
} }
// remove synthetic constructor for inner classes // remove synthetic constructor for inner classes
...@@ -219,40 +225,45 @@ public class ClassModifier extends AbstractVisitor { ...@@ -219,40 +225,45 @@ public class ClassModifier extends AbstractVisitor {
private static boolean checkSyntheticWrapper(MethodNode mth, InsnNode insn) { private static boolean checkSyntheticWrapper(MethodNode mth, InsnNode insn) {
InsnType insnType = insn.getType(); InsnType insnType = insn.getType();
if (insnType == InsnType.INVOKE) { if (insnType != InsnType.INVOKE) {
MethodInfo callMth = ((InvokeNode) insn).getCallMth(); return false;
MethodNode wrappedMth = mth.root().deepResolveMethod(callMth); }
if (wrappedMth != null) { InvokeNode invokeInsn = (InvokeNode) insn;
AccessInfo wrappedAccFlags = wrappedMth.getAccessFlags(); if (invokeInsn.getInvokeType() == InvokeType.SUPER) {
if (wrappedAccFlags.isStatic()) { return false;
return false; }
} MethodInfo callMth = invokeInsn.getCallMth();
if (callMth.getArgsCount() != mth.getMethodInfo().getArgsCount()) { MethodNode wrappedMth = mth.root().deepResolveMethod(callMth);
return false; if (wrappedMth == null) {
} return false;
// rename method only from current class }
if (!mth.getParentClass().equals(wrappedMth.getParentClass())) { AccessInfo wrappedAccFlags = wrappedMth.getAccessFlags();
return false; if (wrappedAccFlags.isStatic()) {
} return false;
// all args must be registers passed from method args (allow only casts insns) }
for (InsnArg arg : insn.getArguments()) { if (callMth.getArgsCount() != mth.getMethodInfo().getArgsCount()) {
if (!registersAndCastsOnly(arg)) { return false;
return false; }
} // rename method only from current class
} if (!mth.getParentClass().equals(wrappedMth.getParentClass())) {
String alias = mth.getAlias(); return false;
if (Objects.equals(wrappedMth.getAlias(), alias)) { }
return true; // all args must be registers passed from method args (allow only casts insns)
} for (InsnArg arg : insn.getArguments()) {
if (!wrappedAccFlags.isPublic()) { if (!registersAndCastsOnly(arg)) {
// must be public return false;
FixAccessModifiers.changeVisibility(wrappedMth, AccessFlags.ACC_PUBLIC);
}
wrappedMth.getMethodInfo().setAlias(alias);
return true;
} }
} }
return false; // remove confirmed, change visibility and name if needed
if (!wrappedAccFlags.isPublic()) {
// must be public
FixAccessModifiers.changeVisibility(wrappedMth, AccessFlags.ACC_PUBLIC);
}
String alias = mth.getAlias();
if (!Objects.equals(wrappedMth.getAlias(), alias)) {
wrappedMth.getMethodInfo().setAlias(alias);
}
return true;
} }
private static boolean registersAndCastsOnly(InsnArg arg) { private static boolean registersAndCastsOnly(InsnArg arg) {
...@@ -274,8 +285,7 @@ public class ClassModifier extends AbstractVisitor { ...@@ -274,8 +285,7 @@ public class ClassModifier extends AbstractVisitor {
if (otherMth != mth) { if (otherMth != mth) {
MethodInfo omi = otherMth.getMethodInfo(); MethodInfo omi = otherMth.getMethodInfo();
if (omi.getName().equals(mi.getName()) if (omi.getName().equals(mi.getName())
&& omi.getArgumentsTypes().size() == mi.getArgumentsTypes().size()) { && Objects.equals(omi.getArgumentsTypes(), mi.getArgumentsTypes())) {
// TODO: check objects types
return false; return false;
} }
} }
......
...@@ -4,6 +4,7 @@ import com.android.dx.rop.code.AccessFlags; ...@@ -4,6 +4,7 @@ import com.android.dx.rop.code.AccessFlags;
import jadx.core.dex.attributes.AType; import jadx.core.dex.attributes.AType;
import jadx.core.dex.info.AccessInfo; import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.nodes.ICodeNode;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
import jadx.core.dex.nodes.RootNode; import jadx.core.dex.nodes.RootNode;
...@@ -32,12 +33,12 @@ public class FixAccessModifiers extends AbstractVisitor { ...@@ -32,12 +33,12 @@ public class FixAccessModifiers extends AbstractVisitor {
} }
} }
public static void changeVisibility(MethodNode mth, int newVisFlag) { public static void changeVisibility(ICodeNode node, int newVisFlag) {
AccessInfo accessFlags = mth.getAccessFlags(); AccessInfo accessFlags = node.getAccessFlags();
AccessInfo newAccFlags = accessFlags.changeVisibility(newVisFlag); AccessInfo newAccFlags = accessFlags.changeVisibility(newVisFlag);
if (newAccFlags != accessFlags) { if (newAccFlags != accessFlags) {
mth.setAccFlags(newAccFlags); node.setAccessFlags(newAccFlags);
mth.addAttr(AType.COMMENTS, "access modifiers changed from: " + accessFlags.rawString()); node.addAttr(AType.COMMENTS, "access modifiers changed from: " + accessFlags.rawString());
} }
} }
......
...@@ -2,28 +2,44 @@ package jadx.core.dex.visitors; ...@@ -2,28 +2,44 @@ package jadx.core.dex.visitors;
import java.util.List; import java.util.List;
import com.android.dx.rop.code.AccessFlags;
import jadx.core.Consts;
import jadx.core.dex.attributes.AFlag; import jadx.core.dex.attributes.AFlag;
import jadx.core.dex.attributes.AType;
import jadx.core.dex.attributes.nodes.MethodInlineAttr; import jadx.core.dex.attributes.nodes.MethodInlineAttr;
import jadx.core.dex.info.AccessInfo; import jadx.core.dex.info.AccessInfo;
import jadx.core.dex.info.FieldInfo;
import jadx.core.dex.instructions.IndexInsnNode;
import jadx.core.dex.instructions.InsnType; import jadx.core.dex.instructions.InsnType;
import jadx.core.dex.instructions.InvokeNode;
import jadx.core.dex.instructions.args.ArgType; import jadx.core.dex.instructions.args.ArgType;
import jadx.core.dex.instructions.args.InsnArg; import jadx.core.dex.instructions.args.InsnArg;
import jadx.core.dex.instructions.args.InsnWrapArg;
import jadx.core.dex.instructions.args.RegisterArg; import jadx.core.dex.instructions.args.RegisterArg;
import jadx.core.dex.nodes.BlockNode; import jadx.core.dex.nodes.BlockNode;
import jadx.core.dex.nodes.FieldNode;
import jadx.core.dex.nodes.InsnNode; import jadx.core.dex.nodes.InsnNode;
import jadx.core.dex.nodes.MethodNode; import jadx.core.dex.nodes.MethodNode;
import jadx.core.utils.exceptions.JadxException; import jadx.core.utils.exceptions.JadxException;
/** @JadxVisitor(
* Inline synthetic methods. name = "InlineMethods",
*/ desc = "Inline synthetic static methods",
runAfter = {
FixAccessModifiers.class,
ClassModifier.class
}
)
public class MethodInlineVisitor extends AbstractVisitor { public class MethodInlineVisitor extends AbstractVisitor {
@Override @Override
public void visit(MethodNode mth) throws JadxException { public void visit(MethodNode mth) throws JadxException {
if (mth.isNoCode() || mth.contains(AFlag.DONT_GENERATE)) {
return;
}
AccessInfo accessFlags = mth.getAccessFlags(); AccessInfo accessFlags = mth.getAccessFlags();
if (accessFlags.isSynthetic() if (accessFlags.isSynthetic() && accessFlags.isStatic()
&& accessFlags.isStatic()
&& mth.getBasicBlocks().size() == 2) { && mth.getBasicBlocks().size() == 2) {
BlockNode returnBlock = mth.getBasicBlocks().get(1); BlockNode returnBlock = mth.getBasicBlocks().get(1);
if (returnBlock.contains(AFlag.RETURN) || returnBlock.getInstructions().isEmpty()) { if (returnBlock.contains(AFlag.RETURN) || returnBlock.getInstructions().isEmpty()) {
...@@ -72,7 +88,47 @@ public class MethodInlineVisitor extends AbstractVisitor { ...@@ -72,7 +88,47 @@ public class MethodInlineVisitor extends AbstractVisitor {
} }
private static void addInlineAttr(MethodNode mth, InsnNode insn) { private static void addInlineAttr(MethodNode mth, InsnNode insn) {
mth.addAttr(new MethodInlineAttr(insn)); if (fixVisibilityOfInlineCode(mth, insn)) {
mth.add(AFlag.DONT_GENERATE); if (Consts.DEBUG) {
mth.addAttr(AType.COMMENTS, "Removed for inline");
} else {
mth.addAttr(new MethodInlineAttr(insn));
mth.add(AFlag.DONT_GENERATE);
}
}
}
private static boolean fixVisibilityOfInlineCode(MethodNode mth, InsnNode insn) {
int newVisFlag = AccessFlags.ACC_PUBLIC; // TODO: calculate more precisely
InsnType insnType = insn.getType();
if (insnType == InsnType.INVOKE) {
InvokeNode invoke = (InvokeNode) insn;
MethodNode callMthNode = mth.root().deepResolveMethod(invoke.getCallMth());
if (callMthNode != null) {
FixAccessModifiers.changeVisibility(callMthNode, newVisFlag);
}
return true;
}
if (insnType == InsnType.ONE_ARG) {
InsnArg arg = insn.getArg(0);
if (!arg.isInsnWrap()) {
return false;
}
return fixVisibilityOfInlineCode(mth, ((InsnWrapArg) arg).getWrapInsn());
}
if (insn instanceof IndexInsnNode) {
Object indexObj = ((IndexInsnNode) insn).getIndex();
if (indexObj instanceof FieldInfo) {
FieldNode fieldNode = mth.root().deepResolveField(((FieldInfo) indexObj));
if (fieldNode != null) {
FixAccessModifiers.changeVisibility(fieldNode, newVisFlag);
}
return true;
}
}
if (Consts.DEBUG) {
mth.addAttr(AType.COMMENTS, "JADX DEBUG: can't inline method, not implemented redirect type: " + insn);
}
return false;
} }
} }
...@@ -107,17 +107,22 @@ public class RenameVisitor extends AbstractVisitor { ...@@ -107,17 +107,22 @@ public class RenameVisitor extends AbstractVisitor {
} }
private void checkMethods(ClassNode cls) { private void checkMethods(ClassNode cls) {
for (MethodNode mth : cls.getMethods()) {
if (!NameMapper.isValidIdentifier(mth.getAlias())) {
deobfuscator.forceRenameMethod(mth);
}
}
Set<String> names = new HashSet<>(); Set<String> names = new HashSet<>();
for (MethodNode mth : cls.getMethods()) { for (MethodNode mth : cls.getMethods()) {
AccessInfo accessFlags = mth.getAccessFlags(); AccessInfo accessFlags = mth.getAccessFlags();
if (accessFlags.isConstructor() if (accessFlags.isConstructor()
|| accessFlags.isBridge() || accessFlags.isBridge()
|| accessFlags.isSynthetic() || accessFlags.isSynthetic()
|| mth.contains(AFlag.DONT_GENERATE)) { || mth.contains(AFlag.DONT_GENERATE) /* this flag not set yet */) {
continue; continue;
} }
String signature = mth.getMethodInfo().makeSignature(false); String signature = mth.getMethodInfo().makeSignature(true, false);
if (!names.add(signature) || !NameMapper.isValidIdentifier(mth.getAlias())) { if (!names.add(signature)) {
deobfuscator.forceRenameMethod(mth); deobfuscator.forceRenameMethod(mth);
} }
} }
......
...@@ -214,12 +214,14 @@ public abstract class IntegrationTest extends TestUtils { ...@@ -214,12 +214,14 @@ public abstract class IntegrationTest extends TestUtils {
rethrow("Original check failed", ie); rethrow("Original check failed", ie);
} }
// run 'check' method from decompiled class // run 'check' method from decompiled class
try { if (compile) {
invoke("check"); try {
} catch (InvocationTargetException ie) { invoke("check");
rethrow("Decompiled check failed", ie); } catch (InvocationTargetException ie) {
rethrow("Decompiled check failed", ie);
}
System.out.println("Auto check: PASSED");
} }
System.out.println("Auto check: PASSED");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
fail("Auto check exception: " + e.getMessage()); fail("Auto check exception: " + e.getMessage());
......
package jadx.tests.integration.inline;
import org.junit.Test;
import jadx.core.dex.nodes.ClassNode;
import jadx.tests.api.IntegrationTest;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertThat;
public class TestSyntheticInline2 extends IntegrationTest {
public static class Base {
protected void call() {
System.out.println("base call");
}
}
public static class TestCls extends Base {
public class A {
public void invokeCall() {
TestCls.this.call();
}
public void invokeSuperCall() {
TestCls.super.call();
}
}
@Override
public void call() {
System.out.println("TestCls call");
}
public void check() {
A a = new A();
a.invokeSuperCall();
a.invokeCall();
}
}
@Test
public void test() {
disableCompilation(); // strange java compiler bug
ClassNode cls = getClassNode(TestCls.class); // Base class in unknown
String code = cls.getCode().toString();
assertThat(code, not(containsString("synthetic")));
assertThat(code, not(containsString("access$")));
assertThat(code, containsString("TestSyntheticInline2$TestCls.this.call();"));
assertThat(code, containsString("TestSyntheticInline2$TestCls.super.call();"));
}
@Test
public void testTopClass() {
ClassNode cls = getClassNode(TestSyntheticInline2.class);
String code = cls.getCode().toString();
assertThat(code, containsString(indent(1) + "TestCls.super.call();"));
}
}
...@@ -46,6 +46,6 @@ public class TestDuplicatedNames extends SmaliTest { ...@@ -46,6 +46,6 @@ public class TestDuplicatedNames extends SmaliTest {
assertThat(code, containsOne("this.f0fieldName")); assertThat(code, containsOne("this.f0fieldName"));
assertThat(code, containsOne("public Object run() {")); assertThat(code, containsOne("public Object run() {"));
assertThat(code, containsOne("public String m0run() {")); assertThat(code, containsOne("public String m1run() {"));
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment