@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))); } } } } } });
@SuppressWarnings("rawtypes") public static void verify(final ClassReader cr, PrintWriter out) throws AnalyzerException, IllegalArgumentException, IllegalAccessException { ClassNode cn = new ClassNode(); cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG); List methods = cn.methods; for (int i = 0; i < methods.size(); ++i) { MethodNode method = (MethodNode) methods.get(i); List tryCatchBlocks = method.tryCatchBlocks; for (int j = 0; j < tryCatchBlocks.size(); j++) { TryCatchBlockNode tcn = (TryCatchBlockNode) tryCatchBlocks.get(j); if (tcn.start.equals(tcn.end)) { throw new DexException("try/catch block %d in %s has same start(%s) and end(%s)", j, method.name, tcn.start.getLabel(), tcn.end.getLabel()); } } BasicVerifier verifier = new BasicVerifier(); Analyzer a = new Analyzer(verifier); try { a.analyze(cn.name, method); } catch (Exception e) { out.println(cr.getClassName() + "." + method.name + method.desc); printAnalyzerResult(method, a, out); e.printStackTrace(out); out.flush(); throw new DexException("method " + method.name + " " + method.desc, e); } } }
@Override public void visitEnd() { Analyzer<BasicValue> a = new Analyzer<BasicValue>( new BasicVerifier()); try { a.analyze("dummy", this); } catch (Exception e) { if (e instanceof IndexOutOfBoundsException && maxLocals == 0 && maxStack == 0) { throw new RuntimeException( "Data flow checking option requires valid, non zero maxLocals and maxStack values."); } e.printStackTrace(); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw, true); CheckClassAdapter.printAnalyzerResult(this, a, pw); pw.close(); throw new RuntimeException(e.getMessage() + ' ' + sw.toString()); } accept(cmv); } }, labels);
@Override public void visitEnd() { Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(new BasicVerifier()); try { analyzer.analyze("dummy", this); } catch (IndexOutOfBoundsException e) { if (maxLocals == 0 && maxStack == 0) { throw new IllegalArgumentException( "Data flow checking option requires valid, non zero maxLocals and maxStack.", e); } throwError(analyzer, e); } catch (AnalyzerException e) { throwError(analyzer, e); } accept(methodVisitor); }
@Override public void visitEnd() { Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(new BasicVerifier()); try { analyzer.analyze("dummy", this); } catch (IndexOutOfBoundsException e) { if (maxLocals == 0 && maxStack == 0) { throw new IllegalArgumentException( "Data flow checking option requires valid, non zero maxLocals and maxStack.", e); } throwError(analyzer, e); } catch (AnalyzerException e) { throwError(analyzer, e); } accept(methodVisitor); }