use of org.objectweb.asm.util.CheckClassAdapter in project felix by apache.
the class Manipulator method manipulate.
/**
* Manipulate the given byte array.
* @param origin : original class.
* @return the manipulated class, if the class is already manipulated, the original class.
* @throws IOException : if an error occurs during the manipulation.
*/
public byte[] manipulate(byte[] origin) throws IOException {
if (!m_alreadyManipulated) {
InputStream is2 = new ByteArrayInputStream(origin);
ClassReader reader = new ClassReader(is2);
ClassWriter writer = new ClassLoaderAwareClassWriter(ClassWriter.COMPUTE_FRAMES, m_className, m_superClass, m_classLoader);
ClassManipulator process = new ClassManipulator(new CheckClassAdapter(writer, false), this);
if (m_version >= Opcodes.V1_6) {
reader.accept(process, ClassReader.EXPAND_FRAMES);
} else {
reader.accept(process, 0);
}
is2.close();
return writer.toByteArray();
} else {
return origin;
}
}
use of org.objectweb.asm.util.CheckClassAdapter in project evosuite by EvoSuite.
the class TracingTestRunner method loadClass.
/**
* {@inheritDoc}
*/
@Override
public Class<?> loadClass(String fullyQualifiedTargetClass) throws ClassNotFoundException {
if (isSystemClass(fullyQualifiedTargetClass)) {
logger.info("Not instrumenting class '{}'.", fullyQualifiedTargetClass);
return super.loadClass(fullyQualifiedTargetClass);
}
logger.info("Instrumenting class '{}'.", fullyQualifiedTargetClass);
String className = fullyQualifiedTargetClass.replace('.', '/');
InputStream is = java.lang.ClassLoader.getSystemResourceAsStream(className + ".class");
if (is == null) {
throw new ClassNotFoundException("Class " + fullyQualifiedTargetClass + "could not be found!");
}
ClassReader reader = null;
try {
reader = new ClassReader(is);
} catch (IOException exc) {
throw new ClassNotFoundException();
}
ClassWriter writer = new ClassWriter(reader, ClassWriter.COMPUTE_MAXS);
ClassVisitor cv = new StatementTracingVisitor(fullyQualifiedTargetClass, writer);
CheckClassAdapter checkClassAdapter = new CheckClassAdapter(cv);
reader.accept(checkClassAdapter, ClassReader.SKIP_FRAMES);
byte[] byteBuffer = writer.toByteArray();
Class<?> result = defineClass(fullyQualifiedTargetClass, byteBuffer, 0, byteBuffer.length);
return result;
}
use of org.objectweb.asm.util.CheckClassAdapter in project runelite by runelite.
the class JarUtil method validateDataFlow.
private static void validateDataFlow(String name, byte[] data) {
try {
ClassReader cr = new ClassReader(data);
ClassWriter cw = new ClassWriter(cr, 0);
ClassVisitor cv = new CheckClassAdapter(cw, true);
cr.accept(cv, 0);
} catch (Exception ex) {
logger.warn("Class {} failed validation", name, ex);
}
}
use of org.objectweb.asm.util.CheckClassAdapter 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);
}
}
use of org.objectweb.asm.util.CheckClassAdapter 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;
}
Aggregations