Fix USB usage

This commit is contained in:
Maschell 2021-12-27 23:31:54 +01:00
parent f05f1a2420
commit 27418f035c
2 changed files with 91 additions and 111 deletions

View File

@ -1,5 +1,5 @@
#include <stdint.h>
#include <string.h>
#include <cstdint>
#include <cstring>
#include <malloc.h>
#include <coreinit/dynload.h>
#include <coreinit/debug.h>
@ -34,6 +34,7 @@ extern "C" void SC_0x25_KernelCopyData(unsigned int addr, unsigned int src, unsi
void __attribute__ ((noinline)) kern_write(void *addr, uint32_t value);
static void InstallPatches();
static unsigned int load_elf_image(const uint8_t *elfstart) {
@ -73,7 +74,7 @@ static unsigned int load_elf_image(const uint8_t *elfstart) {
}
//! clear BSS
Elf32_Shdr *shdr = (Elf32_Shdr *) (elfstart + ehdr->e_shoff);
auto *shdr = (Elf32_Shdr *) (elfstart + ehdr->e_shoff);
for (i = 0; i < ehdr->e_shnum; i++) {
const char *section_name = ((const char *) elfstart) + shdr[ehdr->e_shstrndx].sh_offset + shdr[i].sh_name;
if (section_name[0] == '.' && section_name[1] == 'b' && section_name[2] == 's' && section_name[3] == 's') {
@ -92,8 +93,8 @@ void KernelWriteU32(uint32_t addr, uint32_t value) {
ICInvalidateRange(&value, 4);
DCFlushRange(&value, 4);
uint32_t dst = (uint32_t) OSEffectiveToPhysical((uint32_t) addr);
uint32_t src = (uint32_t) OSEffectiveToPhysical((uint32_t) &value);
auto dst = (uint32_t) OSEffectiveToPhysical((uint32_t) addr);
auto src = (uint32_t) OSEffectiveToPhysical((uint32_t) &value);
SC_0x25_KernelCopyData(dst, src, 4);
@ -118,7 +119,7 @@ void InstallHBL() {
InstallPatches();
unsigned char *pElfBuffer = (unsigned char *) sd_loader_elf; // use this address as temporary to load the elf
auto *pElfBuffer = (unsigned char *) sd_loader_elf; // use this address as temporary to load the elf
unsigned int mainEntryPoint = load_elf_image(pElfBuffer);
if (mainEntryPoint == 0) {
@ -144,16 +145,16 @@ static void InstallPatches() {
unsigned int bufferU32;
/* Pre-setup a few options to defined values */
bufferU32 = 550;
memcpy((void*)&OS_FIRMWARE, &bufferU32, sizeof(bufferU32));
memcpy((void *) &OS_FIRMWARE, &bufferU32, sizeof(bufferU32));
bufferU32 = 0xDEADC0DE;
memcpy((void*)&MAIN_ENTRY_ADDR, &bufferU32, sizeof(bufferU32));
memcpy((void*)&ELF_DATA_ADDR, &bufferU32, sizeof(bufferU32));
memcpy((void *) &MAIN_ENTRY_ADDR, &bufferU32, sizeof(bufferU32));
memcpy((void *) &ELF_DATA_ADDR, &bufferU32, sizeof(bufferU32));
bufferU32 = 0;
memcpy((void*)&ELF_DATA_SIZE, &bufferU32, sizeof(bufferU32));
memcpy((void*)&HBL_CHANNEL, &bufferU32, sizeof(bufferU32));
memcpy((void *) &ELF_DATA_SIZE, &bufferU32, sizeof(bufferU32));
memcpy((void *) &HBL_CHANNEL, &bufferU32, sizeof(bufferU32));
osSpecificFunctions.addr_OSDynLoad_Acquire = (unsigned int)OSDynLoad_Acquire;
osSpecificFunctions.addr_OSDynLoad_FindExport = (unsigned int)OSDynLoad_FindExport;
osSpecificFunctions.addr_OSDynLoad_Acquire = (unsigned int) OSDynLoad_Acquire;
osSpecificFunctions.addr_OSDynLoad_FindExport = (unsigned int) OSDynLoad_FindExport;
osSpecificFunctions.addr_KernSyscallTbl1 = KERN_SYSCALL_TBL_1;
osSpecificFunctions.addr_KernSyscallTbl2 = KERN_SYSCALL_TBL_2;
@ -167,12 +168,12 @@ static void InstallPatches() {
osSpecificFunctions.addr_PrepareTitle_hook = address_PrepareTitle_hook;
osSpecificFunctions.addr_sgIsLoadingBuffer = address_sgIsLoadingBuffer;
osSpecificFunctions.addr_gDynloadInitialized = address_gDynloadInitialized;
osSpecificFunctions.orig_LiWaitOneChunkInstr = *(unsigned int*)address_LiWaitOneChunk;
osSpecificFunctions.orig_LiWaitOneChunkInstr = *(unsigned int *) address_LiWaitOneChunk;
//! pointer to main entry point of a title
osSpecificFunctions.addr_OSTitle_main_entry = ADDRESS_OSTitle_main_entry_ptr;
memcpy((void*)OS_SPECIFICS, &osSpecificFunctions, sizeof(OsSpecifics));
memcpy((void *) OS_SPECIFICS, &osSpecificFunctions, sizeof(OsSpecifics));
}
/* Write a 32-bit word with kernel permissions */

View File

@ -1,4 +1,4 @@
#include <stdint.h>
#include <cstdint>
#include <malloc.h>
#include <cstring>
#include <proc_ui/procui.h>
@ -6,12 +6,10 @@
#include <sysapp/title.h>
#include <coreinit/mcp.h>
#include <coreinit/debug.h>
#include <nn/acp/title.h>
#include <nn/sl/common.h>
#include <nn/sl/FileStream.h>
#include <nn/sl/LaunchInfoDatabase.h>
#include <nn/acp.h>
#include <nn/spm.h>
#include <nn/sl.h>
#include <nn/ccr/sys_caffeine.h>
#include <coreinit/dynload.h>
#include <nn/act/client_cpp.h>
@ -28,7 +26,7 @@ bool getQuickBoot() {
if (bootCheck == 0) {
nn::sl::Initialize(MEMAllocFromDefaultHeapEx, MEMFreeToDefaultHeap);
char path[0x80];
nn::sl::GetDefaultDatabasePath(path, 0x80, 0x00050010, 0x10066000);
nn::sl::GetDefaultDatabasePath(path, 0x80, 0x0005001010066000L); // ECO process
FSCmdBlock cmdBlock;
FSInitCmdBlock(&cmdBlock);
@ -57,18 +55,18 @@ bool getQuickBoot() {
nn::sl::Finalize();
if(!result.IsSuccess()) {
if (!result.IsSuccess()) {
DEBUG_FUNCTION_LINE("GetLaunchInfoById failed.");
return false;
}
if( info.titleId == 0x0005001010040000L ||
if (info.titleId == 0x0005001010040000L ||
info.titleId == 0x0005001010040100L ||
info.titleId == 0x0005001010040200L) {
DEBUG_FUNCTION_LINE("Skip quick booting into the Wii U Menu");
return false;
}
if(!SYSCheckTitleExists(info.titleId)) {
if (!SYSCheckTitleExists(info.titleId)) {
DEBUG_FUNCTION_LINE("Title %016llX doesn't exist", info.titleId);
return false;
}
@ -77,13 +75,13 @@ bool getQuickBoot() {
int32_t handle = MCP_Open();
auto err = MCP_GetTitleInfo(handle, info.titleId, &titleInfo);
MCP_Close(handle);
if(err == 0) {
if (err == 0) {
nn::act::Initialize();
for(int i = 0; i < 13; i++){
for (int i = 0; i < 13; i++) {
char uuid[16];
auto result = nn::act::GetUuidEx(uuid, i);
if(result.IsSuccess()){
if( memcmp(uuid, data.uuid, 8) == 0) {
result = nn::act::GetUuidEx(uuid, i);
if (result.IsSuccess()) {
if (memcmp(uuid, data.uuid, 8) == 0) {
DEBUG_FUNCTION_LINE("Load Console account %d", i);
nn::act::LoadConsoleAccount(i, 0, 0, 0);
break;
@ -104,80 +102,61 @@ bool getQuickBoot() {
return false;
}
struct WUT_PACKED VolumeInfo
{
WUT_UNKNOWN_BYTES(0xAC);
char volumeId[16];
WUT_UNKNOWN_BYTES(0x100);
};
WUT_CHECK_OFFSET(VolumeInfo, 0xAC, volumeId);
WUT_CHECK_SIZE(VolumeInfo, 444);
extern "C" uint32_t FSGetVolumeInfo(FSClient*, FSCmdBlock*, const char* path, VolumeInfo* data, FSErrorFlag errorMask);
extern "C" void Initialize__Q2_2nn3spmFv();
extern "C" void SetAutoFatal__Q2_2nn3spmFb(bool);
extern "C" void SetExtendedStorage__Q2_2nn3spmFQ3_2nn3spm12StorageIndex(uint64_t*);
extern "C" void SetDefaultExtendedStorageVolumeId__Q2_2nn3spmFRCQ3_2nn3spm8VolumeId(char *);
extern "C" uint32_t FindStorageByVolumeId__Q2_2nn3spmFPQ3_2nn3spm12StorageIndexRCQ3_2nn3spm8VolumeId(uint64_t *, char *);
static void initExternalStorage(void) {
Initialize__Q2_2nn3spmFv();
static void initExternalStorage() {
nn::spm::Initialize();
FSCmdBlock cmdBlock;
FSInitCmdBlock(&cmdBlock);
VolumeInfo volumeInfo;
FSVolumeInfo volumeInfo;
auto *fsClient = (FSClient *) memalign(0x40, sizeof(FSClient));
memset(fsClient, 0, sizeof(*fsClient));
FSAddClient(fsClient, FS_ERROR_FLAG_NONE);
char volumePaths[][19] =
{ "/vol/storage_usb01",
char volumePaths[][19] = {"/vol/storage_usb01",
"/vol/storage_usb02",
"/vol/storage_usb03",
};
bool found = false;
for(auto path : volumePaths) {
for (auto path: volumePaths) {
DEBUG_FUNCTION_LINE("Check if %s is connected", path);
if(FSGetVolumeInfo(fsClient, &cmdBlock, path, &volumeInfo, FS_ERROR_FLAG_ALL) == 0){
if (FSGetVolumeInfo(fsClient, &cmdBlock, path, &volumeInfo, FS_ERROR_FLAG_ALL) == 0) {
nn::spm::StorageIndex storageIndex = 0;
if (nn::spm::FindStorageByVolumeId(&storageIndex, (nn::spm::VolumeId *) volumeInfo.volumeId)) {
DEBUG_FUNCTION_LINE("Set DefaultExtendedStorage to %s", volumeInfo.volumeId);
SetDefaultExtendedStorageVolumeId__Q2_2nn3spmFRCQ3_2nn3spm8VolumeId(volumeInfo.volumeId);
uint64_t storageIndex = 0;
FindStorageByVolumeId__Q2_2nn3spmFPQ3_2nn3spm12StorageIndexRCQ3_2nn3spm8VolumeId(&storageIndex, volumeInfo.volumeId);
SetExtendedStorage__Q2_2nn3spmFQ3_2nn3spm12StorageIndex(&storageIndex);
nn::spm::SetDefaultExtendedStorageVolumeId((nn::spm::VolumeId *) volumeInfo.volumeId);
nn::spm::SetExtendedStorage(&storageIndex);
ACPMountExternalStorage();
found = true;
break;
} else {
DEBUG_FUNCTION_LINE("Failed to find Storage by VolumeId(%s)", volumeInfo.volumeId);
}
}
}
if (!found) {
DEBUG_FUNCTION_LINE("Fallback to empty ExtendedStorage");
char empty[16];
empty[0] = '\0';
SetDefaultExtendedStorageVolumeId__Q2_2nn3spmFRCQ3_2nn3spm8VolumeId(empty);
nn::spm::VolumeId empty{};
nn::spm::SetDefaultExtendedStorageVolumeId(&empty);
uint64_t storageIndex = 0;
SetExtendedStorage__Q2_2nn3spmFQ3_2nn3spm12StorageIndex(&storageIndex);
nn::spm::StorageIndex storageIndex = 0;
nn::spm::SetExtendedStorage(&storageIndex);
}
FSDelClient(fsClient, FS_ERROR_FLAG_ALL);
nn::spm::Finalize();
}
void bootHomebrewLauncher(void) {
void bootHomebrewLauncher() {
uint64_t titleId = _SYSGetSystemApplicationTitleId(SYSTEM_APP_ID_MII_MAKER);
_SYSLaunchTitleWithStdArgsInNoSplash(titleId, nullptr);
}
extern "C" void _SYSLaunchMenuWithCheckingAccount(nn::act::SlotNo slot);
int main(int argc, char **argv) {
if(!WHBLogModuleInit()){
if (!WHBLogModuleInit()) {
WHBLogCafeInit();
WHBLogUdpInit();
}
@ -186,7 +165,7 @@ int main(int argc, char **argv) {
InstallHBL();
if(getQuickBoot()) {
if (getQuickBoot()) {
return 0;
}