private void decoracteAsmClassFromBytecode(AsmClass asmClass, DETAIL_LEVEL level) { InputStream input = null; try { AsmClassVisitor classVisitor = new AsmClassVisitor(this, asmClass, level); input = classLoader.getResourceAsStream(asmClass.getInternalName() + ".class"); ClassReader asmReader = new ClassReader(input); asmReader.accept(classVisitor, 0); } catch (IOException e) { LOG.warn("Class '" + asmClass.getInternalName() + "' is not accessible through the ClassLoader."); } catch (SecurityException e) { LOG.warn("Class '" + asmClass.getInternalName() + "' is not accessible through the ClassLoader. One signed jar seems to be corrupted."); } catch (Exception e) { LOG.error("Unable to process bytecode of class '" + asmClass.getInternalName() + "'", e); } finally { IOUtils.closeQuietly(input); } }
@Override public FieldVisitor visitField(int access, String fieldName, String description, String signature, Object value) { AsmField field = asmClass.getFieldOrCreateIt(fieldName); field.setAccessFlags(access); String[] internalNames = AsmSignature.extractInternalNames(description, signature); AsmClass[] asmClasses = internalNamesToAsmClasses(internalNames, DETAIL_LEVEL.NOTHING); field.addUsesOfClasses(asmClasses); return null; }
private static boolean isInheritedMethodSignature(AsmClass parent, String key) { if (parent.getSuperClass() != null && (parent.getSuperClass().getMethod(key) != null || isInheritedMethodSignature(parent.getSuperClass(), key))) { return true; } for (AsmClass interfaceClass : parent.getInterfaces()) { if (interfaceClass.getMethod(key) != null || isInheritedMethodSignature(interfaceClass, key)) { return true; } } return false; } }
@Override public MethodVisitor visitMethod(int access, String methodName, String description, String signature, String[] exceptions) { AsmMethod method = asmClass.getMethodOrCreateIt(methodName + description); if (isInheritedMethodSignature(method.getParent(), method.getKey())) { method.setInherited(true); } method.setSignature(signature); method.setBodyLoaded(true); method.setAccessFlags(access); method.clearOutogingEdges(); String[] internalNames = AsmSignature.extractInternalNames(description, signature); AsmClass[] asmClasses = internalNamesToAsmClasses(internalNames, DETAIL_LEVEL.NOTHING); method.addUsesOfClasses(asmClasses); AsmClass[] asmExceptionClasses = internalNamesToAsmClasses(exceptions, DETAIL_LEVEL.STRUCTURE); method.addUsesOfClasses(asmExceptionClasses); method.addThrowsOfClasses(asmExceptionClasses); if (level == DETAIL_LEVEL.STRUCTURE_AND_CALLS) { return new AsmMethodVisitor(method, asmClassProvider); } return null; }
@Override public MethodVisitor visitMethod(int access, String methodName, String description, String signature, String[] exceptions) { AsmMethod method = asmClass.getMethodOrCreateIt(methodName + description); if (isInheritedMethodSignature(method.getParent(), method.getKey())) { method.setInherited(true); } method.setSignature(signature); method.setBodyLoaded(true); method.setAccessFlags(access); method.clearOutogingEdges(); String[] internalNames = AsmSignature.extractInternalNames(description, signature); AsmClass[] asmClasses = internalNamesToAsmClasses(internalNames, DETAIL_LEVEL.NOTHING); method.addUsesOfClasses(asmClasses); AsmClass[] asmExceptionClasses = internalNamesToAsmClasses(exceptions, DETAIL_LEVEL.STRUCTURE); method.addUsesOfClasses(asmExceptionClasses); method.addThrowsOfClasses(asmExceptionClasses); if (level == DETAIL_LEVEL.STRUCTURE_AND_CALLS) { return new AsmMethodVisitor(method, asmClassProvider); } return null; }
@Override public FieldVisitor visitField(int access, String fieldName, String description, String signature, Object value) { AsmField field = asmClass.getFieldOrCreateIt(fieldName); field.setAccessFlags(access); String[] internalNames = AsmSignature.extractInternalNames(description, signature); AsmClass[] asmClasses = internalNamesToAsmClasses(internalNames, DETAIL_LEVEL.NOTHING); field.addUsesOfClasses(asmClasses); return null; }
private boolean isInheritedMethodSignature(AsmClass parent, String key) { if (parent.getSuperClass() != null && (parent.getSuperClass().getMethod(key) != null || isInheritedMethodSignature(parent.getSuperClass(), key))) { return true; } for (AsmClass interfaceClass : parent.getInterfaces()) { if (interfaceClass.getMethod(key) != null || isInheritedMethodSignature(interfaceClass, key)) { return true; } } return false; } }
private void decoracteAsmClassFromBytecode(AsmClass asmClass, DETAIL_LEVEL level) { InputStream input = null; try { AsmClassVisitor classVisitor = new AsmClassVisitor(this, asmClass, level); input = classLoader.getResourceAsStream(asmClass.getInternalName() + ".class"); ClassReader asmReader = new ClassReader(input); asmReader.accept(classVisitor, 0); } catch (IOException e) { LOG.warn("Class '" + asmClass.getInternalName() + "' is not accessible through the ClassLoader."); } catch (SecurityException e) { LOG.warn("Class '" + asmClass.getInternalName() + "' is not accessible through the ClassLoader. One signed jar seems to be corrupted."); } catch (Exception e) { LOG.error("Unable to process bytecode of class '" + asmClass.getInternalName() + "'", e); } finally { IOUtils.closeQuietly(input); } }
@Override public void visit(int version, int accessFlags, String internalName, String signature, String superClass, String[] interfaces) { if (asmClass.getDetailLevel() == DETAIL_LEVEL.NOTHING) { asmClass.setAccessFlags(accessFlags); if (asmClass.isInterface()) { if (interfaces.length == 1) { asmClass.setSuperClass(asmClassProvider.getClass(interfaces[0], DETAIL_LEVEL.STRUCTURE)); } } else { if (superClass != null) { asmClass.setSuperClass(asmClassProvider.getClass(superClass, DETAIL_LEVEL.STRUCTURE)); } for (String interfaceName : interfaces) { asmClass.addInterface(asmClassProvider.getClass(interfaceName, DETAIL_LEVEL.STRUCTURE)); } } if (signature != null) { String[] internalNames = AsmSignature.extractInternalNames(signature); AsmClass[] asmClasses = internalNamesToAsmClasses(internalNames, DETAIL_LEVEL.NOTHING); asmClass.addUsesOfClasses(asmClasses); } } asmClass.setDetailLevel(level); }
@Override public void visit(int version, int accessFlags, String internalName, String signature, String superClass, String[] interfaces) { if (asmClass.getDetailLevel() == DETAIL_LEVEL.NOTHING) { asmClass.setAccessFlags(accessFlags); if (asmClass.isInterface()) { if (interfaces.length == 1) { asmClass.setSuperClass(asmClassProvider.getClass(interfaces[0], DETAIL_LEVEL.STRUCTURE)); } } else { if (superClass != null) { asmClass.setSuperClass(asmClassProvider.getClass(superClass, DETAIL_LEVEL.STRUCTURE)); } for (String interfaceName : interfaces) { asmClass.addInterface(asmClassProvider.getClass(interfaceName, DETAIL_LEVEL.STRUCTURE)); } } if (signature != null) { String[] internalNames = AsmSignature.extractInternalNames(signature); AsmClass[] asmClasses = internalNamesToAsmClasses(internalNames, DETAIL_LEVEL.NOTHING); asmClass.addUsesOfClasses(asmClasses); } } asmClass.setDetailLevel(level); }