 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Slasher
Joined: 27 Jan 2006 Posts: 5
|
Posted: Sun Jul 02, 2006 7:49 am Post subject: Processing an eboots icon0 |
|
|
Basically I'm looking to extract the icon0 out of an eboot, load it with the graphics.c library, then delete the file. I've come up with this so far. It works fine up until you process 10 eboots. On the 10th process, the "ERROR: Could not open the output file." pops up and when attempting to load ANY image after that point, it crashes.
| Code: | void removeFile(const char *fullpath) {
sceIoRemove(fullpath);
}
long getFileSize(const char * fileName) {
struct stat file;
if(!stat(fileName, &file)) {
return file.st_size;
}
return 0;
}
char *filename[8] = { "PARAM.SFO", "ICON0.PNG", "ICON1.PMF", "UNKNOWN.PNG", "PIC1.PNG", "SND0.AT3", "UNKNOWN.PSP", "UNKNOWN.PSAR" };
Image* processPBP(const char * path) {
Image* imgSource;
Image* imgDefault;
char curPath[512];
getcwd(curPath, 512);
char loadImg[512];
sprintf(loadImg, "%s/icon0.png", curPath);
int theSize = 0;
int loop0, total_size;
FILE *infile, *outfile;
HEADER header;
infile = fopen(path, "rb");
fseek(infile, 0, SEEK_END); total_size = ftell(infile); fseek(infile, 0, SEEK_SET);
if (fread(&header, sizeof(HEADER), 1, infile) < 0) { printf("ERROR: Could not read the input file header. \n"); return NULL; }
if (header.signature[0] != 0x00) { printf("ERROR: Input file is not a PBP file. \n"); return NULL; } else
if (header.signature[1] != 0x50) { printf("ERROR: Input file is not a PBP file. \n"); return NULL; } else
if (header.signature[2] != 0x42) { printf("ERROR: Input file is not a PBP file. \n"); return NULL; } else
if (header.signature[3] != 0x50) { printf("ERROR: Input file is not a PBP file. \n"); return NULL; }
#ifdef __BIG_ENDIAN__
for (loop0=0;loop0<2;loop0++) {
header.offset[loop0] = NXSwapInt(header.offset[loop0]);
}
#endif
// loop0 = 0 is the param.sfo (reads the data then erases, because you have to loop or it ***** up)
// loop0 = 1 is the icon0.png (reads the data, spits out a file; we load, then delete it)
for (loop0=0; loop0<2; loop0++) { void *buffer; int size;
size = header.offset[loop0 + 1] - header.offset[loop0];
buffer = malloc(size);
if (buffer == NULL) { printf("ERROR: Could not allocate the section data buffer. (%d)\n", size); return NULL; }
if (fread(buffer, size, 1, infile) < 0) { printf("ERROR: Could not read in the section data.\n"); return NULL; }
if (loop0==1) {
// WTF (works great until after loading 10 homebrews!?)
// Mess up is happening here
outfile = fopen(filename[loop0], "wb");
if (outfile == NULL) {
printf("ERROR: Could not open the output file. (%s)\n", filename[loop0]);
return NULL;
}
// Mess up is happening here
if (fwrite(buffer, size, 1, outfile) < 0) { printf("ERROR: Could not write out the section data.\n"); return NULL; }
if (fclose(outfile) < 0) { printf("ERROR: Could not close the output file.\n"); return NULL; }
}
free(buffer);
}
theSize = getFileSize(loadImg);
printf("%02d \n", theSize); // Debug
if (theSize > 0) {
imgSource = loadImage(loadImg);
if (!(imgSource)) {
removeFile(loadImg);
imgDefault = loadImage("ms0:/PSPOSX/skins/default/pages/games/default.png");
return (imgDefault);
}
}
else {
removeFile(loadImg);
imgDefault = loadImage("ms0:/PSPOSX/skins/default/pages/games/default.png");
return (imgDefault);
}
removeFile(loadImg);
return (imgSource);
} |
I've also tried different combinations of homebrew, so I know it's not my homebrew.
Hopefully somebody has some experience with this sort of thing and can lend me a hand.
See any problems with it?
Thanks |
|
| Back to top |
|
 |
Raphael

Joined: 17 Jan 2006 Posts: 646 Location: Germany
|
Posted: Sun Jul 02, 2006 9:10 am Post subject: |
|
|
| You don't call fclose(infile), so I suppose after opening 10 files, it's the end for PSP. Close the infile after reading the buffer. |
|
| Back to top |
|
 |
ufoz
Joined: 10 Nov 2005 Posts: 86 Location: Tokyo
|
Posted: Sun Jul 02, 2006 9:40 am Post subject: |
|
|
| The problem is that there's absolutely no need to create a temporary file just to load the image. Load it into memory directly from the PBP and load the png from there. |
|
| Back to top |
|
 |
Slasher
Joined: 27 Jan 2006 Posts: 5
|
Posted: Sun Jul 02, 2006 9:50 am Post subject: |
|
|
| Raphael wrote: | | You don't call fclose(infile), so I suppose after opening 10 files, it's the end for PSP. Close the infile after reading the buffer. |
I'll try that. Thanks.
| ufoz wrote: | | The problem is that there's absolutely no need to create a temporary file just to load the image. Load it into memory directly from the PBP and load the png from there. |
Well the library I'm using has no function to load the image from memory directly; and as I'm not up to coding one right now either, this will have to do.
EDIT - Thanks Raphael, it fixed the problem :) |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|