-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
15197 lines (12978 loc) · 469 KB
/
Copy pathmain.c
File metadata and controls
15197 lines (12978 loc) · 469 KB
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
#include <sdk_version.h>
#include <cellstatus.h>
#include <cell/cell_fs.h>
#include <cell/rtc.h>
#include <cell/gcm.h>
#include <cell/pad.h>
#include <sys/vm.h>
#include <sysutil/sysutil_common.h>
#include <sys/prx.h>
#include <sys/ppu_thread.h>
#include <sys/event.h>
#include <sys/syscall.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/memory.h>
#include <sys/timer.h>
#include <sys/process.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <netex/net.h>
#include <netex/errno.h>
#include <netex/libnetctl.h>
#include <netex/sockinfo.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include "flags.h"
#include "types.h"
#include "common.h"
#include "cobra/cobra.h"
#include "cobra/storage.h"
#include "vsh/game_plugin.h"
#ifdef EXTRA_FEAT
#include "vsh/system_plugin.h"
#endif
#define _game_TitleID _game_info+0x04
#define _game_Title _game_info+0x14
static char _game_info[0x120];
static char search_url[50] = "http://google.com/search?q=";
#ifdef COBRA_ONLY
#include "cobra/netiso.h"
#ifdef LITE_EDITION
#define EDITION " [Lite]"
#else
#ifdef PS3MAPI
#ifdef REX_ONLY
#define EDITION " [Rebug-PS3MAPI]"
#else
#define EDITION " [PS3MAPI]"
#endif
#else
#ifdef REX_ONLY
#define EDITION " [Rebug]"
#else
#define EDITION ""
#endif
#endif
#endif
#else
#ifdef CCAPI
#define EDITION " [CCAPI]"
#else
#define EDITION " [nonCobra]"
#endif
#endif
SYS_MODULE_INFO(WWWD, 0, 1, 0);
SYS_MODULE_START(wwwd_start);
SYS_MODULE_STOP(wwwd_stop);
#define VSH_MODULE_PATH "/dev_blind/vsh/module/"
#define VSH_ETC_PATH "/dev_blind/vsh/etc/"
#define PS2_EMU_PATH "/dev_blind/ps2emu/"
#define REBUG_COBRA_PATH "/dev_blind/rebug/cobra/"
#define HABIB_COBRA_PATH "/dev_blind/habib/cobra/"
#define SYS_COBRA_PATH "/dev_blind/sys/"
#define PS2_CLASSIC_TOGGLER "/dev_hdd0/classic_ps2"
#define REBUG_TOOLBOX "/dev_hdd0/game/RBGTLBOX2/USRDIR/"
#define COLDBOOT_PATH "/dev_blind/vsh/resource/coldboot.raf"
#define ORG_LIBFS_PATH "/dev_flash/sys/external/libfs.sprx"
#define NEW_LIBFS_PATH "/dev_hdd0/tmp/libfs.sprx"
#define PS2_CLASSIC_PLACEHOLDER "/dev_hdd0/game/PS2U10000/USRDIR"
#define PS2_CLASSIC_ISO_PATH "/dev_hdd0/game/PS2U10000/USRDIR/ISO.BIN.ENC"
#define PS2_CLASSIC_ISO_ICON "/dev_hdd0/game/PS2U10000/ICON0.PNG"
#define WM_VERSION "1.41.41 MOD" // webMAN version
#define MM_ROOT_STD "/dev_hdd0/game/BLES80608/USRDIR" // multiMAN root folder
#define MM_ROOT_SSTL "/dev_hdd0/game/NPEA00374/USRDIR" // multiman SingStar® Stealth root folder
#define MM_ROOT_STL "/dev_hdd0/tmp/game_repo/main" // stealthMAN root folder
#define WMCONFIG "/dev_hdd0/tmp/wmconfig.bin" // webMAN config file
#define WMTMP "/dev_hdd0/tmp/wmtmp" // webMAN work/temp folder
#define WM_ICONS_PATH "/dev_hdd0/tmp/wm_icons/" // webMAN icons path
#define WMNOSCAN "/dev_hdd0/tmp/wm_noscan" // webMAN config file
#ifdef WEB_CHAT
#define WMCHATFILE "/dev_hdd0/tmp/wmtmp/wmchat.htm"
#define DELETE_TURNOFF {do_umount(false); cellFsUnlink((char*)"/dev_hdd0/tmp/turnoff"); cellFsUnlink((char*)WMCHATFILE);}
#else
#define DELETE_TURNOFF {do_umount(false); cellFsUnlink((char*)"/dev_hdd0/tmp/turnoff");}
#endif
#define THREAD_NAME "wwwdt"
#define THREAD_NAME_FTP "ftpdt"
#define THREAD_NAME_NET "netiso"
#define THREAD_NAME_NTFS "ntfsd"
#define STOP_THREAD_NAME "wwwds"
////////////
#define HTML_BASE_PATH "/dev_hdd0/xmlhost/game_plugin"
#define FB_XML HTML_BASE_PATH "/fb.xml"
#define MY_GAMES_XML HTML_BASE_PATH "/mygames.xml"
#define MOBILE_HTML HTML_BASE_PATH "/mobile.html"
#define GAMELIST_JS HTML_BASE_PATH "/gamelist.js"
#define DELETE_CACHED_GAMES {cellFsUnlink((char*)WMTMP "/games.html"); cellFsUnlink((char*)GAMELIST_JS);}
#define XML_HEADER "<?xml version=\"1.0\" encoding=\"UTF-8\"?><XMBML version=\"1.0\">"
#define XML_PAIR(key, value) "<Pair key=\"" key "\"><String>" value "</String></Pair>"
#define QUERY_XMB(key, src) "<Query class=\"type:x-xmb/folder-pixmap\" key=\"" key "\" attr=\"" key "\" src=\"" src "\"/>"
#define ADD_XMB_ITEM(key) "<Item class=\"type:x-xmb/module-action\" key=\"" key "\" attr=\"" key "\"/>"
#define ITEM_CHECKED " checked=\"checked\""
#define ITEM_SELECTED " selected=\"selected\""
#define WEB_LINK_PAIR XML_PAIR("module_name", "webbrowser_plugin")
#define STR_NOITEM_PAIR XML_PAIR("str_noitem", "msg_error_no_content") "</Table>"
#define HTML_DIR "<dir>"
#define HTML_BUTTON_FMT "%s%s\" %s'%s';\">"
#define HTML_BUTTON " <input type=\"button\" value=\""
#define HTML_ONCLICK "onclick=\"window.location.href="
#define HTML_INPUT(n, v, m, s) "<input name=\"" n "\" type=\"text\" value=\"" v "\" maxlength=\"" m "\" size=\"" s "\">"
////////////
#define SC_PEEK_LV2 (6)
#define SC_POKE_LV2 (7)
#define SC_PEEK_LV1 (8)
#define SC_POKE_LV1 (9)
#define SC_COBRA_SYSCALL8 (8)
#define SC_GET_FREE_MEM (352)
#define SC_SYS_CONTROL_LED (386)
#define SC_GET_PLATFORM_INFO (387)
#define SC_RING_BUZZER (392)
#define SC_SET_FAN_POLICY (389)
#define SC_GET_FAN_POLICY (409)
#define SC_GET_TEMPERATURE (383)
#define SC_STORAGE_OPEN (600)
#define SC_STORAGE_CLOSE (601)
#define SC_STORAGE_INSERT_EJECT (616)
#define SC_FS_LINK (810)
#define SC_FS_MOUNT (837)
#define SC_FS_UMOUNT (838)
#define SC_GET_IDPS (870)
#define SC_GET_PSID (872)
#define SC_GET_CONSOLE_TYPE (985)
#define SC_GET_PRX_MODULE_BY_ADDRESS (461)
#define SC_STOP_PRX_MODULE (482)
#define SC_UNLOAD_PRX_MODULE (483)
#define SC_PPU_THREAD_EXIT (41)
#define SC_SYS_POWER (379)
#define SYS_SOFT_REBOOT 0x0200
#define SYS_HARD_REBOOT 0x1200
#define SYS_REBOOT 0x8201 /*load LPAR id 1*/
#define SYS_SHUTDOWN 0x1100
#define SYS_NET_EURUS_POST_COMMAND (726)
#define CMD_GET_MAC_ADDRESS 0x103f
#define BEEP1 { system_call_3(SC_RING_BUZZER, 0x1004, 0x4, 0x6); }
#define BEEP2 { system_call_3(SC_RING_BUZZER, 0x1004, 0x7, 0x36); }
#define BEEP3 { system_call_3(SC_RING_BUZZER, 0x1004, 0xa, 0x1b6); }
#ifdef PS3MAPI
///////////// PS3MAPI BEGIN //////////////
#define PS3MAPI_SERVER_VERSION 0x0120
#define PS3MAPI_SERVER_MINVERSION 0x0120
#define PS3MAPI_WEBUI_VERSION 0x0121
#define PS3MAPI_WEBUI_MINVERSION 0x0120
#define PS3MAPI_CORE_MINVERSION 0x0111
#define SYSCALL8_OPCODE_PS3MAPI 0x7777
#define PS3MAPI_OPCODE_GET_CORE_VERSION 0x0011
#define PS3MAPI_OPCODE_GET_CORE_MINVERSION 0x0012
#define PS3MAPI_OPCODE_GET_FW_TYPE 0x0013
#define PS3MAPI_OPCODE_GET_FW_VERSION 0x0014
#define PS3MAPI_OPCODE_GET_ALL_PROC_PID 0x0021
#define PS3MAPI_OPCODE_GET_PROC_NAME_BY_PID 0x0022
#define PS3MAPI_OPCODE_GET_PROC_BY_PID 0x0023
#define PS3MAPI_OPCODE_GET_CURRENT_PROC 0x0024
#define PS3MAPI_OPCODE_GET_CURRENT_PROC_CRIT 0x0025
#define PS3MAPI_OPCODE_GET_PROC_MEM 0x0031
#define PS3MAPI_OPCODE_SET_PROC_MEM 0x0032
#define PS3MAPI_OPCODE_GET_ALL_PROC_MODULE_PID 0x0041
#define PS3MAPI_OPCODE_GET_PROC_MODULE_NAME 0x0042
#define PS3MAPI_OPCODE_GET_PROC_MODULE_FILENAME 0x0043
#define PS3MAPI_OPCODE_LOAD_PROC_MODULE 0x0044
#define PS3MAPI_OPCODE_UNLOAD_PROC_MODULE 0x0045
#define PS3MAPI_OPCODE_UNLOAD_VSH_PLUGIN 0x0046
#define PS3MAPI_OPCODE_GET_VSH_PLUGIN_INFO 0x0047
#define PS3MAPI_OPCODE_GET_IDPS 0x0081
#define PS3MAPI_OPCODE_SET_IDPS 0x0082
#define PS3MAPI_OPCODE_GET_PSID 0x0083
#define PS3MAPI_OPCODE_SET_PSID 0x0084
#define PS3MAPI_OPCODE_CHECK_SYSCALL 0x0091
#define PS3MAPI_OPCODE_DISABLE_SYSCALL 0x0092
#define PS3MAPI_OPCODE_PDISABLE_SYSCALL8 0x0093
#define PS3MAPI_OPCODE_PCHECK_SYSCALL8 0x0094
#define PS3MAPI_OPCODE_REMOVE_HOOK 0x0101
///////////// PS3MAPI END //////////////
#endif
#define WWWPORT (80)
#define FTPPORT (21)
#define ssend(socket, str) send(socket, str, strlen(str), 0)
#define getPort(p1x, p2x) ((p1x * 256) + p2x)
#define KB 1024UL
#define _4KB_ 4096UL
#define _8KB_ 8192UL
#define _32KB_ 32768UL
#define _64KB_ 65536UL
#define _128KB_ 131072UL
#define _192KB_ 196608UL
#define _256KB_ 262144UL
#define _1MB_ 1048576UL
#define _32MB_ 33554432UL
#define MIN_MEM _192KB_
#define MODE 0777
#define LINELEN 512 // file listing
#define MAX_LINE_LEN 640 // html games
#define MAX_PATH_LEN 512 // do not change!
#define FAILED -1
#define FTP_RECV_SIZE 1024
#define HTML_RECV_SIZE 2048
static u32 BUFFER_SIZE_FTP = ( _128KB_);
static u32 BUFFER_SIZE = ( 448*KB);
static u32 BUFFER_SIZE_PSX = ( 160*KB);
static u32 BUFFER_SIZE_PSP = ( _32KB_);
static u32 BUFFER_SIZE_PS2 = ( _64KB_);
static u32 BUFFER_SIZE_DVD = ( _192KB_);
static u32 BUFFER_SIZE_ALL = ( 896*KB);
#ifdef COBRA_ONLY
#ifndef LITE_EDITION
static sys_ppu_thread_t thread_id_net =-1;
#endif
static sys_ppu_thread_t thread_id_ntfs =-1;
#endif
static sys_ppu_thread_t thread_id_poll =-1;
static sys_ppu_thread_t thread_id_ftp =-1;
static sys_ppu_thread_t thread_id =-1;
#define SUFIX(a) ((a==1)? "_1" :(a==2)? "_2" :(a==3)? "_3" :(a==4)?"_4":"")
#define SUFIX2(a) ((a==1)?" (1)":(a==2)?" (2)":(a==3)?" (3)":(a==4)?" (4)":"")
#define SUFIX3(a) ((a==1)?" (1).ntfs[":(a==2)?" (2).ntfs[":(a==3)?" (3).ntfs[":(a==4)?" (4).ntfs[":"")
#define IS_ISO_FOLDER (f1>1 && f1<10)
#define IS_PS3_FOLDER (f1<3 || f1>=10)
#define IS_BLU_FOLDER (f1==3)
#define IS_DVD_FOLDER (f1==4)
#define IS_PS2_FOLDER (f1==5)
#define IS_PSX_FOLDER (f1==6 || f1==7)
#define IS_PSP_FOLDER (f1==8 || f1==9)
#define MIN(a, b) ((a) <= (b) ? (a) : (b))
#define ABS(a) (((a) < 0) ? -(a) : (a))
#define RANGE(a, b, c) ((a) <= (b) ? (b) : (a) >= (c) ? (c) : (a))
#define CD_CACHE_SIZE (64)
#define ATA_HDD 0x101000000000007ULL
#define BDVD_DRIVE 0x101000000000006ULL
#define PATA0_HDD_DRIVE 0x101000000000008ULL
#define PATA0_BDVD_DRIVE BDVD_DRIVE
#define PATA1_HDD_DRIVE ATA_HDD
#define PATA1_BDVD_DRIVE 0x101000000000009ULL
#define BUILTIN_FLASH 0x100000000000001ULL
#define MEMORY_STICK 0x103000000000010ULL
#define SD_CARD 0x103000100000010ULL
#define COMPACT_FLASH 0x103000200000010ULL
#define USB_MASS_STORAGE_1(n) (0x10300000000000AULL+n) /* For 0-5 */
#define USB_MASS_STORAGE_2(n) (0x10300000000001FULL+(n-6)) /* For 6-127 */
#define HDD_PARTITION(n) (ATA_HDD | ((uint64_t)n<<32))
#define FLASH_PARTITION(n) (BUILTIN_FLASH | ((uint64_t)n<<32))
#define DEVICE_TYPE_PS3_DVD 0xFF70
#define DEVICE_TYPE_PS3_BD 0xFF71
#define DEVICE_TYPE_PS2_CD 0xFF60
#define DEVICE_TYPE_PS2_DVD 0xFF61
#define DEVICE_TYPE_PSX_CD 0xFF50
#define DEVICE_TYPE_BDROM 0x40
#define DEVICE_TYPE_BDMR_SR 0x41 /* Sequential record */
#define DEVICE_TYPE_BDMR_RR 0x42 /* Random record */
#define DEVICE_TYPE_BDMRE 0x43
#define DEVICE_TYPE_DVD 0x10 /* DVD-ROM, DVD+-R, DVD+-RW etc, they are differenced by booktype field in some scsi command */
#define DEVICE_TYPE_CD 0x08 /* CD-ROM, CD-DA, CD-R, CD-RW, etc, they are differenced somehow with scsi commands */
#define DEVICE_TYPE_USB 0x00
#define IS_COPY 9
#define COPY_WHOLE_FILE 0
#ifdef EXT_GDATA
#define MOUNT_EXT_GDATA 2
#endif
#define START_DAEMON (0xC0FEBABE)
#define REFRESH_CONTENT (0xC0FEBAB0)
#define LV1_UPPER_MEMORY 0x8000000010000000ULL
#define LV2_UPPER_MEMORY 0x8000000000800000ULL
enum FIX_GAME_MODES
{
FIX_GAME_AUTO,
FIX_GAME_QUICK,
FIX_GAME_FORCED,
FIX_GAME_DISABLED
};
enum STORAGE_COMMAND
{
CMD_READ_ISO,
CMD_READ_DISC,
CMD_READ_CD_ISO_2352,
CMD_FAKE_STORAGE_EVENT,
CMD_GET_PSX_VIDEO_MODE
};
#ifdef COBRA_ONLY
#ifndef LITE_EDITION
typedef struct
{
char server[0x40];
char path[0x420];
uint32_t emu_mode;
uint32_t num_tracks;
uint16_t port;
uint8_t pad[6];
ScsiTrackDescriptor tracks[1];
} __attribute__((packed)) netiso_args;
int connect_to_remote_server(u8 server_id);
#endif
typedef struct
{
uint64_t device;
uint32_t emu_mode;
uint32_t num_sections;
uint32_t num_tracks;
} __attribute__((packed)) rawseciso_args;
static sys_device_info_t disc_info;
static uint32_t *sections, *sections_size;
static uint32_t num_sections;
uint64_t sector_size = 0x200;
uint32_t handle = -1;
static sys_event_queue_t command_queue_ntfs = -1;
static u8 netiso_loaded=0;
static u8 rawseciso_loaded=0;
#endif
typedef struct {
uint32_t total;
uint32_t avail;
} _meminfo;
//static bool is_rebug = false;
static u8 profile = 0;
#ifdef EXT_GDATA
static u8 extgd = 0; //external gameDATA
#endif
static u8 loading_html = 0;
static u8 loading_games = 0;
static u8 init_running = 0;
#ifdef COBRA_ONLY
#ifndef LITE_EDITION
static int g_socket = -1;
static sys_event_queue_t command_queue = -1;
#endif
#define CD_SECTOR_SIZE_2048 2048
static u32 CD_SECTOR_SIZE_2352 = 2352;
static uint64_t discsize=0;
static int is_cd2352=0;
static uint8_t *cd_cache=0;
static uint32_t cached_cd_sector=0x80000000;
#endif
#define NTFS (10)
#define MIN_FANSPEED (20)
#define DEFAULT_MIN_FANSPEED (25)
#define MAX_FANSPEED (0xE6)
#define MY_TEMP (68)
static u8 fan_speed=0x33;
static u8 old_fan=0x33;
static u32 max_temp=MY_TEMP;
static bool fan_ps2_mode=false; // temporary disable dynamic fan control
#define MAX_LAST_GAMES (5)
typedef struct
{
uint8_t last;
char game[MAX_LAST_GAMES][MAX_PATH_LEN];
} __attribute__((packed)) _lastgames;
#ifdef USE_DEBUG
static int debug_s=-1;
static char debug[256];
#endif
static volatile u8 wm_unload_combo = 0;
static volatile u8 working = 1;
static u8 cobra_mode=0;
static u8 max_mapped=0;
static float c_firmware=0.0f;
static u8 dex_mode=0;
static u64 SYSCALL_TABLE = 0;
#ifndef COBRA_ONLY
static u64 base_addr=0;
static u64 open_hook=0;
typedef struct
{
char src[384];
char dst[384];
} redir_files_struct;
static redir_files_struct file_to_map[10];
#endif
typedef struct
{
uint8_t usb0;
uint8_t usb1;
uint8_t usb2;
uint8_t usb3;
uint8_t usb6;
uint8_t usb7;
uint8_t netd0;
uint8_t lastp;
uint8_t autob;
uint8_t delay;
uint8_t bootd;
uint8_t boots;
uint8_t blind;
uint8_t nogrp;
uint8_t noset;
uint8_t cmask;
uint32_t netp0;
char neth0[16];
uint8_t poll;
uint8_t ftpd;
uint8_t warn;
uint8_t fanc;
uint8_t temp1;
uint8_t rxvid;
uint8_t bind;
uint8_t refr;
uint8_t manu;
uint8_t temp0;
uint8_t netd1;
uint32_t netp1;
char neth1[16];
uint8_t foot;
uint8_t nopad;
uint8_t nocov;
uint8_t nospoof;
uint8_t ps2temp;
uint8_t pspl;
uint8_t minfan;
uint16_t combo;
uint8_t sidps;
uint8_t spsid;
uint8_t spp;
uint8_t lang;
char vIDPS1[17];
char vIDPS2[17];
char vPSID1[17];
char vPSID2[17];
uint8_t tid;
uint8_t wmdn;
char autoboot_path[256];
uint8_t ps2l;
uint32_t combo2;
uint8_t homeb;
char home_url[256];
uint8_t netd2;
uint32_t netp2;
char neth2[16];
uint8_t profile;
char uaccount[9];
char allow_ip[16];
uint8_t noss;
uint8_t fixgame;
uint8_t bus;
uint8_t dev_sd;
uint8_t dev_ms;
uint8_t dev_cf;
uint8_t ps1emu;
} __attribute__((packed)) WebmanCfg;
//combo
#define FAIL_SAFE (1<<0)
#define SHOW_TEMP (1<<1)
#define PREV_GAME (1<<2)
#define NEXT_GAME (1<<3)
#define SHUT_DOWN (1<<4)
#define RESTARTPS (1<<5)
#define UNLOAD_WM (1<<6)
#define MANUALFAN (1<<7)
#define SHOW_IDPS (1<<8)
#define DISABLESH (1<<9)
#define DISABLEFC (1<<10)
#define MINDYNFAN (1<<11)
#define DISACOBRA (1<<12)
//combo2
#define EXTGAMDAT (1<<0)
#define MOUNTNET0 (1<<1)
#define MOUNTNET1 (1<<2)
#define PS2TOGGLE (1<<3)
#define PS2SWITCH (1<<4)
#define BLOCKSVRS (1<<5)
#define XMLREFRSH (1<<6)
#define UMNT_GAME (1<<7)
#define VIDRECORD (1<<8)
#define REBUGMODE (1<<13)
#define NORMAMODE (1<<14)
#define DEBUGMENU (1<<15)
#define AUTOBOOT_PATH "/dev_hdd0/PS3ISO/AUTOBOOT.ISO"
#ifdef COBRA_ONLY
#define DEFAULT_AUTOBOOT_PATH "/dev_hdd0/PS3ISO/AUTOBOOT.ISO"
#else
#define DEFAULT_AUTOBOOT_PATH "/dev_hdd0/GAMES/AUTOBOOT"
#endif
#define ISO_EXTENSIONS ".iso.cue.img.mdf.bin"
uint64_t idps_offset1=0;
uint64_t idps_offset2=0;
uint64_t psid_offset=0;
uint64_t get_fan_policy_offset=0;
uint64_t set_fan_policy_offset=0;
static CellRtcTick rTick, gTick;
static int set_gamedata_status(u8 status, bool do_mount);
static void set_buffer_sizes(int footprint);
static void get_idps_psid(void);
static void enable_dev_blind(char *msg);
#ifdef NOSINGSTAR
static void no_singstar_icon(void);
#endif
#ifdef COBRA_ONLY
static void select_ps1emu(void);
uint64_t getlba(const char *s1, u16 n1, const char *s2, u16 n2, u16 start);
void fix_iso(char *iso_file, uint64_t maxbytes, bool patch_update);
#endif
int extcmp(const char *s1, const char *s2, size_t n);
int extcasecmp(const char *s1, const char *s2, size_t n);
char *strcasestr(const char *s1, const char *s2);
static void refresh_xml(char *msg);
static void reset_settings(void);
static int save_settings(void);
static u64 backup[6];
static u8 wmconfig[sizeof(WebmanCfg)];
static WebmanCfg *webman_config = (WebmanCfg*) wmconfig;
static bool gmobile_mode = false;
static char ftp_password[20]="";
static char html_base_path[MAX_PATH_LEN]="";
static char smonth[12][4]={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static char drives[14][12]={"/dev_hdd0", "/dev_usb000", "/dev_usb001", "/dev_usb002", "/dev_usb003", "/dev_usb006", "/dev_usb007", "/net0", "/net1", "/net2", "/ext", "/dev_sd", "/dev_ms", "/dev_cf"};
static char paths [11][12]={"GAMES", "GAMEZ", "PS3ISO", "BDISO", "DVDISO", "PS2ISO", "PSXISO", "PSXGAMES", "PSPISO", "ISO", "video"};
static char wm_icons[12][60]={WM_ICONS_PATH "icon_wm_album_ps3.png", //024.png [0]
WM_ICONS_PATH "icon_wm_album_psx.png", //026.png [1]
WM_ICONS_PATH "icon_wm_album_ps2.png", //025.png [2]
WM_ICONS_PATH "icon_wm_album_psp.png", //022.png [3]
WM_ICONS_PATH "icon_wm_album_dvd.png", //023.png [4]
WM_ICONS_PATH "icon_wm_ps3.png", //024.png [5]
WM_ICONS_PATH "icon_wm_psx.png", //026.png [6]
WM_ICONS_PATH "icon_wm_ps2.png", //025.png [7]
WM_ICONS_PATH "icon_wm_psp.png", //022.png [8]
WM_ICONS_PATH "icon_wm_dvd.png", //023.png [9]
WM_ICONS_PATH "icon_wm_settings.png", //icon/icon_home.png [10]
WM_ICONS_PATH "icon_wm_eject.png" //icon/icon_home.png [11]
};
static bool covers_exist[7];
static char local_ip[16] = "127.0.0.1";
uint64_t convertH(char *val);
//uint64_t find_syscall();
//uint64_t search64(uint64_t val);
//uint64_t find_syscall_table();
#define SYSCALLS_UNAVAILABLE 0xFFFFFFFF80010003ULL
uint64_t IDPS[2] = {0, 0};
uint64_t PSID[2] = {0, 0};
int lang_pos, fh;
#ifdef ENGLISH_ONLY
static char STR_HOME[8] = "Home";
#define STR_TRADBY "<br>"
#define STR_FILES "Files"
#define STR_GAMES "Games"
#define STR_SETUP "Setup"
#define STR_EJECT "Eject"
#define STR_INSERT "Insert"
#define STR_UNMOUNT "Unmount"
#define STR_COPY "Copy Folder"
#define STR_REFRESH "Refresh"
#define STR_SHUTDOWN "Shutdown"
#define STR_RESTART "Restart"
#define STR_BYTE "b"
#define STR_KILOBYTE "KB"
#define STR_MEGABYTE "MB"
#define STR_GIGABYTE "GB"
#define STR_COPYING "Copying"
#define STR_CPYDEST "Destination"
#define STR_CPYFINISH "Copy Finished!"
#define STR_CPYABORT "Copy aborted!"
#define STR_DELETE "Delete"
#define STR_SCAN1 "Scan these devices"
#define STR_SCAN2 "Scan for content"
#define STR_PSPL "Show PSP Launcher"
#define STR_PS2L "Show PS2 Classic Launcher"
#define STR_RXVID "Show Video sub-folder"
#define STR_VIDLG "Video"
#define STR_LPG "Load last-played game on startup"
#define STR_AUTOB "Check for /dev_hdd0/PS3ISO/AUTOBOOT.ISO on startup"
#define STR_DELAYAB "Delay loading of AUTOBOOT.ISO/last-game (Disc Auto-start)"
#define STR_DEVBL "Enable /dev_blind (writable /dev_flash) on startup"
#define STR_CONTSCAN "Disable content scan on startup"
#define STR_USBPOLL "Disable USB polling"
#define STR_FTPSVC "Disable FTP service"
#define STR_FIXGAME "Disable auto-fix game"
#define STR_COMBOS "Disable all PAD shortcuts"
#define STR_MMCOVERS "Disable multiMAN covers"
#define STR_ACCESS "Disable remote access to FTP/WWW services"
#define STR_NOSETUP "Disable webMAN Setup entry in \"webMAN Games\""
#define STR_NOSPOOF "Disable firmware version spoofing"
#define STR_NOGRP "Disable grouping of content in \"webMAN Games\""
#define STR_NOWMDN "Disable startup notification of WebMAN on the XMB"
#ifdef NOSINGSTAR
#define STR_NOSINGSTAR "Remove SingStar icon"
#endif
#define STR_RESET_USB "Disable Reset USB Bus"
#define STR_TITLEID "Include the ID as part of the title of the game"
#define STR_FANCTRL "Enable dynamic fan control"
#define STR_NOWARN "Disable temperature warnings"
#define STR_AUTOAT "Auto at"
#define STR_LOWEST "Lowest"
#define STR_FANSPEED "fan speed"
#define STR_MANUAL "Manual"
#define STR_PS2EMU "PS2 Emulator"
#define STR_LANGAMES "Scan for LAN games/videos"
#define STR_ANYUSB "Wait for any USB device to be ready"
#define STR_ADDUSB "Wait additionally for each selected USB device to be ready"
#define STR_SPOOFID "Change idps and psid in lv2 memory at system startup"
#define STR_DELCFWSYS "Disable lv1&lv2 peek&poke syscalls (6,7,9,10,36) and delete history files at system startup"
#define STR_MEMUSAGE "Plugin memory usage"
#define STR_PLANG "Plugin language"
#define STR_PROFILE "Profile"
#define STR_DEFAULT "Default"
#define STR_COMBOS2 "XMB/In-Game PAD SHORTCUTS"
#define STR_FAILSAFE "FAIL SAFE"
#define STR_SHOWTEMP "SHOW TEMP"
#define STR_SHOWIDPS "SHOW IDPS"
#define STR_PREVGAME "PREV GAME"
#define STR_NEXTGAME "NEXT GAME"
#define STR_SHUTDOWN2 "SHUTDOWN "
#define STR_RESTART2 "RESTART "
#define STR_DELCFWSYS2 "DEL CFW SYSCALLS"
#define STR_UNLOADWM "UNLOAD WM"
#define STR_FANCTRL2 "CTRL FAN"
#define STR_FANCTRL4 "CTRL DYN FAN"
#define STR_FANCTRL5 "CTRL MIN FAN"
#define STR_UPDN "↑/↓" //↑/↓
#define STR_LFRG "←/→" //←/→
#ifdef COBRA_ONLY
#define STR_DISCOBRA "COBRA TOGGLE"
#endif
#ifdef REX_ONLY
#define STR_RBGMODE "RBG MODE TOGGLE"
#define STR_RBGNORM "NORM MODE TOGGLE"
#define STR_RBGMENU "MENU TOGGLE"
#endif
#define STR_SAVE "Save"
#define STR_SETTINGSUPD "Settings updated.<br><br>Click <a href=\"/restart.ps3\">here</a> to restart your PLAYSTATION®3 system."
#define STR_ERROR "Error!"
#define STR_MYGAMES "webMAN Games"
#define STR_LOADGAMES "Load games with webMAN"
#define STR_FIXING "Fixing"
#define STR_WMSETUP "webMAN Setup"
#define STR_WMSETUP2 "Setup webMAN options"
#define STR_EJECTDISC "Eject Disc"
#define STR_UNMOUNTGAME "Unmount current game"
#define STR_WMSTART "webMAN loaded!"
#define STR_WMUNL "webMAN unloaded!"
#define STR_CFWSYSALRD "CFW Syscalls already disabled"
#define STR_CFWSYSRIP "Removal History files & CFW Syscalls in progress..."
#define STR_RMVCFWSYS "History files & CFW Syscalls deleted OK!"
#define STR_RMVCFWSYSF "Failed to remove CFW Syscalls"
#define STR_RMVWMCFG "webMAN config reset in progress..."
#define STR_RMVWMCFGOK "Done! Restart within 3 seconds"
#define STR_PS3FORMAT "PS3 format games"
#define STR_PS2FORMAT "PS2 format games"
#define STR_PS1FORMAT "PSOne format games"
#define STR_PSPFORMAT "PSP\xE2\x84\xA2 format games"
#define STR_VIDFORMAT "Blu-ray\xE2\x84\xA2 and DVD"
#define STR_VIDEO "Video content"
#define STR_LAUNCHPSP "Launch PSP ISO mounted through webMAN or mmCM"
#define STR_LAUNCHPS2 "Launch PS2 Classic"
#define STR_GAMEUM "Game unmounted."
#define STR_EJECTED "Disc ejected."
#define STR_LOADED "Disc inserted."
#define STR_GAMETOM "Game to mount"
#define STR_GAMELOADED "Game loaded successfully. Start the game from the disc icon<br>or from <b>/app_home</b> XMB entry.<hr>Click <a href=\"/mount.ps3/unmount\">here</a> to unmount the game."
#define STR_PSPLOADED "Game loaded successfully. Start the game using <b>PSP Launcher</b>.<hr>"
#define STR_PS2LOADED "Game loaded successfully. Start the game using <b>PS2 Classic Launcher</b>.<hr>"
#define STR_LOADED2 "loaded "
#define STR_MOVIETOM "Movie to mount"
#define STR_MOVIELOADED "Movie loaded successfully. Start the movie from the disc icon<br>under the Video column.<hr>Click <a href=\"/mount.ps3/unmount\">here</a> to unmount the movie."
#define STR_XMLRF "Game list refreshed (<a href=\"" MY_GAMES_XML "\">mygames.xml</a>).<br>Click <a href=\"/restart.ps3\">here</a> to restart your PLAYSTATION®3 system now."
#define STR_STORAGE "System storage"
#define STR_MEMORY "Memory available"
#define STR_MBFREE "MB free"
#define STR_KBFREE "KB free"
#define STR_FANCTRL3 "Fan control:"
#define STR_ENABLED "Enabled"
#define STR_DISABLED "Disabled"
#define STR_FANCH0 "Fan setting changed:"
#define STR_FANCH1 "MAX TEMP: "
#define STR_FANCH2 "FAN SPEED: "
#define STR_FANCH3 "MIN FAN SPEED: "
#define STR_OVERHEAT "System overheat warning!"
#define STR_OVERHEAT2 " OVERHEAT DANGER!\r\nFAN SPEED INCREASED!"
#define STR_NOTFOUND "Not found!"
#else
static char lang_code[3] = "";
static char STR_TRADBY[150] = "<br>";
static char STR_FILES[30] = "Files";
static char STR_GAMES[30] = "Games";
static char STR_SETUP[30] = "Setup";
static char STR_HOME[30] = "Home";
static char STR_EJECT[50] = "Eject";
static char STR_INSERT[50] = "Insert";
static char STR_UNMOUNT[50] = "Unmount";
static char STR_COPY[50] = "Copy Folder";
static char STR_REFRESH[50] = "Refresh";
static char STR_SHUTDOWN[50] = "Shutdown";
static char STR_RESTART[50] = "Restart";
static char STR_BYTE[10] = "b";
static char STR_KILOBYTE[10] = "KB";
static char STR_MEGABYTE[10] = "MB";
static char STR_GIGABYTE[10] = "GB";
static char STR_COPYING[30] = "Copying";
static char STR_CPYDEST[30] = "Destination";
static char STR_CPYFINISH[30] = "Copy Finished!";
static char STR_CPYABORT[50] = "Copy aborted!";
static char STR_DELETE[50] = "Delete";
static char STR_SCAN1[100] = "Scan these devices";
static char STR_SCAN2[100] = "Scan for content";
static char STR_PSPL[100] = "Show PSP Launcher";
static char STR_PS2L[100] = "Show PS2 Classic Launcher";
static char STR_RXVID[100] = "Show Video sub-folder";
static char STR_VIDLG[30] = "Video";
static char STR_LPG[100] = "Load last-played game on startup";
static char STR_AUTOB[150] = "Check for /dev_hdd0/PS3ISO/AUTOBOOT.ISO on startup";
static char STR_DELAYAB[200] = "Delay loading of AUTOBOOT.ISO/last-game (Disc Auto-start)";
static char STR_DEVBL[150] = "Enable /dev_blind (writable /dev_flash) on startup";
static char STR_CONTSCAN[150] = "Disable content scan on startup";
static char STR_USBPOLL[100] = "Disable USB polling";
static char STR_FTPSVC[100] = "Disable FTP service";
static char STR_FIXGAME[100] = "Disable auto-fix game";
static char STR_COMBOS[100] = "Disable all PAD shortcuts";
static char STR_MMCOVERS[100] = "Disable multiMAN covers";
static char STR_ACCESS[100] = "Disable remote access to FTP/WWW services";
static char STR_NOSETUP[150] = "Disable webMAN Setup entry in \"webMAN Games\"";
static char STR_NOSPOOF[100] = "Disable firmware version spoofing";
static char STR_NOGRP[100] = "Disable grouping of content in \"webMAN Games\"";
static char STR_NOWMDN[200] = "Disable startup notification of WebMAN on the XMB";
#ifdef NOSINGSTAR
static char STR_NOSINGSTAR[100] = "Remove SingStar icon";
#endif
static char STR_RESET_USB[100] = "Disable Reset USB Bus";
static char STR_TITLEID[200] = "Include the ID as part of the title of the game";
static char STR_FANCTRL[120] = "Enable dynamic fan control";
static char STR_NOWARN[120] = "Disable temperature warnings";
static char STR_AUTOAT[100] = "Auto at";
static char STR_LOWEST[30] = "Lowest";
static char STR_FANSPEED[80] = "fan speed";
static char STR_MANUAL[30] = "Manual";
static char STR_PS2EMU[100] = "PS2 Emulator";
static char STR_LANGAMES[100] = "Scan for LAN games/videos";
static char STR_ANYUSB[100] = "Wait for any USB device to be ready";
static char STR_ADDUSB[150] = "Wait additionally for each selected USB device to be ready";
static char STR_SPOOFID[150] = "Change idps and psid in lv2 memory at system startup";
static char STR_DELCFWSYS[200] = "Disable lv1&lv2 peek&poke syscalls (6,7,9,10,11,36) and delete history files at system startup";
static char STR_MEMUSAGE[100] = "Plugin memory usage";
static char STR_PLANG[100] = "Plugin language";
static char STR_PROFILE[30] = "Profile";
static char STR_DEFAULT[30] = "Default";
static char STR_COMBOS2[100] = "XMB/In-Game PAD SHORTCUTS";
static char STR_FAILSAFE[100] = "FAIL SAFE";
static char STR_SHOWTEMP[100] = "SHOW TEMP";
static char STR_SHOWIDPS[100] = "SHOW IDPS";
static char STR_PREVGAME[100] = "PREV GAME";
static char STR_NEXTGAME[100] = "NEXT GAME";
static char STR_SHUTDOWN2[100] = "SHUTDOWN ";
static char STR_RESTART2[100] = "RESTART ";
#ifdef REMOVE_SYSCALLS
static char STR_DELCFWSYS2[100] = "DEL CFW SYSCALLS";
#endif
static char STR_UNLOADWM[100] = "UNLOAD WM";
static char STR_FANCTRL2[100] = "CTRL FAN";
static char STR_FANCTRL4[100] = "CTRL DYN FAN";
static char STR_FANCTRL5[100] = "CTRL MIN FAN";
static char STR_UPDN[20] = "↑/↓"; //↑/↓
static char STR_LFRG[20] = "←/→"; //←/→
#ifdef COBRA_ONLY
static char STR_DISCOBRA[100] = "COBRA TOGGLE";
#endif
#ifdef REX_ONLY
static char STR_RBGMODE[100] = "RBG MODE TOGGLE";
static char STR_RBGNORM[100] = "NORM MODE TOGGLE";
static char STR_RBGMENU[100] = "MENU TOGGLE";
#endif
static char STR_SAVE[30] = "Save";
static char STR_SETTINGSUPD[250] = "Settings updated.<br><br>Click <a href=\"/restart.ps3\">here</a> to restart your PLAYSTATION®3 system.";
static char STR_ERROR[30] = "Error!";
static char STR_MYGAMES[50] = "webMAN Games";
static char STR_LOADGAMES[80] = "Load games with webMAN";
static char STR_FIXING[50] = "Fixing";
static char STR_WMSETUP[50] = "webMAN Setup";
static char STR_WMSETUP2[50] = "Setup webMAN options";
static char STR_EJECTDISC[50] = "Eject Disc";
static char STR_UNMOUNTGAME[100] = "Unmount current game";
static char STR_WMSTART[50] = "webMAN loaded!";
static char STR_WMUNL[80] = "webMAN unloaded!";
static char STR_CFWSYSALRD[130] = "CFW Syscalls already disabled";
static char STR_CFWSYSRIP[130] = "Removal History files & CFW Syscalls in progress...";
static char STR_RMVCFWSYS[130] = "History files & CFW Syscalls deleted OK!";
static char STR_RMVCFWSYSF[130] = "Failed to remove CFW Syscalls";
static char STR_RMVWMCFG[130] = "webMAN config reset in progress...";
static char STR_RMVWMCFGOK[130] = "Done! Restart within 3 seconds";
static char STR_PS3FORMAT[50] = "PS3 format games";
static char STR_PS2FORMAT[50] = "PS2 format games";
static char STR_PS1FORMAT[50] = "PSOne format games";
static char STR_PSPFORMAT[50] = "PSP\xE2\x84\xA2 format games";
static char STR_VIDFORMAT[50] = "Blu-ray\xE2\x84\xA2 and DVD";
static char STR_VIDEO[50] = "Video content";
static char STR_LAUNCHPSP[100] = "Launch PSP ISO mounted through webMAN or mmCM";
static char STR_LAUNCHPS2[100] = "Launch PS2 Classic";
static char STR_GAMEUM[50] = "Game unmounted.";
static char STR_EJECTED[50] = "Disc ejected.";
static char STR_LOADED[50] = "Disc inserted.";
static char STR_GAMETOM[50] = "Game to mount";
static char STR_GAMELOADED[250] = "Game loaded successfully. Start the game from the disc icon<br>or from <b>/app_home</b> XMB entry.<hr>Click <a href=\"/mount.ps3/unmount\">here</a> to unmount the game.";
static char STR_PSPLOADED[230] = "Game loaded successfully. Start the game using <b>PSP Launcher</b>.<hr>";
static char STR_PS2LOADED[230] = "Game loaded successfully. Start the game using <b>PS2 Classic Launcher</b>.<hr>";
static char STR_LOADED2[50] = "loaded ";
static char STR_MOVIETOM[50] = "Movie to mount";
static char STR_MOVIELOADED[250] = "Movie loaded successfully. Start the movie from the disc icon<br>under the Video column.<hr>Click <a href=\"/mount.ps3/unmount\">here</a> to unmount the movie.";
static char STR_XMLRF[200] = "Game list refreshed (<a href=\"" MY_GAMES_XML "\">mygames.xml</a>).<br>Click <a href=\"/restart.ps3\">here</a> to restart your PLAYSTATION®3 system now.";
static char STR_STORAGE[50] = "System storage";
static char STR_MEMORY[50] = "Memory available";
static char STR_MBFREE[50] = "MB free";
static char STR_KBFREE[50] = "KB free";
static char STR_FANCTRL3[50] = "Fan control:";
static char STR_ENABLED[50] = "Enabled";
static char STR_DISABLED[50] = "Disabled";
static char STR_FANCH0[50] = "Fan setting changed:";
static char STR_FANCH1[50] = "MAX TEMP: ";
static char STR_FANCH2[50] = "FAN SPEED: ";
static char STR_FANCH3[50] = "MIN FAN SPEED: ";
static char STR_OVERHEAT[100] = "System overheat warning!";