Commit f715d6ce authored by Skylot's avatar Skylot

core: fix inherited methods renaming

parent 350b6054
......@@ -575,9 +575,12 @@ public class InsnGen {
MethodInfo callMth = insn.getCallMth();
// inline method
MethodNode callMthNode = mth.dex().resolveMethod(callMth);
if (callMthNode != null && inlineMethod(callMthNode, insn, code)) {
return;
MethodNode callMthNode = mth.dex().deepResolveMethod(callMth);
if (callMthNode != null) {
if (inlineMethod(callMthNode, insn, code)) {
return;
}
callMth = callMthNode.getMethodInfo();
}
int k = 0;
......
......@@ -28,17 +28,7 @@ public final class MethodInfo {
ProtoId proto = dex.getProtoId(mthId.getProtoIndex());
retType = dex.getType(proto.getReturnTypeIndex());
args = dex.readParamList(proto.getParametersOffset());
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();
shortId = makeSignature(true);
}
public static MethodInfo fromDex(DexNode dex, int mthIndex) {
......@@ -50,6 +40,20 @@ public final class MethodInfo {
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() {
return name;
}
......
......@@ -14,6 +14,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import com.android.dex.ClassData;
......@@ -87,7 +88,15 @@ public class DexNode {
}
@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());
if (cls != null) {
return cls.searchMethod(mth);
......@@ -95,6 +104,48 @@ public class DexNode {
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
public FieldNode resolveField(FieldInfo field) {
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