use of org.objectweb.asm.ClassWriter in project bytecode-viewer by Konloch.
the class JarArchive method write.
public void write(File target) {
try (JarOutputStream output = (manifest != null ? new JarOutputStream(new FileOutputStream(target), manifest) : new JarOutputStream(new FileOutputStream(target)))) {
for (Map.Entry<String, ClassNode> entry : build().entrySet()) {
output.putNextEntry(new JarEntry(entry.getKey().replaceAll("\\.", "/") + ".class"));
ClassWriter writer = new ClassWriter(0);
entry.getValue().accept(writer);
output.write(writer.toByteArray());
output.closeEntry();
}
output.flush();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.objectweb.asm.ClassWriter in project gradle by gradle.
the class ApiClassExtractor method extractApiClassFrom.
/**
* Extracts an API class from a given original class.
*
* @param originalClassReader the reader containing the original class
* @return bytecode of the API class extracted from the original class. Returns null when class should not be included, due to some reason that is not known until visited.
*/
@Nullable
public byte[] extractApiClassFrom(ClassReader originalClassReader) {
ClassWriter apiClassWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ApiMemberSelector visitor = new ApiMemberSelector(originalClassReader.getClassName(), new MethodStubbingApiMemberAdapter(apiClassWriter), apiIncludesPackagePrivateMembers);
originalClassReader.accept(visitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
if (visitor.isPrivateInnerClass()) {
return null;
}
return apiClassWriter.toByteArray();
}
use of org.objectweb.asm.ClassWriter in project ignite by apache.
the class HadoopHelperImpl method loadReplace.
/**
* {@inheritDoc}
*/
@Override
public byte[] loadReplace(InputStream in, final String originalName, final String replaceName) {
ClassReader rdr;
try {
rdr = new ClassReader(in);
} catch (IOException e) {
throw new RuntimeException(e);
}
ClassWriter w = new ClassWriter(Opcodes.ASM4);
rdr.accept(new RemappingClassAdapter(w, new Remapper() {
/**
*/
String replaceType = replaceName.replace('.', '/');
/**
*/
String nameType = originalName.replace('.', '/');
@Override
public String map(String type) {
if (type.equals(replaceType))
return nameType;
return type;
}
}), ClassReader.EXPAND_FRAMES);
return w.toByteArray();
}
use of org.objectweb.asm.ClassWriter in project Lucee by lucee.
the class ClassRenamer method rename.
public static byte[] rename(byte[] src, String newName) {
ClassReader cr = new ClassReader(src);
ClassWriter cw = ASMUtil.getClassWriter();
ClassVisitor ca = new ClassRenamer(cw, newName);
cr.accept(ca, 0);
return cw.toByteArray();
}
use of org.objectweb.asm.ClassWriter in project Lucee by lucee.
the class MethodCleaner method modifie.
public static byte[] modifie(byte[] src, String methodName, Class[] args, Class rtn, String msg) {
ClassReader cr = new ClassReader(src);
ClassWriter cw = ASMUtil.getClassWriter();
ClassVisitor ca = new MethodCleaner(cw, methodName, args, rtn, msg);
cr.accept(ca, 0);
return cw.toByteArray();
}
Aggregations