diff --git a/include/install/hfs0.hpp b/include/install/hfs0.hpp new file mode 100644 index 0000000..6557f88 --- /dev/null +++ b/include/install/hfs0.hpp @@ -0,0 +1,57 @@ +#pragma once + +#include + +#define MAGIC_HFS0 0x30534648 + +namespace tin::install +{ + struct HFS0FileEntry + { + u64 dataOffset; + u64 fileSize; + u32 stringTableOffset; + u32 hashedSize; + u64 padding; + unsigned char hash[0x20]; + } PACKED; + + static_assert(sizeof(HFS0FileEntry) == 0x40, "HFS0FileEntry must be 0x18"); + + struct HFS0BaseHeader + { + u32 magic; + u32 numFiles; + u32 stringTableSize; + u32 reserved; + } PACKED; + + static_assert(sizeof(HFS0BaseHeader) == 0x10, "HFS0BaseHeader must be 0x10"); + + NX_INLINE const HFS0FileEntry *hfs0GetFileEntry(const HFS0BaseHeader *header, u32 i) + { + if (i >= header->numFiles) + return NULL; + return (const HFS0FileEntry*)(header + 0x1 + i * 0x4); + } + + NX_INLINE const char *hfs0GetStringTable(const HFS0BaseHeader *header) + { + return (const char*)(header + 0x1 + header->numFiles * 0x4); + } + + NX_INLINE u64 hfs0GetHeaderSize(const HFS0BaseHeader *header) + { + return 0x1 + header->numFiles * 0x4 + header->stringTableSize; + } + + NX_INLINE const char *hfs0GetFileName(const HFS0BaseHeader *header, u32 i) + { + return hfs0GetStringTable(header) + hfs0GetFileEntry(header, i)->stringTableOffset; + } + + NX_INLINE const char *hfs0GetFileName(const HFS0BaseHeader *header, const HFS0FileEntry *entry) + { + return hfs0GetStringTable(header) + entry->stringTableOffset; + } +} \ No newline at end of file diff --git a/include/install/http_nsp.hpp b/include/install/http_nsp.hpp new file mode 100644 index 0000000..6c67701 --- /dev/null +++ b/include/install/http_nsp.hpp @@ -0,0 +1,40 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include "install/nsp.hpp" +#include + +namespace tin::install::nsp +{ + class HTTPNSP : public NSP + { + public: + tin::network::HTTPDownload m_download; + + HTTPNSP(std::string url); + + virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId placeholderId) override; + virtual void BufferData(void* buf, off_t offset, size_t size) override; + }; +} \ No newline at end of file diff --git a/include/install/http_xci.hpp b/include/install/http_xci.hpp new file mode 100644 index 0000000..0ae313a --- /dev/null +++ b/include/install/http_xci.hpp @@ -0,0 +1,41 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include "install/xci.hpp" +#include "util/network_util.hpp" +#include + +namespace tin::install::xci +{ + class HTTPXCI : public XCI + { + public: + tin::network::HTTPDownload m_download; + + HTTPXCI(std::string url); + + virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId placeholderId) override; + virtual void BufferData(void* buf, off_t offset, size_t size) override; + }; +} \ No newline at end of file diff --git a/include/install/install.hpp b/include/install/install.hpp new file mode 100644 index 0000000..a688248 --- /dev/null +++ b/include/install/install.hpp @@ -0,0 +1,69 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +extern "C" +{ +#include +} + +#include +#include +#include + +#include "install/simple_filesystem.hpp" +#include "data/byte_buffer.hpp" + +#include "nx/content_meta.hpp" +#include "nx/ipc/tin_ipc.h" + +namespace tin::install +{ + class Install + { + protected: + const NcmStorageId m_destStorageId; + bool m_ignoreReqFirmVersion = false; + bool m_declinedValidation = false; + + std::vector m_contentMeta; + + Install(NcmStorageId destStorageId, bool ignoreReqFirmVersion); + + virtual std::vector> ReadCNMT() = 0; + + virtual void InstallContentMetaRecords(tin::data::ByteBuffer& installContentMetaBuf, int i); + virtual void InstallApplicationRecord(int i); + virtual void InstallTicketCert() = 0; + virtual void InstallNCA(const NcmContentId &ncaId) = 0; + + public: + virtual ~Install(); + + virtual void Prepare(); + virtual void Begin(); + + virtual u64 GetTitleId(int i = 0); + virtual NcmContentMetaType GetContentMetaType(int i = 0); + }; +} \ No newline at end of file diff --git a/include/install/install_nsp.hpp b/include/install/install_nsp.hpp new file mode 100644 index 0000000..486fa9a --- /dev/null +++ b/include/install/install_nsp.hpp @@ -0,0 +1,45 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include +#include +#include "install/install.hpp" +#include "install/nsp.hpp" + +namespace tin::install::nsp +{ + class NSPInstall : public Install + { + private: + const std::shared_ptr m_NSP; + + protected: + std::vector> ReadCNMT() override; + void InstallNCA(const NcmContentId& ncaId) override; + void InstallTicketCert() override; + + public: + NSPInstall(NcmStorageId destStorageId, bool ignoreReqFirmVersion, const std::shared_ptr& remoteNSP); + }; +} \ No newline at end of file diff --git a/include/install/install_xci.hpp b/include/install/install_xci.hpp new file mode 100644 index 0000000..166e05c --- /dev/null +++ b/include/install/install_xci.hpp @@ -0,0 +1,47 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include +#include "install/install.hpp" +#include "install/xci.hpp" +#include "nx/content_meta.hpp" +#include "nx/ipc/tin_ipc.h" + +namespace tin::install::xci +{ + class XCIInstallTask : public Install + { + private: + const std::shared_ptr m_xci; + + protected: + std::vector> ReadCNMT() override; + void InstallNCA(const NcmContentId& ncaId) override; + void InstallTicketCert() override; + + public: + XCIInstallTask(NcmStorageId destStorageId, bool ignoreReqFirmVersion, const std::shared_ptr& xci); + }; +}; + diff --git a/include/install/nca.hpp b/include/install/nca.hpp new file mode 100644 index 0000000..84e4398 --- /dev/null +++ b/include/install/nca.hpp @@ -0,0 +1,77 @@ +#pragma once + +#include + +#define NCA_HEADER_SIZE 0x4000 +#define MAGIC_NCA3 0x3341434E /* "NCA3" */ +namespace tin::install +{ + struct NcaFsHeader + { + u8 _0x0; + u8 _0x1; + u8 partition_type; + u8 fs_type; + u8 crypt_type; + u8 _0x5[0x3]; + u8 superblock_data[0x138]; + /*union { + pfs0_superblock_t pfs0_superblock; + romfs_superblock_t romfs_superblock; + //nca0_romfs_superblock_t nca0_romfs_superblock; + bktr_superblock_t bktr_superblock; + };*/ + union { + u64 section_ctr; + struct { + u32 section_ctr_low; + u32 section_ctr_high; + }; + }; + u8 _0x148[0xB8]; /* Padding. */ + } PACKED; + + static_assert(sizeof(NcaFsHeader) == 0x200, "NcaFsHeader must be 0x200"); + + struct NcaSectionEntry + { + u32 media_start_offset; + u32 media_end_offset; + u8 _0x8[0x8]; /* Padding. */ + } PACKED; + + static_assert(sizeof(NcaSectionEntry) == 0x10, "NcaSectionEntry must be 0x10"); + + struct NcaHeader + { + u8 fixed_key_sig[0x100]; /* RSA-PSS signature over header with fixed key. */ + u8 npdm_key_sig[0x100]; /* RSA-PSS signature over header with key in NPDM. */ + u32 magic; + u8 distribution; /* System vs gamecard. */ + u8 content_type; + u8 m_cryptoType; /* Which keyblob (field 1) */ + u8 m_kaekIndex; /* Which kaek index? */ + u64 nca_size; /* Entire archive size. */ + u64 m_titleId; + u8 _0x218[0x4]; /* Padding. */ + union { + uint32_t sdk_version; /* What SDK was this built with? */ + struct { + u8 sdk_revision; + u8 sdk_micro; + u8 sdk_minor; + u8 sdk_major; + }; + }; + u8 m_cryptoType2; /* Which keyblob (field 2) */ + u8 _0x221[0xF]; /* Padding. */ + u64 m_rightsId[2]; /* Rights ID (for titlekey crypto). */ + NcaSectionEntry section_entries[4]; /* Section entry metadata. */ + u8 section_hashes[4 * 0x20]; /* SHA-256 hashes for each section header. */ + u8 m_keys[4 * 0x10]; /* Encrypted key area. */ + u8 _0x340[0xC0]; /* Padding. */ + NcaFsHeader fs_headers[4]; /* FS section headers. */ + } PACKED; + + static_assert(sizeof(NcaHeader) == 0xc00, "NcaHeader must be 0xc00"); +} \ No newline at end of file diff --git a/include/install/nsp.hpp b/include/install/nsp.hpp new file mode 100644 index 0000000..47e37b1 --- /dev/null +++ b/include/install/nsp.hpp @@ -0,0 +1,57 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include +#include + +#include +#include "install/pfs0.hpp" +#include "nx/ncm.hpp" +#include "util/network_util.hpp" + +namespace tin::install::nsp +{ + class NSP + { + protected: + std::vector m_headerBytes; + + NSP(); + + public: + virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId placeholderId) = 0; + virtual void BufferData(void* buf, off_t offset, size_t size) = 0; + + virtual void RetrieveHeader(); + virtual const PFS0BaseHeader* GetBaseHeader(); + virtual u64 GetDataOffset(); + + virtual const PFS0FileEntry* GetFileEntry(unsigned int index); + virtual const PFS0FileEntry* GetFileEntryByName(std::string name); + virtual const PFS0FileEntry* GetFileEntryByNcaId(const NcmContentId& ncaId); + virtual std::vector GetFileEntriesByExtension(std::string extension); + + virtual const char* GetFileEntryName(const PFS0FileEntry* fileEntry); + }; +} \ No newline at end of file diff --git a/include/install/pfs0.hpp b/include/install/pfs0.hpp new file mode 100644 index 0000000..3c02840 --- /dev/null +++ b/include/install/pfs0.hpp @@ -0,0 +1,48 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include + +namespace tin::install +{ + struct PFS0FileEntry + { + u64 dataOffset; + u64 fileSize; + u32 stringTableOffset; + u32 padding; + } PACKED; + + static_assert(sizeof(PFS0FileEntry) == 0x18, "PFS0FileEntry must be 0x18"); + + struct PFS0BaseHeader + { + u32 magic; + u32 numFiles; + u32 stringTableSize; + u32 reserved; + } PACKED; + + static_assert(sizeof(PFS0BaseHeader) == 0x10, "PFS0BaseHeader must be 0x10"); +} \ No newline at end of file diff --git a/include/install/sdmc_nsp.hpp b/include/install/sdmc_nsp.hpp new file mode 100644 index 0000000..cf64c10 --- /dev/null +++ b/include/install/sdmc_nsp.hpp @@ -0,0 +1,40 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include "install/nsp.hpp" + +namespace tin::install::nsp +{ + class SDMCNSP : public NSP + { + public: + SDMCNSP(std::string path); + ~SDMCNSP(); + + virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId ncaId) override; + virtual void BufferData(void* buf, off_t offset, size_t size) override; + private: + FILE* m_nspFile; + }; +} diff --git a/include/install/sdmc_xci.hpp b/include/install/sdmc_xci.hpp new file mode 100644 index 0000000..aa1b646 --- /dev/null +++ b/include/install/sdmc_xci.hpp @@ -0,0 +1,40 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include "install/xci.hpp" + +namespace tin::install::xci +{ + class SDMCXCI : public XCI + { + public: + SDMCXCI(std::string path); + ~SDMCXCI(); + + virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId ncaId) override; + virtual void BufferData(void* buf, off_t offset, size_t size) override; + private: + FILE* m_xciFile; + }; +} \ No newline at end of file diff --git a/include/install/simple_filesystem.hpp b/include/install/simple_filesystem.hpp new file mode 100644 index 0000000..7d2f115 --- /dev/null +++ b/include/install/simple_filesystem.hpp @@ -0,0 +1,46 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include +#include "nx/fs.hpp" + +namespace tin::install::nsp +{ + class SimpleFileSystem final + { + private: + nx::fs::IFileSystem* m_fileSystem; + + public: + const std::string m_rootPath; + const std::string m_absoluteRootPath; + + SimpleFileSystem(nx::fs::IFileSystem& fileSystem, std::string rootPath, std::string absoluteRootPath); + ~SimpleFileSystem(); + + nx::fs::IFile OpenFile(std::string path); + bool HasFile(std::string path); + std::string GetFileNameFromExtension(std::string path, std::string extension); + }; +} \ No newline at end of file diff --git a/include/install/usb_nsp.hpp b/include/install/usb_nsp.hpp new file mode 100644 index 0000000..5612bb3 --- /dev/null +++ b/include/install/usb_nsp.hpp @@ -0,0 +1,41 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include +#include "install/nsp.hpp" + +namespace tin::install::nsp +{ + class USBNSP : public NSP + { + private: + std::string m_nspName; + + public: + USBNSP(std::string nspName); + + virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId placeholderId) override; + virtual void BufferData(void* buf, off_t offset, size_t size) override; + }; +} \ No newline at end of file diff --git a/include/install/usb_xci.hpp b/include/install/usb_xci.hpp new file mode 100644 index 0000000..0c9bd5d --- /dev/null +++ b/include/install/usb_xci.hpp @@ -0,0 +1,41 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include +#include "install/xci.hpp" + +namespace tin::install::xci +{ + class USBXCI : public XCI + { + private: + std::string m_xciName; + + public: + USBXCI(std::string xciName); + + virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId placeholderId) override; + virtual void BufferData(void* buf, off_t offset, size_t size) override; + }; +} \ No newline at end of file diff --git a/include/install/xci.hpp b/include/install/xci.hpp new file mode 100644 index 0000000..d5a4d0a --- /dev/null +++ b/include/install/xci.hpp @@ -0,0 +1,58 @@ +/* +Copyright (c) 2017-2018 Adubbz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#pragma once + +#include +#include + +#include +#include "install/hfs0.hpp" +#include "nx/ncm.hpp" +#include + +namespace tin::install::xci +{ + class XCI + { + protected: + u64 m_secureHeaderOffset; + std::vector m_secureHeaderBytes; + + XCI(); + + public: + virtual void StreamToPlaceholder(std::shared_ptr& contentStorage, NcmContentId placeholderId) = 0; + virtual void BufferData(void* buf, off_t offset, size_t size) = 0; + + virtual void RetrieveHeader(); + virtual const HFS0BaseHeader* GetSecureHeader(); + virtual u64 GetDataOffset(); + + virtual const HFS0FileEntry* GetFileEntry(unsigned int index); + virtual const HFS0FileEntry* GetFileEntryByName(std::string name); + virtual const HFS0FileEntry* GetFileEntryByNcaId(const NcmContentId& ncaId); + virtual std::vector GetFileEntriesByExtension(std::string extension); + + virtual const char* GetFileEntryName(const HFS0FileEntry* fileEntry); + }; +} \ No newline at end of file