diff --git a/include/resource_data.h b/include/resource_data.h index 1be5482..d303bd2 100644 --- a/include/resource_data.h +++ b/include/resource_data.h @@ -48,8 +48,9 @@ const static std::string SOLUTIONS = "Solutions:"; const static std::string SOLUTIONS_ARROW = "> "; const static std::string LONG_PATH_HEAD = "\\\\?\\"; const static int32_t VERSION_MAX_LEN = 128; -const static int32_t INT_TO_BYTES = sizeof(uint32_t); -static const int8_t RESTOOL_VERSION[VERSION_MAX_LEN] = { "Restool 6.0.0.001" }; +static const std::string RESTOOL_NAME = "Restool"; +static const std::string RESTOOLV2_NAME = "RestoolV2"; +static const std::string RESTOOL_VERSION = { " 6.0.0.001" }; const static int32_t TAG_LEN = 4; constexpr static int DEFAULT_POOL_SIZE = 8; static std::set g_resourceSet; diff --git a/src/cmd/package_parser.cpp b/src/cmd/package_parser.cpp index 6d8ba8b..f1092b3 100644 --- a/src/cmd/package_parser.cpp +++ b/src/cmd/package_parser.cpp @@ -248,7 +248,8 @@ uint32_t PackageParser::ForceWrite() uint32_t PackageParser::PrintVersion() { - cout << "Info: Restool version = " << RESTOOL_VERSION << endl; + std::string restoolVersion = RESTOOL_NAME + RESTOOL_VERSION; + cout << "Info: Restool version = " << restoolVersion << endl; exit(RESTOOL_SUCCESS); return RESTOOL_SUCCESS; } diff --git a/src/resource_table.cpp b/src/resource_table.cpp index 55073f2..a6d4837 100644 --- a/src/resource_table.cpp +++ b/src/resource_table.cpp @@ -268,28 +268,8 @@ uint32_t ResourceTable::SaveToResouorceIndex(const map bool ResourceTable::InitHeader(IndexHeaderV2 &indexHeader, IdSetHeader &idSetHeader, DataHeader &dataHeader, uint32_t count) { - const int8_t newModuleTag[3] = "V2"; - const size_t tagLen = 2; - int8_t newResToolVersion[VERSION_MAX_LEN] = {0}; - size_t nameIndex = find(RESTOOL_VERSION, RESTOOL_VERSION + VERSION_MAX_LEN, ' ') - RESTOOL_VERSION; - // copy "Restool" - if (memcpy_s(newResToolVersion, VERSION_MAX_LEN, RESTOOL_VERSION, nameIndex) != EOK) { - PrintError(GetError(ERR_CODE_UNDEFINED_ERROR).FormatCause("memcpy error when init index header")); - return false; - } - // copy "V2" - if (memcpy_s(newResToolVersion + nameIndex, VERSION_MAX_LEN - nameIndex, newModuleTag, tagLen) != EOK) { - PrintError(GetError(ERR_CODE_UNDEFINED_ERROR).FormatCause("memcpy error when init index header")); - return false; - } - // copy version id - if (memcpy_s(newResToolVersion + nameIndex + tagLen, VERSION_MAX_LEN - nameIndex - tagLen, - RESTOOL_VERSION + nameIndex, VERSION_MAX_LEN - nameIndex - tagLen) != EOK) { - PrintError(GetError(ERR_CODE_UNDEFINED_ERROR).FormatCause("memcpy error when init index header")); - return false; - } - - if (memcpy_s(indexHeader.version, VERSION_MAX_LEN, newResToolVersion, VERSION_MAX_LEN) != EOK) { + std::string restoolVersion = RESTOOLV2_NAME + RESTOOL_VERSION; + if (memcpy_s(indexHeader.version, VERSION_MAX_LEN, restoolVersion.data(), restoolVersion.length()) != EOK) { PrintError(GetError(ERR_CODE_UNDEFINED_ERROR).FormatCause("memcpy error when init index header")); return false; } @@ -488,7 +468,8 @@ uint32_t ResourceTable::SaveToNewResouorceIndex(const map &in, IndexHeader &indexHe return false; } in.read(reinterpret_cast(indexHeader.version), VERSION_MAX_LEN); - in.read(reinterpret_cast(&indexHeader.fileSize), INT_TO_BYTES); - in.read(reinterpret_cast(&indexHeader.limitKeyConfigSize), INT_TO_BYTES); + in.read(reinterpret_cast(&indexHeader.fileSize), sizeof(uint32_t)); + in.read(reinterpret_cast(&indexHeader.limitKeyConfigSize), sizeof(uint32_t)); return true; } @@ -622,7 +603,7 @@ bool ResourceTable::ReadLimitKeys(basic_istream &in, map length) { PrintError(GetError(ERR_CODE_INVALID_RESOURCE_INDEX).FormatCause("KEYS length error")); return false; @@ -635,19 +616,19 @@ bool ResourceTable::ReadLimitKeys(basic_istream &in, map(&keyParam.keyType), INT_TO_BYTES); - in.read(reinterpret_cast(&keyParam.value), INT_TO_BYTES); + in.read(reinterpret_cast(&keyParam.keyType), sizeof(uint32_t)); + in.read(reinterpret_cast(&keyParam.value), sizeof(uint32_t)); keyParams.push_back(keyParam); } limitKeys[limitKey.offset] = keyParams; @@ -659,7 +640,7 @@ bool ResourceTable::ReadIdTables(basic_istream &in, std::map length) { PrintError(GetError(ERR_CODE_INVALID_RESOURCE_INDEX).FormatCause("IDSS length error")); return false; @@ -673,17 +654,17 @@ bool ResourceTable::ReadIdTables(basic_istream &in, std::map(&data.id), INT_TO_BYTES); - in.read(reinterpret_cast(&data.dataOffset), INT_TO_BYTES); + in.read(reinterpret_cast(&data.id), sizeof(uint32_t)); + in.read(reinterpret_cast(&data.dataOffset), sizeof(uint32_t)); datas[data.dataOffset] = make_pair(data.id, offset); } } @@ -692,19 +673,19 @@ bool ResourceTable::ReadIdTables(basic_istream &in, std::map &in, RecordItem &record, uint64_t &pos, uint64_t length) { - pos = pos + INT_TO_BYTES; + pos = pos + sizeof(uint32_t); if (pos > length) { PrintError(GetError(ERR_CODE_INVALID_RESOURCE_INDEX).FormatCause("data record length error")); return false; } - in.read(reinterpret_cast(&record.size), INT_TO_BYTES); + in.read(reinterpret_cast(&record.size), sizeof(uint32_t)); pos = pos + record.size; if (pos > length) { PrintError(GetError(ERR_CODE_INVALID_RESOURCE_INDEX).FormatCause("record.size length error")); return false; } - in.read(reinterpret_cast(&record.resType), INT_TO_BYTES); - in.read(reinterpret_cast(&record.id), INT_TO_BYTES); + in.read(reinterpret_cast(&record.resType), sizeof(uint32_t)); + in.read(reinterpret_cast(&record.id), sizeof(uint32_t)); return true; } @@ -714,7 +695,7 @@ bool ResourceTable::ReadDataRecordStart(basic_istream &in, RecordItem &rec map> &resInfos) { int64_t offset = in.tellg(); - offset = offset - INT_TO_BYTES - INT_TO_BYTES - INT_TO_BYTES; + offset = offset - sizeof(uint32_t) - sizeof(uint32_t) - sizeof(uint32_t); uint16_t value_size = 0; in.read(reinterpret_cast(&value_size), sizeof(uint16_t)); if (value_size + sizeof(uint16_t) > record.size) { @@ -804,9 +785,9 @@ bool ResourceTable::ReadNewFileHeader(basic_istream &in, IndexHeaderV2 &in return false; } in.read(reinterpret_cast(indexHeader.version), VERSION_MAX_LEN); - in.read(reinterpret_cast(&indexHeader.length), INT_TO_BYTES); - in.read(reinterpret_cast(&indexHeader.keyCount), INT_TO_BYTES); - in.read(reinterpret_cast(&indexHeader.dataBlockOffset), INT_TO_BYTES); + in.read(reinterpret_cast(&indexHeader.length), sizeof(uint32_t)); + in.read(reinterpret_cast(&indexHeader.keyCount), sizeof(uint32_t)); + in.read(reinterpret_cast(&indexHeader.dataBlockOffset), sizeof(uint32_t)); for (uint32_t key = 0; key < indexHeader.keyCount; key++) { pos += KeyConfig::KEY_CONFIG_HEADER_LEN; @@ -816,8 +797,8 @@ bool ResourceTable::ReadNewFileHeader(basic_istream &in, IndexHeaderV2 &in } KeyConfig keyConfig; in.read(reinterpret_cast(keyConfig.keyTag), TAG_LEN); - in.read(reinterpret_cast(&keyConfig.configId), INT_TO_BYTES); - in.read(reinterpret_cast(&keyConfig.keyCount), INT_TO_BYTES); + in.read(reinterpret_cast(&keyConfig.configId), sizeof(uint32_t)); + in.read(reinterpret_cast(&keyConfig.keyCount), sizeof(uint32_t)); for (uint32_t keyType = 0; keyType < keyConfig.keyCount; keyType++) { pos += KeyParam::KEY_PARAM_LEN; @@ -826,8 +807,8 @@ bool ResourceTable::ReadNewFileHeader(basic_istream &in, IndexHeaderV2 &in return false; } KeyParam keyParam; - in.read(reinterpret_cast(&keyParam.keyType), INT_TO_BYTES); - in.read(reinterpret_cast(&keyParam.value), INT_TO_BYTES); + in.read(reinterpret_cast(&keyParam.keyType), sizeof(uint32_t)); + in.read(reinterpret_cast(&keyParam.value), sizeof(uint32_t)); keyConfig.configs.push_back(keyParam); } indexHeader.idKeyConfigs[keyConfig.configId] = keyConfig; @@ -843,9 +824,9 @@ bool ResourceTable::ReadIdSetHeader(basic_istream &in, IdSetHeader &idSetH return false; } in.read(reinterpret_cast(idSetHeader.idTag), TAG_LEN); - in.read(reinterpret_cast(&idSetHeader.length), INT_TO_BYTES); - in.read(reinterpret_cast(&idSetHeader.typeCount), INT_TO_BYTES); - in.read(reinterpret_cast(&idSetHeader.idCount), INT_TO_BYTES); + in.read(reinterpret_cast(&idSetHeader.length), sizeof(uint32_t)); + in.read(reinterpret_cast(&idSetHeader.typeCount), sizeof(uint32_t)); + in.read(reinterpret_cast(&idSetHeader.idCount), sizeof(uint32_t)); for (uint32_t resType = 0; resType < idSetHeader.typeCount; resType++) { pos += ResTypeHeader::RES_TYPE_HEADER_LEN; @@ -854,9 +835,9 @@ bool ResourceTable::ReadIdSetHeader(basic_istream &in, IdSetHeader &idSetH return false; } ResTypeHeader resTypeHeader; - in.read(reinterpret_cast(&resTypeHeader.resType), INT_TO_BYTES); - in.read(reinterpret_cast(&resTypeHeader.length), INT_TO_BYTES); - in.read(reinterpret_cast(&resTypeHeader.count), INT_TO_BYTES); + in.read(reinterpret_cast(&resTypeHeader.resType), sizeof(uint32_t)); + in.read(reinterpret_cast(&resTypeHeader.length), sizeof(uint32_t)); + in.read(reinterpret_cast(&resTypeHeader.count), sizeof(uint32_t)); for (uint32_t resId = 0; resId < resTypeHeader.count; resId++) { pos += ResIndex::RES_INDEX_LEN; @@ -865,9 +846,9 @@ bool ResourceTable::ReadIdSetHeader(basic_istream &in, IdSetHeader &idSetH return false; } ResIndex resIndex; - in.read(reinterpret_cast(&resIndex.resId), INT_TO_BYTES); - in.read(reinterpret_cast(&resIndex.offset), INT_TO_BYTES); - in.read(reinterpret_cast(&resIndex.length), INT_TO_BYTES); + in.read(reinterpret_cast(&resIndex.resId), sizeof(uint32_t)); + in.read(reinterpret_cast(&resIndex.offset), sizeof(uint32_t)); + in.read(reinterpret_cast(&resIndex.length), sizeof(uint32_t)); pos += resIndex.length; if (pos > length) { PrintError(GetError(ERR_CODE_INVALID_RESOURCE_INDEX).FormatCause("resource name length error")); @@ -918,9 +899,9 @@ bool ResourceTable::ReadResInfo(std::basic_istream &in, ResInfo &resInfo, PrintError(GetError(ERR_CODE_INVALID_RESOURCE_INDEX).FormatCause("ResInfo length error")); return false; } - in.read(reinterpret_cast(&resInfo.resId), INT_TO_BYTES); - in.read(reinterpret_cast(&resInfo.length), INT_TO_BYTES); - in.read(reinterpret_cast(&resInfo.valueCount), INT_TO_BYTES); + in.read(reinterpret_cast(&resInfo.resId), sizeof(uint32_t)); + in.read(reinterpret_cast(&resInfo.length), sizeof(uint32_t)); + in.read(reinterpret_cast(&resInfo.valueCount), sizeof(uint32_t)); return true; } @@ -928,13 +909,13 @@ bool ResourceTable::ReadResConfig(std::basic_istream &in, uint32_t &resCon uint64_t &pos, uint64_t length) { in.seekg(pos, ios::beg); - pos += INT_TO_BYTES + INT_TO_BYTES; + pos += sizeof(uint32_t) + sizeof(uint32_t); if (pos > length) { PrintError(GetError(ERR_CODE_INVALID_RESOURCE_INDEX).FormatCause("Config id length error")); return false; } - in.read(reinterpret_cast(&resConfigId), INT_TO_BYTES); - in.read(reinterpret_cast(&dataOffset), INT_TO_BYTES); + in.read(reinterpret_cast(&resConfigId), sizeof(uint32_t)); + in.read(reinterpret_cast(&dataOffset), sizeof(uint32_t)); return true; }