Ejemplo n.º 1
0
s32 IOS_ReloadIOS(int version)
{
	int ret = 0;
	int res;

#ifdef DEBUG_IOS
	printf("Reloading to IOS%d\n",version);
#endif

	res = __IOS_ShutdownSubsystems();
	if(res < 0) {
#ifdef DEBUG_IOS
		printf("__IOS_ShutdownSubsystems failed: %d\n", res);
#endif
		ret = res;
	}

	res = __ES_Init();
	if(res < 0) {
#ifdef DEBUG_IOS
		printf("__ES_Init failed: %d\n", res);
#endif
		ret = res;
	} else {
		res = __IOS_LaunchNewIOS(version);
		if(res < 0) {
#ifdef DEBUG_IOS
			printf("__IOS_LaunchNewIOS failed: %d\n", res);
#endif
			ret = res;
			__ES_Close();
		}
	}

	res = __IOS_InitializeSubsystems();
	if(res < 0) {
#ifdef DEBUG_IOS
		printf("__IOS_InitializeSubsystems failed: %d\n", res);
#endif
		ret = res;
	}

	return ret;
}
Ejemplo n.º 2
0
s32 __DI_LoadStub(void)
{
	int ret = 0;
	int res;
#ifdef DEBUG_IOS
	dprintf("Reloading to IOS%d\n",version);
#endif
	res = __IOS_ShutdownSubsystems();
	if(res < 0) ret = res;
	res = __ES_Init();
	if(res < 0) ret = res;
	else {
		res = __DI_StubLaunch();
		if(res < 0) {
			ret = res;
			__ES_Close();
		}
	}
	res = __IOS_InitializeSubsystems();
	if(res < 0) ret = res;
	return ret;
}
Ejemplo n.º 3
0
s32 __DI_StubLaunch(void)
{
	u64 titleID = DVD_TITLEID;
	static tikview views[4] ATTRIBUTE_ALIGN(32);
	u32 numviews;
	s32 res;
	
	u32 ints;
	
	dprintf("Shutting down IOS subsystems\n");
	res = __IOS_ShutdownSubsystems();
	if(res < 0) {
		dprintf("Shutdown failed: %d\n",res);
	}
	dprintf("Initializing ES\n");
	res = __ES_Init();
	if(res < 0) {
		dprintf("ES init failed: %d\n",res);
		return res;
	}
	
	dprintf("Launching TitleID: %016llx\n",titleID);
	
	res = ES_GetNumTicketViews(titleID, &numviews);
	if(res < 0) {
		dprintf(" GetNumTicketViews failed: %d\n",res);
		return res;
	}
	if(numviews > 4) {
		dprintf(" GetNumTicketViews too many views: %u\n",numviews);
		return IOS_ETOOMANYVIEWS;
	}
	res = ES_GetTicketViews(titleID, views, numviews);
	if(res < 0) {
		dprintf(" GetTicketViews failed: %d\n",res);
		return res;
	}
	dprintf("Ready to launch channel\n");
	res = ES_LaunchTitleBackground(titleID, &views[0]);
	if(res<0) {
		dprintf("Launch failed: %d\n",res);
		return res;
	}
	dprintf("Channel launching in the background\n");
	dprintf("Pre-stub status:\n");
	dumpregs();
	dprintf("ISR Disable...\n");
	_CPU_ISR_Disable( ints );
	dprintf("Saving regs...\n");
	__distub_saveregs();
	dprintf("Taking the plunge...\n");
	__distub_take_plunge(&di_ctx);
	
	dprintf("We're back!\n");
	dprintf("Restoring regs...\n");
	__distub_restregs();
	dprintf("ISR Enable...\n");
	_CPU_ISR_Restore( ints );
	
	dprintf("Post-stub status:\n");
	dumpregs();
	
	__IPC_Reinitialize();
	__ES_Reset();
	
	dprintf("IPC reinitialized\n");
	sleep(1);
	dprintf("Restarting IOS subsystems\n");
	
	res = __IOS_InitializeSubsystems();
	
	dprintf("Subsystems running!\n");
	
	res = ES_GetNumTicketViews(titleID, &numviews);
	if(res < 0) {
		dprintf(" GetNumTicketViews failed: %d\n",res);
		return res;
	}
	dprintf(" GetNumTicketViews: %d",numviews);
	
	return 0;
}
Ejemplo n.º 4
0
s32 Disc_BootPartition(u64 offset, u8 videoselected, u8 cheat, u8 vipatch, u8 patchcountrystring, u32 rtrn) {
    entry_point p_entry;

    s32 ret;

    /* Open specified partition */
    ret = WDVD_OpenPartition(offset, tmd_buffer);
    if (ret < 0)
        return ret;

	char gameid[8];
	memset(gameid, 0, 8);
	memcpy(gameid, (char*)Disc_ID, 6);

	//kill the SD
    SDCard_deInit();

    /* Disconnect Wiimote */
    WPAD_Flush(0);
    WPAD_Disconnect(0);
    WPAD_Shutdown();
	
	// Load Disc IOS
	u32 disc_ios = tmd_buffer[0x18B];
	if (disc_ios != IOS_GetVersion()) {
		WDVD_ClosePartition();
		WDVD_Close();

		ret = IOS_ReloadIOS(disc_ios);
		if (ret < 0) {
			gprintf("Disc IOS %u could not be loaded! (ret = %d)", disc_ios, ret);
			return ret;
		}
		Disc_Init();
		Disc_Open();
		WDVD_OpenPartition(offset, tmd_buffer);
	}	

    /* Setup low memory */
    __Disc_SetLowMem();

    /* Run apploader */
    ret = Apploader_Run(&p_entry, cheat, videoselected, vipatch, patchcountrystring, rtrn);
    if (ret < 0)
        return ret;

    bool cheatloaded = false;

    if (cheat == 1) {
        /* OCARINA STUFF - FISHEARS*/
		cheatloaded = ocarina_do_code() == 1;
		cheatloaded = true;
    }

    /* Set an appropiate video mode */
    __Disc_SetVMode(videoselected);

    /* Set time */
    __Disc_SetTime();

	// Anti-green screen fix
	VIDEO_SetBlack(TRUE);
	VIDEO_Flush();
	VIDEO_WaitVSync();
	gprintf("\n\nUSB Loader GX is done.\n\n");

    /* Shutdown IOS subsystems */
	// fix for PeppaPig (from NeoGamma)
	extern void __exception_closeall();
	IRQ_Disable();
	__IOS_ShutdownSubsystems();
	__exception_closeall();

	appentrypoint = (u32) p_entry;

	if (cheat == 1 && cheatloaded)
	{
		__asm__(
			"lis %r3, appentrypoint@h\n"
			"ori %r3, %r3, appentrypoint@l\n"
			"lwz %r3, 0(%r3)\n"
			"mtlr %r3\n"
			"lis %r3, 0x8000\n"
			"ori %r3, %r3, 0x18A8\n"
			"mtctr %r3\n"
			"bctr\n"
		);
	}
	else
	{
		__asm__(
			"lis %r3, appentrypoint@h\n"
			"ori %r3, %r3, appentrypoint@l\n"
			"lwz %r3, 0(%r3)\n"
			"mtlr %r3\n"
			"blr\n"
		);
	}

    return 0;
}
Ejemplo n.º 5
0
//---------------------------------------------------------------------------------
int main(int argc, char **argv) {
//---------------------------------------------------------------------------------

	#ifdef DEBUG
		init_video_and_wpad();
		printf("::: Configurable USB Loader - Forwarder Universal [SD/USB] by Narolez :::\n\n");
	#endif

	// create a buffer for the elf/dol content
	void* myBuffer;
	
	// read elf/dol from given path:
	FILE* inputFile;

	// try loading from SD
	inputFile = tryOpenDolFromSD();
	
	// dol file on SD not found
	if(inputFile == NULL) 
	{
		// try loading from USB
		inputFile = tryOpenDolFromUSB();
	}

	// dol file on SD or USB not found
	if(inputFile == NULL) 
	{
		init_video_and_wpad();
		printf("\nError: Couldn't open file!\n");
		printf("Press any button to reboot Wii...\n");
		press_button_to_reboot();
	}
	
	#ifdef DEBUG	
	printf("\n[+] Loading %s to buffer ... ", filename);
	#endif
	
	int pos = ftell(inputFile);
	fseek(inputFile, 0, SEEK_END);
	int size = ftell(inputFile);
	fseek(inputFile, pos, SEEK_SET); //return to previous position

	myBuffer = malloc(size);
	fread( myBuffer, 1, size, inputFile);

	fclose(inputFile);

	#ifdef DEBUG	
	printf("OK!\n");
	#endif
	
	release_storage();
	
	#ifdef DEBUG	
	printf("\n[+] Running ... ");
	#endif

	//Check if valid elf file:
	s32 res;
	res = valid_elf_image(myBuffer);
    if(res == 1) 
	{
		//elf ok! -> Load entry point of elf file:
		void (*ep)();
		ep = (void(*)())load_elf_image(myBuffer);

		// code from geckoloader
		u32 level;
		__IOS_ShutdownSubsystems ();
		//printf("IOS_ShutdownSubsystems() done\n");
		_CPU_ISR_Disable (level);
		//printf("_CPU_ISR_Disable() done\n");
		__exception_closeall ();
		//printf("__exception_closeall() done. Jumping to ep now...\n");
		
		ep();
		_CPU_ISR_Restore (level);
	} else 
	{
		//Elf not valid, load dol:
		
		//Stuff for arguments
		struct __argv argv;
		bzero(&argv, sizeof(argv));
		argv.argvMagic = ARGV_MAGIC;
		argv.length = strlen(filename) + 2;
		argv.commandLine = malloc(argv.length);
		if (!argv.commandLine)
		{
			init_video_and_wpad();
			printf("Error creating arguments, could not allocate memory for commandLine\n");
			printf("Press any button to reboot Wii...\n");
			press_button_to_reboot();
		}
		strcpy(argv.commandLine, filename);
		argv.commandLine[argv.length - 1] = '\x00';
		argv.argc = 1;
		argv.argv = &argv.commandLine;
		argv.endARGV = argv.argv + 1;

		run_dol(myBuffer, &argv);		
	}
	
	#ifdef DEBUG	
	printf("HAVE FUN!");
	#endif
	
	return 0;
}