| 3 | #include <core/io/marshalls.h> |
| 4 | |
| 5 | Error AXMLParser::parse_manifest(Vector<uint8_t> &p_manifest) { |
| 6 | // Leaving the unused types commented because looking these constants up |
| 7 | // again later would be annoying |
| 8 | // const int CHUNK_AXML_FILE = 0x00080003; |
| 9 | // const int CHUNK_RESOURCEIDS = 0x00080180; |
| 10 | const int CHUNK_STRINGS = 0x001C0001; |
| 11 | // const int CHUNK_XML_END_NAMESPACE = 0x00100101; |
| 12 | const int CHUNK_XML_END_TAG = 0x00100103; |
| 13 | // const int CHUNK_XML_START_NAMESPACE = 0x00100100; |
| 14 | const int CHUNK_XML_START_TAG = 0x00100102; |
| 15 | // const int CHUNK_XML_TEXT = 0x00100104; |
| 16 | const int UTF8_FLAG = 0x00000100; |
| 17 | |
| 18 | Vector<String> string_table; |
| 19 | |
| 20 | uint32_t ofs = 8; |
| 21 | |
| 22 | uint32_t string_count = 0; |
| 23 | uint32_t string_flags = 0; |
| 24 | // uint32_t string_data_offset = 0; |
| 25 | |
| 26 | // uint32_t string_table_begins = 0; |
| 27 | // uint32_t string_table_ends = 0; |
| 28 | Vector<uint8_t> stable_extra; |
| 29 | |
| 30 | while (ofs < (uint32_t)p_manifest.size()) { |
| 31 | uint32_t chunk = decode_uint32(&p_manifest[ofs]); |
| 32 | uint32_t size = decode_uint32(&p_manifest[ofs + 4]); |
| 33 | |
| 34 | switch (chunk) { |
| 35 | case CHUNK_STRINGS: { |
| 36 | int iofs = ofs + 8; |
| 37 | |
| 38 | string_count = decode_uint32(&p_manifest[iofs]); |
| 39 | string_flags = decode_uint32(&p_manifest[iofs + 8]); |
| 40 | /*string_data_offset = */ decode_uint32(&p_manifest[iofs + 12]); |
| 41 | |
| 42 | uint32_t st_offset = iofs + 20; |
| 43 | string_table.resize(string_count); |
| 44 | uint32_t string_end = 0; |
| 45 | |
| 46 | /*string_table_begins = st_offset;*/ |
| 47 | |
| 48 | for (uint32_t i = 0; i < string_count; i++) { |
| 49 | uint32_t string_at = decode_uint32(&p_manifest[st_offset + i * 4]); |
| 50 | string_at += st_offset + string_count * 4; |
| 51 | |
| 52 | ERR_FAIL_COND_V_MSG(string_flags & UTF8_FLAG, ERR_FILE_CORRUPT, "Unimplemented, can't read UTF-8 string table."); |
| 53 | |
| 54 | if (string_flags & UTF8_FLAG) { |
| 55 | } else { |
| 56 | uint32_t len = decode_uint16(&p_manifest[string_at]); |
| 57 | Vector<char32_t> ucstring; |
| 58 | ucstring.resize(len + 1); |
| 59 | for (uint32_t j = 0; j < len; j++) { |
| 60 | uint16_t c = decode_uint16(&p_manifest[string_at + 2 + 2 * j]); |
| 61 | ucstring.write[j] = c; |
| 62 | } |
no test coverage detected