Guest User

Untitled

a guest
Jun 25th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. #include <fcntl.h>
  2. #include <malloc.h>
  3.  
  4. typedef struct{
  5. unsigned id;
  6. short padding;
  7. unsigned short len;
  8. unsigned unk;
  9. }TPAheader;
  10. typedef struct{
  11. unsigned id;
  12. unsigned size;
  13. unsigned offset;
  14. unsigned dummy;
  15. }FileEntry;
  16. typedef struct{
  17. unsigned id;//0xdec00400
  18. short unk;//0x0000
  19. short len;//0xf900
  20. unsigned unk2;//0x60c4 3800
  21. }PKHeader;
  22. typedef struct{
  23. unsigned id;//0xa24ac3d6
  24. unsigned short size;//0x0001
  25. unsigned short size2;//0x0000
  26. unsigned unk;//0x00000000
  27. unsigned unk2;//0x00000000
  28. }PKEntry;
  29. int main(int argc,char** argv){
  30. if(argc<2)return printf("missing arg");
  31. printf("opening %s...\n",argv[1]);
  32. FILE*fd=fopen(argv[1],"rb");
  33. if(fd<=0)return printf("file %s not found",argv[1]);
  34. TPAheader head;
  35. fread(&head,sizeof(head),1,fd);
  36. printf("%i files found\n",head.len);
  37. FileEntry ent;
  38. int i;
  39. for(i=0;i<head.len;i++){
  40. fread(&ent,sizeof(ent),1,fd);
  41. int pos=ftell(fd);
  42. char*p=malloc(ent.size);
  43. fseek(fd,ent.offset,SEEK_SET);
  44. fread(p,ent.size,1,fd);
  45. fseek(fd,pos,SEEK_SET);
  46. //printf("%08X @%08X (%i)\n",ent.id,ent.offset,ent.size);
  47. char fname[8+1+3+1],*ext=NULL;
  48. switch(*((int*)p)){
  49. case 0x46464952:ext="at3";break;//RIFF
  50. case 0x46465450:ext="pt";break;//PTFF
  51. case 0x0004c0de://no extention it will be a folder
  52. if(ent.id!=0x96E6F686)break;
  53. sprintf(fname,"%08X",ent.id);
  54. mkdir(fname);
  55. PKHeader*pk=(PKHeader*)p;
  56. printf(" <PKG [%08X]> %i\n",pk->id,pk->len);
  57. PKEntry*pke=(PKEntry*)(p+sizeof(PKHeader));
  58. for(;;){
  59. printf("[%08X](%i)\n",pke->size,pke->size);
  60. pke=pke+(pke->size+sizeof(PKEntry))/16;
  61.  
  62. // printf(" | %08X %i\n",pke->id,pke->size);
  63. // pke=(PKEntry*)(pke->size+sizeof(PKEntry));
  64. // printf(" > %08X %i\n",pke->id,pke->size);
  65. break;
  66. }
  67. break;
  68. default :ext="unk";
  69. }
  70. if(ext){
  71. sprintf(fname,"%08X.%s",ent.id,ext);
  72. FILE*out=fopen(fname,"w+b");
  73. fwrite(p,ent.size,1,out);
  74. fclose(out);
  75. }
  76. free(p);
  77. }
  78. printf("%i files extracted!",i);
  79. fclose(fd);
  80. }
Add Comment
Please, Sign In to add comment