mirror of
https://github.com/wiiu-env/haxchi.git
synced 2024-11-16 13:19:16 +01:00
-made possible elf path much longer, instead of 80 characters it now supports up to 250
-if a elf requests to return to hbl it will now also return to hbl instead of always forcing it out to mii maker, fixes apps like wupinstaller
This commit is contained in:
parent
e803047295
commit
eedfba866c
@ -29,6 +29,9 @@ extern "C" {
|
|||||||
|
|
||||||
#define MEM_AREA_TABLE ((s_mem_area*)(MEM_BASE + 0x1600))
|
#define MEM_AREA_TABLE ((s_mem_area*)(MEM_BASE + 0x1600))
|
||||||
|
|
||||||
|
#define SD_LOADER_PATH ((char*)(MEM_BASE + 0x1E00))
|
||||||
|
#define SD_LOADER_FORCE_HBL (*(volatile unsigned int*)(MEM_BASE + 0x1E00 + 0xFC))
|
||||||
|
|
||||||
#ifndef EXIT_SUCCESS
|
#ifndef EXIT_SUCCESS
|
||||||
#define EXIT_SUCCESS 0
|
#define EXIT_SUCCESS 0
|
||||||
#endif
|
#endif
|
||||||
|
@ -305,16 +305,6 @@ static void InstallMain(private_data_t *private_data)
|
|||||||
if(section_offset > 0)
|
if(section_offset > 0)
|
||||||
SC_0x25_KernelCopyData((void*)(CODE_RW_BASE_OFFSET + main_text_addr), main_text, main_text_len);
|
SC_0x25_KernelCopyData((void*)(CODE_RW_BASE_OFFSET + main_text_addr), main_text, main_text_len);
|
||||||
|
|
||||||
// get the .rodata1 section
|
|
||||||
unsigned int main_rodata1_addr = 0;
|
|
||||||
unsigned int main_rodata1_len = 0;
|
|
||||||
section_offset = get_section(private_data, private_data->data_elf, ".rodata1", &main_rodata1_len, &main_rodata1_addr, 0);
|
|
||||||
if(section_offset > 0)
|
|
||||||
{
|
|
||||||
/* Copy main rodata to memory */
|
|
||||||
SC_0x25_KernelCopyData((void*)(DATA_RW_BASE_OFFSET + main_rodata1_addr), (void*)0xF5E70000, main_rodata1_len);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the .rodata section
|
// get the .rodata section
|
||||||
unsigned int main_rodata_addr = 0;
|
unsigned int main_rodata_addr = 0;
|
||||||
unsigned int main_rodata_len = 0;
|
unsigned int main_rodata_len = 0;
|
||||||
@ -367,6 +357,9 @@ static void InstallPatches(private_data_t *private_data)
|
|||||||
SC_0x25_KernelCopyData((void*)&ELF_DATA_ADDR, &bufferU32, sizeof(bufferU32));
|
SC_0x25_KernelCopyData((void*)&ELF_DATA_ADDR, &bufferU32, sizeof(bufferU32));
|
||||||
bufferU32 = 0;
|
bufferU32 = 0;
|
||||||
SC_0x25_KernelCopyData((void*)&ELF_DATA_SIZE, &bufferU32, sizeof(bufferU32));
|
SC_0x25_KernelCopyData((void*)&ELF_DATA_SIZE, &bufferU32, sizeof(bufferU32));
|
||||||
|
/* Related to sd-loader elf choice */
|
||||||
|
SC_0x25_KernelCopyData((void*)SD_LOADER_PATH, (void*)0xF5E70000, 250);
|
||||||
|
SC_0x25_KernelCopyData((void*)&SD_LOADER_FORCE_HBL, &bufferU32, sizeof(bufferU32));
|
||||||
|
|
||||||
unsigned int jump_main_hook = 0;
|
unsigned int jump_main_hook = 0;
|
||||||
osSpecificFunctions.addr_OSDynLoad_Acquire = (unsigned int)OSDynLoad_Acquire;
|
osSpecificFunctions.addr_OSDynLoad_Acquire = (unsigned int)OSDynLoad_Acquire;
|
||||||
|
@ -564,17 +564,10 @@ static void loadFunctionPointers(private_data_t * private_data)
|
|||||||
OS_FIND_EXPORT(sysapp_handle, "SYSRelaunchTitle", private_data->SYSRelaunchTitle);
|
OS_FIND_EXPORT(sysapp_handle, "SYSRelaunchTitle", private_data->SYSRelaunchTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern const char PROVIDED_ELF_LAUNCH_PATH;
|
static const char *HBL_ELF_PATH = "/vol/external01/wiiu/apps/homebrew_launcher/homebrew_launcher.elf";
|
||||||
extern int INT_EXIT_TO_MENU;
|
|
||||||
|
|
||||||
unsigned int _main(int argc, char **argv)
|
unsigned int _main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
unsigned int entry = *(unsigned int*)OS_SPECIFICS->addr_OSTitle_main_entry;
|
|
||||||
|
|
||||||
//! force launch normal title every time (safety lock-out mechanism)
|
|
||||||
if(INT_EXIT_TO_MENU == 2)
|
|
||||||
return entry;
|
|
||||||
|
|
||||||
private_data_t private_data;
|
private_data_t private_data;
|
||||||
|
|
||||||
if(MAIN_ENTRY_ADDR != 0xC001C0DE)
|
if(MAIN_ENTRY_ADDR != 0xC001C0DE)
|
||||||
@ -609,7 +602,7 @@ unsigned int _main(int argc, char **argv)
|
|||||||
unsigned char *pElfBuffer = NULL;
|
unsigned char *pElfBuffer = NULL;
|
||||||
unsigned int uiElfSize = 0;
|
unsigned int uiElfSize = 0;
|
||||||
|
|
||||||
LoadFileToMem(&private_data, &PROVIDED_ELF_LAUNCH_PATH, &pElfBuffer, &uiElfSize);
|
LoadFileToMem(&private_data, SD_LOADER_FORCE_HBL ? HBL_ELF_PATH : SD_LOADER_PATH, &pElfBuffer, &uiElfSize);
|
||||||
|
|
||||||
if(!pElfBuffer)
|
if(!pElfBuffer)
|
||||||
{
|
{
|
||||||
@ -632,19 +625,15 @@ unsigned int _main(int argc, char **argv)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
int returnVal = ((int (*)(int, char **))MAIN_ENTRY_ADDR)(argc, argv);
|
int returnVal = ((int (*)(int, char **))MAIN_ENTRY_ADDR)(argc, argv);
|
||||||
//! launched custom elf once, now activate lock-out mechanism for safety
|
|
||||||
if(INT_EXIT_TO_MENU == 1)
|
|
||||||
INT_EXIT_TO_MENU = 2;
|
|
||||||
//! exit to miimaker and restart application on re-enter of another application
|
//! exit to miimaker and restart application on re-enter of another application
|
||||||
if(returnVal == (int)EXIT_RELAUNCH_ON_LOAD)
|
if(returnVal == (int)EXIT_RELAUNCH_ON_LOAD)
|
||||||
{
|
{
|
||||||
//! exited hbl itself, activate lock-out mechanism for safety
|
|
||||||
INT_EXIT_TO_MENU = 2;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//! exit to homebrew launcher in all other cases
|
//! exit to homebrew launcher in all other cases
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
SD_LOADER_FORCE_HBL = 1;
|
||||||
MAIN_ENTRY_ADDR = 0xDEADC0DE;
|
MAIN_ENTRY_ADDR = 0xDEADC0DE;
|
||||||
private_data.SYSRelaunchTitle(0, 0);
|
private_data.SYSRelaunchTitle(0, 0);
|
||||||
private_data.exit(0);
|
private_data.exit(0);
|
||||||
@ -654,13 +643,14 @@ unsigned int _main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int entry = *(unsigned int*)OS_SPECIFICS->addr_OSTitle_main_entry;
|
||||||
//! if an application was an RPX launch then launch HBL again after return
|
//! if an application was an RPX launch then launch HBL again after return
|
||||||
if(MAIN_ENTRY_ADDR == 0xC001C0DE)
|
/*if(MAIN_ENTRY_ADDR == 0xC001C0DE)
|
||||||
{
|
{
|
||||||
int ret = ( (int (*)(int, char **))(entry) )(argc, argv);
|
int ret = ( (int (*)(int, char **))(entry) )(argc, argv);
|
||||||
private_data.SYSRelaunchTitle(0, 0);
|
private_data.SYSRelaunchTitle(0, 0);
|
||||||
private_data.exit(ret);
|
private_data.exit(ret);
|
||||||
}
|
}*/
|
||||||
//! launch the original title with clean stack
|
//! launch the original title with clean stack
|
||||||
return entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
@ -11,16 +11,13 @@ SECTIONS {
|
|||||||
KEEP(*(.kernel_code*));
|
KEEP(*(.kernel_code*));
|
||||||
}
|
}
|
||||||
.data : {
|
.data : {
|
||||||
*(.rodata) *(.rodata.*);
|
*(.rodata*);
|
||||||
*(.data*);
|
*(.data*);
|
||||||
*(.bss*);
|
*(.bss*);
|
||||||
}
|
}
|
||||||
.rodata1 : {
|
|
||||||
*(.rodata1) *(.rodata1.*)
|
|
||||||
}
|
|
||||||
/DISCARD/ : {
|
/DISCARD/ : {
|
||||||
*(*);
|
*(*);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT((SIZEOF(.text) + SIZEOF(.data) + SIZEOF(.rodata1)) <= 0x1300, "Memory overlapping with main elf.");
|
ASSERT((SIZEOF(.text) + SIZEOF(.data)) <= 0x1300, "Memory overlapping with main elf.");
|
||||||
|
@ -105,18 +105,13 @@ uint32_t __main(void)
|
|||||||
void*(*MEMAllocFromDefaultHeap)(int size) = (void*)(*pMEMAllocFromDefaultHeap);
|
void*(*MEMAllocFromDefaultHeap)(int size) = (void*)(*pMEMAllocFromDefaultHeap);
|
||||||
void(*MEMFreeToDefaultHeap)(void *ptr) = (void*)(*pMEMFreeToDefaultHeap);
|
void(*MEMFreeToDefaultHeap)(void *ptr) = (void*)(*pMEMFreeToDefaultHeap);
|
||||||
|
|
||||||
void* (*OSAllocFromSystem)(uint32_t size, int align);
|
|
||||||
void (*OSFreeToSystem)(void *ptr);
|
|
||||||
OSDynLoad_FindExport(coreinit_handle, 0, "OSAllocFromSystem", &OSAllocFromSystem);
|
|
||||||
OSDynLoad_FindExport(coreinit_handle, 0, "OSFreeToSystem", &OSFreeToSystem);
|
|
||||||
|
|
||||||
int hbl = 1;
|
int hbl = 1;
|
||||||
//default path goes to HBL
|
//default path goes to HBL
|
||||||
strcpy((void*)0xF5E70000,"/vol/external01/wiiu/apps/homebrew_launcher/homebrew_launcher.elf");
|
strcpy((void*)0xF5E70000,"/vol/external01/wiiu/apps/homebrew_launcher/homebrew_launcher.elf");
|
||||||
|
|
||||||
int iFd = -1;
|
int iFd = -1;
|
||||||
void *pClient = OSAllocFromSystem(0x1700,4);
|
void *pClient = MEMAllocFromDefaultHeapEx(0x1700,4);
|
||||||
void *pCmd = OSAllocFromSystem(0xA80,4);
|
void *pCmd = MEMAllocFromDefaultHeapEx(0xA80,4);
|
||||||
void *pBuffer = NULL;
|
void *pBuffer = NULL;
|
||||||
|
|
||||||
void (*DCStoreRange)(void *buffer, uint32_t length);
|
void (*DCStoreRange)(void *buffer, uint32_t length);
|
||||||
@ -153,7 +148,7 @@ uint32_t __main(void)
|
|||||||
|
|
||||||
if(stat.size > 0)
|
if(stat.size > 0)
|
||||||
{
|
{
|
||||||
pBuffer = OSAllocFromSystem(stat.size+1,0x40);
|
pBuffer = MEMAllocFromDefaultHeapEx(stat.size+1,0x40);
|
||||||
memset(pBuffer,0,stat.size+1);
|
memset(pBuffer,0,stat.size+1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -219,24 +214,24 @@ uint32_t __main(void)
|
|||||||
if(FnameChar[0] == '/' && fLen > 7 && *(FnameChar+fLen-7) == '/')
|
if(FnameChar[0] == '/' && fLen > 7 && *(FnameChar+fLen-7) == '/')
|
||||||
{
|
{
|
||||||
*(FnameChar+fLen-7) = '\0';
|
*(FnameChar+fLen-7) = '\0';
|
||||||
__os_snprintf((void*)0xF5E70000,160,"/vol/sdcard%s",FnameChar);
|
__os_snprintf((void*)0xF5E70000,32,"/vol/sdcard%s",FnameChar);
|
||||||
}
|
}
|
||||||
else if(FnameChar[0] != '/' && fLen > 6 && *(FnameChar+fLen-7) == '/')
|
else if(FnameChar[0] != '/' && fLen > 6 && *(FnameChar+fLen-7) == '/')
|
||||||
{
|
{
|
||||||
*(FnameChar+fLen-7) = '\0';
|
*(FnameChar+fLen-7) = '\0';
|
||||||
__os_snprintf((void*)0xF5E70000,160,"/vol/sdcard/%s",FnameChar);
|
__os_snprintf((void*)0xF5E70000,32,"/vol/sdcard/%s",FnameChar);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
__os_snprintf((void*)0xF5E70000,160,"/vol/sdcard");
|
__os_snprintf((void*)0xF5E70000,32,"/vol/sdcard");
|
||||||
hbl = 0;
|
hbl = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else if(memcmp(FnameChar+fLen-4,".elf",5) == 0)
|
else if(memcmp(FnameChar+fLen-4,".elf",5) == 0)
|
||||||
{
|
{
|
||||||
if(FnameChar[0] == '/')
|
if(FnameChar[0] == '/')
|
||||||
__os_snprintf((void*)0xF5E70000,80,"/vol/external01%s",FnameChar);
|
__os_snprintf((void*)0xF5E70000,250,"/vol/external01%s",FnameChar);
|
||||||
else
|
else
|
||||||
__os_snprintf((void*)0xF5E70000,80,"/vol/external01/%s",FnameChar);
|
__os_snprintf((void*)0xF5E70000,250,"/vol/external01/%s",FnameChar);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -249,18 +244,13 @@ fileEnd:
|
|||||||
if(iFd >= 0)
|
if(iFd >= 0)
|
||||||
FSCloseFile(pClient, pCmd, iFd, -1);
|
FSCloseFile(pClient, pCmd, iFd, -1);
|
||||||
FSDelClient(pClient);
|
FSDelClient(pClient);
|
||||||
OSFreeToSystem(pClient);
|
MEMFreeToDefaultHeap(pClient);
|
||||||
OSFreeToSystem(pCmd);
|
MEMFreeToDefaultHeap(pCmd);
|
||||||
}
|
}
|
||||||
if(pBuffer)
|
if(pBuffer)
|
||||||
OSFreeToSystem(pBuffer);
|
MEMFreeToDefaultHeap(pBuffer);
|
||||||
if(hbl)
|
if(hbl)
|
||||||
{
|
*(int*)0xF5E700FC = 0; //set SD_LOADER_FORCE_HBL to 0
|
||||||
if(strstr((char*)0xF5E70000, "/homebrew_launcher.elf") != NULL)
|
|
||||||
*(int*)0xF5E70050 = 0; //return to hbl
|
|
||||||
else
|
|
||||||
*(int*)0xF5E70050 = 1; //return to menu
|
|
||||||
}
|
|
||||||
DCStoreRange((void*)0xF5E70000,0xA0);
|
DCStoreRange((void*)0xF5E70000,0xA0);
|
||||||
uint32_t entry = (hbl ? 0x01800000 : 0x0180C000);
|
uint32_t entry = (hbl ? 0x01800000 : 0x0180C000);
|
||||||
return entry;
|
return entry;
|
||||||
|
Loading…
Reference in New Issue
Block a user