PackManager getPM() { if (pm == null) { PackManager.v(); } return pm; }
/** * Gets the baf body for the given SootMethod. This method will first check whether the method already has a baf body. If * not, it will query the local cache. If this fails as well, it will construct a new baf body. * * @param method * The method for which to obtain a baf body * @return The baf body for the given method */ protected BafBody getBafBody(SootMethod method) { final Body activeBody = method.getActiveBody(); if (activeBody instanceof BafBody) { return (BafBody) activeBody; } BafBody body = bafBodyCache.get(method); if (body != null) { return body; } if (activeBody instanceof JimpleBody) { body = PackManager.v().convertJimpleBodyToBaf(method); } else { throw new RuntimeException("ASM-backend can only translate Baf- and JimpleBodies!"); } bafBodyCache.put(method, body); return body; }
protected String getPhaseUsage() { StringBuffer b = new StringBuffer(); b.append("\nPhases and phase options:\n"); for (Pack p : PackManager.v().allPacks()) { b.append(padOpt(p.getPhaseName(), p.getDeclaredOptions())); for (Iterator<Transform> phIt = p.iterator(); phIt.hasNext();) { final HasPhaseOptions ph = (HasPhaseOptions) phIt.next(); b.append(padVal(ph.getPhaseName(), ph.getDeclaredOptions())); } } return b.toString(); }
public soot.Body getBody(soot.SootMethod sm, String phaseName) { // JimpleBodyBuilder jbb = new JimpleBodyBuilder(); soot.jimple.JimpleBody jb = ajbb.createJimpleBody(block, formals, sm); PackManager.v().getPack("jj").apply(jb); return jb; }
/** * @param args */ public static void main(String[] args) { PackManager.v().getPack("jtp").add(new Transform("jtp.fixedie", new BodyTransformer() { @Override protected void internalTransform(Body b, String phaseName, Map<String, String> options) { for (Unit u : b.getUnits()) { Stmt s = (Stmt) u; if (s.containsInvokeExpr()) { InvokeExpr ie = s.getInvokeExpr(); if (FixedMethods.isFixed(ie)) { System.err.println("+++ " + ie); yes++; } else { System.err.println(" - " + ie); no++; } } } } })); soot.Main.main(args); System.err.println("+++ " + yes); System.err.println(" - " + no); }
private ZipOutputStream getZipOutputStream() throws IOException { if (Options.v().output_jar()) { LOGGER.info("Writing JAR to \"{}\"", Options.v().output_dir()); return PackManager.v().getJarFile(); } final String name = originalApk == null ? "out.apk" : originalApk.getName(); if (originalApk == null) { LOGGER.warn("Setting output file name to \"{}\" as original APK has not been found.", name); } final Path outputFile = Paths.get(SourceLocator.v().getOutputDir(), name); if (Files.exists(outputFile, LinkOption.NOFOLLOW_LINKS)) { if (!Options.v().force_overwrite()) { throw new CompilationDeathException("Output file \"" + outputFile + "\" exists. Not overwriting."); } try { Files.delete(outputFile); } catch (IOException exception) { throw new IllegalStateException("Removing \"" + outputFile + "\" failed. Not writing out anything.", exception); } } LOGGER.info("Writing APK to \"{}\".", outputFile); return new ZipOutputStream(Files.newOutputStream(outputFile, StandardOpenOption.CREATE_NEW)); }
public soot.Body getBody(soot.SootMethod sootMethod, String phaseName) { AnonInitBodyBuilder aibb = new AnonInitBodyBuilder(); soot.jimple.JimpleBody body = aibb.createBody(sootMethod); PackManager.v().getPack("jj").apply(body); return body; }
public Body getBody(SootMethod m, String phaseName) { JimpleBody jb = (JimpleBody) mJimpleAST.getBody(m); if (jb == null) { throw new RuntimeException("Could not load body for method " + m.getSignature()); } if (Options.v().verbose()) { logger.debug("[" + m.getName() + "] Retrieving JimpleBody from AST..."); } PackManager.v().getPack("jb").apply(jb); return jb; } }
private void registerGuard(SootMethod container, Stmt stmt, String string) { guards.add(new Guard(container, stmt, string)); if (options.verbose()) { logger.debug("Incomplete trace file: Class.forName() is called in method '" + container + "' but trace contains no information about the receiver class of this call."); if (options.guards().equals("ignore")) { logger.debug("Guarding strategy is set to 'ignore'. Will ignore this problem."); } else if (options.guards().equals("print")) { logger.debug("Guarding strategy is set to 'print'. " + "Program will print a stack trace if this location is reached during execution."); } else if (options.guards().equals("throw")) { logger.debug("Guarding strategy is set to 'throw'. Program will throw an " + "Error if this location is reached during execution."); } else { throw new RuntimeException("Invalid value for phase option (guarding): " + options.guards()); } } if (!registeredTransformation) { registeredTransformation = true; PackManager.v().getPack("wjap").add(new Transform("wjap.guards", new SceneTransformer() { @Override protected void internalTransform(String phaseName, Map<String, String> options) { for (Guard g : guards) { insertGuard(g); } } })); PhaseOptions.v().setPhaseOption("wjap.guards", "enabled"); } }
/** * @param args */ public static void main(String[] args) { PackManager.v().getPack("wjtp").add(new Transform("wjtp.ifds", new SceneTransformer() { protected void internalTransform(String phaseName, @SuppressWarnings("rawtypes") Map options) { IFDSTabulationProblem<Unit, ?, SootMethod, InterproceduralCFG<Unit, SootMethod>> problem = new IFDSPossibleTypes(new JimpleBasedInterproceduralCFG()); @SuppressWarnings({ "rawtypes", "unchecked" }) JimpleIFDSSolver<?, InterproceduralCFG<Unit, SootMethod>> solver = new JimpleIFDSSolver(problem); solver.solve(); } })); soot.Main.main(args); }
public static void main(String[] args) { PackManager.v().getPack("wjpp").add(new Transform("wjpp.inlineReflCalls", new ReflectiveCallsInliner())); Scene.v().addBasicClass(Object.class.getName()); Scene.v().addBasicClass(SootSig.class.getName(), SootClass.BODIES);
public static void main(String[] argv) { // if you do not want soot to output new class files, run with comman line option "-f n" // if you want the source code line numbers for jimple statements, use this: PackManager.v().getPack("jtp").add(new Transform("jtp.lnprinter", new LineNumberGenerator().bln)); // if you want the source code line numbers for baf instructions, use this: PackManager.v().getPack("bb").add(new Transform("bb.lnprinter", new LineNumberGenerator().bln)); soot.Main.main(argv); }
/** * @param args */ public static void main(String[] args) { PackManager.v().getPack("wjtp").add(new Transform("wjtp.narm", new DumpNumAppReachableMethods())); soot.Main.main(args); }
public static void main(String[] args) { PackManager.v().getPack("cg").add(new Transform("cg.badfields", new BadFields())); soot.Main.main(args); }
public BafBody convertJimpleBodyToBaf(SootMethod m) { JimpleBody body = (JimpleBody) m.getActiveBody().clone(); // Change // ConditionalBranchFolder.v().transform(body); // UnreachableCodeEliminator.v().transform(body); // DeadAssignmentEliminator.v().transform(body); // UnusedLocalEliminator.v().transform(body); BafBody bafBody = Baf.v().newBody(body); PackManager.v().getPack("bop").apply(bafBody); PackManager.v().getPack("tag").apply(bafBody); if (Options.v().validate()) { bafBody.validate(); } return bafBody; }
PackManager.v().getTransform("jj.ls").apply(b); PackManager.v().getTransform("jj.a").apply(b); PackManager.v().getTransform("jj.ule").apply(b); PackManager.v().getTransform("jj.ne").apply(b); PackManager.v().getTransform("jj.tr").apply(b); PackManager.v().getTransform("jj.ulp").apply(b); PackManager.v().getTransform("jj.lns").apply(b); PackManager.v().getTransform("jj.cp").apply(b); PackManager.v().getTransform("jj.dae").apply(b); PackManager.v().getTransform("jj.cp-ule").apply(b); PackManager.v().getTransform("jj.lp").apply(b); PackManager.v().getTransform("jj.uce").apply(b);
public static void main(String[] args) { CFGViewer viewer = new CFGViewer(); Transform printTransform = new Transform(phaseFullname, viewer); printTransform.setDeclaredOptions("enabled " + altClassPathOptionName + ' ' + graphTypeOptionName + ' ' + irOptionName + ' ' + multipageOptionName + ' ' + briefLabelOptionName + ' '); printTransform.setDefaultOptions( "enabled " + altClassPathOptionName + ": " + graphTypeOptionName + ':' + defaultGraph + ' ' + irOptionName + ':' + defaultIR + ' ' + multipageOptionName + ":false " + ' ' + briefLabelOptionName + ":false "); PackManager.v().getPack("jtp").add(printTransform); args = viewer.parse_options(args); if (args.length == 0) { usage(); } else { soot.Main.main(args); } }
/** * Loads the phase plugin and adds it to PackManager. * * @param pluginDescription * the plugin description instance read from configuration file. */ private static void handlePhasePlugin(final PhasePluginDescription pluginDescription) { try { final Object instance = PluginLoader.loadStrategy.create(pluginDescription.getClassName()); if (!(instance instanceof SootPhasePlugin)) { throw new RuntimeException( "The plugin class '" + pluginDescription.getClassName() + "' does not implement SootPhasePlugin."); } final SootPhasePlugin phasePlugin = (SootPhasePlugin) instance; phasePlugin.setDescription(pluginDescription); final String packName = getPackName(pluginDescription.getPhaseName()); Transform transform = new Transform(pluginDescription.getPhaseName(), phasePlugin.getTransformer()); transform.setDeclaredOptions(concat(appendEnabled(phasePlugin.getDeclaredOptions()))); transform.setDefaultOptions(concat(phasePlugin.getDefaultOptions())); PackManager.v().getPack(packName).add(transform); } catch (final ClassNotFoundException e) { throw new RuntimeException("Failed to load plugin class for " + pluginDescription + ".", e); } catch (final InstantiationException e) { throw new RuntimeException("Failed to instanciate plugin class for " + pluginDescription + ".", e); } }
coffiClass = null; PackManager.v().getPack("jb").apply(jb); return jb;