Java .Class文件更改字符串 [英] Java .Class file change string
问题描述
我正在尝试修改一个Minecraft mod(gravisuite),每当我按下F键时Gravitation Engine OFF / ON,但是我想改变这个字符串,我开始将Gravitation Engine OFF改为Gravitation Engine关闭通过使用十六进制编辑器,但之后文件不再有效:/我试图使用像jbe和cjbe和rej这样的工具,并且该字符串在常量池中,但它只会让我删除它...
I'm trying to modify a minecraft mod (gravisuite) that puts "Gravitation Engine OFF/ON" whenever I press F, however I want to change this string, I started with replacing "Gravitation Engine OFF" with "Gravitation Engine Turned OFF" by using a hex editor but the file was no longer valid afterwards :/ I tried to use tools like jbe and cjbe and rej and that string is in the constant pool but it will only let me delete it...
有没有办法在不破坏它的情况下更改已编译的java类中的字符串?
Is there any way to change a string in a compiled java class without destroying it?
谢谢
推荐答案
我用一个小调整编译了同一个类,首先是foo,然后是foo-bar
I compiled the same class twice with a minor tweak, firstly with "foo" and then with "foo-bar"
public class HelloWorld {
public static final String HELLO = "foo-bar";
}
使用foo
000000b0 74 01 00 **03** 66 6f 6f 00 21 00 02 00 03 00 00 00 |t...foo.!.......|
000000c0 01 00 19 00 04 00 05 00 01 00 06 00 00 00 02 00 |................|
000000d0 07 00 01 00 01 00 08 00 09 00 01 00 0a 00 00 00 |................|
000000e0 1d 00 01 00 01 00 00 00 05 2a b7 00 01 b1 00 00 |.........*......|
000000f0 00 01 00 0b 00 00 00 06 00 01 00 00 00 01 00 01 |................|
00000100 00 0c 00 00 00 02 00 0d |........|
使用foo-bar
000000b0 74 01 00 **07** 66 6f 6f 2d 62 61 72 00 21 00 02 00 |t...foo-bar.!...|
000000c0 03 00 00 00 01 00 19 00 04 00 05 00 01 00 06 00 |................|
000000d0 00 00 02 00 07 00 01 00 01 00 08 00 09 00 01 00 |................|
000000e0 0a 00 00 00 1d 00 01 00 01 00 00 00 05 2a b7 00 |.............*..|
000000f0 01 b1 00 00 00 01 00 0b 00 00 00 06 00 01 00 00 |................|
00000100 00 01 00 01 00 0c 00 00 00 02 00 0d |............|
似乎长度也在结构中编码。注意3和7 ...有更多信息在这个结构上
It seems that the length is also encoded in the structure. Note the 3 and the 7... There is more information on this structure
并且字符串为300个字符,前两个字节为01 2c。
And with a String of 300 characters the preceding two bytes were 01 2c.
所以鉴于万有引力关闭是29个字符长,我确保你把字符串前面的字节改为1D,它当前应该是19(万有引擎OFF / ON的25个字符)
So given "Gravitation Engine Turned OFF" is 29 characters long, I'd make sure you change the byte immediately before the string to 1D, it should currently be 19 (25 characters for "Gravitation Engine OFF/ON")
这篇关于Java .Class文件更改字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!