WiiFlow_Lite/source/channel/channel_launcher.cpp

124 lines
3.1 KiB
C++
Raw Normal View History

2012-01-21 21:57:41 +01:00
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <malloc.h>
2012-01-21 21:57:41 +01:00
#include "channel_launcher.h"
#include "gecko/gecko.h"
#include "loader/disc.h"
#include "loader/external_booter.hpp"
#include "loader/fs.h"
#include "loader/fst.h"
#include "loader/utils.h"
#include "memory/memory.h"
#include "unzip/lz77.h"
#include "types.h"
2012-01-21 21:57:41 +01:00
s32 BootChannel(u64 chantitle, u32 ios, u8 vidMode, bool vipatch, bool countryString, u8 patchVidMode, int aspectRatio)
2012-01-21 21:57:41 +01:00
{
// IOS Version Check
*Real_IOSVersion = ((ios << 16)) | 0xFFFF;
*Game_IOSVersion = ((ios << 16)) | 0xFFFF;
DCFlushRange((void*)Real_IOSVersion, 4);
DCFlushRange((void*)Game_IOSVersion, 4);
// Game ID Online Check
memset((void*)Disc_ID, 0, 4);
*Disc_ID = TITLE_LOWER(chantitle);
DCFlushRange((void*)Disc_ID, 4);
2012-01-21 21:57:41 +01:00
WiiFlow_ExternalBooter(vidMode, vipatch, countryString, patchVidMode, aspectRatio, 0, TYPE_CHANNEL);
2012-01-21 21:57:41 +01:00
return 0;
}
bool Identify_GenerateTik(signed_blob **outbuf, u32 *outlen)
{
signed_blob *buffer = (signed_blob *)memalign(32, ALIGN32(STD_SIGNED_TIK_SIZE));
if(!buffer)
return false;
2012-01-21 21:57:41 +01:00
memset(buffer, 0, STD_SIGNED_TIK_SIZE);
sig_rsa2048 *signature = (sig_rsa2048 *)buffer;
signature->type = ES_SIG_RSA2048;
tik *tik_data = (tik *)SIGNATURE_PAYLOAD(buffer);
strcpy(tik_data->issuer, "Root-CA00000001-XS00000003");
memset(tik_data->cidx_mask, 0xFF, 32);
*outbuf = buffer;
*outlen = STD_SIGNED_TIK_SIZE;
return true;
}
bool Identify(u64 titleid)
2012-01-21 21:57:41 +01:00
{
char filepath[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32);
gprintf("Reading TMD...");
2012-01-21 21:57:41 +01:00
sprintf(filepath, "/title/%08x/%08x/content/title.tmd", TITLE_UPPER(titleid), TITLE_LOWER(titleid));
u32 tmdSize;
u8 *tmdBuffer = ISFS_GetFile((u8 *) &filepath, &tmdSize, -1);
if (tmdBuffer == NULL || tmdSize == 0)
{
gprintf("Failed!\n");
2012-01-21 21:57:41 +01:00
return false;
}
gprintf("Success!\n");
2012-01-21 21:57:41 +01:00
u32 tikSize;
signed_blob *tikBuffer = NULL;
gprintf("Generating fake ticket...");
2012-01-21 21:57:41 +01:00
if(!Identify_GenerateTik(&tikBuffer,&tikSize))
{
gprintf("Failed!\n");
2012-01-21 21:57:41 +01:00
return false;
}
gprintf("Success!\n");
2012-01-21 21:57:41 +01:00
gprintf("Reading certs...");
2012-01-21 21:57:41 +01:00
sprintf(filepath, "/sys/cert.sys");
u32 certSize;
u8 *certBuffer = ISFS_GetFile((u8 *) &filepath, &certSize, -1);
if (certBuffer == NULL || certSize == 0)
{
gprintf("Failed!\n");
free(tmdBuffer);
free(tikBuffer);
2012-01-21 21:57:41 +01:00
return false;
}
gprintf("Success!\n");
gprintf("ES_Identify\n");
2012-01-21 21:57:41 +01:00
s32 ret = ES_Identify((signed_blob*)certBuffer, certSize, (signed_blob*)tmdBuffer, tmdSize, tikBuffer, tikSize, NULL);
if (ret < 0)
{
switch(ret)
{
case ES_EINVAL:
gprintf("Error! ES_Identify (ret = %d;) Data invalid!\n", ret);
break;
case ES_EALIGN:
gprintf("Error! ES_Identify (ret = %d;) Data not aligned!\n", ret);
break;
case ES_ENOTINIT:
gprintf("Error! ES_Identify (ret = %d;) ES not initialized!\n", ret);
break;
case ES_ENOMEM:
gprintf("Error! ES_Identify (ret = %d;) No memory!\n", ret);
break;
default:
gprintf("Error! ES_Identify (ret = %d)\n", ret);
break;
}
}
free(tmdBuffer);
free(tikBuffer);
free(certBuffer);
2012-01-21 21:57:41 +01:00
return ret < 0 ? false : true;
}