int Playlog_Delete(void) { s32 res = -1; //Open play_rec.dat s32 fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); if(fd < 0) return fd; PlayRec * playrec_buf = memalign(32, ALIGN32(sizeof(PlayRec))); if(!playrec_buf) goto cleanup; //Read play_rec.dat if(IOS_Read(fd, playrec_buf, sizeof(PlayRec)) != sizeof(PlayRec)) goto cleanup; if(IOS_Seek(fd, 0, 0) < 0) goto cleanup; // invalidate checksum playrec_buf->checksum = 0; if(IOS_Write(fd, playrec_buf, sizeof(PlayRec)) != sizeof(PlayRec)) goto cleanup; res = 0; cleanup: free(playrec_buf); IOS_Close(fd); return res; }
int Playlog_Delete(void) //Make Wiiflow not show in playlog { //Open play_rec.dat s32 playrec_fd = IOS_Open(PLAYRECPATH, IPC_OPEN_RW); if(playrec_fd < 0) goto error_2; //Read play_rec.dat if(IOS_Read(playrec_fd, &playrec_buf, sizeof(playrec_buf)) != sizeof(playrec_buf)) goto error_1; if(IOS_Seek(playrec_fd, 0, 0) < 0) goto error_1; // invalidate checksum playrec_buf.checksum=0; if(IOS_Write(playrec_fd, &playrec_buf, sizeof(playrec_buf)) != sizeof(playrec_buf)) goto error_1; IOS_Close(playrec_fd); return 0; error_1: IOS_Close(playrec_fd); error_2: return -1; }
u8 *NANDLoadFile( char *path, u32 *Size ) { s32 fd = IOS_Open( path, 1 ); if( fd < 0 ) { //dbgprintf("ES:NANDLoadFile->IOS_Open(\"%s\", 1 ):%d\n", path, fd ); *Size = fd; return (u8*)NULL; } //dbgprintf("ES:NANDLoadFile->IOS_Open(\"%s\", 1 ):%d\n", path, fd ); *Size = IOS_Seek( fd, 0, SEEK_END ); //dbgprintf("ES:NANDLoadFile->Size:%d\n", *Size ); IOS_Seek( fd, 0, 0 ); u8 *data = (u8*)heap_alloc_aligned( 0, *Size, 0x40 ); if( data == NULL ) { //dbgprintf("ES:NANDLoadFile(\"%s\")->Failed to alloc %d bytes!\n", path, status->Size ); IOS_Close( fd ); return (u8*)NULL; } s32 r = IOS_Read( fd, data, *Size ); //dbgprintf("ES:NANDLoadFile->IOS_Read():%d\n", r ); if( r < 0 ) { //dbgprintf("ES:NANDLoadFile->IOS_Read():%d\n", r ); *Size = r; IOS_Close( fd ); return (u8*)NULL; } IOS_Close( fd ); return data; }
void ReadFlash(int blocks_read, tDumpMode mode) { s32 res; s32 flash_fd = -1; u8 *block_buffer; int block; int flash_block_size= getDumpBlockSize(mode); printf("\nReading 0x%05X : ", blocks_read); flash_fd = IOS_Open(WII_FLASH_DEVICE, 1 /* 2 = write, 1 = read */); for(block=0 ; block<WII_MAX_BUFFER; block++) { // Do not panic: gives something to user if((block%INFO_BLOCK_PACK)==0) printf("."); block_buffer= buffer + block*flash_block_size; // must seek before every block read -- offset is block number, not byte number IOS_Seek(flash_fd, blocks_read+block, SEEK_SET); res = IOS_Read(flash_fd, block_buffer, flash_block_size); // -12 is "bad block" and should be ignored (fill with zeroes) if(res!=flash_block_size) { if(res==-12) memset(block_buffer, 0, flash_block_size); else { printf("\nERROR reading flash at %d (error:%d)\n", blocks_read+block, res); pressAnyButton(); exit(0); } } } IOS_Close(flash_fd); }
s32 LoadKernel() { u32 TMDSize; u32 i,u; s32 r = ES_GetStoredTMDSize( 0x000000010000003aLL, &TMDSize ); if( r < 0 ) { gprintf("ES_GetStoredTMDSize():%d\r\n", r ); return r; } gprintf("TMDSize:%u\r\n", TMDSize ); TitleMetaData *TMD = (TitleMetaData*)memalign( 32, TMDSize ); if( TMD == (TitleMetaData*)NULL ) { gprintf("Failed to alloc:%u\r\n", TMDSize ); return r; //todo errors are < 0 r still has >= 0 from previous call } r = ES_GetStoredTMD( 0x000000010000003aLL, (signed_blob *)TMD, TMDSize ); if( r < 0 ) { gprintf("ES_GetStoredTMD():%d\r\n", r ); free(TMD); return r; } //Look for boot index for( i=0; i < TMD->ContentCount; ++i ) { if( TMD->BootIndex == TMD->Contents[i].Index ) break; } gprintf("BootIndex:%u\r\n", i ); s32 cfd = IOS_Open( "/shared1/content.map", 1 ); if( cfd < 0 ) { gprintf("IOS_Open():%d\r\n", cfd ); free(TMD); return cfd; } for( u=0;; u+=0x1C ) { if( IOS_Read( cfd, Entry, 0x1C ) != 0x1C ) { gprintf("Hash not found in content.map\r\n"); free(TMD); return -2; } if( memcmp( (char*)(Entry+8), TMD->Contents[i].SHA1, 0x14 ) == 0 ) break; } FoundVersion = ((TMD->TitleID & 0xFFFF) << 16) | (TMD->TitleVersion); free(TMD); IOS_Close( cfd ); u32 *IOSVersion = (u32*)0x93003000; DCInvalidateRange(IOSVersion, 0x20); *IOSVersion = FoundVersion; gprintf("IOS Version: 0x%08X\n", FoundVersion); DCFlushRange(IOSVersion, 0x20); //char Path[32]; char *Path = (char*)0x93003020; DCInvalidateRange(Path, 1024); memset(Path, 0, 1024); sprintf( Path, "/shared1/%.8s.app", Entry ); gprintf("Kernel:\"%s\"\r\n", Path ); DCFlushRange(Path, 1024); s32 kfd = IOS_Open( Path, 1 ); if( kfd < 0 ) { gprintf("IOS_Open():%d\r\n", kfd ); return kfd; } KernelSize = IOS_Seek( kfd, 0, SEEK_END ); IOS_Seek( kfd, 0, 0); gprintf("KernelSize:%u\r\n", KernelSize ); if( IOS_Read( kfd, Kernel, KernelSize ) != KernelSize ) { gprintf("IOS_Read() failed\r\n"); IOS_Close(kfd); return -1; } IOS_Close(kfd); return 0; }
int mload_seek(int offset, int mode) { if(mload_init()<0) return -1; return IOS_Seek(mload_fd, offset, mode); }