Guest User

Untitled

a guest
Apr 24th, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. // © Copyright Dasda 2008
  2. // Thanks to StoneWood.
  3.  
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include "tools.h"
  11.  
  12. int file_len(FILE *f)
  13. {
  14. int pos;
  15. int end;
  16. pos = ftell (f);
  17. fseek (f, 0, SEEK_END);
  18. end = ftell (f);
  19. fseek (f, pos, SEEK_SET);
  20. return end;
  21. }
  22.  
  23. int main(int argc, char* argv[])
  24. {
  25. printf("-----------------------------------------------------\n");
  26. printf(" DisPac, .PAC extractor (from SMBB) written by dasda\n");
  27. printf("-----------------------------------------------------\n");
  28. if(argc == 2)
  29. {
  30. FILE* fileIn = fopen(argv[1], "rb");
  31. if(!fileIn)
  32. {
  33. printf("File cannot be found.\n");
  34. exit(1);
  35. }
  36.  
  37. int fileIn_len = file_len(fileIn);
  38. u8* fileIn_buf = (u8*) malloc(fileIn_len);
  39.  
  40. fread(fileIn_buf, fileIn_len, 1, fileIn);
  41.  
  42. if(strncmp(fileIn_buf, "ARC", 3) != 0)
  43. {
  44. printf("File isn't a PAC.\n");
  45. exit(1);
  46. }
  47.  
  48. int fileOut_name_len = strlen(fileIn_buf + 0x10);
  49. char* fileOut_name_buf = malloc(fileOut_name_len + 20); // For file extension.
  50. strcpy(fileOut_name_buf, fileIn_buf + 0x10);
  51.  
  52. // Different file types.
  53. u8 fileOut_type = 0;
  54. memcpy(&fileOut_type, fileIn_buf + 0x7, 1);
  55.  
  56. if(fileOut_type == 0x6 || fileOut_type == 0x3)
  57. strcat(fileOut_name_buf, ".brres");
  58. else if(fileOut_type == 0x2)
  59. strcat(fileOut_name_buf, ".bmg");
  60. else
  61. strcat(fileOut_name_buf, ".unk");
  62.  
  63. printf("File type: %x\n", fileOut_type);
  64. printf("Writing to file: %s\n", fileOut_name_buf);
  65.  
  66. FILE* fileOut = fopen(fileOut_name_buf, "wb");
  67. if(!fileOut)
  68. {
  69. printf("Cannot open file for writing.\n");
  70. exit(1);
  71. }
  72.  
  73. fwrite(fileIn_buf + 0x60, fileIn_len - 0x60, 1, fileOut);
  74.  
  75. // Free stuff. :)
  76. free(fileIn_buf);
  77. free(fileOut_name_buf);
  78. }
  79. else printf("Usage: DisPac <File>\n");
  80. }
Add Comment
Please, Sign In to add comment