├── icon.jpg ├── .gitattributes ├── raw ├── screenshot1.jpg ├── screenshot10.jpg ├── screenshot11.jpg ├── screenshot2.jpg ├── screenshot3.jpg ├── screenshot4.jpg ├── screenshot5.jpg ├── screenshot6.jpg ├── screenshot7.jpg ├── screenshot8.jpg ├── screenshot9.jpg └── buy-me-a-coffee.png ├── .gitmodules ├── .gitignore ├── include ├── views │ ├── country_select_view.hpp │ ├── create_backup_view.hpp │ ├── link_accounts_view.hpp │ ├── restore_backup_view.hpp │ ├── unlink_accounts_view.hpp │ ├── account_select_view.hpp │ ├── account_list_item.hpp │ ├── confirm_view.hpp │ └── worker_view.hpp ├── utils │ ├── reboot_payload.h │ ├── utils.hpp │ ├── progress_event.hpp │ └── country_list.hpp ├── core │ ├── file_operations.hpp │ ├── switch_profile.hpp │ ├── generator.hpp │ └── shared_settings.hpp ├── styles │ └── visual_overrides.hpp └── constants.hpp ├── lib └── zipper │ ├── source │ ├── aes │ │ ├── entropy.h │ │ ├── Makefile │ │ ├── entropy.c │ │ ├── pwd2key.h │ │ ├── sha1.h │ │ ├── prng.h │ │ ├── hmac.h │ │ ├── fileenc.h │ │ ├── fileenc.c │ │ ├── brg_endian.h │ │ ├── hmac.c │ │ ├── prng.c │ │ ├── aestab.h │ │ ├── pwd2key.c │ │ ├── aes.h │ │ ├── brg_types.h │ │ └── sha1.c │ ├── tools.cpp │ ├── ioapi_mem.c │ └── zipper.cpp │ ├── include │ ├── tools.h │ ├── iowin32.h │ ├── zipper.h │ ├── defs.h │ ├── ioapi_buf.h │ ├── ioapi_mem.h │ ├── unzipper.h │ ├── crypt.h │ ├── ioapi.h │ ├── CDirEntry.h │ └── zip.h │ └── LICENSE.md ├── resources └── i18n │ └── en-US │ ├── brls.json │ └── translations.json ├── source ├── views │ ├── country_select_view.cpp │ ├── account_list_item.cpp │ ├── create_backup_view.cpp │ ├── link_accounts_view.cpp │ ├── unlink_accounts_view.cpp │ ├── restore_backup_view.cpp │ ├── worker_view.cpp │ ├── confirm_view.cpp │ └── account_select_view.cpp ├── styles │ └── visual_overrides.cpp ├── utils │ ├── reboot_payload.c │ └── utils.cpp ├── main.cpp └── core │ └── generator.cpp ├── README.md └── Makefile /icon.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/icon.jpg -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /raw/screenshot1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/screenshot1.jpg -------------------------------------------------------------------------------- /raw/screenshot10.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/screenshot10.jpg -------------------------------------------------------------------------------- /raw/screenshot11.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/screenshot11.jpg -------------------------------------------------------------------------------- /raw/screenshot2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/screenshot2.jpg -------------------------------------------------------------------------------- /raw/screenshot3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/screenshot3.jpg -------------------------------------------------------------------------------- /raw/screenshot4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/screenshot4.jpg -------------------------------------------------------------------------------- /raw/screenshot5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/screenshot5.jpg -------------------------------------------------------------------------------- /raw/screenshot6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/screenshot6.jpg -------------------------------------------------------------------------------- /raw/screenshot7.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/screenshot7.jpg -------------------------------------------------------------------------------- /raw/screenshot8.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/screenshot8.jpg -------------------------------------------------------------------------------- /raw/screenshot9.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/screenshot9.jpg -------------------------------------------------------------------------------- /raw/buy-me-a-coffee.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/impeeza/linkalho/HEAD/raw/buy-me-a-coffee.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/borealis"] 2 | path = lib/borealis 3 | url = https://github.com/HamletDuFromage/borealis 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.nro 2 | *.elf 3 | *.nacp 4 | build 5 | su 6 | .vscode 7 | debug 8 | resources/i18n/en-GB 9 | resources/icon 10 | resources/inter 11 | resources/material 12 | -------------------------------------------------------------------------------- /include/views/country_select_view.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class CountrySelectView : public brls::SelectListItem 6 | { 7 | public: 8 | CountrySelectView(); 9 | }; -------------------------------------------------------------------------------- /include/views/create_backup_view.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class CreateBackupView : public brls::ListItem 6 | { 7 | public: 8 | CreateBackupView(bool canUseLed); 9 | }; -------------------------------------------------------------------------------- /include/views/link_accounts_view.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class LinkAccountsView : public brls::ListItem 6 | { 7 | public: 8 | LinkAccountsView(bool canUseLed); 9 | }; -------------------------------------------------------------------------------- /include/views/restore_backup_view.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class RestoreBackupView : public brls::ListItem 6 | { 7 | public: 8 | RestoreBackupView(bool canUseLed); 9 | }; -------------------------------------------------------------------------------- /include/utils/reboot_payload.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | bool rebootToPayload(const char* payloadFile); 8 | 9 | #ifdef __cplusplus 10 | } 11 | #endif 12 | -------------------------------------------------------------------------------- /include/core/file_operations.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | bool initDirs(); 7 | void linkAccounts(); 8 | void unlinkAccounts(); 9 | void restoreBackup(const std::string& backupFullpath); 10 | void manualBackup(); 11 | -------------------------------------------------------------------------------- /include/views/unlink_accounts_view.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "core/switch_profile.hpp" 4 | #include 5 | #include 6 | 7 | class UnlinkAccountsView : public brls::ListItem 8 | { 9 | public: 10 | UnlinkAccountsView(bool canUseLed); 11 | }; -------------------------------------------------------------------------------- /lib/zipper/source/aes/entropy.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef _ENTROPY_FUN_H 3 | #define _ENTROPY_FUN_H 4 | 5 | #if defined(__cplusplus) 6 | extern "C" 7 | { 8 | #endif 9 | 10 | int entropy_fun(unsigned char buf[], unsigned int len); 11 | 12 | #if defined(__cplusplus) 13 | } 14 | #endif 15 | 16 | #endif 17 | -------------------------------------------------------------------------------- /include/styles/visual_overrides.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class VisualOverrides 7 | { 8 | public: 9 | static brls::Style* LinkalhoStyle(); 10 | static brls::LibraryViewsThemeVariantsWrapper* LinkalhoTheme(); 11 | }; 12 | -------------------------------------------------------------------------------- /resources/i18n/en-US/brls.json: -------------------------------------------------------------------------------- 1 | { 2 | "hints": { 3 | "ok": "OK", 4 | "back": "Back", 5 | "exit": "Exit" 6 | }, 7 | 8 | "crash_frame": { 9 | "button": "OK" 10 | }, 11 | 12 | "thumbnail_sidebar": { 13 | "save": "Save" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/Makefile: -------------------------------------------------------------------------------- 1 | CC=cc 2 | CFLAGS=-O -DHAVE_AES 3 | OBJS=aescrypt.o aeskey.o aestab.o entropy.o fileenc.o hmac.o prng.o pwd2key.o sha1.o 4 | ARFLAGS=rv 5 | 6 | .c.o: 7 | $(CC) -c $(CFLAGS) $*.c 8 | 9 | libaes.a: $(OBJS) 10 | $(ECHO) $(AR) $(ARFLAGS) ../libaes.a $? 11 | $(AR) $(ARFLAGS) ../libaes.a $? 12 | $(RANLIB) ../libaes.a 13 | 14 | all: libaes.a 15 | 16 | .PHONY: clean 17 | 18 | clean: 19 | rm *.o *.a -------------------------------------------------------------------------------- /include/core/switch_profile.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | class SwitchProfile { 8 | public: 9 | const AccountUid id; 10 | const std::string uid_str; 11 | const std::string name; 12 | const std::pair icon; 13 | const bool is_linked; 14 | uint64_t account_id; 15 | uint64_t nas_id; 16 | bool selected; 17 | }; -------------------------------------------------------------------------------- /include/views/account_select_view.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "core/switch_profile.hpp" 4 | #include "views/account_list_item.hpp" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | class AccountSelectView : public brls::ListItem 13 | { 14 | public: 15 | AccountSelectView(); 16 | 17 | private: 18 | vector accountListItems; 19 | void computeValue(); 20 | }; -------------------------------------------------------------------------------- /include/views/account_list_item.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include "core/switch_profile.hpp" 4 | 5 | class AccountListItem : public brls::ListItem 6 | { 7 | protected: 8 | SwitchProfile accountProfile; 9 | bool toggleState; 10 | 11 | public: 12 | AccountListItem(const SwitchProfile& profile, bool initialValue = true); 13 | 14 | virtual bool onClick() override; 15 | 16 | bool getToggleState(); 17 | void forceState(bool state); 18 | const SwitchProfile& getAccountProfile(); 19 | }; -------------------------------------------------------------------------------- /include/constants.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // #define LINKALHO_DEBUG 4 | #define LOCAL_PATH "sdmc:/switch/" APP_TITLE_LOWER "/" 5 | #define BACKUP_PATH LOCAL_PATH "backups/" 6 | #define RESTORE_FILE_DIR LOCAL_PATH "restore/" 7 | #define RESTORE_FILE_PATH RESTORE_FILE_DIR "restore.zip" 8 | 9 | #ifdef LINKALHO_DEBUG 10 | # define ACCOUNT_PATH LOCAL_PATH "debug" 11 | #else 12 | # define ACCOUNT_PATH "account:/su" 13 | #endif 14 | 15 | #define CUSTOM_PAYLOAD_FILE "reboot.bin" 16 | #define CUSTOM_PAYLOAD_FILE_PATH LOCAL_PATH CUSTOM_PAYLOAD_FILE 17 | 18 | #define DEFAULT_COUNTRY "Portugal" 19 | #define DEFAULT_COUNTRY_CODE "PT" 20 | #define DEFAULT_LOCALE "en-US" 21 | #define DEFAULT_TIMEZONE "Europe/Lisbon" 22 | -------------------------------------------------------------------------------- /lib/zipper/include/tools.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | 8 | namespace zipper 9 | { 10 | void getFileCrc(std::istream& input_stream, std::vector& buff, unsigned long& result_crc); 11 | bool isLargeFile(std::istream& input_stream); 12 | bool checkFileExists(const std::string& filename); 13 | bool makedir(const std::string& newdir); 14 | void removeFolder(const std::string& foldername); 15 | std::string parentDirectory(const std::string& filepath); 16 | std::string currentPath(); 17 | bool isDirectory(const std::string& path); 18 | std::vector filesFromDirectory(const std::string& path); 19 | std::string fileNameFromPath(const std::string& path); 20 | } 21 | -------------------------------------------------------------------------------- /include/core/generator.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | class Generator{ 6 | private: 7 | 8 | unsigned long _nasId; 9 | std::string _nasIdStr; 10 | unsigned long _baasUserId; 11 | 12 | public: 13 | Generator(); // Disallow instantiation outside of the class. 14 | // Generator(const Generator&) = delete; 15 | // Generator& operator=(const Generator &) = delete; 16 | // Generator(Generator &&) = delete; 17 | // Generator & operator=(Generator &&) = delete; 18 | 19 | // static auto& instance(){ 20 | // static Generator gen; 21 | // return gen; 22 | // } 23 | 24 | const std::string& nasIdStr(); 25 | void writeBaas(const std::string& fullpath); 26 | void writeProfileDat(const std::string& fullpath); 27 | void writeProfileJson(const std::string& fullpath); 28 | 29 | }; 30 | -------------------------------------------------------------------------------- /include/utils/utils.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | enum HardwareType { 6 | Erista, 7 | Mariko, 8 | Aula, 9 | UnknownHardware 10 | }; 11 | 12 | void attemptForceReboot(); 13 | HidsysNotificationLedPattern getBreathePattern(); 14 | HidsysNotificationLedPattern getConfirmPattern(); 15 | HidsysNotificationLedPattern getClearPattern(); 16 | void sendLedPattern(HidsysNotificationLedPattern pattern); 17 | const std::string getPayload(); 18 | bool isErista(); 19 | HardwareType getHardwareType(); 20 | const std::string getLocale(); 21 | const std::string getTimezone(); 22 | Result getBaasAccountAdministrator(const AccountUid user_id, Service *out_admin_srv); 23 | Result baasAdministrator_isLinkedWithNAS(Service *admin_srv, bool *out_linked); 24 | Result baasAdministrator_getAccountId(Service *admin_srv, u64 *out_id); 25 | Result baasAdministrator_getNasId(Service *admin_srv, u64 *out_id); 26 | -------------------------------------------------------------------------------- /include/views/confirm_view.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | class ConfirmView : public brls::View 7 | { 8 | private: 9 | brls::Button* button = nullptr; 10 | brls::Label* label = nullptr; 11 | std::chrono::system_clock::time_point start = std::chrono::high_resolution_clock::now(); 12 | bool reboot = false; 13 | bool isLastStage = false; 14 | bool canUseLed = false; 15 | brls::StagedAppletFrame* frame = nullptr; 16 | 17 | public: 18 | ConfirmView(brls::StagedAppletFrame* frame, const std::string& text, bool reboot, bool canUseLed); 19 | ~ConfirmView(); 20 | 21 | void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx) override; 22 | void layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash) override; 23 | brls::View* getDefaultFocus() override; 24 | void willDisappear(bool resetState = false) override; 25 | }; 26 | -------------------------------------------------------------------------------- /include/utils/progress_event.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | class ProgressEvent{ 3 | private: 4 | ProgressEvent() {} 5 | int _current = 0; 6 | int _target = 0; 7 | int _max = 60; 8 | 9 | public: 10 | ProgressEvent(const ProgressEvent&) = delete; 11 | ProgressEvent& operator=(const ProgressEvent &) = delete; 12 | ProgressEvent(ProgressEvent &&) = delete; 13 | ProgressEvent & operator=(ProgressEvent &&) = delete; 14 | 15 | static auto& instance(){ 16 | static ProgressEvent event; 17 | return event; 18 | } 19 | 20 | int increment() { 21 | if (_current < _target) { 22 | ++_current; 23 | } 24 | return _current; 25 | } 26 | 27 | void reset() { 28 | _current = 0; 29 | _target = 0; 30 | _max = 60; 31 | } 32 | 33 | inline void setTotalSteps(int steps) { _max = steps*5; } 34 | inline void setStep(int step) { _target = step*5; } 35 | inline bool finished() { return _current == _max; } 36 | inline int getMax() { return _max; } 37 | }; 38 | -------------------------------------------------------------------------------- /lib/zipper/include/iowin32.h: -------------------------------------------------------------------------------- 1 | /* iowin32.h -- IO base function header for compress/uncompress .zip 2 | Version 1.1, February 14h, 2010 3 | part of the MiniZip project 4 | 5 | Copyright (C) 1998-2010 Gilles Vollant 6 | http://www.winimage.com/zLibDll/minizip.html 7 | Modifications for Zip64 support 8 | Copyright (C) 2009-2010 Mathias Svensson 9 | http://result42.com 10 | 11 | This program is distributed under the terms of the same license as zlib. 12 | See the accompanying LICENSE file for the full text of the license. 13 | */ 14 | 15 | #ifndef _IOWIN32_H 16 | #define _IOWIN32_H 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | void fill_win32_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 25 | void fill_win32_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def)); 26 | void fill_win32_filefunc64A OF((zlib_filefunc64_def* pzlib_filefunc_def)); 27 | void fill_win32_filefunc64W OF((zlib_filefunc64_def* pzlib_filefunc_def)); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /include/views/worker_view.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | 7 | typedef std::function worker_func_t; 8 | 9 | class WorkerView : public brls::View 10 | { 11 | private: 12 | brls::Label* label; 13 | brls::ProgressDisplay* progressDisp = nullptr; 14 | brls::StagedAppletFrame* frame; 15 | brls::Button* button; 16 | int progressValue = 0; 17 | bool workStarted = false; 18 | std::thread* workerThread; 19 | worker_func_t workerFunc; 20 | 21 | public: 22 | WorkerView(brls::StagedAppletFrame* frame, const std::string& warning, worker_func_t workerFunc); 23 | ~WorkerView(); 24 | 25 | void draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx) override; 26 | void layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash) override; 27 | brls::View* getDefaultFocus() override; 28 | void doWork(); 29 | 30 | void willAppear(bool resetState = false) override; 31 | void willDisappear(bool resetState = false) override; 32 | }; 33 | -------------------------------------------------------------------------------- /source/views/country_select_view.cpp: -------------------------------------------------------------------------------- 1 | #include "views/country_select_view.hpp" 2 | #include "utils/country_list.hpp" 3 | #include "core/shared_settings.hpp" 4 | #include "constants.hpp" 5 | #include 6 | 7 | using namespace std; 8 | using namespace brls::i18n::literals; 9 | 10 | CountrySelectView::CountrySelectView() : SelectListItem("translations/country_select_view/title"_i18n, {DEFAULT_COUNTRY}, 0) 11 | { 12 | SharedSettings::instance().setCountryCode(DEFAULT_COUNTRY_CODE); 13 | vector countryList = {}; 14 | 15 | countryList.reserve(COUNTRIES.size()); 16 | for (auto const& c : COUNTRIES) { 17 | countryList.emplace_back(c.first); 18 | } 19 | this->values.swap(countryList); 20 | auto it = find(this->values.begin(), this->values.end(), DEFAULT_COUNTRY); 21 | if (it != this->values.end()) { 22 | this->setSelectedValue(distance(this->values.begin(), it)); 23 | } 24 | 25 | this->getValueSelectedEvent()->subscribe([this](int result) { 26 | SharedSettings::instance().setCountryCode(getOrDefault(COUNTRIES, this->getValue() ,DEFAULT_COUNTRY_CODE)); 27 | }); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /lib/zipper/LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 seb 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /source/views/account_list_item.cpp: -------------------------------------------------------------------------------- 1 | #include "views/account_list_item.hpp" 2 | 3 | using namespace brls::i18n::literals; 4 | 5 | AccountListItem::AccountListItem(const SwitchProfile& profile, bool initialValue) 6 | : ListItem(profile.name, "", (profile.is_linked ? "translations/account_list_item/linked"_i18n : "translations/account_list_item/not_linked"_i18n)) 7 | , toggleState(initialValue) 8 | , accountProfile(profile) 9 | { 10 | this->setChecked(this->toggleState); 11 | this->setThumbnail(this->accountProfile.icon.first, this->accountProfile.icon.second); 12 | } 13 | 14 | bool AccountListItem::onClick() 15 | { 16 | this->toggleState = !this->toggleState; 17 | this->setChecked(this->toggleState); 18 | 19 | ListItem::onClick(); 20 | return true; 21 | } 22 | 23 | bool AccountListItem::getToggleState() 24 | { 25 | return this->toggleState; 26 | } 27 | 28 | void AccountListItem::forceState(bool state) { 29 | this->toggleState = state; 30 | this->setChecked(this->toggleState); 31 | ListItem::onClick(); 32 | } 33 | 34 | const SwitchProfile& AccountListItem::getAccountProfile() { 35 | return this->accountProfile; 36 | } -------------------------------------------------------------------------------- /lib/zipper/include/zipper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace zipper { 10 | 11 | class Zipper 12 | { 13 | public: 14 | // Minizip options/params: 15 | // -o -a -0 -1 -9 -j 16 | enum zipFlags { Overwrite = 0x01, Append = 0x02, Store = 0x04, Faster = 0x08, Better = 0x10, NoPaths = 0x20 }; 17 | 18 | Zipper(std::iostream& buffer); 19 | Zipper(std::vector& buffer); 20 | Zipper(const std::string& zipname); 21 | Zipper(const std::string& zipname, const std::string& password); 22 | 23 | ~Zipper(void); 24 | 25 | bool add(std::istream& source, const std::string& nameInZip = std::string(), zipFlags flags = Better); 26 | bool add(const std::string& fileOrFolderPath, zipFlags flags = Better); 27 | 28 | void open(); 29 | void close(); 30 | 31 | private: 32 | std::string m_password; 33 | std::string m_zipname; 34 | std::iostream& m_obuffer; 35 | std::vector& m_vecbuffer; 36 | bool m_usingMemoryVector; 37 | bool m_usingStream; 38 | bool m_open; 39 | 40 | struct Impl; 41 | Impl* m_impl; 42 | }; 43 | } 44 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/entropy.c: -------------------------------------------------------------------------------- 1 | #ifdef _WIN32 2 | #include 3 | #else 4 | #include 5 | #include 6 | #endif 7 | 8 | #if defined(__cplusplus) 9 | extern "C" 10 | { 11 | #endif 12 | 13 | #ifdef _WIN32 14 | int entropy_fun(unsigned char buf[], unsigned int len) 15 | { 16 | HCRYPTPROV provider; 17 | unsigned __int64 pentium_tsc[1]; 18 | unsigned int i; 19 | int result = 0; 20 | 21 | 22 | if (CryptAcquireContext(&provider, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) 23 | { 24 | result = CryptGenRandom(provider, len, buf); 25 | CryptReleaseContext(provider, 0); 26 | if (result) 27 | return len; 28 | } 29 | 30 | QueryPerformanceCounter((LARGE_INTEGER *)pentium_tsc); 31 | 32 | for(i = 0; i < 8 && i < len; ++i) 33 | buf[i] = ((unsigned char*)pentium_tsc)[i]; 34 | 35 | return i; 36 | } 37 | #else 38 | int entropy_fun(unsigned char buf[], unsigned int len) 39 | { 40 | int frand = open("/dev/random", O_RDONLY); 41 | int rlen = 0; 42 | if (frand != -1) 43 | { 44 | rlen = read(frand, buf, len); 45 | close(frand); 46 | } 47 | return rlen; 48 | } 49 | #endif 50 | 51 | #if defined(__cplusplus) 52 | } 53 | #endif 54 | -------------------------------------------------------------------------------- /source/styles/visual_overrides.cpp: -------------------------------------------------------------------------------- 1 | #include "styles/visual_overrides.hpp" 2 | #include 3 | 4 | brls::Style* VisualOverrides::LinkalhoStyle() 5 | { 6 | brls::Style* style = new brls::HorizonStyle(); 7 | style->AppletFrame.titleSize = 30; 8 | style->AppletFrame.titleStart = 35; 9 | style->List.marginLeftRight = 40; 10 | style->List.marginTopBottom = 38; 11 | style->Dialog.height = 380; 12 | style->Dialog.paddingLeftRight = 56; 13 | return style; 14 | } 15 | 16 | brls::LibraryViewsThemeVariantsWrapper* VisualOverrides::LinkalhoTheme() 17 | { 18 | brls::Theme* custom_light = new brls::HorizonLightTheme(); 19 | custom_light->buttonPrimaryDisabledBackgroundColor = nvgRGB(136, 90, 75); 20 | custom_light->buttonPrimaryDisabledTextColor = nvgRGB(167, 129, 118); 21 | custom_light->buttonPrimaryEnabledBackgroundColor = nvgRGB(255, 59, 0); 22 | custom_light->buttonPrimaryEnabledTextColor = nvgRGB(255, 247, 255); 23 | 24 | brls::Theme* custom_dark = new brls::HorizonDarkTheme(); 25 | custom_dark->buttonPrimaryDisabledBackgroundColor = nvgRGB(136, 90, 75); 26 | custom_dark->buttonPrimaryDisabledTextColor = nvgRGB(167, 129, 118); 27 | custom_dark->buttonPrimaryEnabledBackgroundColor = nvgRGB(255, 59, 0); 28 | custom_dark->buttonPrimaryEnabledTextColor = nvgRGB(255, 247, 255); 29 | 30 | return new brls::LibraryViewsThemeVariantsWrapper(custom_light, custom_dark); 31 | } 32 | -------------------------------------------------------------------------------- /source/views/create_backup_view.cpp: -------------------------------------------------------------------------------- 1 | #include "views/create_backup_view.hpp" 2 | #include "views/confirm_view.hpp" 3 | #include "views/worker_view.hpp" 4 | #include "core/file_operations.hpp" 5 | 6 | using namespace std; 7 | using namespace brls::i18n::literals; 8 | 9 | CreateBackupView::CreateBackupView(bool canUseLed) : ListItem("translations/create_backup_view/title"_i18n) 10 | { 11 | this->getClickEvent()->subscribe([canUseLed](brls::View* view) { 12 | brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); 13 | stagedFrame->setTitle("Create manual backup"); 14 | 15 | stagedFrame->addStage( 16 | new ConfirmView(stagedFrame, "translations/create_backup_view/warning"_i18n, false, canUseLed) 17 | ); 18 | stagedFrame->addStage( 19 | new WorkerView(stagedFrame, "translations/create_backup_view/working"_i18n, [](){ 20 | manualBackup(); 21 | }) 22 | ); 23 | stagedFrame->addStage( 24 | new ConfirmView(stagedFrame, "translations/create_backup_view/complete"_i18n, true, canUseLed) 25 | ); 26 | 27 | brls::Application::pushView(stagedFrame); 28 | stagedFrame->registerAction("", brls::Key::PLUS, []{return true;}, true); 29 | stagedFrame->updateActionHint(brls::Key::PLUS, ""); // make the change visible 30 | stagedFrame->registerAction("", brls::Key::B, []{return true;}, true); 31 | stagedFrame->updateActionHint(brls::Key::B, ""); // make the change visible 32 | }); 33 | } -------------------------------------------------------------------------------- /lib/zipper/include/defs.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | extern "C" 4 | { 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #if (defined(_WIN32)) || (defined(_WIN64)) 14 | # include 15 | # include 16 | #else 17 | # include 18 | # include 19 | #endif 20 | 21 | #include 22 | #include 23 | #include 24 | #define CASESENSITIVITY (0) 25 | #define WRITEBUFFERSIZE (8192) 26 | #define MAXFILENAME (256) 27 | 28 | #if (defined(_WIN32)) || (defined(_WIN64)) 29 | #define USEWIN32IOAPI 30 | #include "iowin32.h" 31 | #endif 32 | } 33 | 34 | #if (defined(_WIN32)) || (defined(_WIN64)) 35 | #include 36 | #endif 37 | 38 | #if (defined(_WIN32)) || (defined(_WIN64)) 39 | #define EXCEPTION_CLASS std::exception 40 | #else 41 | #define EXCEPTION_CLASS std::runtime_error 42 | #endif 43 | 44 | 45 | #if (defined(_WIN64)) && (!defined(__APPLE__)) 46 | #ifndef __USE_FILE_OFFSET64 47 | #define __USE_FILE_OFFSET64 48 | #endif 49 | #ifndef __USE_LARGEFILE64 50 | #define __USE_LARGEFILE64 51 | #endif 52 | #ifndef _LARGEFILE64_SOURCE 53 | #define _LARGEFILE64_SOURCE 54 | #endif 55 | #ifndef _FILE_OFFSET_BIT 56 | #define _FILE_OFFSET_BIT 64 57 | #endif 58 | #endif 59 | 60 | #if (defined(_WIN32)) || (defined(_WIN64)) 61 | # define MKDIR(d) _mkdir(d) 62 | # define CHDIR(d) _chdir(d) 63 | #else 64 | # define MKDIR(d) mkdir(d, 0775) 65 | # define CHDIR(d) chdir(d) 66 | #endif 67 | -------------------------------------------------------------------------------- /source/views/link_accounts_view.cpp: -------------------------------------------------------------------------------- 1 | #include "views/link_accounts_view.hpp" 2 | #include "views/confirm_view.hpp" 3 | #include "views/worker_view.hpp" 4 | #include "core/file_operations.hpp" 5 | #include "core/shared_settings.hpp" 6 | 7 | using namespace std; 8 | using namespace brls::i18n::literals; 9 | 10 | LinkAccountsView::LinkAccountsView(bool canUseLed) : ListItem("translations/link_accounts_view/title"_i18n) 11 | { 12 | this->getClickEvent()->subscribe([canUseLed](brls::View* view) { 13 | 14 | if (SharedSettings::instance().getSelectedCount() == 0) { 15 | brls::Application::notify("translations/errors/no_accounts_selected"_i18n); 16 | return; 17 | } 18 | 19 | brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); 20 | stagedFrame->setTitle("translations/link_accounts_view/title"_i18n); 21 | #ifndef LINKALHO_DEBUG 22 | stagedFrame->addStage( 23 | new ConfirmView(stagedFrame, "translations/link_accounts_view/warning"_i18n, false, canUseLed) 24 | ); 25 | #endif 26 | stagedFrame->addStage( 27 | new WorkerView(stagedFrame, "translations/link_accounts_view/working"_i18n, [](){ 28 | linkAccounts(); 29 | }) 30 | ); 31 | stagedFrame->addStage( 32 | new ConfirmView(stagedFrame, "translations/link_accounts_view/complete"_i18n, true, canUseLed) 33 | ); 34 | 35 | brls::Application::pushView(stagedFrame); 36 | stagedFrame->registerAction("", brls::Key::PLUS, []{return true;}, true); 37 | stagedFrame->updateActionHint(brls::Key::PLUS, ""); // make the change visible 38 | stagedFrame->registerAction("", brls::Key::B, []{return true;}, true); 39 | stagedFrame->updateActionHint(brls::Key::B, ""); // make the change visible 40 | }); 41 | } -------------------------------------------------------------------------------- /source/views/unlink_accounts_view.cpp: -------------------------------------------------------------------------------- 1 | #include "views/unlink_accounts_view.hpp" 2 | #include "views/confirm_view.hpp" 3 | #include "views/worker_view.hpp" 4 | #include "core/file_operations.hpp" 5 | #include "core/shared_settings.hpp" 6 | 7 | #include 8 | 9 | using namespace std; 10 | using namespace brls::i18n::literals; 11 | 12 | UnlinkAccountsView::UnlinkAccountsView(bool canUseLed) : ListItem("translations/unlink_accounts_view/title"_i18n) 13 | { 14 | this->getClickEvent()->subscribe([this, canUseLed](brls::View* view) { 15 | 16 | if (SharedSettings::instance().getSelectedCount() == 0) { 17 | brls::Application::notify("translations/errors/no_accounts_selected"_i18n); 18 | return; 19 | } 20 | 21 | brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); 22 | stagedFrame->setTitle("translations/unlink_accounts_view/title"_i18n); 23 | #ifndef LINKALHO_DEBUG 24 | stagedFrame->addStage( 25 | new ConfirmView(stagedFrame, "translations/unlink_accounts_view/warning"_i18n, false, canUseLed) 26 | ); 27 | #endif 28 | stagedFrame->addStage( 29 | new WorkerView(stagedFrame, "translations/unlink_accounts_view/working"_i18n, [this](){ 30 | unlinkAccounts(); 31 | }) 32 | ); 33 | stagedFrame->addStage( 34 | new ConfirmView(stagedFrame, "translations/unlink_accounts_view/complete"_i18n, true, canUseLed) 35 | ); 36 | 37 | brls::Application::pushView(stagedFrame); 38 | stagedFrame->registerAction("", brls::Key::PLUS, []{return true;}, true); 39 | stagedFrame->updateActionHint(brls::Key::PLUS, ""); // make the change visible 40 | stagedFrame->registerAction("", brls::Key::B, []{return true;}, true); 41 | stagedFrame->updateActionHint(brls::Key::B, ""); // make the change visible 42 | }); 43 | } -------------------------------------------------------------------------------- /include/core/shared_settings.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "core/switch_profile.hpp" 4 | #include "constants.hpp" 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | using namespace std; 12 | 13 | class SharedSettings{ 14 | private: 15 | SharedSettings() {} 16 | 17 | string countryCode = DEFAULT_COUNTRY_CODE; 18 | vector switchProfiles; 19 | 20 | public: 21 | 22 | void printSelection() { 23 | for(auto& p: this->switchProfiles) { 24 | cout << p.uid_str << " - " << (p.selected ? "selected" : "not selected") << endl; 25 | } 26 | } 27 | 28 | SharedSettings(const SharedSettings&) = delete; 29 | SharedSettings& operator=(const SharedSettings &) = delete; 30 | SharedSettings(SharedSettings &&) = delete; 31 | SharedSettings & operator=(SharedSettings &&) = delete; 32 | 33 | static auto& instance(){ 34 | static SharedSettings storage; 35 | return storage; 36 | } 37 | 38 | inline const string& getCountryCode() { 39 | return countryCode; 40 | } 41 | 42 | inline void setCountryCode(const string& code) { 43 | countryCode = code; 44 | cout << "new country code: " << code << endl; 45 | } 46 | 47 | void setProfileSelected(const AccountUid id, bool selected) { 48 | for(auto& p: this->switchProfiles) { 49 | if (p.id.uid[0] == id.uid[0] && p.id.uid[1] == id.uid[1]) { 50 | p.selected = selected; 51 | } 52 | } 53 | printSelection(); 54 | } 55 | 56 | size_t getSelectedCount() { 57 | return count_if(this->switchProfiles.begin(), this->switchProfiles.end(), [](const SwitchProfile& p) { return p.selected; }); 58 | } 59 | 60 | size_t getProfileCount() { 61 | return this->switchProfiles.size(); 62 | } 63 | 64 | void addProfile(const SwitchProfile& p) { 65 | this->switchProfiles.emplace_back(p); 66 | } 67 | 68 | vector& getSwitchProfiles() { 69 | return this->switchProfiles; 70 | } 71 | }; 72 | -------------------------------------------------------------------------------- /lib/zipper/include/ioapi_buf.h: -------------------------------------------------------------------------------- 1 | /* ioapi_buf.h -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | This version of ioapi is designed to buffer IO. 5 | 6 | Copyright (C) 1998-2003 Gilles Vollant 7 | (C) 2012-2014 Nathan Moinvaziri 8 | 9 | This program is distributed under the terms of the same license as zlib. 10 | See the accompanying LICENSE file for the full text of the license. 11 | */ 12 | 13 | #ifndef _IOAPI_BUF_H 14 | #define _IOAPI_BUF_H 15 | 16 | #include 17 | #include 18 | #include 19 | 20 | #include "zlib.h" 21 | #include "ioapi.h" 22 | 23 | #define IOBUF_BUFFERSIZE (64 * 1024) 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | voidpf ZCALLBACK fopen_buf_func OF((voidpf opaque,const char* filename,int mode)); 30 | voidpf ZCALLBACK fopen64_buf_func OF((voidpf opaque,const void* filename,int mode)); 31 | voidpf ZCALLBACK fopendisk_buf_func OF((voidpf opaque, voidpf stream_cd, int number_disk, int mode)); 32 | voidpf ZCALLBACK fopendisk64_buf_func OF((voidpf opaque, voidpf stream_cd, int number_disk, int mode)); 33 | uLong ZCALLBACK fread_buf_func OF((voidpf opaque,voidpf stream,void* buf,uLong size)); 34 | uLong ZCALLBACK fwrite_buf_func OF((voidpf opaque,voidpf stream,const void* buf,uLong size)); 35 | long ZCALLBACK ftell_buf_func OF((voidpf opaque,voidpf stream)); 36 | ZPOS64_T ZCALLBACK ftell64_buf_func OF((voidpf opaque, voidpf stream)); 37 | long ZCALLBACK fseek_buf_func OF((voidpf opaque,voidpf stream,uLong offset,int origin)); 38 | long ZCALLBACK fseek64_buf_func OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 39 | int ZCALLBACK fclose_buf_func OF((voidpf opaque,voidpf stream)); 40 | int ZCALLBACK ferror_buf_func OF((voidpf opaque,voidpf stream)); 41 | 42 | typedef struct ourbuffer_s { 43 | zlib_filefunc_def filefunc; 44 | zlib_filefunc64_def filefunc64; 45 | } ourbuffer_t; 46 | 47 | void fill_buffer_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def, ourbuffer_t *ourbuf)); 48 | void fill_buffer_filefunc64 OF((zlib_filefunc64_def* pzlib_filefunc_def, ourbuffer_t *ourbuf)); 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/pwd2key.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of RFC2898, which specifies key derivation from 33 | a password and a salt value. 34 | */ 35 | 36 | #ifndef PWD2KEY_H 37 | #define PWD2KEY_H 38 | 39 | #if defined(__cplusplus) 40 | extern "C" 41 | { 42 | #endif 43 | 44 | void derive_key( 45 | const unsigned char pwd[], /* the PASSWORD, and */ 46 | unsigned int pwd_len, /* its length */ 47 | const unsigned char salt[], /* the SALT and its */ 48 | unsigned int salt_len, /* length */ 49 | unsigned int iter, /* the number of iterations */ 50 | unsigned char key[], /* space for the output key */ 51 | unsigned int key_len); /* and its required length */ 52 | 53 | #if defined(__cplusplus) 54 | } 55 | #endif 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /lib/zipper/include/ioapi_mem.h: -------------------------------------------------------------------------------- 1 | /* ioapi_mem.h -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | This version of ioapi is designed to access memory rather than files. 5 | We do use a region of memory to put data in to and take it out of. We do 6 | not have auto-extending buffers and do not inform anyone else that the 7 | data has been written. It is really intended for accessing a zip archive 8 | embedded in an application such that I can write an installer with no 9 | external files. 10 | 11 | Copyright (C) 1998-2003 Gilles Vollant 12 | (C) 2003 Justin Fletcher 13 | 14 | This program is distributed under the terms of the same license as zlib. 15 | See the accompanying LICENSE file for the full text of the license. 16 | */ 17 | 18 | #ifndef _IOAPI_MEM_H 19 | #define _IOAPI_MEM_H 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "zlib.h" 26 | #include "ioapi.h" 27 | 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | voidpf ZCALLBACK fopen_mem_func OF((voidpf opaque,const char* filename,int mode)); 33 | voidpf ZCALLBACK fopendisk_mem_func OF((voidpf opaque, voidpf stream, int number_disk, int mode)); 34 | uLong ZCALLBACK fread_mem_func OF((voidpf opaque,voidpf stream,void* buf,uLong size)); 35 | uLong ZCALLBACK fwrite_mem_func OF((voidpf opaque,voidpf stream,const void* buf,uLong size)); 36 | long ZCALLBACK ftell_mem_func OF((voidpf opaque,voidpf stream)); 37 | long ZCALLBACK fseek_mem_func OF((voidpf opaque,voidpf stream,uLong offset,int origin)); 38 | int ZCALLBACK fclose_mem_func OF((voidpf opaque,voidpf stream)); 39 | int ZCALLBACK ferror_mem_func OF((voidpf opaque,voidpf stream)); 40 | 41 | typedef struct ourmemory_s { 42 | char *base; /* Base of the region of memory we're using */ 43 | uLong size; /* Size of the region of memory we're using */ 44 | uLong limit; /* Furthest we've written */ 45 | uLong cur_offset; /* Current offset in the area */ 46 | int grow; /* Growable memory buffer */ 47 | } ourmemory_t; 48 | 49 | void fill_memory_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def, ourmemory_t *ourmem)); 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /source/utils/reboot_payload.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include "utils/reboot_payload.h" 6 | #include "constants.hpp" 7 | 8 | #define IRAM_PAYLOAD_MAX_SIZE 0x2F000 9 | #define IRAM_PAYLOAD_BASE 0x40010000 10 | 11 | static alignas(0x1000) u8 g_reboot_payload[IRAM_PAYLOAD_MAX_SIZE]; 12 | static alignas(0x1000) u8 g_ff_page[0x1000]; 13 | static alignas(0x1000) u8 g_work_page[0x1000]; 14 | 15 | 16 | void do_iram_dram_copy(void *buf, uintptr_t iram_addr, size_t size, int option) { 17 | memcpy(g_work_page, buf, size); 18 | 19 | SecmonArgs args = {0}; 20 | args.X[0] = 0xF0000201; /* smcAmsIramCopy */ 21 | args.X[1] = (uintptr_t)g_work_page; /* DRAM Address */ 22 | args.X[2] = iram_addr; /* IRAM Address */ 23 | args.X[3] = size; /* Copy size */ 24 | args.X[4] = option; /* 0 = Read, 1 = Write */ 25 | svcCallSecureMonitor(&args); 26 | 27 | memcpy(buf, g_work_page, size); 28 | } 29 | 30 | void copy_to_iram(uintptr_t iram_addr, void *buf, size_t size) { 31 | do_iram_dram_copy(buf, iram_addr, size, 1); 32 | } 33 | 34 | void copy_from_iram(void *buf, uintptr_t iram_addr, size_t size) { 35 | do_iram_dram_copy(buf, iram_addr, size, 0); 36 | } 37 | 38 | static void clear_iram(void) { 39 | memset(g_ff_page, 0xFF, sizeof(g_ff_page)); 40 | for (size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += sizeof(g_ff_page)) { 41 | copy_to_iram(IRAM_PAYLOAD_BASE + i, g_ff_page, sizeof(g_ff_page)); 42 | } 43 | } 44 | 45 | static void inject_payload(void) { 46 | clear_iram(); 47 | 48 | for (size_t i = 0; i < IRAM_PAYLOAD_MAX_SIZE; i += 0x1000) { 49 | copy_to_iram(IRAM_PAYLOAD_BASE + i, &g_reboot_payload[i], 0x1000); 50 | } 51 | 52 | splSetConfig((SplConfigItem)65001, 2); 53 | } 54 | 55 | bool rebootToPayload(const char* payloadFile) 56 | { 57 | #ifndef LINKALHO_DEBUG 58 | Result rc = splInitialize(); 59 | if (R_FAILED(rc)) { 60 | return false; 61 | } else { 62 | FILE *f = fopen(payloadFile, "rb"); 63 | if (f == NULL) { 64 | splExit(); 65 | return false; 66 | } 67 | fread(g_reboot_payload, 1, sizeof(g_reboot_payload), f); 68 | fclose(f); 69 | inject_payload(); 70 | splExit(); 71 | } 72 | #endif 73 | return true; 74 | } -------------------------------------------------------------------------------- /source/views/restore_backup_view.cpp: -------------------------------------------------------------------------------- 1 | #include "views/restore_backup_view.hpp" 2 | #include "views/confirm_view.hpp" 3 | #include "views/worker_view.hpp" 4 | #include "core/file_operations.hpp" 5 | #include "constants.hpp" 6 | #include 7 | 8 | using namespace std; 9 | using namespace brls::i18n::literals; 10 | 11 | RestoreBackupView::RestoreBackupView(bool canUseLed) : ListItem("translations/restore_backup_view/title"_i18n) 12 | { 13 | struct stat buffer; 14 | bool backupExists = (stat(RESTORE_FILE_PATH, &buffer) == 0); 15 | 16 | if (backupExists) 17 | { 18 | this->getClickEvent()->subscribe([canUseLed](brls::View* view) { 19 | brls::StagedAppletFrame* stagedFrame = new brls::StagedAppletFrame(); 20 | stagedFrame->setTitle("translations/restore_backup_view/title"_i18n); 21 | 22 | stagedFrame->addStage( 23 | new ConfirmView(stagedFrame, "translations/restore_backup_view/warning"_i18n, false, canUseLed) 24 | ); 25 | stagedFrame->addStage( 26 | new WorkerView(stagedFrame, "translations/restore_backup_view/working"_i18n, [](){ 27 | restoreBackup(RESTORE_FILE_PATH); 28 | }) 29 | ); 30 | stagedFrame->addStage( 31 | new ConfirmView(stagedFrame, "translations/restore_backup_view/complete"_i18n, true, canUseLed) 32 | ); 33 | 34 | brls::Application::pushView(stagedFrame); 35 | stagedFrame->registerAction("", brls::Key::PLUS, []{return true;}, true); 36 | stagedFrame->updateActionHint(brls::Key::PLUS, ""); // make the change visible 37 | stagedFrame->registerAction("", brls::Key::B, []{return true;}, true); 38 | stagedFrame->updateActionHint(brls::Key::B, ""); // make the change visible 39 | }); 40 | } else { 41 | this->getClickEvent()->subscribe([](brls::View* view) { 42 | brls::Dialog* dialog = new brls::Dialog(fmt::format("translations/restore_backup_view/not_found_dialog_text"_i18n, RESTORE_FILE_PATH)); 43 | 44 | dialog->addButton("translations/restore_backup_view/not_found_dialog_btn"_i18n, [dialog](brls::View* view) { 45 | dialog->close(); 46 | }); 47 | dialog->open(); 48 | dialog->registerAction("", brls::Key::PLUS, []{return true;}, true); 49 | dialog->updateActionHint(brls::Key::PLUS, ""); // make the change visible 50 | }); 51 | this->setValue("translations/restore_backup_view/not_found_dialog_hint"_i18n, true, false); 52 | } 53 | } -------------------------------------------------------------------------------- /lib/zipper/source/aes/sha1.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 01/08/2005 31 | */ 32 | 33 | #ifndef _SHA1_H 34 | #define _SHA1_H 35 | 36 | #include 37 | #include "brg_types.h" 38 | 39 | #define SHA1_BLOCK_SIZE 64 40 | #define SHA1_DIGEST_SIZE 20 41 | 42 | #if defined(__cplusplus) 43 | extern "C" 44 | { 45 | #endif 46 | 47 | /* type to hold the SHA256 context */ 48 | 49 | typedef struct 50 | { uint_32t count[2]; 51 | uint_32t hash[5]; 52 | uint_32t wbuf[16]; 53 | } sha1_ctx; 54 | 55 | /* Note that these prototypes are the same for both bit and */ 56 | /* byte oriented implementations. However the length fields */ 57 | /* are in bytes or bits as appropriate for the version used */ 58 | /* and bit sequences are input as arrays of bytes in which */ 59 | /* bit sequences run from the most to the least significant */ 60 | /* end of each byte */ 61 | 62 | VOID_RETURN sha1_compile(sha1_ctx ctx[1]); 63 | 64 | VOID_RETURN sha1_begin(sha1_ctx ctx[1]); 65 | VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]); 66 | VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]); 67 | VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len); 68 | 69 | #if defined(__cplusplus) 70 | } 71 | #endif 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /source/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "styles/visual_overrides.hpp" 4 | #include "views/country_select_view.hpp" 5 | #include "views/restore_backup_view.hpp" 6 | #include "views/create_backup_view.hpp" 7 | #include "views/link_accounts_view.hpp" 8 | #include "views/unlink_accounts_view.hpp" 9 | #include "views/account_select_view.hpp" 10 | #include "core/file_operations.hpp" 11 | 12 | using namespace std; 13 | using namespace brls::i18n::literals; 14 | 15 | int main(int argc, char* argv[]) 16 | { 17 | pmshellInitialize(); 18 | bool canUseLed = false; 19 | if (R_SUCCEEDED(hidsysInitialize())) { 20 | canUseLed = true; 21 | } 22 | initDirs(); 23 | 24 | brls::i18n::loadTranslations(); 25 | 26 | auto linkalhoStyle = VisualOverrides::LinkalhoStyle(); 27 | auto linkalhoTheme = VisualOverrides::LinkalhoTheme(); 28 | 29 | if (!brls::Application::init(APP_TITLE_LOWER, linkalhoStyle, linkalhoTheme)) 30 | { 31 | brls::Logger::error(string("Unable to init ") + APP_TITLE); 32 | return EXIT_FAILURE; 33 | } 34 | 35 | brls::AppletFrame* rootFrame = new brls::AppletFrame(false, false); 36 | rootFrame->setTitle(string(APP_TITLE) + " v" + string(APP_VERSION)); 37 | if (R_SUCCEEDED(accountInitialize(AccountServiceType_System))) { 38 | s32 acc_count = 0; 39 | accountGetUserCount(&acc_count); 40 | accountExit(); 41 | } 42 | 43 | auto linkAccountsView = new LinkAccountsView(canUseLed); 44 | auto unlinkAccountsView = new UnlinkAccountsView(canUseLed); 45 | auto restoreBackupView = new RestoreBackupView(canUseLed); 46 | auto createBackupView = new CreateBackupView(canUseLed); 47 | auto countrySelectView = new CountrySelectView(); 48 | auto accountSelectView = new AccountSelectView(); 49 | 50 | auto operationList = new brls::List(); 51 | { 52 | operationList->addView(linkAccountsView); 53 | operationList->addView(unlinkAccountsView); 54 | operationList->addView(restoreBackupView); 55 | operationList->addView(createBackupView); 56 | operationList->addView(countrySelectView); 57 | operationList->addView(accountSelectView); 58 | } 59 | rootFrame->setContentView(operationList); 60 | 61 | brls::Application::pushView(rootFrame); 62 | rootFrame->registerAction("", brls::Key::MINUS, []{return true;}, true); 63 | rootFrame->updateActionHint(brls::Key::MINUS, ""); // make the change visible 64 | 65 | // Run the app 66 | while (brls::Application::mainLoop()) 67 | ; 68 | 69 | pmshellExit(); 70 | if (canUseLed) 71 | hidsysExit(); 72 | 73 | // Exit 74 | return EXIT_SUCCESS; 75 | } 76 | -------------------------------------------------------------------------------- /lib/zipper/include/unzipper.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace zipper { 12 | 13 | class ZipEntry; 14 | 15 | class Unzipper 16 | { 17 | public: 18 | Unzipper(std::istream& buffer); 19 | Unzipper(std::vector& buffer); 20 | Unzipper(const std::string& zipname); 21 | Unzipper(const std::string& zipname, const std::string& password); 22 | 23 | ~Unzipper(void); 24 | 25 | std::vector entries(); 26 | 27 | bool extract(const std::string& destination, const std::map& alternativeNames); 28 | bool extract(const std::string& destination=std::string()); 29 | bool extractEntry(const std::string& name, const std::string& destination = std::string()); 30 | bool extractEntryToStream(const std::string& name, std::ostream& stream); 31 | bool extractEntryToMemory(const std::string& name, std::vector& vec); 32 | 33 | void close(); 34 | 35 | private: 36 | std::string m_password; 37 | std::string m_zipname; 38 | std::istream& m_ibuffer; 39 | std::vector& m_vecbuffer; 40 | bool m_usingMemoryVector; 41 | bool m_usingStream; 42 | bool m_open; 43 | 44 | struct Impl; 45 | Impl* m_impl; 46 | }; 47 | 48 | 49 | class ZipEntry 50 | { 51 | private: 52 | typedef struct 53 | { 54 | unsigned int tm_sec; 55 | unsigned int tm_min; 56 | unsigned int tm_hour; 57 | unsigned int tm_mday; 58 | unsigned int tm_mon; 59 | unsigned int tm_year; 60 | } tm_s; 61 | 62 | public: 63 | ZipEntry(const std::string& name, unsigned long long int compressed_size, unsigned long long int uncompressed_size, 64 | int year, int month, int day, int hour, int minute, int second, unsigned long dosdate) 65 | : name(name), compressedSize(compressed_size), uncompressedSize(uncompressed_size), dosdate(dosdate) 66 | { 67 | // timestamp YYYY-MM-DD HH:MM:SS 68 | std::stringstream str; 69 | str << year << "-" << month << "-" << day << 70 | " " << hour << ":" << minute << ":" << second; 71 | timestamp = str.str(); 72 | 73 | unixdate.tm_year = year; 74 | unixdate.tm_mon = month; 75 | unixdate.tm_mday = day; 76 | unixdate.tm_hour = hour; 77 | unixdate.tm_min = minute; 78 | unixdate.tm_sec = second; 79 | } 80 | 81 | bool valid() { return !name.empty(); } 82 | 83 | std::string name, timestamp; 84 | unsigned long long int compressedSize, uncompressedSize; 85 | unsigned long dosdate; 86 | tm_s unixdate; 87 | }; 88 | } 89 | -------------------------------------------------------------------------------- /resources/i18n/en-US/translations.json: -------------------------------------------------------------------------------- 1 | { 2 | "restore_backup_view": { 3 | "title": "Restore backup", 4 | "not_found_dialog_hint": "Restore file not found!", 5 | "not_found_dialog_text": "To restore, please place your backup file into\n{}\n\nMake sure the backup is valid as it will overwrite the console's partition files and might cause your Switch to stop booting!", 6 | "not_found_dialog_btn": "close", 7 | "warning": "Restoring this backup WILL overwrite all files!\n(Your saves will be preserved)\n\nMake sure the backup is valid as it will overwrite the console's partition files and might cause your Switch to stop booting!", 8 | "working": "Restoring...", 9 | "complete": "Backup restored!" 10 | }, 11 | "create_backup_view": { 12 | "title": "Create manual backup", 13 | "warning": "All linking and unlinking operations will produce a backup before making changes!\n\nYou should only use this option if you want to manually create a backup.", 14 | "working": "Backing up...", 15 | "complete": "Backup created!" 16 | }, 17 | "link_accounts_view": { 18 | "title": "Link selected accounts", 19 | "warning": "Linking accounts will overwrite all previous links.\n(Your saves will be preserved)\n\nIf any of the selected accounts had a NNID link, it will be overwritten!", 20 | "working": "Linking...", 21 | "complete": "Accounts linked!" 22 | }, 23 | "unlink_accounts_view": { 24 | "title": "Unlink selected accounts", 25 | "warning": "Unlinking will change users accounts.\n(Your saves will be preserved)\n\nIf any of the selected accounts had a NNID link, it will be erased!", 26 | "working": "Uninking...", 27 | "complete": "Accounts unlinked!" 28 | }, 29 | "country_select_view": { 30 | "title": "Select country for linked accounts" 31 | }, 32 | "account_select_view": { 33 | "title": "Select accounts to link/unlink", 34 | "select_all": "Select all", 35 | "unselect_all": "Unselect all", 36 | "selected_count": "{}/{} selected", 37 | "extra_info": "Found {} account{}\nReboot to payload {}", 38 | "reboot_payload_disabled": "disabled", 39 | "reboot_payload_inactive": "inactive ({} not found)", 40 | "reboot_payload_active": "active" 41 | }, 42 | "account_list_item": { 43 | "linked": "Linked", 44 | "not_linked": "Not linked" 45 | }, 46 | "confirm_view": { 47 | "continue": "Continue", 48 | "back": "Back", 49 | "reboot": "Reboot", 50 | "reboot_to_payload": "Reboot to payload" 51 | }, 52 | "errors": { 53 | "no_accounts_selected": "No accounts selected!" 54 | } 55 | } -------------------------------------------------------------------------------- /source/views/worker_view.cpp: -------------------------------------------------------------------------------- 1 | #include "views/worker_view.hpp" 2 | #include "utils/progress_event.hpp" 3 | #include 4 | #include 5 | 6 | WorkerView::WorkerView(brls::StagedAppletFrame* frame, const std::string& warning, worker_func_t workerFunc): frame(frame), workerFunc(workerFunc) 7 | { 8 | 9 | this->progressDisp = new brls::ProgressDisplay(); 10 | this->progressDisp->setParent(this); 11 | 12 | this->label = new brls::Label(brls::LabelStyle::DIALOG, warning, true); 13 | this->label->setHorizontalAlign(NVG_ALIGN_CENTER); 14 | this->label->setParent(this); 15 | 16 | this->button = new brls::Button(brls::ButtonStyle::BORDERLESS); // avoid back button bug 17 | this->button->setParent(this); 18 | } 19 | 20 | void WorkerView::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx) 21 | { 22 | if (!this->workStarted) 23 | { 24 | this->workStarted = true; 25 | workerThread = new std::thread(&WorkerView::doWork, this); 26 | } 27 | else if (ProgressEvent::instance().finished()) 28 | { 29 | frame->nextStage(); 30 | } 31 | else 32 | { 33 | this->progressDisp->setProgress(ProgressEvent::instance().increment(), ProgressEvent::instance().getMax()); 34 | this->progressDisp->frame(ctx); 35 | 36 | this->label->frame(ctx); 37 | } 38 | } 39 | 40 | void WorkerView::doWork() 41 | { 42 | if (this->workerFunc) 43 | this->workerFunc(); 44 | //frame->nextStage(); 45 | } 46 | 47 | brls::View* WorkerView::getDefaultFocus() 48 | { 49 | return this->button; 50 | } 51 | 52 | void WorkerView::layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash) 53 | { 54 | this->label->setWidth(roundf((float)this->width * style->CrashFrame.labelWidth)); 55 | //this->label->invalidate(true); 56 | 57 | this->label->setBoundaries( 58 | this->x + this->width / 2 - this->label->getWidth() / 2, 59 | this->y + (this->height - style->AppletFrame.footerHeight) / 2, 60 | this->label->getWidth(), 61 | this->label->getHeight()); 62 | 63 | this->progressDisp->setBoundaries( 64 | this->x + this->width / 2 - style->CrashFrame.buttonWidth, 65 | this->y + this->height / 2, 66 | style->CrashFrame.buttonWidth * 2, 67 | style->CrashFrame.buttonHeight); 68 | 69 | // this->button->setBoundaries( 70 | // this->x, 71 | // this->y, 72 | // 0, 73 | // 0); 74 | } 75 | 76 | void WorkerView::willAppear(bool resetState) 77 | { 78 | this->progressDisp->willAppear(resetState); 79 | } 80 | 81 | void WorkerView::willDisappear(bool resetState) 82 | { 83 | this->progressDisp->willDisappear(resetState); 84 | } 85 | 86 | WorkerView::~WorkerView() 87 | { 88 | if (this->workStarted && workerThread->joinable()) 89 | { 90 | this->workerThread->join(); 91 | if (this->workerThread) 92 | delete this->workerThread; 93 | } 94 | 95 | delete this->progressDisp; 96 | delete this->label; 97 | delete this->button; 98 | } 99 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/prng.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This is the header file for an implementation of a random data pool based on 34 | the use of an external entropy function (inspired by Peter Gutmann's work). 35 | */ 36 | 37 | #ifndef _PRNG_H 38 | #define _PRNG_H 39 | 40 | #include "sha1.h" 41 | 42 | #define PRNG_POOL_LEN 256 /* minimum random pool size */ 43 | #define PRNG_MIN_MIX 20 /* min initial pool mixing iterations */ 44 | 45 | /* ensure that pool length is a multiple of the SHA1 digest size */ 46 | 47 | #define PRNG_POOL_SIZE (SHA1_DIGEST_SIZE * (1 + (PRNG_POOL_LEN - 1) / SHA1_DIGEST_SIZE)) 48 | 49 | #if defined(__cplusplus) 50 | extern "C" 51 | { 52 | #endif 53 | 54 | /* A function for providing entropy is a parameter in the prng_init() */ 55 | /* call. This function has the following form and returns a maximum */ 56 | /* of 'len' bytes of pseudo random data in the buffer 'buf'. It can */ 57 | /* return less than 'len' bytes but will be repeatedly called for more */ 58 | /* data in this case. */ 59 | 60 | typedef int (*prng_entropy_fn)(unsigned char buf[], unsigned int len); 61 | 62 | typedef struct 63 | { unsigned char rbuf[PRNG_POOL_SIZE]; /* the random pool */ 64 | unsigned char obuf[PRNG_POOL_SIZE]; /* pool output buffer */ 65 | unsigned int pos; /* output buffer position */ 66 | prng_entropy_fn entropy; /* entropy function pointer */ 67 | } prng_ctx; 68 | 69 | /* initialise the random stream generator */ 70 | void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]); 71 | 72 | /* obtain random bytes from the generator */ 73 | void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]); 74 | 75 | /* close the random stream generator */ 76 | void prng_end(prng_ctx ctx[1]); 77 | 78 | #if defined(__cplusplus) 79 | } 80 | #endif 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/hmac.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of HMAC, the FIPS standard keyed hash function 33 | */ 34 | 35 | #ifndef _HMAC_H 36 | #define _HMAC_H 37 | 38 | #include 39 | 40 | #if defined(__cplusplus) 41 | extern "C" 42 | { 43 | #endif 44 | 45 | #define USE_SHA1 46 | 47 | #if !defined(USE_SHA1) && !defined(USE_SHA256) 48 | #error define USE_SHA1 or USE_SHA256 to set the HMAC hash algorithm 49 | #endif 50 | 51 | #ifdef USE_SHA1 52 | 53 | #include "sha1.h" 54 | 55 | #define HASH_INPUT_SIZE SHA1_BLOCK_SIZE 56 | #define HASH_OUTPUT_SIZE SHA1_DIGEST_SIZE 57 | #define sha_ctx sha1_ctx 58 | #define sha_begin sha1_begin 59 | #define sha_hash sha1_hash 60 | #define sha_end sha1_end 61 | 62 | #endif 63 | 64 | #ifdef USE_SHA256 65 | 66 | #include "sha2.h" 67 | 68 | #define HASH_INPUT_SIZE SHA256_BLOCK_SIZE 69 | #define HASH_OUTPUT_SIZE SHA256_DIGEST_SIZE 70 | #define sha_ctx sha256_ctx 71 | #define sha_begin sha256_begin 72 | #define sha_hash sha256_hash 73 | #define sha_end sha256_end 74 | 75 | #endif 76 | 77 | #define HMAC_OK 0 78 | #define HMAC_BAD_MODE -1 79 | #define HMAC_IN_DATA 0xffffffff 80 | 81 | typedef struct 82 | { unsigned char key[HASH_INPUT_SIZE]; 83 | sha_ctx ctx[1]; 84 | unsigned long klen; 85 | } hmac_ctx; 86 | 87 | void hmac_sha_begin(hmac_ctx cx[1]); 88 | 89 | int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]); 90 | 91 | void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]); 92 | 93 | void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]); 94 | 95 | void hmac_sha(const unsigned char key[], unsigned long key_len, 96 | const unsigned char data[], unsigned long data_len, 97 | unsigned char mac[], unsigned long mac_len); 98 | 99 | #if defined(__cplusplus) 100 | } 101 | #endif 102 | 103 | #endif 104 | -------------------------------------------------------------------------------- /lib/zipper/source/tools.cpp: -------------------------------------------------------------------------------- 1 | #include "tools.h" 2 | #include "defs.h" 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | #include 9 | 10 | #if defined(WIN32) && !defined(CYGWIN) 11 | # include "tps/dirent.h" 12 | # include "tps/dirent.c" 13 | #else 14 | # include 15 | # include 16 | # include 17 | #endif /* WIN32 */ 18 | 19 | 20 | 21 | namespace zipper { 22 | 23 | /* calculate the CRC32 of a file, 24 | because to encrypt a file, we need known the CRC32 of the file before */ 25 | 26 | void getFileCrc(std::istream& input_stream, std::vector& buff, unsigned long& result_crc) 27 | { 28 | unsigned long calculate_crc = 0; 29 | unsigned long size_read = 0; 30 | unsigned long total_read = 0; 31 | 32 | do { 33 | input_stream.read(buff.data(), buff.size()); 34 | size_read = (unsigned long)input_stream.gcount(); 35 | 36 | if (size_read > 0) 37 | calculate_crc = crc32(calculate_crc, (const unsigned char*)buff.data(), size_read); 38 | 39 | total_read += size_read; 40 | 41 | } while (size_read > 0); 42 | 43 | input_stream.seekg(0); 44 | result_crc = calculate_crc; 45 | } 46 | 47 | bool isLargeFile(std::istream& input_stream) 48 | { 49 | ZPOS64_T pos = 0; 50 | input_stream.seekg(0, std::ios::end); 51 | pos = input_stream.tellg(); 52 | input_stream.seekg(0); 53 | 54 | return pos >= 0xffffffff; 55 | } 56 | 57 | bool checkFileExists(const std::string& filename) 58 | { 59 | return CDirEntry::exist(filename); 60 | } 61 | 62 | bool makedir(const std::string& newdir) 63 | { 64 | return CDirEntry::createDir(newdir); 65 | } 66 | 67 | void removeFolder(const std::string& foldername) 68 | { 69 | if (!CDirEntry::remove(foldername)) 70 | { 71 | std::vector files = filesFromDirectory(foldername); 72 | std::vector::iterator it = files.begin(); 73 | for (; it != files.end(); ++it) 74 | { 75 | if (isDirectory(*it) && *it != foldername) 76 | removeFolder(*it); 77 | else 78 | std::remove(it->c_str()); 79 | } 80 | CDirEntry::remove(foldername); 81 | } 82 | } 83 | 84 | bool isDirectory(const std::string& path) 85 | { 86 | return CDirEntry::isDir(path); 87 | } 88 | 89 | std::string parentDirectory(const std::string& filepath) 90 | { 91 | return CDirEntry::dirName(filepath); 92 | } 93 | 94 | std::string currentPath() 95 | { 96 | char buffer[1024]; 97 | getcwd(buffer, 1024); 98 | std::string result(buffer); 99 | return result; 100 | 101 | } 102 | 103 | 104 | std::vector filesFromDirectory(const std::string& path) 105 | { 106 | std::vector files; 107 | DIR* dir; 108 | struct dirent* entry; 109 | 110 | dir = opendir(path.c_str()); 111 | 112 | if (dir == NULL) 113 | { 114 | return files; 115 | } 116 | 117 | for (entry = readdir(dir); entry != NULL; entry = readdir(dir)) 118 | { 119 | std::string filename(entry->d_name); 120 | 121 | if (filename == "." || filename == "..") continue; 122 | 123 | if (CDirEntry::isDir(path + CDirEntry::Separator + filename)) 124 | { 125 | std::vector moreFiles = filesFromDirectory(path + CDirEntry::Separator + filename); 126 | std::copy(moreFiles.begin(), moreFiles.end(), std::back_inserter(files)); 127 | continue; 128 | } 129 | 130 | 131 | files.push_back(path + CDirEntry::Separator + filename); 132 | } 133 | 134 | closedir(dir); 135 | 136 | 137 | return files; 138 | } 139 | 140 | std::string fileNameFromPath(const std::string& fullPath) 141 | { 142 | return CDirEntry::fileName(fullPath); 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /source/core/generator.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "constants.hpp" 8 | #include "utils/utils.hpp" 9 | #include "core/shared_settings.hpp" 10 | #include "core/generator.hpp" 11 | 12 | #include 13 | 14 | using namespace std; 15 | 16 | // static auto BAAS_HEADER1 = 0xA5D192EA40AD1304; 17 | static auto BAAS_HEADER2 = 0x0000006E00000001; 18 | static auto BAAS_HEADER3 = 0x0000000100000001; 19 | static auto PROFILE = R"({"id":"#NAS_ID#","language":"#LOCALE#","timezone":"#TIMEZONE#","country":"#COUNTRY_CODE#","analyticsOptedIn":false,"gender":"male","emailOptedIn":false,"birthday":"1980-01-01","isChild":false,"email":"•","screenName":"•","region":"","loginId":"•","nickname":"•","isNnLinked":false,"isTwitterLinked":false,"isFacebookLinked":false,"isGoogleLinked":false})"; 20 | 21 | static mt19937_64 engine(chrono::duration_cast(chrono::system_clock::now().time_since_epoch()).count()); 22 | 23 | const string generateRandomAlphanumericString(size_t len) 24 | { 25 | static constexpr auto chars = 26 | "0123456789" 27 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ" 28 | "abcdefghijklmnopqrstuvwxyz"; 29 | 30 | uniform_int_distribution dist(0, strlen(chars) - 1); 31 | auto result = string(len, '\0'); 32 | generate_n(begin(result), len, [&]() { return chars[dist(engine)]; }); 33 | return result; 34 | } 35 | 36 | unsigned long generateBytes() 37 | { 38 | uniform_int_distribution byteGenerator(0x0UL, 0xFFFFFFFFFFFFFFFF); 39 | return byteGenerator(engine); 40 | } 41 | 42 | unsigned long generateNasId() 43 | { 44 | return generateBytes(); 45 | } 46 | 47 | unsigned long generateBaasId() 48 | { 49 | return generateBytes(); 50 | } 51 | 52 | const string generateBaasUserPassword() 53 | { 54 | return generateRandomAlphanumericString(40); 55 | } 56 | 57 | const string generateProfileDat() 58 | { 59 | return generateRandomAlphanumericString(128); 60 | } 61 | 62 | string stringReplace(const string& str, const string& from, const string& to) { 63 | string strCopy = str; 64 | size_t startPos = strCopy.find(from); 65 | if(startPos == string::npos) 66 | return str; 67 | strCopy.replace(startPos, from.length(), to); 68 | return strCopy; 69 | } 70 | 71 | Generator::Generator() 72 | { 73 | _baasUserId = generateBaasId(); 74 | _nasId = generateNasId(); 75 | stringstream ss; 76 | ss << std::hex << _nasId; 77 | _nasIdStr = ss.str(); 78 | } 79 | 80 | const string& Generator::nasIdStr() { 81 | return _nasIdStr; 82 | } 83 | 84 | 85 | void Generator::writeBaas(const string& fullpath) 86 | { 87 | ofstream ofs(fullpath, ios::binary); 88 | auto account_id = generateBaasId(); 89 | ofs.write(reinterpret_cast(&account_id), sizeof(account_id)); 90 | ofs.write(reinterpret_cast(&BAAS_HEADER2), sizeof(BAAS_HEADER2)); 91 | ofs.write(reinterpret_cast(&_nasId), sizeof(_nasId)); 92 | ofs.write(reinterpret_cast(&BAAS_HEADER3), sizeof(BAAS_HEADER3)); 93 | ofs.write(reinterpret_cast(&_baasUserId), sizeof(_baasUserId)); 94 | ofs << generateBaasUserPassword(); 95 | } 96 | 97 | void Generator::writeProfileDat(const string& fullpath) 98 | { 99 | ofstream ofs(fullpath, ios::binary); 100 | ofs << generateProfileDat(); 101 | } 102 | 103 | void Generator::writeProfileJson(const string& fullpath) 104 | { 105 | ofstream ofs(fullpath, ios::binary); 106 | string locale = getLocale(); 107 | string timezone = getTimezone(); 108 | string country_code = SharedSettings::instance().getCountryCode(); 109 | string generated_profile = stringReplace( 110 | stringReplace( 111 | stringReplace( 112 | stringReplace( 113 | PROFILE, 114 | "#NAS_ID#", 115 | _nasIdStr 116 | ), 117 | "#LOCALE#", 118 | locale 119 | ), 120 | "#TIMEZONE#", 121 | timezone 122 | ), 123 | "#COUNTRY_CODE#", 124 | country_code 125 | ); 126 | cout << "generated profile: " << generated_profile << endl; 127 | ofs << generated_profile; 128 | } 129 | -------------------------------------------------------------------------------- /source/views/confirm_view.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "views/confirm_view.hpp" 3 | #include "utils/reboot_payload.h" 4 | #include "utils/utils.hpp" 5 | #include 6 | #include 7 | 8 | using namespace std; 9 | using namespace brls::i18n::literals; 10 | 11 | ConfirmView::ConfirmView(brls::StagedAppletFrame* frame, const std::string& text, bool reboot, bool canUseLed): reboot(reboot), canUseLed(canUseLed) 12 | { 13 | auto payloadFile = getPayload(); 14 | this->frame = frame; 15 | this->reboot = reboot; 16 | 17 | string buttonLabel = "translations/confirm_view/continue"_i18n; 18 | if (reboot) { 19 | bool canRebootToPayload = isErista() && !payloadFile.empty(); 20 | buttonLabel = canRebootToPayload ? "translations/confirm_view/reboot_to_payload"_i18n : "translations/confirm_view/reboot"_i18n; 21 | } 22 | 23 | this->button = (new brls::Button(reboot ? brls::ButtonStyle::BORDERLESS : brls::ButtonStyle::PRIMARY))->setLabel(buttonLabel); 24 | 25 | this->button->setParent(this); 26 | this->button->getClickEvent()->subscribe([frame, this, payloadFile](View* view) { 27 | if (!this->frame->isLastStage()) { 28 | frame->nextStage(); 29 | } else { 30 | if (this->reboot) { 31 | if (!isErista() || payloadFile.empty() || !rebootToPayload(payloadFile.c_str())) { 32 | attemptForceReboot(); 33 | } 34 | } 35 | brls::Application::popView(); 36 | } 37 | }); 38 | 39 | this->label = new brls::Label(brls::LabelStyle::DIALOG, text, true); 40 | this->label->setHorizontalAlign(NVG_ALIGN_CENTER); 41 | this->label->setParent(this); 42 | 43 | if (!reboot) { 44 | this->registerAction("translations/confirm_view/back"_i18n, brls::Key::B, [this] { 45 | brls::Application::popView(); 46 | return true; 47 | }); 48 | } 49 | } 50 | 51 | void ConfirmView::draw(NVGcontext* vg, int x, int y, unsigned width, unsigned height, brls::Style* style, brls::FrameContext* ctx) 52 | { 53 | if (!this->reboot && !this->frame->isLastStage()) { 54 | auto end = std::chrono::high_resolution_clock::now(); 55 | auto missing = std::max(3l - std::chrono::duration_cast(end - start).count(), 0l); 56 | auto text = std::string(this->reboot ? "translations/confirm_view/reboot"_i18n: "translations/confirm_view/continue"_i18n); 57 | if (missing > 0) { 58 | this->button->setLabel(text + " (" + std::to_string(missing) + ")"); 59 | this->button->setState(brls::ButtonState::DISABLED); 60 | } else { 61 | this->button->setLabel(text); 62 | this->button->setState(brls::ButtonState::ENABLED); 63 | } 64 | this->button->invalidate(); 65 | } 66 | this->label->frame(ctx); 67 | this->button->frame(ctx); 68 | } 69 | 70 | brls::View* ConfirmView::getDefaultFocus() 71 | { 72 | return this->button; 73 | } 74 | 75 | void ConfirmView::layout(NVGcontext* vg, brls::Style* style, brls::FontStash* stash) 76 | { 77 | this->label->setWidth(this->width); 78 | this->label->invalidate(true); 79 | // this->label->setBackground(brls::ViewBackground::DEBUG); 80 | this->label->setBoundaries( 81 | this->x + this->width / 2 - this->label->getWidth() / 2, 82 | this->y + (this->height - this->label->getHeight() - this->y - style->CrashFrame.buttonHeight)/2, 83 | this->label->getWidth(), 84 | this->label->getHeight()); 85 | 86 | this->button->setBoundaries( 87 | this->x + this->width / 2 - style->CrashFrame.buttonWidth / 2, 88 | this->y + (this->height-style->CrashFrame.buttonHeight*3), 89 | style->CrashFrame.buttonWidth, 90 | style->CrashFrame.buttonHeight); 91 | this->button->invalidate(); 92 | 93 | start = std::chrono::high_resolution_clock::now() + std::chrono::milliseconds(150); 94 | if (this->canUseLed) { 95 | if (!this->reboot) { 96 | HidsysNotificationLedPattern pattern = getBreathePattern(); 97 | sendLedPattern(pattern); 98 | } else { 99 | HidsysNotificationLedPattern pattern = getConfirmPattern(); 100 | sendLedPattern(pattern); 101 | } 102 | } 103 | } 104 | 105 | void ConfirmView::willDisappear(bool resetState) 106 | { 107 | if (!this->reboot) { 108 | HidsysNotificationLedPattern pattern = getClearPattern(); 109 | sendLedPattern(pattern); 110 | } 111 | } 112 | 113 | ConfirmView::~ConfirmView() 114 | { 115 | delete this->label; 116 | delete this->button; 117 | } 118 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/fileenc.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file contains the header file for fileenc.c, which implements password 34 | based file encryption and authentication using AES in CTR mode, HMAC-SHA1 35 | authentication and RFC2898 password based key derivation. 36 | */ 37 | 38 | #ifndef _FENC_H 39 | #define _FENC_H 40 | 41 | #include "aes.h" 42 | #include "hmac.h" 43 | #include "pwd2key.h" 44 | 45 | #define PASSWORD_VERIFIER 46 | 47 | #define MAX_KEY_LENGTH 32 48 | #define MAX_PWD_LENGTH 128 49 | #define MAX_SALT_LENGTH 16 50 | #define KEYING_ITERATIONS 1000 51 | 52 | #ifdef PASSWORD_VERIFIER 53 | #define PWD_VER_LENGTH 2 54 | #else 55 | #define PWD_VER_LENGTH 0 56 | #endif 57 | 58 | #define GOOD_RETURN 0 59 | #define PASSWORD_TOO_LONG -100 60 | #define BAD_MODE -101 61 | 62 | /* 63 | Field lengths (in bytes) versus File Encryption Mode (0 < mode < 4) 64 | 65 | Mode Key Salt MAC Overhead 66 | 1 16 8 10 18 67 | 2 24 12 10 22 68 | 3 32 16 10 26 69 | 70 | The following macros assume that the mode value is correct. 71 | */ 72 | 73 | #define KEY_LENGTH(mode) (8 * (mode & 3) + 8) 74 | #define SALT_LENGTH(mode) (4 * (mode & 3) + 4) 75 | #define MAC_LENGTH(mode) (10) 76 | 77 | /* the context for file encryption */ 78 | 79 | #if defined(__cplusplus) 80 | extern "C" 81 | { 82 | #endif 83 | 84 | typedef struct 85 | { unsigned char nonce[AES_BLOCK_SIZE]; /* the CTR nonce */ 86 | unsigned char encr_bfr[AES_BLOCK_SIZE]; /* encrypt buffer */ 87 | aes_encrypt_ctx encr_ctx[1]; /* encryption context */ 88 | hmac_ctx auth_ctx[1]; /* authentication context */ 89 | unsigned int encr_pos; /* block position (enc) */ 90 | unsigned int pwd_len; /* password length */ 91 | unsigned int mode; /* File encryption mode */ 92 | } fcrypt_ctx; 93 | 94 | /* initialise file encryption or decryption */ 95 | 96 | int fcrypt_init( 97 | int mode, /* the mode to be used (input) */ 98 | const unsigned char pwd[], /* the user specified password (input) */ 99 | unsigned int pwd_len, /* the length of the password (input) */ 100 | const unsigned char salt[], /* the salt (input) */ 101 | #ifdef PASSWORD_VERIFIER 102 | unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */ 103 | #endif 104 | fcrypt_ctx cx[1]); /* the file encryption context (output) */ 105 | 106 | /* perform 'in place' encryption or decryption and authentication */ 107 | 108 | void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]); 109 | void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]); 110 | 111 | /* close encryption/decryption and return the MAC value */ 112 | /* the return value is the length of the MAC */ 113 | 114 | int fcrypt_end(unsigned char mac[], /* the MAC value (output) */ 115 | fcrypt_ctx cx[1]); /* the context (input) */ 116 | 117 | #if defined(__cplusplus) 118 | } 119 | #endif 120 | 121 | #endif 122 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/fileenc.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | ------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file implements password based file encryption and authentication 34 | using AES in CTR mode, HMAC-SHA1 authentication and RFC2898 password 35 | based key derivation. 36 | 37 | */ 38 | 39 | #include 40 | 41 | #include "fileenc.h" 42 | 43 | #if defined(__cplusplus) 44 | extern "C" 45 | { 46 | #endif 47 | 48 | /* subroutine for data encryption/decryption */ 49 | /* this could be speeded up a lot by aligning */ 50 | /* buffers and using 32 bit operations */ 51 | 52 | static void encr_data(unsigned char data[], unsigned long d_len, fcrypt_ctx cx[1]) 53 | { unsigned long i = 0, pos = cx->encr_pos; 54 | 55 | while(i < d_len) 56 | { 57 | if(pos == AES_BLOCK_SIZE) 58 | { unsigned int j = 0; 59 | /* increment encryption nonce */ 60 | while(j < 8 && !++cx->nonce[j]) 61 | ++j; 62 | /* encrypt the nonce to form next xor buffer */ 63 | aes_encrypt(cx->nonce, cx->encr_bfr, cx->encr_ctx); 64 | pos = 0; 65 | } 66 | 67 | data[i++] ^= cx->encr_bfr[pos++]; 68 | } 69 | 70 | cx->encr_pos = pos; 71 | } 72 | 73 | int fcrypt_init( 74 | int mode, /* the mode to be used (input) */ 75 | const unsigned char pwd[], /* the user specified password (input) */ 76 | unsigned int pwd_len, /* the length of the password (input) */ 77 | const unsigned char salt[], /* the salt (input) */ 78 | #ifdef PASSWORD_VERIFIER 79 | unsigned char pwd_ver[PWD_VER_LENGTH], /* 2 byte password verifier (output) */ 80 | #endif 81 | fcrypt_ctx cx[1]) /* the file encryption context (output) */ 82 | { unsigned char kbuf[2 * MAX_KEY_LENGTH + PWD_VER_LENGTH]; 83 | 84 | if(pwd_len > MAX_PWD_LENGTH) 85 | return PASSWORD_TOO_LONG; 86 | 87 | if(mode < 1 || mode > 3) 88 | return BAD_MODE; 89 | 90 | cx->mode = mode; 91 | cx->pwd_len = pwd_len; 92 | 93 | /* derive the encryption and authentication keys and the password verifier */ 94 | derive_key(pwd, pwd_len, salt, SALT_LENGTH(mode), KEYING_ITERATIONS, 95 | kbuf, 2 * KEY_LENGTH(mode) + PWD_VER_LENGTH); 96 | 97 | /* initialise the encryption nonce and buffer pos */ 98 | cx->encr_pos = AES_BLOCK_SIZE; 99 | /* if we need a random component in the encryption */ 100 | /* nonce, this is where it would have to be set */ 101 | memset(cx->nonce, 0, AES_BLOCK_SIZE * sizeof(unsigned char)); 102 | 103 | /* initialise for encryption using key 1 */ 104 | aes_encrypt_key(kbuf, KEY_LENGTH(mode), cx->encr_ctx); 105 | 106 | /* initialise for authentication using key 2 */ 107 | hmac_sha_begin(cx->auth_ctx); 108 | hmac_sha_key(kbuf + KEY_LENGTH(mode), KEY_LENGTH(mode), cx->auth_ctx); 109 | 110 | #ifdef PASSWORD_VERIFIER 111 | memcpy(pwd_ver, kbuf + 2 * KEY_LENGTH(mode), PWD_VER_LENGTH); 112 | #endif 113 | 114 | return GOOD_RETURN; 115 | } 116 | 117 | /* perform 'in place' encryption and authentication */ 118 | 119 | void fcrypt_encrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]) 120 | { 121 | encr_data(data, data_len, cx); 122 | hmac_sha_data(data, data_len, cx->auth_ctx); 123 | } 124 | 125 | /* perform 'in place' authentication and decryption */ 126 | 127 | void fcrypt_decrypt(unsigned char data[], unsigned int data_len, fcrypt_ctx cx[1]) 128 | { 129 | hmac_sha_data(data, data_len, cx->auth_ctx); 130 | encr_data(data, data_len, cx); 131 | } 132 | 133 | /* close encryption/decryption and return the MAC value */ 134 | 135 | int fcrypt_end(unsigned char mac[], fcrypt_ctx cx[1]) 136 | { 137 | hmac_sha_end(mac, MAC_LENGTH(cx->mode), cx->auth_ctx); 138 | return MAC_LENGTH(cx->mode); /* return MAC length in bytes */ 139 | } 140 | 141 | #if defined(__cplusplus) 142 | } 143 | #endif 144 | -------------------------------------------------------------------------------- /lib/zipper/include/crypt.h: -------------------------------------------------------------------------------- 1 | /* crypt.h -- base code for traditional PKWARE encryption 2 | Version 1.01e, February 12th, 2005 3 | 4 | Copyright (C) 1998-2005 Gilles Vollant 5 | Modifications for Info-ZIP crypting 6 | Copyright (C) 2003 Terry Thorsen 7 | 8 | This code is a modified version of crypting code in Info-ZIP distribution 9 | 10 | Copyright (C) 1990-2000 Info-ZIP. All rights reserved. 11 | 12 | See the Info-ZIP LICENSE file version 2000-Apr-09 or later for terms of use 13 | which also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html 14 | 15 | The encryption/decryption parts of this source code (as opposed to the 16 | non-echoing password parts) were originally written in Europe. The 17 | whole source package can be freely distributed, including from the USA. 18 | (Prior to January 2000, re-export from the US was a violation of US law.) 19 | 20 | This encryption code is a direct transcription of the algorithm from 21 | Roger Schlafly, described by Phil Katz in the file appnote.txt. This 22 | file (appnote.txt) is distributed with the PKZIP program (even in the 23 | version without encryption capabilities). 24 | 25 | If you don't need crypting in your application, just define symbols 26 | NOCRYPT and NOUNCRYPT. 27 | */ 28 | 29 | #define CRC32(c, b) ((*(pcrc_32_tab+(((int)(c) ^ (b)) & 0xff))) ^ ((c) >> 8)) 30 | 31 | /*********************************************************************** 32 | * Return the next byte in the pseudo-random sequence 33 | */ 34 | static int decrypt_byte(unsigned long* pkeys, const unsigned long* pcrc_32_tab) 35 | { 36 | unsigned temp; /* POTENTIAL BUG: temp*(temp^1) may overflow in an 37 | * unpredictable manner on 16-bit systems; not a problem 38 | * with any known compiler so far, though */ 39 | 40 | temp = ((unsigned)(*(pkeys+2)) & 0xffff) | 2; 41 | return (int)(((temp * (temp ^ 1)) >> 8) & 0xff); 42 | } 43 | 44 | /*********************************************************************** 45 | * Update the encryption keys with the next byte of plain text 46 | */ 47 | static int update_keys(unsigned long* pkeys,const unsigned long* pcrc_32_tab,int c) 48 | { 49 | (*(pkeys+0)) = CRC32((*(pkeys+0)), c); 50 | (*(pkeys+1)) += (*(pkeys+0)) & 0xff; 51 | (*(pkeys+1)) = (*(pkeys+1)) * 134775813L + 1; 52 | { 53 | register int keyshift = (int)((*(pkeys+1)) >> 24); 54 | (*(pkeys+2)) = CRC32((*(pkeys+2)), keyshift); 55 | } 56 | return c; 57 | } 58 | 59 | 60 | /*********************************************************************** 61 | * Initialize the encryption keys and the random header according to 62 | * the given password. 63 | */ 64 | static void init_keys(const char* passwd,unsigned long* pkeys,const unsigned long* pcrc_32_tab) 65 | { 66 | *(pkeys+0) = 305419896L; 67 | *(pkeys+1) = 591751049L; 68 | *(pkeys+2) = 878082192L; 69 | while (*passwd != 0) { 70 | update_keys(pkeys,pcrc_32_tab,(int)*passwd); 71 | passwd++; 72 | } 73 | } 74 | 75 | #define zdecode(pkeys,pcrc_32_tab,c) \ 76 | (update_keys(pkeys,pcrc_32_tab,c ^= decrypt_byte(pkeys,pcrc_32_tab))) 77 | 78 | #define zencode(pkeys,pcrc_32_tab,c,t) \ 79 | (t=decrypt_byte(pkeys,pcrc_32_tab), update_keys(pkeys,pcrc_32_tab,c), t^(c)) 80 | 81 | #ifdef INCLUDECRYPTINGCODE_IFCRYPTALLOWED 82 | 83 | #define RAND_HEAD_LEN 12 84 | /* "last resort" source for second part of crypt seed pattern */ 85 | # ifndef ZCR_SEED2 86 | # define ZCR_SEED2 3141592654UL /* use PI as default pattern */ 87 | # endif 88 | 89 | static int crypthead(const char* passwd, /* password string */ 90 | unsigned char* buf, /* where to write header */ 91 | int bufSize, 92 | unsigned long* pkeys, 93 | const unsigned long* pcrc_32_tab, 94 | unsigned long crcForCrypting) 95 | { 96 | int n; /* index in random header */ 97 | int t; /* temporary */ 98 | int c; /* random byte */ 99 | unsigned char header[RAND_HEAD_LEN-2]; /* random header */ 100 | static unsigned calls = 0; /* ensure different random header each time */ 101 | 102 | if (bufSize> 7) & 0xff; 117 | header[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, c, t); 118 | } 119 | /* Encrypt random header (last two bytes is high word of crc) */ 120 | init_keys(passwd, pkeys, pcrc_32_tab); 121 | for (n = 0; n < RAND_HEAD_LEN-2; n++) 122 | { 123 | buf[n] = (unsigned char)zencode(pkeys, pcrc_32_tab, header[n], t); 124 | } 125 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 16) & 0xff, t); 126 | buf[n++] = (unsigned char)zencode(pkeys, pcrc_32_tab, (int)(crcForCrypting >> 24) & 0xff, t); 127 | return n; 128 | } 129 | 130 | #endif 131 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/brg_endian.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | */ 20 | 21 | #ifndef _BRG_ENDIAN_H 22 | #define _BRG_ENDIAN_H 23 | 24 | #define IS_BIG_ENDIAN 4321 /* byte 0 is most significant (mc68k) */ 25 | #define IS_LITTLE_ENDIAN 1234 /* byte 0 is least significant (i386) */ 26 | 27 | /* Include files where endian defines and byteswap functions may reside */ 28 | #if defined( __sun ) 29 | # include 30 | #elif defined( __FreeBSD__ ) || defined( __OpenBSD__ ) || defined( __NetBSD__ ) 31 | # include 32 | #elif defined( BSD ) && ( BSD >= 199103 ) || defined( __APPLE__ ) || \ 33 | defined( __CYGWIN32__ ) || defined( __DJGPP__ ) || defined( __osf__ ) 34 | # include 35 | #elif defined( __linux__ ) || defined( __GNUC__ ) || defined( __GNU_LIBRARY__ ) 36 | # if !defined( __MINGW32__ ) && !defined( _AIX ) 37 | # include 38 | # if !defined( __BEOS__ ) 39 | # include 40 | # endif 41 | # endif 42 | #endif 43 | 44 | /* Now attempt to set the define for platform byte order using any */ 45 | /* of the four forms SYMBOL, _SYMBOL, __SYMBOL & __SYMBOL__, which */ 46 | /* seem to encompass most endian symbol definitions */ 47 | 48 | #if defined( BIG_ENDIAN ) && defined( LITTLE_ENDIAN ) 49 | # if defined( BYTE_ORDER ) && BYTE_ORDER == BIG_ENDIAN 50 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 51 | # elif defined( BYTE_ORDER ) && BYTE_ORDER == LITTLE_ENDIAN 52 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 53 | # endif 54 | #elif defined( BIG_ENDIAN ) 55 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 56 | #elif defined( LITTLE_ENDIAN ) 57 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 58 | #endif 59 | 60 | #if defined( _BIG_ENDIAN ) && defined( _LITTLE_ENDIAN ) 61 | # if defined( _BYTE_ORDER ) && _BYTE_ORDER == _BIG_ENDIAN 62 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 63 | # elif defined( _BYTE_ORDER ) && _BYTE_ORDER == _LITTLE_ENDIAN 64 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 65 | # endif 66 | #elif defined( _BIG_ENDIAN ) 67 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 68 | #elif defined( _LITTLE_ENDIAN ) 69 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 70 | #endif 71 | 72 | #if defined( __BIG_ENDIAN ) && defined( __LITTLE_ENDIAN ) 73 | # if defined( __BYTE_ORDER ) && __BYTE_ORDER == __BIG_ENDIAN 74 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 75 | # elif defined( __BYTE_ORDER ) && __BYTE_ORDER == __LITTLE_ENDIAN 76 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 77 | # endif 78 | #elif defined( __BIG_ENDIAN ) 79 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 80 | #elif defined( __LITTLE_ENDIAN ) 81 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 82 | #endif 83 | 84 | #if defined( __BIG_ENDIAN__ ) && defined( __LITTLE_ENDIAN__ ) 85 | # if defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __BIG_ENDIAN__ 86 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 87 | # elif defined( __BYTE_ORDER__ ) && __BYTE_ORDER__ == __LITTLE_ENDIAN__ 88 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 89 | # endif 90 | #elif defined( __BIG_ENDIAN__ ) 91 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 92 | #elif defined( __LITTLE_ENDIAN__ ) 93 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 94 | #endif 95 | 96 | /* if the platform byte order could not be determined, then try to */ 97 | /* set this define using common machine defines */ 98 | #if !defined(PLATFORM_BYTE_ORDER) 99 | 100 | #if defined( __alpha__ ) || defined( __alpha ) || defined( i386 ) || \ 101 | defined( __i386__ ) || defined( _M_I86 ) || defined( _M_IX86 ) || \ 102 | defined( __OS2__ ) || defined( sun386 ) || defined( __TURBOC__ ) || \ 103 | defined( vax ) || defined( vms ) || defined( VMS ) || \ 104 | defined( __VMS ) || defined( _M_X64 ) 105 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 106 | 107 | #elif defined( AMIGA ) || defined( applec ) || defined( __AS400__ ) || \ 108 | defined( _CRAY ) || defined( __hppa ) || defined( __hp9000 ) || \ 109 | defined( ibm370 ) || defined( mc68000 ) || defined( m68k ) || \ 110 | defined( __MRC__ ) || defined( __MVS__ ) || defined( __MWERKS__ ) || \ 111 | defined( sparc ) || defined( __sparc) || defined( SYMANTEC_C ) || \ 112 | defined( __VOS__ ) || defined( __TIGCC__ ) || defined( __TANDEM ) || \ 113 | defined( THINK_C ) || defined( __VMCMS__ ) || defined( _AIX ) 114 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 115 | 116 | #elif 0 /* **** EDIT HERE IF NECESSARY **** */ 117 | # define PLATFORM_BYTE_ORDER IS_LITTLE_ENDIAN 118 | #elif 0 /* **** EDIT HERE IF NECESSARY **** */ 119 | # define PLATFORM_BYTE_ORDER IS_BIG_ENDIAN 120 | #else 121 | # error Please edit lines 126 or 128 in brg_endian.h to set the platform byte order 122 | #endif 123 | 124 | #endif 125 | 126 | #endif 127 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/hmac.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of HMAC, the FIPS standard keyed hash function 33 | */ 34 | 35 | #include "hmac.h" 36 | #include "brg_types.h" 37 | 38 | #if defined(__cplusplus) 39 | extern "C" 40 | { 41 | #endif 42 | 43 | /* initialise the HMAC context to zero */ 44 | void hmac_sha_begin(hmac_ctx cx[1]) 45 | { 46 | memset(cx, 0, sizeof(hmac_ctx)); 47 | } 48 | 49 | /* input the HMAC key (can be called multiple times) */ 50 | int hmac_sha_key(const unsigned char key[], unsigned long key_len, hmac_ctx cx[1]) 51 | { 52 | if(cx->klen == HMAC_IN_DATA) /* error if further key input */ 53 | return HMAC_BAD_MODE; /* is attempted in data mode */ 54 | 55 | if(cx->klen + key_len > HASH_INPUT_SIZE) /* if the key has to be hashed */ 56 | { 57 | if(cx->klen <= HASH_INPUT_SIZE) /* if the hash has not yet been */ 58 | { /* started, initialise it and */ 59 | sha_begin(cx->ctx); /* hash stored key characters */ 60 | sha_hash(cx->key, cx->klen, cx->ctx); 61 | } 62 | 63 | sha_hash(key, key_len, cx->ctx); /* hash long key data into hash */ 64 | } 65 | else /* otherwise store key data */ 66 | memcpy(cx->key + cx->klen, key, key_len); 67 | 68 | cx->klen += key_len; /* update the key length count */ 69 | return HMAC_OK; 70 | } 71 | 72 | /* input the HMAC data (can be called multiple times) - */ 73 | /* note that this call terminates the key input phase */ 74 | void hmac_sha_data(const unsigned char data[], unsigned long data_len, hmac_ctx cx[1]) 75 | { unsigned int i; 76 | 77 | if(cx->klen != HMAC_IN_DATA) /* if not yet in data phase */ 78 | { 79 | if(cx->klen > HASH_INPUT_SIZE) /* if key is being hashed */ 80 | { /* complete the hash and */ 81 | sha_end(cx->key, cx->ctx); /* store the result as the */ 82 | cx->klen = HASH_OUTPUT_SIZE; /* key and set new length */ 83 | } 84 | 85 | /* pad the key if necessary */ 86 | memset(cx->key + cx->klen, 0, HASH_INPUT_SIZE - cx->klen); 87 | 88 | /* xor ipad into key value */ 89 | for(i = 0; i < (HASH_INPUT_SIZE >> 2); ++i) 90 | ((uint_32t*)cx->key)[i] ^= 0x36363636; 91 | 92 | /* and start hash operation */ 93 | sha_begin(cx->ctx); 94 | sha_hash(cx->key, HASH_INPUT_SIZE, cx->ctx); 95 | 96 | /* mark as now in data mode */ 97 | cx->klen = HMAC_IN_DATA; 98 | } 99 | 100 | /* hash the data (if any) */ 101 | if(data_len) 102 | sha_hash(data, data_len, cx->ctx); 103 | } 104 | 105 | /* compute and output the MAC value */ 106 | void hmac_sha_end(unsigned char mac[], unsigned long mac_len, hmac_ctx cx[1]) 107 | { unsigned char dig[HASH_OUTPUT_SIZE]; 108 | unsigned int i; 109 | 110 | /* if no data has been entered perform a null data phase */ 111 | if(cx->klen != HMAC_IN_DATA) 112 | hmac_sha_data((const unsigned char*)0, 0, cx); 113 | 114 | sha_end(dig, cx->ctx); /* complete the inner hash */ 115 | 116 | /* set outer key value using opad and removing ipad */ 117 | for(i = 0; i < (HASH_INPUT_SIZE >> 2); ++i) 118 | ((uint_32t*)cx->key)[i] ^= 0x36363636 ^ 0x5c5c5c5c; 119 | 120 | /* perform the outer hash operation */ 121 | sha_begin(cx->ctx); 122 | sha_hash(cx->key, HASH_INPUT_SIZE, cx->ctx); 123 | sha_hash(dig, HASH_OUTPUT_SIZE, cx->ctx); 124 | sha_end(dig, cx->ctx); 125 | 126 | /* output the hash value */ 127 | for(i = 0; i < mac_len; ++i) 128 | mac[i] = dig[i]; 129 | } 130 | 131 | /* 'do it all in one go' subroutine */ 132 | void hmac_sha(const unsigned char key[], unsigned long key_len, 133 | const unsigned char data[], unsigned long data_len, 134 | unsigned char mac[], unsigned long mac_len) 135 | { hmac_ctx cx[1]; 136 | 137 | hmac_sha_begin(cx); 138 | hmac_sha_key(key, key_len, cx); 139 | hmac_sha_data(data, data_len, cx); 140 | hmac_sha_end(mac, mac_len, cx); 141 | } 142 | 143 | #if defined(__cplusplus) 144 | } 145 | #endif 146 | -------------------------------------------------------------------------------- /lib/zipper/source/ioapi_mem.c: -------------------------------------------------------------------------------- 1 | /* ioapi_mem.h -- IO base function header for compress/uncompress .zip 2 | files using zlib + zip or unzip API 3 | 4 | This version of ioapi is designed to access memory rather than files. 5 | We do use a region of memory to put data in to and take it out of. We do 6 | not have auto-extending buffers and do not inform anyone else that the 7 | data has been written. It is really intended for accessing a zip archive 8 | embedded in an application such that I can write an installer with no 9 | external files. Creation of archives has not been attempted, although 10 | parts of the framework are present. 11 | 12 | Based on Unzip ioapi.c version 0.22, May 19th, 2003 13 | 14 | Copyright (C) 1998-2003 Gilles Vollant 15 | (C) 2003 Justin Fletcher 16 | 17 | This file is under the same license as the Unzip tool it is distributed 18 | with. 19 | */ 20 | 21 | 22 | #include 23 | #include 24 | #include 25 | 26 | #include "zlib.h" 27 | #include "ioapi.h" 28 | 29 | #include "ioapi_mem.h" 30 | 31 | #ifndef IOMEM_BUFFERSIZE 32 | # define IOMEM_BUFFERSIZE (64 * 1024) 33 | #endif 34 | 35 | voidpf ZCALLBACK fopen_mem_func (opaque, filename, mode) 36 | voidpf opaque; 37 | const char* filename; 38 | int mode; 39 | { 40 | ourmemory_t *mem = (ourmemory_t *)opaque; 41 | if (mem == NULL) 42 | return NULL; /* Mem structure passed in was null */ 43 | 44 | if (mode & ZLIB_FILEFUNC_MODE_CREATE) 45 | { 46 | if (mem->grow) 47 | { 48 | mem->size = IOMEM_BUFFERSIZE; 49 | mem->base = (char *)malloc(mem->size); 50 | } 51 | 52 | mem->limit = 0; /* When writing we start with 0 bytes written */ 53 | } 54 | else 55 | mem->limit = mem->size; 56 | 57 | mem->cur_offset = 0; 58 | 59 | return mem; 60 | } 61 | 62 | voidpf ZCALLBACK fopendisk_mem_func (opaque, stream, number_disk, mode) 63 | voidpf opaque; 64 | voidpf stream; 65 | int number_disk; 66 | int mode; 67 | { 68 | /* Not used */ 69 | return NULL; 70 | } 71 | 72 | uLong ZCALLBACK fread_mem_func (opaque, stream, buf, size) 73 | voidpf opaque; 74 | voidpf stream; 75 | void* buf; 76 | uLong size; 77 | { 78 | ourmemory_t *mem = (ourmemory_t *)stream; 79 | 80 | if (size > mem->size - mem->cur_offset) 81 | size = mem->size - mem->cur_offset; 82 | 83 | memcpy(buf, mem->base + mem->cur_offset, size); 84 | mem->cur_offset += size; 85 | 86 | return size; 87 | } 88 | 89 | 90 | uLong ZCALLBACK fwrite_mem_func (opaque, stream, buf, size) 91 | voidpf opaque; 92 | voidpf stream; 93 | const void* buf; 94 | uLong size; 95 | { 96 | ourmemory_t *mem = (ourmemory_t *)stream; 97 | char *newbase = NULL; 98 | int newmemsize = 0; 99 | 100 | if (size > mem->size - mem->cur_offset) 101 | { 102 | if (mem->grow) 103 | { 104 | newmemsize = mem->size; 105 | if (size < IOMEM_BUFFERSIZE) 106 | newmemsize += IOMEM_BUFFERSIZE; 107 | else 108 | newmemsize += size; 109 | newbase = (char *)malloc(newmemsize); 110 | memcpy(newbase, mem->base, mem->size); 111 | free(mem->base); 112 | mem->base = newbase; 113 | mem->size = newmemsize; 114 | } 115 | else 116 | size = mem->size - mem->cur_offset; 117 | } 118 | memcpy(mem->base + mem->cur_offset, buf, size); 119 | mem->cur_offset += size; 120 | if (mem->cur_offset > mem->limit) 121 | mem->limit = mem->cur_offset; 122 | 123 | return size; 124 | } 125 | 126 | long ZCALLBACK ftell_mem_func (opaque, stream) 127 | voidpf opaque; 128 | voidpf stream; 129 | { 130 | ourmemory_t *mem = (ourmemory_t *)stream; 131 | return mem->cur_offset; 132 | } 133 | 134 | long ZCALLBACK fseek_mem_func (opaque, stream, offset, origin) 135 | voidpf opaque; 136 | voidpf stream; 137 | uLong offset; 138 | int origin; 139 | { 140 | ourmemory_t *mem = (ourmemory_t *)stream; 141 | uLong new_pos; 142 | switch (origin) 143 | { 144 | case ZLIB_FILEFUNC_SEEK_CUR: 145 | new_pos = mem->cur_offset + offset; 146 | break; 147 | case ZLIB_FILEFUNC_SEEK_END: 148 | new_pos = mem->limit + offset; 149 | break; 150 | case ZLIB_FILEFUNC_SEEK_SET: 151 | new_pos = offset; 152 | break; 153 | default: 154 | return -1; 155 | } 156 | 157 | if (new_pos > mem->size) 158 | return 1; /* Failed to seek that far */ 159 | mem->cur_offset = new_pos; 160 | return 0; 161 | } 162 | 163 | int ZCALLBACK fclose_mem_func (opaque, stream) 164 | voidpf opaque; 165 | voidpf stream; 166 | { 167 | /* Even with grow = 1, caller must always free() memory */ 168 | return 0; 169 | } 170 | 171 | int ZCALLBACK ferror_mem_func (opaque, stream) 172 | voidpf opaque; 173 | voidpf stream; 174 | { 175 | /* We never return errors */ 176 | return 0; 177 | } 178 | 179 | void fill_memory_filefunc (pzlib_filefunc_def, ourmem) 180 | zlib_filefunc_def* pzlib_filefunc_def; 181 | ourmemory_t *ourmem; 182 | { 183 | pzlib_filefunc_def->zopen_file = fopen_mem_func; 184 | pzlib_filefunc_def->zopendisk_file = fopendisk_mem_func; 185 | pzlib_filefunc_def->zread_file = fread_mem_func; 186 | pzlib_filefunc_def->zwrite_file = fwrite_mem_func; 187 | pzlib_filefunc_def->ztell_file = ftell_mem_func; 188 | pzlib_filefunc_def->zseek_file = fseek_mem_func; 189 | pzlib_filefunc_def->zclose_file = fclose_mem_func; 190 | pzlib_filefunc_def->zerror_file = ferror_mem_func; 191 | pzlib_filefunc_def->opaque = ourmem; 192 | } 193 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/prng.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman < >, Worcester, UK. 4 | All rights reserved. 5 | 6 | LICENSE TERMS 7 | 8 | The free distribution and use of this software in both source and binary 9 | form is allowed (with or without changes) provided that: 10 | 11 | 1. distributions of this source code include the above copyright 12 | notice, this list of conditions and the following disclaimer; 13 | 14 | 2. distributions in binary form include the above copyright 15 | notice, this list of conditions and the following disclaimer 16 | in the documentation and/or other associated materials; 17 | 18 | 3. the copyright holder's name is not used to endorse products 19 | built using this software without specific written permission. 20 | 21 | ALTERNATIVELY, provided that this notice is retained in full, this product 22 | may be distributed under the terms of the GNU General Public License (GPL), 23 | in which case the provisions of the GPL apply INSTEAD OF those given above. 24 | 25 | DISCLAIMER 26 | 27 | This software is provided 'as is' with no explicit or implied warranties 28 | in respect of its properties, including, but not limited to, correctness 29 | and/or fitness for purpose. 30 | --------------------------------------------------------------------------- 31 | Issue Date: 24/01/2003 32 | 33 | This file implements a random data pool based on the use of an external 34 | entropy function. It is based on the ideas advocated by Peter Gutmann in 35 | his work on pseudo random sequence generators. It is not a 'paranoid' 36 | random sequence generator and no attempt is made to protect the pool 37 | from prying eyes either by memory locking or by techniques to obscure 38 | its location in memory. 39 | */ 40 | 41 | #include 42 | #include "prng.h" 43 | 44 | #if defined(__cplusplus) 45 | extern "C" 46 | { 47 | #endif 48 | 49 | /* mix a random data pool using the SHA1 compression function (as */ 50 | /* suggested by Peter Gutmann in his paper on random pools) */ 51 | 52 | static void prng_mix(unsigned char buf[]) 53 | { unsigned int i, len; 54 | sha1_ctx ctx[1]; 55 | 56 | /*lint -e{663} unusual array to pointer conversion */ 57 | for(i = 0; i < PRNG_POOL_SIZE; i += SHA1_DIGEST_SIZE) 58 | { 59 | /* copy digest size pool block into SHA1 hash block */ 60 | memcpy(ctx->hash, buf + (i ? i : PRNG_POOL_SIZE) 61 | - SHA1_DIGEST_SIZE, SHA1_DIGEST_SIZE); 62 | 63 | /* copy data from pool into the SHA1 data buffer */ 64 | len = PRNG_POOL_SIZE - i; 65 | memcpy(ctx->wbuf, buf + i, (len > SHA1_BLOCK_SIZE ? SHA1_BLOCK_SIZE : len)); 66 | 67 | if(len < SHA1_BLOCK_SIZE) 68 | memcpy(((char*)ctx->wbuf) + len, buf, SHA1_BLOCK_SIZE - len); 69 | 70 | /* compress using the SHA1 compression function */ 71 | sha1_compile(ctx); 72 | 73 | /* put digest size block back into the random pool */ 74 | memcpy(buf + i, ctx->hash, SHA1_DIGEST_SIZE); 75 | } 76 | } 77 | 78 | /* refresh the output buffer and update the random pool by adding */ 79 | /* entropy and remixing */ 80 | 81 | static void update_pool(prng_ctx ctx[1]) 82 | { unsigned int i = 0; 83 | 84 | /* transfer random pool data to the output buffer */ 85 | memcpy(ctx->obuf, ctx->rbuf, PRNG_POOL_SIZE); 86 | 87 | /* enter entropy data into the pool */ 88 | while(i < PRNG_POOL_SIZE) 89 | i += ctx->entropy(ctx->rbuf + i, PRNG_POOL_SIZE - i); 90 | 91 | /* invert and xor the original pool data into the pool */ 92 | for(i = 0; i < PRNG_POOL_SIZE; ++i) 93 | ctx->rbuf[i] ^= ~ctx->obuf[i]; 94 | 95 | /* mix the pool and the output buffer */ 96 | prng_mix(ctx->rbuf); 97 | prng_mix(ctx->obuf); 98 | } 99 | 100 | void prng_init(prng_entropy_fn fun, prng_ctx ctx[1]) 101 | { int i; 102 | 103 | /* clear the buffers and the counter in the context */ 104 | memset(ctx, 0, sizeof(prng_ctx)); 105 | 106 | /* set the pointer to the entropy collection function */ 107 | ctx->entropy = fun; 108 | 109 | /* initialise the random data pool */ 110 | update_pool(ctx); 111 | 112 | /* mix the pool a minimum number of times */ 113 | for(i = 0; i < PRNG_MIN_MIX; ++i) 114 | prng_mix(ctx->rbuf); 115 | 116 | /* update the pool to prime the pool output buffer */ 117 | update_pool(ctx); 118 | } 119 | 120 | /* provide random bytes from the random data pool */ 121 | 122 | void prng_rand(unsigned char data[], unsigned int data_len, prng_ctx ctx[1]) 123 | { unsigned char *rp = data; 124 | unsigned int len, pos = ctx->pos; 125 | 126 | while(data_len) 127 | { 128 | /* transfer 'data_len' bytes (or the number of bytes remaining */ 129 | /* the pool output buffer if less) into the output */ 130 | len = (data_len < PRNG_POOL_SIZE - pos ? data_len : PRNG_POOL_SIZE - pos); 131 | memcpy(rp, ctx->obuf + pos, len); 132 | rp += len; /* update ouput buffer position pointer */ 133 | pos += len; /* update pool output buffer pointer */ 134 | data_len -= len; /* update the remaining data count */ 135 | 136 | /* refresh the random pool if necessary */ 137 | if(pos == PRNG_POOL_SIZE) 138 | { 139 | update_pool(ctx); pos = 0; 140 | } 141 | } 142 | 143 | ctx->pos = pos; 144 | } 145 | 146 | void prng_end(prng_ctx ctx[1]) 147 | { 148 | /* ensure the data in the context is destroyed */ 149 | memset(ctx, 0, sizeof(prng_ctx)); 150 | } 151 | 152 | #if defined(__cplusplus) 153 | } 154 | #endif 155 | 156 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/aestab.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This file contains the code for declaring the tables needed to implement 21 | AES. The file aesopt.h is assumed to be included before this header file. 22 | If there are no global variables, the definitions here can be used to put 23 | the AES tables in a structure so that a pointer can then be added to the 24 | AES context to pass them to the AES routines that need them. If this 25 | facility is used, the calling program has to ensure that this pointer is 26 | managed appropriately. In particular, the value of the t_dec(in,it) item 27 | in the table structure must be set to zero in order to ensure that the 28 | tables are initialised. In practice the three code sequences in aeskey.c 29 | that control the calls to aes_init() and the aes_init() routine itself will 30 | have to be changed for a specific implementation. If global variables are 31 | available it will generally be preferable to use them with the precomputed 32 | FIXED_TABLES option that uses static global tables. 33 | 34 | The following defines can be used to control the way the tables 35 | are defined, initialised and used in embedded environments that 36 | require special features for these purposes 37 | 38 | the 't_dec' construction is used to declare fixed table arrays 39 | the 't_set' construction is used to set fixed table values 40 | the 't_use' construction is used to access fixed table values 41 | 42 | 256 byte tables: 43 | 44 | t_xxx(s,box) => forward S box 45 | t_xxx(i,box) => inverse S box 46 | 47 | 256 32-bit word OR 4 x 256 32-bit word tables: 48 | 49 | t_xxx(f,n) => forward normal round 50 | t_xxx(f,l) => forward last round 51 | t_xxx(i,n) => inverse normal round 52 | t_xxx(i,l) => inverse last round 53 | t_xxx(l,s) => key schedule table 54 | t_xxx(i,m) => key schedule table 55 | 56 | Other variables and tables: 57 | 58 | t_xxx(r,c) => the rcon table 59 | */ 60 | 61 | #if !defined( _AESTAB_H ) 62 | #define _AESTAB_H 63 | 64 | #if defined(__cplusplus) 65 | extern "C" { 66 | #endif 67 | 68 | #define t_dec(m,n) t_##m##n 69 | #define t_set(m,n) t_##m##n 70 | #define t_use(m,n) t_##m##n 71 | 72 | #if defined(FIXED_TABLES) 73 | # if !defined( __GNUC__ ) && (defined( __MSDOS__ ) || defined( __WIN16__ )) 74 | /* make tables far data to avoid using too much DGROUP space (PG) */ 75 | # define CONST const far 76 | # else 77 | # define CONST const 78 | # endif 79 | #else 80 | # define CONST 81 | #endif 82 | 83 | #if defined(DO_TABLES) 84 | # define EXTERN 85 | #else 86 | # define EXTERN extern 87 | #endif 88 | 89 | #if defined(_MSC_VER) && defined(TABLE_ALIGN) 90 | #define ALIGN __declspec(align(TABLE_ALIGN)) 91 | #else 92 | #define ALIGN 93 | #endif 94 | 95 | #if defined( __WATCOMC__ ) && ( __WATCOMC__ >= 1100 ) 96 | # define XP_DIR __cdecl 97 | #else 98 | # define XP_DIR 99 | #endif 100 | 101 | #if defined(DO_TABLES) && defined(FIXED_TABLES) 102 | #define d_1(t,n,b,e) EXTERN ALIGN CONST XP_DIR t n[256] = b(e) 103 | #define d_4(t,n,b,e,f,g,h) EXTERN ALIGN CONST XP_DIR t n[4][256] = { b(e), b(f), b(g), b(h) } 104 | EXTERN ALIGN CONST uint_32t t_dec(r,c)[RC_LENGTH] = rc_data(w0); 105 | #else 106 | #define d_1(t,n,b,e) EXTERN ALIGN CONST XP_DIR t n[256] 107 | #define d_4(t,n,b,e,f,g,h) EXTERN ALIGN CONST XP_DIR t n[4][256] 108 | EXTERN ALIGN CONST uint_32t t_dec(r,c)[RC_LENGTH]; 109 | #endif 110 | 111 | #if defined( SBX_SET ) 112 | d_1(uint_8t, t_dec(s,box), sb_data, h0); 113 | #endif 114 | #if defined( ISB_SET ) 115 | d_1(uint_8t, t_dec(i,box), isb_data, h0); 116 | #endif 117 | 118 | #if defined( FT1_SET ) 119 | d_1(uint_32t, t_dec(f,n), sb_data, u0); 120 | #endif 121 | #if defined( FT4_SET ) 122 | d_4(uint_32t, t_dec(f,n), sb_data, u0, u1, u2, u3); 123 | #endif 124 | 125 | #if defined( FL1_SET ) 126 | d_1(uint_32t, t_dec(f,l), sb_data, w0); 127 | #endif 128 | #if defined( FL4_SET ) 129 | d_4(uint_32t, t_dec(f,l), sb_data, w0, w1, w2, w3); 130 | #endif 131 | 132 | #if defined( IT1_SET ) 133 | d_1(uint_32t, t_dec(i,n), isb_data, v0); 134 | #endif 135 | #if defined( IT4_SET ) 136 | d_4(uint_32t, t_dec(i,n), isb_data, v0, v1, v2, v3); 137 | #endif 138 | 139 | #if defined( IL1_SET ) 140 | d_1(uint_32t, t_dec(i,l), isb_data, w0); 141 | #endif 142 | #if defined( IL4_SET ) 143 | d_4(uint_32t, t_dec(i,l), isb_data, w0, w1, w2, w3); 144 | #endif 145 | 146 | #if defined( LS1_SET ) 147 | #if defined( FL1_SET ) 148 | #undef LS1_SET 149 | #else 150 | d_1(uint_32t, t_dec(l,s), sb_data, w0); 151 | #endif 152 | #endif 153 | 154 | #if defined( LS4_SET ) 155 | #if defined( FL4_SET ) 156 | #undef LS4_SET 157 | #else 158 | d_4(uint_32t, t_dec(l,s), sb_data, w0, w1, w2, w3); 159 | #endif 160 | #endif 161 | 162 | #if defined( IM1_SET ) 163 | d_1(uint_32t, t_dec(i,m), mm_data, v0); 164 | #endif 165 | #if defined( IM4_SET ) 166 | d_4(uint_32t, t_dec(i,m), mm_data, v0, v1, v2, v3); 167 | #endif 168 | 169 | #if defined(__cplusplus) 170 | } 171 | #endif 172 | 173 | #endif 174 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Buy me a coffee](https://img.shields.io/badge/buy%20me%20a%20coffee-donate-yellow.svg)](https://paypal.me/rdmrocha) 2 | 3 | ![License](https://img.shields.io/badge/License-GPLv3-blue.svg) 4 | [![GitHub release](https://img.shields.io/github/release/rdmrocha/linkalho.svg)](https://github.com/rdmrocha/linkalho/releases/latest/) 5 | 6 | [![Github all releases](https://img.shields.io/github/downloads/rdmrocha/linkalho/total.svg)](https://GitHub.com/rdmrocha/linkalho/releases/latest/) 7 | [![Github all releases](https://img.shields.io/github/downloads/rdmrocha/linkalho/latest/total.svg)](https://GitHub.com/rdmrocha/linkalho/releases/latest/) 8 | 9 | 10 |

