Processing an eboots icon0

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Slasher
Posts: 5
Joined: Fri Jan 27, 2006 11:39 am

Processing an eboots icon0

Post by Slasher »

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: Select all

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 &#40;fread&#40;&header, sizeof&#40;HEADER&#41;, 1, infile&#41; < 0&#41; &#123; printf&#40;"ERROR&#58; Could not read the input file header. \n"&#41;; return NULL; &#125; 

   if &#40;header.signature&#91;0&#93; != 0x00&#41; &#123; printf&#40;"ERROR&#58; Input file is not a PBP file. \n"&#41;; return NULL; &#125; else 
   if &#40;header.signature&#91;1&#93; != 0x50&#41; &#123; printf&#40;"ERROR&#58; Input file is not a PBP file. \n"&#41;; return NULL; &#125; else 
   if &#40;header.signature&#91;2&#93; != 0x42&#41; &#123; printf&#40;"ERROR&#58; Input file is not a PBP file. \n"&#41;; return NULL; &#125; else 
   if &#40;header.signature&#91;3&#93; != 0x50&#41; &#123; printf&#40;"ERROR&#58; Input file is not a PBP file. \n"&#41;; return NULL; &#125; 

   #ifdef __BIG_ENDIAN__ 
      for &#40;loop0=0;loop0<2;loop0++&#41; &#123; 
         header.offset&#91;loop0&#93; = NXSwapInt&#40;header.offset&#91;loop0&#93;&#41;; 
      &#125; 
   #endif 

   // loop0 = 0 is the param.sfo &#40;reads the data then erases, because you have to loop or it ***** up&#41; 
   // loop0 = 1 is the icon0.png &#40;reads the data, spits out a file; we load, then delete it&#41; 
   for &#40;loop0=0; loop0<2; loop0++&#41; &#123; void *buffer; int size; 
       
      size = header.offset&#91;loop0 + 1&#93; - header.offset&#91;loop0&#93;; 

      buffer = malloc&#40;size&#41;; 
      if &#40;buffer == NULL&#41; &#123; printf&#40;"ERROR&#58; Could not allocate the section data buffer. &#40;%d&#41;\n", size&#41;; return NULL; &#125; 

      if &#40;fread&#40;buffer, size, 1, infile&#41; < 0&#41; &#123; printf&#40;"ERROR&#58; Could not read in the section data.\n"&#41;; return NULL; &#125; 

      if &#40;loop0==1&#41; &#123; 
         // WTF &#40;works great until after loading 10 homebrews!?&#41; 
         // Mess up is happening here 
         outfile = fopen&#40;filename&#91;loop0&#93;, "wb"&#41;;          
         if &#40;outfile == NULL&#41; &#123; 
            printf&#40;"ERROR&#58; Could not open the output file. &#40;%s&#41;\n", filename&#91;loop0&#93;&#41;; 
            return NULL; 
         &#125; 
         // Mess up is happening here 

         if &#40;fwrite&#40;buffer, size, 1, outfile&#41; < 0&#41; &#123; printf&#40;"ERROR&#58; Could not write out the section data.\n"&#41;; return NULL; &#125; 
       
         if &#40;fclose&#40;outfile&#41; < 0&#41; &#123; printf&#40;"ERROR&#58; Could not close the output file.\n"&#41;; return NULL; &#125; 
      &#125; 
    
      free&#40;buffer&#41;; 
   &#125; 


   theSize = getFileSize&#40;loadImg&#41;; 

   printf&#40;"%02d \n", theSize&#41;; // Debug 

   if &#40;theSize > 0&#41; &#123; 
      imgSource = loadImage&#40;loadImg&#41;; 
      if &#40;!&#40;imgSource&#41;&#41; &#123; 
         removeFile&#40;loadImg&#41;; 
         imgDefault = loadImage&#40;"ms0&#58;/PSPOSX/skins/default/pages/games/default.png"&#41;; 
         return &#40;imgDefault&#41;; 
      &#125; 
   &#125; 
   else &#123; 
      removeFile&#40;loadImg&#41;; 
      imgDefault = loadImage&#40;"ms0&#58;/PSPOSX/skins/default/pages/games/default.png"&#41;; 
      return &#40;imgDefault&#41;; 
   &#125; 

   removeFile&#40;loadImg&#41;; 
   return &#40;imgSource&#41;; 
&#125;
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
User avatar
Raphael
Posts: 646
Joined: Tue Jan 17, 2006 4:54 pm
Location: Germany
Contact:

Post by Raphael »

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.
ufoz
Posts: 86
Joined: Thu Nov 10, 2005 2:36 am
Location: Tokyo
Contact:

Post by ufoz »

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.
Slasher
Posts: 5
Joined: Fri Jan 27, 2006 11:39 am

Post by Slasher »

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 :)
Post Reply