snOop2k2
08-16-2002, 10:23 PM
Here is an example source from the Transworld Surf Extractor by me and Bart
:lol:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#include <ctype.h>
void ps2convert (char original[8]);
long hex2dec (void);
char ps2conv[8];
void main()
{
unsigned char Byte1, Byte2, Byte3, Byte4;
char temp, filesize[9], filestart[9], file_number[5], gen_name[5];
long size_count, file_pos, file_size;
int filenum=0, loop;
FILE *bigfile_ptr, *output_ptr, *table_ptr;
printf("Transworld Surfing TWSAUD.DAT Extractor");
printf("\nProgrammed by snOop2k2 and Bart");
printf("\nPress Enter to start extraction");
temp=getchar();
bigfile_ptr=fopen("TWSAUD.DAT", "rb");
table_ptr=fopen("TWSAUD.DAT", "rb");
_mkdir("extracted");
_chdir("extracted");
_mkdir("music");
_chdir("music");
//Go to Position where table starts
fseek(table_ptr,12580,SEEK_SET);
for(loop=0; loop<69; loop++) // THIS IS WHERE THE LOOP STARTS
{
//Read next 4 bytes, this is the File Position
fread(&Byte1,sizeof (char), 1, table_ptr);
fread(&Byte2,sizeof (char), 1, table_ptr);
fread(&Byte3,sizeof (char), 1, table_ptr);
fread(&Byte4,sizeof (char), 1, table_ptr);
//Remember 4 bytes in HEXBYTES
sprintf (filestart, "%02X%02X%02X%02X", (unsigned long) Byte1, Byte2, Byte3, Byte4);
ps2convert(filestart); //Sony Reverse File_pos
file_pos=hex2dec(); //Convert that to DECIMAL
//We have the FileStart now, the next 4 bytes is the FileSize
fread(&Byte1,sizeof (char), 1, table_ptr);
fread(&Byte2,sizeof (char), 1, table_ptr);
fread(&Byte3,sizeof (char), 1, table_ptr);
fread(&Byte4,sizeof (char), 1, table_ptr);
sprintf (filesize, "%02X%02X%02X%02X", (unsigned long) Byte1, Byte2, Byte3, Byte4);
ps2convert(filesize);
file_size=hex2dec();
//We got both
//Lets extract!
itoa(filenum, file_number, 10);
strcpy(gen_name, "music");
strcat(gen_name, file_number);
strcat(gen_name, ".stm");
filenum++;
printf("Extracting %s" ,gen_name);
output_ptr=fopen(gen_name, "wb");
fseek(bigfile_ptr, file_pos, SEEK_SET);
size_count=0;
while(size_count<file_size)
{
fread(&Byte1,sizeof (char), 1, bigfile_ptr);
fwrite (&Byte1,sizeof (char), 1, output_ptr);
size_count=size_count+1;
};
fclose(output_ptr);
fseek(table_ptr, 8, SEEK_CUR); // Move 8 bytes forward in the table before starting next loop
} // END OF LOOP
}
void ps2convert (char original[8]) // Function To Swap Bytes To/From PS2 Format
{
ps2conv[0]=original[6];
ps2conv[1]=original[7];
ps2conv[2]=original[4];
ps2conv[3]=original[5];
ps2conv[4]=original[2];
ps2conv[5]=original[3];
ps2conv[6]=original[0];
ps2conv[7]=original[1];
ps2conv[8]='\0';
}
long hex2dec (void) // Converts Hex To Decimal
{
long temp=0, temp2[8];
int convert[8], indx;
for(indx=0;indx<8;indx++)
{
if(ps2conv[indx]=='0') convert[indx]=0;
if(ps2conv[indx]=='1') convert[indx]=1;
if(ps2conv[indx]=='2') convert[indx]=2;
if(ps2conv[indx]=='3') convert[indx]=3;
if(ps2conv[indx]=='4') convert[indx]=4;
if(ps2conv[indx]=='5') convert[indx]=5;
if(ps2conv[indx]=='6') convert[indx]=6;
if(ps2conv[indx]=='7') convert[indx]=7;
if(ps2conv[indx]=='8') convert[indx]=8;
if(ps2conv[indx]=='9') convert[indx]=9;
if(ps2conv[indx]=='A') convert[indx]=10;
if(ps2conv[indx]=='B') convert[indx]=11;
if(ps2conv[indx]=='C') convert[indx]=12;
if(ps2conv[indx]=='D') convert[indx]=13;
if(ps2conv[indx]=='E') convert[indx]=14;
if(ps2conv[indx]=='F') convert[indx]=15;
}
temp2[7]=convert[7];
temp2[6]=(convert[6]*16);
temp2[5]=((convert[5]*16)*16);
temp2[4]=(((convert[4]*16)*16)*16);
temp2[3]=((((convert[3]*16)*16)*16)*16);
temp2[2]=(((((convert[2]*16)*16)*16)*16)*16);
temp2[1]=((((((convert[1]*16)*16)*16)*16)*16)*16);
temp2[0]=(((((((convert[0]*16)*16)*16)*16)*16)*16)*16);
for(indx=0;indx<8;indx++)
temp=temp+temp2[indx];
return temp;
}
:lol:
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <stdlib.h>
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#include <ctype.h>
void ps2convert (char original[8]);
long hex2dec (void);
char ps2conv[8];
void main()
{
unsigned char Byte1, Byte2, Byte3, Byte4;
char temp, filesize[9], filestart[9], file_number[5], gen_name[5];
long size_count, file_pos, file_size;
int filenum=0, loop;
FILE *bigfile_ptr, *output_ptr, *table_ptr;
printf("Transworld Surfing TWSAUD.DAT Extractor");
printf("\nProgrammed by snOop2k2 and Bart");
printf("\nPress Enter to start extraction");
temp=getchar();
bigfile_ptr=fopen("TWSAUD.DAT", "rb");
table_ptr=fopen("TWSAUD.DAT", "rb");
_mkdir("extracted");
_chdir("extracted");
_mkdir("music");
_chdir("music");
//Go to Position where table starts
fseek(table_ptr,12580,SEEK_SET);
for(loop=0; loop<69; loop++) // THIS IS WHERE THE LOOP STARTS
{
//Read next 4 bytes, this is the File Position
fread(&Byte1,sizeof (char), 1, table_ptr);
fread(&Byte2,sizeof (char), 1, table_ptr);
fread(&Byte3,sizeof (char), 1, table_ptr);
fread(&Byte4,sizeof (char), 1, table_ptr);
//Remember 4 bytes in HEXBYTES
sprintf (filestart, "%02X%02X%02X%02X", (unsigned long) Byte1, Byte2, Byte3, Byte4);
ps2convert(filestart); //Sony Reverse File_pos
file_pos=hex2dec(); //Convert that to DECIMAL
//We have the FileStart now, the next 4 bytes is the FileSize
fread(&Byte1,sizeof (char), 1, table_ptr);
fread(&Byte2,sizeof (char), 1, table_ptr);
fread(&Byte3,sizeof (char), 1, table_ptr);
fread(&Byte4,sizeof (char), 1, table_ptr);
sprintf (filesize, "%02X%02X%02X%02X", (unsigned long) Byte1, Byte2, Byte3, Byte4);
ps2convert(filesize);
file_size=hex2dec();
//We got both
//Lets extract!
itoa(filenum, file_number, 10);
strcpy(gen_name, "music");
strcat(gen_name, file_number);
strcat(gen_name, ".stm");
filenum++;
printf("Extracting %s" ,gen_name);
output_ptr=fopen(gen_name, "wb");
fseek(bigfile_ptr, file_pos, SEEK_SET);
size_count=0;
while(size_count<file_size)
{
fread(&Byte1,sizeof (char), 1, bigfile_ptr);
fwrite (&Byte1,sizeof (char), 1, output_ptr);
size_count=size_count+1;
};
fclose(output_ptr);
fseek(table_ptr, 8, SEEK_CUR); // Move 8 bytes forward in the table before starting next loop
} // END OF LOOP
}
void ps2convert (char original[8]) // Function To Swap Bytes To/From PS2 Format
{
ps2conv[0]=original[6];
ps2conv[1]=original[7];
ps2conv[2]=original[4];
ps2conv[3]=original[5];
ps2conv[4]=original[2];
ps2conv[5]=original[3];
ps2conv[6]=original[0];
ps2conv[7]=original[1];
ps2conv[8]='\0';
}
long hex2dec (void) // Converts Hex To Decimal
{
long temp=0, temp2[8];
int convert[8], indx;
for(indx=0;indx<8;indx++)
{
if(ps2conv[indx]=='0') convert[indx]=0;
if(ps2conv[indx]=='1') convert[indx]=1;
if(ps2conv[indx]=='2') convert[indx]=2;
if(ps2conv[indx]=='3') convert[indx]=3;
if(ps2conv[indx]=='4') convert[indx]=4;
if(ps2conv[indx]=='5') convert[indx]=5;
if(ps2conv[indx]=='6') convert[indx]=6;
if(ps2conv[indx]=='7') convert[indx]=7;
if(ps2conv[indx]=='8') convert[indx]=8;
if(ps2conv[indx]=='9') convert[indx]=9;
if(ps2conv[indx]=='A') convert[indx]=10;
if(ps2conv[indx]=='B') convert[indx]=11;
if(ps2conv[indx]=='C') convert[indx]=12;
if(ps2conv[indx]=='D') convert[indx]=13;
if(ps2conv[indx]=='E') convert[indx]=14;
if(ps2conv[indx]=='F') convert[indx]=15;
}
temp2[7]=convert[7];
temp2[6]=(convert[6]*16);
temp2[5]=((convert[5]*16)*16);
temp2[4]=(((convert[4]*16)*16)*16);
temp2[3]=((((convert[3]*16)*16)*16)*16);
temp2[2]=(((((convert[2]*16)*16)*16)*16)*16);
temp2[1]=((((((convert[1]*16)*16)*16)*16)*16)*16);
temp2[0]=(((((((convert[0]*16)*16)*16)*16)*16)*16)*16);
for(indx=0;indx<8;indx++)
temp=temp+temp2[indx];
return temp;
}