-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathpolyphony_ps2vol.bms
268 lines (266 loc) · 7.74 KB
/
polyphony_ps2vol.bms
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
open FDDE "vol" 0
get vol_size asize
math name_quirks = 0
get vol_sign long
if vol_sign == 0xacb990ad
math name_quirks = 1
print "\n hold on, this script will analyze the archive itself based on a 4-byte sign alongside its 4-byte number just so it can handle the whole extraction/reimport process. \n don't worry this script won't scan the entire archive for just two 4-byte values, but you do have to wait until the script can extract the files for you. "
savepos temp_01
goto 0
math vol_ver = 0
math c_01 = 0
do
savepos temp_02
get vol_check_01 long
get vol_check_02 long
if vol_check_01 == 0xacb990ad
math c_01 + 1
putarray c_01 0 temp_02
if vol_check_02 == 0x00020002
math vol_ver = 1
endif
if vol_check_02 == 0x00030001
math vol_ver = 2
endif
endif
math temp_02 += 0x800
goto temp_02
while temp_02 != 0x2000000
goto temp_01
print "\n right... parsing vol info now. \n"
elif vol_sign == 0x53466f52
math vol_ver = 1
print " \n found .vol file with RoFS sign. \n parsing vol info now."
putarray 1 0 0
else
string unknown_vol_sign p "0x%08x" vol_sign
print "\n unknown VOL sign - %unknown_vol_sign% \n find me(AnonBaiter) at ZenHAX or some github repo of mine if you want. "
cleanexit
endif
if vol_ver = 1
getarray vol_offset 1 0
goto vol_offset
get vol_sign_01 long
get min_ver short
get max_ver short
get header_size long
get info_size long
get name_size long
savepos info_offset
xmath info_size_in_memory "info_size - info_offset"
log MEMORY_FILE info_offset info_size_in_memory
math full_count = info_size_in_memory
for pos_01 = 0 < full_count
savepos pos_01 MEMORY_FILE
get entry_01 long MEMORY_FILE
if entry_01 != 0
xmath entry_01_01 "(entry_01 >> 24) & 0xff"
putarray 1 0 entry_01_01
xmath entry_01_02 "entry_01 & 0xffffff"
putarray 1 0 entry_01_02
set entry_02 string ""
goto entry_01_02
if name_quirks = 0
get entry_02 string
elif name_quirks = 1
for x = 0
get string_byte byte
if string_byte = 0xff
break
else
math string_byte ^ -1
math string_byte & 0xff
string string_byte = string_byte
string entry_02 + string_byte
endif
next x
endif
putarray 1 0 entry_02
if entry_01_01 == 0
get entry_03 long MEMORY_FILE
xmath file_offset "entry_03 << 11"
get entry_04 long MEMORY_FILE
math file_size == entry_04
string temp_name p "normal\"
log temp_name file_offset file_size
elif entry_01_01 == 1
get entry_03 long MEMORY_FILE
putarray 1 0 entry_03
for j = 0 < entry_03
get entry_03_01 long MEMORY_FILE
putarray 1 0 entry_03_01
next j
elif entry_01_01 == 2
get entry_03 long MEMORY_FILE
xmath file_offset "entry_03 << 11"
get entry_04 long MEMORY_FILE
math original_file_size_01 == entry_04
get entry_05 long MEMORY_FILE
math compressed_file_size_01 == entry_05
xmath raw_deflate_size "entry_05 - 8"
goto file_offset
for cc = 1 <= 2
get compressed_sign byte
if cc = 1
if compressed_sign == 0x1f
math comp_type = 1
elif compressed_sign == 0xc5
math comp_type = 2
endif
elif cc = 2
if compressed_sign == 0x8b
math comp_type = 1
elif compressed_sign == 0xee
math comp_type = 2
endif
endif
next cc
if comp_type = 1
comtype gzip
elif comp_type = 2
comtype deflate_noerror
goto file_offset
get deflate_sign long
math deflate_sign ~ deflate_sign
get original_file_size_02 long
math original_file_size_02 ~ original_file_size_02
math file_offset + 8
endif
string temp_name p "compressed\"
clog temp_name file_offset raw_deflate_size original_file_size_01
endif
else
break
endif
next
endif
if vol_ver == 2
getarray vol_offset 2 0
goto vol_offset
get vol_sign_02 long
get min_ver short
get max_ver short
get cycles_01 long
get cycles_02 long
get cycles_03 short
get file_info_chunks short
xmath base_offset "(vol_offset >> 11) + ((cycles_01 && 0x800) >> 11)"
putarray 0 0 base_offset
xmath encrypted_offset "vol_offset + 0x40"
goto encrypted_offset
math decoded_value = 0
math z1 = 1
math z2 = 0
for i = 0 <= file_info_chunks
math value_01 = 0x14AC327A
get file_value long
math value_01 * z1
xmath decoded_value "(file_value ^ value_01) & 0xffffffff"
putarray 1 z2 decoded_value
math z1 + 1
math z2 + 1
next i
comtype deflate_noerror
math entry_index = 0
math actual_entry_index = 0
for j = 0 < file_info_chunks
getarray info_offset 1 j
math archive_info_chunk_size = 0
math j + 1
getarray next_offset 1 j
math j - 1
xmath info_size "next_offset - info_offset"
xmath info_off_02 "info_offset + vol_offset"
math original_info_size = 0x800
clog MEMORY_FILE info_off_02 info_size original_info_size
filexor 0x55
get chunk_type short MEMORY_FILE
get chunk_entries short MEMORY_FILE
math chunk_entries >> 1
get chunk_number_01 long MEMORY_FILE
get chunk_number_02 long MEMORY_FILE
if chunk_type == 0
for m = 0 < chunk_entries
set entry_02 string ""
get entry_01 long MEMORY_FILE
xmath entry_01_01 "((entry_01 >> 24) & 0xff) | (((entry_01 >> 16) & 0xff) << 8) | (((entry_01 >> 8) & 0xff) << 16) | ((entry_01 & 0xff) << 24)"
putarray 11 entry_index entry_01_01
for
get string_byte byte MEMORY_FILE
if string_byte >= 0 && string_byte <= 2
goto -1 MEMORY_FILE SEEK_CUR
break
else
string string_byte = string_byte
string entry_02 + string_byte
endif
next
padding 4 MEMORY_FILE
putarray 12 entry_index entry_02
get entry_03 byte MEMORY_FILE
putarray 13 entry_index entry_03
get entry_04 long MEMORY_FILE
putarray 14 entry_index entry_04
if entry_03 == 1
get entry_05 time MEMORY_FILE
putarray 15 entry_index entry_05
get entry_06 long MEMORY_FILE
putarray 16 entry_index entry_06
elif entry_03 == 2
get entry_05 time MEMORY_FILE
putarray 15 entry_index entry_05
get entry_06 long MEMORY_FILE
putarray 16 entry_index entry_06
get entry_07 long MEMORY_FILE
putarray 17 entry_index entry_07
endif
getdstring padding_02 3 MEMORY_FILE
math entry_index + 1
next m
savepos archive_info_chunk_size MEMORY_FILE
for k1 = 0
get check_number short MEMORY_FILE
if check_number == archive_info_chunk_size
for m = 0 < chunk_entries
get entry_08 short MEMORY_FILE
putarray 18 entry_index entry_08
get entry_09 short MEMORY_FILE
putarray 19 entry_index entry_09
next m
break
endif
next k1
endif
filexor ""
next j
math total_entries = entry_index
for i = 0 < total_entries
getarray entry_point 11 i
getarray entry_name 12 i
getarray entry_type 13 i
getarray entry_position 14 i
getarray entry_name_offset 18 i
getarray entry_name_size 19 i
if entry_type != 0
xmath file_offset "(entry_position + base_offset) << 11"
getarray file_timestamp 15 i
endif
if entry_type == 1
getarray file_size 16 i
string temp_name p "normal\"
log temp_name file_offset file_size
elif entry_type == 2
getarray compressed_file_size 16 i
xmath raw_deflate_size "compressed_file_size - 8"
getarray original_file_size_01 17 i
goto file_offset
get deflate_sign long
math deflate_sign ~ deflate_sign
get original_file_size_02 long
math original_file_size_02 ~ original_file_size_02
math file_offset + 8
string temp_name p "compressed\"
clog temp_name file_offset raw_deflate_size original_file_size_01
endif
next i
endif