use of org.objectweb.asm.tree.ClassNode in project neo4j by neo4j.
the class ByteCodeVerifier method classNode.
private static ClassNode classNode(ByteBuffer bytecode) {
byte[] bytes;
if (bytecode.hasArray()) {
bytes = bytecode.array();
} else {
bytes = new byte[bytecode.limit()];
bytecode.get(bytes);
}
ClassNode classNode = new ClassNode();
new ClassReader(bytes).accept(new CheckClassAdapter(classNode, false), SKIP_DEBUG);
return classNode;
}
use of org.objectweb.asm.tree.ClassNode in project pinpoint by naver.
the class ASMClassNodeAdapter method get.
public static ASMClassNodeAdapter get(final InstrumentContext pluginContext, final ClassLoader classLoader, final String classInternalName, final boolean skipCode) {
if (pluginContext == null || classInternalName == null) {
throw new IllegalArgumentException("plugin context or class name must not be null.");
}
InputStream in = null;
try {
in = pluginContext.getResourceAsStream(classLoader, classInternalName + ".class");
if (in != null) {
final ClassReader classReader = new ClassReader(in);
final ClassNode classNode = new ClassNode();
if (skipCode) {
classReader.accept(classNode, ClassReader.SKIP_CODE);
} else {
classReader.accept(classNode, 0);
}
return new ASMClassNodeAdapter(pluginContext, classLoader, classNode, skipCode);
}
} catch (IOException ignored) {
// not found class.
} finally {
if (in != null) {
try {
in.close();
} catch (IOException ignored) {
}
}
}
return null;
}
use of org.objectweb.asm.tree.ClassNode in project pinpoint by naver.
the class ASMEngine method getClass.
@Override
public InstrumentClass getClass(InstrumentContext instrumentContext, ClassLoader classLoader, String className, byte[] classFileBuffer) throws NotFoundInstrumentException {
if (className == null) {
throw new NullPointerException("class name must not be null.");
}
try {
if (classFileBuffer == null) {
ASMClassNodeAdapter classNode = ASMClassNodeAdapter.get(instrumentContext, classLoader, JavaAssistUtils.javaNameToJvmName(className));
if (classNode == null) {
return null;
}
ApiMetaDataService apiMetaDataService = this.apiMetaDataService.get();
return new ASMClass(objectBinderFactory, instrumentContext, interceptorRegistryBinder, apiMetaDataService, classLoader, classNode);
}
// Use ASM tree api.
final ClassReader classReader = new ClassReader(classFileBuffer);
final ClassNode classNode = new ClassNode();
classReader.accept(classNode, 0);
ApiMetaDataService apiMetaDataService = this.apiMetaDataService.get();
return new ASMClass(objectBinderFactory, instrumentContext, interceptorRegistryBinder, apiMetaDataService, classLoader, classNode);
} catch (Exception e) {
throw new NotFoundInstrumentException(e);
}
}
use of org.objectweb.asm.tree.ClassNode in project Engine by VoltzEngine-Project.
the class ClassTransformer method transform.
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
if (EngineCoreMod.devMode && enableSuperDetails) {
EngineCoreMod.logger.info("com.builtbroken.mc.core.asm.template.transform(name='" + name + "' transformedName='" + transformedName + "', bytes);");
}
try {
//Only functions on our classes
if (!shouldProcess(transformedName) || TemplateManager.templates.isEmpty()) {
if (EngineCoreMod.devMode && enableSuperDetails) {
EngineCoreMod.logger.info("\tClass is not in processing list so is ignored");
}
return bytes;
}
boolean changed = false;
ClassNode cnode = ASMHelper.createClassNode(bytes);
if (cnode != null && cnode.visibleAnnotations != null) {
for (AnnotationNode nodes : cnode.visibleAnnotations) {
if (nodes.desc.equals("Lcom/builtbroken/mc/api/InjectTemplate;")) {
if (EngineCoreMod.devMode && enableSuperDetails) {
EngineCoreMod.logger.info("\t Class contains annotation, injecting code");
}
/*
* The 2nd value in UniversalClass is the annotation we're looking for to filter
* out which mod to deal with.
*/
String flags = null;
if (nodes.values != null && nodes.values.size() >= 2) {
flags = (String) nodes.values.get(1);
}
changed |= injectTemplate(cnode, flags);
break;
}
}
}
if (changed) {
byte[] data = ASMHelper.createBytes(cnode, ClassWriter.COMPUTE_FRAMES);
if (EngineCoreMod.devMode) {
try {
File file = new File(System.getProperty("user.dir"), "asmTestFolder/" + name + ".class");
if (!file.getParentFile().exists()) {
file.getParentFile().mkdirs();
}
FileOutputStream fos = new FileOutputStream(file);
fos.write(data);
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return data;
}
} catch (Exception e) {
throw new RuntimeException("TemplateClassTransformer: Failed to process class " + transformedName, e);
}
return bytes;
}
use of org.objectweb.asm.tree.ClassNode in project Engine by VoltzEngine-Project.
the class InjectionTemplate method init.
//Called late to avoid loading class data in the constructor
private boolean init() {
if (!init) {
init = true;
try {
final ClassNode cnode = ASMHelper.createClassNode(((LaunchClassLoader) InjectionTemplate.class.getClassLoader()).getClassBytes(className.replace('/', '.')));
for (MethodNode method : cnode.methods) {
this.methodImplementations.add(method);
method.desc = new ObfMapping(cnode.name, method.name, method.desc).toRuntime().s_desc;
}
} catch (IOException e) {
//TODO error out in dev mode
//TODO make notation to users that this injector failed
e.printStackTrace();
failedToLoadClass = true;
}
}
return failedToLoadClass;
}
Aggregations