static MethodAnnotation obfuscate(MethodAnnotation m) { String className = m.getClassName(); if (className.startsWith("java")) { return m; } String methodName = m.getMethodName(); String methodSignature = m.getMethodSignature(); if ("hashCode".equals(methodName) && "()I".equals(methodSignature) || "equals".equals(methodName) && "(Ljava/lang/Object;)Z".equals(methodSignature) || "compareTo".equals(methodName) && "(Ljava/lang/Object;)I".equals(methodSignature) || "<init>".equals(methodName) || "<clinit>".equals(methodName)) { // don't need to obfuscate method name } else { methodName = hashData(methodName); } MethodAnnotation result = new MethodAnnotation(hashClass(className), methodName, hashMethodSignature(methodSignature), m.isStatic()); result.setDescription(m.getDescription()); return result; }
public static XMethod createXMethod(MethodAnnotation ma) { return createXMethod(ma.getClassName(), ma.getMethodName(), ma.getMethodSignature(), ma.isStatic()); }
@Override public boolean match(BugInstance bugInstance) { MethodAnnotation methodAnnotation = null; if (role == null || "".equals(role)) { methodAnnotation = bugInstance.getPrimaryMethod(); } else { for (BugAnnotation a : bugInstance.getAnnotations()) { if (a instanceof MethodAnnotation && role.equals(a.getDescription())) { methodAnnotation = (MethodAnnotation) a; break; } } } if (methodAnnotation == null) { return false; } if (!name.match(methodAnnotation.getMethodName())) { return false; } if (signature != null && !signature.match(methodAnnotation.getMethodSignature())) { return false; } return true; }
public MethodDescriptor getMethodDescriptor(MethodAnnotation ma) { return getMethodDescriptor(ClassName.toSlashedClassName(ma.getClassName()), ma.getMethodName(), ma.getMethodSignature(), ma.isStatic()); }
if (methodName.equals(simpleClassName) && "()V".equals(m.getMethodSignature())) { continue;
/** * Rewrite a MethodAnnotation to update the class name, and any class names * mentioned in the method signature. * * @param classNameRewriter * a ClassNameRewriter * @param annotation * a MethodAnnotation * @return the possibly-rewritten MethodAnnotation */ public static MethodAnnotation convertMethodAnnotation(ClassNameRewriter classNameRewriter, MethodAnnotation annotation) { if (classNameRewriter != IdentityClassNameRewriter.instance()) { annotation = new MethodAnnotation(classNameRewriter.rewriteClassName(annotation.getClassName()), annotation.getMethodName(), rewriteMethodSignature(classNameRewriter, annotation.getMethodSignature()), annotation.isStatic()); } return annotation; }
if ("[Ljava/lang/Object;".equals(refSig) && source instanceof MethodAnnotation && "toArray".equals(((MethodAnnotation) source).getMethodName()) && "()[Ljava/lang/Object;".equals(((MethodAnnotation) source).getMethodSignature())) { bugPattern = "BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY"; } else { && "()[Ljava/lang/Object;".equals(((MethodAnnotation) source).getMethodSignature())) { bugReporter.reportBug(new BugInstance(this, "BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY", HIGH_PRIORITY) .addClassAndMethod(methodGen, sourceFile)
@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { XMLAttributeList attributeList = new XMLAttributeList().addAttribute("classname", getClassName()) .addAttribute("name", getMethodName()).addAttribute("signature", getMethodSignature()) .addAttribute("isStatic", String.valueOf(isStatic())); if (isPrimary) { attributeList.addAttribute("primary", "true"); } String role = getDescription(); if (!DEFAULT_ROLE.equals(role)) { attributeList.addAttribute("role", role); } if (sourceLines == null && !addMessages) { xmlOutput.openCloseTag(ELEMENT_NAME, attributeList); } else { xmlOutput.openTag(ELEMENT_NAME, attributeList); if (sourceLines != null) { sourceLines.writeXML(xmlOutput); } if (addMessages) { xmlOutput.openTag(MESSAGE_TAG); xmlOutput.writeText(this.toString()); xmlOutput.closeTag(MESSAGE_TAG); } xmlOutput.closeTag(ELEMENT_NAME); } }
static MethodAnnotation obfuscate(MethodAnnotation m) { String className = m.getClassName(); if (className.startsWith("java")) { return m; } String methodName = m.getMethodName(); String methodSignature = m.getMethodSignature(); if ("hashCode".equals(methodName) && "()I".equals(methodSignature) || "equals".equals(methodName) && "(Ljava/lang/Object;)Z".equals(methodSignature) || "compareTo".equals(methodName) && "(Ljava/lang/Object;)I".equals(methodSignature) || "<init>".equals(methodName) || "<clinit>".equals(methodName)) { // don't need to obfuscate method name } else { methodName = hashData(methodName); } MethodAnnotation result = new MethodAnnotation(hashClass(className), methodName, hashMethodSignature(methodSignature), m.isStatic()); result.setDescription(m.getDescription()); return result; }
public static XMethod createXMethod(MethodAnnotation ma) { return createXMethod(ma.getClassName(), ma.getMethodName(), ma.getMethodSignature(), ma.isStatic()); }
@Override public boolean match(BugInstance bugInstance) { MethodAnnotation methodAnnotation = null; if (role == null || "".equals(role)) { methodAnnotation = bugInstance.getPrimaryMethod(); } else { for (BugAnnotation a : bugInstance.getAnnotations()) { if (a instanceof MethodAnnotation && role.equals(a.getDescription())) { methodAnnotation = (MethodAnnotation) a; break; } } } if (methodAnnotation == null) { return false; } if (!name.match(methodAnnotation.getMethodName())) { return false; } if (signature != null && !signature.match(methodAnnotation.getMethodSignature())) { return false; } return true; }
public MethodDescriptor getMethodDescriptor(MethodAnnotation ma) { return getMethodDescriptor(ClassName.toSlashedClassName(ma.getClassName()), ma.getMethodName(), ma.getMethodSignature(), ma.isStatic()); }
if (methodName.equals(simpleClassName) && "()V".equals(m.getMethodSignature())) { continue;
/** * Rewrite a MethodAnnotation to update the class name, and any class names * mentioned in the method signature. * * @param classNameRewriter * a ClassNameRewriter * @param annotation * a MethodAnnotation * @return the possibly-rewritten MethodAnnotation */ public static MethodAnnotation convertMethodAnnotation(ClassNameRewriter classNameRewriter, MethodAnnotation annotation) { if (classNameRewriter != IdentityClassNameRewriter.instance()) { annotation = new MethodAnnotation(classNameRewriter.rewriteClassName(annotation.getClassName()), annotation.getMethodName(), rewriteMethodSignature(classNameRewriter, annotation.getMethodSignature()), annotation.isStatic()); } return annotation; }
if ("[Ljava/lang/Object;".equals(refSig) && source instanceof MethodAnnotation && "toArray".equals(((MethodAnnotation) source).getMethodName()) && "()[Ljava/lang/Object;".equals(((MethodAnnotation) source).getMethodSignature())) { bugPattern = "BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY"; } else { && "()[Ljava/lang/Object;".equals(((MethodAnnotation) source).getMethodSignature())) { bugReporter.reportBug(new BugInstance(this, "BC_IMPOSSIBLE_DOWNCAST_OF_TOARRAY", HIGH_PRIORITY) .addClassAndMethod(methodGen, sourceFile)
@Override public void writeXML(XMLOutput xmlOutput, boolean addMessages, boolean isPrimary) throws IOException { XMLAttributeList attributeList = new XMLAttributeList().addAttribute("classname", getClassName()) .addAttribute("name", getMethodName()).addAttribute("signature", getMethodSignature()) .addAttribute("isStatic", String.valueOf(isStatic())); if (isPrimary) { attributeList.addAttribute("primary", "true"); } String role = getDescription(); if (!DEFAULT_ROLE.equals(role)) { attributeList.addAttribute("role", role); } if (sourceLines == null && !addMessages) { xmlOutput.openCloseTag(ELEMENT_NAME, attributeList); } else { xmlOutput.openTag(ELEMENT_NAME, attributeList); if (sourceLines != null) { sourceLines.writeXML(xmlOutput); } if (addMessages) { xmlOutput.openTag(MESSAGE_TAG); xmlOutput.writeText(this.toString()); xmlOutput.closeTag(MESSAGE_TAG); } xmlOutput.closeTag(ELEMENT_NAME); } }