1 19 20 25 26 27 28 29 30 31 32 package soot.coffi; 33 import soot.*; 34 35 import java.io.*; 36 import java.util.StringTokenizer ; 37 import java.util.NoSuchElementException ; 38 39 43 abstract class cp_info { 44 45 public static final byte CONSTANT_Utf8 = 1; 46 public static final byte CONSTANT_Integer = 3; 47 public static final byte CONSTANT_Float = 4; 48 public static final byte CONSTANT_Long = 5; 49 public static final byte CONSTANT_Double = 6; 50 public static final byte CONSTANT_Class = 7; 51 public static final byte CONSTANT_String = 8; 52 public static final byte CONSTANT_Fieldref = 9; 53 public static final byte CONSTANT_Methodref = 10; 54 public static final byte CONSTANT_InterfaceMethodref = 11; 55 public static final byte CONSTANT_NameAndType = 12; 56 57 58 public byte tag; 59 60 63 public abstract int size(); 64 65 69 public abstract String toString(cp_info constant_pool[]); 70 71 74 public abstract String typeName(); 75 76 84 public abstract int compareTo(cp_info constant_pool[],cp_info cp, 85 cp_info cp_constant_pool[]); 86 87 88 93 public static long ints2long(long high,long low) { 94 long h,l; 95 h = high; l = low; 96 return ((h<<32) + l); 97 } 98 99 105 public static String printBits(int i) { 106 String s = ""; 107 int j,k; 108 k = 1; 109 for (j=0;j<32; j++) { 110 if ((i&k)!=0) 111 s = "1" + s; 112 else 113 s = "0" + s; 114 k = k<<1; 115 } 116 return s; 117 } 118 119 125 public static String printBits(long i) { 126 String s = ""; 127 long j,k; 128 k = 1; 129 for (j=0;j<64; j++) { 130 if ((i&k)!=0) 131 s = "1" + s; 132 else 133 s = "0" + s; 134 k = k<<1; 135 } 136 return s; 137 } 138 139 146 public static String getClassname(cp_info constant_pool[],int i) { 147 cp_info c = constant_pool[i]; 148 switch (c.tag) { 149 case cp_info.CONSTANT_Class: 150 return c.toString(constant_pool); 151 case cp_info.CONSTANT_Fieldref: 152 return getClassname(constant_pool,((CONSTANT_Fieldref_info)c).class_index); 153 case cp_info.CONSTANT_Methodref: 154 return getClassname(constant_pool,((CONSTANT_Methodref_info)c).class_index); 155 case cp_info.CONSTANT_InterfaceMethodref: 156 return getClassname(constant_pool, 157 ((CONSTANT_InterfaceMethodref_info)c).class_index); 158 } 159 G.v().out.println("Request for classname for non-class object!"); 160 return "Can't find classname. Sorry."; 161 } 162 163 170 public static String getName(cp_info constant_pool[],int i) { 171 cp_info c = constant_pool[i]; 172 switch (c.tag) { 173 case cp_info.CONSTANT_Utf8: 174 return c.toString(constant_pool); 175 case cp_info.CONSTANT_NameAndType: 176 return getName(constant_pool,((CONSTANT_NameAndType_info)c).name_index); 177 case cp_info.CONSTANT_Fieldref: 178 return getName(constant_pool,((CONSTANT_Fieldref_info)c).name_and_type_index); 179 case cp_info.CONSTANT_Methodref: 180 return getName(constant_pool,((CONSTANT_Methodref_info)c).name_and_type_index); 181 case cp_info.CONSTANT_InterfaceMethodref: 182 return getName(constant_pool, 183 ((CONSTANT_InterfaceMethodref_info)c).name_and_type_index); 184 } 185 G.v().out.println("Request for name for non-named object!"); 186 return "Can't find name of that object. Sorry."; 187 } 188 189 195 public static int countParams(cp_info constant_pool[],int m) { 196 StringTokenizer st; 197 String s = getTypeDescr(constant_pool,m); 198 s = ClassFile.parseMethodDesc_params(s); 199 st = new StringTokenizer (s,",",false); 200 return st.countTokens(); 201 } 202 203 212 public static String getTypeDescr(cp_info constant_pool[],int i) { 213 cp_info c = constant_pool[i]; 214 if (c instanceof CONSTANT_Utf8_info) 215 return c.toString(constant_pool); 216 if (c instanceof CONSTANT_NameAndType_info) 217 return getTypeDescr(constant_pool, 218 ((CONSTANT_NameAndType_info)c).descriptor_index); 219 if (c instanceof CONSTANT_Methodref_info) 220 return getTypeDescr(constant_pool, 221 ((CONSTANT_Methodref_info)c).name_and_type_index); 222 if (c instanceof CONSTANT_InterfaceMethodref_info) 223 return getTypeDescr(constant_pool, 224 ((CONSTANT_InterfaceMethodref_info)c).name_and_type_index); 225 if (c instanceof CONSTANT_Fieldref_info) 226 return getTypeDescr(constant_pool, 227 ((CONSTANT_Fieldref_info)c).name_and_type_index); 228 G.v().out.println("Invalid request for type descr!"); 229 return "Invalid type descriptor request."; 230 } 231 232 240 public static String fieldType(cp_info constant_pool[],int i) { 241 return ClassFile.parseDesc(getTypeDescr(constant_pool,i),""); 242 } 243 } 244 | Popular Tags |