void AppendToFile(tDevice dev, tDumpMode mode) { FILE *pFile; u8 *block_buffer; int bytes= INFO_BLOCK_PACK*getDumpBlockSize(mode); int num_blocks= WII_MAX_BUFFER/INFO_BLOCK_PACK; int block; pFile = fopen(getDeviceFile(dev, mode), "a"); if (pFile==NULL) { printf("\nERROR: fopen(\"%s\") failed. No FAT filesystem on the %s ?\n", getDeviceFile(dev, mode), getDeviceName(dev)); pressAnyButton(); exit(0); } else { printf(" -> To %s: ", getDeviceName(dev)); for(block=0 ; block<num_blocks; block++) { block_buffer= buffer + block*bytes; if(fwrite(block_buffer, 1, bytes, pFile)!=bytes) { printf("\nError writting on %s. Is it Full?\n", getDeviceName(dev)); pressAnyButton(); exit(0); } else printf("* "); } fclose(pFile); } }
void DumpFlash(tDevice dev, tDumpMode mode) { int totalBlocks= WII_FLASH_SIZE/FLASH_BLOCKSIZE; // Number of pages in NAND int totalSteps= totalBlocks/WII_MAX_BUFFER; FILE *pFile; int blocks_read=0; int steps= 0; // To test //totalSteps= 2; buffer = (u8*) memalign(0x40, WII_MAX_BUFFER*getDumpBlockSize(mode)); if(buffer==NULL) { printf("ERROR: Unable to allocate enough memory for buffer. Unable to continue. Exiting...\n"); pressAnyButton(); exit(0); } initialise_fat(dev); pFile = fopen(getDeviceFile(dev, mode), "wb+"); if (pFile==NULL) { printf("ERROR: fopen(\"%s\") failed. No FAT filesystem on the %s?\n", getDeviceFile(dev, mode), getDeviceName(dev)); pressAnyButton(); exit(0); } else { fclose(pFile); CleanScreen(); for(steps=0; steps<totalSteps; steps++) { // Block set to read in this step starts on... blocks_read= steps*WII_MAX_BUFFER; if((steps % WII_SCREEN_LINES)==0) {CleanScreen(); printf("\nDumping NAND. Pass %d of %d.", (steps/WII_SCREEN_LINES)+1, WII_SCREEN_STEPS);} ReadFlash(blocks_read, mode); AppendToFile(dev, mode); } } printf("\n\nEnd of Flash Dump."); pressAnyButton(); if(buffer!=NULL) free(buffer); }
/** * Gets a raw key press from user and converts it to a string. * * @param self Pointer to self. * args The arguments passed from python program, must * be parsed by python's parse tuple function. * @return PyObject version of string. */ static PyObject * getkeypress(PyObject * self, PyObject *args) { char * returnString = ""; rootCheck(); Config config; getDeviceFile(&config); int kbd_fd = openKeyboardDeviceFile(config.deviceFile); assert(kbd_fd > 0); // Daemonize process. Don't change working directory but redirect standard // inputs and outputs to /dev/null // if (daemon(1, 0) == -1) { // LOG_ERROR("%s", strerror(errno)); // exit(-1); // } uint8_t shift_pressed = 0; input_event event; while (read(kbd_fd, &event, sizeof(input_event)) > 0) { if (event.type == EV_KEY) { if (event.value == KEY_PRESS) { char *name = getKeyText(event.code, shift_pressed); if (isShift(event.code)) { shift_pressed++; } else if (strcmp(name, UNKNOWN_KEY) != 0) { //LOG("%s", name); returnString = strdup(name); break; } } else if (event.value == KEY_RELEASE) { if (isShift(event.code)) { shift_pressed--; } } } assert(shift_pressed >= 0 && shift_pressed <= 2); } Config_cleanup(&config); close(kbd_fd); return Py_BuildValue("s", returnString); }