use of org.objectweb.asm.ClassReader in project spring-loaded by spring-projects.
the class ClassPrinter method main.
public static void main(String[] argv) throws Exception {
ClassReader reader = new ClassReader(Utils.loadBytesFromStream(new FileInputStream(new File(argv[0]))));
reader.accept(new ClassPrinter(System.out, INCLUDE_BYTECODE), 0);
}
use of org.objectweb.asm.ClassReader in project es6draft by anba.
the class Code method toByteCode.
private static String toByteCode(ClassVisitor cv, Printer p, byte[] bytes) {
new ClassReader(bytes).accept(cv, ClassReader.EXPAND_FRAMES);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
p.print(pw);
pw.flush();
return sw.toString();
}
use of org.objectweb.asm.ClassReader in project flink by apache.
the class JarFileCreator method addDependencies.
/**
* Add the dependencies within the given packages automatically.
* @throws IOException
* throw if an error occurs while read the class file.
*/
private synchronized void addDependencies() throws IOException {
List<String> dependencies = new ArrayList<String>();
for (Class clazz : classSet) {
dependencies.add(clazz.getName());
}
//Traverse the dependency tree using BFS.
int head = 0;
while (head != dependencies.size()) {
DependencyVisitor v = new DependencyVisitor(Opcodes.ASM5);
v.addNameSpace(this.packages);
InputStream classInputStream = null;
String name = dependencies.get(head);
try {
Class clazz = Class.forName(name);
int n = name.lastIndexOf('.');
String className = null;
if (n > -1) {
className = name.substring(n + 1, name.length());
}
classInputStream = clazz.getResourceAsStream(className + CLASS_EXTENSION);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage());
}
new ClassReader(classInputStream).accept(v, 0);
classInputStream.close();
//Update the BFS queue.
Set<String> classPackages = v.getPackages();
for (String s : classPackages) {
if (!dependencies.contains(s.replace('/', '.'))) {
dependencies.add(s.replace('/', '.'));
}
}
head++;
}
for (String dependency : dependencies) {
try {
this.classSet.add(Class.forName(dependency));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e.getMessage());
}
}
}
use of org.objectweb.asm.ClassReader in project groovy by apache.
the class SunClassLoader method loadFromRes.
protected void loadFromRes(String name) throws IOException {
final InputStream asStream = SunClassLoader.class.getClassLoader().getResourceAsStream(resName(name));
ClassReader reader = new ClassReader(asStream);
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
reader.accept(cw, ClassWriter.COMPUTE_MAXS);
asStream.close();
define(cw.toByteArray(), name);
}
use of org.objectweb.asm.ClassReader 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;
}
Aggregations