Modify the class file tool in other jar packages directly: Jclasslib

Source: Internet
Author: User

For some reason

Need to change the information in the other JAR package

Configuration file *.properties MANIFEST. MF these things can be directly opened with Notepad changes and then replace the OK.

Wandering the net for a long while, did not find the right method

At first I was using Jd-gui to decompile the A.class file that I needed to modify to save the code to A.java

And then compile it directly in DOS with Javac A.java.

Here's the problem.

Because A.java references a lot of other jars under the method and A.java has the package

After a half-day of tinkering, the end result: compilation does not work properly by not achieving direct modification to replace someone else's class file.

And then I wandered around the internet.

See jclasslib this thing and then tinker for a while

It's been a success. Note the step method provided to the desired friend.

Software Installation: Download the jclasslib to install (I am under the 3.0, Baidu Google a lot.)

I'm here with a gadget I wrote myself. Pojotool.jar For example

Software Open screen effect is as follows

For example, I want to modify the message that cannot be linked to the database "Sesame does not open the door!"

The steps are as follows:

1. Open the jar with Jd-gui how do I open it?

After opening, find the class file that you want to modify the prompt information here is genentity.

Find the method name that corresponds to the code that needs to be modified

I am here to include this code of cue information in method Getalldatabase () such as:

2. Use Jd-gui or WinRAR to extract the Genentity.class to C drive (directory does not matter)

3. Double-click on the Jclasslib bytecode Viewer installed on the desktop, click on the file of the software-open class file Opens the class files you just extracted

4. Click Methods--getalldatabase--code

Methods is a way of saying, needless to say.

Getalldatabase is the name of the method just found in Jd-gui.

Code contains all the information in the Getalldatabase method.

Found "Cannot open database connection, please check!"

This tool does not provide a search function here.

If there's a lot of content, then you can click Copy to clipboard the contents into a text file and then search

This is the 82nd line.

5. Click on the #34 after line 82nd to jump to the 34th constant of the constant pool constant

6. Point to the right of the CP info #362 will jump to the No. 362 constant

Here you can see string: Cannot open database connection, please check! That is, the final output of the information

7. Find the key constants for Genentity.class and now it's time to modify it.

Create a new test in eclipse to handle Genentity.class

[Java]View PlainCopy
  1. Import java.io.*;
  2. Import Org.gjt.jclasslib.io.ClassFileWriter;
  3. Import Org.gjt.jclasslib.structures.CPInfo;
  4. Import Org.gjt.jclasslib.structures.ClassFile;
  5. Import Org.gjt.jclasslib.structures.constants.ConstantUtf8Info;
  6. Public class Test {
  7. public static void Main (string[] args) throws Exception {
  8. String FilePath = "C:\\genentity.class";
  9. FileInputStream FIS = new FileInputStream (FilePath);
  10. Datainput di = new DataInputStream (FIS);
  11. Classfile CF = new Classfile ();
  12. Cf.read (DI);
  13. cpinfo[] Infos = Cf.getconstantpool ();
  14. int count = infos.length;
  15. For (int i = 0; i < count; i++) {
  16. if (infos[i]! = null) {
  17. System.out.print (i);
  18. System.out.print ("=");
  19. System.out.print (Infos[i].getverbose ());
  20. System.out.print ("=");
  21. System.out.println (Infos[i].gettagverbose ());
  22. if (i = = 362) {
  23. Constantutf8info Uinfo = (constantutf8info) infos[i];
  24. Uinfo.setbytes ("Sesame does not open the door!").     GetBytes ());
  25. Infos[i]=uinfo;
  26. }
  27. }
  28. }
  29. Cf.setconstantpool (infos);
  30. Fis.close ();
  31. File F = new file (FilePath);
  32. Classfilewriter.writetofile (f, CF);
  33. }
  34. }

It's important to note that "C:\\genentity.class" is the directory where I store class.


if (i = = 362) Here is the constant number I found in step seventh


"Sesame does not open the door!" Here is the text message I want to change!

Run Test.java will have the following message without an error, it proves normal if the error is correct then there is a problem

9. Replace the original Genentity.class with the newly modified genentity.class of the C drive.

How to replace it without me saying it.

Open the. jar with WinRAR and drag the Genentity.class into the cover.

10. Operation Effect:

Done...

Modify the class file tool in other jar packages directly: Jclasslib

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.