Add files via upload

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

31
include/ui/HDInstPage.hpp Normal file
View File

@ -0,0 +1,31 @@
#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);
};
}

View 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;
};
}

27
include/ui/instPage.hpp Normal file
View File

@ -0,0 +1,27 @@
#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;
Image::Ref awooImage;
pu::ui::elm::ProgressBar::Ref installBar;
static void setTopInstInfoText(std::string ourText);
static void setInstInfoText(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;
};
}

37
include/ui/mainPage.hpp Normal file
View File

@ -0,0 +1,37 @@
#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, 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;
};
}

View File

@ -0,0 +1,30 @@
#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> 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 selectTitle(int selectedIndex);
};
}

View File

@ -0,0 +1,26 @@
#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);
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);
};
}

31
include/ui/sdInstPage.hpp Normal file
View File

@ -0,0 +1,31 @@
#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);
};
}

View File

@ -0,0 +1,31 @@
#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 selectTitle(int selectedIndex);
};
}

25
include/util/config.hpp Normal file
View File

@ -0,0 +1,25 @@
#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.4";
extern std::string gAuthKey;
extern std::string sigPatchesUrl;
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;
void setConfig();
void parseConfig();
}

154
include/util/crypto.hpp Normal file
View File

@ -0,0 +1,154 @@
#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 };
};
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;
};
}

7
include/util/curl.hpp Normal file
View File

@ -0,0 +1,7 @@
#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);
}

36
include/util/debug.h Normal file
View 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
#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
View 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

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

22875
include/util/json.hpp Normal file

File diff suppressed because it is too large Load Diff

28
include/util/lang.hpp Normal file
View 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));
}

View 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);
}

View 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
View File

@ -0,0 +1,3 @@
namespace inst::zip {
bool extractFile(const std::string filename, const std::string destination);
}

View 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
View 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);
}

24
include/util/util.hpp Normal file
View File

@ -0,0 +1,24 @@
#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();
}