forked from TalZiv/bgtoolset
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflashmem.php
1593 lines (1582 loc) · 65.9 KB
/
flashmem.php
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
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<div id='flashmem'>
<iframe name='dlframe' id='dlframe' src='blank.php' class='dl-frame ui-helper-hidden'></iframe>
<div id='dLoad' class='ui-helper-hidden' title='Load'>
<fieldset class='df ui-widget-content ui-corner-all'><div id='dlDialog_Path' class='ldialog-path'>*.*</div></fieldset>
<div class='scroll-dialog-box scbload'>
<div id='dLTree' class='diag-dtree ui-widget-content ui-corner-all'></div>
</div>
</div>
<div id='dSave_As' class='ui-helper-hidden' title='Save As'>
<fieldset class='df ui-widget-content ui-corner-all'><label id='lsDialog_Path' for='sDialog_FileName' class='diag-dldialog-path'></label><input id='sDialog_FileName' name='sDialog_FileName' type='text' class='diag-dsdialog-ipt ui-corner-all'/></fieldset>
<div class='scroll-dialog-box scbsave'>
<div id='dSTree' class='diag-dtree ui-widget-content ui-corner-all'></div>
</div>
</div>
<h2 align='right' class='tab-header'>Flash Memory Manager <span class='header-tiny-text'>v1.3.1</span></h2>
<div id='treecontainer' class='fm-container'>
<table id='fmbox' class='window'>
<tbody class='window'>
<tr class='window-header ui-widget-header'>
<th class='logoptions window-header ui-widget-header '><div class='dir-table'><span class='dir-left header-normal-text'>CFW Compatible PS3: <span class='fmm-compat'><span id='cfwcompat'></span></span></span><span class='dir-center header-normal-text'></span><span id='spanmode' class='dir-right-fixed' title='Disabling FMM Strict Mode is very risky.Patching checks & restrictions are disabled when FMM Strict Mode is off.Use at your own risk!!!'><div class='switch-wrapper pointer' tabindex='0'><input type='checkbox' name='mode' id='admode' value='true' checked='true' ></div></span></div></th>
</tr>
<tr class='window-content-top ui-widget-content'>
<td align='justify' class='window-content-top ui-widget-content'>
<div id='fTree' class='fm-tree ui-widget-content'></div>
</td>
</tr>
<tr class='pl window-bottom-small'>
<td align='justify' class='window-bottom-small'>
<div class='sizer height-5px'>XXX</div>
</td>
</tr>
</tbody>
</table>
<br>
<div align='center' id='accordion' >
<h3>Instructions</h3>
<div>
<div align='left'>
<ul>
<li>Click on the various FMM tree nodes to reveal available context menu items.</li>
<li>The Flash Memory Patch node's context menu is only enabled if your console is detected to be CFW compatible.</li>
</ul>
</div>
</div>
<h3>Tips</h3>
<div>
<div align='left'>
<ul>
<li><b>Always keep FMM Strict Mode ON.</b><span class='header-small-text'>Strict Mode OFF is ONLY for DEVELOPERS wishing to use their own custom patches.</span></li>
<li><b>Strict Mode OFF.</b><span class='header-small-text'>will let you patch the Flash Memory with any file regardless of its detected validity. You have been warned.</span></li>
<li>For performance reasons, avoid using storage directories containing more than a dozen items in total (files & folders).</li>
<li>For convenience sake, the SHA256 hashes displayed for each Flash Memory ROS region are calculated on the range of 0x6FFE0 bytes used by standard no-FSM patch files.</li>
</ul>
</div>
</div>
</div>
</div>
<div id='dfmProgress' class='diag-fmProgress ui-helper-hidden' title='Operations Progress'></div>
<div id='ulog' class='ui-helper-hidden'></div>
</div>
<script>
jQuery('.refresh-fm').removeClass('ui-state-disabled').addClass('ui-state-disabled');
var ldiag=null;
var sdiag=null;
var ft1 =null;
var pbfm1=null;
var dl_object=null;
var sha256_ros='';
if(!helper.sm){
helper.sm = new sysmem();
}
if(!helper.worker['fmm']){
helper.worker['fmm'] = new workerThread('BGTOOLSET_WKR_FMM');
}
function updatePD(o,st){
pbfm1.updateProgressDialog(o,st);
}
function updateBuffer(b,s){
ldiag.addPatchInfo(b,s);
}
function validatePatchFile(buf_po,filename){
var _nor = so.is_nor();
helper.memory.upokes(buf_po.offset,helper.patch_ros_fragment_start);
if(!_nor){
helper.memory.upokes(buf_po.offset,getActiveNandROS(so));
}
helper.memory.upokes(buf_po.offset+helper.patchfile_size+0x30,_nor ? helper.patch_ros_fragment_end1:helper.patch_ros_fragment_end2);
Logger.info('getSHA256hash 0x'+(buf_po.offset+0x30).toString(16));
sha256_ros = getSHA256hash(buf_po.offset+0x30, helper.patchfile_size);
if(dl_object && buf_po===dl_object.buffer){dl_object.sha256 = sha256_ros;}
updateBuffer(buf_po,sha256_ros);
ulog('SHA256 Extraction Complete');
Logger.info('Patch File '+filename+' SHA256 checksum: '+sha256_ros);
ulog('Patch validation operations complete');
if(sha256_ros!==helper.nofsm_hash){
if(dl_object && buf_po===dl_object.buffer){toast('Patch Download Error','warning',5);}
Logger.warn('Custom patch file detected.');
return 1;
}
else{
Logger.info('official patch file detected.');
return 0;
}
}
function updateValidationGUI(start,filename){
var jQftree = jQuery('#fTree').jstree(true);
if(!jQftree.is_disabled('flashbk')){
jQftree.create_node('flashbk',{'id' : 'rosbk', 'type' : 'ros', 'text' : 'ROS' });
jQftree.create_node('rosbk',{'id' : 'infobk', 'type' : 'info', 'text' : 'SHA256: '+sha256_ros });
jQftree.open_node('rosbk');
jQftree.open_node('flashbk');
}
setTimeout(function(){
helper.sp.playOK();
pbfm1.updateProgressDialog({'dlabel':'Idle','glabel':'Patch File \''+filename+'\' loaded & validated','dvalue':100,'gvalue':100,'istatus':'success-image'},start);
},250);
}
function updateNoValidationGUI(buf_po,start,filename){
helper.sp.playNG();
pbfm1.updateProgressDialog({'glabel':'Loading Operations failed','dlabel':'File validation error','dvalue':100,'gvalue':100,'istatus':'error-image'},start);
Logger.info('Invalid Patch File '+filename);
}
function ulog(ht,clean){
var u = document.getElementById('ulog');
if(clean){u.innerHTML='';}
else{u.innerHTML+='<br>'+ht;}
Logger.info(ht);
}
function dl_cancel(){
helper.swf.cancelDownload();
dl_object=null;
helper.sp.playNG();
}
var so =null;
jQuery('.preloader').removeClass('ui-helper-hidden');
jQuery('#admode').switchButton({
labels_placement: 'left',
//checked: true,
clear: false,
on_label: 'FMM Strict Mode ON ',
off_label: 'FMM Strict Mode OFF',
on_callback: function (){
jQuery(document).tooltip('disable');
helper.fm_usermode = 0;
jQuery(document).tooltip('enable');
},
off_callback: function(){
jQuery(document).tooltip('disable');
function confirmMode(){
helper.fm_usermode = 1;
jQuery(document).tooltip('enable');
}
confirmDialog('YOU SHOULD NEVER TURN FMM Strict Mode OFF!!!<br><br>Only advanced users & developers should ever consider using FMM with strict mode off.You have been warned.','Are you sure you want to continue?',confirmMode,null,function(ck){jQuery('#admode').switchButton('option','checked', ck);jQuery(document).tooltip('enable');},true);
}
});
var sDialog = function(_name){
var sdef = null;
var jQtree = jQuery('#dSTree');
var jQpt_fname = jQuery('input[name=sDialog_FileName]');
var jQlbl_fname = jQuery('label[id=lsDialog_Path]');
var fname = _name ? _name : 'dump.hex';
var sel_path = '';
var jQftree=null;
var sd = this;
var sobj = {
'sector_count': 0x77800, //nand: 0x78000 - nor: 0x8000
'nsec_iter': 0x8000,//nand 0x8000 (16Mb) - nor: 0x2000 (4Mb)
'dump_start': 0,
'save_offset': 0,
'file_path': '/dev_hdd0/dump.hex',
'default_name': 'dump.hex',
'buffer': null
};
var dialogButtons = [{text: 'Save', icon: 'ui-icon-disk', click: function(event, ui){
if(sobj.sector_count){
sobj.file_path = jQlbl_fname[0].innerText;
function confirmDump(){
jQdialog.dialog('close');
jQuery('.preloader').removeClass('ui-helper-hidden');
ldiag.removePatch();
setTimeout(function() {
sobj.buffer = helper.sm.getBuffer();
sobj.tls = helper.worker['fmm'].getTLS();
if(!sobj.buffer){Logger.error('saveDump: Buffer memory allocation failed!');toast('Buffer memory allocation failed','error',5);return;}
if(!sobj.tls){Logger.error('saveDump: TLS memory allocation failed!');toast('TLS memory allocation failed','error',5);return;}
pbfm1.setTitle('Dumping Operations Progress');
pbfm1.open();
setTimeout(function() {
sdef.resolve(sobj);
},1200);
},1000);
}
if(fsitem_exists(sobj.file_path)){
confirmDialog('If you continue, '+sobj.file_path+' will be overwritten','Confirm',confirmDump);
}
else{
confirmDump();
}
}
else if(sobj.idps){
//alert(sobj.idps);
jQdialog.dialog('close');
sobj.file_path = jQlbl_fname[0].innerText;
function confirmSave(){
setTimeout(function() {
sdef.resolve(sobj);
},250);
}
if(fsitem_exists(sobj.file_path)){
confirmDialog('If you continue, '+sobj.file_path+' will be overwritten','Confirm',confirmSave);
}
else{
confirmSave();
}
}
}},{text: 'Cancel', icon: 'ui-icon-close', click: function(event, ui){
jQdialog.dialog('close');
}}];//
jQuery('#dSave_As').removeClass('ui-helper-hidden');
var jQdialog = jQuery('#dSave_As').dialog({
autoOpen: false,
modal: true,
closeOnEscape: false,
resizable: false,
height: 480,
width: 720,
buttons: dialogButtons,
open: function(event, ui ) {
jQftree = jQuery('#fTree').jstree(true);
jQpt_fname = jQuery('input[name=sDialog_FileName]');
jQlbl_fname = jQuery('label[id=lsDialog_Path]');
jQlbl_fname.html('');
jQpt_fname.val(fname);
jQtree.jstree({
'core' : {
'multiple':false,
'restore_focus':false,
'dblclick_toggle':false,
'data' : function (node, cb) {
if(node.type!=='file'){
jQtree.find('i.jstree-ocl').addClass('ui-state-disabled');
var dat = getJSTreeData_fast(this, node, false, true);
//var dat = getJSTreeData_wk(this, node, false, true);
cb(dat===-1? [] : dat);
if(dat===-1 || dat.length>0){
jQtree.find('i.jstree-ocl').removeClass('ui-state-disabled');
this.get_node(node, true).removeClass('jstree-loading').attr('aria-busy',false);
}
}
}
},
'themes':{
'dots': true,
'icons': true
},
'sort' : function(a, b) {
return (this.get_node(a).text > this.get_node(b).text) ? 1 : -1;
},
'types' : {
'#' : {
'max_children' : 12,
'max_depth' : 128,
'valid_children' : ['root']
},
'root' : {
'max_depth' : 127,
'icon' : 'jstree-folder',
'valid_children' : ['folder','file']
},
'folder' : {
'icon' : 'jstree-folder',
'valid_children' : ['folder','file']
},
'file' : {
'icon' : 'jstree-file',
'valid_children' : []
}
},
'plugins' : [
'search', 'types', 'changed', 'unique', 'sort'//, 'wholerow'
]
});
jQtree.on('select_node.jstree', function (e, data) {
var _path = data.instance.get_fullpath(data.node);
if(data.node.type === 'file'){
jQlbl_fname.text(_path);
jQpt_fname.val(data.node.text);
}
else{
if(jQpt_fname.val().length===0){jQpt_fname.val('dump.hex');}
jQlbl_fname.text(_path+'/'+jQpt_fname.val());
}
sel_path = _path.substr(_path.lastIndexOf('/'));
sd.enableSaveButton();
sd.enableSaveText();
});
jQpt_fname.on('change',function(e){
var v = jQpt_fname.val();
if(validateFileName(v)){
jQlbl_fname.text(sel_path+'/');
sd.disableSaveButton();
}
else if(sel_path.length>0){
jQlbl_fname.text(sel_path+'/'+v);
sd.enableSaveButton();
}
else{
jQlbl_fname.text('Please select a destination folder');
sd.disableSaveText();
sd.disableSaveButton();
}
change = false;
});
var change = false;
jQpt_fname.on('input',function(e){
change = true;
});
jQtree.parent().on('click', function (e) {
if(change===true){jQtree.parent().focus();}
});
jQtree.on('click', function (e) {
if(change===true){jQtree.focus();}
});
jQtree.on('after_open.jstree', function (e,data) {
jQtree.find('i.jstree-ocl').removeClass('ui-state-disabled');
data.instance.get_node(data.node, true).removeClass('jstree-loading').attr('aria-busy',false);
});
jQtree.on('load_node.jstree', function (e,data) {
data.instance.get_node(data.node, true).addClass('jstree-loading').attr('aria-busy',true);
data.instance.open_node(data.node);
});
jQtree.on('before_open.jstree', function (e, data) {
data.instance.get_node(data.node, true).addClass('jstree-loading').attr('aria-busy',true);
var nodes_to_close = jQuery.grep(data.instance.get_node(data.node.parent).children, function(elem,index) {
return elem!==data.node ? data.instance.is_open(elem) : false;
});
data.instance.close_node(nodes_to_close);
});
},
beforeClose: function(event, ui ) {
},
close: function(event, ui ) {
jQpt_fname.val(fname);
jQtree.jstree('destroy',true);
}
});
this.setTitle = function(txt){
jQdialog.dialog('option', 'title', txt );
};
this.open = function(obj,func){
sobj = obj ? obj : sobj;
if(sobj.default_name){
fname = sobj.default_name ? sobj.default_name : 'dump.hex';
}
jQdialog.dialog('open');
jQuery('.scbsave').mCustomScrollbar({
theme: (Cookies.get('style')==='eggplant') ? 'light-thick' : 'dark-thick'
});
this.disableSaveButton();
this.disableSaveText();
jQlbl_fname.text('Please select a destination folder');
sdef = jQuery.Deferred();
sdef.promise().done(func);
jQtree.focus();
jQuery('#dSave_As').parent().find('button').blur();
jQuery('#dSave_As').parent().find('.ui-dialog-titlebar-close').prop('title','');
jQuery(document).tooltip();
};
this.close = function(){
jQdialog.dialog('close');
jQuery('.scbsave').find('.mCustomScrollBox').off('mousewheel wheel');
jQuery('.scbsave').mCustomScrollbar('destroy');
//TO-DO:
//Reset dialog features...
};
this.enableSaveText = function(){
jQuery('#sDialog_FileName').removeClass('ui-state-disabled');
};
this.disableSaveText = function(){
jQuery('#sDialog_FileName').removeClass('ui-state-disabled').addClass('ui-state-disabled');
};
this.disableSaveButton= function(){
jQuery('#dSave_As').parent().find('div.ui-dialog-buttonset:first').children('button:first').removeClass('ui-state-disabled').addClass('ui-state-disabled').blur();
};
this.enableSaveButton= function(){
jQuery('#dSave_As').parent().find('div.ui-dialog-buttonset:first').children('button:first').removeClass('ui-state-disabled').focus().blur();
};
};
var lDialog = function(){
var jQtree = jQuery('#dLTree');
var jQpath = jQuery('div[id=dlDialog_Path]');
var lrosFile=null;
var ld = this;
var sha256_ros = '';
var buf_po = null;
var dialogButtons = [
{text: 'Load', icon: 'ui-icon-folder-open', click: function(event, ui){
jQdialog.dialog('close');
var idx = jQpath[0].innerText.lastIndexOf('/');
var filename = jQpath[0].innerText.substr(idx+1,jQpath.text().length-idx-1);
var start = new Date();
ulog(start,true);
pbfm1.open();
pbfm1.updateProgressDialog({'dlabel':'Preparing buffer','glabel':'Loading \''+filename+'\'','dvalue':0,'gvalue':0,'title':'Loading Operations Progress'});
setTimeout(function(){
var jQftree = jQuery('#fTree').jstree(true);
ldiag.removePatch();
sha256_ros = '';
buf_po = helper.sm.getBuffer();
if(!buf_po){Logger.error('loadPatch: Buffer memory allocation failed!');toast('Buffer memory allocation failed','error',5);return;}
lrosFile = new fileObject(jQpath.text());
ulog('Opened File '+jQpath.text());
ulog('Size: 0x'+lrosFile.size.toString(16));
if(lrosFile.size===helper.patchfile_size){
ulog('File Size Check: OK');
pbfm1.updateProgressDialog({'dlabel':'Reading file data','gvalue':0},start);
setTimeout(function(){
Logger.info('loadPatch: loading file '+jQpath.text());
var err = lrosFile.load(helper.patchfile_size,{'offset':buf_po.offset+0x30,'size':helper.patchfile_size});
if(err===0){
ulog('File loaded successfully');
pbfm1.updateProgressDialog({'dlabel':'SHA256 Extraction','glabel':'Validating \''+filename+'\'','dvalue':100,'gvalue':75},start);
//setTimeout(function(){
if(validatePatchFile(buf_po,filename)===1){
var tsttxt = 'The loaded file is a custom patch file. Applying it on this console without a hardware flasher for emergencies is risky & unwise.';
if(!helper.fm_usermode){
toast(tsttxt+' You cannot use it in Strict Mode.','warning',10);
ulog(tsttxt+'<br>You cannot use it in Strict Mode.');
updateNoValidationGUI(buf_po,start,filename);
closure();
return;
}
else{
toast(tsttxt,'warning',5);
ulog('Patch file type: Custom<br>Using this file to patch the console is risky<br>You should consider your next steps carefully.');
}
}
else{
if(helper.kmode==='CEX'){
toast('The loaded file is the recommended patch file for use on this console with the current firmware version','success',5);
ulog('Patch file type: Official CEX');
}
else{
toast('The loaded file is the recommended patch file for CEX mode only. This console is in ('+helper.kmode+') mode, using this patch will brick it.','warning',10);
ulog('Patch file type: Official CEX - NOT compatible with the current mode ('+helper.kmode+') of this console');
}
}
updateValidationGUI(start,filename);
closure();
//},500);
}
else {
ulog('File IO error: 0x'+err.toString(16)+'<br>Loading operations aborted');
updateNoValidationGUI(buf_po,start,filename);
closure();
}
},500);
}
else {
helper.sp.playNG();
pbfm1.updateProgressDialog({'dlabel':'Loading Operations failed','glabel':jQpath.text()+' is not a valid patch file','dvalue':100,'gvalue':100,'istatus':'error-image'},start);
ulog('File Size Check: NG<br>Loading operations aborted');
Logger.info('loadPatch: Invalid File '+jQpath.text());
closure();
}
function closure(){
err = lrosFile.close();
delete lrosFile;
}
},1200);
}},
{text: 'Cancel', icon: 'ui-icon-close', click: function(event, ui){
jQdialog.dialog('close');
}}];//
jQuery('#dLoad').removeClass('ui-helper-hidden');
var jQdialog = jQuery('#dLoad').dialog({
autoOpen: false,
modal: true,
closeOnEscape: false,
resizable: false,
height: 480,
width: 720,
buttons: dialogButtons,
open: function(event, ui ) {
jQtree.jstree({
'core' : {
'multiple':false,
'restore_focus':false,
'dblclick_toggle':false,
'data' : function (node, cb) {
jQtree.find('i.jstree-ocl').addClass('ui-state-disabled');
var dat = getJSTreeData_fast(this, node, true, false);
//var dat = getJSTreeData_wk(this, node, true, false);
cb(dat===-1? [] : dat);
if(dat===-1 || dat.length>0){
jQtree.find('i.jstree-ocl').removeClass('ui-state-disabled');
this.get_node(node, true).removeClass('jstree-loading').attr('aria-busy',false);
}
}
},
'themes':{
'dots': true,
'icons': true
},
'sort' : function(a, b) {
var a1 = this.get_node(a);
var b1 = this.get_node(b);
if (a1.type == b1.type){
return (a1.text > b1.text) ? 1 : -1;
} else {
return (a1.type < b1.type) ? 1 : -1;
}
},
'types' : {
'#' : {
'max_children' : 12,
'max_depth' : 128,
'valid_children' : ['root']
},
'root' : {
'max_depth' : 127,
'icon' : 'jstree-folder',
'valid_children' : ['folder','file']
},
'folder' : {
'icon' : 'jstree-folder',
'valid_children' : ['folder','file']
},
'file' : {
'icon' : 'jstree-file',
'valid_children' : 'none',
'max_children' : 0
}
},
'conditionalselect' : function (node, event) {
if(node.type === 'file'){return true;}
else {return false;}
},
'plugins' : [
'search', 'types', 'changed', 'unique', 'sort', 'conditionalselect'//,
]
});
jQtree.on('activate_node.jstree', function (e, data) {
jQpath.text(data.instance.get_fullpath(data.node));
ld.enableLoadButton();
});
jQtree.on('load_node.jstree', function (e,data) {
data.instance.get_node(data.node, true).addClass('jstree-loading').attr('aria-busy',true);
data.instance.open_node(data.node);
});
jQtree.on('before_open.jstree', function (e, data) {
data.instance.get_node(data.node, true).addClass('jstree-loading').attr('aria-busy',true);
var nodes_to_close = jQuery.grep(data.instance.get_node(data.node.parent).children, function(elem,index) {
return elem!==data.node ? data.instance.is_open(elem) : false;
});
data.instance.close_node(nodes_to_close);
});
jQtree.on('after_open.jstree', function (e,data) {
jQtree.find('i.jstree-ocl').removeClass('ui-state-disabled');
data.instance.get_node(data.node, true).removeClass('jstree-loading').attr('aria-busy',false);
});
},
beforeClose: function(event, ui ) {
},
close: function(event, ui ) {
jQtree.jstree('destroy',true);
}
});
this.setTitle = function(txt){
jQdialog.dialog( 'option', 'title', txt );
};
this.open = function(){
jQdialog.dialog( 'open');
jQuery('.scbload').mCustomScrollbar({
theme: (Cookies.get('style')==='eggplant') ? 'light-thick' : 'dark-thick'
});
jQpath.text('*.*');
this.disableLoadButton();
jQuery('#dLoad').parent().find('.ui-dialog-titlebar-close').prop('title','');
jQuery(document).tooltip();
};
this.close = function(){
jQdialog.dialog('close');
jQuery('.scbload').find('.mCustomScrollBox').off('mousewheel wheel');
jQuery('.scbload').mCustomScrollbar('destroy');
};
this.getSHA256 = function (){
return sha256_ros;
};
this.getBuffer = function(){
return buf_po;
};
this.addPatchInfo = function(buf,sha){
buf_po=buf;
sha256_ros=sha;
};
this.removePatch = function(){
var jQftree = jQuery('#fTree').jstree(true);
var _node = jQftree.get_node('flashbk');
var children = _node ? _node.children : [];
if(children.length>0){
jQftree.delete_node(children);
}
buf_po={'offset':0,'size':0};
};
this.disableLoadButton= function(){
jQuery('#dLoad').parent().find('div.ui-dialog-buttonset:first').children('button:first').removeClass('ui-state-disabled').addClass('ui-state-disabled').blur();
};
this.enableLoadButton= function(){
jQuery('#dLoad').parent().find('div.ui-dialog-buttonset:first').children('button:first').removeClass('ui-state-disabled').focus().blur();
};
};
var fTree = function(close_toast){
var jQtree = jQuery('.fm-tree');
so = so ? so : new storageObject();
helper.minver = getMinVer();
var cfwminver = parseFloat(helper.minver)<3.60;
var metldr = getMtldrVersion(so);
function metldr_err(){
Logger.error('The minimum applicable firmware version does not match the metldr version');
Logger.warn('If the IDPS of your console is spoofed, the minimum applicable firmware version calculated by the system is no longer reliable');
toast('A discrepancy possibly caused by IDPS spoofing was detected in the minimum applicable firmware version returned by the system.','warning',5);
helper.minver += ' !';
}
if(metldr === 'metldr.2' && cfwminver){
metldr_err();
}
else if(metldr === 'metldr' && !cfwminver){
metldr_err();
}
var cfw_compat = metldr!=='metldr.2';
var compat = jQuery('#cfwcompat');
compat.parent().addClass(cfw_compat ? 'header-label on':'header off');
compat.addClass(cfw_compat ? 'fa fa-check fa-lg fa-fw':'fa fa-times fa-lg fa-fw');
compat.css({'color':cfw_compat ? '#99c700':'#e95136','font-size':'20px','width':'30px','position':'relative','padding-top':'1px','text-shadow':'-1px -1px 0 #000,0 -1px 0 #000,1px -1px 0 #000,1px 0 0 #000,1px 1px 0 #000,0 1px 0 #000,-1px 1px 0 #000,-1px 0 0 #000'});
var _nor = so.is_nor();
var idps = getIDPS(so,_nor ? helper.idps_sector_nor : helper.idps_sector_nand);
var XXX = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
var idps_hidden = false;
var jstree;
jQtree.jstree({
'core' : {
'multiple':false,
'restore_focus':false,
'dblclick_toggle':false,
'data' : function (node, cb) {
if(node.id === '#') {
var nodes = [{ 'id' : 'flash', 'type' : 'flash', 'parent' : '#', 'text' : 'Flash Memory' },
{ 'id' : 'type', 'type' : 'ros', 'parent' : 'flash', 'text' : 'Type: ?' },
{ 'id' : 'sectors', 'type' : 'ros', 'parent' : 'flash', 'text' : 'Number of Sectors: ?' },
{ 'id' : 'idps', 'type' : 'ros', 'parent' : 'flash', 'text' : 'IDPS: ?' },
{ 'id' : 'minver', 'type' : 'ros', 'parent' : 'flash', 'text' : 'Minimum Applicable FW Version: ?' },
{ 'id' : 'ros0', 'type' : 'ros', 'parent' : 'flash', 'text' : 'ROS bank 0' },
{ 'id' : 'ros1', 'type' : 'ros', 'parent' : 'flash', 'text' : 'ROS bank 1' },
{ 'id' : 'info0', 'type' : 'info', 'parent' : 'ros0', 'text' : 'Calculating SHA256 checksum, please wait...' },
{ 'id' : 'info1', 'type' : 'info', 'parent' : 'ros1', 'text' : 'Calculating SHA256 checksum, please wait...' },
{ 'id' : 'flashbk', 'type' : 'flash', 'parent' : '#', 'text' : 'Flash Memory Patch' }
];
cb(nodes);
}
},
'check_callback' : function (operation, node, node_parent, node_position, more) {
var ret = false;
switch(operation){
case 'create_node':
ret= true;
break;
case 'rename_node':
ret= true;
break;
case 'delete_node':
ret= true;
break;
case 'move_node':
ret= true;
break;
case 'copy_node':
ret= true;
break;
case 'edit':
ret= true;
break;
default:
ret= false;
}
return ret;
}
},
'themes':{
'dots': true,
'icons': true
},
'sort' : function(a, b) {
return (this.get_node(a).text > this.get_node(b).text) ? 1 : -1;
},
'types' : {
'#' : {
'max_children' : 2,
'max_depth' : 3,
'valid_children' : ['flash']
},
'flash' : {
'max_children' : 2,
'max_depth' : 2,
'icon' : 'jstree-folder',
'valid_children' : ['ros']
},
'ros' : {
'max_children' : 1,
'max_depth' : 1,
'icon' : 'jstree-folder',
'valid_children' : ['info']
},
'info' : {
'max_children' : 0,
'max_depth' : 0,
'icon' : 'jstree-file',
'valid_children' : []
}
},
'contextmenu' :{
'show_at_node':true,
'items': function(node) {
var is_regmode = helper.fm_usermode === 0;
var is_patch_rec = helper.nofsm_hash === ldiag.getSHA256();
var is_cex = helper.kmode === 'CEX';
var _node = jstree.get_node('flashbk');
if(jstree.is_disabled('flashbk') && node.id === 'flashbk'){return {};}
var is_patch_avail = _node ? _node.children.length > 0 ? true : false : false;
var ret = node.id === 'flash' ? {
'Save': {
'separator_before': false,
'separator_after': false,
'label': 'Save Flash Memory Backup',
'icon' : 'fa fa-floppy-o fa-fw',
'action': function (obj) {
setTimeout(function(){
sdiag.open({
'sector_count': _nor ? 0x8000 : 0x77800,
'nsec_iter': _nor ? 0x2000 : 0x8000,//nand 0x8000 (16Mb) - nor: 0x2000 (4Mb)
'dump_start': 0,
'save_offset':0,
'file_path': '',
'default_name': 'dump.hex',
'tls': null,
'buffer': null
},mt_dump);
},0);
}
}
} : (node.id === 'flashbk') ? {
'Load': {
'separator_before': false,
'separator_after': false,
'label': 'Load Patch from file',
'icon' : 'fa fa-folder-open-o fa-fw',
'action': function (obj) {
setTimeout(function(){
ldiag.open();
},0);
}
},
'LoadWeb':{
'separator_before': false,
'separator_after': false,
'label': 'Load Patch via HTTPS',
'_disabled': is_cex ? helper.nofsm_url.length>0 ? false: true : true, //add more checks????
'icon' : 'fa fa-cloud-download fa-fw',
'action': function (obj) {
setTimeout(function(){
jQuery('.preloader').removeClass('ui-helper-hidden');
ldiag.removePatch();
setTimeout(function() {
dl_object = {buffer: helper.sm.getBuffer(),file: helper.nofsm_url,start:new Date(),sha256:''};
ulog(dl_object.start,true);
if(!dl_object.buffer){Logger.error('loadPatch: Buffer memory allocation failed!');toast('Buffer memory allocation failed','error',5);return;}
pbfm1.open(false,dl_cancel);
pbfm1.updateStatusText('Initializing download operations');
pbfm1.updateProgressDialog({'glabel':'Establishing server connection','title':'Download Operations Progress'});
setTimeout(function() {
helper.swf.downloadFile(dl_object.file);//
},500);
},500);
},0);
}
},
'Download':{
'separator_before': false,
'separator_after': false,
'label': 'Download Patch file',
'_disabled': is_cex ? helper.nofsm_url.length>0 ? false: true : true, //add more checks????
'icon' : 'fa fa-download fa-fw',
'action': function (obj) {
document.getElementById('dlframe').src = 'file3.php?tk='+ftoken+'&file='+helper.nofsm_url;
}
},
'Patch': {
'separator_before': true,
'separator_after': false,
'label': 'Apply loaded Patch',
'icon' : 'fa fa-cogs fa-fw',
'_disabled': is_regmode ? is_patch_rec && is_cex && is_patch_avail ? false : true : is_patch_avail ? false : true , //add more checks????
'action': function (obj) {
function confirmPatch(){
jQuery('.preloader').removeClass('ui-helper-hidden');
var def = jQuery.Deferred();
def.promise().done(mt_patch);
setTimeout(function(){
var patch_object = {
'sector_count': 0x7000,
'patch_start': _nor ? 0x600 : 0x400,
'data_buffer': window.ldiag.getBuffer(),
'offset_data':{'ros0':_nor ? 0x20 : 0, 'ros1': _nor ? 0x20 : 0x10}
};
pbfm1.setTitle('Patching Operations Progress');
pbfm1.open(true);
def.resolve(patch_object);
},0);
}
if(!is_patch_rec){ //check against offcial no-fsm patch sha256 ??
confirmDialog('Patching the ps3 Flash Memory with this patch file is allowed because you disabled Strict Mode. Proceeding to patching using this data could be seriously risky, you have been warned. There is no way to pause or cancel the patching process beyond this confirmation dialog. Are you sure you want to continue?','Patch Confirmation',confirmPatch);
}
else{
confirmDialog('Patching the ps3 Flash Memory can brick your console, it should never be done casually. There is no way to pause or cancel the patching process beyond this confirmation dialog. Are you sure you want to continue?','Patch Confirmation',confirmPatch);
}
}
}
}: node.id === 'ros0' || node.id === 'ros1' ? {
'Save_ROS': {
'separator_before': false,
'separator_after': false,
'label': node.id === 'ros0' ? 'Save ROS0 data as noFSM Patch File':'Save ROS1 data as noFSM Patch File',
'icon' : 'fa fa-floppy-o fa-fw',
'_disabled': is_regmode ? true:false,
'action': function (obj) {
setTimeout(function(){
sdiag.open( node.id === 'ros0' ? {
'sector_count': 0x3800,
'nsec_iter': 0x3800,//nand 0x8000 (16Mb) - nor: 0x2000 (4Mb)
'dump_start': _nor ? 0x600:0x400,
'save_offset': _nor ? 0x10:0x30,
'file_path': '',
'default_name': 'ros0.hex',
'buffer': null
}: {
'sector_count': 0x3800,
'nsec_iter': 0x3800,//nand 0x8000 (16Mb) - nor: 0x2000 (4Mb)
'dump_start': _nor ? 0x3E00:0x3C00,
'save_offset': _nor ? 0x10:0x20,
'file_path': '',
'default_name': 'ros1.hex',
'buffer': null
},mt_dump);
},0);
}
}
}: (node.id === 'idps') ? {
'Toggle': {
'separator_before': false,
'separator_after': false,
'label': idps_hidden ? 'Show IDPS': 'Hide IDPS',
'icon' : idps_hidden ? 'fa fa-unlock-alt fa-fw': 'fa fa-lock fa-fw',
'action': function (obj) {
idps_hidden ? jstree.rename_node('idps', 'IDPS: '+idps.toUpperCase()) : jstree.rename_node('idps', 'IDPS: '+XXX);
idps_hidden = !idps_hidden;
//u64 value=0;
//lv2_ss_update_mgr_if(UPDATE_MGR_PACKET_ID_READ_EPROM, QA_FLAG_OFFSET, (uint64_t) &value, 0, 0, 0, 0);
// var rvalue = helper.heap.store(8);
// var scret = helper.rop.rrun(syscall32(863,0x600b,0x48C61,rvalue,0, 0, 0, 0));
// alert('syscall returned 0x'+scret.toString(16));
// alert('value 0x'+helper.memory.upeek32(rvalue).toString(16)+helper.memory.upeek32(rvalue+4).toString(16));
// helper.heap.free([rvalue]);
}
},
'Save':{
'separator_before': false,
'separator_after': false,
'label': 'Save IDPS as file',
'icon' : 'fa fa-floppy-o fa-fw',
'action': function (obj) {
setTimeout(function(){
sdiag.open( {
'file_path': '',
'idps':idps,
'default_name': 'idps.hex'
},idps_dump);
},0);
}
}
}:{};
return ret;
}
},
'conditionalselect' : function (node, event) {
if(node.type === 'flash' || node.id === 'ros0' || node.id === 'ros1'|| node.id === 'idps'){return true;}
else {return false;}
},
'plugins' : [
'search', 'types', 'changed', 'contextmenu', 'unique', 'sort', 'conditionalselect'//,
]
});
jQtree.on('select_node.jstree', function (e, data) {
var evt = window.event || e;
var button = evt.which || evt.button;
if( button != 1 && ( typeof button != 'undefined'))
return false;
else if(data.event){
setTimeout(function() {
data.instance.show_contextmenu(data.node, evt.offsetX,evt.offsetY, data.event);
}, 0);
return true;
}
});
//alert('fmm ros hashing');
jstree = jQtree.jstree(true);
jstree.rename_node('type', _nor ? 'Flash Memory Type: NOR 16Mb' : cfw_compat ? 'Flash Memory Type: NAND 256Mb':'Flash Memory Type: eMMC 256Mb');
jstree.rename_node('sectors', _nor ? 'Number of Sectors: 0x8000' : 'Number of Sectors: 0x80000 (0x77800 in dump)');
jstree.rename_node('idps', 'IDPS: '+idps.toUpperCase());
if(!cfw_compat){jstree.disable_node('flashbk');}
var ros0_ref = '';
var ros1_ref = '';
var ros0_new = '';
var ros1_new = '';
var sha256_ref = '';
var sha256_pending = false;
this.refreshFM_node = function(cb){
//alert('fmm refreshFM_node');
sha256_pending = true;
jstree.rename_node('info0','Calculating SHA256 checksum, please wait...');
jstree.rename_node('info1','Calculating SHA256 checksum, please wait...');
var sbuf = helper.sm.getBuffer();
if(!sbuf){
helper.sp.playNG();
Logger.error('SHA256 Extraction failed. No buffer available.');
toast('If the toolset keeps getting errors when allocating buffer memory, you should restart the console.','error',5);
jQuery().toastmessage('removeToast', close_toast);
jQuery('.preloader').removeClass('ui-helper-hidden').addClass('ui-helper-hidden');
return;
}
//alert('sbuf: 0x'+sbuf.offset.toString(16)+' - size 0x'+sbuf.size.toString(16));
var tl = helper.worker['fmm'].getTLS();
if(!tl){
Logger.error('SHA256 Extraction: TLS memory allocation failed!');
toast('TLS memory allocation failed','error',5);
return;
}
//alert('fmm ROSHashObject');
var rosH = new ROSHashObject(so,{'dump_start':so.is_nor() ? 0x600: 0x400,'data_buffer':sbuf,'tls':tl});
if(rosH.error.code>0){
Logger.error('SHA256 Extraction: ROSHashObject creation failed!');
toast('SHA256 Extraction failed','error',5);
return;
}
//TO-DO:
//Show spinner
function sha256_cleanup(){
//alert('sha256_cleanup');
so.close();
delete rosH;
enable_GUI();
jQuery().toastmessage('removeToast', close_toast);
jQuery('.refresh-fm').removeClass('ui-state-disabled');
jQuery('.preloader').removeClass('ui-helper-hidden').addClass('ui-helper-hidden');
}
function sha256_error(str){
//alert(str);
jstree.rename_node('info0','SHA256: Extraction Error');
jstree.rename_node('info1','SHA256: Extraction Error');
jstree.rename_node('minver','Minimum Applicable Firmware Version: '+helper.minver);
jstree.open_all('flash');
sha256_pending = false;
sha256_cleanup();
}
ros0_ref = ros0_new;
ros1_ref = ros1_new;
//alert('fmm workers call 1');
helper.worker['fmm'].run(rosH.sfx[0],'ROS Data Extraction',function(){Logger.info('Extracting data from Flash Memory ROS regions');},function(){
//alert('fmm ros data extraction');
function checkArr(arr,val){
var good=true;
for(var st=0;st<arr.length;st++){
if(helper.memory.upeek32(arr[st])===val){
//alert('problem at index 0x'+st.toString(16)+' Offset: 0x'+arr[st].toString(16));
good=false;
break;
}
}
return good;
}
if(!checkArr(rosH.rlen,0xFFFFFFFF)){
sha256_error('ROS Extraction error');
return;
}