void ResetWakeup_Timestamp() { s32 fd; unsigned char *miscbuf; printf("Resetting wakeup time...\n"); fd = ISFS_Open("/shared2/wc24/misc.bin", ISFS_OPEN_RW); if(fd<0) { printf("Failed to open misc.bin: %d\n", fd); } else { miscbuf = (unsigned char*)memalign(32, 0x400); memset(miscbuf, 0, 0x400); ISFS_Read(fd, miscbuf, 0x400); ISFS_Seek(fd, 0, SEEK_SET); time_t curtime = (time_t)*((u32*)&miscbuf[0x3c]); struct tm *misc_time = gmtime(&curtime); if(curtime)printf("Wakeup timestamp time: %s\n", asctime(misc_time)); if(curtime==0)printf("Current wakeup timestamp time is zero.\n"); *((u32*)&miscbuf[0x38]) = 0; *((u32*)&miscbuf[0x3c]) = 0; ISFS_Write(fd, miscbuf, 0x400); free(miscbuf); ISFS_Close(fd); } }
int fileBrowser_WiiFS_writeFile(fileBrowser_file* file, void* buffer, unsigned int length){ // Make sure everything is aligned (address and length) int isUnaligned = ((int)buffer)%32 | length%32; int alignedLen = (length+31)&0xffffffe0; char* alignedBuf; if(isUnaligned){ alignedBuf = memalign(32, alignedLen); memcpy(alignedBuf, buffer, length); } else alignedBuf = buffer; // Make sure the filename is 8.3 and open the short filename shrinkFilename( &file->name ); char* name = getAlignedName(&file->name); int f = ISFS_Open( name, 2 ); if(f < 0){ // Create rw file: rwrwr- if((f = ISFS_CreateFile( name, 0, 1|2, 1|2, 1 )) < 0) return FILE_BROWSER_ERROR; else f = ISFS_Open( name, 2 ); } // Do the actual write, from the aligned buffer if need be ISFS_Seek(f, file->offset, 0); int bytes_read = ISFS_Write(f, alignedBuf, alignedLen); if(bytes_read > 0) file->offset += bytes_read; // Clean up if(isUnaligned) free(alignedBuf); ISFS_Close(f); return bytes_read; }
void RestoreSneekFolder (void) { s32 fd; int ret; char path[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); char pathBak[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); Debug ("RestoreSneekFolder [begin]"); ISFS_Initialize (); sprintf (path, "/sneek/nandpath.bin"); ret = ISFS_Delete (path); Debug ("RestoreSneekFolder: delete '%s' = %d", path, ret); sprintf (path, "/sneek/nandcfg.pl"); ret = ISFS_Delete (path); Debug ("RestoreSneekFolder: delete '%s' = %d", path, ret); ret = sprintf (path, "/sneek/nandcfg.ch"); ISFS_Delete (path); Debug ("RestoreSneekFolder: delete '%s' = %d", path, ret); sprintf (path, "/title/00000001/00000002/data/loader.ini"); sprintf (pathBak, "/title/00000001/00000002/data/loader.bak"); fd = ISFS_Open(pathBak, ISFS_OPEN_READ); if (fd > 0) { ISFS_Close(fd); ret = ISFS_Delete (path); Debug ("RestoreSneekFolder: delete '%s' = %d", path, ret); ret = ISFS_Rename (pathBak, path); Debug ("RestoreSneekFolder: rename '%s'->'%s' = %d", pathBak, path, ret); } sprintf (path, "/sneek/nandcfg.bin"); sprintf (pathBak, "/sneek/nandcfg.bak"); fd = ISFS_Open(pathBak, ISFS_OPEN_READ); if (fd > 0) { ISFS_Close(fd); ret = ISFS_Delete (path); Debug ("RestoreSneekFolder: delete '%s' = %d", path, ret); ret = ISFS_Rename (pathBak, path); Debug ("RestoreSneekFolder: rename '%s'->'%s' = %d", pathBak, path, ret); } ISFS_Deinitialize (); Debug ("RestoreSneekFolder [end]"); }
bool LoadPostloaderFromISFS (void) { char path[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); ISFS_Initialize(); strcpy (path, "/apps/postLoader/boot.dol"); s32 fd = ISFS_Open (path, ISFS_OPEN_READ); if (fd < 0) goto fail; s32 filesize = ISFS_Seek(fd, 0, 2); if (filesize == 0) goto fail; ISFS_Seek (fd, 0, 0); // exeBuffer is already 32bit aligned... should work fine s32 readed = ISFS_Read (fd, exeBuffer, filesize); ISFS_Close (fd); if (readed != filesize) goto fail; return TRUE; fail: ISFS_Deinitialize (); return FALSE; }
bool readch (s_channelConfig *cc) { s32 ret; char path[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); Debug ("neek_PLNandInfo [begin]"); ISFS_Initialize (); sprintf (path, "/sneek/nandcfg.ch"); s32 fd; fd = ISFS_Open( path, ISFS_OPEN_READ); ret = -1; if (fd > 0) { ret = ISFS_Read(fd, cc, sizeof(s_channelConfig)); ISFS_Close(fd); } ISFS_Deinitialize (); if (ret >= 0) return true; return false; }
s8 VerifyNandBootInfo ( void ) { // path : /shared2/sys/NANDBOOTINFO NANDBootInfo *Boot_Info = (NANDBootInfo *)mem_align( 32, sizeof(NANDBootInfo) ); memset( Boot_Info, 0, sizeof(NANDBootInfo) ); s32 fd = ISFS_Open("/shared2/sys/NANDBOOTINFO", 1 ); if(fd < 0) { mem_free( Boot_Info ); return -1; } s32 ret = ISFS_Read(fd, Boot_Info, sizeof(NANDBootInfo)); if(ret != sizeof(NANDBootInfo)) { ISFS_Close(fd); mem_free( Boot_Info ); return -2 ; } ISFS_Close(fd); u8 r = Boot_Info->titletype; mem_free( Boot_Info ); if (r == 8) { SetBootState(4,132,0,0); return 1; } else return 0; }
bool NandTitle::Exists(u64 tid) { char app[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); tmd* titleTmd = GetTMD(tid); if (!titleTmd) return false; u16 i; bool ok = false; for (i = 0; i < titleTmd->num_contents; i++) { if (!titleTmd->contents[i].index) { ok = true; break; } } if (!ok) return false; snprintf(app, sizeof(app), "/title/%08x/%08x/content/%08x.app", TITLE_UPPER( tid ), TITLE_LOWER( tid ), titleTmd->contents[i].cid); s32 fd = ISFS_Open(app, ISFS_OPEN_READ); if (fd >= 0) ISFS_Close(fd); //gprintf(" fd: %d\n", fd ); return fd >= 0 || fd == -102; //102 means it exists, but we dont have permission to open it }
int fileBrowser_WiiFS_readFile(fileBrowser_file* file, void* buffer, unsigned int length){ // Make sure everything is aligned (address and length) int isUnaligned = ((int)buffer)%32 | length%32; int alignedLen = (length+31)&0xffffffe0; char* alignedBuf; if(isUnaligned) alignedBuf = memalign(32, alignedLen); else alignedBuf = buffer; // Make sure the filename is 8.3 and open the short filename shrinkFilename( &file->name ); int f = ISFS_Open( getAlignedName(&file->name), 1 ); if(f < 0) return FILE_BROWSER_ERROR; // Do the actual read, into the aligned buffer if we need to ISFS_Seek(f, file->offset, 0); int bytes_read = ISFS_Read(f, alignedBuf, alignedLen); if(bytes_read > 0) file->offset += bytes_read; // If it was unaligned, you have to copy it and clean up if(isUnaligned){ memcpy(buffer, alignedBuf, length); free(alignedBuf); } ISFS_Close(f); return bytes_read; }
int fileBrowser_WiiFS_readDir(fileBrowser_file* file, fileBrowser_file** dir){ static char dirents[32*(8+1+3+1)] __attribute__((aligned(32))); unsigned int numDirents = 32; // Call the corresponding ISFS function char* name = getAlignedName(&file->name); int ret = ISFS_ReadDir(name, dirents, &numDirents); // If it was not successful, just return the error if(ret < 0) return ret; // Convert the ISFS data to fileBrowser_files *dir = malloc( numDirents * sizeof(fileBrowser_file) ); int i; char* dirent = &dirents[0]; for(i=0; i<numDirents; ++i){ sprintf((*dir)[i].name, "%s/%s", name, dirent); // Collect info about this file int fd = ISFS_Open( getAlignedName((*dir)[i].name), 1 ); if(fd >= 0){ fstats* stats = memalign( 32, sizeof(fstats) ); ISFS_GetFileStats(fd, stats); (*dir)[i].attr = 0; (*dir)[i].size = stats->file_length; free(stats); ISFS_Close(fd); } else { (*dir)[i].attr = FILE_BROWSER_ATTR_DIR; (*dir)[i].size = 0; } (*dir)[i].offset = 0; while(*(dirent++)); // Advance to the next dirent } return numDirents; }
s8 RemovePriiloader ( void ) { s32 fd = 0; Nand_Permissions SysPerm; memset(&SysPerm,0,sizeof(Nand_Permissions)); SysPerm.otherperm = 3; SysPerm.groupperm = 3; SysPerm.ownerperm = 3; printf("Restoring System menu app..."); s32 ret = nand_copy(copy_app,original_app,SysPerm); if (ret < 0) { if(ret == -80) { //checksum issues printf("\x1b[%u;%dm", 33, 1); printf("\nWARNING!!\n Installer could not calculate the Checksum when coping the System menu app\n"); printf("back! the app however was copied...\n"); printf("Do you want to Continue ?\n"); printf("A = Yes B = No\n "); printf("\x1b[%u;%dm", 37, 1); if(!UserYesNoStop()) { printf("reverting changes...\n"); ISFS_Close(fd); ISFS_CreateFile(original_app,0,3,3,3); fd = ISFS_Open(original_app,ISFS_OPEN_RW); ISFS_Write(fd,priiloader_app,priiloader_app_size); ISFS_Close(fd); abort("System Menu Copying Failure"); } } else { ISFS_CreateFile(original_app,0,3,3,3); fd = ISFS_Open(original_app,ISFS_OPEN_RW); ISFS_Write(fd,priiloader_app,priiloader_app_size); ISFS_Close(fd); abort("\nUnable to restore the system menu! (ret = %d)",ret); } } ret = ISFS_Delete(copy_app); printf("Done!\n"); return 1; }
s32 read_file(char *filepath, u8 **buffer, u32 *filesize){ s32 Fd; int ret; if(buffer == NULL){ printf("NULL Pointer\n"); return -1; } Fd = ISFS_Open(filepath, ISFS_OPEN_READ); if (Fd < 0){ //printf("\n * ISFS_Open %s failed %d", filepath, Fd); //Pad_WaitButtons(); return Fd; } fstats *status; status = allocate_memory(sizeof(fstats)); if (status == NULL){ printf("Out of memory for status\n"); return -1; } ret = ISFS_GetFileStats(Fd, status); if (ret < 0){ printf("ISFS_GetFileStats failed %d\n", ret); ISFS_Close(Fd); free(status); return -1; } *buffer = allocate_memory(status->file_length); if (*buffer == NULL){ printf("Out of memory for buffer\n"); ISFS_Close(Fd); free(status); return -1; } ret = ISFS_Read(Fd, *buffer, status->file_length); if (ret < 0){ printf("ISFS_Read failed %d\n", ret); ISFS_Close(Fd); free(status); free(*buffer); return ret; } ISFS_Close(Fd); *filesize = status->file_length; free(status); return 0; }
int NandTitle::LoadFileFromNand(const char *filepath, u8 **outbuffer, u32 *outfilesize) { if(!filepath) return -1; fstats *stats = (fstats *) memalign(32, ALIGN32(sizeof(fstats))); if(!stats) return IPC_ENOMEM; int fd = ISFS_Open(filepath, ISFS_OPEN_READ); if(fd < 0) { free(stats); return fd; } int ret = ISFS_GetFileStats(fd, stats); if (ret < 0) { free(stats); ISFS_Close(fd); return ret; } u32 filesize = stats->file_length; free(stats); u8 *buffer = (u8 *) memalign(32, ALIGN32(filesize)); if(!buffer) { ISFS_Close(fd); return IPC_ENOMEM; } ret = ISFS_Read(fd, buffer, filesize); ISFS_Close(fd); if (ret < 0) { free(buffer); return ret; } *outbuffer = buffer; *outfilesize = filesize; return 0; }
bool IsPriiloaderCnt(u16 cid) { char priiloader_cnt[ISFS_MAXPATH]; snprintf(priiloader_cnt, MAX_CHARACTERS(priiloader_cnt), "/title/00000001/00000002/content/%08lx.app", (u32)((1 << 28) | cid)); s32 cfd = ISFS_Open(priiloader_cnt, ISFS_OPEN_READ); if (cfd >= 0) { ISFS_Close(cfd); printf("Priiloader content detected!\n"); logfile("Priiloader content detected! Original System Menu content file: %08lx.app.\r\n", (u32)((1 << 28) | cid)); return true; } return false; }
void NandSave::WriteFile(const char *file_name, u8 *content, u32 size) { memset(&ISFS_Path, 0, ISFS_MAXPATH); if(file_name == NULL || content == NULL || size == 0) return; strcpy(ISFS_Path, file_name); ISFS_CreateFile(ISFS_Path, 0, 3, 3, 3); fd = ISFS_Open(ISFS_Path, ISFS_OPEN_WRITE); if(fd < 0) return; ret = ISFS_Write(fd, content, size); ISFS_Close(fd); if(ret < 0) ISFS_Delete(ISFS_Path); }
s32 SetBootState( u8 type , u8 flags , u8 returnto , u8 discstate ) { StateFlags *sf = (StateFlags *)mem_align( 32, sizeof(StateFlags) ); memset( sf, 0, sizeof(StateFlags) ); s32 fd = ISFS_Open("/title/00000001/00000002/data/state.dat", 1|2 ); if(fd < 0) { mem_free( sf ); ISFS_Close(fd); return -1; } s32 ret = ISFS_Read(fd, sf, sizeof(StateFlags)); if(ret != sizeof(StateFlags)) { mem_free( sf ); ISFS_Close(fd); return -2 ; } sf->type = type; sf->returnto = returnto; sf->flags = flags; sf->discstate = discstate; sf->checksum= __CalcChecksum((u32*)sf, sizeof(StateFlags)); if(ISFS_Seek( fd, 0, 0 )<0) { mem_free( sf ); ISFS_Close(fd); return -3; } if(ISFS_Write(fd, sf, sizeof(StateFlags))!=sizeof(StateFlags)) { mem_free( sf ); ISFS_Close(fd); return -4; } ISFS_Close(fd); mem_free( sf ); return 1; }
s8 HaveNandPermissions( void ) { gprintf("testing permissions..."); s32 temp = ISFS_Open("/title/00000001/00000002/content/title.tmd",ISFS_OPEN_RW); if ( temp < 0 ) { gprintf("no permissions.error %d\n",temp); return false; } else { ISFS_Close(temp); gprintf("and bingo was his name-O\n"); return true; } }
static s32 __Config_Delete(const char *filename) { s32 ret; /* Open ISFS */ ret = ISFS_Open(); if (ret < 0) return ret; /* Delete file */ ret = ISFS_Delete(filename); /* Close ISFS */ ISFS_Close(); return ret; }
bool PriiloaderCheck(u64 id) { if (TITLE_UPPER(id) == 1 && TITLE_LOWER(id) == 2) { char pl_tmd[ISFS_MAXPATH]; snprintf(pl_tmd, MAX_CHARACTERS(pl_tmd), "/title/00000001/00000002/content/title_or.tmd"); s32 cfd = ISFS_Open(pl_tmd, ISFS_OPEN_READ); if (cfd >= 0) { ISFS_Close(cfd); printf("Priiloader detected in System Menu!\n"); logfile("Priiloader detected in System Menu!\r\n"); return true; } } return false; }
void RestoreSM (int nidx) { bool find = FALSE; char path[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); char pathBack[ISFS_MAXPATH] ATTRIBUTE_ALIGN(32); char *sm[] = {"00000088","00000085","0000008b","0000008e","00000098","00000095","0000009b","0000009e"}; s32 smsize; bool issm = FALSE; ISFS_Initialize(); int i; s32 fd; for (i = 0; i < sizeof(sm) / sizeof(char*); i++) { sprintf (path, "%s/title/00000001/00000002/content/%s.app", nandConfig->NandInfo[nidx], sm[i]); sprintf (pathBack, "%s/title/00000001/00000002/content/%s.bak", nandConfig->NandInfo[nidx], sm[i]); fd = ISFS_Open (path, ISFS_OPEN_READ); Debug ("ReplaceNandSystemMenu: checking %s (%d)", sm[i], fd); if (fd < 0) continue; smsize = ISFS_Seek(fd, 0, 2); Debug ("ReplaceNandSystemMenu: sm size %d", smsize); if (smsize > 1000000) // E' piu' grande di 1MB... e' il sistem menu issm = TRUE; ISFS_Close (fd); find = TRUE; break; } if (find && !issm) { // Restore filesistem ISFS_Delete (path); ISFS_Rename (pathBack, path); } ISFS_Deinitialize (); }
bool CheckForPriiloader( void ) { bool ret = false; s32 fd = 0; printf("Checking for Priiloader...\n"); gprintf("checking for SystemMenu Dol\n"); fd = ISFS_Open(copy_app,ISFS_OPEN_RW); if (fd < 0) { printf("Priiloader not found : Installing Priiloader...\n\n"); ret = false; } else { ISFS_Close(fd); printf("Priiloader installation found : Updating Priiloader...\n\n"); ret = true; } return ret; }
s32 CheckBootState( void ) { StateFlags *sf = (StateFlags *)mem_align( 32, sizeof(StateFlags) ); memset( sf, 0, sizeof(StateFlags) ); s32 fd = ISFS_Open("/title/00000001/00000002/data/state.dat", 1); if(fd < 0) { mem_free(sf); return 0; } s32 ret = ISFS_Read(fd, sf, sizeof(StateFlags)); ISFS_Close(fd); if(ret != sizeof(StateFlags)) { mem_free(sf); return 0; } u8 r = sf->type; mem_free( sf ); return r; }
StateFlags GetStateFlags( void ) { StateFlags *sf = (StateFlags *)mem_align( 32, sizeof(StateFlags) ); StateFlags State; memset( sf, 0, sizeof(StateFlags) ); s32 fd = ISFS_Open("/title/00000001/00000002/data/state.dat", 1); if(fd < 0) { mem_free(sf); return State; } s32 ret = ISFS_Read(fd, sf, sizeof(StateFlags)); ISFS_Close(fd); if(ret != sizeof(StateFlags)) { mem_free(sf); return State; } memcpy((StateFlags*)&State,sf,sizeof(StateFlags)); mem_free( sf ); return State; }
u8 *ISFS_GetFile(u8 *path, u32 *size, s32 length) { *size = 0; s32 fd = ISFS_Open((const char *) path, ISFS_OPEN_READ); u8 *buf = NULL; static fstats stats ATTRIBUTE_ALIGN(32); if(fd >= 0) { if(ISFS_GetFileStats(fd, &stats) >= 0) { if(length <= 0) length = stats.file_length; if(length > 0) buf = (u8 *)MEM2_memalign(32, length); if(buf) { *size = stats.file_length; if(ISFS_Read(fd, (char*)buf, length) != length) { *size = 0; MEM2_free(buf); } } } ISFS_Close(fd); } if(*size > 0) { DCFlushRange(buf, *size); ICInvalidateRange(buf, *size); } return buf; }
s32 SetNandBootInfo(void) { static NANDBootInfo BootInfo ATTRIBUTE_ALIGN(32); memset(&BootInfo,0,sizeof(NANDBootInfo)); BootInfo.apptype = 0x80; BootInfo.titletype = 2; if(ES_GetTitleID(&BootInfo.launcher) < 0) BootInfo.launcher = 0x0000000100000002LL; BootInfo.checksum = __CalcChecksum((u32*)&BootInfo,sizeof(NANDBootInfo)); s32 fd = ISFS_Open("/shared2/sys/NANDBOOTINFO", ISFS_OPEN_RW ); if(fd < 0) { return fd; } s32 ret = ISFS_Write(fd, &BootInfo, sizeof(NANDBootInfo)); if(ret < 0) { ISFS_Close(fd); gprintf("SetNandBootInfo : ISFS_Write returned %d\n",ret); return -2; } ISFS_Close(fd); return 1; }
static bool read_directory(DIR_ENTRY *parent) { if(!parent || !parent->abspath) return false; u32 fileCount; if(parent->size != 0 && is_dir(parent)) { fileCount = parent->size; } else { s32 ret = ISFS_ReadDir(parent->abspath, NULL, &fileCount); if (ret != ISFS_OK) { return false; } } parent->flags = FLAG_DIR; parent->size = fileCount; parent->childCount = 0; if(strcmp(parent->abspath, "/") != 0) { DIR_ENTRY *child = add_child_entry(parent, "."); if (!child) return false; child->flags = FLAG_DIR; child->size = 0; child = add_child_entry(parent, ".."); if (!child) return false; child->flags = FLAG_DIR; child->size = 0; } if (fileCount > 0) { char *buffer = (char *) memalign(32, ISFS_MAXPATHLEN * fileCount); if(!buffer) return false; s32 ret = ISFS_ReadDir(parent->abspath, buffer, &fileCount); if (ret != ISFS_OK) { free(buffer); return false; } u32 fileNum; char *name = buffer; for (fileNum = 0; fileNum < fileCount; fileNum++) { DIR_ENTRY *child = add_child_entry(parent, name); if (!child) { free(buffer); return false; } name += strlen(name) + 1; u32 childFileCount; ret = ISFS_ReadDir(child->abspath, NULL, &childFileCount); if (ret == ISFS_OK) { child->flags = FLAG_DIR; child->size = childFileCount; } else { s32 fd = ISFS_Open(child->abspath, ISFS_OPEN_READ); if (fd >= 0) { if (ISFS_GetFileStats(fd, &filest) == ISFS_OK) child->size = filest.file_length; ISFS_Close(fd); } } } free(buffer); } return true; }
bool U8NandArchive::SetFile( const char* nandPath ) { if(fst) free(fst); if(name_table) free(name_table); CloseFile(); // open file if( (fd = ISFS_Open( nandPath, ISFS_OPEN_READ ) ) < 0 ) { gprintf( "U8NandArchive: ISFS_Open( \"%s\" ) failed\n", nandPath ); return false; } // get file size fstats stats __attribute__(( aligned( 32 ) )); int ret = ISFS_GetFileStats( fd, &stats ); if( ret < 0 ) { CloseFile(); gprintf( "U8NandArchive: ISFS_GetFileStats( \"%s\" ) failed\n", nandPath ); return false; } // buffer for reading the header and stuff u8* buffer = (u8*)memalign( 32, 0x800 ); if( !buffer ) { CloseFile(); gprintf( "U8NandArchive: enomem\n" ); return false; } // read a chunk big enough that it should contain the U8 header if there is going to be one if( (ret = ISFS_Read( fd, buffer, 0x800 )) != 0x800 ) { free( buffer ); CloseFile(); gprintf( "U8NandArchive: ISFS_Read( 0x800 ) = %i\n", ret ); return false; } // find the start of the U8 data U8Header* tagStart = (U8Header*)FindU8Tag( buffer, ret ); if( !tagStart ) { free( buffer ); CloseFile(); gprintf( "U8NandArchive: didn't see a U8 tag\n" ); return false; } // remember where in the file the U8 starts dataOffset = ( (u8*)tagStart - buffer ); // allocate memory and read the fst if( !(fst = (FstEntry *)memalign( 32, RU( tagStart->dataOffset - dataOffset, 32 ) ) ) || ( ISFS_Seek( fd, dataOffset + tagStart->rootNodeOffset, SEEK_SET ) != (s32)( dataOffset + tagStart->rootNodeOffset ) ) || ( ISFS_Read( fd, fst, tagStart->dataOffset - dataOffset ) != (s32)( tagStart->dataOffset - dataOffset ) ) || ( fst->filelen * 0xC > tagStart->dataOffset ) ) { dataOffset = 0; free( buffer ); if( fst ) free( fst ); CloseFile(); gprintf( "U8NandArchive: error reading fst\n" ); } // set name table pointer u32 name_table_offset = fst->filelen * 0xC; name_table = ((char *)fst) + name_table_offset; free( buffer ); return true; }
s8 GetTitleName(u64 id, u32 app, char* name,u8* _dst_uncode_name) { s32 r; int lang = 1; //CONF_GetLanguage(); /* languages: enum { CONF_LANG_JAPANESE = 0, CONF_LANG_ENGLISH, CONF_LANG_GERMAN, CONF_LANG_FRENCH, CONF_LANG_SPANISH, CONF_LANG_ITALIAN, CONF_LANG_DUTCH, CONF_LANG_SIMP_CHINESE, CONF_LANG_TRAD_CHINESE, CONF_LANG_KOREAN }; cause we dont support unicode stuff in font.cpp we will force to use english then(1) */ u8 return_unicode_name = 0; if(_dst_uncode_name == NULL) { return_unicode_name = 0; } else { return_unicode_name = 1; } char file[256] ATTRIBUTE_ALIGN(32); memset(file,0,256); sprintf(file, "/title/%08x/%08x/content/%08x.app", (u32)(id >> 32), (u32)(id & 0xFFFFFFFF), app); gdprintf("GetTitleName : %s\n",file); u32 cnt ATTRIBUTE_ALIGN(32); cnt = 0; IMET *data = (IMET *)mem_align(32, ALIGN32( sizeof(IMET) ) ); if(data == NULL) { gprintf("GetTitleName : IMET header align failure\n"); return -1; } memset(data,0,sizeof(IMET) ); r = ES_GetNumTicketViews(id, &cnt); if(r < 0) { gprintf("GetTitleName : GetNumTicketViews error %d!\n",r); mem_free(data); return -1; } tikview *views = (tikview *)mem_align( 32, sizeof(tikview)*cnt ); if(views == NULL) { mem_free(data); return -2; } r = ES_GetTicketViews(id, views, cnt); if (r < 0) { gprintf("GetTitleName : GetTicketViews error %d \n",r); mem_free(data); mem_free(views); return -3; } //lets get this party started with the right way to call ES_OpenTitleContent. and not like how libogc < 1.8.3 does it. patch was passed on , and is done correctly in 1.8.3 //the right way is ES_OpenTitleContent(u64 TitleID,tikview* views,u16 Index); note the views >_> s32 fh = ES_OpenTitleContent(id, views, 0); if (fh == -106) { CheckTitleOnSD(id); mem_free(data); mem_free(views); return -106; } else if(fh < 0) { //ES method failed. remove tikviews from memory and fall back on ISFS method gprintf("GetTitleName : ES_OpenTitleContent error %d\n",fh); mem_free(views); fh = ISFS_Open(file, ISFS_OPEN_READ); // f**k failed. lets check SD & GTFO if (fh == -106) { CheckTitleOnSD(id); return -106; } else if (fh < 0) { mem_free(data); gprintf("open %s error %d\n",file,fh); return -5; } // read the completed IMET header r = ISFS_Read(fh, data, sizeof(IMET)); if (r < 0) { gprintf("IMET read error %d\n",r); ISFS_Close(fh); mem_free(data); return -6; } ISFS_Close(fh); } else { //ES method r = ES_ReadContent(fh,(u8*)data,sizeof(IMET)); if (r < 0) { gprintf("GetTitleName : ES_ReadContent error %d\n",r); ES_CloseContent(fh); mem_free(data); mem_free(views); return -8; } //free data and let it point to IMET_data so everything else can work just fine ES_CloseContent(fh); mem_free(views); } char str[10][84]; char str_unprocessed[10][84]; //clear any memory that is in the place of the array cause we dont want any confusion here memset(str,0,10*84); if(return_unicode_name) memset(str_unprocessed,0,10*84); if(data->imet == 0x494d4554) // check if its a valid imet header { for(u8 y =0;y <= 9;y++) { u8 p = 0; u8 up = 0; for(u8 j=0;j<83;j++) { if(data->names[y][j] < 0x20) if(return_unicode_name && data->names[y][j] == 0x00) str_unprocessed[y][up++] = data->names[y][j]; else continue; else if(data->names[y][j] > 0x7E) continue; else { str[y][p++] = data->names[y][j]; str_unprocessed[y][up++] = data->names[y][j]; } } str[y][83] = '\0'; } mem_free(data); } else { gprintf("invalid IMET header for 0x%08x/0x%08x\n", (u32)(id >> 32), (u32)(id & 0xFFFFFFFF)); return -9; } if(str[lang][0] != '\0') { gdprintf("GetTitleName : title %s\n",str[lang]); snprintf(name,255, "%s", str[lang]); if (return_unicode_name && str_unprocessed[lang][1] != '\0') { memcpy(_dst_uncode_name,&str_unprocessed[lang][0],83); } else if(return_unicode_name) gprintf("WARNING : empty unprocessed string\n"); } else gprintf("GetTitleName: no name found\n"); memset(str,0,10*84); memset(str_unprocessed,0,10*84); return 1; }
void load() { u32 file_size; static fstats filestats_settings ATTRIBUTE_ALIGN(32); static fstats filestats_appios ATTRIBUTE_ALIGN(32); static u8 filearray_settings[1024] ATTRIBUTE_ALIGN(32); static u8 filearray_appios[1024] ATTRIBUTE_ALIGN(32); #if defined(STBOOT) || defined(STBOOTVWII) Settings.ios_dat = "/title/00010001/48424630/data/appios.dat"; Settings.dir_dat = "/title/00010001/48424630/data/list.dat"; Settings.settings_dat = "/title/00010001/48424630/data/settings.dat"; #else Settings.ios_dat = "/title/00010001/54484246/data/appios.dat"; Settings.dir_dat = "/title/00010001/54484246/data/list.dat"; Settings.settings_dat = "/title/00010001/54484246/data/settings.dat"; #endif AvailableCategoryLoad(Settings.dir_dat); // get settings s32 fd; fd = ISFS_Open(Settings.settings_dat.c_str(), ISFS_OPEN_READ); if (fd <= 0) ISFS_Close(fd); ISFS_GetFileStats(fd, &filestats_settings); file_size = ISFS_Read(fd, filearray_settings, filestats_settings.file_length); ISFS_Close(fd); if(file_size >= 0) { string source = (char*)filearray_settings; if(get_setting(source, "device_dat") != "") Settings.device_dat = get_setting(source, "device_dat"); if (get_setting(source, "theme") != "") { sprintf (Options.theme, get_setting(source, "theme").c_str()); theme(check_path(Settings.device_dat + ":/config/HBF/themes/") + Options.theme + "/"); } if(get_setting(source, "language") != "") { sprintf (Options.language, get_setting(source, "language").c_str()); ini_Open(check_path(Settings.device_dat + ":/config/HBF/languages/") + Options.language + ".lang"); AvailableCategory.categories[0] = tr(Settings.category_name_all); } if(get_setting(source, "font") != "") sprintf (Options.font, get_setting(source, "font").c_str()); if(get_setting(source, "slide_effect") != "") Options.slide_effect = atoi(get_setting(source, "slide_effect").c_str()); if(get_setting(source, "last_category_name") != "") { if(KategorieNr(get_setting(source, "last_category_name")) != -1) Settings.current_category = KategorieNr(get_setting(source, "last_category_name").c_str()); } if(get_setting(source, "last_category") != "") { Options.last_category = atoi(get_setting(source, "last_category").c_str()); if(Options.last_category == 1) Options.last_category = Settings.current_category +1; } if(get_setting(source, "last_app_name") != "") Settings.startingAppName = get_setting(source, "last_app_name"); if(get_setting(source, "apps_nr") != "") { Options.apps = atoi(get_setting(source, "apps_nr").c_str()); if(Options.apps > 5) Options.apps = 5; else if(Options.apps < 4) Options.apps = 4; } if(get_setting(source, "quick_start") != "") Options.quick_start = atoi(get_setting(source, "quick_start").c_str()); if(get_setting(source, "show_all") != "") Options.show_all = atoi(get_setting(source, "show_all").c_str()); if(get_setting(source, "navigation") != "") Options.navigation = atoi(get_setting(source, "navigation").c_str()); if(get_setting(source, "sdgecko") != "") Options.sdgecko = atoi(get_setting(source, "sdgecko").c_str()); #ifndef VWII if(get_setting(source, "bootmii_boot2") != "") Options.bootmii_boot2 = atoi(get_setting(source, "bootmii_boot2").c_str()); #endif if(get_setting(source, "network") != "") { Options.network = atoi(get_setting(source, "network").c_str()); Options.temp_network = Options.network; } if(get_setting(source, "wifigecko") != "") { Options.wifigecko = atoi(get_setting(source, "wifigecko").c_str()); Options.temp_wifigecko = Options.wifigecko; } if(get_setting(source, "newrevtext") != "") { Options.newrevtext = atoi(get_setting(source, "newrevtext").c_str()); Options.temp_newrevtext = Options.newrevtext; } if(get_setting(source, "code") != "") { sprintf (Settings.code, get_setting(source, "code").c_str()); strcpy (Options.temp_code, Settings.code); } if(get_setting(source, "grid") != "") Settings.grid = atoi(get_setting(source, "grid").c_str()); if(get_setting(source, "device") != "") Settings.device = get_setting(source, "device"); if(get_setting(source, "device_icon") != "") Options.device_icon = atoi(get_setting(source, "device_icon").c_str()); if(get_setting(source, "wiiload_ahb") != "") Options.wiiload_ahb = atoi(get_setting(source, "wiiload_ahb").c_str()); if(get_setting(source, "wiiload_ios") != "") Options.wiiload_ios = atoi(get_setting(source, "wiiload_ios").c_str()); if(get_setting(source, "system") != "") Settings.system = atoi(get_setting(source, "system").c_str()); if(get_setting(source, "top") != "") Settings.top = atoi(get_setting(source, "top").c_str()); if(get_setting(source, "bottom") != "") Settings.bottom = atoi(get_setting(source, "bottom").c_str()); if(get_setting(source, "left") != "") Settings.left = atoi(get_setting(source, "left").c_str()); if(get_setting(source, "right") != "") Settings.right = atoi(get_setting(source, "right").c_str()); } // get appios fd = ISFS_Open(Settings.ios_dat.c_str(), ISFS_OPEN_READ); if (fd <= 0) ISFS_Close(fd); ISFS_GetFileStats(fd, &filestats_appios); file_size = ISFS_Read(fd, filearray_appios, filestats_appios.file_length); ISFS_Close(fd); if(file_size >= 0) { string line; istringstream in((char*)filearray_appios); while(getline(in, line)) appios.push_back(app_ios(line.substr(0, line.find(" = ")), atoi(line.substr(line.find(" = ") +3).c_str()))); } }
static int _ISFS_open_r(struct _reent *r, void *fileStruct, const char *path, int flags, int mode) { FILE_STRUCT *file = (FILE_STRUCT *)fileStruct; char *abspath = malloc(ISFS_MAXPATHLEN); if(!abspath) { r->_errno = ENOMEM; return -1; } char *ptr = strchr(path, ':'); if (ptr != NULL) snprintf(abspath, ISFS_MAXPATHLEN, "%s", ptr + 1); else snprintf(abspath, ISFS_MAXPATHLEN, "%s/%s", current->entry->abspath, path); RemoveDoubleSlash(abspath); if (!READ_ONLY && (flags & O_CREAT)) { int iOwnerPerm = 0; int iGroupPerm = 0; int iOtherPerm = 0; if (flags & S_IRUSR) iOwnerPerm |= ISFS_OPEN_READ; if (flags & S_IWUSR) iOwnerPerm |= ISFS_OPEN_WRITE; if (flags & S_IRGRP) iGroupPerm |= ISFS_OPEN_READ; if (flags & S_IWGRP) iGroupPerm |= ISFS_OPEN_WRITE; if (iGroupPerm & S_IROTH) iOtherPerm |= ISFS_OPEN_READ; if (flags & S_IWOTH) iOtherPerm |= ISFS_OPEN_WRITE; ISFS_CreateFile(abspath, 0, iOwnerPerm, iGroupPerm, iOtherPerm); } int iOpenMode = 0; if ((flags & 0x03) == O_RDONLY) iOpenMode |= ISFS_OPEN_READ; if (!READ_ONLY && ((flags & 0x03) == O_WRONLY)) iOpenMode |= ISFS_OPEN_WRITE; if ((flags & 0x03) == O_RDWR) iOpenMode |= READ_ONLY ? ISFS_OPEN_READ : ISFS_OPEN_RW; file->fd = ISFS_Open(abspath, iOpenMode); free(abspath); if (file->fd < 0) { if (file->fd == ISFS_EINVAL) r->_errno = EACCES; else r->_errno = -file->fd; return -1; } file->flags = flags; file->mode = mode; if (ISFS_GetFileStats(file->fd, &filest) == ISFS_OK) file->size = filest.file_length; if (!READ_ONLY && (flags & O_APPEND)) ISFS_Seek(file->fd, 0, SEEK_END); return (int)file; }
s32 extractChannelContents(u64 titleID, char* location) { u32 TitleIDH=TITLE_UPPER(titleID); u32 TitleIDL=TITLE_LOWER(titleID); if(ES_SetUID(titleID)<0) return ERR_UID; u32 tmd_size ATTRIBUTE_ALIGN(32); if(ES_GetStoredTMDSize(titleID, &tmd_size)<0) return ERR_TMDSIZE; signed_blob *TMD = (signed_blob *)memalign( 32, tmd_size ); memset(TMD, 0, tmd_size); if(ES_GetStoredTMD(titleID, TMD, tmd_size)<0) { free(TMD); return ERR_TMD; } u32 cnt ATTRIBUTE_ALIGN(32); if(ES_GetNumTicketViews(titleID, &cnt)<0) { free(TMD); return ERR_TIKCOUNT; } if( cnt <= 0 ) { free(TMD); return ERR_TIKCOUNT; } tikview *views = (tikview *)memalign( 32, sizeof(tikview)*cnt ); if(ES_GetTicketViews(titleID, views, cnt)<0) { free(views); free(TMD); return ERR_TIK; } printf("Allocated and filled views.\n"); sleep(3); Identify_SU(); int z; tmd_content *TMDc = TMD_CONTENTS(((tmd*)(SIGNATURE_PAYLOAD(TMD)))); // OH GOD CREDIAR, WTF WAS THAT MESS! // List format is "XXXXXXXX = YYYYYYYY" where X is index, and Y is cid. char *lookup_list=calloc(21,((tmd*)(SIGNATURE_PAYLOAD(TMD)))->num_contents); ClearScreen(); printf("\nNumber of contents: %d\n",((tmd*)(SIGNATURE_PAYLOAD(TMD)))->num_contents); sleep(1); for(z=0; z < ((tmd*)(SIGNATURE_PAYLOAD(TMD)))->num_contents; z++) { /* Get Content */ char nameDirectory[80]; sprintf(nameDirectory,"/title/%08x/%08x/content/%08x.app",TitleIDH,TitleIDL,TMDc[z].cid); s32 contentFd=ISFS_Open(nameDirectory,ISFS_OPEN_READ); u8 *data=calloc(TMDc[z].size,1); if(contentFd<0) { switch(contentFd) { case ISFS_EINVAL: printf("FAILED! (Invalid Argument %s)\n\tQuitting...\n",nameDirectory); sleep(5); Finish(1); break; case ISFS_ENOMEM: printf("FAILED! (Out of memory %s)\n\tQuitting...\n",nameDirectory); sleep(5); Finish(1); break; default: goto skip; // Finish(1); break; } } int isUnaligned = ((int)data)%32 | TMDc[z].size%32; int alignedLen = (TMDc[z].size+31)&0xffffffe0; unsigned char* alignedBuf; if(isUnaligned) alignedBuf = memalign(32, alignedLen); else alignedBuf = data; ISFS_Seek(contentFd,0,0); ISFS_Read(contentFd, alignedBuf, alignedLen); // If it was unaligned, you have to copy it and clean up if(isUnaligned){ memcpy(data, alignedBuf, TMDc[z].size); free(alignedBuf); } ISFS_Close(contentFd); // Do copying here. // data is the actual content data (use fwrite with it :P). // Copy the file with it's index as it's filename char* destination=calloc(sizeof(location)+14, 1); char lookup_entry[21]; sprintf(destination, "%s/%08x.app",location,TMDc[z].index); sprintf(lookup_entry, "%08x = %08x\n",TMDc[z].index,TMDc[z].cid); strcat(lookup_list, lookup_entry); printf("Got destination as: %s\n", destination); sleep(3); FILE *dfd=fopen(destination,"wb+"); printf("Opened %s\n", destination); sleep(3); // free(destination); fwrite(data, TMDc[z].size, 1, dfd); printf("Wrote data to %s\n", destination); sleep(3); fclose(dfd); printf("Closed %s\n", destination); sleep(2); skip: _nop(); } // Make a file containing the lookups called files.txt char* lookup_file=calloc(sizeof(location)+14, 1); sprintf(lookup_file, "%s/files.txt",location); printf("Got destination as: %s\n", lookup_file); sleep(3); FILE* lfd=fopen(lookup_file,"wb+"); printf("Opened %s\n", lookup_file); sleep(3); // free(lookup_file); fwrite(lookup_list, 21, ((tmd*)SIGNATURE_PAYLOAD(TMD))->num_contents, lfd); printf("Wrote lookups to %s\n", lookup_file); sleep(3); fclose(lfd); printf("Closed %s\n", lookup_file); sleep(2); printf("Freed TMD and views"); sleep(1);