void printChosen(char* s, unsigned size, struct information info) { printf("Length: %u bytes\n", size-1); if(info.hex) { if(info.doXor) printf("XOR: 0x%02x\n", xor_hash(s, size)); if(info.doCrc16) printf("CRC-16: 0x%04x\n", crc_16(s, size)); if(info.doCrc32) printf("CRC-32: 0x%08x\n", crc_32(s, size)); } else { if(info.doXor) printf("XOR: %u\n", xor_hash(s, size)); if(info.doCrc16) printf("CRC-16: %u\n", crc_16(s, size)); if(info.doCrc32) printf("CRC-32: %u\n", crc_32(s, size)); } if(info.doMd5) { printf("MD5: "); printMD5(s, size); printf("\n"); } }
int main(int argc, char *argv[]) { uint8_t Status = EXIT_SUCCESS; uint8_t GlobalStatus = EXIT_SUCCESS; FILE *BinaryFile; //uint32_t FileLength; char *Buffer = malloc(DATA_BUFFER_SIZE); uint8_t Cursor; int OptionType=0; struct Options Option[NB_OPTIONS]; //uint32_t ExtractionSize; //char DisplaySection[DATA_BUFFER_SIZE]; uint32_t *SizedCheck = malloc(sizeof(uint32_t)+1); //uint32_t GlobalSizedCheck=0; //uint8_t GlobalReport[NBToReport]={0}; uint8_t MD5result[MD5_DIGEST_LENGTH]; printf("******************************\n"); printf("* dev-debugging *\n"); printf("******************************\n"); printf("\nOpen source project aimed to help me for my PS3 NOR dumps\n"); if ((argc < 2)||(strcmp(argv[1], "--help")==0)) { printf("Usage: %s CORES_OS_DECRYPTED (Options)\n", argv[0]); printf("Options:\n"); printf(" --help\t\t: Display this help.\n"); //printf(" -P \t\t\t: Give percentage of bytes\n"); //printf(" -G \t\t\t: Check PS3 Generic information\n"); //printf(" -C \t\t\t: Check and display perconsole information\n"); //printf(" -f \t\t\t: Check areas filled with '00' or 'FF'\n"); printf(" -F \t\t\t:(Default option if none given) display some MD5 on Firmware information (ros0/1 + tvrk)\n"); //printf(" -N \t\t\t: Check areas containing data in opposition to -F option\n"); //printf(" -S FolderName \t: Split some NOR section to folder 'FolderName'\n"); printf(" -M Start Size \t: Run MD5 sum on file from 'Start' for 'Size' long\n"); //printf(" -E FileName Start Size: Extract specific NOR Section from 'Start' for 'Size' long\n"); //printf(" -D Start Size H/A \t: Display a specific NOR Section \n\t\t\t from 'Start' for 'Size' long, use H or A for HEX or ASCII\n"); //printf("\nBy default -P -G -C -f and -F will be applied if no option is given\n"); printf("\nRepo: <https://github.com/anaria28/dev-debugging>\n"); // "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789 // " 1 2 3 4 5 6 7 8 return EXIT_FAILURE; } if (argc==2) { OptionType = OPTION_CHECK_PER_FW; } for (Cursor=1;Cursor<argc;Cursor++) { if (strcmp(argv[Cursor], "-M")==0) { OptionType += OPTION_MD5; Option[1].Start = strtol(argv[Cursor+1],NULL,0); Option[1].Size = strtol(argv[Cursor+2],NULL,0); } if (strcmp(argv[Cursor], "-F")==0){ OptionType += OPTION_CHECK_PER_FW; } } BinaryFile = fopen(argv[1], "rb"); if (!BinaryFile) { printf("Failed to open %s\n", argv[1]); return EXIT_FAILURE; } // fseek(BinaryFile, 0, SEEK_END); // if ((FileLength=ftell(BinaryFile))!=NOR_FILE_SIZE) { // printf("File size not correct for NOR, %d Bytes instead of %d\n", FileLength, NOR_FILE_SIZE); // return EXIT_FAILURE; // } if (((OptionType)&(1<<1))==OPTION_MD5) { printf("******************************\n"); printf("* MD5 Sum on Section *\n"); printf("******************************\n"); printf("Chosen section MD5 sum is: "); MD5SumFileSection( BinaryFile, Option[1].Start, Option[1].Size, MD5result); printMD5(MD5result); printf ("\n"); } if (((OptionType)&(1<<9))==OPTION_CHECK_PER_FW) { if((Status = CheckPerFW(BinaryFile, SizedCheck))) { printf("T'a merde mon gars...\n"); } // else { // printf("C'est bon!\n"); // } } free(Buffer); fclose(BinaryFile); return GlobalStatus; }
uint8_t CheckPerFW (FILE *FileToRead, uint32_t *PercentCheck){ uint16_t Cursor=0; uint32_t SizedCheck=0; uint8_t Status =EXIT_SUCCESS; uint8_t MD5result[MD5_DIGEST_LENGTH]; uint8_t NbFileTOCros0; uint32_t ros0Size; //uint32_t ros0FilledSize; uint32_t LastFileTOC; uint32_t LastFileOffset; uint32_t LastFileSize; char ROS0SDKVersion[]="3.55"; char *Buffer = malloc(DATA_BUFFER_SIZE); struct Sections SectionRos[NB_MAX_FILE_ROS+1] = { {NULL, 0, 0, 0, 0, NULL} }; printf("******************************\n"); printf("* CORES OS MD5 *\n"); printf("******************************\n"); GetSection(FileToRead, 0x4, 0x04, TYPE_HEX, Buffer); NbFileTOCros0 = strtol(Buffer,NULL,16); SizedCheck += 0x04; if (NbFileTOCros0<NB_MAX_FILE_ROS) { for (Cursor=0;Cursor<NbFileTOCros0;Cursor++) { //www.ps3devwiki.com/wiki/Flash:ROS#Entry_Table GetSection(FileToRead, 0x10+Cursor*0x30, 0x08, TYPE_HEX, Buffer); SectionRos[Cursor].Offset = strtol(Buffer,NULL,16); // + 0x10; GetSection(FileToRead, 0x18+Cursor*0x30, 0x08, TYPE_HEX, Buffer); SectionRos[Cursor].Size = strtol(Buffer,NULL,16); GetSection(FileToRead, 0x20+Cursor*0x30, 0x20, TYPE_ASCII, Buffer); SectionRos[Cursor].name = strdup(Buffer); SizedCheck += SectionRos[Cursor].Size; } } else { printf ("Found %d files in the TOC of ros0, max is %d !\n" , NbFileTOCros0 , NB_MAX_FILE_ROS); return EXIT_FAILURE; } Cursor = 0; while (SectionRos[Cursor].name!=NULL) { if (strcmp(SectionRos[Cursor].name, "sdk_version")==0) { GetSection(FileToRead, SectionRos[Cursor].Offset, SectionRos[Cursor].Size, TYPE_ASCII, Buffer); ROS0SDKVersion[0]=Buffer[0]; ROS0SDKVersion[2]=Buffer[1]; ROS0SDKVersion[3]=Buffer[2]; } Cursor++; } //at ros0 offset + 0x14: nb of files, (nb of files) * 0x30 = size of TOC GetSection(FileToRead, 0x04, 0x04, TYPE_HEX, Buffer); LastFileTOC = (strtol(Buffer,NULL,16))*0x30-0x20; printf ("debug: LastFileTOC : '0x%08X'\n",LastFileTOC); //last file position found at (ros0 offset) + (size of TOC) - 0x10 GetSection(FileToRead, LastFileTOC, 0x08, TYPE_HEX, Buffer); LastFileOffset = strtol(Buffer,NULL,16); printf ("debug: LastFileOffset : '0x%08X'\n",LastFileOffset); //+ 0x8 for its size. GetSection(FileToRead, LastFileTOC+0x08, 0x08, TYPE_HEX, Buffer); LastFileSize = strtol(Buffer,NULL,16); ros0Size = 0x10 + LastFileOffset + LastFileSize; printf ("{\"ros0\" , \""); MD5SumFileSection (FileToRead, SectionTOC[ros0].Offset+0x10, ros0Size, MD5result); printf("%c.%c%c\" , \"", ROS0SDKVersion[0],ROS0SDKVersion[2],ROS0SDKVersion[3]); printMD5(MD5result); printf ("\"}, // ros Size:'0x%08X'\n",ros0Size); Cursor = 0; while (SectionRos[Cursor].name!=NULL) { //printf("Debug: at '0x%08X' size '0x%08X' ",SectionRos[Cursor].Offset,SectionRos[Cursor].Size); printf ("{\"%s\" , \"",SectionRos[Cursor].name); printf("%c.%c%c\" , \"", ROS0SDKVersion[0],ROS0SDKVersion[2],ROS0SDKVersion[3]); MD5SumFileSection ( FileToRead, SectionRos[Cursor].Offset, SectionRos[Cursor].Size, MD5result); printMD5(MD5result); printf ("\"},\n"); Cursor++; } free(Buffer); return Status; }