Code:
u64 is_size(char *path)
{
struct CellFsStat s;
if(cellFsStat(path, &s)==CELL_FS_SUCCEEDED)
return s.st_size;
else
return 0;
}
int exist(char *path)
{
struct stat p_stat;
return (stat(path, &p_stat)>=0);
}
void array_to_file(char *_path, unsigned char* _buf, int _size)
{
FILE *flistW;
flistW = fopen(_path, "wb");
if(flistW!=NULL)
{
fwrite( _buf, _size, 1, flistW);
fclose(flistW);
}
}
u8 bubble_pkg( char* _path, char* _file)
{
char task_path[512];
char temp_path1[512];
char temp_path2[512];
cellFsMkdir((char*)"/dev_hdd0/vsh/game_pkg", S_IRWXO | S_IRWXU | S_IRWXG | S_IFDIR | CELL_FS_S_IFDIR | 0777);
for(u8 n=0;n<99;n++)
{
//sprintf(task_path, "/dev_hdd0/vsh/task/000000%02i", n);
sprintf(task_path, "/dev_hdd0/vsh/game_pkg/800000%02i", n);
if(!exist(task_path)) break;
}
if(exist(task_path)) return 0;
mkdir(task_path, S_IRWXO | S_IRWXU | S_IRWXG | S_IFDIR); cellFsChmod(task_path, 0777);
sprintf(temp_path1, "%s/%s", _path, _file);
sprintf(temp_path2, "%s/%s", task_path, _file);
rename(temp_path1, temp_path2); // <-- moves file from one location on internal HDD to another.
// if copying from USB you must deal with it here.
if(!exist(temp_path2)) return 0;
u8 d0[109]={0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x04,
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x65,
0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x66, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01,
0x00, 0x00, 0x00, 0x00, 0x6B, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00,
0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x6C, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0xD0, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x08};
u64 task_size=is_size(temp_path2);
u64 temp_val1=0;
u32 temp_val2=0;
sprintf(temp_path1, "%s/d0.pdb", task_path);
FILE *fp = fopen(temp_path1, "wb");
if(fp==NULL) return 0;
fwrite((char*) &d0, 109, 1, fp);
fwrite((char*) &task_size, 8, 1, fp);
temp_val1=0x000000CE00000008ULL;
fwrite((char*) &temp_val1, 8, 1, fp);
temp_val2=0x00000008;
fwrite((char*) &temp_val2, 4, 1, fp);
fwrite((char*) &task_size, 8, 1, fp);
temp_val2=0x00000069;
fwrite((char*) &temp_val2, 4, 1, fp);
sprintf(temp_path2, "\xE2\x98\x85 Install \x22%s\x22", _file);
temp_val2=strlen(temp_path2)+1;
fwrite((char*) &temp_val2, 4, 1, fp);
fwrite((char*) &temp_val2, 4, 1, fp);
fwrite((char*) temp_path2, strlen(temp_path2), 1, fp);
temp_val2=0;
fwrite((char*) &temp_val2, 1, 1, fp);
temp_val2=0x000000CB;
fwrite((char*) &temp_val2, 4, 1, fp);
temp_val2=strlen(_file)+1;
fwrite((char*) &temp_val2, 4, 1, fp);
fwrite((char*) &temp_val2, 4, 1, fp);
fwrite((char*) _file, strlen(_file), 1, fp);
temp_val2=0;
fwrite((char*) &temp_val2, 1, 1, fp);
u8 d0_1[0x1E]={0x00, 0x00, 0x00, 0xDA, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
0x00, 0xCD, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x6A};
fwrite((char*) &d0_1, 0x1E, 1, fp);
sprintf(temp_path2, "%s/ICON_FILE", task_path);
temp_val2=strlen(temp_path2)+1;
fwrite((char*) &temp_val2, 4, 1, fp);
fwrite((char*) &temp_val2, 4, 1, fp);
fwrite((char*) temp_path2, strlen(temp_path2), 1, fp);
temp_val2=0;
fwrite((char*) &temp_val2, 1, 1, fp);
fclose(fp);
u8 icon_file[0x85F9]={...your PNG bytes here....}; // change 0x85F9 to the size of the PNG
array_to_file(temp_path2, icon_file, 0x85F9); // here too
return 1;
}