From 77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Fri, 6 Jul 2018 10:51:32 -0400 Subject: Virtual Filesystem (#597) * Add VfsFile and VfsDirectory classes * Finish abstract Vfs classes * Implement RealVfsFile (computer fs backend) * Finish RealVfsFile and RealVfsDirectory * Finished OffsetVfsFile * More changes * Fix import paths * Major refactor * Remove double const * Use experimental/filesystem or filesystem depending on compiler * Port partition_filesystem * More changes * More Overhaul * FSP_SRV fixes * Fixes and testing * Try to get filesystem to compile * Filesystem on linux * Remove std::filesystem and document/test * Compile fixes * Missing include * Bug fixes * Fixes * Rename v_file and v_dir * clang-format fix * Rename NGLOG_* to LOG_* * Most review changes * Fix TODO * Guess 'main' to be Directory by filename --- src/core/file_sys/content_archive.h | 89 +++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/core/file_sys/content_archive.h (limited to 'src/core/file_sys/content_archive.h') diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h new file mode 100644 index 000000000..eb4ca1c18 --- /dev/null +++ b/src/core/file_sys/content_archive.h @@ -0,0 +1,89 @@ +// Copyright 2018 yuzu emulator team +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include "common/common_funcs.h" +#include "common/common_types.h" +#include "common/swap.h" +#include "core/file_sys/partition_filesystem.h" + +namespace FileSys { + +enum class NCAContentType : u8 { Program = 0, Meta = 1, Control = 2, Manual = 3, Data = 4 }; + +struct NCASectionTableEntry { + u32_le media_offset; + u32_le media_end_offset; + INSERT_PADDING_BYTES(0x8); +}; +static_assert(sizeof(NCASectionTableEntry) == 0x10, "NCASectionTableEntry has incorrect size."); + +struct NCAHeader { + std::array rsa_signature_1; + std::array rsa_signature_2; + u32_le magic; + u8 is_system; + NCAContentType content_type; + u8 crypto_type; + u8 key_index; + u64_le size; + u64_le title_id; + INSERT_PADDING_BYTES(0x4); + u32_le sdk_version; + u8 crypto_type_2; + INSERT_PADDING_BYTES(15); + std::array rights_id; + std::array section_tables; + std::array, 0x4> hash_tables; + std::array, 0x4> key_area; + INSERT_PADDING_BYTES(0xC0); +}; +static_assert(sizeof(NCAHeader) == 0x400, "NCAHeader has incorrect size."); + +static bool IsDirectoryExeFS(std::shared_ptr pfs) { + // According to switchbrew, an exefs must only contain these two files: + return pfs->GetFile("main") != nullptr && pfs->GetFile("main.npdm") != nullptr; +} + +static bool IsValidNCA(const NCAHeader& header) { + return header.magic == Common::MakeMagic('N', 'C', 'A', '2') || + header.magic == Common::MakeMagic('N', 'C', 'A', '3'); +} + +// An implementation of VfsDirectory that represents a Nintendo Content Archive (NCA) conatiner. +// After construction, use GetStatus to determine if the file is valid and ready to be used. +class NCA : public ReadOnlyVfsDirectory { +public: + explicit NCA(VirtualFile file); + Loader::ResultStatus GetStatus() const; + + std::vector> GetFiles() const override; + std::vector> GetSubdirectories() const override; + std::string GetName() const override; + std::shared_ptr GetParentDirectory() const override; + + NCAContentType GetType() const; + u64 GetTitleId() const; + + VirtualFile GetRomFS() const; + VirtualDir GetExeFS() const; + +protected: + bool ReplaceFileWithSubdirectory(VirtualFile file, VirtualDir dir) override; + +private: + std::vector dirs; + std::vector files; + + VirtualFile romfs = nullptr; + VirtualDir exefs = nullptr; + VirtualFile file; + + NCAHeader header{}; + + Loader::ResultStatus status{}; +}; + +} // namespace FileSys -- cgit v1.2.3