Reverse engineered TRE checksum function

This commit is contained in:
2015-05-15 22:15:56 +02:00
parent 8872d9d92d
commit d8a96ee73f
2 changed files with 35 additions and 3 deletions

View File

@@ -267,7 +267,11 @@ void TreFile::dumpAll(std::string path) const
std::string name = path;
name.append(crcStr);
dumpIdx_(name, ent.second);
try {
dumpIdx_(name, ent.second);
} catch (Exception &ex) {
continue;
}
}
for (auto ent : table2_) {
@@ -301,13 +305,37 @@ void TreFile::printStructure()
std::get<2>(table3_[ent.second]),
std::get<3>(table3_[ent.second]));
}
printf("CRC<->Name:\n");
for (auto const& ent1 : table1_) {
for (auto const& ent2 : table2_) {
if (ent1.second == ent2.second)
printf("\t%.8x\t%s\n", ent1.first, ent2.first.c_str());
}
}
}
uint32_t TreFile::calcCRC(std::string const& path)
{
uint32_t sum = 0;
for(unsigned char c: path) {
sum = (sum << 3) | ((sum>>29)&0x7);
sum += c;
}
return sum;
}
size_t TreFile::findName_(std::string const& name) const
{
auto it = table2_.find(name);
if (it == table2_.end())
throw Exception{name + " not found"};
if (it == table2_.end()) {
try {
return findCRC_(calcCRC(name));
} catch (Exception &ex) {
throw Exception{name + " not found"};
}
}
return it->second;
}

View File

@@ -23,6 +23,10 @@ public:
void printStructure();
/* Calculate the XTRE "CRC" (in reality a cheap checksum) of
'path' */
static uint32_t calcCRC(std::string const& path);
class Object {
public:
Object() : base_(nullptr), length_(0) {