1

I was trying to patch an application, but the application is required to exact same class size as the original one but editing class file with JByteMod, Recaf or whatsoever always changes the class file size. Is it possible to patch class file without changing its size? I have one older patch which I got from Internet & its have the exact same thing.

I was trying to patch the application by putting static byte array instead of the private static byte (to bypass some restriction).

How can I do this without changing the size of the class file? The jar file is required Java 9.0.4 to run & I have tried JBE bytecode deitor: http://set.ee/jbe/ but it was not able to open the class file.

The older version crack & original file comparison

Unmodified private bytes

Want to change to array byte like this

2

Can you post the classfile, as well as the changes you want made to it? Depending on the changes, it should be possible. Obviously if you want to add a lot of new code or data, that won't be possible without changing the size, unless you delete a corresponding about of existing code from the classfile.

Anyway, Krakatau is capable of editing a classfile without changing the size. In particular, if you disassemble a classfile in roundtrip mode and reassemble it without modification, you'll get the exact classfile back. However, it still requires knowledge of bytecode and the classfile format to understand which changes you can make without affecting the size, or which things to delete to balance out increases in size.

That being said, this is likely not a fruitful approach. If the jar is checking classfile size, it is likely doing other integrity checks as well. Your best bet is to just find the integrity checks and remove them.

  • Here is the link to those class files - www80.zippyshare.com/v/TsPZe3M8/file.html I need to delete the private static bytes & include new array bytes. The old already patch file is also there which bytes need to replicate in the new classes. My request to you please let me know how can I change it by myself so that I can do it in later onwards. – sks15 Jun 3 '18 at 14:08
  • What bytes do you need to add? I can see if I can do it and then post step by step how I did it. – Antimony Jun 4 '18 at 2:34
  • Thanks for your suggestion to use Krakatau & I disassemble the class files & done the changes & then assemble the file again. It works for only one class file. Though the other two class file changes the file size. I have noticed one thing that disassembling original class file with "Krakatau" & assemble it back make the changes. & running it with "javap -c" shows lots of difference. Attachment link - [www7.zippyshare.com/v/diNNVsTz/file.html] – sks15 Jun 4 '18 at 12:28
  • @Subhashish The default settings are designed for convenience. If you want to ensure there are no changes at the binary level, use -roundtrip when disassembling. – Antimony Jun 4 '18 at 16:53
  • Your suggestion solved the problem. Thank you. The program is working fine now but after 20min the software crash automatically, because heap dump shows memory leak but I don't able to fix it. can you please take a look at this program & rectify the issue if possible. I'll be highly thankful to you. Link - www25.zippyshare.com/v/i6aYoIso/file.html – sks15 Jun 5 '18 at 11:25
1

Depending on your use case and how you are running your jar file, if you can run the file you may want to create a java agent that hooks into your JVM (java -jar -javaagent:YourAgent.jar Target.jar) and you could use ASM or Javassist libraries to alter the byte code at runtime.

For adding a field or altering it in ASM you could override your visitField or visitMethod functions in your transformer class that inherits from ClassVisitor. In the visitField method you could create a new field or alter the values of the variables without modifying the actual class files.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.