From 550659d3723bf59613f75fd61145f93d841977cc Mon Sep 17 00:00:00 2001 From: Skylot Date: Thu, 18 Apr 2013 23:15:09 +0400 Subject: [PATCH] Fix generic types for abstract methods --- src/main/java/jadx/dex/nodes/MethodNode.java | 38 +++++++++---------- .../java/jadx/samples/TestGenerics.java | 6 ++- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/main/java/jadx/dex/nodes/MethodNode.java b/src/main/java/jadx/dex/nodes/MethodNode.java index 283fe812e..03ffc1f2a 100644 --- a/src/main/java/jadx/dex/nodes/MethodNode.java +++ b/src/main/java/jadx/dex/nodes/MethodNode.java @@ -70,31 +70,22 @@ public class MethodNode extends AttrNode implements ILoadable { this.parentClass = classNode; this.accFlags = new AccessInfo(mth.getAccessFlags(), AFType.METHOD); this.methodData = mth; - - if (methodData.getCodeOffset() == 0) { - noCode = true; - regsCount = 0; - retType = mthInfo.getReturnType(); - initArguments(mthInfo.getArgumentsTypes()); - } else { - noCode = false; - } + this.noCode = (methodData.getCodeOffset() == 0); } @Override public void load() throws DecodeException { - if (noCode) - return; - try { + if (noCode) { + regsCount = 0; + initMethodTypes(); + return; + } + DexNode dex = parentClass.dex(); Code mthCode = dex.readCode(methodData); regsCount = mthCode.getRegistersSize(); - - if (!parseSignature()) { - retType = mthInfo.getReturnType(); - initArguments(mthInfo.getArgumentsTypes()); - } + initMethodTypes(); InsnDecoder decoder = new InsnDecoder(this, mthCode); InsnNode[] insnByOffset = decoder.run(); @@ -117,6 +108,13 @@ public class MethodNode extends AttrNode implements ILoadable { } } + private void initMethodTypes() { + if (!parseSignature()) { + retType = mthInfo.getReturnType(); + initArguments(mthInfo.getArgumentsTypes()); + } + } + @Override public void unload() { if (noCode) @@ -185,12 +183,12 @@ public class MethodNode extends AttrNode implements ILoadable { private void initArguments(List args) { int pos; - if (!noCode) { + if (noCode) { + pos = 1; + } else { pos = regsCount; for (ArgType arg : args) pos -= arg.getRegCount(); - } else { - pos = 2 * args.size() + 1; } if (accFlags.isStatic()) { diff --git a/src/samples/java/jadx/samples/TestGenerics.java b/src/samples/java/jadx/samples/TestGenerics.java index 9def12b99..6c88b2e4c 100644 --- a/src/samples/java/jadx/samples/TestGenerics.java +++ b/src/samples/java/jadx/samples/TestGenerics.java @@ -11,7 +11,11 @@ public class TestGenerics extends AbstractTest { public Class[] classes; - public static class GenericClass implements Comparable { + public interface MyComparable { + public int compareTo(T o); + } + + public static class GenericClass implements MyComparable { @Override public int compareTo(String o) { return 0;