twinstar6980 / Twinning

https://github.com/twinstar6980/Twinning.Documentation
GNU General Public License v3.0
59 stars 12 forks source link

RTON Decode Lenient Error #13

Closed Haruma-VN closed 1 year ago

Haruma-VN commented 1 year ago

RTON Decode Lenient cannot decode an RTON with 0x20 replaced by 0x19 & 0x00 in #comment, below is screenshot & zip file contains the RTON file error

image ARCADE_CONFIG.zip

twinstar6980 commented 1 year ago

Where is this file from? Can it be loaded normally by the game? Do you have similar sample files?

Haruma-VN commented 1 year ago

This file is an example I found last month when datamined old ECLISE RSB. It took me a bit to find the mistake from the RTON. The game can process some RTONs like this normally, but some will crash (this is really unstable)

twinstar6980 commented 1 year ago

After testing (pvz2 10.6.2 android, modify pp.dat to test), the abnormal data segment in this file cannot be read by the game, which causes the game to crash.

According to the reverse analysis of the rton decoding function in libpvz2.so, the rton parsing function of the game translates rton into json text (rather than directly converting it into json object), and then deserializes the json object from the json text.

When the game encounters 90-type data, it first reads a varint as the number of string bytes n, and then memcpy n bytes as the string content (considered as utf-8, without character check), so the null character (0x00 ) insertion will not affect subsequent rton data, just only truncate the current string.

When the game reads an object member, it first reads a value unit as a key, and then reads a value unit as a value. During this period, it does not check the data type (bool, int, str, etc) of the value unit, even if the type of the key is not string.

If the type flag byte of the value unit is not in the supported type enumeration (0x00, 0x24, 0x90, etc), the program will not output any data for the json text, which does not affect the process of rton translation into json text, but will cause The subsequent json reading process went wrong. The exception data section of this file should be translated as:

{
"#comment": "Mini-Game ....",
: "version",
1: "objects",
{
}....
}

This is a wrong json text, which will cause parsing failure in 10.6.2.

I don't know why the "old ECLISE" you mentioned can load the rton, maybe the old version of pvz2 tolerated this wrong data, so that the game loaded him correctly.

In short, at present, this wrong data should not be tolerated, so this is not a bug of the tool, and rton's lenient decoding function will not be modified.

If you have no other questions, please close the issue.