1 19 20 package soot.toolkits.graph.interaction; 21 22 import soot.*; 23 import soot.toolkits.graph.*; 24 import soot.jimple.toolkits.annotation.callgraph.*; 25 import java.util.*; 26 import soot.options.*; 27 28 public class InteractionHandler { 29 30 public InteractionHandler(Singletons.Global g){} 31 public static InteractionHandler v() { return G.v().soot_toolkits_graph_interaction_InteractionHandler();} 32 33 private ArrayList stopUnitList; 34 public ArrayList getStopUnitList(){ 35 return stopUnitList; 36 } 37 public void addToStopUnitList(Object elem){ 38 if (stopUnitList == null){ 39 stopUnitList = new ArrayList(); 40 } 41 stopUnitList.add(elem); 42 } 43 44 public void removeFromStopUnitList(Object elem){ 45 if (stopUnitList.contains(elem)){ 46 stopUnitList.remove(elem); 47 } 48 } 49 50 public void handleNewAnalysis(Transform t, Body b){ 51 if (PhaseOptions.getBoolean(PhaseOptions.v().getPhaseOptions( t.getPhaseName()), "enabled")){ 53 String name = t.getPhaseName()+" for method: "+b.getMethod().getName(); 54 currentPhaseName(name); 55 currentPhaseEnabled(true); 56 doneCurrent(false); 57 } 58 else { 59 currentPhaseEnabled(false); 60 setInteractThisAnalysis(false); 61 } 62 } 63 64 public void handleCfgEvent(DirectedGraph g){ 65 if (currentPhaseEnabled()){ 66 G.v().out.println("Analyzing: "+currentPhaseName()); 67 doInteraction(new InteractionEvent(IInteractionConstants.NEW_ANALYSIS, currentPhaseName())); 68 } 69 if (isInteractThisAnalysis()){ 70 doInteraction(new InteractionEvent(IInteractionConstants.NEW_CFG, g)); 71 } 72 } 73 74 public void handleStopAtNodeEvent(Object u){ 75 if (isInteractThisAnalysis()){ 76 doInteraction(new InteractionEvent(IInteractionConstants.STOP_AT_NODE, u)); 77 } 78 } 79 80 public void handleBeforeAnalysisEvent(Object beforeFlow){ 81 if (isInteractThisAnalysis()){ 82 if (autoCon()){ 83 doInteraction(new InteractionEvent(IInteractionConstants.NEW_BEFORE_ANALYSIS_INFO_AUTO, beforeFlow)); 84 } 85 else{ 86 doInteraction(new InteractionEvent(IInteractionConstants.NEW_BEFORE_ANALYSIS_INFO, beforeFlow)); 87 } 88 } 89 } 90 91 public void handleAfterAnalysisEvent(Object afterFlow){ 92 if (isInteractThisAnalysis()){ 93 if (autoCon()){ 94 doInteraction(new InteractionEvent(IInteractionConstants.NEW_AFTER_ANALYSIS_INFO_AUTO, afterFlow)); 95 } 96 else { 97 doInteraction(new InteractionEvent(IInteractionConstants.NEW_AFTER_ANALYSIS_INFO, afterFlow)); 98 } 99 } 100 } 101 102 public void handleTransformDone(Transform t, Body b){ 103 doneCurrent(true); 104 if (isInteractThisAnalysis()){ 105 doInteraction(new InteractionEvent(IInteractionConstants.DONE, null)); 106 } 107 } 108 109 public void handleCallGraphStart(Object info, CallGraphGrapher grapher){ 110 setGrapher(grapher); 111 doInteraction(new InteractionEvent(IInteractionConstants.CALL_GRAPH_START, info)); 112 if (!isCgReset()){ 113 handleCallGraphNextMethod(); 114 } 115 else { 116 setCgReset(false); 117 handleReset(); 118 } 119 } 120 121 public void handleCallGraphNextMethod(){ 122 if (!cgDone()){ 123 getGrapher().setNextMethod(getNextMethod()); 124 getGrapher().handleNextMethod(); 125 } 126 } 127 128 private boolean cgReset = false; 129 public void setCgReset(boolean v){ 130 cgReset = v; 131 } 132 public boolean isCgReset(){ 133 return cgReset; 134 } 135 136 public void handleReset(){ 137 if (!cgDone()){ 138 getGrapher().reset(); 139 } 140 } 141 142 public void handleCallGraphPart(Object info){ 143 doInteraction(new InteractionEvent(IInteractionConstants.CALL_GRAPH_PART, info)); 144 if (!isCgReset()){ 145 handleCallGraphNextMethod(); 146 } 147 else { 148 setCgReset(false); 149 handleReset(); 150 } 151 } 152 153 private CallGraphGrapher grapher; 154 private void setGrapher(CallGraphGrapher g){ 155 grapher = g; 156 } 157 private CallGraphGrapher getGrapher(){ 158 return grapher; 159 } 160 161 private SootMethod nextMethod; 162 public void setNextMethod(SootMethod m){ 163 nextMethod = m; 164 } 165 private SootMethod getNextMethod(){ 166 return nextMethod; 167 } 168 169 private synchronized void doInteraction(InteractionEvent event){ 170 getInteractionListener().setEvent(event); 171 getInteractionListener().handleEvent(); 172 173 } 174 175 public synchronized void waitForContinue(){ 176 try { 177 this.wait(); 178 } 179 catch (InterruptedException e){ 180 } 181 182 } 183 184 private boolean interactThisAnalysis; 185 public void setInteractThisAnalysis(boolean b){ 186 interactThisAnalysis = b; 187 } 188 public boolean isInteractThisAnalysis(){ 189 return interactThisAnalysis; 190 } 191 private boolean interactionCon; 192 public synchronized void setInteractionCon(){ 193 this.notify(); 194 } 195 196 public boolean isInteractionCon(){ 197 return interactionCon; 198 } 199 private IInteractionListener interactionListener; 200 public void setInteractionListener(IInteractionListener listener){ 201 interactionListener = listener; 202 } 203 public IInteractionListener getInteractionListener(){ 204 return interactionListener; 205 } 206 207 private String currentPhaseName; 208 public void currentPhaseName(String name){ 209 currentPhaseName = name; 210 } 211 public String currentPhaseName(){ 212 return currentPhaseName; 213 } 214 215 private boolean currentPhaseEnabled; 216 public void currentPhaseEnabled(boolean b){ 217 currentPhaseEnabled = b; 218 } 219 public boolean currentPhaseEnabled(){ 220 return currentPhaseEnabled; 221 } 222 223 private boolean cgDone = false; 224 public void cgDone(boolean b){ 225 cgDone = b; 226 } 227 public boolean cgDone(){ 228 return cgDone; 229 } 230 231 private boolean doneCurrent; 232 public void doneCurrent(boolean b){ 233 doneCurrent = b; 234 } 235 public boolean doneCurrent(){ 236 return doneCurrent; 237 } 238 239 private boolean autoCon; 240 public void autoCon(boolean b){ 241 autoCon = b; 242 } 243 public boolean autoCon(){ 244 return autoCon; 245 } 246 247 private boolean stopInteraction = false; 248 public void stopInteraction(boolean b){ 249 stopInteraction = b; 250 Options.v().set_interactive_mode(false); 251 } 252 253 } 254 255 | Popular Tags |