1 package club.wpia.gigi.localisation;
3 import java.util.regex.Matcher;
4 import java.util.regex.Pattern;
6 import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
8 public class TaintSource {
10 private String pack, cls, meth;
14 private TaintSource maskOnly;
16 public TaintSource(String pack, String cls, String meth, int tgt) {
17 this(pack, cls, meth, tgt, null);
20 public TaintSource(String pack, String cls, String meth, int tgt, TaintSource maskOnly) {
25 this.maskOnly = maskOnly;
29 public TaintSource(MethodBinding mb) {
30 pack = new String(mb.declaringClass.qualifiedPackageName());
31 cls = new String(mb.declaringClass.qualifiedSourceName());
32 meth = new String(mb.readableName());
36 public int hashCode() {
39 result = prime * result + ((cls == null) ? 0 : cls.hashCode());
40 result = prime * result + ((meth == null) ? 0 : meth.hashCode());
41 result = prime * result + ((pack == null) ? 0 : pack.hashCode());
46 public String toString() {
47 StringBuffer res = new StringBuffer();
48 res.append("new TaintSource(");
49 res.append("\"" + pack + "\",");
50 res.append("\"" + cls + "\",");
51 res.append("\"" + meth + "\",0);");
52 return res.toString();
55 public String toConfLine() {
56 return pack + " " + cls + "." + meth + "," + tgt + (maskOnly == null ? "" : "=>" + maskOnly.toConfLine());
60 public boolean equals(Object obj) {
67 if (getClass() != obj.getClass()) {
70 TaintSource other = (TaintSource) obj;
72 if (other.cls != null) {
75 } else if ( !cls.equals(other.cls)) {
79 if (other.pack != null) {
82 } else if ( !pack.equals(other.pack)) {
86 if (other.meth != null) {
89 } else if ( !meth.equals(other.meth)) {
95 public static TaintSource parseTaint(String confline) {
96 // Pattern matches "Taint-lines"
97 // first part is package name up to space (may not include space or
99 // second part is Class name [with inner class name] (may not include
100 // "=" but may include ".")
101 // third part is method name including params (may not include "=" or
103 // fourth is index of tainted argument (seperated by "," from the rest)
104 Pattern p = Pattern.compile("^([^= ]*) ([^=]*)\\.([^=.]*\\([^)]*\\)),([0-9]+)");
105 Matcher m = p.matcher(confline);
107 throw new Error(confline);
109 String pack = m.group(1);
110 String cls = m.group(2);
111 String meth = m.group(3);
112 int tgt = Integer.parseInt(m.group(4));
113 TaintSource mask = null;
114 if (m.end() != confline.length()) {
115 String s = confline.substring(m.end(), m.end() + 2);
116 if ( !s.equals("=>")) {
117 throw new Error("malformed");
119 mask = parseTaint(confline.substring(m.end() + 2));
121 return new TaintSource(pack, cls, meth, tgt, mask);
124 public TaintSource getMaskOnly() {
128 public int getTgt() {