Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.60 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<string.h>
  3.  
  4. int get_riff(FILE *fp_in,FILE *fp_out, size_t riff_size, size_t shoc_size);
  5. int get_size(FILE *fp_in);
  6. char * get_form(FILE *fp_in);
  7. char * get_filename(char *form);
  8.  
  9. int main() {
  10.  
  11.     char *form;
  12.     char *filename;
  13.    
  14.     size_t counter=0;
  15.     size_t size;
  16.     size_t position;
  17.     size_t file_size;
  18.     size_t riff_size;
  19.  
  20.     printf("\nFuture Cop RIFF extractor - v0.16\n\n");
  21.  
  22.     printf("Opening file Mp\n\n");
  23.         FILE *fp_in;
  24.         fp_in = fopen("Mp", "rb");
  25.         fseek(fp_in, 0, SEEK_END);
  26.         file_size = ftell(fp_in);
  27.         fseek(fp_in, 0, SEEK_SET);     
  28.         FILE *fp_out;
  29.  
  30.     //loop start
  31.    
  32.     while(position != file_size)
  33.     {
  34.         form = get_form(fp_in);
  35.         size = get_size(fp_in);
  36.        
  37.         //print chunk info
  38.         printf("ID: %u\n", counter);   
  39.         printf("Form: %s\n", form);
  40.         printf("Size: %u bytes\n\n",size);
  41.  
  42.         fseek(fp_in, -8, SEEK_CUR);
  43.  
  44.         //check if fourcc is SHOC
  45.         if (strstr (form,"SHOC") != 0)
  46.         {
  47.             //if fourcc was SHOC, jump 20 bytes ahead
  48.             fseek(fp_in, 20, SEEK_CUR);                
  49.             form = get_form(fp_in);        
  50.            
  51.             //check if fourcc is RIFF
  52.             if (strstr (form,"FFIR") != 0)
  53.             {  
  54.                 riff_size = get_size(fp_in);
  55.                 printf("RIFF gefunden!\n");
  56.                 printf("RIFF size: %u bytes\n\n",riff_size);
  57.  
  58.                 fseek(fp_in, -8, SEEK_CUR);                 // zu RIFF fourcc zurueck spulen
  59.                 filename = get_filename(form);
  60.                 fp_out = fopen(filename,"w");
  61.                 get_riff(fp_in, fp_out, riff_size, size);
  62.                 fclose(fp_out);
  63.             }
  64.                 //printf("Press ENTER to continue");
  65.                 //getchar();
  66.             else
  67.             {
  68.                 fseek(fp_in, -24, SEEK_CUR);   
  69.                 fseek(fp_in, size, SEEK_CUR);
  70.             }
  71.         }
  72.         else
  73.         {
  74.             fseek(fp_in, size, SEEK_CUR);
  75.         }
  76.         counter++;
  77.         position = ftell(fp_in);       
  78.     }
  79.    
  80.     fclose(fp_in);
  81.     return 0;
  82. }
  83.  
  84. char * get_filename(char *form)
  85. {
  86.     static char filename[30];
  87.     static size_t riff_counter;
  88.    
  89.     if (strcmp(form,"FFIR")==0)
  90.     {
  91.         snprintf(filename, 10, "%d", riff_counter);
  92.         strcat(filename, ".wav");                  
  93.         riff_counter++;
  94.         return filename;
  95.     }  
  96. }
  97.  
  98. int get_riff(FILE *fp_in, FILE *fp_out, size_t riff_size, size_t shoc_size)
  99. {  
  100.     int x;
  101.     char buffer;
  102.    
  103.     shoc_size = shoc_size-20;
  104.    
  105.             for (x=0; x < shoc_size; x++)
  106.             {
  107.                 fread(&buffer, 1, 1, fp_in);
  108.                 fwrite(&buffer, 1, 1, fp_out);
  109.                 riff_size--;
  110.             }
  111.            
  112.             while (riff_size > 0)
  113.             {
  114.                 fseek(fp_in, 4, SEEK_CUR);     
  115.                 shoc_size = get_size(fp_in);
  116.                 fseek(fp_in, 12, SEEK_CUR);
  117.                 shoc_size = shoc_size-20;
  118.            
  119.                 for (x=0; x < shoc_size; x++)
  120.                 {
  121.                     fread(&buffer, 1, 1, fp_in);
  122.                     fwrite(&buffer, 1, 1, fp_out);
  123.                     if(riff_size > 0){
  124.                         riff_size--;
  125.                     }
  126.                 }  
  127.             }          
  128.             printf("RIFF complete!\n\n");
  129. }
  130.  
  131. int get_size( FILE *fp_in)
  132. {
  133.     size_t size=0;
  134.     fread(&size, 1, 4, fp_in);
  135.     return size;
  136. }
  137.  
  138. char * get_form( FILE *fp_in)
  139. {
  140.     static int endian = 0;
  141.    
  142.     static char fourcc[sizeof "XXXX"];
  143.         fourcc[0]=48;
  144.         fourcc[1]=48;
  145.         fourcc[2]=48;
  146.         fourcc[3]=48;
  147.         fourcc[4]='\0';
  148.  
  149.     //read fourcc
  150.    
  151.     switch(endian)
  152.     {
  153.         case 0:
  154.             fread(&fourcc[0], 1, 1, fp_in);
  155.             fread(&fourcc[1], 1, 1, fp_in);
  156.             fread(&fourcc[2], 1, 1, fp_in);
  157.             fread(&fourcc[3], 1, 1, fp_in);
  158.  
  159.             if (strstr (fourcc,"CTRL") != 0)
  160.             {  
  161.                 endian=1;
  162.             }
  163.            
  164.             if (strstr (fourcc,"LRTC") != 0)
  165.             {  
  166.                 endian=2;
  167.             }
  168.         break;
  169.        
  170.         case 1:
  171.             fread(&fourcc[0], 1, 1, fp_in);
  172.             fread(&fourcc[1], 1, 1, fp_in);
  173.             fread(&fourcc[2], 1, 1, fp_in);
  174.             fread(&fourcc[3], 1, 1, fp_in);
  175.         break;
  176.        
  177.         case 2:
  178.             fread(&fourcc[3], 1, 1, fp_in);
  179.             fread(&fourcc[2], 1, 1, fp_in);
  180.             fread(&fourcc[1], 1, 1, fp_in);
  181.             fread(&fourcc[0], 1, 1, fp_in);
  182.         break;
  183.     }
  184.        
  185.     return fourcc;
  186. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement