1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
// PSP Theme File splitter
// (C) 2007 FreePlay
#include <stdio.h>
char comp1[]={0x00,0x00,0x00,0x05,0xD9,0x6B};
char comp2[]={0x00,0x00,0x00,0x06,0xD9,0x6B};
char comp3[]={0x00,0x00,0x00,0x07,0xD9,0x6B};
int main(int argc, char **argv)
{
if(argc<2)
{
printf("Usage: %s filename.ptf\n", argv[0]);
return 1;
}
FILE *f = fopen(argv[1],"rb"), *f2;
if(!f)
{
printf("File %s not found!\n", argv[1]);
return 1;
}
char *fname=argv[1];
while(strstr(fname, "/") > 0) fname = (strstr(fname,"/")+1);
char *themename=(char *)malloc(strlen(fname)+2);
strcpy(themename, fname);
((char *)strstr(themename,"."))[0]='_';
strcat(themename,"/");
char *dirname=(char *)malloc(strlen(themename)+3);
printf("%s\n",dirname);
mkdir(themename, 0777);
sprintf(dirname, "%s05", themename);
mkdir(dirname, 0777);
sprintf(dirname, "%s06", themename);
mkdir(dirname, 0777);
sprintf(dirname, "%s07", themename);
mkdir(dirname, 0777);
fseek(f, 0, SEEK_END);
int size=ftell(f);
fseek(f, 0, SEEK_SET);
int x=0;
unsigned char buf[6];
int begin=0, end;
char *filename = (char *)malloc(strlen(themename)+18);
filename[strlen(themename)+13]='\0';
int y = 0;
while(x<size)
{
buf[0]=buf[1];
buf[1]=buf[2];
buf[2]=buf[3];
buf[3]=buf[4];
buf[4]=buf[5];
fread(buf+5, 1, 1, f);
if((!memcmp(buf, comp1, 6))||(!memcmp(buf, comp2, 6))||(!memcmp(buf, comp3, 6)))
{
y++;
if(begin != 0)
{
end=x-34;
begin+=(y>3?-1:0);
fseek(f, begin+28, SEEK_SET);
fread(buf, 1, 6, f);
sprintf(filename, "%s0%i/0x%08X.bin", themename, buf[3], begin);
printf("0x%08X:{%i,%i,%i,%i,%i,%i}\n", begin+29, buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
printf("0%i // %s: begin 0x%08X, end 0x%08X, size 0x%08X\n", buf[3], filename, begin, end, end-begin+1);
fseek(f, begin, SEEK_SET);
unsigned char *buf2 = (unsigned char *)malloc(end-begin+1);
fread(buf2, 1, end-begin+1, f);
f2 = fopen(filename, "wb");
fwrite(buf2, 1, end-begin+1, f2);
free(buf2);
fclose(f2);
fseek(f, x, SEEK_SET);
}
begin=x-33;
}
x++;
}
free(filename);
free(dirname);
free(themename);
fclose(f);
return 0;
}
|