From 7b13bc418885d911d5d97662d3edafae9e807ef0 Mon Sep 17 00:00:00 2001 From: cpasjuste Date: Thu, 10 Mar 2016 10:13:42 +0100 Subject: [PATCH] - add new hax for FW > 10.3 - downgrade browser and homemenu last (but before native_firm) - few bug fix and improvements --- .gitmodules | 3 ++ CMakeLists.txt | 10 +++++- source/Main.cpp | 6 ++-- source/Utility.cpp | 84 +++++++++++++++++++++++++++++++++++++--------- source/Utility.h | 4 +++ source/svchax | 1 + 6 files changed, 88 insertions(+), 20 deletions(-) create mode 160000 source/svchax diff --git a/.gitmodules b/.gitmodules index b42039a..03e1094 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "source/SuperUserLib3DS"] path = source/SuperUserLib3DS url = https://github.com/delebile/SuperUserLib3DS +[submodule "source/svchax"] + path = source/svchax + url = https://github.com/aliaspider/svchax.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 28f5911..2c2949e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,8 +14,16 @@ include(Tools3DS) # Include all the macros and tools needed for 3ds development. find_package(CTRULIB REQUIRED) # Look for ctrulib file(GLOB_RECURSE SOURCE_FILES - source/* + source/* ) +file(GLOB FILTER_FILES + source/SuperUserLib3DS/demo/source/* + source/svchax/test.c +) +list(REMOVE_ITEM SOURCE_FILES + ${FILTER_FILES} +) + add_executable(SafeSysUpdater ${SOURCE_FILES}) # Create the elf file target_link_libraries(SafeSysUpdater ${LIBCTRU_LIBRARIES}) # Link ctrulib diff --git a/source/Main.cpp b/source/Main.cpp index b7f5e4a..4f932e2 100644 --- a/source/Main.cpp +++ b/source/Main.cpp @@ -168,6 +168,8 @@ void downgrade() { quit(); } + std::sort(titlesToInstall.begin(), titlesToInstall.end(), Utility::sortTitles); + // downgrade ! debug->printr("\n-> DOWNGRADING <-\n\n"); for (auto it : titlesToInstall) { @@ -221,16 +223,14 @@ int main(int argc, char *argv[]) { } consoleClear(); + printf("HAX INIT...\n"); if (mode > MODE_TITLES_CHECK) { // needs AM - gfxExit(); if (Utility::getAMu() != 0) { - _gfxInit(); debug->printr("FAIL\n"); debug->printr("Can't get am:u service ... try again :x\n"); quit(); } - _gfxInit(); debug->printg("HAX SUCCESS\n"); } diff --git a/source/Utility.cpp b/source/Utility.cpp index bb5f0ca..08ea7ef 100644 --- a/source/Utility.cpp +++ b/source/Utility.cpp @@ -11,27 +11,67 @@ #define BUFSIZE 131072 static FS_Archive sdmcArchive; +extern void _gfxInit(); +extern u8 isNew3DS; +extern "C" { + void patchServiceAccess(); + void svchax_init(); +} + static const u32 titleTypes[7] = { - 0x00040138, // System Firmware - 0x00040130, // System Modules - 0x00040030, // Applets - 0x00040010, // System Applications - 0x0004001B, // System Data Archives - 0x0004009B, // System Data Archives (Shared Archives) - 0x000400DB, // System Data Archives + 0x00040138, // System Firmware + 0x00040130, // System Modules + 0x00040030, // Applets + 0x00040010, // System Applications + 0x0004001B, // System Data Archives + 0x0004009B, // System Data Archives (Shared Archives) + 0x000400DB, // System Data Archives +}; + +static const u64 titleHomeMenu[3] = { + 0x0004003000008F02, // USA Home Menu + 0x0004003000009802, // EUR Home Menu + 0x0004003000008202, // JPN Home Menu +}; + +static const u64 titleBrowser[6] = { + 0x0004003020009402, // USA New3DS Internet Browser + 0x0004003020009D02, // EUR New3DS Internet Browser + 0x0004003020008802, // JPN New3DS Internet Browser + 0x0004003000009402, // USA Internet Browser + 0x0004003000009D02, // EUR Internet Browser + 0x0004003000008802, // JPN Internet Browser }; -static u32 getTitlePriority(u64 id) { +u32 Utility::getTitlePriority(u64 id) { + + // nfirm last + if( id == 0x0004013800000002LL + || id == 0x0004013820000002LL) { + return 0; + } + + // downgrade browser and homemenu last + for (u32 i = 0; i < 6; i++) { + if (id == titleBrowser[i]) { + return 2; + } + } + for (u32 i = 0; i < 3; i++) { + if (id == titleHomeMenu[i]) { + return 1; + } + } u32 type = (u32) (id >> 32); for (u32 i = 0; i < 7; i++) { if (type == titleTypes[i]) { - return i; + return i+3; } } return 0; } -static bool sortTitles(const TitleInfo &a, const TitleInfo &b) { +bool Utility::sortTitles(const TitleInfo &a, const TitleInfo &b) { bool aSafe = (a.titleID & 0xFF) == 0x03; bool bSafe = (b.titleID & 0xFF) == 0x03; if (aSafe != bSafe) { @@ -189,14 +229,26 @@ int Utility::getAMu() { } // try to get arm11 - if (suInit() == 0) { - // verify am:u access - srvGetServiceHandleDirect(&amHandle, "am:u"); - if (amHandle) { - svcCloseHandle(amHandle); - return 0; + if(osGetKernelVersion() > SYSTEM_VERSION(2,50,9)) { + svchax_init(); + aptInit(); + APT_CheckNew3DS(&isNew3DS); + patchServiceAccess(); + } else { + gfxExit(); + if (suInit() != 0) { + _gfxInit(); + return 1; } + _gfxInit(); + } + + srvGetServiceHandleDirect(&amHandle, "am:u"); + if (amHandle) { + svcCloseHandle(amHandle); + return 0; } + return 1; } diff --git a/source/Utility.h b/source/Utility.h index ca4d90b..dc6c75c 100644 --- a/source/Utility.h +++ b/source/Utility.h @@ -29,6 +29,10 @@ class Utility { static bool installTitle(std::string path); + static u32 getTitlePriority(u64 id); + + static bool sortTitles(const TitleInfo &a, const TitleInfo &b); + static int cmp(std::vector &installedTitles, u64 &titleID, u16 version); static int version(std::vector &titles, u64 &titleID); diff --git a/source/svchax b/source/svchax new file mode 160000 index 0000000..40d050e --- /dev/null +++ b/source/svchax @@ -0,0 +1 @@ +Subproject commit 40d050ee92cd933d603a23558382f79780faec72