org.objectweb.asm.tree.analysis.SimpleVerifier Java Examples
The following examples show how to use
org.objectweb.asm.tree.analysis.SimpleVerifier.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CheckClassAdapter.java From Concurnas with MIT License | 5 votes |
/** * Checks the given class. * * @param classReader the class to be checked. * @param loader a <code>ClassLoader</code> which will be used to load referenced classes. May be * {@literal null}. * @param printResults whether to print the results of the bytecode verification. * @param printWriter where the results (or the stack trace in case of error) must be printed. */ public static void verify( final ClassReader classReader, final ClassLoader loader, final boolean printResults, final PrintWriter printWriter) { ClassNode classNode = new ClassNode(); classReader.accept( new CheckClassAdapter(Opcodes.ASM7, classNode, false) {}, ClassReader.SKIP_DEBUG); Type syperType = classNode.superName == null ? null : Type.getObjectType(classNode.superName); List<MethodNode> methods = classNode.methods; List<Type> interfaces = new ArrayList<>(); for (String interfaceName : classNode.interfaces) { interfaces.add(Type.getObjectType(interfaceName)); } for (MethodNode method : methods) { SimpleVerifier verifier = new SimpleVerifier( Type.getObjectType(classNode.name), syperType, interfaces, (classNode.access & Opcodes.ACC_INTERFACE) != 0); Analyzer<BasicValue> analyzer = new Analyzer<>(verifier); if (loader != null) { verifier.setClassLoader(loader); } try { analyzer.analyze(classNode.name, method); } catch (AnalyzerException e) { e.printStackTrace(printWriter); } if (printResults) { printAnalyzerResult(method, analyzer, printWriter); } } printWriter.flush(); }
Example #2
Source File: CheckClassAdapter.java From JByteMod-Beta with GNU General Public License v2.0 | 5 votes |
/** * Checks a given class. * * @param cr * a <code>ClassReader</code> that contains bytecode for the * analysis. * @param loader * a <code>ClassLoader</code> which will be used to load referenced * classes. This is useful if you are verifiying multiple * interdependent classes. * @param dump * true if bytecode should be printed out not only when errors are * found. * @param pw * write where results going to be printed */ public static void verify(final ClassReader cr, final ClassLoader loader, final boolean dump, final PrintWriter pw) { ClassNode cn = new ClassNode(); cr.accept(new CheckClassAdapter(cn, false), ClassReader.SKIP_DEBUG); Type syperType = cn.superName == null ? null : Type.getObjectType(cn.superName); List<MethodNode> methods = cn.methods; List<Type> interfaces = new ArrayList<Type>(); for (Iterator<String> i = cn.interfaces.iterator(); i.hasNext();) { interfaces.add(Type.getObjectType(i.next())); } for (int i = 0; i < methods.size(); ++i) { MethodNode method = methods.get(i); SimpleVerifier verifier = new SimpleVerifier(Type.getObjectType(cn.name), syperType, interfaces, (cn.access & Opcodes.ACC_INTERFACE) != 0); Analyzer<BasicValue> a = new Analyzer<BasicValue>(verifier); if (loader != null) { verifier.setClassLoader(loader); } try { a.analyze(cn.name, method); if (!dump) { continue; } } catch (Exception e) { e.printStackTrace(pw); } printAnalyzerResult(method, a, pw); } pw.flush(); }
Example #3
Source File: CheckClassAdapter.java From JReFrameworker with MIT License | 5 votes |
/** * Checks the given class. * * @param classReader the class to be checked. * @param loader a <code>ClassLoader</code> which will be used to load referenced classes. May be * {@literal null}. * @param printResults whether to print the results of the bytecode verification. * @param printWriter where the results (or the stack trace in case of error) must be printed. */ public static void verify( final ClassReader classReader, final ClassLoader loader, final boolean printResults, final PrintWriter printWriter) { ClassNode classNode = new ClassNode(); classReader.accept( new CheckClassAdapter(Opcodes.ASM7, classNode, false) {}, ClassReader.SKIP_DEBUG); Type syperType = classNode.superName == null ? null : Type.getObjectType(classNode.superName); List<MethodNode> methods = classNode.methods; List<Type> interfaces = new ArrayList<Type>(); for (String interfaceName : classNode.interfaces) { interfaces.add(Type.getObjectType(interfaceName)); } for (MethodNode method : methods) { SimpleVerifier verifier = new SimpleVerifier( Type.getObjectType(classNode.name), syperType, interfaces, (classNode.access & Opcodes.ACC_INTERFACE) != 0); Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(verifier); if (loader != null) { verifier.setClassLoader(loader); } try { analyzer.analyze(classNode.name, method); } catch (AnalyzerException e) { e.printStackTrace(printWriter); } if (printResults) { printAnalyzerResult(method, analyzer, printWriter); } } printWriter.flush(); }
Example #4
Source File: CheckClassAdapter.java From JReFrameworker with MIT License | 5 votes |
/** * Checks the given class. * * @param classReader the class to be checked. * @param loader a <code>ClassLoader</code> which will be used to load referenced classes. May be * {@literal null}. * @param printResults whether to print the results of the bytecode verification. * @param printWriter where the results (or the stack trace in case of error) must be printed. */ public static void verify( final ClassReader classReader, final ClassLoader loader, final boolean printResults, final PrintWriter printWriter) { ClassNode classNode = new ClassNode(); classReader.accept( new CheckClassAdapter(Opcodes.ASM7, classNode, false) {}, ClassReader.SKIP_DEBUG); Type syperType = classNode.superName == null ? null : Type.getObjectType(classNode.superName); List<MethodNode> methods = classNode.methods; List<Type> interfaces = new ArrayList<Type>(); for (String interfaceName : classNode.interfaces) { interfaces.add(Type.getObjectType(interfaceName)); } for (MethodNode method : methods) { SimpleVerifier verifier = new SimpleVerifier( Type.getObjectType(classNode.name), syperType, interfaces, (classNode.access & Opcodes.ACC_INTERFACE) != 0); Analyzer<BasicValue> analyzer = new Analyzer<BasicValue>(verifier); if (loader != null) { verifier.setClassLoader(loader); } try { analyzer.analyze(classNode.name, method); } catch (AnalyzerException e) { e.printStackTrace(printWriter); } if (printResults) { printAnalyzerResult(method, analyzer, printWriter); } } printWriter.flush(); }
Example #5
Source File: AsmTestUtils.java From grappa with Apache License 2.0 | 5 votes |
public static void verifyMethodIntegrity(final String ownerInternalName, final MethodNode method) { try { new Analyzer(new SimpleVerifier()).analyze(ownerInternalName, method); } catch (AnalyzerException e) { throw new RuntimeException( "Integrity error in method '" + method.name + "' of type '" + ownerInternalName + "': ", e); } }