Commit f715d6ce authored by Skylot's avatar Skylot

core: fix inherited methods renaming

parent 350b6054
...@@ -575,9 +575,12 @@ public class InsnGen { ...@@ -575,9 +575,12 @@ public class InsnGen {
MethodInfo callMth = insn.getCallMth(); MethodInfo callMth = insn.getCallMth();
// inline method // inline method
MethodNode callMthNode = mth.dex().resolveMethod(callMth); MethodNode callMthNode = mth.dex().deepResolveMethod(callMth);
if (callMthNode != null && inlineMethod(callMthNode, insn, code)) { if (callMthNode != null) {
return; if (inlineMethod(callMthNode, insn, code)) {
return;
}
callMth = callMthNode.getMethodInfo();
} }
int k = 0; int k = 0;
......
...@@ -28,17 +28,7 @@ public final class MethodInfo { ...@@ -28,17 +28,7 @@ public final class MethodInfo {
ProtoId proto = dex.getProtoId(mthId.getProtoIndex()); ProtoId proto = dex.getProtoId(mthId.getProtoIndex());
retType = dex.getType(proto.getReturnTypeIndex()); retType = dex.getType(proto.getReturnTypeIndex());
args = dex.readParamList(proto.getParametersOffset()); args = dex.readParamList(proto.getParametersOffset());
shortId = makeSignature(true);
StringBuilder signature = new StringBuilder();
signature.append(name);
signature.append('(');
for (ArgType arg : args) {
signature.append(TypeGen.signature(arg));
}
signature.append(')');
signature.append(TypeGen.signature(retType));
shortId = signature.toString();
} }
public static MethodInfo fromDex(DexNode dex, int mthIndex) { public static MethodInfo fromDex(DexNode dex, int mthIndex) {
...@@ -50,6 +40,20 @@ public final class MethodInfo { ...@@ -50,6 +40,20 @@ public final class MethodInfo {
return dex.getInfoStorage().putMethod(mthIndex, mth); return dex.getInfoStorage().putMethod(mthIndex, mth);
} }
public String makeSignature(boolean includeRetType) {
StringBuilder signature = new StringBuilder();
signature.append(name);
signature.append('(');
for (ArgType arg : args) {
signature.append(TypeGen.signature(arg));
}
signature.append(')');
if (includeRetType) {
signature.append(TypeGen.signature(retType));
}
return signature.toString();
}
public String getName() { public String getName() {
return name; return name;
} }
......
...@@ -14,6 +14,7 @@ import java.util.HashMap; ...@@ -14,6 +14,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.android.dex.ClassData; import com.android.dex.ClassData;
...@@ -87,7 +88,15 @@ public class DexNode { ...@@ -87,7 +88,15 @@ public class DexNode {
} }
@Nullable @Nullable
public MethodNode resolveMethod(MethodInfo mth) { public ClassNode resolveClass(@NotNull ArgType type) {
if (type.isGeneric()) {
type = ArgType.object(type.getObject());
}
return resolveClass(ClassInfo.fromType(this, type));
}
@Nullable
public MethodNode resolveMethod(@NotNull MethodInfo mth) {
ClassNode cls = resolveClass(mth.getDeclClass()); ClassNode cls = resolveClass(mth.getDeclClass());
if (cls != null) { if (cls != null) {
return cls.searchMethod(mth); return cls.searchMethod(mth);
...@@ -95,6 +104,48 @@ public class DexNode { ...@@ -95,6 +104,48 @@ public class DexNode {
return null; return null;
} }
/**
* Search method in class hierarchy.
*/
@Nullable
public MethodNode deepResolveMethod(@NotNull MethodInfo mth) {
ClassNode cls = resolveClass(mth.getDeclClass());
if (cls == null) {
return null;
}
return deepResolveMethod(cls, mth.makeSignature(false));
}
@Nullable
private MethodNode deepResolveMethod(@NotNull ClassNode cls, String signature) {
for (MethodNode m : cls.getMethods()) {
if (m.getMethodInfo().getShortId().startsWith(signature)) {
return m;
}
}
MethodNode found;
ArgType superClass = cls.getSuperClass();
if (superClass != null) {
ClassNode superNode = resolveClass(superClass);
if (superNode != null) {
found = deepResolveMethod(superNode, signature);
if (found != null) {
return found;
}
}
}
for (ArgType iFaceType : cls.getInterfaces()) {
ClassNode iFaceNode = resolveClass(iFaceType);
if (iFaceNode != null) {
found = deepResolveMethod(iFaceNode, signature);
if (found != null) {
return found;
}
}
}
return null;
}
@Nullable @Nullable
public FieldNode resolveField(FieldInfo field) { public FieldNode resolveField(FieldInfo field) {
ClassNode cls = resolveClass(field.getDeclClass()); ClassNode cls = resolveClass(field.getDeclClass());
......
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