1 package org.cacert.gigi.localisation;
2 import java.util.regex.Matcher;
3 import java.util.regex.Pattern;
5 import org.eclipse.jdt.internal.compiler.lookup.MethodBinding;
7 public class TaintSource {
8 private String pack, cls, meth;
10 private TaintSource maskOnly;
12 public TaintSource(String pack, String cls, String meth, int tgt) {
13 this(pack, cls, meth, tgt, null);
15 public TaintSource(String pack, String cls, String meth, int tgt,
16 TaintSource maskOnly) {
21 this.maskOnly = maskOnly;
24 public TaintSource(MethodBinding mb) {
25 pack = new String(mb.declaringClass.qualifiedPackageName());
26 cls = new String(mb.declaringClass.qualifiedSourceName());
27 meth = new String(mb.readableName());
30 public int hashCode() {
33 result = prime * result + ((cls == null) ? 0 : cls.hashCode());
34 result = prime * result + ((meth == null) ? 0 : meth.hashCode());
35 result = prime * result + ((pack == null) ? 0 : pack.hashCode());
39 public String toString() {
40 StringBuffer res = new StringBuffer();
41 res.append("new TaintSource(");
42 res.append("\"" + pack + "\",");
43 res.append("\"" + cls + "\",");
44 res.append("\"" + meth + "\",0);");
45 return res.toString();
47 public String toConfLine() {
48 return pack + " " + cls + "." + meth + "," + tgt
49 + (maskOnly == null ? "" : "=>" + maskOnly.toConfLine());
52 public boolean equals(Object obj) {
59 if (getClass() != obj.getClass()) {
62 TaintSource other = (TaintSource) obj;
64 if (other.cls != null) {
67 } else if (!cls.equals(other.cls)) {
71 if (other.pack != null) {
74 } else if (!pack.equals(other.pack)) {
78 if (other.meth != null) {
81 } else if (!meth.equals(other.meth)) {
86 public static TaintSource parseTaint(String confline) {
87 // Pattern matches "Taint-lines"
88 // first part is package name up to space (may not include space or equals sign)
89 // second part is Class name [with inner class name] (may not include "=" but may include ".")
90 // third part is method name including params (may not include "=" or ".")
91 // fourth is index of tainted argument (seperated by "," from the rest)
93 .compile("^([^= ]*) ([^=]*)\\.([^=.]*\\([^)]*\\)),([0-9]+)");
94 Matcher m = p.matcher(confline);
96 throw new Error(confline);
98 String pack = m.group(1);
99 String cls = m.group(2);
100 String meth = m.group(3);
101 int tgt = Integer.parseInt(m.group(4));
102 TaintSource mask = null;
103 if (m.end() != confline.length()) {
104 String s = confline.substring(m.end(), m.end() + 2);
105 if (!s.equals("=>")) {
106 throw new Error("malformed");
108 mask = parseTaint(confline.substring(m.end() + 2));
110 return new TaintSource(pack, cls, meth, tgt, mask);
112 public TaintSource getMaskOnly() {
115 public int getTgt() {