forked from maxton/LibOrbisPkg
-
Notifications
You must be signed in to change notification settings - Fork 12
/
PS4PFS.bt
310 lines (290 loc) · 7.35 KB
/
PS4PFS.bt
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
//--------------------------------------
//--- 010 Editor v6.0.2 Binary Template
//
// File: PS4PFS.bt
// Author:
// Revision:
// Purpose:
//--------------------------------------
LittleEndian();
typedef union {
time_t time;
uint64 time_64;
} time_t64;
typedef struct {
int16 mode;
int16 nlink;
int32 unk;
int64 size;
int64 size2;
struct {
time_t64 unk1_tv_sec;
time_t64 unk2_tv_sec;
time_t64 unk3_tv_sec;
time_t64 unk4_tv_sec;
uint32 unk1_tv_nsec;
uint32 unk2_tv_nsec;
uint32 unk3_tv_nsec;
uint32 unk4_tv_nsec;
} times;
int32 uid;
int32 gid;
int64 unk2[2];
int64 blocks;
int64 db[12];
int64 ib[5];
} di_d64;
typedef struct {
int16 mode;
int16 nlink;
int32 unk;
int64 size;
int64 size2;
struct {
time_t64 unk1_tv_sec;
time_t64 unk2_tv_sec;
time_t64 unk3_tv_sec;
time_t64 unk4_tv_sec;
uint32 unk1_tv_nsec;
uint32 unk2_tv_nsec;
uint32 unk3_tv_nsec;
uint32 unk4_tv_nsec;
} times;
int32 uid;
int32 gid;
int64 unk2[2];
int64 blocks;
struct { byte sig[32]; int64 block; } db[12];
struct { byte sig[32]; int64 block; } ib[5];
} di_s64;
typedef struct {
int64 unk[5];
} idxBlockDescriptor;
typedef struct {
uint16 o_read : 1;
uint16 o_write : 1;
uint16 o_execute : 1;
uint16 g_read : 1;
uint16 g_write : 1;
uint16 g_execute : 1;
uint16 u_read : 1;
uint16 u_write : 1;
uint16 u_execute : 1;
uint16 unk : 5;
uint16 dir : 1;
uint16 file : 1;
} ino_mode;
typedef struct {
ino_mode mode;
uint16 nlink;
struct {
uint compressed : 1;
uint unk0 : 1;
uint unk1 : 1;
uint unk2 : 1;
uint readonly : 1;
uint unk3 : 12;
uint internal : 1;
} flags;
uint64 size;
uint64 size_compressed;
struct {
time_t64 unk1_tv_sec;
time_t64 unk2_tv_sec;
time_t64 unk3_tv_sec;
time_t64 unk4_tv_sec;
uint32 unk1_tv_nsec;
uint32 unk2_tv_nsec;
uint32 unk3_tv_nsec;
uint32 unk4_tv_nsec;
} times;
uint32 uid;
uint32 gid;
uint64 unk2[2];
uint32 blocks;
struct {
int blockno;
} db[12];
struct {
uint32 blockno;
} ib[5];
} di_d32 <read=DID32READ>;
typedef struct {
ino_mode mode;
uint16 nlink;
struct {
uint compressed : 1;
uint unk0 : 1;
uint unk1 : 1;
uint unk2 : 1;
uint readonly : 1;
uint unk3 : 12;
uint internal : 1;
} flags;
uint64 size;
uint64 size_compressed;
struct {
time_t64 unk1_tv_sec;
time_t64 unk2_tv_sec;
time_t64 unk3_tv_sec;
time_t64 unk4_tv_sec;
uint32 unk1_tv_nsec;
uint32 unk2_tv_nsec;
uint32 unk3_tv_nsec;
uint32 unk4_tv_nsec;
} times;
uint32 uid;
uint32 gid;
uint64 unk2[2];
uint32 blocks;
struct {
char sig[32];
int blockno;
} db[12];
struct {
char sig[32];
uint32 blockno;
} ib[5];
} di_s32 <read=DIS32READ>;
string DID32READ( di_d32 &m )
{
char outbuf[100];
SPrintf(outbuf, "%s, size %u (%u blocks) start %x",
m.mode.dir ? "Directory" : "File", m.size, m.blocks, m.db[0].blockno);
return outbuf;
}
string DIS32READ( di_s32 &m )
{
char outbuf[100];
SPrintf(outbuf, "%s, size %u (%u blocks) start %x",
m.mode.dir ? "Directory" : "File", m.size, m.blocks, m.db[0].blockno);
return outbuf;
}
// modes:
// 0x8 : read-only
// 0x4 : compressed
// 0x2 : ??
// 0x1 : encrypted
typedef struct {
local int start = FTell();
int64 version; // 1
int64 magic; // 20130305 (march 5 2013???)
int32 id[2];
uchar fmode;
uchar clean;
uchar ronly;
uchar rsv;
struct {
uint16 is_signed : 1;
uint16 is_64_bit : 1;
uint16 encrypted: 1;
uint16 unk_always_1 : 1;
uint16 unk : 12;
} mode;
int16 unk1;
int32 blocksz;
int32 nbackup;
int64 nblock;
int64 dinodeCount; // changes
int64 ndblock; // changes
int64 dinodeBlockCount; // changes
int64 zero;
di_s64 superroot_ino;
FSeek(start + 0x36C);
int unk_index;
byte crypt_seed[16];
byte unk_digest[32];
byte superblock_sig[256];
byte fs_img_sig[256];
} PFS_HDR;
typedef struct {
local int64 start = FTell();
int32 ino;
int32 type;
int32 namelen;
int32 entsize;
char name[];
if((FTell() & 7) != 0)
char space[(FTell() + 7 & (~7)) - FTell()];
FSeek(start + entsize);
} dirent<read=DIRENTRD>;
string DIRENTRD(dirent& di){
return di.name;
}
typedef struct {
int32 dib_num;
int32 numdirs;
} dirent_block;
typedef struct {
local int offset = FTell();
PFS_HDR header;
//idxBlockDescriptor blocks[header.dinodeBlockCount];
FSeek(offset + header.blocksz);
local int numDirs;
local int total;
if(header.mode.encrypted) {
FSeek(offset + header.blocksz);
local uint64 data_length = (uint64)header.blocksz * (uint64)(header.ndblock - 1);
char encrypted_data[1];
} else {
struct dinode_block {
local int maxPerSector = header.blocksz / sizeof(di_d32);
local int i;
local int j;
total = 0;
for(i = 0; i < header.dinodeBlockCount; i++) {
FSeek(offset + header.blocksz + header.blocksz * i);
for(j = 0; j < maxPerSector && total < header.dinodeCount; j++){
if(header.mode.is_signed){
di_s32 dinode;
} else {
di_d32 dinode;
}
if(dinode[i].mode.dir) numDirs++;
total++;
}
}
} dinodes;
if(header.mode.is_signed) {
local int i;
local int j;
local int k;
for(i = 0; i < total; i++){
struct {
for(j = 0; j < 5; j++){
if(dinodes.dinode[i].ib[j].blockno == 0) break;
FSeek(header.blocksz * dinodes.dinode[i].ib[j].blockno);
for(k = 0; k < header.blocksz; k += 36) {
if(ReadInt64() == 0){
break;
}
struct {
char sig[32];
int block;
} indirect_block;
}
}
} inode_ibs;
}
}
FSeek(offset + header.blocksz * dinodes.dinode[0].db[0].blockno);
local int min_size = 280;
struct {
local int i;
local int cont;
local int blocks;
for(i =0; i< header.dinodeCount; i++) {
if((dinodes.dinode[i].mode.dir) != 1) continue;
FSeek(offset + header.blocksz * dinodes.dinode[i].db[0].blockno);
cont = true;
while(cont == true){
dirent d<optimize=false>;
cont = d.ino != 0;
}
}
} dirent_blocks;
} // not encrypted
} PFS_IMAGE;
if(FTell() == 0) {
PFS_IMAGE image;
}