1 29 package com.yworks.yguard.obf; 30 31 import java.io.*; 32 import java.lang.reflect.*; 33 import java.util.*; 34 import com.yworks.yguard.obf.classfile.*; 35 36 42 public class TreeItem 43 { 44 46 47 protected boolean isSynthetic; protected int access; protected ClassTree classTree = null; protected TreeItem parent = null; protected String sep = ClassFile.SEP_REGULAR; private String inName = null; private String outName = null; private boolean isFixed = false; private boolean isFromScript = false; private boolean isFromScriptMap = false; 59 60 62 63 public static boolean isNRMatch(String pattern, String string) { 64 Enumeration enum1, enum2; 65 try { 66 for (enum1 = ClassTree.getNameEnum(pattern), 67 enum2 = ClassTree.getNameEnum(string); 68 enum1.hasMoreElements() && enum2.hasMoreElements(); ) { 69 Cons nameSegment1 = (Cons)enum1.nextElement(); 70 char tag1 = ((Character )nameSegment1.car).charValue(); 71 String name1 = (String )nameSegment1.cdr; 72 Cons nameSegment2 = (Cons)enum2.nextElement(); 73 char tag2 = ((Character )nameSegment2.car).charValue(); 74 String name2 = (String )nameSegment2.cdr; 75 if (tag1 != tag2 || !isMatch(name1, name2)) { 76 return false; 77 } 78 } 79 if (enum1.hasMoreElements() || enum2.hasMoreElements()) { 80 return false; 81 } 82 } catch (Exception e) { 83 return false; 84 } 85 return true; 86 } 87 88 89 public static boolean isMatch(String pattern, String string) { 90 if (pattern == null || string == null) { 92 return false; 93 } 94 95 97 if (pattern.indexOf('*') == -1) { 99 return pattern.equals(string); 100 } 101 102 int pos = -1; 104 if (pattern.charAt(0) != '*') { 105 pos = pattern.indexOf('*'); 106 String head = pattern.substring(0, pos); 107 if (string.length() < head.length()) { 108 return false; 109 } 110 if (!string.substring(0, head.length()).equals(head)) { 111 return false; 112 } else { 113 pattern = pattern.substring(pos); 114 string = string.substring(pos); 115 } 116 } 117 118 120 if (pattern.charAt(pattern.length() - 1) != '*') { 122 pos = pattern.lastIndexOf('*'); 123 String tail = pattern.substring(pos + 1); 124 if (string.length() < tail.length()) { 125 return false; 126 } 127 if (!string.substring(string.length() - tail.length()).equals(tail)) { 128 return false; 129 } else { 130 pattern = pattern.substring(0, pos + 1); 131 string = string.substring(0, string.length() - tail.length()); 132 } 133 } 134 135 137 Vector section = new Vector(); 139 pos = pattern.indexOf('*'); 140 int rpos = -1; 141 while ((rpos = pattern.indexOf('*', pos+1)) != -1) { 142 if (rpos != pos + 1) { 143 section.addElement(pattern.substring(pos + 1, rpos)); 144 } 145 pos = rpos; 146 } 147 for (Enumeration enumeration = section.elements(); enumeration.hasMoreElements(); ) { 149 String chunk = (String )enumeration.nextElement(); 150 pos = string.indexOf(chunk); 152 if (pos == -1) { 153 return false; 154 } 155 string = string.substring(pos + chunk.length()); 156 } 157 return true; 158 } 159 160 161 163 public TreeItem(TreeItem parent, String name) 164 { 165 this.parent = parent; 166 this.inName = name; 167 if (parent != null) 168 { 169 classTree = parent.classTree; 170 } 171 } 172 173 174 public int getModifiers() {return access;} 175 176 177 public String getInName() {return inName;} 178 179 180 public void setOutName(String outName) 181 { 182 this.outName = outName; 188 isFixed = true; 189 } 190 191 192 public String getOutName() {return outName != null ? outName : inName;} 193 194 195 public String getObfName() {return outName;} 196 197 198 public void setFromScript() {isFromScript = true;} 199 200 201 public void setFromScriptMap() {isFromScriptMap = true;} 202 203 204 public boolean isFixed() {return isFixed;} 205 206 207 public boolean isFromScript() {return isFromScript;} 208 209 210 public boolean isFromScriptMap() {return isFromScriptMap;} 211 212 213 public boolean isSynthetic() {return isSynthetic;} 214 215 216 public void setParent(TreeItem parent) {this.parent = parent;} 217 218 219 public TreeItem getParent() {return parent;} 220 221 222 public String getFullInName() 223 { 224 if (parent == null) 225 { 226 return ""; 227 } 228 else if (parent.parent == null) 229 { 230 return getInName(); 231 } 232 else 233 { 234 return parent.getFullInName() + sep + getInName(); 235 } 236 } 237 238 239 public String getFullOutName() 240 { 241 if (parent == null) 242 { 243 return ""; 244 } 245 else if (parent.parent == null) 246 { 247 return getOutName(); 248 } 249 else 250 { 251 return parent.getFullOutName() + sep + getOutName(); 252 } 253 } 254 } 255 | Popular Tags |