11 | 12 | # Linkalho 13 | 14 | Linkalho is an homebrew app that will link NNID accounts offline. It links (or unlinks) existing accounts so you won't lose your saves. 15 | This app does not create new accounts. If you create a new account and want to link it, just re-run the app. 16 | 17 |
18 | 19 | ## Why do I need this app? 20 | If you never had issues with games/apps failing to launch until you link your Switch user account and you never experienced issues with certain titles stuck in _Updating game data_ or certain official emulators presenting you with nothing else but a black screen instead of the game selection, then you don't need to use this homebrew. 21 | 22 |
23 | 24 | Do you like this app and find it useful? You can buy me a coffee clicking the link below. Thanks!
25 | 26 | 27 |
28 | 29 | ## Frequently Asked Questions: 30 | - Why can't I navigate the app via touchscreen or using the thumbs ticks? 31 | - This is a very simple and straightforward app that most users will only use once or twice. Unless Borealis developers implement this natively, there are no plans for me to extend their feature set. 32 | 33 | - Can I go online with a fake/generated linked account? 34 | - No! You have a hacked switch. Online is always a risk. 35 | 36 | - Can this app do "place whatever question here"? 37 | - You can start by reading the [previous section](https://github.com/rdmrocha/linkalho#why-do-i-need-this-app). This app will allow you to link/unlink a fake/generated NNID to your user accounts without the need for an internet connection, and that's it. If you still fail to understand what this is and its purpose, it's highly likely that you simply don't need this app. Worry not: if you ever need it, you'll know it. 38 | 39 |
40 | 41 | ## Installation: 42 | - Place the .nro file in the `/switch/linkalho` folder of your SDcard. 43 | - Go to the homebrew app and run Linkalho 44 | 45 |
46 | 47 | ### Reboot to payload 48 | After completing the selected operation, Linkalho will reboot to an existing payload if: 49 | - the console hardware is Erista and the user places a payload file in the application's root (`/switch/linkalho/reboot.bin`) 50 | 51 | Reboot to payload is not supported on Mariko hardware! 52 |
53 | 54 | ## Usage: 55 | 56 | ### Link selected accounts 57 | - Will link all selected accounts from the ones present on the console. If any of the existing accounts is already linked, it will be re-linked (regardless of the NNIDs being officially linked or not). 58 | This operation creates a backup in `/switch/linkalho/backups` 59 | 60 | ### Unlink selected accounts 61 | - Will remove NNID linking from any of the selected accounts on the console regardless of the NNIDs being officially linked or not. 62 | This operation creates a backup in `/switch/linkalho/backups` 63 | 64 | ### Restore backup 65 | - Restores any previous state from a backup file. The file must be placed in `/switch/linkalho/restore/restore.zip`. If not present, the UI will notify the user. 66 | This operation creates a backup in `/switch/linkalho/backups` 67 | 68 | ### Create manual backup 69 | - Will create a backup in `/switch/linkalho/backups`. 70 | All linking and unlinking operations will automatically produce a backup before making changes. 71 | You should only use this option if you want to manually create a backup! 72 | 73 | ### Select country for linked accounts 74 | - Allows the user to customize the country that will be injected into the linked account. This has impact in some software by showing the appropriate flag (like in mk8). 75 | 76 | ### Select accounts to link/unlink 77 | - Allows the user to pick which accounts are going to be linked/unlinked. It defaults to **_all_**. If no accounts are selected and the user tries to perform a link or unlink operation, the application will show an error. 78 | 79 |
80 | 81 | ## Screenshots 82 |

