Java .Class file change string

后端 未结 4 1576
耶瑟儿~
耶瑟儿~ 2021-01-18 07:05

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

4条回答
  •  执笔经年
    2021-01-18 07:36

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

提交回复
热议问题