| 1112 | #include "utility/common.h" |
| 1113 | |
| 1114 | Error GDScriptV1TokenizerBufferCompat::set_code_buffer(const Vector<uint8_t> &p_buffer) { |
| 1115 | const uint8_t *buf = p_buffer.ptr(); |
| 1116 | uint64_t total_len = p_buffer.size(); |
| 1117 | GDSDECOMP_FAIL_COND_V_MSG(p_buffer.size() < 24 || !CHECK_GDSC_HEADER(p_buffer), ERR_INVALID_DATA, "Invalid GDScript token buffer."); |
| 1118 | int version = decode_uint32(&buf[4]); |
| 1119 | ERR_FAIL_COND_V_MSG(version >= GDScriptDecomp::GDSCRIPT_2_0_VERSION, ERR_INVALID_DATA, "Wrong function!"); |
| 1120 | const int contents_start = 8 + (version >= GDScriptDecomp::GDSCRIPT_2_0_VERSION ? 4 : 0); |
| 1121 | uint32_t identifier_count = decode_uint32(&buf[contents_start]); |
| 1122 | uint32_t constant_count = decode_uint32(&buf[contents_start + 4]); |
| 1123 | uint32_t line_count = decode_uint32(&buf[contents_start + 8]); |
| 1124 | uint32_t token_count = decode_uint32(&buf[contents_start + 12]); |
| 1125 | |
| 1126 | const uint8_t *b = &buf[24]; |
| 1127 | total_len -= 24; |
| 1128 | |
| 1129 | identifiers.resize(identifier_count); |
| 1130 | for (uint32_t i = 0; i < identifier_count; i++) { |
| 1131 | uint32_t len = decode_uint32(b); |
| 1132 | GDSDECOMP_FAIL_COND_V_MSG(len > total_len, ERR_INVALID_DATA, "Invalid identifier length."); |
| 1133 | b += 4; |
| 1134 | Vector<uint8_t> cs; |
| 1135 | cs.resize(len); |
| 1136 | for (uint32_t j = 0; j < len; j++) { |
| 1137 | cs.write[j] = b[j] ^ 0xb6; |
| 1138 | } |
| 1139 | |
| 1140 | cs.write[cs.size() - 1] = 0; |
| 1141 | String s; |
| 1142 | s.append_utf8((const char *)cs.ptr()); |
| 1143 | b += len; |
| 1144 | total_len -= len + 4; |
| 1145 | identifiers.write[i] = s; |
| 1146 | } |
| 1147 | |
| 1148 | constants.resize(constant_count); |
| 1149 | for (uint32_t i = 0; i < constant_count; i++) { |
| 1150 | Variant v; |
| 1151 | int len; |
| 1152 | Error err = VariantDecoderCompat::decode_variant_compat(decomp->get_variant_ver_major(), v, b, total_len, &len); |
| 1153 | if (err) { |
| 1154 | error_message = RTR("Invalid constant"); |
| 1155 | return err; |
| 1156 | } |
| 1157 | b += len; |
| 1158 | total_len -= len; |
| 1159 | constants.write[i] = v; |
| 1160 | } |
| 1161 | |
| 1162 | GDSDECOMP_FAIL_COND_V_MSG(line_count * /*sizeof(HashMap<uint32_t, uint32_t>::Pair)*/ 8 > total_len, ERR_INVALID_DATA, "Invalid line count."); |
| 1163 | |
| 1164 | for (uint32_t i = 0; i < line_count; i++) { |
| 1165 | uint32_t token_index = decode_uint32(b); |
| 1166 | b += 4; |
| 1167 | uint32_t linecol = decode_uint32(b); |
| 1168 | b += 4; |
| 1169 | |
| 1170 | lines.insert(token_index, linecol); |
| 1171 | total_len -= 8; |
nothing calls this directly
no test coverage detected