public static CallGraph makeScriptCG(String dir, String name, CGBuilderType builderType, ClassLoader loader) throws IOException, IllegalArgumentException, CancelException, WalaException { PropagationCallGraphBuilder b = makeScriptCGBuilder(dir, name, builderType, loader); CallGraph CG = b.makeCallGraph(b.getOptions()); // dumpCG(b.getPointerAnalysis(), CG); return CG; }
@Test(expected = WalaException.class) public void testParseError() throws IllegalArgumentException, IOException, CancelException, WalaException { PropagationCallGraphBuilder B = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "portal-example-simple.html"); B.makeCallGraph(B.getOptions()); com.ibm.wala.cast.util.Util.checkForFrontEndErrors(B.getClassHierarchy()); }
@Override public void action(AbstractFieldPointerKey fieldKey) { if (!representsNullType(fieldKey.getInstanceKey())) { system.newConstraint(fieldKey, assignOperator, rhs); } } }
@Test public void testArrayIndexConv2() throws IllegalArgumentException, IOException, CancelException, WalaException { PropagationCallGraphBuilder b = JSCallGraphBuilderUtil.makeScriptCGBuilder("tests", "array_index_conv2.js"); b.setContextSelector(new PropertyNameContextSelector(b.getAnalysisCache(), b.getContextSelector())); CallGraph cg = b.makeCallGraph(b.getOptions()); //JSCallGraphUtil.AVOID_DUMP = false; //JSCallGraphUtil.dumpCG(b.getPointerAnalysis(), cg); verifyGraphAssertions(cg, assertionsForArrayIndexConv2); }
if (getBuilder().getOptions().getMaxNumberOfNodes() > -1) { if (getBuilder().getCallGraph().getNumberOfNodes() >= getBuilder().getOptions().getMaxNumberOfNodes()) { if (DEBUG) { System.err.println("Bail out from call graph limit" + i); System.err.println("adding constraints"); getBuilder().addConstraintsFromNewNodes(monitor); System.err.println("handling reflection"); if (i <= getBuilder().getOptions().getReflectionOptions().getNumFlowToCastIterations()) { getReflectionHandler().updateForReflection(monitor); System.err.println("adding constraints again"); getBuilder().addConstraintsFromNewNodes(monitor);
/** * Simply add the instance to each relevant points-to set. */ @Override public byte evaluate(PointsToSetVariable dummyLHS, PointsToSetVariable var) { PointsToSetVariable ref = var; if (ref.size() == 0) { return NOT_CHANGED; } IntSet value = ref.getValue(); final MutableBoolean sideEffect = new MutableBoolean(); IntSetAction action = i -> { InstanceKey I = system.getInstanceKey(i); if (!representsNullType(I)) { PointerKey p = getPointerKeyForInstanceField(I, field); if (p != null) { sideEffect.b |= system.newConstraint(p, instance); } } }; if (priorInstances != null) { value.foreachExcluding(priorInstances, action); priorInstances.addAll(value); } else { value.foreach(action); } byte sideEffectMask = sideEffect.b ? (byte) SIDE_EFFECT_MASK : 0; return (byte) (NOT_CHANGED | sideEffectMask); }
private Collection<Statement> computeFactoryReturnStatements() { // todo: clean up logic with inheritance, delegation. HashSet<Statement> result = HashSetFactory.make(); for (CGNode n : builder.getCallGraph()) { if (n.getMethod() instanceof SyntheticMethod) { SyntheticMethod m = (SyntheticMethod) n.getMethod(); if (m.isFactoryMethod()) { result.add(new NormalReturnCallee(n)); } } } return result; }
changedNodes.addAll(modifyFactoryInterpreter(st, casts, builder.getContextInterpreter(), builder.getClassHierarchy())); builder.addConstraintsFromChangedNode(cgNode, monitor);
continue; IClass contents = getClassHierarchy().lookupClass(C); if (contents == null) { assert false : "null type for " + C + ' ' + I.getConcreteType(); PointerKey p = getPointerKeyForArrayContents(I); if (DEBUG_ARRAY_STORE) { System.err.println("ArrayStore add filtered-assign: " + p + ' ' + pVal); if (isJavaLangObject(contents)) { sideEffect |= system.newFieldWrite(p, assignOperator, pVal); } else {
PointerAnalysis<InstanceKey> pointerAnalysis = builder.getPointerAnalysis(); JavaScriptLoader jsLoader = (JavaScriptLoader) builder.getClassHierarchy().getLoader(JavaScriptTypes.jsLoader); JSCallGraphUtil.loadAdditionalFile(builder.getClassHierarchy(), jsLoader, sourceModule); IClass script = builder.getClassHierarchy() .lookupClass(TypeReference.findOrCreate(jsLoader.getReference(), className));
/** * get the CGNode representing the lexical parent of {@link #creator} with * name definer * */ public Iterator<CGNode> getFunargNodes(Pair<String, String> name) { Collection<CGNode> constructorCallers = getConstructorCallers(this, name); assert constructorCallers != null && !constructorCallers.isEmpty() : "no callers for constructor"; Iterator<CGNode> result = EmptyIterator.instance(); for (CGNode callerOfConstructor : constructorCallers) { if (callerOfConstructor.getMethod().getReference().getDeclaringClass().getName().toString().equals(name.snd)) { result = new CompoundIterator<>(result, new NonNullSingletonIterator<>(callerOfConstructor)); } else { PointerKey funcKey = builder.getPointerKeyForLocal(callerOfConstructor, 1); for (InstanceKey funcPtr : builder.getPointerAnalysis().getPointsToSet(funcKey)) { if (funcPtr instanceof ScopeMappingInstanceKey) { result = new CompoundIterator<>(result, ((ScopeMappingInstanceKey) funcPtr).getFunargNodes(name)); } } } } return result; }
return; IClass contents = getClassHierarchy().lookupClass(C); if (contents == null) { assert false : "null type for " + C + ' ' + I.getConcreteType(); PointerKey p = getPointerKeyForArrayContents(I); if (contents.isInterface()) { if (getClassHierarchy().implementsInterface(instance.getConcreteType(), contents)) { sideEffect.b |= system.newConstraint(p, instance); if (getClassHierarchy().isSubclassOf(instance.getConcreteType(), contents)) { sideEffect.b |= system.newConstraint(p, instance);
@Override public IClassHierarchy getClassHierarchy() { return builder.getClassHierarchy(); } }
public CallGraph makeCallGraph(AnalysisOptions options) throws IllegalArgumentException, CancelException { return makeCallGraph(options, null); }
protected ExplicitCallGraph createEmptyCallGraph(IMethod abstractRootMethod, AnalysisOptions options) { return new ExplicitCallGraph(abstractRootMethod, options, getAnalysisCache()); }
private Set<String> getRequireTargets(PointerAnalysis<InstanceKey> pointerAnalysis, CGNode caller, JavaScriptInvoke callInstr) { HashSet<String> set = HashSetFactory.make(); PointerKey pk = builder.getPointerKeyForLocal(caller, callInstr.getUse(2)); OrdinalSet<InstanceKey> instanceKeys = pointerAnalysis.getPointsToSet(pk); for (InstanceKey instanceKey : instanceKeys) { if (instanceKey instanceof ConstantKey<?>) { Object value = ((ConstantKey<?>) instanceKey).getValue(); if (value instanceof String) { set.add((String) value); } else { System.err.println("NodejsRequireTargetSelector: Unexpected value: " + value); return HashSetFactory.make(); } } else if (instanceKey instanceof ConcreteTypeKey) { // Cannot do anything with this information... } else { System.err.println("NodejsRequireTargetSelector: Unexpected instanceKey: " + instanceKey.getClass() + " -- " + instanceKey); return HashSetFactory.make(); } } return set; }
if (getBuilder().getOptions().getMaxNumberOfNodes() > -1) { if (getBuilder().getCallGraph().getNumberOfNodes() >= getBuilder().getOptions().getMaxNumberOfNodes()) { if (DEBUG) { System.err.println("Bail out from call graph limit" + i); System.err.println("adding constraints"); getBuilder().addConstraintsFromNewNodes(monitor); System.err.println("handling reflection"); if (i <= getBuilder().getOptions().getReflectionOptions().getNumFlowToCastIterations()) { getReflectionHandler().updateForReflection(monitor); System.err.println("adding constraints again"); getBuilder().addConstraintsFromNewNodes(monitor);
/** * Simply add the instance to each relevant points-to set. */ @Override public byte evaluate(PointsToSetVariable dummyLHS, PointsToSetVariable var) { PointsToSetVariable ref = var; if (ref.size() == 0) { return NOT_CHANGED; } IntSet value = ref.getValue(); final MutableBoolean sideEffect = new MutableBoolean(); IntSetAction action = i -> { InstanceKey I = system.getInstanceKey(i); if (!representsNullType(I)) { PointerKey p = getPointerKeyForInstanceField(I, field); if (p != null) { sideEffect.b |= system.newConstraint(p, instance); } } }; if (priorInstances != null) { value.foreachExcluding(priorInstances, action); priorInstances.addAll(value); } else { value.foreach(action); } byte sideEffectMask = sideEffect.b ? (byte) SIDE_EFFECT_MASK : 0; return (byte) (NOT_CHANGED | sideEffectMask); }
private Collection<Statement> computeFactoryReturnStatements() { // todo: clean up logic with inheritance, delegation. HashSet<Statement> result = HashSetFactory.make(); for (CGNode n : builder.getCallGraph()) { if (n.getMethod() instanceof SyntheticMethod) { SyntheticMethod m = (SyntheticMethod) n.getMethod(); if (m.isFactoryMethod()) { result.add(new NormalReturnCallee(n)); } } } return result; }
changedNodes.addAll(modifyFactoryInterpreter(st, casts, builder.getContextInterpreter(), builder.getClassHierarchy())); builder.addConstraintsFromChangedNode(cgNode, monitor);