use of org.objectweb.asm.util.CheckClassAdapter in project dex2jar by pxb1988.
the class AsmVerify method doCommandLine.
@Override
protected void doCommandLine() throws Exception {
if (remainingArgs.length < 1) {
usage();
return;
}
List<Path> files = new ArrayList<>();
for (String fn : remainingArgs) {
Path file = new File(fn).toPath();
if (!Files.exists(file)) {
System.err.println(fn + " doesn't exist");
usage();
return;
}
files.add(file);
}
for (Path file : files) {
System.out.println("verify " + file);
walkJarOrDir(file, new FileVisitorX() {
@Override
public void visitFile(Path file, String relative) throws IOException {
if (file.getFileName().toString().endsWith(".class")) {
ClassReader cr = new ClassReader(Files.readAllBytes(file));
ClassNode cn = new ClassNode();
cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG | ClassReader.EXPAND_FRAMES | ClassReader.SKIP_FRAMES);
for (MethodNode method : cn.methods) {
BasicVerifier verifier = new BasicVerifier();
Analyzer<BasicValue> a = new Analyzer<>(verifier);
try {
a.analyze(cn.name, method);
} catch (Exception ex) {
System.err.println("Error verify method " + cr.getClassName() + "." + method.name + " " + method.desc);
if (detail) {
ex.printStackTrace(System.err);
printAnalyzerResult(method, a, new PrintWriter(new OutputStreamWriter(System.err, StandardCharsets.UTF_8)));
}
}
}
}
}
});
}
}
use of org.objectweb.asm.util.CheckClassAdapter in project closure-templates by google.
the class ClassData method checkClass.
/**
* Runs the {@link CheckClassAdapter} on this class in basic analysis mode.
*
* <p>Basic anaylsis mode can flag verification errors that don't depend on knowing complete type
* information for the classes and methods being called. This is useful for flagging simple
* generation mistakes (e.g. stack underflows, method return type mismatches, accessing invalid
* locals). Additionally, the error messages are more useful than what the java verifier normally
* presents.
*/
public void checkClass() {
ClassNode cv = new ClassNode();
new ClassReader(data).accept(new CheckClassAdapter(cv, true), 0);
// double check our fields while we are here.
checkState(type.internalName().equals(cv.name));
checkState(numberOfFields == cv.fields.size());
}
use of org.objectweb.asm.util.CheckClassAdapter in project phosphor by gmu-swe.
the class SourceSinkTransformer method transform.
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
if (classBeingRedefined == null) {
// should be performed
return null;
} else if (Throwable.class.isAssignableFrom(classBeingRedefined)) {
return null;
}
try {
ClassReader cr = new ClassReader(classfileBuffer);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
ClassVisitor cv = cw;
if (PreMain.DEBUG || TaintUtils.VERIFY_CLASS_GENERATION) {
cv = new CheckClassAdapter(cw, false);
}
cr.accept(new SourceSinkTaintingClassVisitor(cv), ClassReader.EXPAND_FRAMES);
if (PreMain.DEBUG) {
try {
File f = new File("debug-source-sink/" + className + ".class");
f.getParentFile().mkdirs();
FileOutputStream fos = new FileOutputStream(f);
fos.write(cw.toByteArray());
fos.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
return cw.toByteArray();
} catch (Throwable t) {
// If we don't try/catch and print the error, then it will be silently swallowed by the JVM
// and we'll never know the instrumentation failed :(
t.printStackTrace();
throw t;
}
}
Aggregations