1 19 20 25 26 package soot.jimple.parser; 27 import soot.options.*; 28 29 import soot.baf.*; 30 import soot.*; 31 import soot.jimple.*; 32 33 import soot.jimple.parser.parser.*; 34 import soot.jimple.parser.lexer.*; 35 import soot.jimple.parser.node.*; 36 import soot.jimple.parser.analysis.*; 37 38 import java.io.*; 39 import java.util.*; 40 41 42 49 50 51 52 public class BodyExtractorWalker extends Walker 53 { 54 Map methodToParsedBodyMap; 55 56 58 public BodyExtractorWalker(SootClass sc, SootResolver resolver, Map methodToParsedBodyMap) 59 { 60 super(sc, resolver); 61 this.methodToParsedBodyMap = methodToParsedBodyMap; 62 } 63 64 68 public void caseAFile(AFile node) 69 { 70 inAFile(node); 71 { 72 Object temp[] = node.getModifier().toArray(); 73 for(int i = 0; i < temp.length; i++) 74 { 75 ((PModifier) temp[i]).apply(this); 76 } 77 } 78 if(node.getFileType() != null) 79 { 80 node.getFileType().apply(this); 81 } 82 if(node.getClassName() != null) 83 { 84 node.getClassName().apply(this); 85 } 86 87 String className = (String ) mProductions.removeLast(); 88 if(!className.equals(mSootClass.getName())) 89 throw new RuntimeException ("expected: " + className + ", but got: " + mSootClass.getName()); 90 91 if(node.getExtendsClause() != null) 92 { 93 node.getExtendsClause().apply(this); 94 } 95 if(node.getImplementsClause() != null) 96 { 97 node.getImplementsClause().apply(this); 98 } 99 if(node.getFileBody() != null) 100 { 101 node.getFileBody().apply(this); 102 } 103 outAFile(node); 104 } 105 106 public void outAFile(AFile node) 107 { 108 if(node.getImplementsClause() != null) 109 mProductions.removeLast(); 111 if(node.getExtendsClause() != null) 112 mProductions.removeLast(); 114 mProductions.removeLast(); mProductions.addLast(mSootClass); 116 } 117 118 119 124 public void outAFieldMember(AFieldMember node) 125 { 126 mProductions.removeLast(); mProductions.removeLast(); } 129 130 public void outAMethodMember(AMethodMember node) 131 { 132 int modifier = 0; 133 Type type; 134 String name; 135 List parameterList = new ArrayList(); 136 List throwsClause = null; 137 JimpleBody methodBody = null; 138 139 if(node.getMethodBody() instanceof AFullMethodBody) 140 methodBody = (JimpleBody) mProductions.removeLast(); 141 142 if(node.getThrowsClause() != null) 143 throwsClause = (List) mProductions.removeLast(); 144 145 if(node.getParameterList() != null) 146 parameterList = (List) mProductions.removeLast(); 147 148 name = (String ) mProductions.removeLast(); type = (Type) mProductions.removeLast(); SootMethod sm = null; 151 if (mSootClass.declaresMethod(SootMethod.getSubSignature(name, parameterList, type))) 152 { 153 sm = mSootClass.getMethod(SootMethod.getSubSignature(name, parameterList, type)); 154 if (Options.v().verbose()) 155 G.v().out.println("[Jimple parser] " + SootMethod.getSubSignature(name, parameterList, type)); 156 } 157 else 158 { 159 G.v().out.println("[!!! Couldn't parse !!] " + SootMethod.getSubSignature(name, parameterList, type)); 160 161 162 G.v().out.println("[!] Methods in class are:"); 163 Iterator it = mSootClass.methodIterator(); 164 while(it.hasNext()) { 165 SootMethod next = (SootMethod) it.next(); 166 G.v().out.println(next.getSubSignature()); 167 } 168 169 } 170 171 if(sm.isConcrete()) 172 { 173 if (Options.v().verbose()) 174 G.v().out.println("[Parsed] "+sm.getDeclaration()); 175 176 methodBody.setMethod(sm); 177 methodToParsedBodyMap.put(sm, methodBody); 178 } 179 else if(node.getMethodBody() instanceof AFullMethodBody) { 180 if(sm.isPhantom() && Options.v().verbose()) 181 G.v().out.println("[jimple parser] phantom method!"); 182 throw new RuntimeException ("Impossible: !concrete => ! instanceof " + sm.getName() ); 183 } 184 } 185 186 } 187 | Popular Tags |