use of org.objectweb.asm.tree.analysis.SimpleVerifier in project groovy by apache.
the class VerifyClass method readClass.
private boolean readClass(String clazz) throws IOException {
ClassReader cr = new ClassReader(new FileInputStream(clazz));
ClassNode ca = new ClassNode() {
public void visitEnd() {
//accept(cv);
}
};
cr.accept(new CheckClassAdapter(ca), ClassWriter.COMPUTE_MAXS);
boolean failed = false;
List methods = ca.methods;
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = (MethodNode) methods.get(i);
if (method.instructions.size() > 0) {
Analyzer a = new Analyzer(new SimpleVerifier());
try {
a.analyze(ca.name, method);
continue;
} catch (Exception e) {
e.printStackTrace();
}
if (!failed) {
failed = true;
log("verifying of class " + clazz + " failed");
}
if (verbose)
log(method.name + method.desc);
TraceMethodVisitor mv = new TraceMethodVisitor(null);
/*= new TraceMethodVisitor(null) {
public void visitMaxs(int maxStack, int maxLocals) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < text.size(); ++i) {
String s = frames[i] == null ? "null" : frames[i].toString();
while (s.length() < maxStack + maxLocals + 1) {
s += " ";
}
buffer.append(Integer.toString(i + 100000).substring(1));
buffer.append(" ");
buffer.append(s);
buffer.append(" : ");
buffer.append(text.get(i));
}
if (verbose) log(buffer.toString());
}
};*/
for (int j = 0; j < method.instructions.size(); ++j) {
Object insn = method.instructions.get(j);
if (insn instanceof AbstractInsnNode) {
((AbstractInsnNode) insn).accept(mv);
} else {
mv.visitLabel((Label) insn);
}
}
mv.visitMaxs(method.maxStack, method.maxLocals);
}
}
return !failed;
}
use of org.objectweb.asm.tree.analysis.SimpleVerifier in project bytecode-viewer by Konloch.
the class CheckClassAdapter method verify.
/**
* Checks a given class.
*
* @param cr
* a <code>ClassReader</code> that contains bytecode for the
* analysis.
* @param loader
* a <code>ClassLoader</code> which will be used to load
* referenced classes. This is useful if you are verifiying
* multiple interdependent classes.
* @param dump
* true if bytecode should be printed out not only when errors
* are found.
* @param pw
* write where results going to be printed
*/
public static void verify(final ClassReader cr, final ClassLoader loader, final boolean dump, final PrintWriter pw) {
ClassNode cn = new ClassNode();
cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG);
Type syperType = cn.superName == null ? null : Type.getObjectType(cn.superName);
List<MethodNode> methods = cn.methods;
List<Type> interfaces = new ArrayList<Type>();
for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext(); ) {
interfaces.add(Type.getObjectType(i.next()));
}
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = methods.get(i);
SimpleVerifier verifier = new SimpleVerifier(Type.getObjectType(cn.name), syperType, interfaces, (cn.access & Opcodes.ACC_INTERFACE) != 0);
Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier);
if (loader != null) {
verifier.setClassLoader(loader);
}
try {
a.analyze(cn.name, method);
if (!dump) {
continue;
}
} catch (Exception e) {
e.printStackTrace(pw);
}
printAnalyzerResult(method, a, pw);
}
pw.flush();
}
use of org.objectweb.asm.tree.analysis.SimpleVerifier in project groovy-core by groovy.
the class VerifyClass method readClass.
private boolean readClass(String clazz) throws IOException {
ClassReader cr = new ClassReader(new FileInputStream(clazz));
ClassNode ca = new ClassNode() {
public void visitEnd() {
//accept(cv);
}
};
cr.accept(new CheckClassAdapter(ca), ClassWriter.COMPUTE_MAXS);
boolean failed = false;
List methods = ca.methods;
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = (MethodNode) methods.get(i);
if (method.instructions.size() > 0) {
Analyzer a = new Analyzer(new SimpleVerifier());
try {
a.analyze(ca.name, method);
continue;
} catch (Exception e) {
e.printStackTrace();
}
final Frame[] frames = a.getFrames();
if (!failed) {
failed = true;
log("verifying of class " + clazz + " failed");
}
if (verbose)
log(method.name + method.desc);
TraceMethodVisitor mv = new TraceMethodVisitor(null);
/*= new TraceMethodVisitor(null) {
public void visitMaxs(int maxStack, int maxLocals) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < text.size(); ++i) {
String s = frames[i] == null ? "null" : frames[i].toString();
while (s.length() < maxStack + maxLocals + 1) {
s += " ";
}
buffer.append(Integer.toString(i + 100000).substring(1));
buffer.append(" ");
buffer.append(s);
buffer.append(" : ");
buffer.append(text.get(i));
}
if (verbose) log(buffer.toString());
}
};*/
for (int j = 0; j < method.instructions.size(); ++j) {
Object insn = method.instructions.get(j);
if (insn instanceof AbstractInsnNode) {
((AbstractInsnNode) insn).accept(mv);
} else {
mv.visitLabel((Label) insn);
}
}
mv.visitMaxs(method.maxStack, method.maxLocals);
}
}
return !failed;
}
Aggregations