Add files via upload

This commit is contained in:
mrdude2478 2022-04-26 01:23:12 +01:00 committed by GitHub
parent ecaa5f0b53
commit 91e60248ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 502 additions and 0 deletions

View File

@ -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 <switch/services/ncm.h>
#include <switch/types.h>
#include <vector>
#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<NcmContentInfo> GetContentInfos();
void GetInstallContentMeta(tin::data::ByteBuffer& installContentMetaBuffer, NcmContentInfo& cnmtContentInfo, bool ignoreReqFirmVersion);
};
}

99
include/nx/fs.hpp Normal file
View File

@ -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 <string>
extern "C"
{
#include <switch/types.h>
#include <switch/services/fs.h>
}
#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);
};
}

42
include/nx/ipc/es.h Normal file
View File

@ -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 <switch/services/ncm.h>
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);

53
include/nx/ipc/ns_ext.h Normal file
View File

@ -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 <switch/services/ns.h>
#include <switch/services/ncm.h>
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);

34
include/nx/ipc/tin_ipc.h Normal file
View File

@ -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

62
include/nx/nca_writer.h Normal file
View File

@ -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 <switch.h>
#include <vector>
#include "nx/ncm.hpp"
#include <memory>
#include "install/nca.hpp"
class NcaBodyWriter
{
public:
NcaBodyWriter(const NcmContentId& ncaId, u64 offset, std::shared_ptr<nx::ncm::ContentStorage>& contentStorage);
virtual ~NcaBodyWriter();
virtual u64 write(const u8* ptr, u64 sz);
bool isOpen() const;
protected:
std::shared_ptr<nx::ncm::ContentStorage> m_contentStorage;
NcmContentId m_ncaId;
u64 m_offset;
};
class NcaWriter
{
public:
NcaWriter(const NcmContentId& ncaId, std::shared_ptr<nx::ncm::ContentStorage>& contentStorage);
virtual ~NcaWriter();
bool isOpen() const;
bool close();
u64 write(const u8* ptr, u64 sz);
void flushHeader();
protected:
NcmContentId m_ncaId;
std::shared_ptr<nx::ncm::ContentStorage> m_contentStorage;
std::vector<u8> m_buffer;
std::shared_ptr<NcaBodyWriter> m_writer;
};

58
include/nx/ncm.hpp Normal file
View File

@ -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 <string>
extern "C"
{
#include <switch/services/fs.h>
#include <switch/services/ncm.h>
}
#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 &registeredId, 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 &registeredId);
void Delete(const NcmContentId &registeredId);
bool Has(const NcmContentId &registeredId);
std::string GetPath(const NcmContentId &registeredId);
};
}

81
include/nx/usbhdd.h Normal file
View File

@ -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();
}