Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "BinFile.h"
- #pragma pack(push, 1)
- struct PackDirectoryHeader
- {
- uint64 directoryOffset;
- uint64 blockSize;
- };
- struct AIDX
- {
- uint32 magic;
- uint32 version;
- uint32 someConstantAlways17B8;
- uint32 rootBlock;
- };
- #pragma pack(pop)
- struct RootDirectoryEntry
- {
- uint32 nextBlock;
- std::wstring directoryName;
- };
- class IFileSystemEntry;
- typedef std::shared_ptr<IFileSystemEntry> IFileSystemEntryPtr;
- class IFileSystemEntry
- {
- protected:
- IFileSystemEntryPtr mParent;
- std::list<IFileSystemEntryPtr> mChildren;
- std::wstring mEntryName;
- public:
- IFileSystemEntryPtr getParent() const { return mParent; }
- std::wstring getEntryName() const { return mEntryName; }
- const std::list<IFileSystemEntryPtr>& getChildren() const { return mChildren; }
- virtual bool isDirectory() const = 0;
- virtual void dumpFiles(std::wstring basePath, std::wostream& output) = 0;
- };
- class PackArchive;
- typedef std::shared_ptr<PackArchive> PackArchivePtr;
- class DirectoryEntry : public IFileSystemEntry, public std::enable_shared_from_this<DirectoryEntry>
- {
- protected:
- PackArchivePtr mArchive;
- uint32 mNextBlock;
- bool mIsRootDirectory;
- public:
- DirectoryEntry(IFileSystemEntryPtr parent, const std::wstring& name, uint32 nextBlock, PackArchivePtr archive);
- virtual void parseChildren();
- void dumpFiles(std::wstring basePath, std::wostream& output);
- void setRoot(bool root) { mIsRootDirectory = root; }
- void getFiles(std::vector<IFileSystemEntryPtr>& files);
- IFileSystemEntryPtr getFile(std::wstring path);
- bool isDirectory() const { return true; }
- };
- typedef std::shared_ptr<DirectoryEntry> DirectoryEntryPtr;
- class FileEntry : public IFileSystemEntry
- {
- uint32 flags;
- uint64 unkValue;
- uint64 compressedSize;
- uint64 uncompressedSize;
- uint8 hash[20];
- uint32 block;
- public:
- FileEntry(IFileSystemEntryPtr parent, const std::wstring& name, const std::vector<uint8>& junk) {
- mParent = parent;
- mEntryName = name;
- flags = *(uint32*)(junk.data());
- unkValue = *(uint64*)(junk.data() + 4);
- uncompressedSize = *(uint64*)(junk.data() + 12);
- compressedSize = *(uint64*)(junk.data() + 20);
- memcpy(hash, junk.data() + 28, 20);
- }
- bool isDirectory() const { return false; }
- const uint8* getHash() const { return hash; }
- uint32 getFlags() { return flags; }
- uint64 getSizeUncompressed() const { return uncompressedSize; }
- void dumpFiles(std::wstring basePath, std::wostream& output) {
- output << basePath << mEntryName << L" (Type: " << flags << L", Compressed: " << compressedSize << L", Uncompressed: " << uncompressedSize << L")" << std::endl;
- }
- std::wstring getFullPath() {
- std::wstring path = mEntryName;
- auto parent = mParent;
- while(parent != nullptr) {
- if(parent->getEntryName().empty() == false) {
- path = parent->getEntryName() + L"\\" + path;
- }
- parent = parent->getParent();
- }
- return path;
- }
- };
- typedef std::shared_ptr<FileEntry> FileEntryPtr;
- class PackArchive : public std::enable_shared_from_this<PackArchive>
- {
- BinFilePtr mFile;
- uint32 mDirectoryCount;
- uint64 mDirectoryTableStart;
- AIDX mIndexHeader;
- std::vector<PackDirectoryHeader> mDirectoryHeaders;
- DirectoryEntryPtr mFileRoot;
- public:
- PackArchive(BinFilePtr binFile);
- void validate();
- void loadDirectoryTree();
- FileEntryPtr getFile(const std::wstring& name) { return std::dynamic_pointer_cast<FileEntry>(mFileRoot->getFile(name)); }
- IFileSystemEntryPtr getEntry(const std::wstring& name) { return mFileRoot->getFile(name); }
- DirectoryEntryPtr getRoot() const { return mFileRoot; }
- BinFilePtr getFile() const { return mFile; }
- const std::vector<PackDirectoryHeader>& getBlockTable() const { return mDirectoryHeaders; }
- static const uint32 FileMagic = 'PACK';
- static const uint32 IndexMagic = 'AIDX';
- };
Advertisement
Add Comment
Please, Sign In to add comment