mirror of
https://github.com/hax4dazy/TinWoo.git
synced 2025-02-09 19:25:05 +01:00
Add files via upload
This commit is contained in:
parent
0db990d4f3
commit
9114b2bb2b
28
include/HDInstall.hpp
Normal file
28
include/HDInstall.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
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 <filesystem>
|
||||
#include <vector>
|
||||
namespace nspInstStuff_B {
|
||||
void installNspFromFile(std::vector<std::filesystem::path> ourNspList, int whereToInstall);
|
||||
}
|
89
include/data/buffered_placeholder_writer.hpp
Normal file
89
include/data/buffered_placeholder_writer.hpp
Normal file
@ -0,0 +1,89 @@
|
||||
/*
|
||||
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 <atomic>
|
||||
#include <switch/types.h>
|
||||
#include <memory>
|
||||
|
||||
#include "nx/ncm.hpp"
|
||||
#include "nx/nca_writer.h"
|
||||
|
||||
namespace tin::data
|
||||
{
|
||||
static const size_t BUFFER_SEGMENT_DATA_SIZE = 0x800000; // Approximately 8MB
|
||||
extern int NUM_BUFFER_SEGMENTS;
|
||||
|
||||
struct BufferSegment
|
||||
{
|
||||
std::atomic_bool isFinalized = false;
|
||||
u64 writeOffset = 0;
|
||||
u8 data[BUFFER_SEGMENT_DATA_SIZE] = { 0 };
|
||||
};
|
||||
|
||||
// Receives data in a circular buffer split into 8MB segments
|
||||
class BufferedPlaceholderWriter
|
||||
{
|
||||
private:
|
||||
size_t m_totalDataSize = 0;
|
||||
size_t m_sizeBuffered = 0;
|
||||
size_t m_sizeWrittenToPlaceholder = 0;
|
||||
|
||||
// The current segment to which further data will be appended
|
||||
u64 m_currentFreeSegment = 0;
|
||||
BufferSegment* m_currentFreeSegmentPtr = NULL;
|
||||
// The current segment that will be written to the placeholder
|
||||
u64 m_currentSegmentToWrite = 0;
|
||||
BufferSegment* m_currentSegmentToWritePtr = NULL;
|
||||
|
||||
std::unique_ptr<BufferSegment[]> m_bufferSegments;
|
||||
|
||||
std::shared_ptr<nx::ncm::ContentStorage> m_contentStorage;
|
||||
NcmContentId m_ncaId;
|
||||
NcaWriter m_writer;
|
||||
|
||||
public:
|
||||
BufferedPlaceholderWriter(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId ncaId, size_t totalDataSize);
|
||||
|
||||
void AppendData(void* source, size_t length);
|
||||
bool CanAppendData(size_t length);
|
||||
|
||||
void WriteSegmentToPlaceholder();
|
||||
bool CanWriteSegmentToPlaceholder();
|
||||
|
||||
// Determine the number of segments required to fit data of this size
|
||||
u32 CalcNumSegmentsRequired(size_t size);
|
||||
|
||||
// Check if there are enough free segments to fit data of this size
|
||||
bool IsSizeAvailable(size_t size);
|
||||
|
||||
bool IsBufferDataComplete();
|
||||
bool IsPlaceholderComplete();
|
||||
|
||||
size_t GetTotalDataSize();
|
||||
size_t GetSizeBuffered();
|
||||
size_t GetSizeWrittenToPlaceholder();
|
||||
|
||||
void DebugPrintBuffers();
|
||||
};
|
||||
}
|
72
include/data/byte_buffer.hpp
Normal file
72
include/data/byte_buffer.hpp
Normal file
@ -0,0 +1,72 @@
|
||||
/*
|
||||
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/types.h>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
namespace tin::data
|
||||
{
|
||||
class ByteBuffer
|
||||
{
|
||||
private:
|
||||
std::vector<u8> m_buffer;
|
||||
|
||||
public:
|
||||
ByteBuffer(size_t reserveSize = 0);
|
||||
|
||||
size_t GetSize();
|
||||
u8* GetData(); // TODO: Remove this, it shouldn't be needed
|
||||
void Resize(size_t size);
|
||||
|
||||
void DebugPrintContents();
|
||||
|
||||
template <typename T>
|
||||
T Read(u64 offset)
|
||||
{
|
||||
if (offset + sizeof(T) <= m_buffer.size())
|
||||
return *((T*)&m_buffer.data()[offset]);
|
||||
|
||||
T def;
|
||||
memset(&def, 0, sizeof(T));
|
||||
return def;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void Write(T data, u64 offset)
|
||||
{
|
||||
size_t requiredSize = offset + sizeof(T);
|
||||
|
||||
if (requiredSize > m_buffer.size())
|
||||
m_buffer.resize(requiredSize, 0);
|
||||
|
||||
memcpy(m_buffer.data() + offset, &data, sizeof(T));
|
||||
}
|
||||
template <typename T>
|
||||
void Append(T data)
|
||||
{
|
||||
this->Write(data, this->GetSize());
|
||||
}
|
||||
};
|
||||
}
|
51
include/data/byte_stream.hpp
Normal file
51
include/data/byte_stream.hpp
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
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/types.h>
|
||||
#include "data/byte_buffer.hpp"
|
||||
|
||||
namespace tin::data
|
||||
{
|
||||
class ByteStream
|
||||
{
|
||||
protected:
|
||||
u64 m_offset = 0;
|
||||
|
||||
public:
|
||||
virtual void ReadBytes(void* dest, size_t length) = 0;
|
||||
};
|
||||
|
||||
// NOTE: This isn't generally useful, it's mainly for things like libpng
|
||||
// which rely on streams
|
||||
class BufferedByteStream : public ByteStream
|
||||
{
|
||||
private:
|
||||
ByteBuffer m_byteBuffer;
|
||||
|
||||
public:
|
||||
BufferedByteStream(ByteBuffer buffer);
|
||||
|
||||
void ReadBytes(void* dest, size_t length) override;
|
||||
};
|
||||
}
|
57
include/install/hfs0.hpp
Normal file
57
include/install/hfs0.hpp
Normal file
@ -0,0 +1,57 @@
|
||||
#pragma once
|
||||
|
||||
#include <switch/types.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
}
|
40
include/install/http_nsp.hpp
Normal file
40
include/install/http_nsp.hpp
Normal file
@ -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 <memory>
|
||||
|
||||
namespace tin::install::nsp
|
||||
{
|
||||
class HTTPNSP : public NSP
|
||||
{
|
||||
public:
|
||||
tin::network::HTTPDownload m_download;
|
||||
|
||||
HTTPNSP(std::string url);
|
||||
|
||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId placeholderId) override;
|
||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
||||
};
|
||||
}
|
41
include/install/http_xci.hpp
Normal file
41
include/install/http_xci.hpp
Normal file
@ -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 <memory>
|
||||
|
||||
namespace tin::install::xci
|
||||
{
|
||||
class HTTPXCI : public XCI
|
||||
{
|
||||
public:
|
||||
tin::network::HTTPDownload m_download;
|
||||
|
||||
HTTPXCI(std::string url);
|
||||
|
||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId placeholderId) override;
|
||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
||||
};
|
||||
}
|
69
include/install/install.hpp
Normal file
69
include/install/install.hpp
Normal file
@ -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 <switch/services/fs.h>
|
||||
}
|
||||
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#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<nx::ncm::ContentMeta> m_contentMeta;
|
||||
|
||||
Install(NcmStorageId destStorageId, bool ignoreReqFirmVersion);
|
||||
|
||||
virtual std::vector<std::tuple<nx::ncm::ContentMeta, NcmContentInfo>> 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);
|
||||
};
|
||||
}
|
45
include/install/install_nsp.hpp
Normal file
45
include/install/install_nsp.hpp
Normal file
@ -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 <switch.h>
|
||||
#include <string>
|
||||
#include "install/install.hpp"
|
||||
#include "install/nsp.hpp"
|
||||
|
||||
namespace tin::install::nsp
|
||||
{
|
||||
class NSPInstall : public Install
|
||||
{
|
||||
private:
|
||||
const std::shared_ptr<NSP> m_NSP;
|
||||
|
||||
protected:
|
||||
std::vector<std::tuple<nx::ncm::ContentMeta, NcmContentInfo>> ReadCNMT() override;
|
||||
void InstallNCA(const NcmContentId& ncaId) override;
|
||||
void InstallTicketCert() override;
|
||||
|
||||
public:
|
||||
NSPInstall(NcmStorageId destStorageId, bool ignoreReqFirmVersion, const std::shared_ptr<NSP>& remoteNSP);
|
||||
};
|
||||
}
|
47
include/install/install_xci.hpp
Normal file
47
include/install/install_xci.hpp
Normal file
@ -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 <switch.h>
|
||||
#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<tin::install::xci::XCI> m_xci;
|
||||
|
||||
protected:
|
||||
std::vector<std::tuple<nx::ncm::ContentMeta, NcmContentInfo>> ReadCNMT() override;
|
||||
void InstallNCA(const NcmContentId& ncaId) override;
|
||||
void InstallTicketCert() override;
|
||||
|
||||
public:
|
||||
XCIInstallTask(NcmStorageId destStorageId, bool ignoreReqFirmVersion, const std::shared_ptr<XCI>& xci);
|
||||
};
|
||||
};
|
||||
|
77
include/install/nca.hpp
Normal file
77
include/install/nca.hpp
Normal file
@ -0,0 +1,77 @@
|
||||
#pragma once
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#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");
|
||||
}
|
57
include/install/nsp.hpp
Normal file
57
include/install/nsp.hpp
Normal file
@ -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 <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <switch/types.h>
|
||||
#include "install/pfs0.hpp"
|
||||
#include "nx/ncm.hpp"
|
||||
#include "util/network_util.hpp"
|
||||
|
||||
namespace tin::install::nsp
|
||||
{
|
||||
class NSP
|
||||
{
|
||||
protected:
|
||||
std::vector<u8> m_headerBytes;
|
||||
|
||||
NSP();
|
||||
|
||||
public:
|
||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& 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<const PFS0FileEntry*> GetFileEntriesByExtension(std::string extension);
|
||||
|
||||
virtual const char* GetFileEntryName(const PFS0FileEntry* fileEntry);
|
||||
};
|
||||
}
|
48
include/install/pfs0.hpp
Normal file
48
include/install/pfs0.hpp
Normal file
@ -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 <switch/types.h>
|
||||
|
||||
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");
|
||||
}
|
40
include/install/sdmc_nsp.hpp
Normal file
40
include/install/sdmc_nsp.hpp
Normal file
@ -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<nx::ncm::ContentStorage>& contentStorage, NcmContentId ncaId) override;
|
||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
||||
private:
|
||||
FILE* m_nspFile;
|
||||
};
|
||||
}
|
40
include/install/sdmc_xci.hpp
Normal file
40
include/install/sdmc_xci.hpp
Normal file
@ -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<nx::ncm::ContentStorage>& contentStorage, NcmContentId ncaId) override;
|
||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
||||
private:
|
||||
FILE* m_xciFile;
|
||||
};
|
||||
}
|
46
include/install/simple_filesystem.hpp
Normal file
46
include/install/simple_filesystem.hpp
Normal file
@ -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 <functional>
|
||||
#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);
|
||||
};
|
||||
}
|
41
include/install/usb_nsp.hpp
Normal file
41
include/install/usb_nsp.hpp
Normal file
@ -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 <string>
|
||||
#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<nx::ncm::ContentStorage>& contentStorage, NcmContentId placeholderId) override;
|
||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
||||
};
|
||||
}
|
41
include/install/usb_xci.hpp
Normal file
41
include/install/usb_xci.hpp
Normal file
@ -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 <string>
|
||||
#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<nx::ncm::ContentStorage>& contentStorage, NcmContentId placeholderId) override;
|
||||
virtual void BufferData(void* buf, off_t offset, size_t size) override;
|
||||
};
|
||||
}
|
58
include/install/xci.hpp
Normal file
58
include/install/xci.hpp
Normal 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 <functional>
|
||||
#include <vector>
|
||||
|
||||
#include <switch/types.h>
|
||||
#include "install/hfs0.hpp"
|
||||
#include "nx/ncm.hpp"
|
||||
#include <memory>
|
||||
|
||||
namespace tin::install::xci
|
||||
{
|
||||
class XCI
|
||||
{
|
||||
protected:
|
||||
u64 m_secureHeaderOffset;
|
||||
std::vector<u8> m_secureHeaderBytes;
|
||||
|
||||
XCI();
|
||||
|
||||
public:
|
||||
virtual void StreamToPlaceholder(std::shared_ptr<nx::ncm::ContentStorage>& 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<const HFS0FileEntry*> GetFileEntriesByExtension(std::string extension);
|
||||
|
||||
virtual const char* GetFileEntryName(const HFS0FileEntry* fileEntry);
|
||||
};
|
||||
}
|
28
include/netInstall.hpp
Normal file
28
include/netInstall.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
#include <vector>
|
||||
extern bool netConnected;
|
||||
|
||||
namespace netInstStuff {
|
||||
void installTitleNet(std::vector<std::string> ourUrlList, int ourStorage, std::vector<std::string> urlListAltNames, std::string ourSource);
|
||||
std::vector<std::string> OnSelected();
|
||||
}
|
73
include/nx/content_meta.hpp
Normal file
73
include/nx/content_meta.hpp
Normal 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);
|
||||
};
|
||||
}
|
102
include/nx/fs.hpp
Normal file
102
include/nx/fs.hpp
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
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);
|
||||
};
|
||||
|
||||
std::string GetFreeStorageSpace();
|
||||
std::string convertSize(s64 size);
|
||||
}
|
42
include/nx/ipc/es.h
Normal file
42
include/nx/ipc/es.h
Normal 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
53
include/nx/ipc/ns_ext.h
Normal 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
34
include/nx/ipc/tin_ipc.h
Normal 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
62
include/nx/nca_writer.h
Normal 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
58
include/nx/ncm.hpp
Normal 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
81
include/nx/usbhdd.h
Normal 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();
|
||||
}
|
28
include/sdInstall.hpp
Normal file
28
include/sdInstall.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
/*
|
||||
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 <filesystem>
|
||||
#include <vector>
|
||||
namespace nspInstStuff {
|
||||
void installNspFromFile(std::vector<std::filesystem::path> ourNspList, int whereToInstall);
|
||||
}
|
3
include/sigInstall.hpp
Normal file
3
include/sigInstall.hpp
Normal file
@ -0,0 +1,3 @@
|
||||
namespace sig {
|
||||
void installSigPatches();
|
||||
}
|
32
include/ui/HDInstPage.hpp
Normal file
32
include/ui/HDInstPage.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <filesystem>
|
||||
#include <pu/Plutonium>
|
||||
|
||||
using namespace pu::ui::elm;
|
||||
namespace inst::ui {
|
||||
class HDInstPage : public pu::ui::Layout
|
||||
{
|
||||
public:
|
||||
HDInstPage();
|
||||
PU_SMART_CTOR(HDInstPage)
|
||||
pu::ui::elm::Menu::Ref menu;
|
||||
void startInstall();
|
||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint touch_pos);
|
||||
TextBlock::Ref pageInfoText;
|
||||
void drawMenuItems(bool clearItems, std::filesystem::path ourPath);
|
||||
private:
|
||||
std::vector<std::filesystem::path> ourDirectories;
|
||||
std::vector<std::filesystem::path> ourFiles;
|
||||
std::vector<std::filesystem::path> selectedTitles;
|
||||
std::filesystem::path currentDir;
|
||||
TextBlock::Ref butText;
|
||||
Rectangle::Ref topRect;
|
||||
Rectangle::Ref infoRect;
|
||||
Rectangle::Ref botRect;
|
||||
Image::Ref titleImage;
|
||||
TextBlock::Ref appVersionText;
|
||||
void followDirectory();
|
||||
void selectNsp(int selectedIndex);
|
||||
bool show_file_ext;
|
||||
};
|
||||
}
|
25
include/ui/MainApplication.hpp
Normal file
25
include/ui/MainApplication.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include <pu/Plutonium>
|
||||
#include "ui/mainPage.hpp"
|
||||
#include "ui/netInstPage.hpp"
|
||||
#include "ui/sdInstPage.hpp"
|
||||
#include "ui/HDInstPage.hpp"
|
||||
#include "ui/usbInstPage.hpp"
|
||||
#include "ui/instPage.hpp"
|
||||
#include "ui/optionsPage.hpp"
|
||||
|
||||
namespace inst::ui {
|
||||
class MainApplication : public pu::ui::Application {
|
||||
public:
|
||||
using Application::Application;
|
||||
PU_SMART_CTOR(MainApplication)
|
||||
void OnLoad() override;
|
||||
MainPage::Ref mainPage;
|
||||
netInstPage::Ref netinstPage;
|
||||
sdInstPage::Ref sdinstPage;
|
||||
HDInstPage::Ref HDinstPage;
|
||||
usbInstPage::Ref usbinstPage;
|
||||
instPage::Ref instpage;
|
||||
optionsPage::Ref optionspage;
|
||||
};
|
||||
}
|
31
include/ui/instPage.hpp
Normal file
31
include/ui/instPage.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
#include <pu/Plutonium>
|
||||
|
||||
using namespace pu::ui::elm;
|
||||
namespace inst::ui {
|
||||
class instPage : public pu::ui::Layout
|
||||
{
|
||||
public:
|
||||
instPage();
|
||||
PU_SMART_CTOR(instPage)
|
||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint touch_pos);
|
||||
TextBlock::Ref pageInfoText;
|
||||
TextBlock::Ref installInfoText;
|
||||
TextBlock::Ref sdInfoText;
|
||||
TextBlock::Ref nandInfoText;
|
||||
TextBlock::Ref countText;
|
||||
Image::Ref awooImage;
|
||||
pu::ui::elm::ProgressBar::Ref installBar;
|
||||
static void setTopInstInfoText(std::string ourText);
|
||||
static void setInstInfoText(std::string ourText);
|
||||
static void filecount(std::string ourText);
|
||||
static void setInstBarPerc(double ourPercent);
|
||||
static void loadMainMenu();
|
||||
static void loadInstallScreen();
|
||||
private:
|
||||
Rectangle::Ref infoRect;
|
||||
Rectangle::Ref topRect;
|
||||
Image::Ref titleImage;
|
||||
TextBlock::Ref appVersionText;
|
||||
};
|
||||
}
|
38
include/ui/mainPage.hpp
Normal file
38
include/ui/mainPage.hpp
Normal file
@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
#include <pu/Plutonium>
|
||||
|
||||
using namespace pu::ui::elm;
|
||||
namespace inst::ui {
|
||||
class MainPage : public pu::ui::Layout
|
||||
{
|
||||
public:
|
||||
MainPage();
|
||||
PU_SMART_CTOR(MainPage)
|
||||
void installMenuItem_Click();
|
||||
void netInstallMenuItem_Click();
|
||||
void usbInstallMenuItem_Click();
|
||||
void HdInstallMenuItem_Click();
|
||||
void settingsMenuItem_Click();
|
||||
void exitMenuItem_Click();
|
||||
void onInput(u64 Down, u64 Up, const u64 Held, pu::ui::TouchPoint touch_pos);
|
||||
Image::Ref awooImage;
|
||||
|
||||
private:
|
||||
bool appletFinished;
|
||||
bool updateFinished;
|
||||
TextBlock::Ref butText;
|
||||
Rectangle::Ref topRect;
|
||||
Rectangle::Ref botRect;
|
||||
Image::Ref titleImage;
|
||||
TextBlock::Ref appVersionText;
|
||||
pu::ui::elm::Menu::Ref optionMenu;
|
||||
pu::ui::elm::MenuItem::Ref installMenuItem;
|
||||
pu::ui::elm::MenuItem::Ref netInstallMenuItem;
|
||||
pu::ui::elm::MenuItem::Ref usbInstallMenuItem;
|
||||
pu::ui::elm::MenuItem::Ref HdInstallMenuItem;
|
||||
pu::ui::elm::MenuItem::Ref settingsMenuItem;
|
||||
pu::ui::elm::MenuItem::Ref exitMenuItem;
|
||||
Image::Ref eggImage;
|
||||
Image::Ref hdd;
|
||||
};
|
||||
}
|
32
include/ui/netInstPage.hpp
Normal file
32
include/ui/netInstPage.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <pu/Plutonium>
|
||||
|
||||
using namespace pu::ui::elm;
|
||||
namespace inst::ui {
|
||||
class netInstPage : public pu::ui::Layout
|
||||
{
|
||||
public:
|
||||
netInstPage();
|
||||
PU_SMART_CTOR(netInstPage)
|
||||
void startInstall(bool urlMode);
|
||||
void startNetwork();
|
||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint touch_pos);
|
||||
TextBlock::Ref pageInfoText;
|
||||
private:
|
||||
std::vector<std::string> ourUrls;
|
||||
std::vector<std::string> modded;
|
||||
std::vector<std::string> selectedUrls;
|
||||
std::vector<std::string> alternativeNames;
|
||||
TextBlock::Ref butText;
|
||||
Rectangle::Ref topRect;
|
||||
Rectangle::Ref infoRect;
|
||||
Rectangle::Ref botRect;
|
||||
Image::Ref titleImage;
|
||||
TextBlock::Ref appVersionText;
|
||||
pu::ui::elm::Menu::Ref menu;
|
||||
Image::Ref infoImage;
|
||||
void drawMenuItems(bool clearItems);
|
||||
void drawMenuItems_withext(bool clearItems);
|
||||
void selectTitle(int selectedIndex);
|
||||
};
|
||||
}
|
27
include/ui/optionsPage.hpp
Normal file
27
include/ui/optionsPage.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
#include <pu/Plutonium>
|
||||
|
||||
using namespace pu::ui::elm;
|
||||
namespace inst::ui {
|
||||
class optionsPage : public pu::ui::Layout
|
||||
{
|
||||
public:
|
||||
optionsPage();
|
||||
PU_SMART_CTOR(optionsPage)
|
||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint touch_pos);
|
||||
static void askToUpdate(std::vector<std::string> updateInfo);
|
||||
void setMenuText();
|
||||
private:
|
||||
TextBlock::Ref butText;
|
||||
Rectangle::Ref topRect;
|
||||
Rectangle::Ref infoRect;
|
||||
Rectangle::Ref botRect;
|
||||
Image::Ref titleImage;
|
||||
TextBlock::Ref appVersionText;
|
||||
TextBlock::Ref pageInfoText;
|
||||
pu::ui::elm::Menu::Ref menu;
|
||||
//void setMenuText();
|
||||
std::string getMenuOptionIcon(bool ourBool);
|
||||
std::string getMenuLanguage(int ourLangCode);
|
||||
};
|
||||
}
|
32
include/ui/sdInstPage.hpp
Normal file
32
include/ui/sdInstPage.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <filesystem>
|
||||
#include <pu/Plutonium>
|
||||
|
||||
using namespace pu::ui::elm;
|
||||
namespace inst::ui {
|
||||
class sdInstPage : public pu::ui::Layout
|
||||
{
|
||||
public:
|
||||
sdInstPage();
|
||||
PU_SMART_CTOR(sdInstPage)
|
||||
pu::ui::elm::Menu::Ref menu;
|
||||
void startInstall();
|
||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint touch_pos);
|
||||
TextBlock::Ref pageInfoText;
|
||||
void drawMenuItems(bool clearItems, std::filesystem::path ourPath);
|
||||
private:
|
||||
std::vector<std::filesystem::path> ourDirectories;
|
||||
std::vector<std::filesystem::path> ourFiles;
|
||||
std::vector<std::filesystem::path> selectedTitles;
|
||||
std::filesystem::path currentDir;
|
||||
TextBlock::Ref butText;
|
||||
Rectangle::Ref topRect;
|
||||
Rectangle::Ref infoRect;
|
||||
Rectangle::Ref botRect;
|
||||
Image::Ref titleImage;
|
||||
TextBlock::Ref appVersionText;
|
||||
void followDirectory();
|
||||
void selectNsp(int selectedIndex);
|
||||
bool show_ext;
|
||||
};
|
||||
}
|
32
include/ui/usbInstPage.hpp
Normal file
32
include/ui/usbInstPage.hpp
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
#include <pu/Plutonium>
|
||||
|
||||
using namespace pu::ui::elm;
|
||||
namespace inst::ui {
|
||||
class usbInstPage : public pu::ui::Layout
|
||||
{
|
||||
public:
|
||||
usbInstPage();
|
||||
PU_SMART_CTOR(usbInstPage)
|
||||
void startInstall();
|
||||
void startUsb();
|
||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint touch_pos);
|
||||
TextBlock::Ref pageInfoText;
|
||||
private:
|
||||
std::vector<std::string> ourTitles;
|
||||
std::vector<std::string> selectedTitles;
|
||||
std::string lastUrl;
|
||||
std::string lastFileID;
|
||||
TextBlock::Ref butText;
|
||||
Rectangle::Ref topRect;
|
||||
Rectangle::Ref infoRect;
|
||||
Rectangle::Ref botRect;
|
||||
Image::Ref titleImage;
|
||||
TextBlock::Ref appVersionText;
|
||||
pu::ui::elm::Menu::Ref menu;
|
||||
Image::Ref infoImage;
|
||||
void drawMenuItems(bool clearItems);
|
||||
void drawMenuItems_withext(bool clearItems);
|
||||
void selectTitle(int selectedIndex);
|
||||
};
|
||||
}
|
8
include/usbInstall.hpp
Normal file
8
include/usbInstall.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace usbInstStuff {
|
||||
std::vector<std::string> OnSelected();
|
||||
void installTitleUsb(std::vector<std::string> ourNspList, int ourStorage);
|
||||
}
|
31
include/util/config.hpp
Normal file
31
include/util/config.hpp
Normal file
@ -0,0 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace inst::config {
|
||||
static const std::string appDir = "sdmc:/switch/tinwoo";
|
||||
static const std::string configPath = appDir + "/config.json";
|
||||
static const std::string appVersion = "1.0.17";
|
||||
|
||||
extern std::string gAuthKey;
|
||||
extern std::string sigPatchesUrl;
|
||||
extern std::string httpIndexUrl;
|
||||
extern std::string httplastUrl;
|
||||
extern std::vector<std::string> updateInfo;
|
||||
extern int languageSetting;
|
||||
extern bool ignoreReqVers;
|
||||
extern bool validateNCAs;
|
||||
extern bool overClock;
|
||||
extern bool deletePrompt;
|
||||
extern bool autoUpdate;
|
||||
extern bool usbAck;
|
||||
extern bool gayMode;
|
||||
extern bool useSound;
|
||||
extern bool useoldphp;
|
||||
extern bool streamhtmls;
|
||||
extern bool fixticket;
|
||||
extern bool httpkeyboard;
|
||||
|
||||
void setConfig();
|
||||
void parseConfig();
|
||||
}
|
155
include/util/crypto.hpp
Normal file
155
include/util/crypto.hpp
Normal file
@ -0,0 +1,155 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <switch.h>
|
||||
|
||||
namespace Crypto
|
||||
{
|
||||
#define RSA_2048_BYTES 0x100
|
||||
#define RSA_2048_BITS (RSA_2048_BYTES*8)
|
||||
static const unsigned char NCAHeaderSignature[0x100] = { /* Fixed RSA key used to validate NCA signature 0. */
|
||||
0xBF, 0xBE, 0x40, 0x6C, 0xF4, 0xA7, 0x80, 0xE9, 0xF0, 0x7D, 0x0C, 0x99, 0x61, 0x1D, 0x77, 0x2F,
|
||||
0x96, 0xBC, 0x4B, 0x9E, 0x58, 0x38, 0x1B, 0x03, 0xAB, 0xB1, 0x75, 0x49, 0x9F, 0x2B, 0x4D, 0x58,
|
||||
0x34, 0xB0, 0x05, 0xA3, 0x75, 0x22, 0xBE, 0x1A, 0x3F, 0x03, 0x73, 0xAC, 0x70, 0x68, 0xD1, 0x16,
|
||||
0xB9, 0x04, 0x46, 0x5E, 0xB7, 0x07, 0x91, 0x2F, 0x07, 0x8B, 0x26, 0xDE, 0xF6, 0x00, 0x07, 0xB2,
|
||||
0xB4, 0x51, 0xF8, 0x0D, 0x0A, 0x5E, 0x58, 0xAD, 0xEB, 0xBC, 0x9A, 0xD6, 0x49, 0xB9, 0x64, 0xEF,
|
||||
0xA7, 0x82, 0xB5, 0xCF, 0x6D, 0x70, 0x13, 0xB0, 0x0F, 0x85, 0xF6, 0xA9, 0x08, 0xAA, 0x4D, 0x67,
|
||||
0x66, 0x87, 0xFA, 0x89, 0xFF, 0x75, 0x90, 0x18, 0x1E, 0x6B, 0x3D, 0xE9, 0x8A, 0x68, 0xC9, 0x26,
|
||||
0x04, 0xD9, 0x80, 0xCE, 0x3F, 0x5E, 0x92, 0xCE, 0x01, 0xFF, 0x06, 0x3B, 0xF2, 0xC1, 0xA9, 0x0C,
|
||||
0xCE, 0x02, 0x6F, 0x16, 0xBC, 0x92, 0x42, 0x0A, 0x41, 0x64, 0xCD, 0x52, 0xB6, 0x34, 0x4D, 0xAE,
|
||||
0xC0, 0x2E, 0xDE, 0xA4, 0xDF, 0x27, 0x68, 0x3C, 0xC1, 0xA0, 0x60, 0xAD, 0x43, 0xF3, 0xFC, 0x86,
|
||||
0xC1, 0x3E, 0x6C, 0x46, 0xF7, 0x7C, 0x29, 0x9F, 0xFA, 0xFD, 0xF0, 0xE3, 0xCE, 0x64, 0xE7, 0x35,
|
||||
0xF2, 0xF6, 0x56, 0x56, 0x6F, 0x6D, 0xF1, 0xE2, 0x42, 0xB0, 0x83, 0x40, 0xA5, 0xC3, 0x20, 0x2B,
|
||||
0xCC, 0x9A, 0xAE, 0xCA, 0xED, 0x4D, 0x70, 0x30, 0xA8, 0x70, 0x1C, 0x70, 0xFD, 0x13, 0x63, 0x29,
|
||||
0x02, 0x79, 0xEA, 0xD2, 0xA7, 0xAF, 0x35, 0x28, 0x32, 0x1C, 0x7B, 0xE6, 0x2F, 0x1A, 0xAA, 0x40,
|
||||
0x7E, 0x32, 0x8C, 0x27, 0x42, 0xFE, 0x82, 0x78, 0xEC, 0x0D, 0xEB, 0xE6, 0x83, 0x4B, 0x6D, 0x81,
|
||||
0x04, 0x40, 0x1A, 0x9E, 0x9A, 0x67, 0xF6, 0x72, 0x29, 0xFA, 0x04, 0xF0, 0x9D, 0xE4, 0xF4, 0x03
|
||||
};
|
||||
|
||||
class Keys
|
||||
{
|
||||
public:
|
||||
Keys()
|
||||
{
|
||||
u8 kek[0x10] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
splCryptoGenerateAesKek(headerKekSource, 0, 0, kek);
|
||||
splCryptoGenerateAesKey(kek, headerKeySource, headerKey);
|
||||
splCryptoGenerateAesKey(kek, headerKeySource + 0x10, headerKey + 0x10);
|
||||
}
|
||||
|
||||
u8 headerKekSource[0x10] = { 0x1F, 0x12, 0x91, 0x3A, 0x4A, 0xCB, 0xF0, 0x0D, 0x4C, 0xDE, 0x3A, 0xF6, 0xD5, 0x23, 0x88, 0x2A };
|
||||
u8 headerKeySource[0x20] = { 0x5A, 0x3E, 0xD8, 0x4F, 0xDE, 0xC0, 0xD8, 0x26, 0x31, 0xF7, 0xE2, 0x5D, 0x19, 0x7B, 0xF5, 0xD0, 0x1C, 0x9B, 0x7B, 0xFA, 0xF6, 0x28, 0x18, 0x3D, 0x71, 0xF6, 0x4D, 0x73, 0xF1, 0x50, 0xB9, 0xD2 };
|
||||
|
||||
//u8 headerKey[0x20] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
u8 headerKey[0x20] = { 0xAE, 0xAA, 0xB1, 0xCA, 0x08, 0xAD, 0xF9, 0xBE, 0xF1, 0x29, 0x91, 0xF3, 0x69, 0xE3, 0xC5, 0x67, 0xD6, 0x88, 0x1E, 0x4E, 0x4A, 0x6A, 0x47, 0xA5, 0x1F, 0x6E, 0x48, 0x77, 0x06, 0x2D, 0x54, 0x2D };
|
||||
};
|
||||
|
||||
void calculateMGF1andXOR(unsigned char* data, size_t data_size, const void* source, size_t source_size);
|
||||
bool rsa2048PssVerify(const void* data, size_t len, const unsigned char* signature, const unsigned char* modulus);
|
||||
|
||||
template<class T>
|
||||
T swapEndian(T s)
|
||||
{
|
||||
T result;
|
||||
u8* dest = (u8*)&result;
|
||||
u8* src = (u8*)&s;
|
||||
for (unsigned int i = 0; i < sizeof(s); i++)
|
||||
{
|
||||
dest[i] = src[sizeof(s) - i - 1];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
class AesCtr
|
||||
{
|
||||
public:
|
||||
AesCtr() : m_high(0), m_low(0)
|
||||
{
|
||||
}
|
||||
|
||||
AesCtr(u64 iv) : m_high(swapEndian(iv)), m_low(0)
|
||||
{
|
||||
}
|
||||
|
||||
u64& high() { return m_high; }
|
||||
u64& low() { return m_low; }
|
||||
private:
|
||||
u64 m_high;
|
||||
u64 m_low;
|
||||
};
|
||||
|
||||
|
||||
class Aes128Ctr
|
||||
{
|
||||
public:
|
||||
Aes128Ctr(const u8* key, const AesCtr& iv)
|
||||
{
|
||||
counter = iv;
|
||||
aes128CtrContextCreate(&ctx, key, &iv);
|
||||
seek(0);
|
||||
}
|
||||
|
||||
virtual ~Aes128Ctr()
|
||||
{
|
||||
}
|
||||
|
||||
void seek(u64 offset)
|
||||
{
|
||||
counter.low() = swapEndian(offset >> 4);
|
||||
aes128CtrContextResetCtr(&ctx, &counter);
|
||||
}
|
||||
|
||||
void encrypt(void* dst, const void* src, size_t l)
|
||||
{
|
||||
aes128CtrCrypt(&ctx, dst, src, l);
|
||||
}
|
||||
|
||||
void decrypt(void* dst, const void* src, size_t l)
|
||||
{
|
||||
encrypt(dst, src, l);
|
||||
}
|
||||
protected:
|
||||
AesCtr counter;
|
||||
|
||||
Aes128CtrContext ctx;
|
||||
};
|
||||
|
||||
class AesXtr
|
||||
{
|
||||
public:
|
||||
AesXtr(const u8* key, bool is_encryptor)
|
||||
{
|
||||
aes128XtsContextCreate(&ctx, key, key + 0x10, is_encryptor);
|
||||
}
|
||||
|
||||
virtual ~AesXtr()
|
||||
{
|
||||
}
|
||||
|
||||
void encrypt(void* dst, const void* src, size_t l, size_t sector, size_t sector_size)
|
||||
{
|
||||
for (size_t i = 0; i < l; i += sector_size)
|
||||
{
|
||||
aes128XtsContextResetSector(&ctx, sector++, true);
|
||||
aes128XtsEncrypt(&ctx, dst, src, sector_size);
|
||||
|
||||
dst = (u8*)dst + sector_size;
|
||||
src = (const u8*)src + sector_size;
|
||||
}
|
||||
}
|
||||
|
||||
void decrypt(void* dst, const void* src, size_t l, size_t sector, size_t sector_size)
|
||||
{
|
||||
for (size_t i = 0; i < l; i += sector_size)
|
||||
{
|
||||
aes128XtsContextResetSector(&ctx, sector++, true);
|
||||
aes128XtsDecrypt(&ctx, dst, src, sector_size);
|
||||
|
||||
dst = (u8*)dst + sector_size;
|
||||
src = (const u8*)src + sector_size;
|
||||
}
|
||||
}
|
||||
protected:
|
||||
Aes128XtsContext ctx;
|
||||
};
|
||||
}
|
8
include/util/curl.hpp
Normal file
8
include/util/curl.hpp
Normal file
@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
|
||||
namespace inst::curl {
|
||||
bool downloadFile(const std::string ourUrl, const char* pagefilename, long timeout = 5000, bool writeProgress = false);
|
||||
std::string downloadToBuffer(const std::string ourUrl, int firstRange = -1, int secondRange = -1, long timeout = 5000);
|
||||
std::string html_to_buffer(const std::string ourUrl);
|
||||
}
|
34
include/util/debug.h
Normal file
34
include/util/debug.h
Normal 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 <stdio.h>
|
||||
#include <switch/types.h>
|
||||
void printBytes(u8* bytes, size_t size, bool includeHeader);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
39
include/util/error.hpp
Normal file
39
include/util/error.hpp
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
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 <cstring>
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include "util/debug.h"
|
||||
|
||||
#define ASSERT_OK(rc_out, desc) if (R_FAILED(rc_out)) { char msg[256] = {0}; snprintf(msg, 256-1, "%s:%u: %s. Error code: 0x%08x\n", __func__, __LINE__, desc, rc_out); throw std::runtime_error(msg); }
|
||||
#define THROW_FORMAT(format, ...) { char error_prefix[512] = {0}; snprintf(error_prefix, 256-1, "%s:%u: ", __func__, __LINE__);\
|
||||
char formatted_msg[256] = {0}; snprintf(formatted_msg, 256-1, format, ##__VA_ARGS__);\
|
||||
strncat(error_prefix, formatted_msg, 512-1); throw std::runtime_error(error_prefix); }
|
||||
|
||||
#ifdef NXLINK_DEBUG
|
||||
#define LOG_DEBUG(format, ...) { printf("%s:%u: ", __func__, __LINE__); printf(format, ##__VA_ARGS__); }
|
||||
#else
|
||||
#define LOG_DEBUG(format, ...) ;
|
||||
#endif
|
36
include/util/file_util.hpp
Normal file
36
include/util/file_util.hpp
Normal file
@ -0,0 +1,36 @@
|
||||
/*
|
||||
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>
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
||||
#include "nx/content_meta.hpp"
|
||||
|
||||
namespace tin::util
|
||||
{
|
||||
NcmContentInfo CreateNSPCNMTContentRecord(const std::string& nspPath);
|
||||
nx::ncm::ContentMeta GetContentMetaFromNCA(const std::string& ncaPath);
|
||||
std::vector<std::string> GetNSPList();
|
||||
}
|
22874
include/util/json.hpp
Normal file
22874
include/util/json.hpp
Normal file
File diff suppressed because it is too large
Load Diff
28
include/util/lang.hpp
Normal file
28
include/util/lang.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include "json.hpp"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
namespace Language {
|
||||
void Load();
|
||||
std::string LanguageEntry(std::string key);
|
||||
std::string GetRandomMsg();
|
||||
inline json GetRelativeJson(json j, std::string key) {
|
||||
std::istringstream ss(key);
|
||||
std::string token;
|
||||
|
||||
while (std::getline(ss, token, '.') && j != nullptr) {
|
||||
j = j[token];
|
||||
}
|
||||
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
||||
inline std::string operator ""_lang(const char* key, size_t size) {
|
||||
return Language::LanguageEntry(std::string(key, size));
|
||||
}
|
83
include/util/network_util.hpp
Normal file
83
include/util/network_util.hpp
Normal file
@ -0,0 +1,83 @@
|
||||
/*
|
||||
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/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <sys/errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <functional>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace tin::network
|
||||
{
|
||||
class HTTPHeader
|
||||
{
|
||||
private:
|
||||
std::string m_url;
|
||||
std::map<std::string, std::string> m_values;
|
||||
|
||||
static size_t ParseHTMLHeader(char* bytes, size_t size, size_t numItems, void* userData);
|
||||
|
||||
public:
|
||||
HTTPHeader(std::string url);
|
||||
|
||||
void PerformRequest();
|
||||
|
||||
bool HasValue(std::string key);
|
||||
std::string GetValue(std::string key);
|
||||
};
|
||||
|
||||
class HTTPDownload
|
||||
{
|
||||
private:
|
||||
std::string m_url;
|
||||
HTTPHeader m_header;
|
||||
bool m_rangesSupported = false;
|
||||
|
||||
static size_t ParseHTMLData(char* bytes, size_t size, size_t numItems, void* userData);
|
||||
|
||||
public:
|
||||
HTTPDownload(std::string url);
|
||||
|
||||
void BufferDataRange(void* buffer, size_t offset, size_t size, std::function<void(size_t sizeRead)> progressFunc);
|
||||
int StreamDataRange(size_t offset, size_t size, std::function<size_t(u8* bytes, size_t size)> streamFunc);
|
||||
};
|
||||
|
||||
size_t WaitReceiveNetworkData(int sockfd, void* buf, size_t len);
|
||||
size_t WaitSendNetworkData(int sockfd, void* buf, size_t len);
|
||||
}
|
41
include/util/title_util.hpp
Normal file
41
include/util/title_util.hpp
Normal file
@ -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 <switch/types.h>
|
||||
#include <string>
|
||||
#include "nx/content_meta.hpp"
|
||||
#include "nx/ipc/tin_ipc.h"
|
||||
|
||||
namespace tin::util
|
||||
{
|
||||
u64 GetRightsIdTid(RightsId rightsId);
|
||||
u64 GetRightsIdKeyGen(RightsId rightsId);
|
||||
|
||||
std::string GetNcaIdString(const NcmContentId& ncaId);
|
||||
NcmContentId GetNcaIdFromString(std::string ncaIdStr);
|
||||
|
||||
u64 GetBaseTitleId(u64 titleId, NcmContentMetaType contentMetaType);
|
||||
std::string GetBaseTitleName(u64 baseTitleId);
|
||||
std::string GetTitleName(u64 titleId, NcmContentMetaType contentMetaType);
|
||||
}
|
3
include/util/unzip.hpp
Normal file
3
include/util/unzip.hpp
Normal file
@ -0,0 +1,3 @@
|
||||
namespace inst::zip {
|
||||
bool extractFile(const std::string filename, const std::string destination);
|
||||
}
|
47
include/util/usb_comms_tinleaf.h
Normal file
47
include/util/usb_comms_tinleaf.h
Normal file
@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file usb_comms.h
|
||||
* @brief USB comms.
|
||||
* @author yellows8
|
||||
* @author plutoo
|
||||
* @copyright libnx Authors
|
||||
*/
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#pragma once
|
||||
#include "switch/types.h"
|
||||
|
||||
typedef struct {
|
||||
u8 bInterfaceClass;
|
||||
u8 bInterfaceSubClass;
|
||||
u8 bInterfaceProtocol;
|
||||
} tinleaf_UsbCommsInterfaceInfo;
|
||||
|
||||
/// Initializes usbComms with the default number of interfaces (1)
|
||||
Result tinleaf_usbCommsInitialize(void);
|
||||
|
||||
/// Initializes usbComms with a specific number of interfaces.
|
||||
Result tinleaf_usbCommsInitializeEx(u32 num_interfaces, const tinleaf_UsbCommsInterfaceInfo* infos);
|
||||
|
||||
/// Exits usbComms.
|
||||
void tinleaf_usbCommsExit(void);
|
||||
|
||||
/// Sets whether to throw a fatal error in usbComms{Read/Write}* on failure, or just return the transferred size. By default (false) the latter is used.
|
||||
void tinleaf_usbCommsSetErrorHandling(bool flag);
|
||||
|
||||
/// Read data with the default interface.
|
||||
size_t tinleaf_usbCommsRead(void* buffer, size_t size, u64 timeout);
|
||||
|
||||
/// Write data with the default interface.
|
||||
size_t tinleaf_usbCommsWrite(const void* buffer, size_t size, u64 timeout);
|
||||
|
||||
/// Same as usbCommsRead except with the specified interface.
|
||||
size_t tinleaf_usbCommsReadEx(void* buffer, size_t size, u32 interface, u64 timeout);
|
||||
|
||||
/// Same as usbCommsWrite except with the specified interface.
|
||||
size_t tinleaf_usbCommsWriteEx(const void* buffer, size_t size, u32 interface, u64 timeout);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
59
include/util/usb_util.hpp
Normal file
59
include/util/usb_util.hpp
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
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 <string>
|
||||
|
||||
namespace tin::util
|
||||
{
|
||||
enum USBCmdType : u8
|
||||
{
|
||||
REQUEST = 0,
|
||||
RESPONSE = 1
|
||||
};
|
||||
|
||||
struct USBCmdHeader
|
||||
{
|
||||
u32 magic;
|
||||
USBCmdType type;
|
||||
u8 padding[0x3] = { 0 };
|
||||
u32 cmdId;
|
||||
u64 dataSize;
|
||||
u8 reserved[0xC] = { 0 };
|
||||
} PACKED;
|
||||
|
||||
static_assert(sizeof(USBCmdHeader) == 0x20, "USBCmdHeader must be 0x20!");
|
||||
|
||||
class USBCmdManager
|
||||
{
|
||||
public:
|
||||
static void SendCmdHeader(u32 cmdId, size_t dataSize);
|
||||
|
||||
static void SendExitCmd();
|
||||
static USBCmdHeader SendFileRangeCmd(std::string nspName, u64 offset, u64 size);
|
||||
};
|
||||
|
||||
size_t USBRead(void* out, size_t len, u64 timeout = 5000000000);
|
||||
size_t USBWrite(const void* in, size_t len, u64 timeout = 5000000000);
|
||||
}
|
25
include/util/util.hpp
Normal file
25
include/util/util.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
#include <filesystem>
|
||||
|
||||
namespace inst::util {
|
||||
void initApp();
|
||||
void deinitApp();
|
||||
void initInstallServices();
|
||||
void deinitInstallServices();
|
||||
bool ignoreCaseCompare(const std::string& a, const std::string& b);
|
||||
std::vector<std::filesystem::path> getDirectoryFiles(const std::string& dir, const std::vector<std::string>& extensions);
|
||||
std::vector<std::filesystem::path> getDirsAtPath(const std::string& dir);
|
||||
bool removeDirectory(std::string dir);
|
||||
bool copyFile(std::string inFile, std::string outFile);
|
||||
std::string formatUrlString(std::string ourString);
|
||||
std::string shortenString(std::string ourString, int ourLength, bool isFile);
|
||||
std::string readTextFromFile(std::string ourFile);
|
||||
std::string softwareKeyboard(std::string guideText, std::string initialText, int LenMax);
|
||||
std::string getDriveFileName(std::string fileId);
|
||||
std::vector<uint32_t> setClockSpeed(int deviceToClock, uint32_t clockSpeed);
|
||||
std::string getIPAddress();
|
||||
int getUsbState();
|
||||
void playAudio(std::string audioPath);
|
||||
std::vector<std::string> checkForAppUpdate();
|
||||
std::string SplitFilename(const std::string& str);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user