/*
  * @see com.ibm.wala.ipa.callgraph.ContextSelector#getCalleeTarget(com.ibm.wala.ipa.callgraph.CGNode,
  *      com.ibm.wala.classLoader.CallSiteReference, com.ibm.wala.classLoader.IMethod,
  *      com.ibm.wala.ipa.callgraph.propagation.InstanceKey)
  */
 public Context getCalleeTarget(
     CGNode caller, CallSiteReference site, IMethod callee, InstanceKey[] receiver) {
   if (callee.getReference().equals(GET_CLASS)) {
     return new JavaTypeContext(new PointType(receiver[0].getConcreteType()));
   }
   return null;
 }
Beispiel #2
0
  @Override
  public IMethod getCalleeTarget(CGNode caller, CallSiteReference site, IClass receiver) {
    IMethod target = base.getCalleeTarget(caller, site, receiver);
    if (target != null && target.getReference().equals(loadFileFunRef)) {

      Set<String> names = new HashSet<String>();
      SSAInstruction call =
          caller.getIR()
              .getInstructions()[
              caller.getIR().getCallInstructionIndices(site).intIterator().next()];
      if (call.getNumberOfUses() > 1) {
        LocalPointerKey fileNameV = new LocalPointerKey(caller, call.getUse(1));
        OrdinalSet<InstanceKey> ptrs = builder.getPointerAnalysis().getPointsToSet(fileNameV);
        for (InstanceKey k : ptrs) {
          if (k instanceof ConstantKey) {
            Object v = ((ConstantKey) k).getValue();
            if (v instanceof String) {
              names.add((String) v);
            }
          }
        }

        if (names.size() == 1) {
          String str = names.iterator().next();
          try {
            JavaScriptLoader cl =
                (JavaScriptLoader) builder.getClassHierarchy().getLoader(JavaScriptTypes.jsLoader);
            URL url = new URL(builder.getBaseURL(), str);
            if (!loadedFiles.contains(url)) {
              // try to open the input stream for the URL.  if it fails, we'll get an IOException
              // and fall through to default case
              InputStream inputStream = url.openConnection().getInputStream();
              inputStream.close();
              JSCallGraphUtil.loadAdditionalFile(builder.getClassHierarchy(), cl, url);
              loadedFiles.add(url);
              IClass script =
                  builder
                      .getClassHierarchy()
                      .lookupClass(
                          TypeReference.findOrCreate(cl.getReference(), "L" + url.getFile()));
              return script.getMethod(JavaScriptMethods.fnSelector);
            }
          } catch (MalformedURLException e1) {
            // do nothing, fall through and return 'target'
          } catch (IOException e) {
            // do nothing, fall through and return 'target'
          } catch (RuntimeException e) {
            // do nothing, fall through and return 'target'
          }
        }
      }
    }

    return target;
  }
 /**
  * @see
  *     com.ibm.wala.ipa.callgraph.propagation.SSAContextInterpreter#getIR(com.ibm.wala.ipa.callgraph.CGNode)
  */
 @Override
 public IR getIR(CGNode node) {
   if (node == null) {
     throw new IllegalArgumentException("node is null");
   }
   assert understands(node);
   if (DEBUG) {
     System.err.println("generating IR for " + node);
   }
   IMethod method = node.getMethod();
   GetMethodContext context = (GetMethodContext) node.getContext();
   Map<Integer, ConstantValue> constants = HashMapFactory.make();
   if (method.getReference().equals(GET_METHOD)) {
     Atom name = Atom.findOrCreateAsciiAtom(context.getName());
     SSAInstruction instrs[] = makeGetMethodStatements(context, constants, name);
     return new SyntheticIR(
         method,
         context,
         new InducedCFG(instrs, method, context),
         instrs,
         SSAOptions.defaultOptions(),
         constants);
   }
   if (method.getReference().equals(GET_DECLARED_METHOD)) {
     Atom name = Atom.findOrCreateAsciiAtom(context.getName());
     SSAInstruction instrs[] = makeGetDeclaredMethodStatements(context, constants, name);
     return new SyntheticIR(
         method,
         context,
         new InducedCFG(instrs, method, context),
         instrs,
         SSAOptions.defaultOptions(),
         constants);
   }
   Assertions.UNREACHABLE("Unexpected method " + node);
   return null;
 }
