Created
October 11, 2011 13:08
-
-
Save anonymous/1278024 to your computer and use it in GitHub Desktop.
Java encryption classloader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 2011-10-11 14:59:58.401:WARN::FAILED encodingFilter: java.lang.IllegalStateException: class org.springframework.web.filter.CharacterEncodingFilter is not a javax.servlet.Filter | |
| 2011-10-11 14:59:58.402:WARN::Failed startup of context o.e.j.w.WebAppContext{/server,[file:/home/astral/workz/protection/classloading/server/target/server-0.0.0-SNAPSHOT/, jar:file:/home/astral/workz/protection/classloading/server/target/server-0.0.0-SNAPSHOT/WEB-INF/lib/south-street-1.0.1.jar!/META-INF/resources/, jar:file:/home/astral/workz/protection/classloading/server/target/server-0.0.0-SNAPSHOT/WEB-INF/lib/jsf-impl-2.1.2.jar!/META-INF/resources/, jar:file:/home/astral/workz/protection/classloading/server/target/server-0.0.0-SNAPSHOT/WEB-INF/lib/primefaces-3.0.M3.jar!/META-INF/resources/]},/home/astral/workz/protection/classloading/server/target/server-0.0.0-SNAPSHOT.war | |
| java.lang.IllegalStateException: class org.springframework.web.filter.CharacterEncodingFilter is not a javax.servlet.Filter | |
| at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:78) | |
| at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58) | |
| at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:742) | |
| at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:245) | |
| at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1208) | |
| at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:586) | |
| at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:449) | |
| at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58) | |
| at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:36) | |
| at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:180) | |
| at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:482) | |
| at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:135) | |
| at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:137) | |
| at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:50) | |
| at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:601) | |
| at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:531) | |
| at org.eclipse.jetty.util.Scanner.scan(Scanner.java:394) | |
| at org.eclipse.jetty.util.Scanner.doStart(Scanner.java:329) | |
| at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58) | |
| at org.eclipse.jetty.deploy.providers.ScanningAppProvider.doStart(ScanningAppProvider.java:114) | |
| at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58) | |
| at org.eclipse.jetty.deploy.DeploymentManager.startAppProvider(DeploymentManager.java:543) | |
| at org.eclipse.jetty.deploy.DeploymentManager.doStart(DeploymentManager.java:218) | |
| at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58) | |
| at org.eclipse.jetty.util.component.AggregateLifeCycle.doStart(AggregateLifeCycle.java:41) | |
| at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:50) | |
| at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:90) | |
| at org.eclipse.jetty.server.Server.doStart(Server.java:258) | |
| at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58) | |
| at org.eclipse.jetty.xml.XmlConfiguration$1.run(XmlConfiguration.java:1197) | |
| at java.security.AccessController.doPrivileged(Native Method) | |
| at org.eclipse.jetty.xml.XmlConfiguration.main(XmlConfiguration.java:1120) | |
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) | |
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) | |
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) | |
| at java.lang.reflect.Method.invoke(Method.java:616) | |
| at org.eclipse.jetty.start.Main.invokeMain(Main.java:469) | |
| at org.eclipse.jetty.start.Main.start(Main.java:612) | |
| at org.eclipse.jetty.start.Main.parseCommandLine(Main.java:265) | |
| at org.eclipse.jetty.start.Main.main(Main.java:79) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class WebAppClassLoaderEnc extends WebAppClassLoader { | |
| public WebAppClassLoaderEnc(ClassLoader parent, Context context) throws IOException { | |
| super(parent, context); | |
| } | |
| public WebAppClassLoaderEnc(Context context) throws IOException { | |
| super(context); | |
| } | |
| @Override | |
| public Class<?> loadClass(final String name, final boolean resolve) | |
| throws ClassNotFoundException { | |
| Class c = null; | |
| c = findLoadedClass(name); | |
| if (c == null) { | |
| Class parentsVersion = null; | |
| try { | |
| parentsVersion = getParent().loadClass(name); | |
| if (parentsVersion.getClassLoader() != getParent()) | |
| c = parentsVersion; | |
| } catch (ClassNotFoundException ignore) { | |
| } catch (ClassFormatError ignore) { | |
| } | |
| if (c == null) { | |
| try { | |
| c = this.findClass(name); | |
| } catch (ClassNotFoundException ignore) { | |
| c = parentsVersion; | |
| } | |
| } | |
| } | |
| if (c == null) | |
| throw new ClassNotFoundException(name); | |
| if (resolve) | |
| resolveClass(c); | |
| return c; | |
| } | |
| @Override | |
| public Class<?> loadClass(String name) throws ClassNotFoundException { | |
| return this.loadClass(name, false); | |
| } | |
| @Override | |
| protected Class<?> findClass(final String name) throws ClassNotFoundException { | |
| String classResource = name.replace('.', '/') + ".classx"; | |
| URL classURL = getResource(classResource); | |
| if (classURL == null) { | |
| classResource = name.replace('.', '/') + ".class"; | |
| classURL = getResource(classResource); | |
| } | |
| try { | |
| InputStream in = null; | |
| in = classURL.openStream(); | |
| final byte[] classBytes = readFully(in); | |
| System.out.println(classBytes); | |
| // "decrypt": | |
| if (classResource.endsWith("x")) | |
| crypt(classBytes); | |
| Class result = this.defineClass(name, classBytes, 0, classBytes.length); | |
| return result; | |
| } catch (IOException ex) { | |
| Logger.getLogger(WebAppClassLoaderEnc.class.getName()).log(Level.SEVERE, null, ex); | |
| } | |
| return null; | |
| } | |
| private static void crypt(final byte[] data) { | |
| for (int i = 16; i < data.length; ++i) | |
| data[i] ^= 0x5A; | |
| } | |
| private static byte[] readFully(final InputStream in) throws IOException { | |
| final ByteArrayOutputStream buf1 = new ByteArrayOutputStream(); | |
| final byte[] buf2 = new byte[8 * 1024]; | |
| for (int read; (read = in.read(buf2)) > 0;) { | |
| buf1.write(buf2, 0, read); | |
| } | |
| return buf1.toByteArray(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment