correct error with bolt structures, now reading file data (need compression though)
This commit is contained in:
parent
d7a48f39b4
commit
f1f081c114
|
@ -48,6 +48,9 @@ namespace lightningbolt {
|
||||||
u32 groupSize;
|
u32 groupSize;
|
||||||
u32 groupOffset;
|
u32 groupOffset;
|
||||||
|
|
||||||
|
// PS2 pointer padding; bolt library stuffs something here
|
||||||
|
u32 pad;
|
||||||
|
|
||||||
u32 EntryCount() {
|
u32 EntryCount() {
|
||||||
// Special case: 0x0 == 256 entries.
|
// Special case: 0x0 == 256 entries.
|
||||||
// I have NO idea why they did it like this,
|
// I have NO idea why they did it like this,
|
||||||
|
@ -58,7 +61,7 @@ namespace lightningbolt {
|
||||||
return entryCount;
|
return entryCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::span<BoltGroupEntry> Entries(u8* base) { return { std::bit_cast<BoltGroupEntry*>(base + groupOffset), EntryCount() }; }
|
std::span<BoltGroupEntry> Entries(u8* base) { return { std::bit_cast<BoltGroupEntry*>(&base[groupOffset]), EntryCount() }; }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct [[gnu::packed]] BoltLibraryHeader {
|
struct [[gnu::packed]] BoltLibraryHeader {
|
||||||
|
|
56
src/main.cpp
56
src/main.cpp
|
@ -1,18 +1,19 @@
|
||||||
#include <base/MmapFile.hpp>
|
#include <base/MmapFile.hpp>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <format>
|
||||||
|
#include <iostream>
|
||||||
#include <structs/BoltStructs.hpp>
|
#include <structs/BoltStructs.hpp>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <format>
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
struct ParsedTableEntry {
|
|
||||||
std::string_view filename;
|
|
||||||
u16 index;
|
|
||||||
u32 gid;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct BoltReader {
|
struct BoltReader {
|
||||||
|
struct ParsedTableEntry {
|
||||||
|
std::string_view filename;
|
||||||
|
u16 index;
|
||||||
|
u16 gid;
|
||||||
|
|
||||||
|
std::span<u8> uncompressedData;
|
||||||
|
};
|
||||||
|
|
||||||
BoltReader() {}
|
BoltReader() {}
|
||||||
|
|
||||||
ErrorOr<void> OpenBolt(const lightningbolt::fs::path& path) {
|
ErrorOr<void> OpenBolt(const lightningbolt::fs::path& path) {
|
||||||
|
@ -29,6 +30,7 @@ struct BoltReader {
|
||||||
if(auto error = boltFile.Open(path); error.HasError())
|
if(auto error = boltFile.Open(path); error.HasError())
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
|
lib = std::bit_cast<lightningbolt::BoltLibraryHeader*>(boltFile.GetMapping());
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,27 +49,45 @@ struct BoltReader {
|
||||||
if(te.filename == "")
|
if(te.filename == "")
|
||||||
break;
|
break;
|
||||||
|
|
||||||
std::cout << std::format("te: {} {:04x} {:04x}\n", te.filename, te.index, te.gid);
|
// std::cout << std::format("te: {} {:04x} {:04x}\n", te.filename, te.index, te.gid);
|
||||||
entryTable.emplace_back(te);
|
entryTable.emplace_back(te);
|
||||||
|
|
||||||
table++;
|
table++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// The ELF file isn't needed after this so unmap it
|
|
||||||
elfFile.Close();
|
|
||||||
}
|
}
|
||||||
return entryTable;
|
return entryTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class F>
|
template <class F>
|
||||||
void ForEachFile(F f) {
|
void ForEachFile(F f) {
|
||||||
//for()()
|
for(auto& file : entryTable) {
|
||||||
|
if(file.uncompressedData.empty()) {
|
||||||
|
auto gid = (file.gid >> 8);
|
||||||
|
auto entries = lib->GroupDescriptors()[gid].Entries(boltFile.GetMapping());
|
||||||
|
|
||||||
|
// std::cout << std::format("ptr: {} {:08x}\n", (void*)entries.data(), (u32)(std::bit_cast<usize>(entries.data()) - (usize)lib));
|
||||||
|
|
||||||
|
auto size = entries[file.index & 0x00ff].fileSize;
|
||||||
|
auto offset = entries[file.index & 0x00ff].fileOffset;
|
||||||
|
|
||||||
|
file.uncompressedData = { std::bit_cast<u8*>(boltFile.GetMapping() + offset), size };
|
||||||
|
|
||||||
|
// for(i32 i = 0; i < entries.size(); ++i) {
|
||||||
|
// std::cout << std::format("dick {}: {:08x}\n", i, entries[i].fileOffset);
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!f(file))
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<ParsedTableEntry> entryTable;
|
std::vector<ParsedTableEntry> entryTable;
|
||||||
lightningbolt::MmapFile elfFile;
|
lightningbolt::MmapFile elfFile;
|
||||||
lightningbolt::MmapFile boltFile;
|
lightningbolt::MmapFile boltFile;
|
||||||
|
|
||||||
|
lightningbolt::BoltLibraryHeader* lib;
|
||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
@ -76,5 +96,11 @@ int main() {
|
||||||
std::cout << "Error opening Bolt file: " << error.Error();
|
std::cout << "Error opening Bolt file: " << error.Error();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
reader.ForEachFile([](BoltReader::ParsedTableEntry& ent) {
|
||||||
|
std::cout << std::format("File: {} magic: ", ent.filename) << ent.uncompressedData[0] << ent.uncompressedData[1] << ent.uncompressedData[2]
|
||||||
|
<< ent.uncompressedData[3] << '\n';
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue