Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- int get_riff(FILE *fp_in,FILE *fp_out, size_t riff_size, size_t shoc_size);
- int get_size(FILE *fp_in);
- char * get_form(FILE *fp_in);
- char * get_filename(char *form);
- int main() {
- char *form;
- char *filename;
- size_t counter=0;
- size_t size;
- size_t position;
- size_t file_size;
- size_t riff_size;
- printf("\nFuture Cop RIFF extractor - v0.16\n\n");
- printf("Opening file Mp\n\n");
- FILE *fp_in;
- fp_in = fopen("Mp", "rb");
- fseek(fp_in, 0, SEEK_END);
- file_size = ftell(fp_in);
- fseek(fp_in, 0, SEEK_SET);
- FILE *fp_out;
- //loop start
- while(position != file_size)
- {
- form = get_form(fp_in);
- size = get_size(fp_in);
- //print chunk info
- printf("ID: %u\n", counter);
- printf("Form: %s\n", form);
- printf("Size: %u bytes\n\n",size);
- fseek(fp_in, -8, SEEK_CUR);
- //check if fourcc is SHOC
- if (strstr (form,"SHOC") != 0)
- {
- //if fourcc was SHOC, jump 20 bytes ahead
- fseek(fp_in, 20, SEEK_CUR);
- form = get_form(fp_in);
- //check if fourcc is RIFF
- if (strstr (form,"FFIR") != 0)
- {
- riff_size = get_size(fp_in);
- printf("RIFF gefunden!\n");
- printf("RIFF size: %u bytes\n\n",riff_size);
- fseek(fp_in, -8, SEEK_CUR); // zu RIFF fourcc zurueck spulen
- filename = get_filename(form);
- fp_out = fopen(filename,"w");
- get_riff(fp_in, fp_out, riff_size, size);
- fclose(fp_out);
- }
- //printf("Press ENTER to continue");
- //getchar();
- else
- {
- fseek(fp_in, -24, SEEK_CUR);
- fseek(fp_in, size, SEEK_CUR);
- }
- }
- else
- {
- fseek(fp_in, size, SEEK_CUR);
- }
- counter++;
- position = ftell(fp_in);
- }
- fclose(fp_in);
- return 0;
- }
- char * get_filename(char *form)
- {
- static char filename[30];
- static size_t riff_counter;
- if (strcmp(form,"FFIR")==0)
- {
- snprintf(filename, 10, "%d", riff_counter);
- strcat(filename, ".wav");
- riff_counter++;
- return filename;
- }
- }
- int get_riff(FILE *fp_in, FILE *fp_out, size_t riff_size, size_t shoc_size)
- {
- int x;
- char buffer;
- shoc_size = shoc_size-20;
- for (x=0; x < shoc_size; x++)
- {
- fread(&buffer, 1, 1, fp_in);
- fwrite(&buffer, 1, 1, fp_out);
- riff_size--;
- }
- while (riff_size > 0)
- {
- fseek(fp_in, 4, SEEK_CUR);
- shoc_size = get_size(fp_in);
- fseek(fp_in, 12, SEEK_CUR);
- shoc_size = shoc_size-20;
- for (x=0; x < shoc_size; x++)
- {
- fread(&buffer, 1, 1, fp_in);
- fwrite(&buffer, 1, 1, fp_out);
- if(riff_size > 0){
- riff_size--;
- }
- }
- }
- printf("RIFF complete!\n\n");
- }
- int get_size( FILE *fp_in)
- {
- size_t size=0;
- fread(&size, 1, 4, fp_in);
- return size;
- }
- char * get_form( FILE *fp_in)
- {
- static int endian = 0;
- static char fourcc[sizeof "XXXX"];
- fourcc[0]=48;
- fourcc[1]=48;
- fourcc[2]=48;
- fourcc[3]=48;
- fourcc[4]='\0';
- //read fourcc
- switch(endian)
- {
- case 0:
- fread(&fourcc[0], 1, 1, fp_in);
- fread(&fourcc[1], 1, 1, fp_in);
- fread(&fourcc[2], 1, 1, fp_in);
- fread(&fourcc[3], 1, 1, fp_in);
- if (strstr (fourcc,"CTRL") != 0)
- {
- endian=1;
- }
- if (strstr (fourcc,"LRTC") != 0)
- {
- endian=2;
- }
- break;
- case 1:
- fread(&fourcc[0], 1, 1, fp_in);
- fread(&fourcc[1], 1, 1, fp_in);
- fread(&fourcc[2], 1, 1, fp_in);
- fread(&fourcc[3], 1, 1, fp_in);
- break;
- case 2:
- fread(&fourcc[3], 1, 1, fp_in);
- fread(&fourcc[2], 1, 1, fp_in);
- fread(&fourcc[1], 1, 1, fp_in);
- fread(&fourcc[0], 1, 1, fp_in);
- break;
- }
- return fourcc;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement