-
Notifications
You must be signed in to change notification settings - Fork 3
/
ps3mfw_tasks.tcl
502 lines (428 loc) · 15.6 KB
/
ps3mfw_tasks.tcl
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
#!/usr/bin/tclsh
#
# ps3mfw -- PS3 MFW creator
#
# Copyright (C) Anonymous Developers (Code Monkeys)
# Copyright (C) RedDot-3ND7355 (Monkey Eater XD)
#
# This software is distributed under the terms of the GNU General Public
# License ("GPL") version 3, as published by the Free Software Foundation.
#
#Import things here for moving operations!
set ::OLDROUTINE "0"
if {$::options(--new-routine)} {
set ::OLDROUTINE "1"
}
proc ego {} {
set dldl2 [open [file join ${::CUSTOM_BUILDVER_TXT}] r]
set versionDL2 [string trim [read $dldl2]]
close $dldl2
set PS3MFW_BUILD $versionDL2
puts "PS3MFW Creator v${::PS3MFW_VERSION}"
puts "Private Build $PS3MFW_BUILD"
puts "Patch on-the-go Edition!"
puts ""
puts " Copyright (C) 2013 Project PS3MFW"
puts " This program comes with ABSOLUTELY NO WARRANTY;"
puts " This is free software, and you are welcome to redistribute it"
puts " under certain conditions; see COPYING for details."
puts ""
puts " Original Dev's :"
puts " KaKaRoTo"
puts " CodeMonkeys"
puts ""
puts " Developed By :"
puts " Anonymous Developers"
puts " RedDot-3ND7355"
puts " B7U3 C50SS"
puts ""
puts " Contributors :"
puts " RazorX"
puts " haz367"
puts " Habib"
puts " haxxxen"
puts " Naewhert"
puts " toolboy2012"
puts " Arachetous"
puts " PS3HAX Network members"
puts ""
}
proc ego_gui {} {
set dldl2 [open [file join ${::CUSTOM_BUILDVER_TXT}] r]
set versionDL2 [string trim [read $dldl2]]
close $dldl2
set PS3MFW_BUILD $versionDL2
log "PS3MFW Creator v${::PS3MFW_VERSION}"
log "Private Build $PS3MFW_BUILD"
log "Patch on-the-go Edition!"
log ""
log " Copyright (C) 2013 Project PS3MFW"
log " This program comes with ABSOLUTELY NO WARRANTY;"
log " This is free software, and you are welcome to redistribute it"
log " under certain conditions; see COPYING for details."
log ""
log " Original Dev's :"
log " KaKaRoTo"
log " CodeMonkeys"
log ""
log " Developed By :"
log " Anonymous Developers"
log " RedDot-3ND7355"
log " B7U3 C50SS"
log ""
log " Contributors :"
log " RazorX"
log " haz367"
log " Habib"
log " haxxxen"
log " Naewhert"
log " toolboy2012"
log " Arachetous"
log " PS3HAX Network members"
log ""
}
proc clean_up {} {
log "Cleaning up"
catch_die {file delete -force -- ${::CUSTOM_PUP_DIR} ${::ORIGINAL_PUP_DIR} ${::OUT_FILE}} \
"Could not cleanup output files"
}
proc unpack_source_pup {pup dest} {
log "Unpacking source PUP [file tail ${pup}]"
catch_die {pup_extract ${pup} ${dest}} "Error extracting PUP file [file tail ${pup}]"
# Check for license.txt for people using older version of ps3tools
set license_txt [file join ${::CUSTOM_UPDATE_DIR} license.txt]
if {![file exists ${::CUSTOM_LICENSE_XML}] && [file exists ${license_txt}]} {
set ::CUSTOM_LICENSE_XML ${license_txt}
}
}
proc unpack_source_pup2 {pup dest} {
log "Unpacking source PUP [file tail ${pup}]"
catch_die {pup_extract2 ${pup} ${dest}} "Error extracting PUP file [file tail ${pup}]"
# Check for license.txt for people using older version of ps3tools
set license_txt [file join ${::CUSTOM_UPDATE_DIR} license.txt]
if {![file exists ${::CUSTOM_LICENSE_XML}] && [file exists ${license_txt}]} {
set ::CUSTOM_LICENSE_XML ${license_txt}
}
}
proc pack_custom_pup {dir pup} {
set build ${::PUP_BUILD}
set obuild [get_pup_build]
log "PUP original build:$obuild"
if {${build} == "" || ![string is integer ${build}] || ${build} == ${obuild}} {
set build ${obuild}
}
# create pup
log "Packing Modified PUP [file tail ${pup}]"
catch_die {pup_create2 ${dir} ${pup} $build} "Error packing PUP file [file tail ${pup}]"
}
proc build_mfw {input output tasks} {
set ::OLDROUTINE "0"
if {$::options(--new-routine)} {
set ::OLDROUTINE "1"
}
#set ::BUILD_DIR [::ttk::entry $settings.temp.2 -textvariable ::temp_dir]
#if {${::OLDROUTINE} == "0" } {
#debug "Using new Routines"
#} elseif {${::OLDROUTINE} == "1" } {
#debug "Using old Routines"
#}
if {${::OLDROUTINE} == "1" } {
global options
set ::selected_tasks [sort_tasks ${tasks}]
# print out ego info
ego_gui
debug "Using old/outdated Routines & tools"
if {${input} == "" || ${output} == ""} {
die "Must specify an input and output file"
}
if {![file exists ${input}]} {
die "Input file does not exist"
}
log "Selected tasks : ${::selected_tasks}"
if {[info exists ::env(HOME)]} {
debug "HOME=$::env(HOME)"
}
if {[info exists ::env(USERPROFILE)]} {
debug "USERPROFILE=$::env(USERPROFILE)"
}
if {[info exists ::env(PATH)]} {
debug "PATH=$::env(PATH)"
}
clean_up
# Add the input OFW SHA1 to the DB
if {${::SHADD} == "true"} {
debug "Adding the SHA1 of the Input PUP to the DB"
sha1_check ${input}
}
# Check input OFW PUP SHA1
if {${::SHCHK} == "true"} {
set catch [catch [sha1_verify ${input}]]
if {$catch == 1} {
log "Error!!"
log "SHA1 of input PUP does not match any known SHA1"
after 20000
exit 0
} elseif {$catch == 0} {
log "PUP SHA1 of input OFW matches known SHA1!"
}
unset catch
}
unpack_source_pup ${input} ${::CUSTOM_PUP_DIR}
extract_tar ${::CUSTOM_UPDATE_TAR} ${::CUSTOM_UPDATE_DIR}
if {[::get_pup_version] >= ${::NEWCFW}} {
extract_tar ${::CUSTOM_SPKG_TAR} ${::CUSTOM_SPKG_DIR}
debug "Extracted spkg_tar"
}
copy_file ${::CUSTOM_PUP_DIR} ${::ORIGINAL_PUP_DIR}
# copy original PUP to working dir
#copy_file ${::CUSTOM_PUP_DIR} ${::ORIGINAL_PUP_DIR}
# set the pup version into a variable so commands later can check it and do fw specific thingy's
debug "checking pup version"
set ::SUF [::get_pup_version]
set ::OFW_MAJOR_VER [lindex [split $::SUF "."] 0]
set ::OFW_MINOR_VER [lindex [split $::SUF "."] 1]
debug "Getting pup version OK! var = ${::SUF}"
log "Unpacking all dev_flash files (SLOW)"
unpkg_devflash_all ${::CUSTOM_DEVFLASH_DIR}
# set X.XX pup image to original due to stupideness of mfw builder!
if { ${::SUF} == "4.50" } {
debug "Fixing build number!"
log "Fixing build number for 4.50!"
set build "61890"
log "Pup build set to $build"
} elseif { ${::SUF} == "$::SUF" } {
debug "Fixing build number for $::SUF"
set build ""
log "Fixed..."
}
# Execute tasks
foreach task ${::selected_tasks} {
log "******** Running task $task **********"
eval [string map {- _} ${task}::main]
}
log "******** Completed tasks **********"
# RECREATE PS3UPDAT.PUP
file delete -force ${::CUSTOM_DEVFLASH_DIR}
debug "custom dev_flash deleted"
if {[::get_pup_version] >= ${::NEWCFW}} {
set filesSPKG [lsort [glob -nocomplain -tails -directory ${::CUSTOM_SPKG_DIR} *.1]]
debug "spkg's added to list"
}
set files [lsort [glob -nocomplain -tails -directory ${::CUSTOM_UPDATE_DIR} *.pkg]]
debug "pkg's added to list"
eval lappend files [lsort [glob -nocomplain -tails -directory ${::CUSTOM_UPDATE_DIR} *.img]]
debug "img's added to list"
eval lappend files [lsort [glob -nocomplain -tails -directory ${::CUSTOM_UPDATE_DIR} dev_flash3_*]]
debug "dev_flash3 added to list"
eval lappend files [lsort [glob -nocomplain -tails -directory ${::CUSTOM_UPDATE_DIR} dev_flash_*]]
debug "dev_flash added to list"
#if {[::get_pup_version] >= ${::NEWCFW}} {
#log "Detected that the FW is over or equal to ${::NEWCFW}, now will be using 4.xx spkg hdr!"
#create_tar ${::CUSTOM_UPDATE_TAR} ${::CUSTOM_UPDATE_DIR} ${files}
#debug "SPKG TAR created"
#} else {
if {[::get_pup_version] >= ${::NEWCFW}} {
create_tar ${::CUSTOM_SPKG_TAR} ${::CUSTOM_SPKG_DIR} ${filesSPKG}
debug "SPKG TAR created (spkg_tar)"
}
create_tar ${::CUSTOM_UPDATE_TAR} ${::CUSTOM_UPDATE_DIR} ${files}
debug "SPKG TAR created (update_files)"
#}
# PACKING ROUTINE
if { ${build} == "61890" } {
set pup $::OUT_FILE
set dir $::CUSTOM_PUP_DIR
debug "Alternate routine!"
log "Packing Modified PUP [file tail ${pup}]"
catch_die {pup_create ${dir} ${pup} $build} "Error packing PUP file [file tail ${pup}]"
} else {
set build ${::PUP_BUILD}
set obuild [get_pup_build]
if {${build} == "" || ![string is integer ${build}] || ${build} == ${obuild}} {
set build ${obuild}
incr build
}
# create pup
debug "Original routine!"
set pup $::OUT_FILE
set dir $::CUSTOM_PUP_DIR
log "Packing Modified PUP [file tail ${pup}]"
catch_die {pup_create ${::CUSTOM_PUP_DIR} ${::OUT_FILE} $build} \
"Error packing PUP file [file tail ${pup}]"
}
#####################################
} elseif { ${::OLDROUTINE} == "0" } {
#####################################
global options
# array for saving off SELF-SCE Hdr fields
# for "LV0" for use by unself/makeself routines
array set LV0_SCE_HDRS {
--KEYREV ""
--AUTHID ""
--VENDORID ""
--SELFTYPE ""
--APPVERSION ""
--FWVERSION ""
--CTRLFLAGS ""
--CAPABFLAGS ""
--COMPRESS ""
}
set ::DID_PATCHING_WITH_UNPACKING_WITHIN_TASK "0"
set ::selected_tasks [sort_tasks ${tasks}]
# print out ego info
ego_gui
debug "Using new Routines & tools"
if {${input} == "" || ${output} == ""} {
die "Must specify an input and output file"
}
if {![file exists ${input}]} {
die "Input file does not exist"
}
log "Selected tasks : ${::selected_tasks}"
if {[info exists ::env(HOME)]} {
debug "HOME=$::env(HOME)"
}
if {[info exists ::env(USERPROFILE)]} {
debug "USERPROFILE=$::env(USERPROFILE)"
}
if {[info exists ::env(PATH)]} {
debug "PATH=$::env(PATH)"
}
# remove all previous files, etc
set ::OUT_FILE [file join ${::OUT_DIR} ${::OUT_FILE}]
clean_up
# Add the input OFW SHA1 to the DB
if {${::SHADD} == "true"} {
debug "Adding the SHA1 of the Input PUP to the DB"
sha1_check ${input}
}
# Check input OFW PUP SHA1
if {${::SHCHK} == "true"} {
set catch [catch [sha1_verify ${input}]]
if {$catch == 1} {
log "Error!!"
log "SHA1 of input PUP does not match any known SHA1"
after 20000
exit 0
} elseif {$catch == 0} {
log "PUP SHA1 of input OFW matches known SHA1!"
}
unset catch
}
## ----------------------------------------------------------------------------------------- ##
## --------------- UNPACK ALL FILES 'FIRST' IN THE 'ORIGINAL_PUP' DIR ---------------------- ##
##
#
# PREPARE PS3UPDAT.PUP for modification
# -- create the 'BUILD-DIR' path first, then
# -- create the 'PS3MFW-OFW' dir
log "Creating initial build directories..."
create_mfw_dir ${::BUILD_DIR}
create_mfw_dir ${::ORIGINAL_PUP_DIR}
## -- unpack the OFW PUP file.....
log "Directorys creation completed!"
unpack_source_pup2 ${input} ${::ORIGINAL_PUP_DIR}
log "PUP Unpacked"
# set the pup version into a variable so commands later can check it and do fw specific thingy's
# save off the "OFW MAJOR.MINOR" into a global for usage throughout
debug "Checking PUP Version"
set ::SUF [::get_pup_version2 ${::ORIGINAL_VERSION_TXT}]
if { [regexp "(^\[0-9]{1,2})\.(\[0-9]{1,2})(.*)" $::SUF all ::OFW_MAJOR_VER ::OFW_MINOR_VER SubVerInfo] } {
set ::NEWMFW_VER [format "%.1d.%.2d" $::OFW_MAJOR_VER $::OFW_MINOR_VER]
if { $SubVerInfo != "" } {
log "Getting pup version OK! var = ${::NEWMFW_VER} (subversion:$SubVerInfo)"
} else {
log "Getting pup version OK! var = ${::NEWMFW_VER}"
}
} else {
die "Getting pup version FAILED! Exiting!"
}
# extract "custom_update.tar
extract_tar2 ${::ORIGINAL_UPDATE_TAR} ${::ORIGINAL_UPDATE_DIR}
# if firmware is >= 3.56 we need to extract
# spkg_hdr.tar
if { ${::NEWMFW_VER} >= ${::OFW_2NDGEN_BASE} } {
extract_tar2 ${::ORIGINAL_SPKG_TAR} ${::ORIGINAL_SPKG_DIR}
}
# unpack devflash files
# (do this before the copy, so we have the unpacked
# flash files in the PS3OFW directory)
log "Unpacking all dev_flash files (FAST)"
unpkg_devflash_all2 ${::ORIGINAL_UPDATE_DIR} ${::ORIGINAL_DEVFLASH_DIR}
# unpack the CORE_OS files here, pass the
# SELF-SCE Headers array
if {[string match "*patch_lv0*" ${::selected_tasks}]} {
set ::DID_PATCHING_WITH_UNPACKING_WITHIN_TASK "1"
debug "Preparing unpacking of lv0 loaders!"
::unpack_coreos_files2 ${::ORIGINAL_PUP_DIR} LV0_SCE_HDRS
}
if {${::DID_PATCHING_WITH_UNPACKING_WITHIN_TASK} == "0"} {
debug "Skipped some useless task..."
}
#::unpack_coreos_files2 ${::ORIGINAL_PUP_DIR} LV0_SCE_HDRS
# Remove the # to the ::unpack_ ... to re-enable pre-unpack of core os and lv0 ldr's!
#debug "Skipped some useless task..."
### DO THE COPY HERE, SO WE HAVE A MIRROR OF ALL REQ'D
### files in the 'PS3MFW-OFW' directory.
# copy original UNPACKED PUP/assoc. files to working dir
log "Copying unpacked OFW to MFW dirs..."
copy_dir ${::ORIGINAL_PUP_DIR} ${::CUSTOM_PUP_DIR}
log "Copied"
#
### --------------------- END OF PRE-EXECUTION PREP-WORK ------------------- ###
### ---------- !!! BEGIN EXECUTION OF MAIN TASKS !!!! --------------------- ###
# Execute tasks
foreach task ${::selected_tasks} {
log "******** Running task: \"$task.tcl\" **********"
eval [string map {- _} ${task}::main]
}
log "******** Completed tasks **********"
### ---------- !!!! DONE EXEUCTION OF TASKS !!! --------------------------- ###
#repack the CORE_OS files here, pass the
# SELF-SCE Headers array
# Remove the # to the ::repack_coreos_... to re-enable the bs useless task whatever... do what you want ffs.
if {[string match "*patch_lv0*" ${::selected_tasks}]} {
set ::DID_PATCHING_WITH_UNPACKING_WITHIN_TASK "1"
debug "Preparing repacking of lv0 loaders!"
::repack_coreos_files2 LV0_SCE_HDRS
}
if {${::DID_PATCHING_WITH_UNPACKING_WITHIN_TASK} == "0"} {
debug "Skipped the packing of core os and so on... (already packed)"
}
# RECREATE PS3UPDAT.PUP
file delete -force ${::CUSTOM_DEVFLASH_DIR}
debug "Custom dev_flash deleted"
# if firmware is >= 3.56, we need to repack spkg files
if { ${::SUF} >= ${::OFW_2NDGEN_BASE} } {
set filesSPKG [lsort [glob -nocomplain -tails -directory ${::CUSTOM_SPKG_DIR} *.1]]
debug "spkg's added to list"
}
set files [lsort [glob -nocomplain -tails -directory ${::CUSTOM_UPDATE_DIR} *.pkg]]
debug "pkg's added to list"
eval lappend files [lsort [glob -nocomplain -tails -directory ${::CUSTOM_UPDATE_DIR} *.img]]
debug "img's added to list"
eval lappend files [lsort [glob -nocomplain -tails -directory ${::CUSTOM_UPDATE_DIR} dev_flash3_*]]
debug "dev_flash 3 added to list"
eval lappend files [lsort [glob -nocomplain -tails -directory ${::CUSTOM_UPDATE_DIR} dev_flash_*]]
debug "dev_flash added to list"
# create the tar with the 'nodirs' flag, to assure 'directories' are NOT
# included in the tar
# '-nodirs' = do NOT include directories in tar file
# do NOT specify 'nofinalpad', as we want the final .tar padded!
create_tar2 ${::CUSTOM_UPDATE_TAR} ${::CUSTOM_UPDATE_DIR} ${files} -nodirs
debug "PKG TAR created"
# if firmware is >= 3.56, we need to repack spkg files
# do NOT specify 'nofinalpad', as we want the final .tar padded!
if { ${::NEWMFW_VER} >= ${::OFW_2NDGEN_BASE} } {
# create the SPKG tar
# '-nodirs' = do NOT include directories in tar file
create_tar2 ${::CUSTOM_SPKG_TAR} ${::CUSTOM_SPKG_DIR} ${filesSPKG} -nodirs
debug "SPKG TAR created"
}
# cleanup any previous output builds
set final_output "${::OUT_FILE}_$::OFW_MAJOR_VER.$::OFW_MINOR_VER.pup"
catch_die {file delete -force -- ${::OUT_FILE}} "Could not cleanup output files"
# finalize the completed PUP
pack_custom_pup ${::CUSTOM_PUP_DIR} ${final_output}
}
}