|
|
@ -18,76 +18,109 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package jode; |
|
|
|
package jode; |
|
|
|
import java.lang.reflect.*; |
|
|
|
import java.lang.reflect.Modifier; |
|
|
|
import gnu.bytecode.Attribute; |
|
|
|
import gnu.bytecode.Attribute; |
|
|
|
import gnu.bytecode.CodeAttr; |
|
|
|
import gnu.bytecode.CodeAttr; |
|
|
|
|
|
|
|
import gnu.bytecode.Spy; |
|
|
|
|
|
|
|
|
|
|
|
public class MethodAnalyzer implements Analyzer { |
|
|
|
public class MethodAnalyzer implements Analyzer { |
|
|
|
JodeEnvironment env; |
|
|
|
JodeEnvironment env; |
|
|
|
CodeAnalyzer code = null; |
|
|
|
CodeAnalyzer code = null; |
|
|
|
ClassAnalyzer classAnalyzer; |
|
|
|
ClassAnalyzer classAnalyzer; |
|
|
|
boolean isConstructor; |
|
|
|
boolean isConstructor; |
|
|
|
Method method; |
|
|
|
int modifiers; |
|
|
|
Constructor constr; |
|
|
|
String methodName; |
|
|
|
|
|
|
|
MethodType methodType; |
|
|
|
private MethodAnalyzer(ClassAnalyzer cla, Method m, Constructor c, |
|
|
|
Type[] exceptions; |
|
|
|
JodeEnvironment e) |
|
|
|
|
|
|
|
{ |
|
|
|
// private MethodAnalyzer(ClassAnalyzer cla, Method m, Constructor c,
|
|
|
|
classAnalyzer = cla; |
|
|
|
// JodeEnvironment e)
|
|
|
|
method = m; |
|
|
|
// {
|
|
|
|
constr = c; |
|
|
|
// classAnalyzer = cla;
|
|
|
|
isConstructor = (c != null); |
|
|
|
// isConstructor = (c != null);
|
|
|
|
env = e; |
|
|
|
// env = e;
|
|
|
|
|
|
|
|
|
|
|
|
String name = isConstructor ? "<init>" : m.getName(); |
|
|
|
// this.modifiers = isConstructor
|
|
|
|
Class[] paramTypes = (isConstructor |
|
|
|
// ? c.getModifiers() : m.getModifiers();
|
|
|
|
? c.getParameterTypes() |
|
|
|
|
|
|
|
: m.getParameterTypes()); |
|
|
|
// {
|
|
|
|
|
|
|
|
// Class[] exceptClasses = isConstructor
|
|
|
|
gnu.bytecode.Method mdef = cla.classType.getMethods(); |
|
|
|
// ? c.getExceptionTypes() : m.getExceptionTypes();
|
|
|
|
while (mdef != null) { |
|
|
|
// this.exceptions = new Type[exceptClasses.length];
|
|
|
|
if (mdef.getName().equals(name)) { |
|
|
|
// for (int i=0; i< exceptClasses.length; i++)
|
|
|
|
gnu.bytecode.Type[] argtypes = mdef.getParameterTypes(); |
|
|
|
// exceptions[i] = Type.tType(exceptClasses[i]);
|
|
|
|
if (argtypes.length == paramTypes.length) { |
|
|
|
// }
|
|
|
|
int i; |
|
|
|
|
|
|
|
for (i=0; i<argtypes.length; i++) { |
|
|
|
// {
|
|
|
|
if (!Type.tType(paramTypes[i]).equals(Type.tType(argtypes[i].getSignature()))) |
|
|
|
// Class[] paramTypes = (isConstructor
|
|
|
|
break; |
|
|
|
// ? c.getParameterTypes()
|
|
|
|
} |
|
|
|
// : m.getParameterTypes());
|
|
|
|
if (i == argtypes.length) |
|
|
|
// Class returnType = (isConstructor
|
|
|
|
break; |
|
|
|
// ? Void.TYPE : m.getReturnType());
|
|
|
|
|
|
|
|
// methodType = new MethodType
|
|
|
|
|
|
|
|
// (!isConstructor && Modifier.isStatic(modifiers),
|
|
|
|
|
|
|
|
// paramTypes, returnType);
|
|
|
|
|
|
|
|
// methodName = isConstructor ? "<init>" : m.getName();
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// gnu.bytecode.Method mdef;
|
|
|
|
|
|
|
|
// for (mdef = cla.classType.getMethods(); ; mdef = mdef.getNext()) {
|
|
|
|
|
|
|
|
// if (mdef.getName().equals(methodName)) {
|
|
|
|
|
|
|
|
// MethodType type = new MethodType(mdef.getStaticFlag(),
|
|
|
|
|
|
|
|
// mdef.getSignature());
|
|
|
|
|
|
|
|
// if (type.equals(methodType))
|
|
|
|
|
|
|
|
// break;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Attribute attr = Attribute.get(mdef, "Code");
|
|
|
|
|
|
|
|
// if (attr != null && attr instanceof CodeAttr)
|
|
|
|
|
|
|
|
// code = new CodeAnalyzer(this, (CodeAttr) attr, env);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MethodAnalyzer(ClassAnalyzer cla, gnu.bytecode.Method mdef, |
|
|
|
|
|
|
|
JodeEnvironment env) { |
|
|
|
|
|
|
|
this.classAnalyzer = cla; |
|
|
|
|
|
|
|
this.env = env; |
|
|
|
|
|
|
|
this.modifiers = Spy.getModifiers(mdef); |
|
|
|
|
|
|
|
this.methodType = new MethodType(mdef.getStaticFlag(), |
|
|
|
|
|
|
|
mdef.getSignature()); |
|
|
|
|
|
|
|
this.methodName = mdef.getName(); |
|
|
|
|
|
|
|
this.isConstructor = |
|
|
|
|
|
|
|
methodName.equals("<init>") || methodName.equals("<clinit>"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Attribute codeattr = Attribute.get(mdef, "Code"); |
|
|
|
|
|
|
|
if (codeattr != null && codeattr instanceof CodeAttr) |
|
|
|
|
|
|
|
code = new CodeAnalyzer(this, (CodeAttr) codeattr, env); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Attribute excattr = Attribute.get(mdef, "Exceptions"); |
|
|
|
|
|
|
|
if (excattr == null) { |
|
|
|
|
|
|
|
exceptions = new Type[0]; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
java.io.DataInputStream stream = Spy.getAttributeStream |
|
|
|
|
|
|
|
((gnu.bytecode.MiscAttr) excattr); |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
int throwCount = stream.readUnsignedShort(); |
|
|
|
|
|
|
|
this.exceptions = new Type[throwCount]; |
|
|
|
|
|
|
|
for (int t=0; t< throwCount; t++) { |
|
|
|
|
|
|
|
int idx = stream.readUnsignedShort(); |
|
|
|
|
|
|
|
gnu.bytecode.CpoolClass cpcls = (gnu.bytecode.CpoolClass) |
|
|
|
|
|
|
|
classAnalyzer.getConstant(idx); |
|
|
|
|
|
|
|
exceptions[t] = Type.tClass(cpcls.getName().getString()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} catch (java.io.IOException ex) { |
|
|
|
|
|
|
|
throw new AssertError("exception attribute too long?"); |
|
|
|
} |
|
|
|
} |
|
|
|
mdef = mdef.getNext(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Attribute attr = Attribute.get(mdef, "Code"); |
|
|
|
|
|
|
|
if (attr != null && attr instanceof CodeAttr) |
|
|
|
|
|
|
|
code = new CodeAnalyzer(this, (CodeAttr) attr, env); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MethodAnalyzer(ClassAnalyzer cla, Method method, |
|
|
|
|
|
|
|
JodeEnvironment env) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this(cla, method, null, env); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public MethodAnalyzer(ClassAnalyzer cla, Constructor constr, |
|
|
|
|
|
|
|
JodeEnvironment env) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
this(cla, null, constr, env); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getParamCount() { |
|
|
|
public int getParamCount() { |
|
|
|
return isConstructor |
|
|
|
return (methodType.isStatic() ? 0 : 1) |
|
|
|
? (constr.getParameterTypes().length + 1) |
|
|
|
+ methodType.getParameterTypes().length; |
|
|
|
: ((Modifier.isStatic(method.getModifiers()) ? 0 : 1) |
|
|
|
|
|
|
|
+ method.getParameterTypes().length); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Type getReturnType() { |
|
|
|
public Type getReturnType() { |
|
|
|
return isConstructor |
|
|
|
return methodType.getReturnType(); |
|
|
|
? Type.tVoid : Type.tType(method.getReturnType()); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void analyze() |
|
|
|
public void analyze() |
|
|
@ -97,30 +130,26 @@ public class MethodAnalyzer implements Analyzer { |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
int offset = 0; |
|
|
|
int offset = 0; |
|
|
|
if (isConstructor || !Modifier.isStatic(method.getModifiers())) { |
|
|
|
if (!methodType.isStatic()) { |
|
|
|
LocalInfo clazz = code.getParamInfo(0); |
|
|
|
LocalInfo clazz = code.getParamInfo(0); |
|
|
|
clazz.setType(Type.tType(this.classAnalyzer.clazz)); |
|
|
|
clazz.setType(Type.tType(this.classAnalyzer.clazz)); |
|
|
|
clazz.setName("this"); |
|
|
|
clazz.setName("this"); |
|
|
|
offset++; |
|
|
|
offset++; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Class[] paramTypes = isConstructor |
|
|
|
Type[] paramTypes = methodType.getParameterTypes(); |
|
|
|
? constr.getParameterTypes() : method.getParameterTypes(); |
|
|
|
|
|
|
|
for (int i=0; i< paramTypes.length; i++) |
|
|
|
for (int i=0; i< paramTypes.length; i++) |
|
|
|
code.getParamInfo(offset+i).setType(Type.tType(paramTypes[i])); |
|
|
|
code.getParamInfo(offset+i).setType(paramTypes[i]); |
|
|
|
|
|
|
|
|
|
|
|
Class[] exceptions = isConstructor |
|
|
|
|
|
|
|
? constr.getExceptionTypes() : method.getExceptionTypes(); |
|
|
|
|
|
|
|
for (int i= 0; i< exceptions.length; i++) |
|
|
|
for (int i= 0; i< exceptions.length; i++) |
|
|
|
env.useClass(exceptions[i]); |
|
|
|
exceptions[i].useType(); |
|
|
|
|
|
|
|
|
|
|
|
if (!isConstructor) |
|
|
|
if (!isConstructor) |
|
|
|
getReturnType().useType(); |
|
|
|
methodType.getReturnType().useType(); |
|
|
|
|
|
|
|
|
|
|
|
if (!Decompiler.immediateOutput) { |
|
|
|
if (!Decompiler.immediateOutput) { |
|
|
|
if (Decompiler.isVerbose) |
|
|
|
if (Decompiler.isVerbose) |
|
|
|
System.err.print((isConstructor |
|
|
|
System.err.print(methodName+": "); |
|
|
|
? "<init>" : method.getName())+": "); |
|
|
|
|
|
|
|
code.analyze(); |
|
|
|
code.analyze(); |
|
|
|
if (Decompiler.isVerbose) |
|
|
|
if (Decompiler.isVerbose) |
|
|
|
System.err.println(""); |
|
|
|
System.err.println(""); |
|
|
@ -135,56 +164,47 @@ public class MethodAnalyzer implements Analyzer { |
|
|
|
// immediate output.
|
|
|
|
// immediate output.
|
|
|
|
|
|
|
|
|
|
|
|
if (Decompiler.isVerbose) |
|
|
|
if (Decompiler.isVerbose) |
|
|
|
System.err.print((isConstructor |
|
|
|
System.err.print(methodName+": "); |
|
|
|
? "<init>" : method.getName())+": "); |
|
|
|
|
|
|
|
code.analyze(); |
|
|
|
code.analyze(); |
|
|
|
if (Decompiler.isVerbose) |
|
|
|
if (Decompiler.isVerbose) |
|
|
|
System.err.println(""); |
|
|
|
System.err.println(""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
writer.println(""); |
|
|
|
writer.println(""); |
|
|
|
String modif = Modifier.toString(isConstructor |
|
|
|
String modif = Modifier.toString(modifiers); |
|
|
|
? constr.getModifiers() |
|
|
|
|
|
|
|
: method.getModifiers()); |
|
|
|
|
|
|
|
if (modif.length() > 0) |
|
|
|
if (modif.length() > 0) |
|
|
|
writer.print(modif+" "); |
|
|
|
writer.print(modif+" "); |
|
|
|
if (isConstructor && Modifier.isStatic(constr.getModifiers())) |
|
|
|
if (isConstructor && methodType.isStatic()) |
|
|
|
writer.print(""); /* static block */ |
|
|
|
writer.print(""); /* static block */ |
|
|
|
else { |
|
|
|
else { |
|
|
|
if (isConstructor) |
|
|
|
if (isConstructor) |
|
|
|
writer.print(env.classString(classAnalyzer.clazz)); |
|
|
|
writer.print(env.classString(classAnalyzer.clazz)); |
|
|
|
else |
|
|
|
else |
|
|
|
writer.print(getReturnType().toString() |
|
|
|
writer.print(getReturnType().toString() |
|
|
|
+ " " + method.getName()); |
|
|
|
+ " " + methodName); |
|
|
|
writer.print("("); |
|
|
|
writer.print("("); |
|
|
|
Class[] paramTypes = isConstructor |
|
|
|
Type[] paramTypes = methodType.getParameterTypes(); |
|
|
|
? constr.getParameterTypes() : method.getParameterTypes(); |
|
|
|
int offset = methodType.isStatic()?0:1; |
|
|
|
int offset = (!isConstructor |
|
|
|
|
|
|
|
&& Modifier.isStatic(method.getModifiers()))?0:1; |
|
|
|
|
|
|
|
for (int i=0; i<paramTypes.length; i++) { |
|
|
|
for (int i=0; i<paramTypes.length; i++) { |
|
|
|
if (i>0) |
|
|
|
if (i>0) |
|
|
|
writer.print(", "); |
|
|
|
writer.print(", "); |
|
|
|
LocalInfo li; |
|
|
|
LocalInfo li; |
|
|
|
if (code == null) { |
|
|
|
if (code == null) { |
|
|
|
li = new LocalInfo(i+offset); |
|
|
|
li = new LocalInfo(i+offset); |
|
|
|
li.setType(Type.tType(paramTypes[i])); |
|
|
|
li.setType(paramTypes[i]); |
|
|
|
} else |
|
|
|
} else |
|
|
|
li = code.getParamInfo(i+offset); |
|
|
|
li = code.getParamInfo(i+offset); |
|
|
|
writer.print(li.getType().toString()+" "+li.getName()); |
|
|
|
writer.print(li.getType().toString()+" "+li.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|
writer.print(")"); |
|
|
|
writer.print(")"); |
|
|
|
} |
|
|
|
} |
|
|
|
Class[] exceptions = isConstructor |
|
|
|
if (exceptions.length > 0) { |
|
|
|
? constr.getExceptionTypes() : method.getExceptionTypes(); |
|
|
|
|
|
|
|
if (exceptions != null && exceptions.length > 0) { |
|
|
|
|
|
|
|
writer.println(""); |
|
|
|
writer.println(""); |
|
|
|
writer.print("throws "); |
|
|
|
writer.print("throws "); |
|
|
|
for (int i= 0; i< exceptions.length; i++) { |
|
|
|
for (int i= 0; i< exceptions.length; i++) { |
|
|
|
if (exceptions[i] != null) { |
|
|
|
if (i > 0) |
|
|
|
if (i > 0) |
|
|
|
writer.print(", "); |
|
|
|
writer.print(", "); |
|
|
|
writer.print(exceptions[i].toString()); |
|
|
|
writer.print(env.classString(exceptions[i])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (code != null) { |
|
|
|
if (code != null) { |
|
|
|