Advertisement
Reisyukaku

PKG/CNT

Aug 23rd, 2016
535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.41 KB | None | 0 0
  1. /*
  2. *   PS4 PKG CNT header parser
  3. *       by Reisyukaku
  4. */
  5.  
  6. #include <stdio.h>
  7. #include <stdint.h>
  8. #include <string.h>
  9. #include <malloc.h>
  10.  
  11. typedef uint16_t u16;
  12. typedef uint32_t u32;
  13.  
  14. typedef struct{
  15.     u32 magic;
  16.     u32 dummy1;
  17.     u32 dummy2;
  18.     u32 dummy3;
  19.     u32 files;
  20.     u16 dummy4;
  21.     u16 dummy5;
  22.     u32 infoOffset;
  23.     u32 dummy7;
  24.     u32 dummy8;
  25.     u32 dummy9;
  26.     u32 dummy10;
  27.     u32 infoEnd;
  28. } header;
  29.  
  30. unsigned endianFlip(int i){
  31.     return ((i >> 24) & 0xFF) | ((i << 8) & 0xFF0000) | ((i >> 8) & 0xFF00) | ((i << 24) & 0xFF000000);
  32. }
  33.  
  34. int main(int argc, char **argv){
  35.     if(argc < 2){
  36.         printf("Invalid args!\nUsage: %s <file>\n", argv[0]);
  37.         return 1;
  38.     }
  39.    
  40.     FILE *fp;
  41.     header *hdr = NULL;
  42.     unsigned char *blob = NULL;
  43.     fp = fopen(argv[1], "rb");
  44.     if(!fp){
  45.         printf("File not found!\n");
  46.         return 1;
  47.     }
  48.     blob = (unsigned char*)malloc(0x100);
  49.     fread(blob, 1, 0x100, fp);
  50.     hdr = (header*)blob;
  51.     if (hdr->magic == 0x544E437F){ //\x7FCNT
  52.         printf("CNT header\n"
  53.                "-----------\n"
  54.                "Files: %d\n"
  55.                "Info Offset: 0x%X\n",
  56.                endianFlip(hdr->files),
  57.                endianFlip(hdr->infoOffset)
  58.         );
  59.     }else{
  60.         printf("Unknown file type!\n");
  61.         return 1;
  62.     }
  63.    
  64.     fclose(fp);
  65.     free(blob);
  66.    
  67.     return 0;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement