Java Reverse basis for exporting class one in memory

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.