-Shouldn't have stripped down IOS_ReloadIOS

-Added an additional method of checking the System Menu version.  The current way works fine, but it doesn't hurt to have some backup methods.
-Fixed mismatched functions in header files.
-A little bit of code cleanup
-Touched up the cogs
This commit is contained in:
Joostinonline 2013-10-21 16:41:01 +00:00
parent bd0c05ee6b
commit 3f30c6bbf9
21 changed files with 6171 additions and 5792 deletions

71
include/SysMenuInfo.h Normal file
View File

@ -0,0 +1,71 @@
/*-------------------------------------------------------------
detect_settings.h -- detects various system settings
Copyright (C) 2008 tona
Unless other credit specified
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1.The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2.Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3.This notice may not be removed or altered from any source
distribution.
-------------------------------------------------------------*/
#ifndef __SYSMENUINFO_H__
#define __SYSMENUINFO_H__
#define SADR_LENGTH 0x1007+1
#define round_up(x,n) (-(-(x) & -(n)))
typedef struct {
u32 deviceId;
u32 hollywoodVersion;
u32 boot2version;
u16 sysMenuVer;
s32 sysMenuIOS;
bool sysMenuIOSisStub;
bool regionChangedKoreanWii;
double sysMenuNinVersion;
char sysMenuRegion;
char regionFromSerial;
s32 lang;
s32 area;
s32 game;
s32 video;
s32 eula;
s32 country;
bool reRunWithSU;
bool missingIOSwarning;
bool SMRegionMismatchWarning;
bool failSMContentRead;
u16 bcVersion;
u16 miosVersion;
u32 titleCnt;
u32 iosCount;
bool ahbprot;
} SYSSETTINGS;
extern SYSSETTINGS wiiSettings;
typedef struct {
char name[ISFS_MAXPATH + 1];
int type;
} dirent_t;
char getSystemMenuRegionFromContent();
#endif

View File

@ -7,9 +7,9 @@ extern "C"
#endif
// Prototypes
void MountSD(void);
int MountSD(void);
void UnmountSD(void);
void MountUSB(void);
int MountUSB(void);
void UnmountUSB(void);
#ifdef __cplusplus

View File

