Guest User

Untitled

a guest
Aug 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 8.76 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include <direct.h>
  4. #include "vars.h"
  5. #include "complib.h"
  6.  
  7. char* AssignExtension(char *name, int n0, int n1, int n2, int n3);
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11.  
  12.  
  13.     FILE *bin, *ext, *exe, *tbl;
  14.     int compression=0;
  15.     char *finalname,thei[8],name[16],comptoe[250];
  16.     unsigned char est[4];
  17.     unsigned long int null,x,numpoint, pointer, fpoints[18000],i,rpoints[18000],c,temp,padding[18000],dim[18000],n0=0,n1=0,n2=0,n3=0;
  18.     unsigned int comprbyte;
  19.     int err,declen,complen;
  20.  
  21.     printf("Shitty Dat.bin/Mov.bin extractor for Tales of Destiny: Director's cut\nby StorMyu and Vash v0.1\n");
  22.       bin=fopen(argv[1],"r+b");
  23.       exe=fopen("DAT.TBL","r+b");
  24.       if (!(exe))
  25.       {
  26.           printf("Can't find or open DAT.TBL.");
  27.           return(0);
  28.       }
  29.       if ((strcmp(argv[1],"DAT.BIN") == 0))
  30.       {
  31.           numpoint=16314;
  32.           _mkdir("DAT");
  33.           _chdir("DAT");
  34.       _mkdir("MGLK");
  35.       _mkdir("TIM2");
  36.       _mkdir("ELF");
  37.       _mkdir("iSE2");
  38.       _mkdir("DUMMY");
  39.       _mkdir("ARCH");  
  40.       _mkdir("iTPK");
  41.       _mkdir("ARCH2S");
  42.       }
  43.  
  44.        fseek(exe,0,SEEK_SET);
  45.        for (i=0;i<numpoint;i++) // Get each pointer in fpoints
  46.        {
  47.            fread(&fpoints[i],4,1,exe);
  48.            fseek(exe,4,SEEK_CUR); //Skip the unknown data
  49.        }
  50.         for (i=0;i<numpoint-1;i++)
  51.        {
  52.           temp=fpoints[i]; //Storing the actual pointer to "temp"
  53.           for(c=0;c<0x40;c++)
  54.           {
  55.  
  56.           if (((temp%64) == 0) || (temp == 0) ) // If / by 0x40 OR first file then
  57.           {
  58.                rpoints[i]=temp; // Then Temp is the good pointer so we store it in rpoints
  59.                c=0x41; // Force cycle to end.
  60.                }else{
  61.                      temp--; // substract 1 till Euclidian division is correct
  62.  
  63.                      }
  64.                      }
  65.          padding[i]=fpoints[i]-rpoints[i]; // get real adress
  66.          }
  67.          rpoints[numpoint-1]=fpoints[numpoint-1]; // for further purpose
  68.  
  69.  
  70.          for (i=0;i<numpoint-1;i++)
  71.        {
  72.        dim[i]=rpoints[i+1]-rpoints[i]-padding[i]; // Get the Size of the file.
  73.  
  74.        sprintf(name,"%d%d%d%d.dat\0",n0,n1,n2,n3);
  75.  
  76.    // Extraction to File
  77.         ext=fopen(name,"w+b");
  78.         fseek(bin,rpoints[i],SEEK_SET);
  79.         printf("%s \n",name);
  80.  
  81.                //test compressione
  82.        compression=0;
  83.        comprbyte=fgetc(bin);
  84.        if (comprbyte == 0x01 || comprbyte == 0x02 || comprbyte == 0x03)
  85.        {
  86.         fread(&complen,4,1,bin);
  87.         if (complen==dim[i]-9)
  88.         {
  89.         printf("...compression type %X found.\n",comprbyte);
  90.         compression=1;
  91.         fread(&declen,4,1,bin);
  92.         dec=(BYTE *)malloc(declen);
  93.         }else{
  94.          printf("\n");
  95.          fseek(bin,rpoints[i],SEEK_SET);
  96.          complen=dim[i];
  97.         }
  98.        }else{
  99.        printf("\n");
  100.        fseek(bin,rpoints[i],SEEK_SET);
  101.        complen=dim[i];
  102.        }
  103.  
  104.        //fine test compressione
  105.  
  106.       comp=(BYTE *)malloc(complen);
  107.       fread(comp,complen,1,bin);
  108.        //se รจ compresso
  109.        if (compression == 1)
  110.        {
  111.         if (comprbyte == 0x01)
  112.         {
  113.          x=1;
  114.         }
  115.         if (comprbyte == 0x02)
  116.         {
  117.          x=2;
  118.         }
  119.         if (comprbyte == 0x03)
  120.         {
  121.          x=3;
  122.         }
  123.          err=Decode(x, comp, complen, dec, &declen);
  124.          if (err == 0)
  125.          {
  126.              fwrite(dec,declen,1,ext);
  127.              free(dec);
  128.          } else {
  129.  
  130.          fseek(bin,rpoints[i],SEEK_SET);
  131.          free(comp);
  132.          comp=(BYTE *)malloc(dim[i]);
  133.          fread(comp,dim[i],1,bin);
  134.          fwrite(comp,dim[i],1,ext);
  135.          free(comp);
  136.          }
  137.         }else{
  138.  
  139.          fwrite(comp,complen,1,ext);
  140.          free(comp);
  141.              }
  142.  
  143.        fclose(ext);
  144.  
  145.        finalname=AssignExtension(name,n0,n1,n2,n3);
  146.    
  147.         // Increase the size of the variable number.
  148.         if (n3==9)
  149.                    {
  150.                    n3=0;
  151.                    n2=n2+1;
  152.                    }else{
  153.                    n3=n3+1;
  154.                          }
  155.                          if (n2==10)
  156.                          {
  157.                          n2=0;
  158.                          n1=n1+1;
  159.                           }
  160.                           if (n1==10)
  161.                          {
  162.                          n1=0;
  163.                          n0=n0+1;
  164.                           }
  165.        }
  166. return(1);
  167.        }
  168.  
  169.  
  170.  
  171. char* AssignExtension( char *name,int n0, int n1, int n2, int n3)
  172. {
  173.     FILE *ext;
  174.     char thei[8],finalname[17],comptoe[250];
  175.     unsigned char est[4];
  176.     unsigned long int null;
  177.  
  178.  
  179.        //controllo dell'estensione
  180.         est[0]=0;
  181.         ext=fopen(name,"rb");
  182.         fread(&est,4,1,ext);
  183.         est[4]=0;
  184.         fseek(ext,0,SEEK_END);
  185.         null=ftell(ext);
  186.         fclose(ext);
  187.         //lista estensioni
  188.         //printf("\n%s\n",est);
  189.         sprintf(finalname,"NONAME\0");
  190.         //if (strcmp(est,"SCPK")==0)
  191.         if (est[0] == 0x69 && est[1]==0x53 && est[2] == 0x45 && est[3] == 0x32)
  192.         {
  193.          sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.iSE2\0",n0,n1,n2,n3,n0,n1,n2,n3);
  194.          system(comptoe);
  195.          sprintf(comptoe,"move %d%d%d%d.iSE2 iSE2\0",n0,n1,n2,n3);
  196.          system(comptoe);
  197.          sprintf(finalname,"iSE2\\%d%d%d%d.iSE2\0",n0,n1,n2,n3);
  198.          return(finalname);
  199.         }  
  200.        // printf("\n%s\n",est);    
  201.        // system("pause");
  202.        if (null == 0)
  203.        {
  204.           sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.null\0",n0,n1,n2,n3,n0,n1,n2,n3);
  205.          system(comptoe);
  206.          sprintf(comptoe,"move %d%d%d%d.null DUMMY\0",n0,n1,n2,n3);
  207.          system(comptoe);
  208.          sprintf(finalname,"DUMMY\\%d%d%d%d.null\0",n0,n1,n2,n3);  
  209.          return(finalname);
  210.        }    
  211.        // if (strcmp(est,"TIM2")==0)
  212.         if (est[0] == 0x54 && est[1]==0x49 && est[2] == 0x4D && est[3] == 0x32)
  213.         {
  214.          sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.tm2\0",n0,n1,n2,n3,n0,n1,n2,n3);
  215.          system(comptoe);
  216.          sprintf(comptoe,"move %d%d%d%d.tm2 TIM2\0",n0,n1,n2,n3);
  217.          system(comptoe);
  218.          sprintf(finalname,"TIM2\\%d%d%d%d.tm2\0",n0,n1,n2,n3);
  219.          return(finalname);
  220.         }
  221.        
  222.         //if (strcmp(est,"RIFF")==0)
  223.         if (est[0] == 0x00 && est[1]==0x00 && est[2] == 0x00 && est[3] == 0x00)
  224.        
  225.         {
  226.          sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.ARCH2S\0",n0,n1,n2,n3,n0,n1,n2,n3);
  227.          system(comptoe);
  228.          sprintf(comptoe,"move %d%d%d%d.ARCH2S ARCH2S\0",n0,n1,n2,n3);
  229.          system(comptoe);
  230.          sprintf(finalname,"ARCH2S\\%d%d%d%d.ARCH2S\0",n0,n1,n2,n3);
  231.          return(finalname);
  232.         }
  233.        
  234.         if (est[0] == 0x4D && est[1]==0x47 && est[2] == 0x4C && est[3] == 0x4B)
  235.         {
  236.          sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.mglk\0",n0,n1,n2,n3,n0,n1,n2,n3);
  237.          system(comptoe);
  238.          sprintf(comptoe,"move %d%d%d%d.mglk MGLK\0",n0,n1,n2,n3);
  239.          system(comptoe);
  240.          sprintf(finalname,"MGLK\\%d%d%d%d.mglk\0",n0,n1,n2,n3);
  241.          return(finalname);
  242.         }
  243.        
  244.         if (est[0] == 0x69 && est[1]==0x54 && est[2] == 0x50 && est[3] == 0x4B)
  245.         {
  246.          sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.iTPK\0",n0,n1,n2,n3,n0,n1,n2,n3);
  247.          system(comptoe);
  248.          sprintf(comptoe,"move %d%d%d%d.iTPK iTPK\0",n0,n1,n2,n3);
  249.          system(comptoe);
  250.          sprintf(finalname,"iTPK\\%d%d%d%d.iTPK\0",n0,n1,n2,n3);
  251.          return(finalname);
  252.         }
  253.        
  254.         //if (strcmp(est,"VAGp")==0)
  255.         if (est[0] == 0x56 && est[1]==0x41 && est[2] == 0x47 && est[3] == 0x70)
  256.         {
  257.          sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.vag\0",n0,n1,n2,n3,n0,n1,n2,n3);
  258.          system(comptoe);
  259.          sprintf(comptoe,"move %d%d%d%d.vag VAG\0",n0,n1,n2,n3);
  260.          system(comptoe);
  261.          sprintf(finalname,"VAG\\%d%d%d%d.vag\0",n0,n1,n2,n3);
  262.          return(finalname);
  263.         }
  264.        
  265.         if (est[0] == 0x7F && est[1]==0x45 && est[2] == 0x4C && est[3] == 0x46)
  266.         {
  267.          sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.elf\0",n0,n1,n2,n3,n0,n1,n2,n3);
  268.          system(comptoe);
  269.          sprintf(comptoe,"move %d%d%d%d.elf ELF\0",n0,n1,n2,n3);
  270.          system(comptoe);
  271.          sprintf(finalname,"ELF\\%d%d%d%d.elf\0",n0,n1,n2,n3);
  272.          return(finalname);
  273.         }
  274.        
  275.         //if (strcmp(est,"YPC2")==0)
  276.         if (est[0] == 0x04 && est[1]==0x00 && est[2] == 0x00 && est[3] == 0x00)
  277.         {
  278.          sprintf(comptoe,"ren %d%d%d%d.dat %d%d%d%d.arch\0",n0,n1,n2,n3,n0,n1,n2,n3);
  279.          system(comptoe);
  280.          sprintf(comptoe,"move %d%d%d%d.arch ARCH\0",n0,n1,n2,n3);
  281.          system(comptoe);
  282.          sprintf(finalname,"ARCH\\%d%d%d%d.arch\0",n0,n1,n2,n3);
  283.          return(finalname);
  284.         }
  285.  
  286.         if (strcmp(finalname,"NONAME")==0)  
  287.          {
  288.             sprintf(finalname,"%s\0",name);
  289.         }
  290.  
  291.         return(finalname);
  292.         }
Add Comment
Please, Sign In to add comment