List of usage examples for org.objectweb.asm.tree ClassNode ClassNode
public ClassNode()
From source file:com.navercorp.pinpoint.profiler.instrument.ASMClassNodeLoader.java
License:Apache License
public static ClassNode get(final String classInternalName) throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); ClassReader cr = new ClassReader( classLoader.getResourceAsStream(classInternalName.replace('.', '/') + ".class")); ClassNode classNode = new ClassNode(); cr.accept(classNode, ClassReader.EXPAND_FRAMES); return classNode; }
From source file:com.navercorp.pinpoint.profiler.instrument.ASMClassPool.java
License:Apache License
@Override public InstrumentClass getClass(InstrumentContext instrumentContext, ClassLoader classLoader, String classInternalName, byte[] classFileBuffer) throws NotFoundInstrumentException { if (classInternalName == null) { throw new NullPointerException("class internal name must not be null."); }//from w w w . ja v a 2 s. com try { if (classFileBuffer == null) { ASMClassNodeAdapter classNode = ASMClassNodeAdapter.get(classLoader, classInternalName.replace('.', '/')); if (classNode == null) { return null; } return new ASMClass(instrumentContext, interceptorRegistryBinder, classLoader, classNode); } // Use ASM tree api. final ClassReader classReader = new ClassReader(classFileBuffer); final ClassNode classNode = new ClassNode(); classReader.accept(classNode, 0); return new ASMClass(instrumentContext, interceptorRegistryBinder, classLoader, classNode); } catch (Exception e) { throw new NotFoundInstrumentException(e); } }
From source file:com.navercorp.pinpoint.profiler.instrument.ASMEngine.java
License:Apache License
@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."); }/* w w w. ja v a 2 s .co m*/ 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); } }
From source file:com.offbynull.coroutines.instrumenter.asm.SimpleClassWriterTest.java
License:Open Source License
@Before public void setUp() throws IOException { byte[] classData = readZipFromResource("SimpleStub.zip").get("SimpleStub.class"); ClassReader classReader = new ClassReader(classData); classNode = new ClassNode(); classReader.accept(classNode, 0);/*from w w w.ja va 2 s . c o m*/ methodNode = classNode.methods.get(1); // stub should be here }
From source file:com.offbynull.coroutines.instrumenter.testhelpers.TestUtils.java
License:Open Source License
/** * Load up a ZIP resource from the classpath and generate a {@link ClassNode} for each file with a class extension in that ZIP. * Behaviour is ZIP or classes within are not a parseable. * @param path path of ZIP resource// w w w. j av a 2 s. co m * @return {@link ClassNode} representation of class files in ZIP * @throws NullPointerException if any argument is {@code null} * @throws IOException if any IO error occurs * @throws IllegalArgumentException if {@code path} cannot be found */ public static Map<String, ClassNode> readZipResourcesAsClassNodes(String path) throws IOException { Validate.notNull(path); Map<String, byte[]> files = readZipFromResource(path); Map<String, ClassNode> ret = new LinkedHashMap<>(); for (Entry<String, byte[]> entry : files.entrySet()) { if (!entry.getKey().toLowerCase().endsWith(".class")) { continue; } ClassReader cr = new ClassReader(new ByteArrayInputStream(entry.getValue())); ClassNode classNode = new ClassNode(); cr.accept(classNode, 0); ret.put(entry.getKey(), classNode); } return ret; }
From source file:com.replaymod.pixelcam.coremod.CameraTiltCT.java
License:Apache License
private byte[] transform(byte[] bytes, String name_orientCamera) { ClassReader classReader = new ClassReader(bytes); ClassNode classNode = new ClassNode(); classReader.accept(classNode, 0);/*from w ww . j av a 2s.com*/ boolean success = false; for (MethodNode m : classNode.methods) { if ("(F)V".equals(m.desc) && name_orientCamera.equals(m.name)) { inject(m.instructions.iterator()); success = true; } } if (!success) { throw new NoSuchMethodError(); } ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS); classNode.accept(classWriter); return classWriter.toByteArray(); }
From source file:com.retroduction.carma.transformer.asm.AbstractASMTransition.java
License:Open Source License
public List<Mutant> applyTransitions(byte[] byteCode) { ClassNode classNode = new ClassNode(); ClassReader reader = new ClassReader(byteCode); reader.accept(classNode, new Attribute[] { new CharacterRangeTable() }, 0); List<Mutant> result = new ArrayList<Mutant>(); int methodIndex = 0; for (MethodNode methodNode : (List<MethodNode>) classNode.methods) { Iterator<AbstractInsnNode> instructionIterator = methodNode.instructions.iterator(); CharacterRangeTable crt = null;//from w ww. ja v a 2s . c om if (methodNode.attrs != null) { for (Attribute attr : (List<Attribute>) methodNode.attrs) { if (attr instanceof CharacterRangeTable) { crt = (CharacterRangeTable) attr; } } } CRTEntry crtEntry = new CRTEntry(); while (instructionIterator.hasNext()) { AbstractInsnNode node = instructionIterator.next(); if (node instanceof LineNumberNode) { if (crt == null) { crtEntry.setStartPos(((LineNumberNode) node).line << 10); crtEntry.setEndPos(((LineNumberNode) node).line << 10); } continue; } if ((node instanceof LabelNode)) { if (crt == null) continue; if (crt.getLabelOffsets().containsKey(((LabelNode) node).getLabel())) { crtEntry = crt.getLabelOffsets().get(((LabelNode) node).getLabel()); } continue; } this.checkNode(classNode, methodNode, result, crtEntry, node); } methodIndex++; } return result; }
From source file:com.samczsun.helios.LoadedFile.java
License:Apache License
public ClassNode getClassNode(String name) { if (name.endsWith(".class")) { name = name.substring(0, name.length() - 6); }/* www . j a va 2 s . com*/ if (!classes.containsKey(name)) { byte[] bytes = getFiles().get(name + ".class"); if (bytes != null) { try { ClassReader reader = new ClassReader(bytes); ClassNode classNode = new ClassNode(); reader.accept(classNode, ClassReader.EXPAND_FRAMES); classes.put(name, new WrappedClassNode(this, classNode)); } catch (Exception t) { ExceptionHandler.handle(t); } } } return classes.get(name) != null ? classes.get(name).getClassNode() : null; }
From source file:com.samczsun.helios.LoadedFile.java
License:Apache License
private void load(String entryName, InputStream inputStream) throws IOException { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); IOUtils.copy(inputStream, outputStream); if (entryName.endsWith(".class")) { try {// w ww . j a va 2 s. c o m ClassReader reader = new ClassReader(outputStream.toByteArray()); ClassNode classNode = new ClassNode(); reader.accept(classNode, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); emptyClasses.put(classNode.name, new WrappedClassNode(this, classNode)); } catch (Exception e) { //Malformed class } } if (!files.containsKey(entryName)) { files.put(entryName, outputStream.toByteArray()); } else { System.out.println("Uh oh. Duplicate file..."); } }
From source file:com.samczsun.helios.transformers.Transformer.java
License:Apache License
protected byte[] fixBytes(byte[] in) { ClassReader reader = new ClassReader(in); ClassNode node = new ClassNode(); reader.accept(node, ClassReader.EXPAND_FRAMES); ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS); node.accept(writer);//ww w . j a v a2 s .co m return writer.toByteArray(); }