1 19 20 package soot.xml; 21 22 import soot.*; 23 import soot.tagkit.*; 24 import java.util.*; 25 import java.io.*; 26 27 public class TagCollector { 28 29 private ArrayList attributes; 30 private ArrayList keys; 31 32 public TagCollector(){ 33 attributes = new ArrayList(); 34 keys = new ArrayList(); 35 } 36 37 public void collectTags(SootClass sc){ 38 39 40 Iterator fit = sc.getFields().iterator(); 42 while (fit.hasNext()){ 43 SootField sf = (SootField)fit.next(); 44 collectFieldTags(sf); 45 } 46 47 Iterator it = sc.getMethods().iterator(); 49 while (it.hasNext()) { 50 SootMethod sm = (SootMethod)it.next(); 51 collectMethodTags(sm); 52 53 if (!sm.hasActiveBody()) continue; 54 Body b = sm.getActiveBody(); 55 collectBodyTags(b); 56 } 57 } 58 59 public void collectKeyTags(SootClass sc){ 60 Iterator it = sc.getTags().iterator(); 61 while (it.hasNext()){ 62 Object next = it.next(); 63 if (next instanceof KeyTag){ 64 KeyTag kt = (KeyTag)next; 65 Key k = new Key(kt.red(), kt.green(), kt.blue(), kt.key()); 66 k.aType(kt.analysisType()); 67 keys.add(k); 68 } 69 } 70 } 71 72 public void printKeys(PrintWriter writerOut){ 73 Iterator it = keys.iterator(); 74 while (it.hasNext()){ 75 Key k = (Key)it.next(); 76 k.print(writerOut); 77 } 78 } 79 80 81 public void collectFieldTags(SootField sf){ 82 Iterator fTags = sf.getTags().iterator(); 83 Attribute fa = new Attribute(); 84 while (fTags.hasNext()){ 85 Tag t = (Tag)fTags.next(); 86 fa.addTag(t); 87 } 89 attributes.add(fa); 90 } 91 92 public void collectMethodTags(SootMethod sm){ 93 if (!sm.hasActiveBody()) { 94 return; 95 } 96 if (!sm.getTags().isEmpty()){ 97 Iterator mTags = sm.getTags().iterator(); 98 Attribute ma = new Attribute(); 99 while (mTags.hasNext()){ 100 Tag t = (Tag)mTags.next(); 101 ma.addTag(t); 102 } 104 attributes.add(ma); 105 } 106 107 } 108 109 public void collectBodyTags(Body b){ 110 Iterator itUnits = b.getUnits().iterator(); 111 while (itUnits.hasNext()) { 112 Unit u = (Unit)itUnits.next(); 113 Iterator itTags = u.getTags().iterator(); 114 Attribute ua = new Attribute(); 115 JimpleLineNumberTag jlnt = null; 116 while (itTags.hasNext()) { 117 Tag t = (Tag)itTags.next(); 118 ua.addTag(t); 119 if (t instanceof JimpleLineNumberTag){ 120 jlnt = (JimpleLineNumberTag)t; 121 } 122 } 124 attributes.add(ua); 125 Iterator valBoxIt = u.getUseAndDefBoxes().iterator(); 126 while (valBoxIt.hasNext()){ 127 ValueBox vb = (ValueBox)valBoxIt.next(); 128 if (!vb.getTags().isEmpty()){ 130 Iterator tagsIt = vb.getTags().iterator(); 131 Attribute va = new Attribute(); 132 while (tagsIt.hasNext()) { 133 Tag t = (Tag)tagsIt.next(); 134 va.addTag(t); 136 if (jlnt != null) { 138 va.addTag(jlnt); 139 } 140 } 141 attributes.add(va); 143 } 145 } 146 } 147 } 148 149 public void printTags(PrintWriter writerOut){ 150 151 Iterator it = attributes.iterator(); 152 while (it.hasNext()){ 153 Attribute a = (Attribute)it.next(); 154 a.print(writerOut); 156 } 157 } 158 } 159 | Popular Tags |