@ -7,6 +7,16 @@
#define HOLLYWOOD_VERSION (vu32*)0x80003138
#define LOADER_STUB (vu32*)0x80001800
// Turn upper and lower into a full title ID
#define TITLE_ID(x,y) (((u64)(x) << 32) | (y))
// Get upper or lower half of a title ID
#define TITLE_UPPER(x) ((u32)((x) >> 32))
// Turn upper and lower into a full title ID
#define TITLE_LOWER(x) ((u32)(x))
#define FULL_TITLE_ID(titleId) ((u32)(titleId))
#define TITLE_ID2(titleId) ((u32)((titleId) >> 32))
enum {
APP_TITLE = 0,
APP_IOS,
@ -102,15 +112,15 @@ bool IsKnownStub(u32, s32);
s32 GetTMD(u64 TicketID, signed_blob **Output, u32 *Length);
char GetBootFilename(u64 titleId);
s32 read_file_from_nand(char *filepath, u8 **buffer, u32 *filesize);
int NandStartup();
void NandShutdown();
int checkSysLoader();
int NandStartup(void);
void NandShutdown(void);
int checkSysLoader(void);
void transmitSyscheck(char ReportBuffer[200][100], int *lines);
u32 IOSPATCH_Apply();
u32 IOSPATCH_Apply(void);
s32 brute_tmd(tmd *p_tmd);
bool CheckVersionPatch(void);
bool checkISFSinRAM();
u32 es_set_ahbprot();
bool checkISFSinRAM(void);
u32 es_set_ahbprot(void);
void *allocate_memory(u32 size);
void logfile(const char *format, ...);
s32 get_miosinfo(char *str);

View File

@ -5,7 +5,7 @@
#define REVISION 20
#define PATH "sd:/apps/SysCheckHDE/"
s32 updateApp();
s32 updateApp(void);
#endif

173
source/SysMenuInfo.c Normal file
View File

@ -0,0 +1,173 @@
/*-------------------------------------------------------------
detect_settings.c -- detects various system settings
Copyright (C) 2008 tona
Unless other credit specified
Changes by JoostinOnline
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1.The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2.Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3.This notice may not be removed or altered from any source
distribution.
-------------------------------------------------------------*/
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gccore.h>
#include <unistd.h>
#include "SysMenuInfo.h"
inline void *AllocateMemory(u32 size) {
return memalign(32, round_up(size, 32));
}
char sanitizeRegion( char region ) {
switch (region){
case 'U':
case 'E':
case 'J':
case 'K':
return region;
break;
default:
return 'X';
break;
}
}
int ctoi(char c) {
switch(c){
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
default:
case '0': return 0;
}
}
s32 __FileCmp(const void *a, const void *b)
{
dirent_t *hdr1 = (dirent_t *)a;
dirent_t *hdr2 = (dirent_t *)b;
if (hdr1->type == hdr2->type)
return strcmp(hdr1->name, hdr2->name);
else
return 0;
}
s32 getdir(char *path, dirent_t **ent, u32 *cnt)
{
u32 num = 0;
int i, j, k;
if(ISFS_ReadDir(path, NULL, &num) != ISFS_OK) return -1;
char *nbuf = (char *)AllocateMemory((ISFS_MAXPATH + 1) * num);
char ebuf[ISFS_MAXPATH + 1];
if(nbuf == NULL) return -2;
if(ISFS_ReadDir(path, nbuf, &num) != ISFS_OK) return -3;
*cnt = num;
*ent = AllocateMemory(sizeof(dirent_t) * num);
for(i = 0, k = 0; i < num; i++)
{
for(j = 0; nbuf[k] != 0; j++, k++)
ebuf[j] = nbuf[k];
ebuf[j] = 0;
k++;
strcpy((*ent)[i].name, ebuf);
}
qsort(*ent, *cnt, sizeof(dirent_t), __FileCmp);
free(nbuf);
return 0;
}
char getSystemMenuRegionFromContent() {
s32 cfd;
s32 ret;
u32 num;
dirent_t *list;
char contentpath[ISFS_MAXPATH];
char path[ISFS_MAXPATH];
int i, j;
u32 cnt = 0;
u8 *buffer;
u8 match[] = "C:\\Revolution", match2[] = "Final";
char region = 'X';
ISFS_Initialize();
sprintf(contentpath, "/title/%08x/%08x/content", 1, 2);
if (getdir(contentpath, &list, &num) < 0) return region;
fstats filestats;
for(cnt=0; region == 'X' && cnt < num; cnt++) {
sprintf(path, "/title/%08x/%08x/content/%s", 1, 2, list[cnt].name);
cfd = ISFS_Open(path, ISFS_OPEN_READ);
if (cfd < 0) continue;
if (ISFS_GetFileStats(cfd, &filestats) < 0) continue;
buffer=(u8*)AllocateMemory(filestats.file_length);
ret = ISFS_Read(cfd, buffer, filestats.file_length);
ISFS_Close(cfd);
if (ret < 0) continue;
for(i = 0; i < filestats.file_length - 49; i += 1 ) {
if(memcmp((buffer+i), match, 13) == 0) {
for(j=0; j<30; j++){
if( memcmp((buffer+i+j+24), match2, 5) == 0) {
region = buffer[i+j+30];
break;
}
}
//if(sysVersion == 0.0) {
// int first = ctoi(buffer[i+24]);
// int second = ctoi(buffer[i+26]);
// sysVersion = first + (0.1 * second);
//}
break;
}
}
free(buffer);
}
free(list);
ISFS_Deinitialize();
return sanitizeRegion(region);
}

View File

@ -4,6 +4,7 @@
#include <sdcard/wiisd_io.h>
#include <ogc/usbstorage.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <ogcsys.h>
@ -171,7 +172,7 @@ int MountUSB(void)
return -1;
/* Mount device */
ret = fatMountSimple("usb", &__io_usbstorage);
ret = fatMountSimple("usb", &__io_usbstorage);
if (!ret)
return -2;

View File

@ -1,13 +1,13 @@
#include <gccore.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
/* init-globals */
bool geckoinit = false;
bool textVideoInit = false;
#ifndef NO_DEBUG
#include <stdarg.h>
//using the gprintf from crediar because it is smaller than mine
void gprintf( const char *str, ... )

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

File diff suppressed because it is too large Load Diff

Binary file not shown.

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

90
source/iosreload.c Normal file
View File

@ -0,0 +1,90 @@
/*-------------------------------------------------------------
iosreload.c -- IOS control
Copyright (C) 2008
Michael Wiedenbauer (shagkur)
Dave Murphy (WinterMute)
Hector Martin (marcan)
JoostinOnline
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you
must not claim that you wrote the original software. If you use
this software in a product, an acknowledgment in the product
documentation would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
-------------------------------------------------------------*/
// This is just stripped down code from ios.c.
// I didn't do any extra work, I'm just making it faster for this one situation
#include <stdio.h>
#include <malloc.h>
#include <ogc/machine/asm.h>
#include <ogc/machine/processor.h>
#include <ogc/cache.h>
#include <ogc/ipc.h>
#include <ogc/stm.h>
#include <ogc/es.h>
#include <ogc/ios.h>
#include <ogc/irq.h>
#define MAX_IPC_RETRIES 400
extern void udelay(int us);
void ReloadIOS(int version) {
__STM_Close();
u32 numviews;
u64 titleID = 0x100000000LL;
raw_irq_handler_t irq_handler;
u32 counter;
STACK_ALIGN(tikview,views,4,32);
titleID |= version;
ES_GetNumTicketViews(titleID, &numviews);
ES_GetTicketViews(titleID, views, numviews);
write32(0x80003140, 0);
ES_LaunchTitleBackground(titleID, &views[0]);
__ES_Reset();
// Mask IPC IRQ while we're busy reloading
__MaskIrq(IRQ_PI_ACR);
irq_handler = IRQ_Free(IRQ_PI_ACR);
while ((read32(0x80003140) >> 16) == 0)
udelay(1000);
for (counter = 0; !(read32(0x0d000004) & 2); counter++) {
udelay(1000);
if (counter >= MAX_IPC_RETRIES)
break;
}
IRQ_Request(IRQ_PI_ACR, irq_handler, NULL);
__UnmaskIrq(IRQ_PI_ACR);
__IPC_Reinitialize();
__ES_Init();
__STM_Init();
}

View File

@ -15,6 +15,7 @@
#include "sys.h"
#include "video.h"
#include "SysMenuInfo.h"
#include "ticket_dat.h"
#include "tmd_dat.h"
@ -29,18 +30,6 @@
#include "fatMounter.h"
// Turn upper and lower into a full title ID
#define TITLE_ID(x,y) (((u64)(x) << 32) | (y))
// Get upper or lower half of a title ID
#define TITLE_UPPER(x) ((u32)((x) >> 32))
// Turn upper and lower into a full title ID
#define TITLE_LOWER(x) ((u32)(x))
#define FULL_TITLE_ID(titleId) ((u32)(titleId))
#define TITLE_ID2(titleId) ((u32)((titleId) >> 32))
// Constants
#define BASE_PATH "/tmp"
@ -163,7 +152,7 @@ const u8 es_set_ahbprot_pattern[] = { 0x68, 0x5B, 0x22, 0xEC, 0x00, 0x52, 0x18,
const u8 es_set_ahbprot_patch[] = { 0x01 };
u32 IOSPATCH_Apply() {
u32 IOSPATCH_Apply(void) {
u32 count = 0;
s32 ret = 0;
@ -191,12 +180,12 @@ u32 IOSPATCH_Apply() {
return count;
}
u32 es_set_ahbprot() {
u32 es_set_ahbprot(void) {
disable_memory_protection();
return apply_patch("es_set_ahbprot", es_set_ahbprot_pattern, sizeof(es_set_ahbprot_pattern), es_set_ahbprot_patch, sizeof(es_set_ahbprot_patch), 25);
}
bool checkISFSinRAM() {
bool checkISFSinRAM(void) {
disable_memory_protection();
bool ret = true;
u8 *ptr_start = (u8*)*((u32*)0x80003134), *ptr_end = (u8*)0x94000000;
@ -209,10 +198,10 @@ bool checkISFSinRAM() {
return ret;
}
int NandStartup()
int NandStartup(void)
{
if (NandInitialized)
return 0;
return 1;
int ret = ISFS_Initialize();
@ -223,7 +212,7 @@ int NandStartup()
return ret;
}
void NandShutdown()
void NandShutdown(void)
{
if (!NandInitialized)
return;
@ -463,7 +452,7 @@ float GetSysMenuNintendoVersion(u32 sysVersion)
case 514:
case 518:
case 544:
//case 545:
case 545:
case 546:
ninVersion = 4.3f;
break;
@ -489,7 +478,7 @@ char GetSysMenuRegion(u32 sysVersion) {
case 54449: // mauifrog 4.1U
case 481: //4.2U
case 513: //4.3U
case 545:
//case 545:
SysMenuRegion = 'U';
break;
case 130: //2.0E
@ -532,10 +521,11 @@ char GetSysMenuRegion(u32 sysVersion) {
SysMenuRegion = 'K';
break;
default:
SysMenuRegion = 'X';
//SysMenuRegion = 'X';
SysMenuRegion = getSystemMenuRegionFromContent();
break;
}
return SysMenuRegion;
return SysMenuRegion;
}
void zero_sig(signed_blob *sig)
@ -619,9 +609,7 @@ bool CheckFakeSignature(void)
int ret = ES_AddTicket((signed_blob *)ticket_dat, ticket_dat_size, (signed_blob *)certs, sizeof(certs), 0, 0);
if (ret > -1) RemoveBogusTicket();
if (ret > -1 || ret == -1028) return true;
return false;
return (ret > -1 || ret == -1028);
}
// Check fake signatures (aka Trucha Bug)
@ -659,12 +647,7 @@ bool CheckESIdentify(void)
{
int ret = ES_Identify((signed_blob *)certs, sizeof(certs), (signed_blob *)tmd_dat, tmd_dat_size, (signed_blob *)ticket_dat, ticket_dat_size, NULL);
if (ret == -2011) ret = 0;
if (ret < 0)
return false;
else
return true;
return ((ret >= 0) || (ret == -2011));
}
@ -672,25 +655,15 @@ bool CheckESIdentify(void)
bool CheckFlashAccess(void)
{
int ret = IOS_Open("/dev/flash", 1);
if (ret >= 0) IOS_Close(ret);
if (ret < 0)
return false;
else
return true;
return (ret >= 0);
}
bool CheckMload(void)
{
int ret = IOS_Open("/dev/mload", 0);
if (ret >= 0) IOS_Close(ret);
if (ret < 0)
return false;
else
return true;
return (ret >= 0);
}
@ -698,13 +671,8 @@ bool CheckMload(void)
bool CheckNANDAccess(void)
{
int ret = IOS_Open("/ticket/00000001/00000002.tik", 1);
if (ret >= 0) IOS_Close(ret);
if (ret < 0)
return false;
else
return true;
return (ret >= 0);
}
@ -712,13 +680,8 @@ bool CheckNANDAccess(void)
bool CheckBoot2Access(void)
{
int ret = IOS_Open("/dev/boot2", 1);
if (ret >= 0) IOS_Close(ret);
if (ret < 0)
return false;
else
return true;
return (ret >= 0);
}
@ -758,11 +721,7 @@ bool CheckUSB2(u32 titleID)
if (ret < 0) ret = IOS_Open("/dev/usb/ehc", 1);
if (ret >= 0) IOS_Close(ret);
if (ret < 0)
return false;
else
return true;
return (ret >= 0);
}
@ -804,7 +763,7 @@ bool IsKnownStub(u32 noIOS, s32 noRevision)
return false;
}
int checkSysLoader() {
int checkSysLoader(void) {
char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(0x20);
static u64 titleId ATTRIBUTE_ALIGN(32) = 0x0000000100000002LL;
int ret = 0;

View File

@ -27,7 +27,7 @@
#include "wiibasics.h"
#include "tmdIdentification.h"
#include "gecko.h"
#include "update.h"
#include "update.h"
// Filename
#define REPORT "sd:/sysCheck.csv"
@ -37,18 +37,19 @@
#define SECTOR_SIZE (0x4000)
extern bool geckoinit;
extern void ReloadIOS(int version);
char miosInfo[128] = {0};
extern void __exception_setreload(int t);
// Stripped down version of IOS_ReloadIOS, run inline
inline void ReloadIOS(int version) {
__IOS_ShutdownSubsystems();
__ES_Init();
__IOS_LaunchNewIOS(version);
__IOS_InitializeSubsystems();
}
//inline void ReloadIOS(int version) {
// //__IOS_ShutdownSubsystems();
// __ES_Init();
// __IOS_LaunchNewIOS(version);
// __IOS_InitializeSubsystems();
// //WII_LaunchTitle(TITLE_ID(0x00000001,version));
//}
int get_title_ios(u64 title) {
s32 ret, fd;
@ -239,6 +240,7 @@ int main(int argc, char **argv)
}
}
}
if (HAVE_AHBPROT && !forceNoAHBPROT)
IOSPATCH_Apply();
@ -608,14 +610,11 @@ int main(int argc, char **argv)
systemmenu.hasInfo = true;
//strcpy(systemmenu.info, sysInfo->name);
sprintf(systemmenu.info, "%s%s", sysInfo->name, sysInfo->versionstring);
if (buffer != 0)
{
free(buffer);
}
if (buffer != NULL) free(buffer);
} else {
systemmenu.realRevision = 0;
systemmenu.hasInfo = false;
strcpy(systemmenu.info, "NICHTS");
strcpy(systemmenu.info, "NONE");
}
NandShutdown();
@ -757,8 +756,8 @@ int main(int argc, char **argv)
// Reload IOS
gprintf("// IOS_ReloadIOS(%d)\n", ios[i].titleID);
logfile("// IOS_ReloadIOS(%d)\r\n", ios[i].titleID);
//IOS_ReloadIOS(ios[i].titleID);
ReloadIOS(ios[i].titleID);
IOS_ReloadIOS(ios[i].titleID);
//ReloadIOS(ios[i].titleID);
// Test fake signature
gprintf("// Test fake signature\n");
@ -824,7 +823,7 @@ int main(int argc, char **argv)
// Reload the running IOS
ReloadIOS(runningIOS);
IOS_ReloadIOS(runningIOS);
sprintf(MSG_Buffer, MSG_ReloadIOS, runningIOS, runningIOSRevision);
printLoading(MSG_Buffer);
//usleep(250000);

View File

@ -56,7 +56,7 @@ s32 downloadSyscheckFile(const char* fileName) {
return 0;
}
s32 updateApp() {
s32 updateApp(void) {
int ret = 0;
ret = net_init();