From 91e60248ca1a6b2d3340c953d14a3ca19fb9db70 Mon Sep 17 00:00:00 2001 From: mrdude2478 Date: Tue, 26 Apr 2022 01:23:12 +0100 Subject: [PATCH] Add files via upload --- include/nx/content_meta.hpp | 73 +++++++++++++++++++++++++++ include/nx/fs.hpp | 99 +++++++++++++++++++++++++++++++++++++ include/nx/ipc/es.h | 42 ++++++++++++++++ include/nx/ipc/ns_ext.h | 53 ++++++++++++++++++++ include/nx/ipc/tin_ipc.h | 34 +++++++++++++ include/nx/nca_writer.h | 62 +++++++++++++++++++++++ include/nx/ncm.hpp | 58 ++++++++++++++++++++++ include/nx/usbhdd.h | 81 ++++++++++++++++++++++++++++++ 8 files changed, 502 insertions(+) create mode 100644 include/nx/content_meta.hpp create mode 100644 include/nx/fs.hpp create mode 100644 include/nx/ipc/es.h create mode 100644 include/nx/ipc/ns_ext.h create mode 100644 include/nx/ipc/tin_ipc.h create mode 100644 include/nx/nca_writer.h create mode 100644 include/nx/ncm.hpp create mode 100644 include/nx/usbhdd.h diff --git a/include/nx/content_meta.hpp b/include/nx/content_meta.hpp new file mode 100644 index 0000000..fed9279 --- /dev/null +++ b/include/nx/content_meta.hpp @@ -0,0 +1,73 @@ +/* +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 "data/byte_buffer.hpp" + +namespace nx::ncm +{ + struct PackagedContentInfo + { + u8 hash[0x20]; + NcmContentInfo content_info; + } PACKED; + + struct PackagedContentMetaHeader + { + u64 title_id; + u32 version; + u8 type; + u8 _0xd; + u16 extended_header_size; + u16 content_count; + u16 content_meta_count; + u8 attributes; + u8 storage_id; + u8 install_type; + bool comitted; + u32 required_system_version; + u32 _0x1c; + }; + + static_assert(sizeof(PackagedContentMetaHeader) == 0x20, "PackagedContentMetaHeader must be 0x20!"); + + class ContentMeta final + { + private: + tin::data::ByteBuffer m_bytes; + + public: + ContentMeta(); + ContentMeta(u8* data, size_t size); + + PackagedContentMetaHeader GetPackagedContentMetaHeader(); + NcmContentMetaKey GetContentMetaKey(); + std::vector GetContentInfos(); + + void GetInstallContentMeta(tin::data::ByteBuffer& installContentMetaBuffer, NcmContentInfo& cnmtContentInfo, bool ignoreReqFirmVersion); + }; +} \ No newline at end of file diff --git a/include/nx/fs.hpp b/include/nx/fs.hpp new file mode 100644 index 0000000..cbcc08c --- /dev/null +++ b/include/nx/fs.hpp @@ -0,0 +1,99 @@ +/* +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 + +extern "C" +{ +#include +#include +} + +#include "nx/ipc/tin_ipc.h" + +namespace nx::fs +{ + class IFileSystem; + + class IFile + { + friend IFileSystem; + + private: + FsFile m_file; + + IFile(FsFile& file); + + public: + // Don't allow copying, or garbage may be closed by the destructor + IFile& operator=(const IFile&) = delete; + IFile(const IFile&) = delete; + + ~IFile(); + + void Read(u64 offset, void* buf, size_t size); + s64 GetSize(); + }; + + class IDirectory + { + friend IFileSystem; + + private: + FsDir m_dir; + + IDirectory(FsDir& dir); + + public: + // Don't allow copying, or garbage may be closed by the destructor + IDirectory& operator=(const IDirectory&) = delete; + IDirectory(const IDirectory&) = delete; + + ~IDirectory(); + + void Read(s64 inval, FsDirectoryEntry* buf, size_t numEntries); + u64 GetEntryCount(); + }; + + class IFileSystem + { + private: + FsFileSystem m_fileSystem; + + public: + // Don't allow copying, or garbage may be closed by the destructor + IFileSystem& operator=(const IFileSystem&) = delete; + IFileSystem(const IFileSystem&) = delete; + + IFileSystem(); + ~IFileSystem(); + + Result OpenSdFileSystem(); + void OpenFileSystemWithId(std::string path, FsFileSystemType fileSystemType, u64 titleId); + void CloseFileSystem(); + + IFile OpenFile(std::string path); + IDirectory OpenDirectory(std::string path, int flags); + }; +} \ No newline at end of file diff --git a/include/nx/ipc/es.h b/include/nx/ipc/es.h new file mode 100644 index 0000000..60bdfeb --- /dev/null +++ b/include/nx/ipc/es.h @@ -0,0 +1,42 @@ +/* +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 + +typedef struct { + u8 c[0x10]; +} RightsId; + +Result esInitialize(); +void esExit(); +Service* esGetServiceSession(); + +Result esImportTicket(void const *tikBuf, size_t tikSize, void const *certBuf, size_t certSize); //1 +Result esDeleteTicket(const RightsId *rightsIdBuf, size_t bufSize); //3 +Result esGetTitleKey(const RightsId *rightsId, u8 *outBuf, size_t bufSize); //8 +Result esCountCommonTicket(u32 *numTickets); //9 +Result esCountPersonalizedTicket(u32 *numTickets); // 10 +Result esListCommonTicket(u32 *numRightsIdsWritten, RightsId *outBuf, size_t bufSize); +Result esListPersonalizedTicket(u32 *numRightsIdsWritten, RightsId *outBuf, size_t bufSize); +Result esGetCommonTicketData(u64 *unkOut, void *outBuf1, size_t bufSize1, const RightsId* rightsId); \ No newline at end of file diff --git a/include/nx/ipc/ns_ext.h b/include/nx/ipc/ns_ext.h new file mode 100644 index 0000000..ce2cd23 --- /dev/null +++ b/include/nx/ipc/ns_ext.h @@ -0,0 +1,53 @@ +/* +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 + +typedef struct { + u64 titleID; + u64 unk; + u64 size; +} PACKED ApplicationRecord; + +typedef struct { + NcmContentMetaKey metaRecord; + u64 storageId; +} PACKED ContentStorageRecord; + +Result nsextInitialize(void); +void nsextExit(void); + +Result nsPushApplicationRecord(u64 title_id, u8 last_modified_event, ContentStorageRecord *content_records_buf, size_t buf_size); +Result nsListApplicationRecordContentMeta(u64 offset, u64 titleID, void *out_buf, size_t out_buf_size, u32 *entries_read_out); +Result nsDeleteApplicationRecord(u64 titleID); +Result nsLaunchApplication(u64 titleID); +Result nsPushLaunchVersion(u64 titleID, u32 version); +Result nsDisableApplicationAutoUpdate(u64 titleID); +Result nsGetContentMetaStorage(const NcmContentMetaKey *record, u8 *out); +Result nsBeginInstallApplication(u64 tid, u32 unk, u8 storageId); +Result nsInvalidateAllApplicationControlCache(void); +Result nsInvalidateApplicationControlCache(u64 tid); +Result nsCheckApplicationLaunchRights(u64 tid); +Result nsGetApplicationContentPath(u64 titleId, u8 type, char *outBuf, size_t bufSize); diff --git a/include/nx/ipc/tin_ipc.h b/include/nx/ipc/tin_ipc.h new file mode 100644 index 0000000..cb5d970 --- /dev/null +++ b/include/nx/ipc/tin_ipc.h @@ -0,0 +1,34 @@ +/* +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 + +#ifdef __cplusplus +extern "C" { +#endif + +#include "nx/ipc/es.h" +#include "nx/ipc/ns_ext.h" + +#ifdef __cplusplus +} +#endif \ No newline at end of file diff --git a/include/nx/nca_writer.h b/include/nx/nca_writer.h new file mode 100644 index 0000000..4f8c12a --- /dev/null +++ b/include/nx/nca_writer.h @@ -0,0 +1,62 @@ +/* +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 "nx/ncm.hpp" +#include +#include "install/nca.hpp" + +class NcaBodyWriter +{ +public: + NcaBodyWriter(const NcmContentId& ncaId, u64 offset, std::shared_ptr& contentStorage); + virtual ~NcaBodyWriter(); + virtual u64 write(const u8* ptr, u64 sz); + + bool isOpen() const; + +protected: + std::shared_ptr m_contentStorage; + NcmContentId m_ncaId; + + u64 m_offset; +}; + +class NcaWriter +{ +public: + NcaWriter(const NcmContentId& ncaId, std::shared_ptr& contentStorage); + virtual ~NcaWriter(); + + bool isOpen() const; + bool close(); + u64 write(const u8* ptr, u64 sz); + void flushHeader(); + +protected: + NcmContentId m_ncaId; + std::shared_ptr m_contentStorage; + std::vector m_buffer; + std::shared_ptr m_writer; +}; diff --git a/include/nx/ncm.hpp b/include/nx/ncm.hpp new file mode 100644 index 0000000..faa654c --- /dev/null +++ b/include/nx/ncm.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 + +extern "C" +{ +#include +#include +} + +#include "nx/ipc/tin_ipc.h" + +namespace nx::ncm +{ + class ContentStorage final + { + private: + NcmContentStorage m_contentStorage; + + public: + // Don't allow copying, or garbage may be closed by the destructor + ContentStorage& operator=(const ContentStorage&) = delete; + ContentStorage(const ContentStorage&) = delete; + + ContentStorage(NcmStorageId storageId); + ~ContentStorage(); + + void CreatePlaceholder(const NcmContentId &placeholderId, const NcmPlaceHolderId ®isteredId, size_t size); + void DeletePlaceholder(const NcmPlaceHolderId &placeholderId); + void WritePlaceholder(const NcmPlaceHolderId &placeholderId, u64 offset, void *buffer, size_t bufSize); + void Register(const NcmPlaceHolderId &placeholderId, const NcmContentId ®isteredId); + void Delete(const NcmContentId ®isteredId); + bool Has(const NcmContentId ®isteredId); + std::string GetPath(const NcmContentId ®isteredId); + }; +} \ No newline at end of file diff --git a/include/nx/usbhdd.h b/include/nx/usbhdd.h new file mode 100644 index 0000000..e5dfe36 --- /dev/null +++ b/include/nx/usbhdd.h @@ -0,0 +1,81 @@ +#pragma once + +/* +Microsoft Public License (Ms-PL) + +This license governs use of the accompanying software. If you use the +software, you accept this license. If you do not accept the license, +do not use the software. + + 1. Definitions + + The terms "reproduce," "reproduction," "derivative works," and + "distribution" have the same meaning here as under U.S. copyright + law. + + A "contribution" is the original software, or any additions or + changes to the software. + + A "contributor" is any person that distributes its contribution + under this license. + + "Licensed patents" are a contributor's patent claims that read + directly on its contribution. + + 2. Grant of Rights + + (A) Copyright Grant- Subject to the terms of this license, + including the license conditions and limitations in section 3, + each contributor grants you a non-exclusive, worldwide, + royalty-free copyright license to reproduce its contribution, + prepare derivative works of its contribution, and distribute its + contribution or any derivative works that you create. + + (B) Patent Grant- Subject to the terms of this license, including + the license conditions and limitations in section 3, each + contributor grants you a non-exclusive, worldwide, royalty-free + license under its licensed patents to make, have made, use, sell, + offer for sale, import, and/or otherwise dispose of its + contribution in the software or derivative works of the + contribution in the software. + + 3. Conditions and Limitations + + (A) No Trademark License- This license does not grant you rights + to use any contributors' name, logo, or trademarks. + + (B) If you bring a patent claim against any contributor over + patents that you claim are infringed by the software, your patent + license from such contributor to the software ends automatically. + + (C) If you distribute any portion of the software, you must retain + all copyright, patent, trademark, and attribution notices that are + present in the software. + + (D) If you distribute any portion of the software in source code + form, you may do so only under this license by including a + complete copy of this license with your distribution. If you + distribute any portion of the software in compiled or object code + form, you may only do so under a license that complies with this + license. + + (E) You may not distribute, copy, use, or link any portion of this + code to any other code that requires distribution of source code. + + (F) The software is licensed "as-is." You bear the risk of using + it. The contributors give no express warranties, guarantees, or + conditions. You may have additional consumer rights under your + local laws which this license cannot change. To the extent + permitted under your local laws, the contributors exclude the + implied warranties of merchantability, fitness for a particular + purpose and non-infringement. +*/ + +namespace nx::hdd +{ + const char* rootPath(u32 index = 0); + u32 count(); + + bool init(); + bool exit(); +}