use of org.objectweb.asm.tree.ClassNode in project pinpoint by naver.
the class ASMClassNodeLoader method get.
public static MethodNode get(final String classInternalName, final String methodName) throws Exception {
ClassNode classNode = get(classInternalName);
List<MethodNode> methodNodes = classNode.methods;
for (MethodNode methodNode : methodNodes) {
if (methodNode.name.equals(methodName)) {
return methodNode;
}
}
return null;
}
use of org.objectweb.asm.tree.ClassNode in project CodeChickenLib by Chicken-Bones.
the class ClassHeirachyManager method declareASM.
private static SuperCache declareASM(byte[] bytes) {
ClassNode node = ASMHelper.createClassNode(bytes);
String name = toKey(node.name);
SuperCache cache = getOrCreateCache(name);
cache.superclass = toKey(node.superName.replace('/', '.'));
cache.add(cache.superclass);
for (String iclass : node.interfaces) cache.add(toKey(iclass.replace('/', '.')));
return cache;
}
use of org.objectweb.asm.tree.ClassNode in project Minechem by iopleke.
the class MinechemTransformer method injectBytes.
private byte[] injectBytes(Method method, InstructionNode instructionNode, byte[] data) {
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(data);
classReader.accept(classNode, ClassReader.EXPAND_FRAMES);
MethodNode methodNode = getMethodByName(classNode, method);
AbstractInsnNode pos = findInstructionNode(instructionNode, methodNode);
if (instructionNode.replace) {
methodNode.instructions.insertBefore(pos, instructionNode.getInsnList());
methodNode.instructions.remove(pos);
} else {
methodNode.instructions.insertBefore(pos, instructionNode.getInsnList());
}
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
return writer.toByteArray();
}
use of org.objectweb.asm.tree.ClassNode in project drill by apache.
the class AsmUtil method classFromBytes.
/**
* Create a ClassNode from bytecode.
*
* @param classBytes the bytecode
* @param asmReaderFlags flags for ASM; see {@link org.objectweb.asm.ClassReader#accept(org.objectweb.asm.ClassVisitor, int)}
* @return the ClassNode
*/
public static ClassNode classFromBytes(final byte[] classBytes, final int asmReaderFlags) {
final ClassNode classNode = new ClassNode(CompilationConfig.ASM_API_VERSION);
final ClassReader classReader = new ClassReader(classBytes);
classReader.accept(classNode, asmReaderFlags);
return classNode;
}
use of org.objectweb.asm.tree.ClassNode in project presto by prestodb.
the class ClassInfoLoader method readClassInfoQuick.
private ClassInfo readClassInfoQuick(ParameterizedType type) {
// check for user supplied class node
ClassNode classNode = classNodes.get(type);
if (classNode != null) {
return new ClassInfo(this, classNode);
}
// check for user supplied byte code
ClassReader classReader;
byte[] bytecode = bytecodes.get(type);
if (bytecode != null) {
classReader = new ClassReader(bytecode);
} else {
// load class file from class loader
String classFileName = type.getClassName() + ".class";
try (InputStream is = classLoader.getResourceAsStream(classFileName)) {
classReader = new ClassReader(is);
} catch (IOException e) {
// check if class is already loaded
try {
Class<?> aClass = classLoader.loadClass(type.getJavaClassName());
return new ClassInfo(this, aClass);
} catch (ClassNotFoundException e1) {
throw new RuntimeException("Class not found " + type, e);
}
}
}
if (loadMethodNodes) {
// slower version that loads all operations
classNode = new ClassNode();
classReader.accept(new CheckClassAdapter(classNode, false), ClassReader.SKIP_DEBUG);
return new ClassInfo(this, classNode);
} else {
// optimized version
int header = classReader.header;
int access = classReader.readUnsignedShort(header);
char[] buf = new char[2048];
// read super class name
int superClassIndex = classReader.getItem(classReader.readUnsignedShort(header + 4));
ParameterizedType superClass;
if (superClassIndex == 0) {
superClass = null;
} else {
superClass = typeFromPathName(classReader.readUTF8(superClassIndex, buf));
}
// read each interface name
int interfaceCount = classReader.readUnsignedShort(header + 6);
ImmutableList.Builder<ParameterizedType> interfaces = ImmutableList.builder();
header += 8;
for (int i = 0; i < interfaceCount; ++i) {
interfaces.add(typeFromPathName(classReader.readClass(header, buf)));
header += 2;
}
return new ClassInfo(this, type, access, superClass, interfaces.build(), null);
}
}
Aggregations