Java sun.misc.Launcher$AppClassLoader 破解代码?

Java sun.misc.Launcher$AppClassLoader breaking code?

所以,我有一个类加载器 ReflectionClassLoader,我用它从不同的地方动态加载 JAR 文件,以便使用混淆代码环境。

这在我的 IDE 中运行良好,玩起来很有趣,但是当我在 Eclipse 中导出设置时,我发现我的 Class 加载程序正在由标准 URLClassLoader,还有一个sun.misc.Launcher$AppClassLoader,就这样加载了两次。由于它存储某些数据,如资源、已加载 类 等,它完全破坏了我的系统。在日食中,它们都由 sun.misc.Launcher$AppClassLoader.

加载

第二次加载似乎在加载我的自定义 URL 协议 (debugrsrc) 的地方很明显。我已经尝试获取系统 ClassLoader 并反映,但是 returns 和 sun.misc.Launcher$AppClassLoader,即使它没有在我的主要方法中返回它。

它似乎与程序的其余部分完全隔离开来。至于逃避,我正在考虑拉一些不安全的东西,尽管我更愿意让 Sun 不要乱用 ClassLoaders。

我通过以下方式解决了这个问题:

ClassLoader oscl = sun.misc.Launcher.getLauncher().getClassLoader();
Field scl = ClassLoader.class.getDeclaredField("scl");
scl.setAccessible(true);
scl.set(null, oscl);
//reflect my real main method here, dont actually call the code because the system classloader will preload it.