java class 文件修改,Java .Class文件更改字符串

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...

Is there any way to change a string in a compiled java class without destroying it?

Thanks

解决方案

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";

}

With "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 |........|

With "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 |............|

It seems that the length is also encoded in the structure. Note the 3 and the 7... There is more information on this structure

And with a String of 300 characters the preceding two bytes were 01 2c.

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")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值