// This method is deprecated. Use soot.util.JasminOutputStream instead. public void writeXXXDeprecated(SootClass cl, String outputDir) { String outputDirWithSep = ""; if (!outputDir.equals("")) outputDirWithSep = outputDir + fileSeparator; try { File tempFile = new File(outputDirWithSep + cl.getName() + ".jasmin"); FileOutputStream streamOut = new FileOutputStream(tempFile); PrintWriter writerOut = new PrintWriter(new EscapedWriter(new OutputStreamWriter(streamOut))); if (cl.containsBafBody()) new soot.baf.JasminClass(cl).print(writerOut); else new soot.jimple.JasminClass(cl).print(writerOut); writerOut.close(); if (Options.v().time()) Timers.v().assembleJasminTimer.start(); // Invoke jasmin { String[] args; if (outputDir.equals("")) { args = new String[1]; args[0] = cl.getName() + ".jasmin"; } else { args = new String[3]; args[0] = "-d"; args[1] = outputDir; args[2] = outputDirWithSep + cl.getName() + ".jasmin"; } jasmin.Main.main(args); } tempFile.delete(); if (Options.v().time()) Timers.v().assembleJasminTimer.end(); } catch (IOException e) { throw new RuntimeException("Could not produce new classfile! (" + e + ")"); } }
/** * Prints out the method corresponding to b Body, (declaration and body), in the textual format * corresponding to the IR used to encode b body. * * @param out a PrintWriter instance to print to. */ public void printTo(Body b, PrintWriter out) { b.validate(); boolean isPrecise = !useAbbreviations(); String decl = b.getMethod().getDeclaration(); out.println(" " + decl); // incJimpleLnNum(); // only print tags if not printing attributes in a file if (!addJimpleLn()) { /*for( Iterator tIt = b.getMethod().getTags().iterator(); tIt.hasNext(); ) { final Tag t = (Tag) tIt.next(); out.println(t); incJimpleLnNum(); }*/ } if (addJimpleLn()) { setJimpleLnNum(addJimpleLnTags(getJimpleLnNum(), b.getMethod())); // G.v().out.println("added jimple ln tag for method: "+b.getMethod().toString()+" // "+b.getMethod().getDeclaringClass().getName()); } out.println(" {"); incJimpleLnNum(); UnitGraph unitGraph = new soot.toolkits.graph.BriefUnitGraph(b); LabeledUnitPrinter up; if (isPrecise) up = new NormalUnitPrinter(b); else up = new BriefUnitPrinter(b); if (addJimpleLn()) { up.setPositionTagger(new AttributesUnitPrinter(getJimpleLnNum())); } printLocalsInBody(b, up); printStatementsInBody(b, out, up, unitGraph); out.println(" }"); incJimpleLnNum(); }
public void printTo(SootClass cl, PrintWriter out) { // add jimple line number tags setJimpleLnNum(1); // Print class name + modifiers { StringTokenizer st = new StringTokenizer(Modifier.toString(cl.getModifiers())); while (st.hasMoreTokens()) { String tok = (String) st.nextToken(); if (cl.isInterface() && tok.equals("abstract")) continue; out.print(tok + " "); } String classPrefix = ""; if (!cl.isInterface()) { classPrefix = classPrefix + " class"; classPrefix = classPrefix.trim(); } out.print(classPrefix + " " + Scene.v().quotedNameOf(cl.getName()) + ""); } // Print extension { if (cl.hasSuperclass()) out.print(" extends " + Scene.v().quotedNameOf(cl.getSuperclass().getName()) + ""); } // Print interfaces { Iterator interfaceIt = cl.getInterfaces().iterator(); if (interfaceIt.hasNext()) { out.print(" implements "); out.print("" + Scene.v().quotedNameOf(((SootClass) interfaceIt.next()).getName()) + ""); while (interfaceIt.hasNext()) { out.print(","); out.print(" " + Scene.v().quotedNameOf(((SootClass) interfaceIt.next()).getName()) + ""); } } } out.println(); incJimpleLnNum(); /* if (!addJimpleLn()) { Iterator clTagsIt = cl.getTags().iterator(); while (clTagsIt.hasNext()) { final Tag t = (Tag)clTagsIt.next(); out.println(t); } }*/ out.println("{"); incJimpleLnNum(); if (Options.v().print_tags_in_output()) { Iterator cTagIterator = cl.getTags().iterator(); while (cTagIterator.hasNext()) { Tag t = (Tag) cTagIterator.next(); out.print("/*"); out.print(t.toString()); out.println("*/"); } } // Print fields { Iterator fieldIt = cl.getFields().iterator(); if (fieldIt.hasNext()) { while (fieldIt.hasNext()) { SootField f = (SootField) fieldIt.next(); if (f.isPhantom()) continue; if (Options.v().print_tags_in_output()) { Iterator fTagIterator = f.getTags().iterator(); while (fTagIterator.hasNext()) { Tag t = (Tag) fTagIterator.next(); out.print("/*"); out.print(t.toString()); out.println("*/"); } } out.println(" " + f.getDeclaration() + ";"); if (addJimpleLn()) { setJimpleLnNum(addJimpleLnTags(getJimpleLnNum(), f)); } // incJimpleLnNum(); } } } // Print methods { Iterator methodIt = cl.methodIterator(); if (methodIt.hasNext()) { if (cl.getMethodCount() != 0) { out.println(); incJimpleLnNum(); } while (methodIt.hasNext()) { SootMethod method = (SootMethod) methodIt.next(); if (method.isPhantom()) continue; if (!Modifier.isAbstract(method.getModifiers()) && !Modifier.isNative(method.getModifiers())) { if (!method.hasActiveBody()) throw new RuntimeException("method " + method.getName() + " has no active body!"); else if (Options.v().print_tags_in_output()) { Iterator mTagIterator = method.getTags().iterator(); while (mTagIterator.hasNext()) { Tag t = (Tag) mTagIterator.next(); out.print("/*"); out.print(t.toString()); out.println("*/"); } } printTo(method.getActiveBody(), out); if (methodIt.hasNext()) { out.println(); incJimpleLnNum(); } } else { if (Options.v().print_tags_in_output()) { Iterator mTagIterator = method.getTags().iterator(); while (mTagIterator.hasNext()) { Tag t = (Tag) mTagIterator.next(); out.print("/*"); out.print(t.toString()); out.println("*/"); } } out.print(" "); out.print(method.getDeclaration()); out.println(";"); incJimpleLnNum(); if (methodIt.hasNext()) { out.println(); incJimpleLnNum(); } } } } } out.println("}"); incJimpleLnNum(); }