Why this is needed, as mentioned in the previous blog post, in order to increase the difficulty of the reverse, some of the software will hide some of the key methods and classes, so we need to take this class out of memory.
This article introduces the method of using Javaagent, the next one introduces Dumpclass, the two methods have pros and cons.
This article needs to use the third-party jar as: Javassist-3.20.0-ga.jar, but what we need is its source code Javassist-3.20.0-ga-sources.jar
Create a new project named Dumpclassagent, the project structure is as follows
Copy the downloaded source to the SRC directory
Dumpclassagent.java File Contents
Package Com.vvvtimes.demo.agent;import Java.lang.instrument.instrumentation;public class Dumpclassagent {public static void Premain (String agentops, Instrumentation inst) {try {Inst.addtransformer (New Dumpclasstransformer ());} catch (Exception e) {e.printstacktrace ();}}}
Dumpclasstransformer.java File Contents
package com.vvvtimes.demo.agent;import java.io.bytearrayinputstream;import Java.lang.instrument.classfiletransformer;import java.lang.instrument.illegalclassformatexception;import java.security.protectiondomain;import javassist. Classpool;import javassist. Ctclass;public class dumpclasstransformer implements classfiletransformer {private static classpool pool;static {pool = classpool.getdefault ();} @Overridepublic byte[] transform (classloader loader, string classname, class< ? > classbeingredefined,protectiondomain protectiondomain, byte[] classfilebuffer) Throws illegalclassformatexception {system.out.println (ClassName);try {if ("com/vvvtimes/ Bean/employee ". Equals (ClassName)) {ctclass ctclass = pool.makeclass (new Bytearrayinputstream (Classfilebuffer), false); Ctclass.writefile ("e:\\");}} catch (exception e) {e.printstacktrace ();} Return null;}}
MANIFEST. MF File contents
Manifest-version:1.0premain-class:com.vvvtimes.demo.agent.dumpclassagentcan-redefine-classes:true
Package files into Dumpclassagent.jar
Export the code in the blog post of the dynamically generated class to run the jar, named Dynamicgenerateclass.jar
Put to the same directory execute command
Java-javaagent:dumpclassagent.jar-jar Dynamicgenerateclass.jar
The e-drive will generate the corresponding class
The source code can be obtained by Jd-gui anti-compilation.
Java Reverse basis for exporting class one in memory