83 |

84 |

85 |

86 |

87 |

88 |

89 |

90 |

91 |

92 |

93 | 94 |
95 | 96 | ## Credits 97 | - [devkitPro](https://devkitpro.org) for the toolchain! 98 | - [natinusala (lib borealis)](https://github.com/natinusala/borealis) for the amazing library that mimicks the Switch's original UI and UX 99 | - [sebastiandev (zipper wrapper for minizip)](https://github.com/sebastiandev/zipper/) for their nice wrapper to the minizip 100 | - [Kronos2308](https://github.com/Kronos2308) for the help in the initial phases of research. 101 | - [SciresM](https://github.com/SciresM) for his "reboot to payload" code and [HamletDuFromage](https://github.com/HamletDuFromage) for the code contributions 102 | - **target** for the icon, the beta testing and for supplying crucial files that helped in the creation of the generators. 103 | - **boredomisacrime** for the beta testing. 104 | -------------------------------------------------------------------------------- /source/utils/utils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "constants.hpp" 5 | #include "utils/utils.hpp" 6 | #include 7 | #include 8 | 9 | void attemptForceReboot() 10 | { 11 | #ifndef LINKALHO_DEBUG 12 | Result rc = spsmInitialize(); 13 | if (R_FAILED(rc)) 14 | printf("spsmInit: %08X\n", rc); 15 | else 16 | { 17 | spsmShutdown(true); 18 | spsmExit(); 19 | } 20 | #else 21 | std::cout << "Reboot would happen here" << std::endl; 22 | #endif 23 | } 24 | 25 | HidsysNotificationLedPattern getBreathePattern() 26 | { 27 | HidsysNotificationLedPattern pattern; 28 | memset(&pattern, 0, sizeof(pattern)); 29 | 30 | pattern.baseMiniCycleDuration = 0x8; // 100ms. 31 | pattern.totalMiniCycles = 0x2; // 2 mini cycles. Last one 12.5ms. 32 | pattern.totalFullCycles = 0x0; // Repeat forever. 33 | pattern.startIntensity = 0x0; // 0% 34 | 35 | pattern.miniCycles[0].ledIntensity = 0xF; // 100%. 36 | pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Transition time 1.5s. 37 | pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms. 38 | pattern.miniCycles[1].ledIntensity = 0x0; // 0%. 39 | pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Transition time 1.5s. 40 | pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms. 41 | 42 | return pattern; 43 | } 44 | 45 | HidsysNotificationLedPattern getConfirmPattern() 46 | { 47 | HidsysNotificationLedPattern pattern; 48 | memset(&pattern, 0, sizeof(pattern)); 49 | 50 | pattern.baseMiniCycleDuration = 0x1; // 12.5ms. 51 | pattern.totalMiniCycles = 0x2; // 3 mini cycles. Last one 12.5ms. 52 | pattern.totalFullCycles = 0x3; // Repeat 3 times. 53 | pattern.startIntensity = 0x0; // 0%. 54 | 55 | pattern.miniCycles[0].ledIntensity = 0xF; // 100%. 56 | pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Transition time 187.5ms. 57 | pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms. 58 | pattern.miniCycles[1].ledIntensity = 0x0; // 0%. 59 | pattern.miniCycles[1].transitionSteps = 0x2; // 2 steps. Transition time 25ms. 60 | pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms. 61 | 62 | return pattern; 63 | } 64 | 65 | HidsysNotificationLedPattern getClearPattern() 66 | { 67 | HidsysNotificationLedPattern pattern; 68 | memset(&pattern, 0, sizeof(pattern)); 69 | return pattern; 70 | } 71 | 72 | void sendLedPattern(HidsysNotificationLedPattern pattern) 73 | { 74 | s32 totalEntries = 0; 75 | HidsysUniquePadId uniquePadIds[2] = {0}; 76 | memset(uniquePadIds, 0, sizeof(uniquePadIds)); 77 | Result res = hidsysGetUniquePadsFromNpad(HidNpadIdType_Handheld, uniquePadIds, 2, &totalEntries); 78 | if (R_SUCCEEDED(res)) { 79 | for (auto i = 0; i < totalEntries; ++i) { 80 | hidsysSetNotificationLedPattern(&pattern, uniquePadIds[i]); 81 | } 82 | } 83 | } 84 | 85 | const std::string getPayload() 86 | { 87 | // if an override payload exists, boot from it 88 | return std::filesystem::exists(CUSTOM_PAYLOAD_FILE_PATH) ? CUSTOM_PAYLOAD_FILE_PATH : ""; 89 | } 90 | 91 | HardwareType getHardwareType() { 92 | /** 93 | * Icosa = 0, // Erista retail 94 | * Copper = 1, // Erista prototype 95 | * Hoag = 2, // Mariko Lite Retail for 8.0.0+, Invalid for 1.0.0-7.0.1 96 | * Iowa = 3, // Mariko retail for 4.0.0+ 97 | * Calcio = 4, // Mariko prototype for 8.0.0+ 98 | * Five = 5, // Aula for 10.0.0+ 99 | */ 100 | 101 | if (splInitialize() != 0) return UnknownHardware; 102 | u64 hwType = 15; // invalid 103 | Result rc = splGetConfig(SplConfigItem_HardwareType, &hwType); 104 | splExit(); 105 | 106 | if (R_FAILED(rc)) return UnknownHardware; 107 | 108 | switch (hwType) { 109 | case 0: 110 | case 1: 111 | return Erista; 112 | case 2: 113 | case 3: 114 | case 4: 115 | return Mariko; 116 | case 5: 117 | return Aula; 118 | } 119 | return UnknownHardware; 120 | } 121 | 122 | bool isErista() { 123 | return getHardwareType() == Erista; 124 | } 125 | 126 | const std::string getLocale() { 127 | u64 languageCode=0; 128 | if (R_SUCCEEDED(setGetSystemLanguage(&languageCode)) && languageCode) { 129 | return std::string(reinterpret_cast(&languageCode)); 130 | } 131 | return std::string(DEFAULT_LOCALE); 132 | } 133 | 134 | const std::string getTimezone() { 135 | TimeLocationName tl; 136 | if (R_SUCCEEDED(setsysGetDeviceTimeZoneLocationName(&tl))) { 137 | return tl.name; 138 | } 139 | return DEFAULT_TIMEZONE; 140 | } 141 | 142 | Result baasAdministrator_getAccountId(Service *admin_srv, u64 *out_id) { 143 | return serviceDispatchOut(admin_srv, 1, *out_id); 144 | } 145 | 146 | Result baasAdministrator_getNasId(Service *admin_srv, u64 *out_id) { 147 | return serviceDispatchOut(admin_srv, 120, *out_id); 148 | } 149 | 150 | Result getBaasAccountAdministrator(const AccountUid user_id, Service *out_admin_srv) { 151 | return serviceDispatchIn(accountGetServiceSession(), 250, user_id, 152 | .out_num_objects = 1, 153 | .out_objects = out_admin_srv, 154 | ); 155 | } 156 | 157 | Result baasAdministrator_isLinkedWithNAS(Service *admin_srv, bool *out_linked) { 158 | return serviceDispatchOut(admin_srv, 250, *out_linked); 159 | } 160 | 161 | Result baasAdministrator_deleteRegistrationInfoLocally(Service *admin_srv) { 162 | return serviceDispatch(admin_srv, 203); 163 | } 164 | 165 | Result unlinkLocally(const AccountUid user_id) { 166 | Service baas; 167 | auto rc = getBaasAccountAdministrator(user_id, &baas); 168 | if(R_SUCCEEDED(rc)) { 169 | bool linked = false; 170 | rc = baasAdministrator_isLinkedWithNAS(&baas, &linked); 171 | std::cout << "is linked:" << linked << std::endl; 172 | if(R_SUCCEEDED(rc) && linked) { 173 | rc = baasAdministrator_deleteRegistrationInfoLocally(&baas); 174 | std::cout << (R_SUCCEEDED(rc) ? "Unlink successful" : "Unlink failed") << std::endl; 175 | } else { 176 | std::cout << (R_SUCCEEDED(rc) ? "Not linked" : "Could not query isLinkedWithNintendoAccount") << std::endl; 177 | } 178 | serviceClose(&baas); 179 | } else {std::cout << "could not elevate to baas administrator" << std::endl;} 180 | return rc; 181 | } -------------------------------------------------------------------------------- /lib/zipper/source/aes/pwd2key.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 26/08/2003 31 | 32 | This is an implementation of RFC2898, which specifies key derivation from 33 | a password and a salt value. 34 | */ 35 | 36 | #include 37 | #include "hmac.h" 38 | 39 | #if defined(__cplusplus) 40 | extern "C" 41 | { 42 | #endif 43 | 44 | void derive_key(const unsigned char pwd[], /* the PASSWORD */ 45 | unsigned int pwd_len, /* and its length */ 46 | const unsigned char salt[], /* the SALT and its */ 47 | unsigned int salt_len, /* length */ 48 | unsigned int iter, /* the number of iterations */ 49 | unsigned char key[], /* space for the output key */ 50 | unsigned int key_len)/* and its required length */ 51 | { 52 | unsigned int i, j, k, n_blk; 53 | unsigned char uu[HASH_OUTPUT_SIZE], ux[HASH_OUTPUT_SIZE]; 54 | hmac_ctx c1[1], c2[1], c3[1]; 55 | 56 | /* set HMAC context (c1) for password */ 57 | hmac_sha_begin(c1); 58 | hmac_sha_key(pwd, pwd_len, c1); 59 | 60 | /* set HMAC context (c2) for password and salt */ 61 | memcpy(c2, c1, sizeof(hmac_ctx)); 62 | hmac_sha_data(salt, salt_len, c2); 63 | 64 | /* find the number of SHA blocks in the key */ 65 | n_blk = 1 + (key_len - 1) / HASH_OUTPUT_SIZE; 66 | 67 | for(i = 0; i < n_blk; ++i) /* for each block in key */ 68 | { 69 | /* ux[] holds the running xor value */ 70 | memset(ux, 0, HASH_OUTPUT_SIZE); 71 | 72 | /* set HMAC context (c3) for password and salt */ 73 | memcpy(c3, c2, sizeof(hmac_ctx)); 74 | 75 | /* enter additional data for 1st block into uu */ 76 | uu[0] = (unsigned char)((i + 1) >> 24); 77 | uu[1] = (unsigned char)((i + 1) >> 16); 78 | uu[2] = (unsigned char)((i + 1) >> 8); 79 | uu[3] = (unsigned char)(i + 1); 80 | 81 | /* this is the key mixing iteration */ 82 | for(j = 0, k = 4; j < iter; ++j) 83 | { 84 | /* add previous round data to HMAC */ 85 | hmac_sha_data(uu, k, c3); 86 | 87 | /* obtain HMAC for uu[] */ 88 | hmac_sha_end(uu, HASH_OUTPUT_SIZE, c3); 89 | 90 | /* xor into the running xor block */ 91 | for(k = 0; k < HASH_OUTPUT_SIZE; ++k) 92 | ux[k] ^= uu[k]; 93 | 94 | /* set HMAC context (c3) for password */ 95 | memcpy(c3, c1, sizeof(hmac_ctx)); 96 | } 97 | 98 | /* compile key blocks into the key output */ 99 | j = 0; k = i * HASH_OUTPUT_SIZE; 100 | while(j < HASH_OUTPUT_SIZE && k < key_len) 101 | key[k++] = ux[j++]; 102 | } 103 | } 104 | 105 | #ifdef TEST 106 | 107 | #include 108 | 109 | struct 110 | { unsigned int pwd_len; 111 | unsigned int salt_len; 112 | unsigned int it_count; 113 | unsigned char *pwd; 114 | unsigned char salt[32]; 115 | unsigned char key[32]; 116 | } tests[] = 117 | { 118 | { 8, 4, 5, (unsigned char*)"password", 119 | { 120 | 0x12, 0x34, 0x56, 0x78 121 | }, 122 | { 123 | 0x5c, 0x75, 0xce, 0xf0, 0x1a, 0x96, 0x0d, 0xf7, 124 | 0x4c, 0xb6, 0xb4, 0x9b, 0x9e, 0x38, 0xe6, 0xb5 125 | } 126 | }, 127 | { 8, 8, 5, (unsigned char*)"password", 128 | { 129 | 0x12, 0x34, 0x56, 0x78, 0x78, 0x56, 0x34, 0x12 130 | }, 131 | { 132 | 0xd1, 0xda, 0xa7, 0x86, 0x15, 0xf2, 0x87, 0xe6, 133 | 0xa1, 0xc8, 0xb1, 0x20, 0xd7, 0x06, 0x2a, 0x49 134 | } 135 | }, 136 | { 8, 21, 1, (unsigned char*)"password", 137 | { 138 | "ATHENA.MIT.EDUraeburn" 139 | }, 140 | { 141 | 0xcd, 0xed, 0xb5, 0x28, 0x1b, 0xb2, 0xf8, 0x01, 142 | 0x56, 0x5a, 0x11, 0x22, 0xb2, 0x56, 0x35, 0x15 143 | } 144 | }, 145 | { 8, 21, 2, (unsigned char*)"password", 146 | { 147 | "ATHENA.MIT.EDUraeburn" 148 | }, 149 | { 150 | 0x01, 0xdb, 0xee, 0x7f, 0x4a, 0x9e, 0x24, 0x3e, 151 | 0x98, 0x8b, 0x62, 0xc7, 0x3c, 0xda, 0x93, 0x5d 152 | } 153 | }, 154 | { 8, 21, 1200, (unsigned char*)"password", 155 | { 156 | "ATHENA.MIT.EDUraeburn" 157 | }, 158 | { 159 | 0x5c, 0x08, 0xeb, 0x61, 0xfd, 0xf7, 0x1e, 0x4e, 160 | 0x4e, 0xc3, 0xcf, 0x6b, 0xa1, 0xf5, 0x51, 0x2b 161 | } 162 | } 163 | }; 164 | 165 | int main() 166 | { unsigned int i, j, key_len = 256; 167 | unsigned char key[256]; 168 | 169 | printf("\nTest of RFC2898 Password Based Key Derivation"); 170 | for(i = 0; i < 5; ++i) 171 | { 172 | derive_key(tests[i].pwd, tests[i].pwd_len, tests[i].salt, 173 | tests[i].salt_len, tests[i].it_count, key, key_len); 174 | 175 | printf("\ntest %i: ", i + 1); 176 | printf("key %s", memcmp(tests[i].key, key, 16) ? "is bad" : "is good"); 177 | for(j = 0; j < key_len && j < 64; j += 4) 178 | { 179 | if(j % 16 == 0) 180 | printf("\n"); 181 | printf("0x%02x%02x%02x%02x ", key[j], key[j + 1], key[j + 2], key[j + 3]); 182 | } 183 | printf(j < key_len ? " ... \n" : "\n"); 184 | } 185 | printf("\n"); 186 | return 0; 187 | } 188 | 189 | #if defined(__cplusplus) 190 | } 191 | #endif 192 | 193 | #endif 194 | -------------------------------------------------------------------------------- /source/views/account_select_view.cpp: -------------------------------------------------------------------------------- 1 | #include "views/account_select_view.hpp" 2 | #include "utils/utils.hpp" 3 | #include "core/shared_settings.hpp" 4 | #include "constants.hpp" 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | using namespace std; 11 | using namespace brls::i18n::literals; 12 | 13 | void AccountSelectView::computeValue() { 14 | this->setValue(fmt::format("translations/account_select_view/selected_count"_i18n, SharedSettings::instance().getSelectedCount(), SharedSettings::instance().getProfileCount()), false, false); 15 | HardwareType hwType = getHardwareType(); 16 | auto reboot_payload_text = "translations/account_select_view/reboot_payload_disabled"_i18n; 17 | if (hwType == Erista) { 18 | if (getPayload().empty()) { 19 | reboot_payload_text = fmt::format("translations/account_select_view/reboot_payload_inactive"_i18n, CUSTOM_PAYLOAD_FILE); 20 | } else { 21 | reboot_payload_text = "translations/account_select_view/reboot_payload_active"_i18n; 22 | } 23 | } 24 | this->setDescription(fmt::format("translations/account_select_view/extra_info"_i18n, SharedSettings::instance().getProfileCount(), (SharedSettings::instance().getProfileCount() == 1 ? "" : "s"), reboot_payload_text)); 25 | } 26 | 27 | AccountSelectView::AccountSelectView() : ListItem("translations/account_select_view/title"_i18n) 28 | { 29 | if (R_SUCCEEDED(accountInitialize(AccountServiceType_Administrator))) { 30 | AccountUid* uids = new AccountUid[ACC_USER_LIST_SIZE]; 31 | s32 userCount = 0; 32 | 33 | if (R_SUCCEEDED(accountListAllUsers(uids, ACC_USER_LIST_SIZE, &userCount))) { 34 | 35 | for (int i = 0; i < userCount; i++) { 36 | // Icon data 37 | u8* iconBuffer; 38 | u32 imageSize, realSize; 39 | AccountUid uid = uids[i]; 40 | // Lookup and cache the users details 41 | AccountProfile profile; 42 | AccountProfileBase profileBase = {}; 43 | 44 | if (R_SUCCEEDED(accountGetProfile(&profile, uid)) && R_SUCCEEDED(accountProfileGet(&profile, nullptr, &profileBase)) && R_SUCCEEDED(accountProfileGetImageSize(&profile, &imageSize)) && (iconBuffer = (u8*)malloc(imageSize)) != NULL && R_SUCCEEDED(accountProfileLoadImage(&profile, iconBuffer, imageSize, &realSize))) { 45 | stringstream uid_str; 46 | uid_str << setfill('0') << setw(8) << hex << (uid.uid[0] & 0xffffffff) << "-"; 47 | uid_str << setfill('0') << setw(4) << hex << ((uid.uid[0] >> 32) & 0xffff) << "-"; 48 | uid_str << setfill('0') << setw(4) << hex << ((uid.uid[0] >> 48) & 0xffff) << "-"; 49 | uid_str << setfill('0') << setw(2) << hex << (uid.uid[1] & 0xff); 50 | uid_str << setfill('0') << setw(2) << hex << ((uid.uid[1] >> 8) & 0xff) << "-"; 51 | uid_str << setfill('0') << setw(8) << hex << ((uid.uid[1] >> 32) & 0xffffffff); 52 | uid_str << setfill('0') << setw(4) << ((uid.uid[1] >> 16) & 0xffff); 53 | 54 | accountProfileClose(&profile); 55 | 56 | // extract current AccountId and NasId 57 | Service baas; 58 | const auto rc = getBaasAccountAdministrator(uid, &baas); 59 | uint64_t account_id = 0; 60 | uint64_t nas_id = 0; 61 | bool linked = false; 62 | 63 | if(R_SUCCEEDED(rc)) { 64 | if (R_FAILED(baasAdministrator_isLinkedWithNAS(&baas, &linked))) { 65 | cout << "Failed to extract link status" << endl; 66 | } 67 | if (R_FAILED(baasAdministrator_getAccountId(&baas, &account_id))) { 68 | cout << "Failed to extract account_id" << endl; 69 | } 70 | if (R_FAILED(baasAdministrator_getNasId(&baas, &nas_id))) { 71 | cout << "Failed to extract nas_id" << endl; 72 | } 73 | serviceClose(&baas); 74 | } 75 | 76 | auto item = SwitchProfile { 77 | .id = uid, 78 | .uid_str = uid_str.str(), 79 | .name = string(profileBase.nickname, 0x20), 80 | .icon = make_pair(iconBuffer, imageSize), 81 | .is_linked = linked, 82 | .account_id = account_id, 83 | .nas_id = nas_id, 84 | .selected = true 85 | }; 86 | SharedSettings::instance().addProfile(item); 87 | } 88 | } 89 | } 90 | 91 | delete[] uids; 92 | accountExit(); 93 | } 94 | 95 | this->getClickEvent()->subscribe([this](brls::View* view) { 96 | auto accountSelectFrame = new brls::AppletFrame(true, true); 97 | accountSelectFrame->setTitle("translations/account_select_view/title"_i18n); 98 | 99 | this->accountListItems.clear(); 100 | this->accountListItems.reserve( SharedSettings::instance().getProfileCount()); 101 | 102 | auto accountList = new brls::List(); 103 | for (auto& p : SharedSettings::instance().getSwitchProfiles()) { 104 | auto item = new AccountListItem(p, p.selected); 105 | item->getClickEvent()->subscribe([this](View* v){ 106 | auto itemPtr = reinterpret_cast(v); 107 | SharedSettings::instance().setProfileSelected(itemPtr->getAccountProfile().id, itemPtr->getToggleState()); 108 | }); 109 | this->accountListItems.emplace_back(item); 110 | accountList->addView(item); 111 | } 112 | accountSelectFrame->setContentView(accountList); 113 | 114 | brls::Application::pushView(accountSelectFrame); 115 | 116 | accountSelectFrame->registerAction("translations/account_select_view/unselect_all"_i18n, brls::Key::L, [this] { 117 | for (auto item: this->accountListItems) { 118 | item->forceState(false); 119 | } 120 | return true; 121 | }); 122 | accountSelectFrame->registerAction("translations/account_select_view/select_all"_i18n, brls::Key::R, [this] { 123 | for (auto item: this->accountListItems) { 124 | item->forceState(true); 125 | } 126 | return true; 127 | }); 128 | accountSelectFrame->registerAction("translations/confirm_view/back"_i18n, brls::Key::B, [this, &accountList] { 129 | this->computeValue(); 130 | brls::Application::popView(); 131 | return true; 132 | }); 133 | accountSelectFrame->registerAction("", brls::Key::PLUS, [this]{return true;}, true); 134 | accountSelectFrame->updateActionHint(brls::Key::PLUS, ""); // make the change visible 135 | }); 136 | this->computeValue(); 137 | } 138 | -------------------------------------------------------------------------------- /lib/zipper/include/ioapi.h: -------------------------------------------------------------------------------- 1 | /* ioapi.h -- IO base function header for compress/uncompress .zip 2 | part of the MiniZip project 3 | 4 | Copyright (C) 1998-2010 Gilles Vollant 5 | http://www.winimage.com/zLibDll/minizip.html 6 | Modifications for Zip64 support 7 | Copyright (C) 2009-2010 Mathias Svensson 8 | http://result42.com 9 | 10 | This program is distributed under the terms of the same license as zlib. 11 | See the accompanying LICENSE file for the full text of the license. 12 | */ 13 | 14 | #ifndef _ZLIBIOAPI64_H 15 | #define _ZLIBIOAPI64_H 16 | 17 | #if (!defined(_WIN32)) && (!defined(WIN32)) && (!defined(__APPLE__)) 18 | # ifndef __USE_FILE_OFFSET64 19 | # define __USE_FILE_OFFSET64 20 | # endif 21 | # ifndef __USE_LARGEFILE64 22 | # define __USE_LARGEFILE64 23 | # endif 24 | # ifndef _LARGEFILE64_SOURCE 25 | # define _LARGEFILE64_SOURCE 26 | # endif 27 | # ifndef _FILE_OFFSET_BIT 28 | # define _FILE_OFFSET_BIT 64 29 | # endif 30 | #endif 31 | 32 | #include 33 | #include 34 | #include "zlib.h" 35 | 36 | #define USE_FILE32API 37 | 38 | #if defined(USE_FILE32API) 39 | # define fopen64 fopen 40 | # define ftello64 ftell 41 | # define fseeko64 fseek 42 | #else 43 | # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) 44 | # define fopen64 fopen 45 | # define ftello64 ftello 46 | # define fseeko64 fseeko 47 | # endif 48 | # ifdef _MSC_VER 49 | # define fopen64 fopen 50 | # if (_MSC_VER >= 1400) && (!(defined(NO_MSCVER_FILE64_FUNC))) 51 | # define ftello64 _ftelli64 52 | # define fseeko64 _fseeki64 53 | # else /* old MSC */ 54 | # define ftello64 ftell 55 | # define fseeko64 fseek 56 | # endif 57 | # endif 58 | #endif 59 | 60 | /* a type choosen by DEFINE */ 61 | #ifdef HAVE_64BIT_INT_CUSTOM 62 | typedef 64BIT_INT_CUSTOM_TYPE ZPOS64_T; 63 | #else 64 | # ifdef HAS_STDINT_H 65 | # include "stdint.h" 66 | typedef uint64_t ZPOS64_T; 67 | # else 68 | # if defined(_MSC_VER) || defined(__BORLANDC__) 69 | typedef unsigned __int64 ZPOS64_T; 70 | # else 71 | typedef unsigned long long int ZPOS64_T; 72 | # endif 73 | # endif 74 | #endif 75 | 76 | #ifdef __cplusplus 77 | extern "C" { 78 | #endif 79 | 80 | #define ZLIB_FILEFUNC_SEEK_CUR (1) 81 | #define ZLIB_FILEFUNC_SEEK_END (2) 82 | #define ZLIB_FILEFUNC_SEEK_SET (0) 83 | 84 | #define ZLIB_FILEFUNC_MODE_READ (1) 85 | #define ZLIB_FILEFUNC_MODE_WRITE (2) 86 | #define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3) 87 | #define ZLIB_FILEFUNC_MODE_EXISTING (4) 88 | #define ZLIB_FILEFUNC_MODE_CREATE (8) 89 | 90 | #ifndef ZCALLBACK 91 | # if (defined(WIN32) || defined(_WIN32) || defined (WINDOWS) || \ 92 | defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK) 93 | # define ZCALLBACK CALLBACK 94 | # else 95 | # define ZCALLBACK 96 | # endif 97 | #endif 98 | 99 | typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode)); 100 | typedef voidpf (ZCALLBACK *opendisk_file_func) OF((voidpf opaque, voidpf stream, int number_disk, int mode)); 101 | typedef uLong (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size)); 102 | typedef uLong (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size)); 103 | typedef int (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream)); 104 | typedef int (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream)); 105 | 106 | typedef long (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream)); 107 | typedef long (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong offset, int origin)); 108 | 109 | /* here is the "old" 32 bits structure structure */ 110 | typedef struct zlib_filefunc_def_s 111 | { 112 | open_file_func zopen_file; 113 | opendisk_file_func zopendisk_file; 114 | read_file_func zread_file; 115 | write_file_func zwrite_file; 116 | tell_file_func ztell_file; 117 | seek_file_func zseek_file; 118 | close_file_func zclose_file; 119 | testerror_file_func zerror_file; 120 | voidpf opaque; 121 | } zlib_filefunc_def; 122 | 123 | typedef ZPOS64_T (ZCALLBACK *tell64_file_func) OF((voidpf opaque, voidpf stream)); 124 | typedef long (ZCALLBACK *seek64_file_func) OF((voidpf opaque, voidpf stream, ZPOS64_T offset, int origin)); 125 | typedef voidpf (ZCALLBACK *open64_file_func) OF((voidpf opaque, const void* filename, int mode)); 126 | typedef voidpf (ZCALLBACK *opendisk64_file_func)OF((voidpf opaque, voidpf stream, int number_disk, int mode)); 127 | 128 | typedef struct zlib_filefunc64_def_s 129 | { 130 | open64_file_func zopen64_file; 131 | opendisk64_file_func zopendisk64_file; 132 | read_file_func zread_file; 133 | write_file_func zwrite_file; 134 | tell64_file_func ztell64_file; 135 | seek64_file_func zseek64_file; 136 | close_file_func zclose_file; 137 | testerror_file_func zerror_file; 138 | voidpf opaque; 139 | } zlib_filefunc64_def; 140 | 141 | void fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def)); 142 | void fill_fopen64_filefunc OF((zlib_filefunc64_def* pzlib_filefunc_def)); 143 | 144 | /* now internal definition, only for zip.c and unzip.h */ 145 | typedef struct zlib_filefunc64_32_def_s 146 | { 147 | zlib_filefunc64_def zfile_func64; 148 | open_file_func zopen32_file; 149 | opendisk_file_func zopendisk32_file; 150 | tell_file_func ztell32_file; 151 | seek_file_func zseek32_file; 152 | } zlib_filefunc64_32_def; 153 | 154 | #define ZREAD64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zread_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 155 | #define ZWRITE64(filefunc,filestream,buf,size) ((*((filefunc).zfile_func64.zwrite_file)) ((filefunc).zfile_func64.opaque,filestream,buf,size)) 156 | /*#define ZTELL64(filefunc,filestream) ((*((filefunc).ztell64_file)) ((filefunc).opaque,filestream))*/ 157 | /*#define ZSEEK64(filefunc,filestream,pos,mode) ((*((filefunc).zseek64_file)) ((filefunc).opaque,filestream,pos,mode))*/ 158 | #define ZCLOSE64(filefunc,filestream) ((*((filefunc).zfile_func64.zclose_file)) ((filefunc).zfile_func64.opaque,filestream)) 159 | #define ZERROR64(filefunc,filestream) ((*((filefunc).zfile_func64.zerror_file)) ((filefunc).zfile_func64.opaque,filestream)) 160 | 161 | voidpf call_zopen64 OF((const zlib_filefunc64_32_def* pfilefunc,const void*filename,int mode)); 162 | voidpf call_zopendisk64 OF((const zlib_filefunc64_32_def* pfilefunc, voidpf filestream, int number_disk, int mode)); 163 | long call_zseek64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream, ZPOS64_T offset, int origin)); 164 | ZPOS64_T call_ztell64 OF((const zlib_filefunc64_32_def* pfilefunc,voidpf filestream)); 165 | 166 | void fill_zlib_filefunc64_32_def_from_filefunc32 OF((zlib_filefunc64_32_def* p_filefunc64_32,const zlib_filefunc_def* p_filefunc32)); 167 | 168 | #define ZOPEN64(filefunc,filename,mode) (call_zopen64((&(filefunc)),(filename),(mode))) 169 | #define ZOPENDISK64(filefunc,filestream,diskn,mode) (call_zopendisk64((&(filefunc)),(filestream),(diskn),(mode))) 170 | #define ZTELL64(filefunc,filestream) (call_ztell64((&(filefunc)),(filestream))) 171 | #define ZSEEK64(filefunc,filestream,pos,mode) (call_zseek64((&(filefunc)),(filestream),(pos),(mode))) 172 | 173 | #ifdef __cplusplus 174 | } 175 | #endif 176 | 177 | #endif 178 | -------------------------------------------------------------------------------- /lib/zipper/include/CDirEntry.h: -------------------------------------------------------------------------------- 1 | // Copyright (C) 2008 by Pedro Mendes, Virginia Tech Intellectual 2 | // Properties, Inc., EML Research, gGmbH, University of Heidelberg, 3 | // and The University of Manchester. 4 | // All rights reserved. 5 | 6 | // Copyright (C) 2001 - 2007 by Pedro Mendes, Virginia Tech Intellectual 7 | // Properties, Inc. and EML Research, gGmbH. 8 | // All rights reserved. 9 | 10 | #ifndef ZIPPER_CDirEntry 11 | #define ZIPPER_CDirEntry 12 | 13 | #include 14 | #include 15 | 16 | namespace zipper 17 | { 18 | /** 19 | * This class provides an OS independent interface to directory entries 20 | * such as files and directories. 21 | */ 22 | class CDirEntry 23 | { 24 | public: 25 | /** 26 | * The character used to separate directory entries. 27 | */ 28 | static const std::string Separator; 29 | 30 | /** 31 | * Check whether the directory entry specified by 'path' is 32 | * a file. 33 | * @param const std::string & path 34 | * @return bool isFile 35 | */ 36 | static bool isFile(const std::string & path); 37 | 38 | /** 39 | * Check whether the directory entry specified by 'path' is 40 | * is a directory. 41 | * @param const std::string & path 42 | * @return bool isDir 43 | */ 44 | static bool isDir(const std::string & path); 45 | 46 | /** 47 | * Check whether the directory entry specified by 'path' exists. 48 | * @param const std::string & path 49 | * @return bool exist 50 | */ 51 | static bool exist(const std::string & path); 52 | 53 | /** 54 | * Check whether the directory entry specified by 'path' is 55 | * is readable. 56 | * @param const std::string & path 57 | * @return bool isReadable 58 | */ 59 | static bool isReadable(const std::string & path); 60 | 61 | /** 62 | * Check whether the directory entry specified by 'path' is 63 | * writable. 64 | * @param const std::string & path 65 | * @return bool isWritable 66 | */ 67 | static bool isWritable(const std::string & path); 68 | 69 | /** 70 | * Returns the base name, i.e., the directory path and the 71 | * the suffix are removed from 'path'. 72 | * @param const std::string & path 73 | * @return std::string baseName 74 | */ 75 | static std::string baseName(const std::string & path); 76 | 77 | /** 78 | * Returns the file name, i.e., the directory path is removed from 'path'. 79 | * @param const std::string & path 80 | * @return std::string fileName 81 | */ 82 | static std::string fileName(const std::string & path); 83 | 84 | /** 85 | * Returns the directory path to the parent directoryu, i.e., 86 | * the file name or directory name are removed from 'path'. 87 | * @param const std::string & path 88 | * @return std::string dirName 89 | */ 90 | static std::string dirName(const std::string & path); 91 | 92 | /** 93 | * Returns the suffix, i.e., the directory path and the 94 | * the base name are removed from 'path'. 95 | * @param const std::string & path 96 | * @return std::string basename 97 | */ 98 | static std::string suffix(const std::string & path); 99 | 100 | /** 101 | * Create the directory 'dir' in the parent directory 'parent'. 102 | * @param const std::string & dir 103 | * @param const std::string & parent (Default: current working directory) 104 | * @return bool success 105 | */ 106 | static bool createDir(const std::string & dir, 107 | const std::string & parent = ""); 108 | 109 | /** 110 | * Create a name for a temporary directory entry. The directory entry 111 | * will be located in the directory given 112 | * @param const std::string & dir 113 | * @param const std::string & suffix 114 | * @return std::string tmpName 115 | */ 116 | static std::string createTmpName(const std::string & dir, 117 | const std::string & suffix); 118 | 119 | /** 120 | * Move a file from. If to is the directory the filename of from is 121 | * appended. 122 | * @param const std::string & from 123 | * @param const std::string & to 124 | * @return bool success 125 | */ 126 | static bool move(const std::string & from, 127 | const std::string & to); 128 | 129 | /** 130 | * Removes a file or directory specified by path. 131 | * @param const std::string & path 132 | * @return bool success 133 | */ 134 | static bool remove(const std::string & path); 135 | 136 | /** 137 | * Remove files or directories matching the pattern in directory dir. 138 | * @param const std::string & pattern 139 | * @param const std::string & dir 140 | * @return bool success 141 | */ 142 | static bool removeFiles(const std::string & pattern, 143 | const std::string & dir); 144 | 145 | /** 146 | * Compiles the pattern to a patternList. Valid wildcards in the pattern are: 147 | * '*' matches any number of characters and '?' matches exactly one character. 148 | * @param const std::string & pattern 149 | * @return std::vector< std::string > patternList 150 | */ 151 | static std::vector< std::string > compilePattern(const std::string & pattern); 152 | 153 | /** 154 | * Compare the name against the pattern list and returns whether the 155 | * name matches. The patternList can be created from a pattern by the 156 | * compilePattern method. 157 | * @param const std::string & name 158 | * @param const std::vector< std::string > & patternList 159 | * @return bool match 160 | */ 161 | static bool match(const std::string & name, 162 | const std::vector< std::string > & patternList); 163 | 164 | /** 165 | * Checks whether the given path is relative 166 | * @return bool isRelative 167 | */ 168 | static bool isRelativePath(const std::string & path); 169 | 170 | /** 171 | * Makes the absolute path relative to the path given in relativeTo 172 | * @param std::string & absolutePath 173 | * @param const std::string & relativeTo 174 | * @return bool success 175 | */ 176 | static bool makePathRelative(std::string & absolutePath, 177 | const std::string & relativeTo); 178 | 179 | /** 180 | * Makes the relative path absolute to the path given in absoluteTo 181 | * @param std::string & relativePath 182 | * @param const std::string & absoluteTo 183 | * @return bool success 184 | */ 185 | static bool makePathAbsolute(std::string & relativePath, 186 | const std::string & absoluteTo); 187 | 188 | /** 189 | * This method normalizes the path, i.e., 190 | * it converts all '\' to '/' (only on WIN32) 191 | * and collapses '^./' to '^', '/./' to '/', and '[^/]+/../' to '/' 192 | * @param const std::string & path 193 | * @return std::string normalizedPath 194 | */ 195 | static std::string normalize(const std::string & path); 196 | 197 | private: 198 | /** 199 | * This private methods checks whether the active section matches the 200 | * specified patter. The section is automatically advanced to allow 201 | * repeated calls. On the first call 'at' must be 0. The parameters 202 | * 'at' and 'after' must not be changed outside this method. 203 | * @param const std::string & name 204 | * @param const std::string pattern 205 | * @param std::string::size_type & at 206 | * @param std::string::size_type & after 207 | * @return bool match 208 | */ 209 | static bool matchInternal(const std::string & name, 210 | const std::string pattern, 211 | std::string::size_type & at, 212 | std::string::size_type & after); 213 | }; 214 | } 215 | #endif // ZIPPER_CDirEntry 216 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/aes.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | This file contains the definitions required to use AES in C. See aesopt.h 21 | for optimisation details. 22 | */ 23 | 24 | #ifndef _AES_H 25 | #define _AES_H 26 | 27 | #include 28 | 29 | /* This include is used to find 8 & 32 bit unsigned integer types */ 30 | #include "brg_types.h" 31 | 32 | #if defined(__cplusplus) 33 | extern "C" 34 | { 35 | #endif 36 | 37 | #define AES_128 /* if a fast 128 bit key scheduler is needed */ 38 | #define AES_192 /* if a fast 192 bit key scheduler is needed */ 39 | #define AES_256 /* if a fast 256 bit key scheduler is needed */ 40 | #define AES_VAR /* if variable key size scheduler is needed */ 41 | #define AES_MODES /* if support is needed for modes */ 42 | 43 | /* The following must also be set in assembler files if being used */ 44 | 45 | #define AES_ENCRYPT /* if support for encryption is needed */ 46 | #define AES_DECRYPT /* if support for decryption is needed */ 47 | #define AES_REV_DKS /* define to reverse decryption key schedule */ 48 | 49 | #define AES_BLOCK_SIZE 16 /* the AES block size in bytes */ 50 | #define N_COLS 4 /* the number of columns in the state */ 51 | 52 | /* The key schedule length is 11, 13 or 15 16-byte blocks for 128, */ 53 | /* 192 or 256-bit keys respectively. That is 176, 208 or 240 bytes */ 54 | /* or 44, 52 or 60 32-bit words. */ 55 | 56 | #if defined( AES_VAR ) || defined( AES_256 ) 57 | #define KS_LENGTH 60 58 | #elif defined( AES_192 ) 59 | #define KS_LENGTH 52 60 | #else 61 | #define KS_LENGTH 44 62 | #endif 63 | 64 | #define AES_RETURN INT_RETURN 65 | 66 | /* the character array 'inf' in the following structures is used */ 67 | /* to hold AES context information. This AES code uses cx->inf.b[0] */ 68 | /* to hold the number of rounds multiplied by 16. The other three */ 69 | /* elements can be used by code that implements additional modes */ 70 | 71 | typedef union 72 | { uint_32t l; 73 | uint_8t b[4]; 74 | } aes_inf; 75 | 76 | typedef struct 77 | { uint_32t ks[KS_LENGTH]; 78 | aes_inf inf; 79 | } aes_encrypt_ctx; 80 | 81 | typedef struct 82 | { uint_32t ks[KS_LENGTH]; 83 | aes_inf inf; 84 | } aes_decrypt_ctx; 85 | 86 | /* This routine must be called before first use if non-static */ 87 | /* tables are being used */ 88 | 89 | AES_RETURN aes_init(void); 90 | 91 | /* Key lengths in the range 16 <= key_len <= 32 are given in bytes, */ 92 | /* those in the range 128 <= key_len <= 256 are given in bits */ 93 | 94 | #if defined( AES_ENCRYPT ) 95 | 96 | #if defined( AES_128 ) || defined( AES_VAR) 97 | AES_RETURN aes_encrypt_key128(const unsigned char *key, aes_encrypt_ctx cx[1]); 98 | #endif 99 | 100 | #if defined( AES_192 ) || defined( AES_VAR) 101 | AES_RETURN aes_encrypt_key192(const unsigned char *key, aes_encrypt_ctx cx[1]); 102 | #endif 103 | 104 | #if defined( AES_256 ) || defined( AES_VAR) 105 | AES_RETURN aes_encrypt_key256(const unsigned char *key, aes_encrypt_ctx cx[1]); 106 | #endif 107 | 108 | #if defined( AES_VAR ) 109 | AES_RETURN aes_encrypt_key(const unsigned char *key, int key_len, aes_encrypt_ctx cx[1]); 110 | #endif 111 | 112 | AES_RETURN aes_encrypt(const unsigned char *in, unsigned char *out, const aes_encrypt_ctx cx[1]); 113 | 114 | #endif 115 | 116 | #if defined( AES_DECRYPT ) 117 | 118 | #if defined( AES_128 ) || defined( AES_VAR) 119 | AES_RETURN aes_decrypt_key128(const unsigned char *key, aes_decrypt_ctx cx[1]); 120 | #endif 121 | 122 | #if defined( AES_192 ) || defined( AES_VAR) 123 | AES_RETURN aes_decrypt_key192(const unsigned char *key, aes_decrypt_ctx cx[1]); 124 | #endif 125 | 126 | #if defined( AES_256 ) || defined( AES_VAR) 127 | AES_RETURN aes_decrypt_key256(const unsigned char *key, aes_decrypt_ctx cx[1]); 128 | #endif 129 | 130 | #if defined( AES_VAR ) 131 | AES_RETURN aes_decrypt_key(const unsigned char *key, int key_len, aes_decrypt_ctx cx[1]); 132 | #endif 133 | 134 | AES_RETURN aes_decrypt(const unsigned char *in, unsigned char *out, const aes_decrypt_ctx cx[1]); 135 | 136 | #endif 137 | 138 | #if defined( AES_MODES ) 139 | 140 | /* Multiple calls to the following subroutines for multiple block */ 141 | /* ECB, CBC, CFB, OFB and CTR mode encryption can be used to handle */ 142 | /* long messages incremantally provided that the context AND the iv */ 143 | /* are preserved between all such calls. For the ECB and CBC modes */ 144 | /* each individual call within a series of incremental calls must */ 145 | /* process only full blocks (i.e. len must be a multiple of 16) but */ 146 | /* the CFB, OFB and CTR mode calls can handle multiple incremental */ 147 | /* calls of any length. Each mode is reset when a new AES key is */ 148 | /* set but ECB and CBC operations can be reset without setting a */ 149 | /* new key by setting a new IV value. To reset CFB, OFB and CTR */ 150 | /* without setting the key, aes_mode_reset() must be called and the */ 151 | /* IV must be set. NOTE: All these calls update the IV on exit so */ 152 | /* this has to be reset if a new operation with the same IV as the */ 153 | /* previous one is required (or decryption follows encryption with */ 154 | /* the same IV array). */ 155 | 156 | AES_RETURN aes_test_alignment_detection(unsigned int n); 157 | 158 | AES_RETURN aes_ecb_encrypt(const unsigned char *ibuf, unsigned char *obuf, 159 | int len, const aes_encrypt_ctx cx[1]); 160 | 161 | AES_RETURN aes_ecb_decrypt(const unsigned char *ibuf, unsigned char *obuf, 162 | int len, const aes_decrypt_ctx cx[1]); 163 | 164 | AES_RETURN aes_cbc_encrypt(const unsigned char *ibuf, unsigned char *obuf, 165 | int len, unsigned char *iv, const aes_encrypt_ctx cx[1]); 166 | 167 | AES_RETURN aes_cbc_decrypt(const unsigned char *ibuf, unsigned char *obuf, 168 | int len, unsigned char *iv, const aes_decrypt_ctx cx[1]); 169 | 170 | AES_RETURN aes_mode_reset(aes_encrypt_ctx cx[1]); 171 | 172 | AES_RETURN aes_cfb_encrypt(const unsigned char *ibuf, unsigned char *obuf, 173 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 174 | 175 | AES_RETURN aes_cfb_decrypt(const unsigned char *ibuf, unsigned char *obuf, 176 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 177 | 178 | #define aes_ofb_encrypt aes_ofb_crypt 179 | #define aes_ofb_decrypt aes_ofb_crypt 180 | 181 | AES_RETURN aes_ofb_crypt(const unsigned char *ibuf, unsigned char *obuf, 182 | int len, unsigned char *iv, aes_encrypt_ctx cx[1]); 183 | 184 | typedef void cbuf_inc(unsigned char *cbuf); 185 | 186 | #define aes_ctr_encrypt aes_ctr_crypt 187 | #define aes_ctr_decrypt aes_ctr_crypt 188 | 189 | AES_RETURN aes_ctr_crypt(const unsigned char *ibuf, unsigned char *obuf, 190 | int len, unsigned char *cbuf, cbuf_inc ctr_inc, aes_encrypt_ctx cx[1]); 191 | 192 | #endif 193 | 194 | #if defined(__cplusplus) 195 | } 196 | #endif 197 | 198 | #endif 199 | -------------------------------------------------------------------------------- /include/utils/country_list.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | const static std::map COUNTRIES = { 7 | {"Afghanistan", "AF"}, 8 | {"Åland Islands", "AX"}, 9 | {"Albania", "AL"}, 10 | {"Algeria", "DZ"}, 11 | {"American Samoa", "AS"}, 12 | {"Andorra", "AD"}, 13 | {"Angola", "AO"}, 14 | {"Anguilla", "AI"}, 15 | {"Antarctica", "AQ"}, 16 | {"Antigua and Barbuda", "AG"}, 17 | {"Argentina", "AR"}, 18 | {"Armenia", "AM"}, 19 | {"Aruba", "AW"}, 20 | {"Australia", "AU"}, 21 | {"Austria", "AT"}, 22 | {"Azerbaijan", "AZ"}, 23 | {"Bahamas", "BS"}, 24 | {"Bahrain", "BH"}, 25 | {"Bangladesh", "BD"}, 26 | {"Barbados", "BB"}, 27 | {"Belarus", "BY"}, 28 | {"Belgium", "BE"}, 29 | {"Belize", "BZ"}, 30 | {"Benin", "BJ"}, 31 | {"Bermuda", "BM"}, 32 | {"Bhutan", "BT"}, 33 | {"Bolivia (Plurinational State of)", "BO"}, 34 | {"Bonaire, Sint Eustatius and Saba", "BQ"}, 35 | {"Bosnia and Herzegovina", "BA"}, 36 | {"Botswana", "BW"}, 37 | {"Bouvet Island", "BV"}, 38 | {"Brazil", "BR"}, 39 | {"British Indian Ocean Territory", "IO"}, 40 | {"Brunei Darussalam", "BN"}, 41 | {"Bulgaria", "BG"}, 42 | {"Burkina Faso", "BF"}, 43 | {"Burundi", "BI"}, 44 | {"Cabo Verde", "CV"}, 45 | {"Cambodia", "KH"}, 46 | {"Cameroon", "CM"}, 47 | {"Canada", "CA"}, 48 | {"Cayman Islands", "KY"}, 49 | {"Central African Republic", "CF"}, 50 | {"Chad", "TD"}, 51 | {"Chile", "CL"}, 52 | {"China", "CN"}, 53 | {"Christmas Island", "CX"}, 54 | {"Cocos (Keeling) Islands", "CC"}, 55 | {"Colombia", "CO"}, 56 | {"Comoros", "KM"}, 57 | {"Congo", "CG"}, 58 | {"Congo, Democratic Republic of the", "CD"}, 59 | {"Cook Islands", "CK"}, 60 | {"Costa Rica", "CR"}, 61 | {"Côte d'Ivoire", "CI"}, 62 | {"Croatia", "HR"}, 63 | {"Cuba", "CU"}, 64 | {"Curaçao", "CW"}, 65 | {"Cyprus", "CY"}, 66 | {"Czechia", "CZ"}, 67 | {"Denmark", "DK"}, 68 | {"Djibouti", "DJ"}, 69 | {"Dominica", "DM"}, 70 | {"Dominican Republic", "DO"}, 71 | {"Ecuador", "EC"}, 72 | {"Egypt", "EG"}, 73 | {"El Salvador", "SV"}, 74 | {"Equatorial Guinea", "GQ"}, 75 | {"Eritrea", "ER"}, 76 | {"Estonia", "EE"}, 77 | {"Eswatini", "SZ"}, 78 | {"Ethiopia", "ET"}, 79 | {"Falkland Islands (Malvinas)", "FK"}, 80 | {"Faroe Islands", "FO"}, 81 | {"Fiji", "FJ"}, 82 | {"Finland", "FI"}, 83 | {"France", "FR"}, 84 | {"French Guiana", "GF"}, 85 | {"French Polynesia", "PF"}, 86 | {"French Southern Territories", "TF"}, 87 | {"Gabon", "GA"}, 88 | {"Gambia", "GM"}, 89 | {"Georgia", "GE"}, 90 | {"Germany", "DE"}, 91 | {"Ghana", "GH"}, 92 | {"Gibraltar", "GI"}, 93 | {"Greece", "GR"}, 94 | {"Greenland", "GL"}, 95 | {"Grenada", "GD"}, 96 | {"Guadeloupe", "GP"}, 97 | {"Guam", "GU"}, 98 | {"Guatemala", "GT"}, 99 | {"Guernsey", "GG"}, 100 | {"Guinea", "GN"}, 101 | {"Guinea-Bissau", "GW"}, 102 | {"Guyana", "GY"}, 103 | {"Haiti", "HT"}, 104 | {"Heard Island and McDonald Islands", "HM"}, 105 | {"Holy See", "VA"}, 106 | {"Honduras", "HN"}, 107 | {"Hong Kong", "HK"}, 108 | {"Hungary", "HU"}, 109 | {"Iceland", "IS"}, 110 | {"India", "IN"}, 111 | {"Indonesia", "ID"}, 112 | {"Iran (Islamic Republic of)", "IR"}, 113 | {"Iraq", "IQ"}, 114 | {"Ireland", "IE"}, 115 | {"Isle of Man", "IM"}, 116 | {"Israel", "IL"}, 117 | {"Italy", "IT"}, 118 | {"Jamaica", "JM"}, 119 | {"Japan", "JP"}, 120 | {"Jersey", "JE"}, 121 | {"Jordan", "JO"}, 122 | {"Kazakhstan", "KZ"}, 123 | {"Kenya", "KE"}, 124 | {"Kiribati", "KI"}, 125 | {"Korea (Democratic People's Republic of)", "KP"}, 126 | {"Korea, Republic of", "KR"}, 127 | {"Kuwait", "KW"}, 128 | {"Kyrgyzstan", "KG"}, 129 | {"Lao People's Democratic Republic", "LA"}, 130 | {"Latvia", "LV"}, 131 | {"Lebanon", "LB"}, 132 | {"Lesotho", "LS"}, 133 | {"Liberia", "LR"}, 134 | {"Libya", "LY"}, 135 | {"Liechtenstein", "LI"}, 136 | {"Lithuania", "LT"}, 137 | {"Luxembourg", "LU"}, 138 | {"Macao", "MO"}, 139 | {"Madagascar", "MG"}, 140 | {"Malawi", "MW"}, 141 | {"Malaysia", "MY"}, 142 | {"Maldives", "MV"}, 143 | {"Mali", "ML"}, 144 | {"Malta", "MT"}, 145 | {"Marshall Islands", "MH"}, 146 | {"Martinique", "MQ"}, 147 | {"Mauritania", "MR"}, 148 | {"Mauritius", "MU"}, 149 | {"Mayotte", "YT"}, 150 | {"Mexico", "MX"}, 151 | {"Micronesia (Federated States of)", "FM"}, 152 | {"Moldova, Republic of", "MD"}, 153 | {"Monaco", "MC"}, 154 | {"Mongolia", "MN"}, 155 | {"Montenegro", "ME"}, 156 | {"Montserrat", "MS"}, 157 | {"Morocco", "MA"}, 158 | {"Mozambique", "MZ"}, 159 | {"Myanmar", "MM"}, 160 | {"Namibia", "NA"}, 161 | {"Nauru", "NR"}, 162 | {"Nepal", "NP"}, 163 | {"Netherlands", "NL"}, 164 | {"New Caledonia", "NC"}, 165 | {"New Zealand", "NZ"}, 166 | {"Nicaragua", "NI"}, 167 | {"Niger", "NE"}, 168 | {"Nigeria", "NG"}, 169 | {"Niue", "NU"}, 170 | {"Norfolk Island", "NF"}, 171 | {"North Macedonia", "MK"}, 172 | {"Northern Mariana Islands", "MP"}, 173 | {"Norway", "NO"}, 174 | {"Oman", "OM"}, 175 | {"Pakistan", "PK"}, 176 | {"Palau", "PW"}, 177 | {"Palestine, State of", "PS"}, 178 | {"Panama", "PA"}, 179 | {"Papua New Guinea", "PG"}, 180 | {"Paraguay", "PY"}, 181 | {"Peru", "PE"}, 182 | {"Philippines", "PH"}, 183 | {"Pitcairn", "PN"}, 184 | {"Poland", "PL"}, 185 | {"Portugal", "PT"}, 186 | {"Puerto Rico", "PR"}, 187 | {"Qatar", "QA"}, 188 | {"Réunion", "RE"}, 189 | {"Romania", "RO"}, 190 | {"Russian Federation", "RU"}, 191 | {"Rwanda", "RW"}, 192 | {"Saint Barthélemy", "BL"}, 193 | {"Saint Helena, Ascension and Tristan da Cunha", "SH"}, 194 | {"Saint Kitts and Nevis", "KN"}, 195 | {"Saint Lucia", "LC"}, 196 | {"Saint Martin (French part)", "MF"}, 197 | {"Saint Pierre and Miquelon", "PM"}, 198 | {"Saint Vincent and the Grenadines", "VC"}, 199 | {"Samoa", "WS"}, 200 | {"San Marino", "SM"}, 201 | {"Sao Tome and Principe", "ST"}, 202 | {"Saudi Arabia", "SA"}, 203 | {"Senegal", "SN"}, 204 | {"Serbia", "RS"}, 205 | {"Seychelles", "SC"}, 206 | {"Sierra Leone", "SL"}, 207 | {"Singapore", "SG"}, 208 | {"Sint Maarten (Dutch part)", "SX"}, 209 | {"Slovakia", "SK"}, 210 | {"Slovenia", "SI"}, 211 | {"Solomon Islands", "SB"}, 212 | {"Somalia", "SO"}, 213 | {"South Africa", "ZA"}, 214 | {"South Georgia and the South Sandwich Islands", "GS"}, 215 | {"South Sudan", "SS"}, 216 | {"Spain", "ES"}, 217 | {"Sri Lanka", "LK"}, 218 | {"Sudan", "SD"}, 219 | {"Suriname", "SR"}, 220 | {"Svalbard and Jan Mayen", "SJ"}, 221 | {"Sweden", "SE"}, 222 | {"Switzerland", "CH"}, 223 | {"Syrian Arab Republic", "SY"}, 224 | {"Taiwan, Province of China", "TW"}, 225 | {"Tajikistan", "TJ"}, 226 | {"Tanzania, United Republic of", "TZ"}, 227 | {"Thailand", "TH"}, 228 | {"Timor-Leste", "TL"}, 229 | {"Togo", "TG"}, 230 | {"Tokelau", "TK"}, 231 | {"Tonga", "TO"}, 232 | {"Trinidad and Tobago", "TT"}, 233 | {"Tunisia", "TN"}, 234 | {"Turkey", "TR"}, 235 | {"Turkmenistan", "TM"}, 236 | {"Turks and Caicos Islands", "TC"}, 237 | {"Tuvalu", "TV"}, 238 | {"Uganda", "UG"}, 239 | {"Ukraine", "UA"}, 240 | {"United Arab Emirates", "AE"}, 241 | {"United Kingdom of Great Britain and Northern Ireland", "GB"}, 242 | {"United States of America", "US"}, 243 | {"United States Minor Outlying Islands", "UM"}, 244 | {"Uruguay", "UY"}, 245 | {"Uzbekistan", "UZ"}, 246 | {"Vanuatu", "VU"}, 247 | {"Venezuela (Bolivarian Republic of)", "VE"}, 248 | {"Viet Nam", "VN"}, 249 | {"Virgin Islands (British)", "VG"}, 250 | {"Virgin Islands (U.S.)", "VI"}, 251 | {"Wallis and Futuna", "WF"}, 252 | {"Western Sahara", "EH"}, 253 | {"Yemen", "YE"}, 254 | {"Zambia", "ZM"}, 255 | {"Zimbabwe", "ZW"} 256 | }; 257 | 258 | inline constexpr auto getOrDefault(const auto &map, const auto &key, const auto &defaultValue) 259 | { 260 | const auto itr = map.find(key); 261 | return itr == map.cend() ? defaultValue : itr->second; 262 | } -------------------------------------------------------------------------------- /lib/zipper/source/aes/brg_types.h: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 1998-2010, Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | The redistribution and use of this software (with or without changes) 6 | is allowed without the payment of fees or royalties provided that: 7 | 8 | source code distributions include the above copyright notice, this 9 | list of conditions and the following disclaimer; 10 | 11 | binary distributions include the above copyright notice, this list 12 | of conditions and the following disclaimer in their documentation. 13 | 14 | This software is provided 'as is' with no explicit or implied warranties 15 | in respect of its operation, including, but not limited to, correctness 16 | and fitness for purpose. 17 | --------------------------------------------------------------------------- 18 | Issue Date: 20/12/2007 19 | 20 | The unsigned integer types defined here are of the form uint_t where 21 | is the length of the type; for example, the unsigned 32-bit type is 22 | 'uint_32t'. These are NOT the same as the 'C99 integer types' that are 23 | defined in the inttypes.h and stdint.h headers since attempts to use these 24 | types have shown that support for them is still highly variable. However, 25 | since the latter are of the form uint_t, a regular expression search 26 | and replace (in VC++ search on 'uint_{:z}t' and replace with 'uint\1_t') 27 | can be used to convert the types used here to the C99 standard types. 28 | */ 29 | 30 | #ifndef _BRG_TYPES_H 31 | #define _BRG_TYPES_H 32 | 33 | #if defined(__cplusplus) 34 | extern "C" { 35 | #endif 36 | 37 | #include 38 | 39 | #if defined( _MSC_VER ) && ( _MSC_VER >= 1300 ) 40 | # include 41 | # define ptrint_t intptr_t 42 | #elif defined( __ECOS__ ) 43 | # define intptr_t unsigned int 44 | # define ptrint_t intptr_t 45 | #elif defined( __GNUC__ ) && ( __GNUC__ >= 3 ) 46 | # include 47 | # define ptrint_t intptr_t 48 | #else 49 | # define ptrint_t int 50 | #endif 51 | 52 | #ifndef BRG_UI8 53 | # define BRG_UI8 54 | # if UCHAR_MAX == 255u 55 | typedef unsigned char uint_8t; 56 | # else 57 | # error Please define uint_8t as an 8-bit unsigned integer type in brg_types.h 58 | # endif 59 | #endif 60 | 61 | #ifndef BRG_UI16 62 | # define BRG_UI16 63 | # if USHRT_MAX == 65535u 64 | typedef unsigned short uint_16t; 65 | # else 66 | # error Please define uint_16t as a 16-bit unsigned short type in brg_types.h 67 | # endif 68 | #endif 69 | 70 | #ifndef BRG_UI32 71 | # define BRG_UI32 72 | # if UINT_MAX == 4294967295u 73 | # define li_32(h) 0x##h##u 74 | typedef unsigned int uint_32t; 75 | # elif ULONG_MAX == 4294967295u 76 | # define li_32(h) 0x##h##ul 77 | typedef unsigned long uint_32t; 78 | # elif defined( _CRAY ) 79 | # error This code needs 32-bit data types, which Cray machines do not provide 80 | # else 81 | # error Please define uint_32t as a 32-bit unsigned integer type in brg_types.h 82 | # endif 83 | #endif 84 | 85 | #ifndef BRG_UI64 86 | # if defined( __BORLANDC__ ) && !defined( __MSDOS__ ) 87 | # define BRG_UI64 88 | # define li_64(h) 0x##h##ui64 89 | typedef unsigned __int64 uint_64t; 90 | # elif defined( _MSC_VER ) && ( _MSC_VER < 1300 ) /* 1300 == VC++ 7.0 */ 91 | # define BRG_UI64 92 | # define li_64(h) 0x##h##ui64 93 | typedef unsigned __int64 uint_64t; 94 | # elif defined( __sun ) && defined( ULONG_MAX ) && ULONG_MAX == 0xfffffffful 95 | # define BRG_UI64 96 | # define li_64(h) 0x##h##ull 97 | typedef unsigned long long uint_64t; 98 | # elif defined( __MVS__ ) 99 | # define BRG_UI64 100 | # define li_64(h) 0x##h##ull 101 | typedef unsigned int long long uint_64t; 102 | # elif defined( UINT_MAX ) && UINT_MAX > 4294967295u 103 | # if UINT_MAX == 18446744073709551615u 104 | # define BRG_UI64 105 | # define li_64(h) 0x##h##u 106 | typedef unsigned int uint_64t; 107 | # endif 108 | # elif defined( ULONG_MAX ) && ULONG_MAX > 4294967295u 109 | # if ULONG_MAX == 18446744073709551615ul 110 | # define BRG_UI64 111 | # define li_64(h) 0x##h##ul 112 | typedef unsigned long uint_64t; 113 | # endif 114 | # elif defined( ULLONG_MAX ) && ULLONG_MAX > 4294967295u 115 | # if ULLONG_MAX == 18446744073709551615ull 116 | # define BRG_UI64 117 | # define li_64(h) 0x##h##ull 118 | typedef unsigned long long uint_64t; 119 | # endif 120 | # elif defined( ULONG_LONG_MAX ) && ULONG_LONG_MAX > 4294967295u 121 | # if ULONG_LONG_MAX == 18446744073709551615ull 122 | # define BRG_UI64 123 | # define li_64(h) 0x##h##ull 124 | typedef unsigned long long uint_64t; 125 | # endif 126 | # endif 127 | #endif 128 | 129 | #if !defined( BRG_UI64 ) 130 | # if defined( NEED_UINT_64T ) 131 | # error Please define uint_64t as an unsigned 64 bit type in brg_types.h 132 | # endif 133 | #endif 134 | 135 | #ifndef RETURN_VALUES 136 | # define RETURN_VALUES 137 | # if defined( DLL_EXPORT ) 138 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 139 | # define VOID_RETURN __declspec( dllexport ) void __stdcall 140 | # define INT_RETURN __declspec( dllexport ) int __stdcall 141 | # elif defined( __GNUC__ ) 142 | # define VOID_RETURN __declspec( __dllexport__ ) void 143 | # define INT_RETURN __declspec( __dllexport__ ) int 144 | # else 145 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 146 | # endif 147 | # elif defined( DLL_IMPORT ) 148 | # if defined( _MSC_VER ) || defined ( __INTEL_COMPILER ) 149 | # define VOID_RETURN __declspec( dllimport ) void __stdcall 150 | # define INT_RETURN __declspec( dllimport ) int __stdcall 151 | # elif defined( __GNUC__ ) 152 | # define VOID_RETURN __declspec( __dllimport__ ) void 153 | # define INT_RETURN __declspec( __dllimport__ ) int 154 | # else 155 | # error Use of the DLL is only available on the Microsoft, Intel and GCC compilers 156 | # endif 157 | # elif defined( __WATCOMC__ ) 158 | # define VOID_RETURN void __cdecl 159 | # define INT_RETURN int __cdecl 160 | # else 161 | # define VOID_RETURN void 162 | # define INT_RETURN int 163 | # endif 164 | #endif 165 | 166 | /* These defines are used to detect and set the memory alignment of pointers. 167 | Note that offsets are in bytes. 168 | 169 | ALIGN_OFFSET(x,n) return the positive or zero offset of 170 | the memory addressed by the pointer 'x' 171 | from an address that is aligned on an 172 | 'n' byte boundary ('n' is a power of 2) 173 | 174 | ALIGN_FLOOR(x,n) return a pointer that points to memory 175 | that is aligned on an 'n' byte boundary 176 | and is not higher than the memory address 177 | pointed to by 'x' ('n' is a power of 2) 178 | 179 | ALIGN_CEIL(x,n) return a pointer that points to memory 180 | that is aligned on an 'n' byte boundary 181 | and is not lower than the memory address 182 | pointed to by 'x' ('n' is a power of 2) 183 | */ 184 | 185 | #define ALIGN_OFFSET(x,n) (((ptrint_t)(x)) & ((n) - 1)) 186 | #define ALIGN_FLOOR(x,n) ((uint_8t*)(x) - ( ((ptrint_t)(x)) & ((n) - 1))) 187 | #define ALIGN_CEIL(x,n) ((uint_8t*)(x) + (-((ptrint_t)(x)) & ((n) - 1))) 188 | 189 | /* These defines are used to declare buffers in a way that allows 190 | faster operations on longer variables to be used. In all these 191 | defines 'size' must be a power of 2 and >= 8. NOTE that the 192 | buffer size is in bytes but the type length is in bits 193 | 194 | UNIT_TYPEDEF(x,size) declares a variable 'x' of length 195 | 'size' bits 196 | 197 | BUFR_TYPEDEF(x,size,bsize) declares a buffer 'x' of length 'bsize' 198 | bytes defined as an array of variables 199 | each of 'size' bits (bsize must be a 200 | multiple of size / 8) 201 | 202 | UNIT_CAST(x,size) casts a variable to a type of 203 | length 'size' bits 204 | 205 | UPTR_CAST(x,size) casts a pointer to a pointer to a 206 | varaiable of length 'size' bits 207 | */ 208 | 209 | #define UI_TYPE(size) uint_##size##t 210 | #define UNIT_TYPEDEF(x,size) typedef UI_TYPE(size) x 211 | #define BUFR_TYPEDEF(x,size,bsize) typedef UI_TYPE(size) x[bsize / (size >> 3)] 212 | #define UNIT_CAST(x,size) ((UI_TYPE(size) )(x)) 213 | #define UPTR_CAST(x,size) ((UI_TYPE(size)*)(x)) 214 | 215 | #if defined(__cplusplus) 216 | } 217 | #endif 218 | 219 | #endif 220 | -------------------------------------------------------------------------------- /lib/zipper/source/zipper.cpp: -------------------------------------------------------------------------------- 1 | #include "zipper.h" 2 | #include "defs.h" 3 | #include "tools.h" 4 | #include "CDirEntry.h" 5 | 6 | #include 7 | #include 8 | 9 | namespace zipper { 10 | 11 | struct Zipper::Impl 12 | { 13 | Zipper& m_outer; 14 | zipFile m_zf; 15 | ourmemory_t m_zipmem; 16 | zlib_filefunc_def m_filefunc; 17 | 18 | Impl(Zipper& outer) : m_outer(outer), m_zipmem(), m_filefunc() 19 | { 20 | m_zf = NULL; 21 | //m_filefunc = { 0 }; 22 | } 23 | 24 | bool initFile(const std::string& filename) 25 | { 26 | #ifdef USEWIN32IOAPI 27 | zlib_filefunc64_def ffunc = { 0 }; 28 | #endif 29 | 30 | int mode = 0; 31 | int flags = Zipper::Append; 32 | 33 | /* open the zip file for output */ 34 | if (checkFileExists(filename)) 35 | mode = (flags & Zipper::Overwrite) ? APPEND_STATUS_CREATE : APPEND_STATUS_ADDINZIP; 36 | else 37 | mode = APPEND_STATUS_CREATE; 38 | 39 | #ifdef USEWIN32IOAPI 40 | fill_win32_filefunc64A(&ffunc); 41 | m_zf = zipOpen2_64(filename.c_str(), mode, NULL, &ffunc); 42 | #else 43 | m_zf = zipOpen64(filename.c_str(), mode); 44 | #endif 45 | 46 | return NULL != m_zf; 47 | } 48 | 49 | bool initWithStream(std::iostream& stream) 50 | { 51 | m_zipmem.grow = 1; 52 | 53 | stream.seekg(0, std::ios::end); 54 | size_t size = (size_t)stream.tellg(); 55 | stream.seekg(0); 56 | 57 | if (size > 0) 58 | { 59 | m_zipmem.base = new char[(size_t)size]; 60 | stream.read(m_zipmem.base, size); 61 | } 62 | 63 | fill_memory_filefunc(&m_filefunc, &m_zipmem); 64 | 65 | return initMemory(size > 0 ? APPEND_STATUS_CREATE : APPEND_STATUS_ADDINZIP, m_filefunc); 66 | } 67 | 68 | bool initWithVector(std::vector& buffer) 69 | { 70 | m_zipmem.grow = 1; 71 | 72 | if (!buffer.empty()) 73 | { 74 | m_zipmem.base = new char[buffer.size()]; 75 | memcpy(m_zipmem.base, (char*)buffer.data(), buffer.size()); 76 | m_zipmem.size = (uLong)buffer.size(); 77 | } 78 | 79 | fill_memory_filefunc(&m_filefunc, &m_zipmem); 80 | 81 | return initMemory(buffer.empty() ? APPEND_STATUS_CREATE : APPEND_STATUS_ADDINZIP, m_filefunc); 82 | } 83 | 84 | bool initMemory(int mode, zlib_filefunc_def& filefunc) 85 | { 86 | m_zf = zipOpen3("__notused__", mode, 0, 0, &filefunc); 87 | return m_zf != NULL; 88 | } 89 | 90 | bool add(std::istream& input_stream, const std::string& nameInZip, const std::string& password, int flags) 91 | { 92 | if (!m_zf) return false; 93 | 94 | int compressLevel = 0; 95 | int zip64 = 0; 96 | int size_buf = WRITEBUFFERSIZE; 97 | int err = ZIP_OK; 98 | unsigned long crcFile = 0; 99 | 100 | zip_fileinfo zi = { 0 }; 101 | size_t size_read; 102 | 103 | std::vector buff; 104 | buff.resize(size_buf); 105 | 106 | if (nameInZip.empty()) 107 | return false; 108 | 109 | if (flags & Zipper::Faster) compressLevel = 1; 110 | if (flags & Zipper::Better) compressLevel = 9; 111 | 112 | zip64 = (int)isLargeFile(input_stream); 113 | if (password.empty()) 114 | err = zipOpenNewFileInZip64(m_zf, 115 | nameInZip.c_str(), 116 | &zi, 117 | NULL, 118 | 0, 119 | NULL, 120 | 0, 121 | NULL /* comment*/, 122 | (compressLevel != 0) ? Z_DEFLATED : 0, 123 | compressLevel, 124 | zip64); 125 | else 126 | { 127 | getFileCrc(input_stream, buff, crcFile); 128 | err = zipOpenNewFileInZip3_64(m_zf, 129 | nameInZip.c_str(), 130 | &zi, 131 | NULL, 132 | 0, 133 | NULL, 134 | 0, 135 | NULL /* comment*/, 136 | (compressLevel != 0) ? Z_DEFLATED : 0, 137 | compressLevel, 138 | 0, 139 | /* -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, */ 140 | -MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY, 141 | password.c_str(), 142 | crcFile, 143 | zip64); 144 | } 145 | 146 | if (ZIP_OK == err) 147 | { 148 | do { 149 | err = ZIP_OK; 150 | input_stream.read(buff.data(), buff.size()); 151 | size_read = (size_t)input_stream.gcount(); 152 | if (size_read < buff.size() && !input_stream.eof() && !input_stream.good()) 153 | err = ZIP_ERRNO; 154 | 155 | if (size_read > 0) 156 | err = zipWriteInFileInZip(this->m_zf, buff.data(), (unsigned int)size_read); 157 | 158 | } while ((err == ZIP_OK) && (size_read>0)); 159 | } 160 | else 161 | throw EXCEPTION_CLASS(("Error adding '" + nameInZip + "' to zip").c_str()); 162 | 163 | if (ZIP_OK == err) 164 | err = zipCloseFileInZip(this->m_zf); 165 | 166 | return ZIP_OK == err; 167 | } 168 | 169 | void close() 170 | { 171 | if (m_zf) 172 | zipClose(m_zf, NULL); 173 | 174 | if (m_zipmem.base && m_zipmem.limit > 0) 175 | { 176 | if (m_outer.m_usingMemoryVector) 177 | { 178 | m_outer.m_vecbuffer.resize(m_zipmem.limit); 179 | m_outer.m_vecbuffer.assign(m_zipmem.base, m_zipmem.base + m_zipmem.limit); 180 | } 181 | 182 | else if (m_outer.m_usingStream) 183 | m_outer.m_obuffer.write(m_zipmem.base, m_zipmem.limit); 184 | } 185 | 186 | free(m_zipmem.base); 187 | } 188 | }; 189 | 190 | /////////////////////////////////////////////////////////////////////////////// 191 | /////////////////////////////////////////////////////////////////////////////// 192 | 193 | Zipper::Zipper(const std::string& zipname) 194 | : m_obuffer(*(new std::stringstream())) //not used but using local variable throws exception 195 | , m_vecbuffer(*(new std::vector())) //not used but using local variable throws exception 196 | , m_usingMemoryVector(false) 197 | , m_usingStream(false) 198 | , m_zipname(zipname) 199 | , m_impl(new Impl(*this)) 200 | { 201 | if (!m_impl->initFile(zipname)) 202 | throw EXCEPTION_CLASS("Error creating zip in file!"); 203 | 204 | m_open = true; 205 | } 206 | 207 | Zipper::Zipper(const std::string& zipname, const std::string& password) 208 | : m_obuffer(*(new std::stringstream())) //not used but using local variable throws exception 209 | , m_vecbuffer(*(new std::vector())) //not used but using local variable throws exception 210 | , m_usingMemoryVector(false) 211 | , m_usingStream(false) 212 | , m_zipname(zipname) 213 | , m_password(password) 214 | , m_impl(new Impl(*this)) 215 | { 216 | if (!m_impl->initFile(zipname)) 217 | throw EXCEPTION_CLASS("Error creating zip in file!"); 218 | 219 | m_open = true; 220 | } 221 | 222 | Zipper::Zipper(std::iostream& buffer) 223 | : m_vecbuffer(*(new std::vector())) //not used but using local variable throws exception 224 | , m_obuffer(buffer) 225 | , m_usingMemoryVector(false) 226 | , m_usingStream(true) 227 | , m_impl(new Impl(*this)) 228 | { 229 | if (!m_impl->initWithStream(m_obuffer)) 230 | throw EXCEPTION_CLASS("Error creating zip in memory!"); 231 | 232 | m_open = true; 233 | } 234 | 235 | Zipper::Zipper(std::vector& buffer) 236 | : m_vecbuffer(buffer) 237 | , m_obuffer(*(new std::stringstream())) //not used but using local variable throws exception 238 | , m_usingMemoryVector(true) 239 | , m_usingStream(false) 240 | , m_impl(new Impl(*this)) 241 | { 242 | if (!m_impl->initWithVector(m_vecbuffer)) 243 | throw EXCEPTION_CLASS("Error creating zip in memory!"); 244 | 245 | m_open = true; 246 | } 247 | 248 | Zipper::~Zipper(void) 249 | { 250 | close(); 251 | } 252 | 253 | bool Zipper::add(std::istream& source, const std::string& nameInZip, zipFlags flags) 254 | { 255 | return m_impl->add(source, nameInZip, "", flags); 256 | } 257 | 258 | bool Zipper::add(const std::string& fileOrFolderPath, zipFlags flags) 259 | { 260 | if (isDirectory(fileOrFolderPath)) 261 | { 262 | std::string folderName = fileNameFromPath(fileOrFolderPath); 263 | std::vector files = filesFromDirectory(fileOrFolderPath); 264 | std::vector::iterator it = files.begin(); 265 | for (; it != files.end(); ++it) 266 | { 267 | std::ifstream input(it->c_str(), std::ios::binary); 268 | std::string nameInZip = it->substr(it->rfind(folderName + CDirEntry::Separator), it->size()); 269 | add(input, nameInZip, flags); 270 | input.close(); 271 | } 272 | } 273 | else 274 | { 275 | std::ifstream input(fileOrFolderPath.c_str(), std::ios::binary); 276 | add(input, fileNameFromPath(fileOrFolderPath), flags); 277 | input.close(); 278 | } 279 | 280 | return true; 281 | } 282 | 283 | 284 | void Zipper::open() 285 | { 286 | if (!m_open) 287 | { 288 | if (m_usingMemoryVector) 289 | { 290 | if (!m_impl->initWithVector(m_vecbuffer)) 291 | throw EXCEPTION_CLASS("Error opening zip memory!"); 292 | } 293 | else if (m_usingStream) 294 | { 295 | if (!m_impl->initWithStream(m_obuffer)) 296 | throw EXCEPTION_CLASS("Error opening zip memory!"); 297 | } 298 | else 299 | { 300 | if (!m_impl->initFile(m_zipname)) 301 | throw EXCEPTION_CLASS("Error opening zip file!"); 302 | } 303 | 304 | m_open = true; 305 | } 306 | } 307 | 308 | void Zipper::close() 309 | { 310 | if (m_open) 311 | { 312 | m_impl->close(); 313 | m_open = false; 314 | } 315 | } 316 | } 317 | -------------------------------------------------------------------------------- /lib/zipper/source/aes/sha1.c: -------------------------------------------------------------------------------- 1 | /* 2 | --------------------------------------------------------------------------- 3 | Copyright (c) 2002, Dr Brian Gladman, Worcester, UK. All rights reserved. 4 | 5 | LICENSE TERMS 6 | 7 | The free distribution and use of this software in both source and binary 8 | form is allowed (with or without changes) provided that: 9 | 10 | 1. distributions of this source code include the above copyright 11 | notice, this list of conditions and the following disclaimer; 12 | 13 | 2. distributions in binary form include the above copyright 14 | notice, this list of conditions and the following disclaimer 15 | in the documentation and/or other associated materials; 16 | 17 | 3. the copyright holder's name is not used to endorse products 18 | built using this software without specific written permission. 19 | 20 | ALTERNATIVELY, provided that this notice is retained in full, this product 21 | may be distributed under the terms of the GNU General Public License (GPL), 22 | in which case the provisions of the GPL apply INSTEAD OF those given above. 23 | 24 | DISCLAIMER 25 | 26 | This software is provided 'as is' with no explicit or implied warranties 27 | in respect of its properties, including, but not limited to, correctness 28 | and/or fitness for purpose. 29 | --------------------------------------------------------------------------- 30 | Issue Date: 01/08/2005 31 | 32 | This is a byte oriented version of SHA1 that operates on arrays of bytes 33 | stored in memory. 34 | */ 35 | 36 | #include /* for memcpy() etc. */ 37 | 38 | #include "sha1.h" 39 | #include "brg_endian.h" 40 | 41 | #if defined(__cplusplus) 42 | extern "C" 43 | { 44 | #endif 45 | 46 | #if defined( _MSC_VER ) && ( _MSC_VER > 800 ) 47 | #pragma intrinsic(memcpy) 48 | #endif 49 | 50 | #if 0 && defined(_MSC_VER) 51 | #define rotl32 _lrotl 52 | #define rotr32 _lrotr 53 | #else 54 | #define rotl32(x,n) (((x) << n) | ((x) >> (32 - n))) 55 | #define rotr32(x,n) (((x) >> n) | ((x) << (32 - n))) 56 | #endif 57 | 58 | #if !defined(bswap_32) 59 | #define bswap_32(x) ((rotr32((x), 24) & 0x00ff00ff) | (rotr32((x), 8) & 0xff00ff00)) 60 | #endif 61 | 62 | #if (PLATFORM_BYTE_ORDER == IS_LITTLE_ENDIAN) 63 | #define SWAP_BYTES 64 | #else 65 | #undef SWAP_BYTES 66 | #endif 67 | 68 | #if defined(SWAP_BYTES) 69 | #define bsw_32(p,n) \ 70 | { int _i = (n); while(_i--) ((uint_32t*)p)[_i] = bswap_32(((uint_32t*)p)[_i]); } 71 | #else 72 | #define bsw_32(p,n) 73 | #endif 74 | 75 | #define SHA1_MASK (SHA1_BLOCK_SIZE - 1) 76 | 77 | #if 0 78 | 79 | #define ch(x,y,z) (((x) & (y)) ^ (~(x) & (z))) 80 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) 81 | #define maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) 82 | 83 | #else /* Discovered by Rich Schroeppel and Colin Plumb */ 84 | 85 | #define ch(x,y,z) ((z) ^ ((x) & ((y) ^ (z)))) 86 | #define parity(x,y,z) ((x) ^ (y) ^ (z)) 87 | #define maj(x,y,z) (((x) & (y)) | ((z) & ((x) ^ (y)))) 88 | 89 | #endif 90 | 91 | /* Compile 64 bytes of hash data into SHA1 context. Note */ 92 | /* that this routine assumes that the byte order in the */ 93 | /* ctx->wbuf[] at this point is in such an order that low */ 94 | /* address bytes in the ORIGINAL byte stream will go in */ 95 | /* this buffer to the high end of 32-bit words on BOTH big */ 96 | /* and little endian systems */ 97 | 98 | #ifdef ARRAY 99 | #define q(v,n) v[n] 100 | #else 101 | #define q(v,n) v##n 102 | #endif 103 | 104 | #define one_cycle(v,a,b,c,d,e,f,k,h) \ 105 | q(v,e) += rotr32(q(v,a),27) + \ 106 | f(q(v,b),q(v,c),q(v,d)) + k + h; \ 107 | q(v,b) = rotr32(q(v,b), 2) 108 | 109 | #define five_cycle(v,f,k,i) \ 110 | one_cycle(v, 0,1,2,3,4, f,k,hf(i )); \ 111 | one_cycle(v, 4,0,1,2,3, f,k,hf(i+1)); \ 112 | one_cycle(v, 3,4,0,1,2, f,k,hf(i+2)); \ 113 | one_cycle(v, 2,3,4,0,1, f,k,hf(i+3)); \ 114 | one_cycle(v, 1,2,3,4,0, f,k,hf(i+4)) 115 | 116 | VOID_RETURN sha1_compile(sha1_ctx ctx[1]) 117 | { uint_32t *w = ctx->wbuf; 118 | 119 | #ifdef ARRAY 120 | uint_32t v[5]; 121 | memcpy(v, ctx->hash, 5 * sizeof(uint_32t)); 122 | #else 123 | uint_32t v0, v1, v2, v3, v4; 124 | v0 = ctx->hash[0]; v1 = ctx->hash[1]; 125 | v2 = ctx->hash[2]; v3 = ctx->hash[3]; 126 | v4 = ctx->hash[4]; 127 | #endif 128 | 129 | #define hf(i) w[i] 130 | 131 | five_cycle(v, ch, 0x5a827999, 0); 132 | five_cycle(v, ch, 0x5a827999, 5); 133 | five_cycle(v, ch, 0x5a827999, 10); 134 | one_cycle(v,0,1,2,3,4, ch, 0x5a827999, hf(15)); \ 135 | 136 | #undef hf 137 | #define hf(i) (w[(i) & 15] = rotl32( \ 138 | w[((i) + 13) & 15] ^ w[((i) + 8) & 15] \ 139 | ^ w[((i) + 2) & 15] ^ w[(i) & 15], 1)) 140 | 141 | one_cycle(v,4,0,1,2,3, ch, 0x5a827999, hf(16)); 142 | one_cycle(v,3,4,0,1,2, ch, 0x5a827999, hf(17)); 143 | one_cycle(v,2,3,4,0,1, ch, 0x5a827999, hf(18)); 144 | one_cycle(v,1,2,3,4,0, ch, 0x5a827999, hf(19)); 145 | 146 | five_cycle(v, parity, 0x6ed9eba1, 20); 147 | five_cycle(v, parity, 0x6ed9eba1, 25); 148 | five_cycle(v, parity, 0x6ed9eba1, 30); 149 | five_cycle(v, parity, 0x6ed9eba1, 35); 150 | 151 | five_cycle(v, maj, 0x8f1bbcdc, 40); 152 | five_cycle(v, maj, 0x8f1bbcdc, 45); 153 | five_cycle(v, maj, 0x8f1bbcdc, 50); 154 | five_cycle(v, maj, 0x8f1bbcdc, 55); 155 | 156 | five_cycle(v, parity, 0xca62c1d6, 60); 157 | five_cycle(v, parity, 0xca62c1d6, 65); 158 | five_cycle(v, parity, 0xca62c1d6, 70); 159 | five_cycle(v, parity, 0xca62c1d6, 75); 160 | 161 | #ifdef ARRAY 162 | ctx->hash[0] += v[0]; ctx->hash[1] += v[1]; 163 | ctx->hash[2] += v[2]; ctx->hash[3] += v[3]; 164 | ctx->hash[4] += v[4]; 165 | #else 166 | ctx->hash[0] += v0; ctx->hash[1] += v1; 167 | ctx->hash[2] += v2; ctx->hash[3] += v3; 168 | ctx->hash[4] += v4; 169 | #endif 170 | } 171 | 172 | VOID_RETURN sha1_begin(sha1_ctx ctx[1]) 173 | { 174 | ctx->count[0] = ctx->count[1] = 0; 175 | ctx->hash[0] = 0x67452301; 176 | ctx->hash[1] = 0xefcdab89; 177 | ctx->hash[2] = 0x98badcfe; 178 | ctx->hash[3] = 0x10325476; 179 | ctx->hash[4] = 0xc3d2e1f0; 180 | } 181 | 182 | /* SHA1 hash data in an array of bytes into hash buffer and */ 183 | /* call the hash_compile function as required. */ 184 | 185 | VOID_RETURN sha1_hash(const unsigned char data[], unsigned long len, sha1_ctx ctx[1]) 186 | { uint_32t pos = (uint_32t)(ctx->count[0] & SHA1_MASK), 187 | space = SHA1_BLOCK_SIZE - pos; 188 | const unsigned char *sp = data; 189 | 190 | if((ctx->count[0] += len) < len) 191 | ++(ctx->count[1]); 192 | 193 | while(len >= space) /* tranfer whole blocks if possible */ 194 | { 195 | memcpy(((unsigned char*)ctx->wbuf) + pos, sp, space); 196 | sp += space; len -= space; space = SHA1_BLOCK_SIZE; pos = 0; 197 | bsw_32(ctx->wbuf, SHA1_BLOCK_SIZE >> 2); 198 | sha1_compile(ctx); 199 | } 200 | 201 | memcpy(((unsigned char*)ctx->wbuf) + pos, sp, len); 202 | } 203 | 204 | /* SHA1 final padding and digest calculation */ 205 | 206 | VOID_RETURN sha1_end(unsigned char hval[], sha1_ctx ctx[1]) 207 | { uint_32t i = (uint_32t)(ctx->count[0] & SHA1_MASK); 208 | 209 | /* put bytes in the buffer in an order in which references to */ 210 | /* 32-bit words will put bytes with lower addresses into the */ 211 | /* top of 32 bit words on BOTH big and little endian machines */ 212 | bsw_32(ctx->wbuf, (i + 3) >> 2); 213 | 214 | /* we now need to mask valid bytes and add the padding which is */ 215 | /* a single 1 bit and as many zero bits as necessary. Note that */ 216 | /* we can always add the first padding byte here because the */ 217 | /* buffer always has at least one empty slot */ 218 | ctx->wbuf[i >> 2] &= 0xffffff80 << 8 * (~i & 3); 219 | ctx->wbuf[i >> 2] |= 0x00000080 << 8 * (~i & 3); 220 | 221 | /* we need 9 or more empty positions, one for the padding byte */ 222 | /* (above) and eight for the length count. If there is not */ 223 | /* enough space, pad and empty the buffer */ 224 | if(i > SHA1_BLOCK_SIZE - 9) 225 | { 226 | if(i < 60) ctx->wbuf[15] = 0; 227 | sha1_compile(ctx); 228 | i = 0; 229 | } 230 | else /* compute a word index for the empty buffer positions */ 231 | i = (i >> 2) + 1; 232 | 233 | while(i < 14) /* and zero pad all but last two positions */ 234 | ctx->wbuf[i++] = 0; 235 | 236 | /* the following 32-bit length fields are assembled in the */ 237 | /* wrong byte order on little endian machines but this is */ 238 | /* corrected later since they are only ever used as 32-bit */ 239 | /* word values. */ 240 | ctx->wbuf[14] = (ctx->count[1] << 3) | (ctx->count[0] >> 29); 241 | ctx->wbuf[15] = ctx->count[0] << 3; 242 | sha1_compile(ctx); 243 | 244 | /* extract the hash value as bytes in case the hash buffer is */ 245 | /* misaligned for 32-bit words */ 246 | for(i = 0; i < SHA1_DIGEST_SIZE; ++i) 247 | hval[i] = (unsigned char)(ctx->hash[i >> 2] >> (8 * (~i & 3))); 248 | } 249 | 250 | VOID_RETURN sha1(unsigned char hval[], const unsigned char data[], unsigned long len) 251 | { sha1_ctx cx[1]; 252 | 253 | sha1_begin(cx); sha1_hash(data, len, cx); sha1_end(hval, cx); 254 | } 255 | 256 | #if defined(__cplusplus) 257 | } 258 | #endif 259 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #--------------------------------------------------------------------------------- 2 | .SUFFIXES: 3 | #--------------------------------------------------------------------------------- 4 | 5 | ifeq ($(strip $(DEVKITPRO)),) 6 | $(error "Please set DEVKITPRO in your environment. export DEVKITPRO=/devkitpro") 7 | endif 8 | 9 | TOPDIR ?= $(CURDIR) 10 | include $(DEVKITPRO)/libnx/switch_rules 11 | 12 | #--------------------------------------------------------------------------------- 13 | # TARGET is the name of the output 14 | # BUILD is the directory where object files & intermediate files will be placed 15 | # SOURCES is a list of directories containing source code 16 | # DATA is a list of directories containing data files 17 | # INCLUDES is a list of directories containing header files 18 | # ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional) 19 | # 20 | # NO_ICON: if set to anything, do not use icon. 21 | # NO_NACP: if set to anything, no .nacp file is generated. 22 | # APP_TITLE is the name of the app stored in the .nacp file (Optional) 23 | # APP_AUTHOR is the author of the app stored in the .nacp file (Optional) 24 | # APP_VERSION is the version of the app stored in the .nacp file (Optional) 25 | # APP_TITLEID is the titleID of the app stored in the .nacp file (Optional) 26 | # ICON is the filename of the icon (.jpg), relative to the project folder. 27 | # If not set, it attempts to use one of the following (in this order): 28 | # - .jpg 29 | # - icon.jpg 30 | # - /default_icon.jpg 31 | # 32 | # CONFIG_JSON is the filename of the NPDM config file (.json), relative to the project folder. 33 | # If not set, it attempts to use one of the following (in this order): 34 | # - .json 35 | # - config.json 36 | # If a JSON file is provided or autodetected, an ExeFS PFS0 (.nsp) is built instead 37 | # of a homebrew executable (.nro). This is intended to be used for sysmodules. 38 | # NACP building is skipped as well. 39 | #--------------------------------------------------------------------------------- 40 | BUILD := build 41 | SOURCES := source source/core source/styles source/utils source/views lib/zipper/source 42 | DATA := data 43 | INCLUDES := include lib/zipper/include 44 | APP_TITLE := Linkalho 45 | APP_AUTHOR := rrocha & Impeeza 46 | APP_VERSION := 2.0.2 47 | TARGET := $(shell echo $(APP_TITLE) | tr A-Z a-z) 48 | ROMFS := resources 49 | BOREALIS_PATH := lib/borealis 50 | BOREALIS_RESOURCES := romfs:/ 51 | 52 | #--------------------------------------------------------------------------------- 53 | # options for code generation 54 | #--------------------------------------------------------------------------------- 55 | ARCH := -march=armv8-a+crc+crypto -mtune=cortex-a57 -mtp=soft -fPIE 56 | 57 | CFLAGS := -g -Wall -O2 -ffunction-sections \ 58 | $(ARCH) $(DEFINES) 59 | 60 | CFLAGS += $(INCLUDE) -D__SWITCH__ \ 61 | -DBOREALIS_RESOURCES="\"$(BOREALIS_RESOURCES)\"" \ 62 | -DAPP_VERSION="\"$(APP_VERSION)\"" \ 63 | -DAPP_TITLE="\"$(APP_TITLE)\"" -DAPP_TITLE_LOWER="\"$(TARGET)\"" 64 | 65 | CXXFLAGS := $(CFLAGS) -std=c++20 -O2 -Wno-reorder 66 | 67 | ASFLAGS := -g $(ARCH) 68 | LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map) 69 | 70 | LIBS := -lnx -lminizip -lz 71 | 72 | #--------------------------------------------------------------------------------- 73 | # list of directories containing libraries, this must be the top level containing 74 | # include and lib 75 | #--------------------------------------------------------------------------------- 76 | LIBDIRS := $(PORTLIBS) $(LIBNX) 77 | 78 | include $(TOPDIR)/$(BOREALIS_PATH)/library/borealis.mk 79 | 80 | #--------------------------------------------------------------------------------- 81 | # no real need to edit anything past this point unless you need to add additional 82 | # rules for different file extensions 83 | #--------------------------------------------------------------------------------- 84 | ifneq ($(BUILD),$(notdir $(CURDIR))) 85 | #--------------------------------------------------------------------------------- 86 | 87 | export OUTPUT := $(CURDIR)/$(TARGET) 88 | export TOPDIR := $(CURDIR) 89 | 90 | export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \ 91 | $(foreach dir,$(DATA),$(CURDIR)/$(dir)) 92 | 93 | export DEPSDIR := $(CURDIR)/$(BUILD) 94 | 95 | CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) 96 | CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) 97 | SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s))) 98 | BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*))) 99 | 100 | #--------------------------------------------------------------------------------- 101 | # use CXX for linking C++ projects, CC for standard C 102 | #--------------------------------------------------------------------------------- 103 | ifeq ($(strip $(CPPFILES)),) 104 | #--------------------------------------------------------------------------------- 105 | export LD := $(CC) 106 | #--------------------------------------------------------------------------------- 107 | else 108 | #--------------------------------------------------------------------------------- 109 | export LD := $(CXX) 110 | #--------------------------------------------------------------------------------- 111 | endif 112 | #--------------------------------------------------------------------------------- 113 | 114 | export OFILES_BIN := $(addsuffix .o,$(BINFILES)) 115 | export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o) 116 | export OFILES := $(OFILES_BIN) $(OFILES_SRC) 117 | export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES))) 118 | 119 | export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \ 120 | $(foreach dir,$(LIBDIRS),-I$(dir)/include) \ 121 | -I$(CURDIR)/$(BUILD) 122 | 123 | export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib) 124 | 125 | ifeq ($(strip $(CONFIG_JSON)),) 126 | jsons := $(wildcard *.json) 127 | ifneq (,$(findstring $(TARGET).json,$(jsons))) 128 | export APP_JSON := $(TOPDIR)/$(TARGET).json 129 | else 130 | ifneq (,$(findstring config.json,$(jsons))) 131 | export APP_JSON := $(TOPDIR)/config.json 132 | endif 133 | endif 134 | else 135 | export APP_JSON := $(TOPDIR)/$(CONFIG_JSON) 136 | endif 137 | 138 | ifeq ($(strip $(ICON)),) 139 | icons := $(wildcard *.jpg) 140 | ifneq (,$(findstring $(TARGET).jpg,$(icons))) 141 | export APP_ICON := $(TOPDIR)/$(TARGET).jpg 142 | else 143 | ifneq (,$(findstring icon.jpg,$(icons))) 144 | export APP_ICON := $(TOPDIR)/icon.jpg 145 | endif 146 | endif 147 | else 148 | export APP_ICON := $(TOPDIR)/$(ICON) 149 | endif 150 | 151 | ifeq ($(strip $(NO_ICON)),) 152 | export NROFLAGS += --icon=$(APP_ICON) 153 | endif 154 | 155 | ifeq ($(strip $(NO_NACP)),) 156 | export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp 157 | endif 158 | 159 | ifneq ($(APP_TITLEID),) 160 | export NACPFLAGS += --titleid=$(APP_TITLEID) 161 | endif 162 | 163 | ifneq ($(ROMFS),) 164 | export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS) 165 | endif 166 | 167 | .PHONY: $(BUILD) $(ROMFS) clean all 168 | 169 | #--------------------------------------------------------------------------------- 170 | all: $(BUILD) 171 | 172 | $(ROMFS): 173 | @[ -d $@ ] || mkdir -p $@ 174 | @echo Merging ROMFS... 175 | @[ -f "$(OUTPUT).nro" ] && rm $(OUTPUT).nro || true 176 | @cp -rf $(CURDIR)/$(BOREALIS_PATH)/resources/i18n/. $(CURDIR)/$(ROMFS)/i18n/ 177 | @rm -rf $(CURDIR)/$(ROMFS)/i18n/fr 178 | @rm -rf $(CURDIR)/$(ROMFS)/i18n/*/installer.json $(CURDIR)/$(ROMFS)/i18n/*/main.json $(CURDIR)/$(ROMFS)/i18n/*/popup.json $(CURDIR)/$(ROMFS)/i18n/*/custom_layout.json 179 | @cp -rf $(CURDIR)/$(BOREALIS_PATH)/resources/inter $(CURDIR)/$(BOREALIS_PATH)/resources/material $(CURDIR)/$(ROMFS)/ 180 | @find . -name ".DS_Store" -delete 181 | 182 | $(BUILD): $(ROMFS) 183 | @[ -d $@ ] || mkdir -p $@ 184 | @MSYS2_ARG_CONV_EXCL="-D;$(MSYS2_ARG_CONV_EXCL)" $(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile 185 | 186 | #--------------------------------------------------------------------------------- 187 | clean: 188 | @echo clean ... 189 | ifeq ($(strip $(APP_JSON)),) 190 | @rm -fr $(BUILD) $(notdir $(CURDIR))*.nro $(notdir $(CURDIR))*.nacp $(notdir $(CURDIR))*.elf 191 | else 192 | @rm -fr $(BUILD) $(TARGET).nsp $(TARGET).nso $(TARGET).npdm $(TARGET).elf 193 | endif 194 | 195 | 196 | #--------------------------------------------------------------------------------- 197 | else 198 | .PHONY: all 199 | 200 | DEPENDS := $(OFILES:.o=.d) 201 | 202 | #--------------------------------------------------------------------------------- 203 | # main targets 204 | #--------------------------------------------------------------------------------- 205 | ifeq ($(strip $(APP_JSON)),) 206 | 207 | all : $(OUTPUT).nro 208 | 209 | ifeq ($(strip $(NO_NACP)),) 210 | $(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp 211 | else 212 | $(OUTPUT).nro : $(OUTPUT).elf 213 | endif 214 | 215 | else 216 | 217 | all : $(OUTPUT).nsp 218 | 219 | $(OUTPUT).nsp : $(OUTPUT).nso $(OUTPUT).npdm 220 | 221 | $(OUTPUT).nso : $(OUTPUT).elf 222 | 223 | endif 224 | 225 | $(OUTPUT).elf : $(OFILES) 226 | 227 | $(OFILES_SRC) : $(HFILES_BIN) 228 | 229 | #--------------------------------------------------------------------------------- 230 | # you need a rule like this for each extension you use as binary data 231 | #--------------------------------------------------------------------------------- 232 | %.bin.o %_bin.h : %.bin 233 | #--------------------------------------------------------------------------------- 234 | @echo $(notdir $<) 235 | @$(bin2o) 236 | 237 | -include $(DEPENDS) 238 | 239 | #--------------------------------------------------------------------------------------- 240 | endif 241 | #--------------------------------------------------------------------------------------- 242 | -------------------------------------------------------------------------------- /lib/zipper/include/zip.h: -------------------------------------------------------------------------------- 1 | /* zip.h -- IO on .zip files using zlib 2 | Version 1.1, February 14h, 2010 3 | part of the MiniZip project 4 | 5 | Copyright (C) 1998-2010 Gilles Vollant 6 | http://www.winimage.com/zLibDll/minizip.html 7 | Modifications for Zip64 support 8 | Copyright (C) 2009-2010 Mathias Svensson 9 | http://result42.com 10 | 11 | This program is distributed under the terms of the same license as zlib. 12 | See the accompanying LICENSE file for the full text of the license. 13 | */ 14 | 15 | #ifndef _ZIP_H 16 | #define _ZIP_H 17 | 18 | #ifdef __cplusplus 19 | extern "C" { 20 | #endif 21 | 22 | #ifndef _ZLIB_H 23 | # include "zlib.h" 24 | #endif 25 | 26 | #ifndef _ZLIBIOAPI_H 27 | # include "ioapi.h" 28 | #endif 29 | 30 | #ifdef HAVE_BZIP2 31 | # include "bzlib.h" 32 | #endif 33 | 34 | #define Z_BZIP2ED 12 35 | 36 | #if defined(STRICTZIP) || defined(STRICTZIPUNZIP) 37 | /* like the STRICT of WIN32, we define a pointer that cannot be converted 38 | from (void*) without cast */ 39 | typedef struct TagzipFile__ { int unused; } zipFile__; 40 | typedef zipFile__ *zipFile; 41 | #else 42 | typedef voidp zipFile; 43 | #endif 44 | 45 | #define ZIP_OK (0) 46 | #define ZIP_EOF (0) 47 | #define ZIP_ERRNO (Z_ERRNO) 48 | #define ZIP_PARAMERROR (-102) 49 | #define ZIP_BADZIPFILE (-103) 50 | #define ZIP_INTERNALERROR (-104) 51 | 52 | #ifndef DEF_MEM_LEVEL 53 | # if MAX_MEM_LEVEL >= 8 54 | # define DEF_MEM_LEVEL 8 55 | # else 56 | # define DEF_MEM_LEVEL MAX_MEM_LEVEL 57 | # endif 58 | #endif 59 | /* default memLevel */ 60 | 61 | /* tm_zip contain date/time info */ 62 | typedef struct tm_zip_s 63 | { 64 | uInt tm_sec; /* seconds after the minute - [0,59] */ 65 | uInt tm_min; /* minutes after the hour - [0,59] */ 66 | uInt tm_hour; /* hours since midnight - [0,23] */ 67 | uInt tm_mday; /* day of the month - [1,31] */ 68 | uInt tm_mon; /* months since January - [0,11] */ 69 | uInt tm_year; /* years - [1980..2044] */ 70 | } tm_zip; 71 | 72 | typedef struct 73 | { 74 | tm_zip tmz_date; /* date in understandable format */ 75 | uLong dosDate; /* if dos_date == 0, tmu_date is used */ 76 | uLong internal_fa; /* internal file attributes 2 bytes */ 77 | uLong external_fa; /* external file attributes 4 bytes */ 78 | } zip_fileinfo; 79 | 80 | typedef const char* zipcharpc; 81 | 82 | #define APPEND_STATUS_CREATE (0) 83 | #define APPEND_STATUS_CREATEAFTER (1) 84 | #define APPEND_STATUS_ADDINZIP (2) 85 | 86 | /***************************************************************************/ 87 | /* Writing a zip file */ 88 | 89 | extern zipFile ZEXPORT zipOpen OF((const char *pathname, int append)); 90 | extern zipFile ZEXPORT zipOpen64 OF((const void *pathname, int append)); 91 | /* Create a zipfile. 92 | 93 | pathname should contain the full pathname (by example, on a Windows XP computer 94 | "c:\\zlib\\zlib113.zip" or on an Unix computer "zlib/zlib113.zip". 95 | 96 | return NULL if zipfile cannot be opened 97 | return zipFile handle if no error 98 | 99 | If the file pathname exist and append == APPEND_STATUS_CREATEAFTER, the zip 100 | will be created at the end of the file. (useful if the file contain a self extractor code) 101 | If the file pathname exist and append == APPEND_STATUS_ADDINZIP, we will add files in existing 102 | zip (be sure you don't add file that doesn't exist) 103 | 104 | NOTE: There is no delete function into a zipfile. If you want delete file into a zipfile, 105 | you must open a zipfile, and create another. Of course, you can use RAW reading and writing to copy 106 | the file you did not want delete. */ 107 | 108 | extern zipFile ZEXPORT zipOpen2 OF((const char *pathname, int append, zipcharpc* globalcomment, 109 | zlib_filefunc_def* pzlib_filefunc_def)); 110 | 111 | extern zipFile ZEXPORT zipOpen2_64 OF((const void *pathname, int append, zipcharpc* globalcomment, 112 | zlib_filefunc64_def* pzlib_filefunc_def)); 113 | 114 | extern zipFile ZEXPORT zipOpen3 OF((const char *pathname, int append, ZPOS64_T disk_size, 115 | zipcharpc* globalcomment, zlib_filefunc_def* pzlib_filefunc_def)); 116 | /* Same as zipOpen2 but allows specification of spanned zip size */ 117 | 118 | extern zipFile ZEXPORT zipOpen3_64 OF((const void *pathname, int append, ZPOS64_T disk_size, 119 | zipcharpc* globalcomment, zlib_filefunc64_def* pzlib_filefunc_def)); 120 | 121 | extern int ZEXPORT zipOpenNewFileInZip OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 122 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 123 | uInt size_extrafield_global, const char* comment, int method, int level)); 124 | /* Open a file in the ZIP for writing. 125 | 126 | filename : the filename in zip (if NULL, '-' without quote will be used 127 | *zipfi contain supplemental information 128 | extrafield_local buffer to store the local header extra field data, can be NULL 129 | size_extrafield_local size of extrafield_local buffer 130 | extrafield_global buffer to store the global header extra field data, can be NULL 131 | size_extrafield_global size of extrafield_local buffer 132 | comment buffer for comment string 133 | method contain the compression method (0 for store, Z_DEFLATED for deflate) 134 | level contain the level of compression (can be Z_DEFAULT_COMPRESSION) 135 | zip64 is set to 1 if a zip64 extended information block should be added to the local file header. 136 | this MUST be '1' if the uncompressed size is >= 0xffffffff. */ 137 | 138 | extern int ZEXPORT zipOpenNewFileInZip64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 139 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 140 | uInt size_extrafield_global, const char* comment, int method, int level, int zip64)); 141 | /* Same as zipOpenNewFileInZip with zip64 support */ 142 | 143 | extern int ZEXPORT zipOpenNewFileInZip2 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 144 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 145 | uInt size_extrafield_global, const char* comment, int method, int level, int raw)); 146 | /* Same as zipOpenNewFileInZip, except if raw=1, we write raw file */ 147 | 148 | extern int ZEXPORT zipOpenNewFileInZip2_64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 149 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 150 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int zip64)); 151 | /* Same as zipOpenNewFileInZip3 with zip64 support */ 152 | 153 | extern int ZEXPORT zipOpenNewFileInZip3 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 154 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 155 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 156 | int strategy, const char* password, uLong crcForCrypting)); 157 | /* Same as zipOpenNewFileInZip2, except 158 | windowBits, memLevel, strategy : see parameter strategy in deflateInit2 159 | password : crypting password (NULL for no crypting) 160 | crcForCrypting : crc of file to compress (needed for crypting) */ 161 | 162 | extern int ZEXPORT zipOpenNewFileInZip3_64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 163 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 164 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 165 | int strategy, const char* password, uLong crcForCrypting, int zip64)); 166 | /* Same as zipOpenNewFileInZip3 with zip64 support */ 167 | 168 | extern int ZEXPORT zipOpenNewFileInZip4 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 169 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 170 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 171 | int strategy, const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase)); 172 | /* Same as zipOpenNewFileInZip3 except versionMadeBy & flag fields */ 173 | 174 | extern int ZEXPORT zipOpenNewFileInZip4_64 OF((zipFile file, const char* filename, const zip_fileinfo* zipfi, 175 | const void* extrafield_local, uInt size_extrafield_local, const void* extrafield_global, 176 | uInt size_extrafield_global, const char* comment, int method, int level, int raw, int windowBits, int memLevel, 177 | int strategy, const char* password, uLong crcForCrypting, uLong versionMadeBy, uLong flagBase, int zip64)); 178 | /* Same as zipOpenNewFileInZip4 with zip64 support */ 179 | 180 | extern int ZEXPORT zipWriteInFileInZip OF((zipFile file, const void* buf, unsigned len)); 181 | /* Write data in the zipfile */ 182 | 183 | extern int ZEXPORT zipCloseFileInZip OF((zipFile file)); 184 | /* Close the current file in the zipfile */ 185 | 186 | extern int ZEXPORT zipCloseFileInZipRaw OF((zipFile file, uLong uncompressed_size, uLong crc32)); 187 | extern int ZEXPORT zipCloseFileInZipRaw64 OF((zipFile file, ZPOS64_T uncompressed_size, uLong crc32)); 188 | /* Close the current file in the zipfile, for file opened with parameter raw=1 in zipOpenNewFileInZip2 189 | uncompressed_size and crc32 are value for the uncompressed size */ 190 | 191 | extern int ZEXPORT zipClose OF((zipFile file, const char* global_comment)); 192 | /* Close the zipfile */ 193 | 194 | /***************************************************************************/ 195 | 196 | #ifdef __cplusplus 197 | } 198 | #endif 199 | 200 | #endif /* _ZIP_H */ 201 | --------------------------------------------------------------------------------