Beispiel #4
0
  private static void computeAliasVariant(
      final MoJo mojo,
      final MayAliasGraph alias,
      final IMethod method,
      final boolean ignoreExceptions,
      final String outDir)
      throws IllegalArgumentException, CancelException, PDGFormatException, WalaException,
          FileNotFoundException {
    final Logger debug = Log.getLogger(Log.L_MOJO_DEBUG);
    final Logger info = Log.getLogger(Log.L_MOJO_INFO);

    info.out("Preparing points-to config and call graph...");
    final PointsTo pts = MoJo.computePointsTo(alias);
    if (debug.isEnabled()) {
      AliasGraphIO.dumpToDot(alias, outDir + ".alias.dot");
    }
    AliasGraphIO.writeOut(alias, new FileOutputStream(outDir + ".alias"));

    final AnalysisOptions optPts = mojo.createAnalysisOptionsWithPTS(pts, method);
    final CallGraphResult cg = mojo.computeContextSensitiveCallGraph(optPts);
    if (debug.isEnabled()) {
      final PrintStream ssaOut = new PrintStream(outDir + ".ssa.txt");
      Util.dumpSSA(cg.cg.getFakeRootNode().getIR(), ssaOut);
      Util.dumpPhiSSA(cg.cg.getFakeRootNode().getIR(), ssaOut);
      ssaOut.flush();
      ssaOut.close();

      Util.dumpHeapGraphToFile(
          outDir + ".heap.dot", cg.pts.getHeapGraph(), cg.cg.getFakeRootNode().getMethod());
    }
    info.out("done, sdg... ");
    // run analysis on callgraph with minimal alias configuration
    // ...
    final edu.kit.joana.ifc.sdg.graph.SDG sdg = createSDG(cg, optPts, method, ignoreExceptions);
    SDGSerializer.toPDGFormat(sdg, new BufferedOutputStream(new FileOutputStream(outDir + ".pdg")));
    info.out("(" + sdg.edgeSet().size() + " edges)");

    if (debug.isEnabled()) {
      final int summary =
          outputSummaryEdges(sdg, method.getReference().getSignature(), outDir + ".sum.dot");
      debug.out(" (" + summary + " sum)");
    }

    info.outln(" done.");
  }
 /**
  * @param m a method reference
  * @return a SyntheticMethod corresponding to m; or null if none is available.
  */
 protected SyntheticMethod findOrCreateSyntheticMethod(IMethod m, boolean isStatic) {
   MethodReference ref = m.getReference();
   if (syntheticMethods.containsKey(ref)) {
     return syntheticMethods.get(ref);
   } else {
     MethodSummary summ = null;
     if (canIgnore(ref)) {
       summ = generateNoOp(ref, isStatic);
     } else {
       summ = findSummary(ref);
     }
     if (summ != null) {
       SummarizedMethod n = new SummarizedMethod(ref, summ, m.getDeclaringClass());
       syntheticMethods.put(ref, n);
       return n;
     } else {
       syntheticMethods.put(ref, null);
       return null;
     }
   }
 }
Beispiel #6
0
  public static Iterable<Entrypoint> makePrimordialPublicEntrypoints(
      AnalysisScope scope, ClassHierarchy cha, String pkg) {
    final HashSet<Entrypoint> result = HashSetFactory.make();
    for (IClass clazz : cha) {

      if (clazz.getName().toString().indexOf(pkg) != -1
          && !clazz.isInterface()
          && !clazz.isAbstract()) {
        for (IMethod method : clazz.getDeclaredMethods()) {
          if (method.isPublic() && !method.isAbstract()) {
            System.out.println("Entry:" + method.getReference());
            result.add(new DefaultEntrypoint(method, cha));
          }
        }
      }
    }
    return new Iterable<Entrypoint>() {
      @Override
      public Iterator<Entrypoint> iterator() {
        return result.iterator();
      }
    };
  }