Reverse engineered TRE checksum function
This commit is contained in:
34
TreFile.cc
34
TreFile.cc
@@ -267,7 +267,11 @@ void TreFile::dumpAll(std::string path) const
|
|||||||
std::string name = path;
|
std::string name = path;
|
||||||
name.append(crcStr);
|
name.append(crcStr);
|
||||||
|
|
||||||
dumpIdx_(name, ent.second);
|
try {
|
||||||
|
dumpIdx_(name, ent.second);
|
||||||
|
} catch (Exception &ex) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto ent : table2_) {
|
for (auto ent : table2_) {
|
||||||
@@ -301,13 +305,37 @@ void TreFile::printStructure()
|
|||||||
std::get<2>(table3_[ent.second]),
|
std::get<2>(table3_[ent.second]),
|
||||||
std::get<3>(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
|
size_t TreFile::findName_(std::string const& name) const
|
||||||
{
|
{
|
||||||
auto it = table2_.find(name);
|
auto it = table2_.find(name);
|
||||||
if (it == table2_.end())
|
if (it == table2_.end()) {
|
||||||
throw Exception{name + " not found"};
|
try {
|
||||||
|
return findCRC_(calcCRC(name));
|
||||||
|
} catch (Exception &ex) {
|
||||||
|
throw Exception{name + " not found"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,6 +23,10 @@ public:
|
|||||||
|
|
||||||
void printStructure();
|
void printStructure();
|
||||||
|
|
||||||
|
/* Calculate the XTRE "CRC" (in reality a cheap checksum) of
|
||||||
|
'path' */
|
||||||
|
static uint32_t calcCRC(std::string const& path);
|
||||||
|
|
||||||
class Object {
|
class Object {
|
||||||
public:
|
public:
|
||||||
Object() : base_(nullptr), length_(0) {
|
Object() : base_(nullptr), length_(0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user