我正在尝试访问加载到内存中的 java 包并将其转储到文件中。安全性的工作原理如下:有一个用 Themida 打包的 exe,其中包含要加载的 java 主类代码。在运行时,Themida exe 将干净的主类 java 代码加载到内存中。该软件的结构是加载程序包含在 exe 中,但多个外部库可以访问 exe 中包含的包。因此,exe 包含 com.mysoft.mainloader。但是干净的jar库Mylib.jar可以调用com.mysoft.mainloader中的函数。如何将 com.mysoft.mainloader 转储到 jar 文件?我可以修改 Mylib.jar 以转储它,因为它在加载后也可以访问该包吗?
I am trying to access a java package loaded into memory and dump it to a file. Here is how the security works: there is an exe packed with Themida that contains the java main class code to be loaded. At runtime the Themida exe loads the clean main class java code into memory. The software is structured with the loader being contained within the exe, but several external libraries can access the packages contained within the exe. So, exe contains com.mysoft.mainloader. But the clean jar library Mylib.jar can call functions within com.mysoft.mainloader. How to I dump com.mysoft.mainloader to a jar file? Can I modify Mylib.jar to dump it as it has access to the package once it is loaded as well?
发布评论
评论(2)
没有受支持的 Java SE 机制来读取/检索已由类加载器加载的“.class”。因此,您的选择是:
在类加载器调用
defineClass
之前(或之后)修改您用来捕获“.class”的自定义类加载器。深入研究 JVM 数据结构,尝试找出整个“.class”流是否在某处捕获,然后检索它。
修改JVM...
其中任何一个都是可行的。所有都会相对困难。
There is no supported Java SE mechanism to read / retrieve a ".class" that has been loaded by a classloader. So your options would be:
Modify the custom classloader you are using to capture the ".class" before (or after) the classloader calls
defineClass
.Burrow into the JVM data structures to try and figure out whether the entire ".class" stream is captured somewhere and then retrieve it.
Modify the JVM ...
Any of these could be feasible. All will be relatively difficult.
可以使用 instrumentation api 。
这个想法是将Java代理注入运行应用程序。
代理商使用
instruntion.getAllloadedClasses
方法,然后使用 。可以在
用法:
其中
< pid>
是目标JVM应用程序的进程ID;mainloader.jar
是输出文件名;com.mysoft.mainloader
是要提取的类的名称前缀。It is possible to get loaded classes in runtime using Dynamic Attach and Instrumentation API.
The idea is to inject a Java Agent into the running application.
The agent gets an array of all loaded classes with
Instrumentation.getAllLoadedClasses
method, then gets their bytecode usingInstrumentation.retransformClasses
.The working implementation can be found in the class-file-extractor project.
Usage:
where
<pid>
is the process ID of the target JVM application;mainloader.jar
is the output file name;com.mysoft.mainloader
is the name prefix of the classes to extract.