1 19 20 25 26 27 package soot.jimple.parser; 28 29 import soot.jimple.parser.parser.*; 30 import soot.jimple.parser.lexer.*; 31 import soot.jimple.parser.node.*; 32 import soot.jimple.parser.analysis.*; 33 import java.io.*; 34 import soot.util.*; 35 import java.util.*; 36 37 import soot.*; 38 39 40 public class Parse 41 { 42 private static final String EXT = ".jimple"; 43 44 private static final String USAGE = "usage: java Parse [options] " + 45 "jimple_file [jimple_file ...]"; 46 47 48 54 static public SootClass parse(InputStream istream, SootClass sc) 55 { 56 Start tree = null; 57 58 Parser p = 59 new Parser(new Lexer( 60 new PushbackReader(new EscapedReader(new BufferedReader( 61 new InputStreamReader(istream))), 1024))); 62 63 try { 64 tree = p.parse(); 65 } catch(ParserException e) { 66 throw new RuntimeException ("Parser exception occurred: " + e); 67 } catch(LexerException e) { 68 throw new RuntimeException ("Lexer exception occurred: " + e); 69 } catch(IOException e) { 70 throw new RuntimeException ("IOException occurred: " + e); 71 } 72 73 Walker w; 74 if(sc == null) 75 w = new Walker(null); 76 else { 77 w = new BodyExtractorWalker(sc, null, new HashMap()); 78 } 79 80 tree.apply(w); 81 return w.getSootClass(); 82 } 83 84 85 public static void main(String args[]) 86 throws java.lang.Exception 87 88 89 { 90 boolean debug = false; 91 boolean verbose = false; 92 InputStream inFile; 93 94 if (args.length < 1) { 96 G.v().out.println(USAGE); 97 System.exit(0); 98 } 99 100 101 Scene.v().setPhantomRefs(true); 102 103 for (int i = 0; i < args.length; i++) { 104 String arg = args[i]; 105 if (arg.startsWith("-")) { 106 arg = arg.substring(1); 107 if (arg.equals("d")) 108 debug = true; 109 else if (arg.equals("v")) 110 verbose = true; 111 } 112 else { 113 114 115 try { 116 if (verbose) 117 G.v().out.println(" ... looking for " + arg); 118 inFile = new FileInputStream(arg); 119 } catch (FileNotFoundException e) { 120 if (arg.endsWith(EXT)) { 121 G.v().out.println(" *** can't find " + arg); 122 continue; 123 } 124 arg = arg + EXT; 125 try { 126 if (verbose) 127 G.v().out.println(" ... looking for " + arg); 128 inFile = new BufferedInputStream(new FileInputStream(arg)); 129 } catch (FileNotFoundException ee) { 130 G.v().out.println(" *** can't find " + arg); 131 continue; 132 } 133 } 134 135 Parser p = 136 new Parser( 137 new Lexer( 138 new PushbackReader( 139 new InputStreamReader(inFile), 1024))); 140 141 Start tree = p.parse(); 142 143 tree.apply(new Walker(null)); 144 } 145 } 146 } } 149 150 151 152 153 | Popular Tags |