Advertisement
Reisyukaku

[SK Estival Versus] fnames.c

Sep 2nd, 2016
615
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.21 KB | None | 0 0
  1. /*
  2. *   fname.c
  3. *       by Reisyukaku
  4. *
  5. *   Quick and dirty parser for filename.bin in Senran Kagura: EV
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdint.h>
  10. #include <malloc.h>
  11.  
  12. typedef uint32_t u32;
  13. typedef uintptr_t uPtr;
  14.  
  15. int main(int argc, char **argv){
  16.     if(argc < 2){
  17.         printf("Usage: %s <filename.bin>\n", argv[0]);
  18.         return -1;
  19.     }
  20.    
  21.     FILE *bin;
  22.     size_t fileSize = 0;
  23.     u32 *buf;
  24.     uPtr stringTable = 0;
  25.     u32 totalStrings = 0;
  26.    
  27.     bin = fopen(argv[1], "rb");
  28.     if(!bin){
  29.         printf("File unable to be opened!\n");
  30.         return -1;
  31.     }
  32.     fseek(bin, 0, SEEK_END);
  33.     fileSize = ftell(bin);
  34.     fseek(bin, 0, SEEK_SET);
  35.  
  36.     buf = malloc(fileSize);
  37.     fread(buf, 4, fileSize/4, bin);
  38.     fclose(bin);
  39.    
  40.     stringTable = buf[2];
  41.     totalStrings = buf[1];
  42.    
  43.     char **stringArray = malloc(totalStrings * sizeof(char*));
  44.     u32 i; for(i = 0; i < totalStrings - 1; i+=2){
  45.         stringArray[i/2] = (void*)buf+((uPtr)buf[i+2]);
  46.         printf("String #%04d [0x%06X] %s\n",
  47.             i/2,
  48.             (uPtr)buf[i+2],
  49.             stringArray[i/2]
  50.         );
  51.     }
  52.    
  53.     free(buf);
  54.     free(stringArray);
  55.    
  56.     return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement