Usages of

com.ibm.wala.types.TypeName.equals(?)
/** * Returns the Element the type matches exactly the given type. * * @return The Element if found or AndroidComponent.UNKNOWN if not */ public static AndroidComponent explicit(final TypeName type) { for (AndroidComponent test: AndroidComponent.values()) { if (type.equals(test.type)) { return test; } } return UNKNOWN; }
@Override public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver) { IMethod method = receiver.getMethod(AstMethodReference.fnSelector); if (method != null) { TypeName tn = method.getReference().getDeclaringClass().getName(); if (tn.equals(APPLY_TYPE_NAME)) { if (applyMethod == null) { applyMethod = createApplyDummyMethod(receiver); } return applyMethod; } } return base.getCalleeTarget(caller, site, receiver); }
/** * First parameter in the selector that matches _exactly_. * * @return first parameter found or null if there is none * @throws IllegalArgumentException if searching for void or null */ public Parameter firstOf(final TypeName tName) { if (tName == null) { throw new IllegalArgumentException("Search-name may not be null"); } if (tName.equals(TypeReference.VoidName)) { throw new IllegalArgumentException("You are searching for 'void' as a parameter."); } final List<Parameter> all = all(); // **** // Implementation starts here for (final Parameter cand : all) { if (cand.getType().getName().equals(tName)) { return cand; } } return null; }
/** * Check if an Entrypoint takes an object. */ public boolean checkNoObjectInEntryPoints() { boolean pass = true; final List <AndroidEntryPoint> entrypoits = AndroidEntryPointManager.ENTRIES; for (AndroidEntryPoint ep : entrypoits) { final TypeName[] params = ep.getMethod().getDescriptor().getParameters(); if (params == null) continue; for (final TypeName type : params) { if (type.equals(TypeReference.JavaLangObject.getName())) { // Why if JavaLangObjectName private? .. narf pass = false; } } } return pass; }
/* * (non-Javadoc) * * @see * com.ibm.wala.ipa.callgraph.MethodTargetSelector#getCalleeTarget(com.ibm * .wala.ipa.callgraph.CGNode, com.ibm.wala.classLoader.CallSiteReference, * com.ibm.wala.classLoader.IClass) */ @Override public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver) { IMethod method = receiver.getMethod(AstMethodReference.fnSelector); if (method != null) { TypeName tn = method.getReference().getDeclaringClass().getName(); if (tn.equals(CALL_TYPE_NAME)) { /* invoking Function.prototype.call as a constructor results in a TypeError * see ECMA-262 5.1, 15: "None of the built-in functions described in this clause that * are not constructors shall implement the [[Construct]] internal method unless otherwise * specified" */ if(!site.getDeclaredTarget().equals(JavaScriptMethods.ctorReference)) { IMethod target = getFunctionCallTarget(caller, site, receiver); if(target != null) return target; } // if we get here, we either saw an invocation of "call" as a constructor, or an invocation // without receiver object; in either case, this is likely due to bad call graph info if(WARN_ABOUT_IMPRECISE_CALLGRAPH) warnAboutImpreciseCallGraph(caller, site); } } return base.getCalleeTarget(caller, site, receiver); }
/** * Construct JUnit entrypoints for the specified test method in a scope. * * @throws IllegalArgumentException if cha is null */ public static Iterable<Entrypoint> makeOne(IClassHierarchy cha, String targetPackageName, String targetSimpleClassName, String targetMethodName) { if (cha == null) { throw new IllegalArgumentException("cha is null"); } // assume test methods don't have parameters final Atom targetPackageAtom = Atom.findOrCreateAsciiAtom(targetPackageName); final Atom targetSimpleClassAtom = Atom.findOrCreateAsciiAtom(targetSimpleClassName); final TypeName targetType = TypeName.findOrCreateClass(targetPackageAtom, targetSimpleClassAtom); final Atom targetMethodAtom = Atom.findOrCreateAsciiAtom(targetMethodName); if (DEBUG) { System.err.println(("finding entrypoint " + targetMethodAtom + " in " + targetType)); } final Set<Entrypoint> entryPts = HashSetFactory.make(); for (IClass klass : cha) { TypeName klassType = klass.getName(); if (klassType.equals(targetType) && isJUnitTestCase(klass)) { if (DEBUG) { System.err.println("found test class"); } // add entry point corresponding to the target method for (Iterator methodsIt = klass.getDeclaredMethods().iterator(); methodsIt.hasNext();) { IMethod method = (IMethod) methodsIt.next(); Atom methodAtom = method.getName(); if (methodAtom.equals(targetMethodAtom)) { entryPts.add(new DefaultEntrypoint(method, cha)); System.out.println("- adding entry point of the call graph: " + methodAtom.toString()); } } // add entry points of setUp/tearDown methods Set<IMethod> setUpTearDowns = getSetUpTearDownMethods(klass); for (IMethod m : setUpTearDowns) { entryPts.add(new DefaultEntrypoint(m, cha)); } } } return new Iterable<Entrypoint>() { @Override public Iterator<Entrypoint> iterator() { return entryPts.iterator(); } }; }
private void updateJavaSourceAnnotations() { this.sources = ArrayListMultimap.create(); this.sinks = ArrayListMultimap.create(); final TypeReference source = TypeReference.findOrCreate( ClassLoaderReference.Application, TypeName.findOrCreate(JavaType.parseSingleTypeFromString(Source.class.getCanonicalName()).toBCString(false))); final TypeReference sink = TypeReference.findOrCreate( ClassLoaderReference.Application, TypeName.findOrCreate(JavaType.parseSingleTypeFromString(Sink.class.getCanonicalName()).toBCString(false))); final TypeName annotationPolicy = TypeName.findOrCreate(JavaType.parseSingleTypeFromString(AnnotationPolicy.class.getCanonicalName()).toBCString()); final TypeName positionDefinition = TypeName.findOrCreate(JavaType.parseSingleTypeFromString(AnnotationPolicy.class.getCanonicalName()).toBCString()); final Map<SDGProgramPart,Collection<Pair<Annotation,String>>> annotations = program.getJavaSourceAnnotations(); for (final Entry<SDGProgramPart,Collection<Pair<Annotation,String>>> e : annotations.entrySet()) { for(final Pair<Annotation,String> p : e.getValue()) { final Annotation a = p.getFirst(); final String sourceFile = p.getSecond(); debug.outln("Processing::: " + a); if (source.equals(a.getType())) { final ElementValue levelValue = a.getNamedArguments().get("level"); final String level; if (levelValue == null) { level = null; } else { // As per @Sink / @Source Definition: "level" is a constant String (such as "LOW" or "HIGH") final ConstantElementValue constantvalue = (ConstantElementValue) levelValue; // .. of Type String level = (String) constantvalue.val; } final ElementValue annotateValue = a.getNamedArguments().get("annotate"); final AnnotationPolicy annotate; if (annotateValue == null) { annotate = null; } else { final EnumElementValue enumannotate = (EnumElementValue) annotateValue; assert (annotationPolicy.equals(TypeName.findOrCreate(enumannotate.enumType))); annotate = AnnotationPolicy.valueOf(enumannotate.enumVal); } final ElementValue positionDefinitionValue = a.getNamedArguments().get("positionDefinition"); final PositionDefinition positionDef; if (positionDefinitionValue == null) { positionDef = null; } else { final EnumElementValue enumpositiondefinition = (EnumElementValue) positionDefinitionValue; assert (positionDefinition.equals(TypeName.findOrCreate(enumpositiondefinition.enumType))); positionDef = PositionDefinition.valueOf(enumpositiondefinition.enumVal); } final ElementValue mayKnowValue = a.getNamedArguments().get("mayKnow"); final String[] mayKnow; if (mayKnowValue == null) { mayKnow = null; } else { final ArrayElementValue arrayMayKnow = (ArrayElementValue) mayKnowValue; mayKnow = new String[arrayMayKnow.vals.length]; for (int i = 0; i < arrayMayKnow.vals.length; i++) { mayKnow[i] = arrayMayKnow.vals[i].toString(); } } final ElementValue includesValue = a.getNamedArguments().get("includes"); final String[] includes; if (includesValue == null) { includes = null; } else { final ArrayElementValue arrayIncludes = (ArrayElementValue) includesValue; includes = new String[arrayIncludes.vals.length]; for (int i = 0; i < arrayIncludes.vals.length; i++) { includes[i] = arrayIncludes.vals[i].toString(); } } final ElementValue lineNumberValue = a.getNamedArguments().get("lineNumber"); final Integer lineNumber; if (lineNumberValue == null) { lineNumber = -1; } else { final ConstantElementValue constantvalue = (ConstantElementValue) lineNumberValue; lineNumber = (Integer) constantvalue.val; } final ElementValue columnNumberValue = a.getNamedArguments().get("columnNumber"); final Integer columnNumber; if (columnNumberValue == null) { columnNumber = -1; } else { final ConstantElementValue constantvalue = (ConstantElementValue) columnNumberValue; columnNumber = (Integer) constantvalue.val; } final ElementValue idValue = a.getNamedArguments().get("id"); final String id; if (idValue == null) { id = null; } else { // As per @Sink / @Source Definition: "id" is a constant String final ConstantElementValue constantvalue = (ConstantElementValue) idValue; // .. of Type String id = (String) constantvalue.val; } sources.put(e.getKey(), Pair.pair(new Source() { @Override public Class<? extends java.lang.annotation.Annotation> annotationType() { return Source.class; } @Override public String[] mayKnow() { return mayKnow; } @Override public String level() { return level; } @Override public String[] includes() { return includes; } @Override public AnnotationPolicy annotate() { return annotate; } @Override public PositionDefinition positionDefinition() { return positionDef; } @Override public int lineNumber() { return lineNumber; } @Override public int columnNumber() { return columnNumber; } @Override public String id() { return id; } @Override public String toString() { return "@Source(level = " + level + ", includes = " + Arrays.toString(includes) + ", mayKnow = " + Arrays.toString(mayKnow) + ")"; }; }, sourceFile)); } else if (sink.equals(a.getType())) { final ElementValue levelValue = a.getNamedArguments().get("level"); final String level; if (levelValue == null) { level = null; } else { // As per @Sink / @Source Definition: "level" is a constant String (such as "LOW" or "HIGH") final ConstantElementValue constantvalue = (ConstantElementValue) levelValue; // .. of Type String level = (String) constantvalue.val; } final ElementValue annotateValue = a.getNamedArguments().get("annotate"); final AnnotationPolicy annotate; if (annotateValue == null) { annotate = null; } else { final EnumElementValue enumannotate = (EnumElementValue) annotateValue; assert (annotationPolicy.equals(TypeName.findOrCreate(enumannotate.enumType))); annotate = AnnotationPolicy.valueOf(enumannotate.enumVal); } final ElementValue positionDefinitionValue = a.getNamedArguments().get("positionDefinition"); final PositionDefinition positionDef; if (positionDefinitionValue == null) { positionDef = null; } else { final EnumElementValue enumpositiondefinition = (EnumElementValue) positionDefinitionValue; assert (positionDefinition.equals(TypeName.findOrCreate(enumpositiondefinition.enumType))); positionDef = PositionDefinition.valueOf(enumpositiondefinition.enumVal); } final ElementValue seenByValue = a.getNamedArguments().get("seenBy"); final String[] seenBy; if (seenByValue == null) { seenBy = null; } else { final ArrayElementValue arraySeenBy = (ArrayElementValue) seenByValue; seenBy = new String[arraySeenBy.vals.length]; for (int i = 0; i < arraySeenBy.vals.length; i++) { seenBy[i] = arraySeenBy.vals[i].toString(); } } final ElementValue mayIncludeValue = a.getNamedArguments().get("mayInclude"); final String[] mayInclude; if (mayIncludeValue == null) { mayInclude = null; } else { final ArrayElementValue arrayMayInclude = (ArrayElementValue) mayIncludeValue; mayInclude = new String[arrayMayInclude.vals.length]; for (int i = 0; i < arrayMayInclude.vals.length; i++) { mayInclude[i] = arrayMayInclude.vals[i].toString(); } } final ElementValue lineNumberValue = a.getNamedArguments().get("lineNumber"); final Integer lineNumber; if (lineNumberValue == null) { lineNumber = -1; } else { final ConstantElementValue constantvalue = (ConstantElementValue) lineNumberValue; lineNumber = (Integer) constantvalue.val; } final ElementValue columnNumberValue = a.getNamedArguments().get("columnNumber"); final Integer columnNumber; if (columnNumberValue == null) { columnNumber = -1; } else { final ConstantElementValue constantvalue = (ConstantElementValue) columnNumberValue; columnNumber = (Integer) constantvalue.val; } final ElementValue idValue = a.getNamedArguments().get("id"); final String id; if (idValue == null) { id = null; } else { // As per @Sink / @Source Definition: "id" is a constant String final ConstantElementValue constantvalue = (ConstantElementValue) idValue; // .. of Type String id = (String) constantvalue.val; } sinks.put(e.getKey(), Pair.pair(new Sink() { @Override public Class<? extends java.lang.annotation.Annotation> annotationType() { return Sink.class; } @Override public String[] seenBy() { return seenBy; } @Override public String[] mayInclude() { return mayInclude; } @Override public String level() { return level; } @Override public AnnotationPolicy annotate() { return annotate; } @Override public PositionDefinition positionDefinition() { return positionDef; } @Override public int lineNumber() { return lineNumber; } @Override public int columnNumber() { return columnNumber; } @Override public String id() { return id; } @Override public String toString() { return "@Sink(level = " + level + ", mayInclude = " + Arrays.toString(mayInclude) + ", seenBy = " + Arrays.toString(seenBy) + ")"; } }, sourceFile)); } } } }
@Override public Context getCalleeTarget(CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] receiver) { IClass declaringClass = callee.getDeclaringClass(); IMethod method = declaringClass.getMethod(AstMethodReference.fnSelector); Context baseCtxt = base.getCalleeTarget(caller, site, callee, receiver); if (method != null) { TypeName tn = method.getReference().getDeclaringClass().getName(); if (tn.equals(APPLY_TYPE_NAME)) { boolean isNonNullArray = false; if (receiver.length >= 4) { InstanceKey argsList = receiver[3]; if (argsList != null && argsList.getConcreteType().equals(caller.getClassHierarchy().lookupClass(JavaScriptTypes.Array))) { isNonNullArray = true; } } if (USE_ONE_LEVEL && caller.getContext().get(APPLY_NON_NULL_ARGS) == null) baseCtxt = oneLevel.getCalleeTarget(caller, site, callee, receiver); return new ApplyContext(baseCtxt, isNonNullArray); } else if (USE_ONE_LEVEL && tn.equals(CALL_TYPE_NAME)) { return oneLevel.getCalleeTarget(caller, site, callee, receiver); } } return baseCtxt; }
/** * If Java Source annotations are available, add corresponding IFC Annotations to the Analysis. */ public void addAllJavaSourceAnnotations() { final TypeReference source = TypeReference.findOrCreate( ClassLoaderReference.Application, TypeName.findOrCreate(JavaType.parseSingleTypeFromString(Source.class.getCanonicalName()).toBCString(false))); final TypeReference sink = TypeReference.findOrCreate( ClassLoaderReference.Application, TypeName.findOrCreate(JavaType.parseSingleTypeFromString(Sink.class.getCanonicalName()).toBCString(false))); final TypeName level = TypeName.findOrCreate(JavaType.parseSingleTypeFromString(Level.class.getCanonicalName()).toBCString()); final TypeName annotationPolicy = TypeName.findOrCreate(JavaType.parseSingleTypeFromString(AnnotationPolicy.class.getCanonicalName()).toBCString()); final Map<SDGProgramPart,Collection<Annotation>> annotations = program.getJavaSourceAnnotations(); for (final Entry<SDGProgramPart,Collection<Annotation>> e : annotations.entrySet()) { for(final Annotation a : e.getValue()) { debug.outln("Processing::: " + a); if(source.equals(a.getType()) || sink.equals(a.getType())) { final ElementValue elemvalue = a.getNamedArguments().get("level"); final Level l; if (elemvalue == null) { // try to get default value Level temp = null; try { if (source.equals(a.getType())) { temp = (Level) Source.class.getMethod("level").getDefaultValue(); } else { temp = (Level) Sink.class.getMethod("level").getDefaultValue(); } } catch (Exception e1) { assert false; } finally { l = temp; } } else { // As per @Sink / @Source Definition: "value" is an Enum .. assert (elemvalue != null && elemvalue instanceof EnumElementValue); final EnumElementValue enumvalue = (EnumElementValue) elemvalue; // .. of Type Level / AnnotationPolicy assert (level.equals(TypeName.findOrCreate(enumvalue.enumType))); l = Level.valueOf(enumvalue.enumVal); } assert (l != null); // If "annotate" is missing, use the default value final ElementValue elemannotate = a.getNamedArguments().get("annotate"); final AnnotationPolicy ap; if (elemannotate == null) { AnnotationPolicy temp = null; try { temp = (AnnotationPolicy) Source.class.getMethod("annotate").getDefaultValue(); } catch (Exception e1) { assert false; } finally { ap = temp; } } else { assert (elemannotate instanceof EnumElementValue); final EnumElementValue enumannotate = (EnumElementValue) elemannotate; assert (annotationPolicy.equals(TypeName.findOrCreate(enumannotate.enumType))); ap = AnnotationPolicy.valueOf(enumannotate.enumVal); } assert ap!=null; // TODO: instead of two "Typeswitches" (over latticelevel and a.getType()), do something nicer. final String latticeLevel; switch (l) { case HIGH: latticeLevel = BuiltinLattices.STD_SECLEVEL_HIGH; break; case LOW: latticeLevel = BuiltinLattices.STD_SECLEVEL_LOW; break; default: latticeLevel = null; throw new IllegalArgumentException("Unknown Security-Level:" + l); } e.getKey().acceptVisitor(new ThrowingSDGProgramPartVisitor<Void, Void>() { @Override protected Void visitMethod(SDGMethod m, Void data) { if (source.equals(a.getType())) addSourceAnnotation(m, latticeLevel,ap); if (sink.equals(a.getType())) addSinkAnnotation(m, latticeLevel,ap); return null; } @Override protected Void visitAttribute(SDGAttribute attribute, Void data) { if (ap != AnnotationPolicy.ANNOTATE_USAGES) { throw new IllegalArgumentException("Fields may onlye be annotated with annotate == " + AnnotationPolicy.ANNOTATE_USAGES); } if (source.equals(a.getType())) addSourceAnnotation(attribute, latticeLevel); if (sink.equals(a.getType())) addSinkAnnotation(attribute, latticeLevel); return null; } }, null); debug.outln("Added " + a.getType().getName().getClassName() + " Annotation: " + e.getKey() + ":::" + latticeLevel); } } } }
@Override protected Map<Integer, StringVariable> flowGetStatic(SSAGetInstruction i, Set<Map<Integer, StringVariable>> previousItems, ControlFlowGraph<SSAInstruction, ISSABasicBlock> cfg, ISSABasicBlock current) { TypeName type = types.getType(i.getDef()).getName(); if (type.equals(STRING)) { IClassHierarchy cha = AnalysisUtil.getClassHierarchy(); IField field = cha.resolveField(i.getDeclaredField()); StringVariable def = factory.getOrCreateLocal(i.getDef(), m, pp); if (field.isFinal()) { // static final field // Get the results of the String analysis for the static initializer for the containing class IMethod clinit = getClassInitMethod(i.getDeclaredField().getDeclaringClass()); Map<StringVariable, AbstractString> res = results.getResultsForMethod(clinit); StringVariable fieldVar = factory.getOrCreateStaticField(field.getReference()); AbstractString s = res.get(fieldVar); statements.add(new ConstantStringStatement(def, s)); } else { // Intra-procedural analysis so we don't track non-final fields statements.add(new ConstantStringStatement(def, AbstractString.ANY)); } } else if (type.equals(STRING_BUILDER)) { // Intra-procedural analysis so we don't track StringBuilder fields // We'll treat this like a new StringBuilder that could contain any string StringVariable def = factory.createStringBuilder(i.getDef(), m, current.getNumber(), StringBuilderVarType.DEF, -1, pp); statements.add(new ConstantStringStatement(def, AbstractString.ANY)); Map<Integer, StringVariable> out = confluence(previousItems, current); out.put(i.getDef(), def); return out; } return confluence(previousItems, current); }
Usage snippet has been bookmarked! Review your bookmarks
Thank you! Review your likes