[color=red]
PS3updat.c
#include <stdio.h>
#include <malloc.h>
#include "PS3updat.h"
char* names[] = {"version.txt", "dots.txt", "updater.sce", "vsh.tar", "update.tar"};
#define min(a, b) (a<b?a:b)
#define BE2LE(a) _BE2LE(&a, sizeof(a))
void _BE2LE(void *buf, int size){
unsigned char *ptr = (unsigned char*)buf, temp; int i;
for (i=0; i<size/2; i++){ temp = ptr[i]; ptr[i] = ptr[size-i-1]; ptr[size-i-1] = temp; }
}
void dumpSection(SECTION *sections, FILE *fi){
FILE *fo;
static char buffer[5*1024*1024], i;
printf("section #%I64d: attr=0x%I64X offs=0x%08I64X size=0x%08I64X\n\t\tsignature=",
sections->hash.index, sections->loc.attr, sections->loc.offset, sections->loc.size);
for (i=0; i<20; i++)printf("%02X", sections->hash.signature[i]);
if (sections->hash.index < 5)sprintf(buffer, "%s", names[sections->hash.index]);
else sprintf(buffer, "%dsection.bin", sections->hash.index);
_fseeki64(fi, sections->loc.offset, SEEK_SET);
fo = fopen(buffer, "wb");
while(sections->loc.size){
sections->loc.size -= fwrite(buffer, 1, fread(buffer, 1, min((size_t)sections->loc.size, 5*1024*1024), fi), fo);
printf(".");
}
fclose(fo);
printf("\n");
}
int main(int argc, char* argv[]){
char *filename = "PS3UPDAT.PUP";
unsigned char signature[0x20];
unsigned __int64 i;
FILE *fi;
PUP_header hdr;
SECTION *sections;
printf("PS3 Update unpacker - ver1 by [RO]man\n\n");
if (argc>1)
filename = argv[1];
fi = fopen(filename, "rb");
if (NULL == fi){
printf("Usage: %s <file.pup>\n", argv[0]);
return 1;
}
// read fixed part of header
fread(&hdr, 1, sizeof(hdr), fi);
// convert header
BE2LE(hdr.version); BE2LE(hdr.unk10); BE2LE(hdr.nSections); BE2LE(hdr.hdrSize); BE2LE(hdr.dataSize);
printf("magic=%s ver=%I64d unk=0x%I64X hdrSize=0x%I64X dataSize=0x%I64X\n",
hdr.magic, hdr.version, hdr.unk10, hdr.hdrSize, hdr.dataSize);
sections = (SECTION*) malloc ((size_t)hdr.nSections * sizeof(SECTION));
for (i=0; i<hdr.nSections; i++){
fread(§ions[i].loc, 1, sizeof(SECTION_LOC), fi);
BE2LE(sections[i].loc.attr); BE2LE(sections[i].loc.offset); BE2LE(sections[i].loc.size); BE2LE(sections[i].loc.zero); //

}
for (i=0; i<hdr.nSections; i++){
fread(§ions[i].hash, 1, sizeof(SECTION_HASH), fi); BE2LE(sections[i].hash.index);
}
fread(signature, 1, 0x20, fi);
printf("signature=");for (i=0; i<20; i++)printf("%02X", signature[i]);
printf("\nsections=%I64d\n", hdr.nSections);
for (i=0; i<hdr.nSections; i++)
dumpSection(§ions[i], fi);
fclose(fi);
printf("\nDone\n");
return 0;
}
[color=red]
PS3updat.h
#ifndef __PS3UPDAT_H__
#define __PS3UPDAT_H__
typedef struct SECTION_LOC{
unsigned __int64 attr;
unsigned __int64 offset;
unsigned __int64 size;
unsigned __int64 zero;
} SECTION_LOC;
typedef struct SECTION_HASH{
unsigned __int64 index;
unsigned char signature[20]; // not a sha1?
unsigned int _pad;
} SECTION_HASH;
typedef struct SECTION{ // this is not in file
SECTION_LOC loc;
SECTION_HASH hash;
} SECTION;
typedef struct PUP_header{
unsigned char magic[8]; // "SCEUF\0\0\0"
unsigned __int64 version; //? = 1
unsigned __int64 unk10; //?
unsigned __int64 nSections; // = 5
unsigned __int64 hdrSize;
unsigned __int64 dataSize;
/* SECTION_LOC sections[nSections];
SECTION_HASH hashes[nSections];
unsigned char globalSignature[20];
unsigned char _pad[12];
*/
} PUP_header;
#endif//__PS3UPDAT_H__