forked from aldostools/webMAN-MOD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
4240 lines (3464 loc) · 128 KB
/
main.c
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
#define USE_INTERNAL_PLUGIN 1
#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 <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <sys/stat.h>
#include "flags.h"
#include "types.h"
#include "include/timer.h"
#ifdef REX_ONLY
#ifndef DEX_SUPPORT
#define DEX_SUPPORT 1
#endif
#endif
#undef NET_SUPPORT
#ifdef COBRA_ONLY
#ifndef LITE_EDITION
#define NET_SUPPORT 1
#endif
#endif
#ifdef LAST_FIRMWARE_ONLY
#undef DECR_SUPPORT
#undef FIX_GAME
#endif
#ifdef PKG_LAUNCHER
#define MOUNT_ROMS 1
#endif
#ifndef WM_REQUEST
#undef WM_CUSTOM_COMBO
#endif
#define IS_ON_XMB (GetCurrentRunningMode() == 0)
#define IS_INGAME (GetCurrentRunningMode() != 0)
#include "common.h"
#include "cobra/cobra.h"
#include "cobra/storage.h"
#include "vsh/game_plugin.h"
#include "vsh/netctl_main.h"
#include "vsh/xregistry.h"
#include "vsh/vsh.h"
#include "vsh/vshnet.h"
#include "vsh/vshmain.h"
#include "vsh/explore_plugin.h"
static char _game_TitleID[16]; //#define _game_TitleID _game_info+0x04
static char _game_Title [64]; //#define _game_Title _game_info+0x14
//static char _game_info[0x120];
static char search_url[50];
#ifdef COBRA_ONLY
#include "cobra/netiso.h"
/////////////////////////////////////
#ifdef LITE_EDITION
#define EDITION_ " [Lite]"
#elif defined(PS3NET_SERVER) && defined(NET3NET4) && defined(XMB_SCREENSHOT)
#define EDITION_ " [Full]"
#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
#define EDITION_ " [nonCobra]"
#undef PS3MAPI
#undef WM_PROXY_SPRX
#endif
#ifdef USE_NTFS
#define EDITION " (NTFS)" EDITION_ // webMAN version (NTFS)
#else
#define EDITION EDITION_ // webMAN version
#endif
/////////////////////////////////////
SYS_MODULE_INFO(WWWD, 0, 1, 1);
SYS_MODULE_START(wwwd_start);
SYS_MODULE_STOP(wwwd_stop);
SYS_MODULE_EXIT(wwwd_stop);
#define VSH_MODULE_DIR "/dev_flash/vsh/module/"
#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 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/wm_res/libfs.sprx"
#define SLAUNCH_FILE "/dev_hdd0/tmp/wmtmp/slist.bin"
#define WM_VERSION "1.47.20 MOD"
#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 MANAGUNZ "/dev_hdd0/game/MANAGUNZ0/USRDIR" // ManaGunZ folder
#define TMP_DIR "/dev_hdd0/tmp"
#define WMCONFIG TMP_DIR "/wm_config.bin" // webMAN config file
#define WMTMP TMP_DIR "/wmtmp" // webMAN work/temp folder
#define WM_RES_PATH TMP_DIR "/wm_res" // webMAN resources
#define WM_LANG_PATH TMP_DIR "/wm_lang" // webMAN language folder
#define WM_ICONS_PATH TMP_DIR "/wm_icons" // webMAN icons folder
#define WM_COMBO_PATH TMP_DIR "/wm_combo" // webMAN custom combos folder
#define WMNOSCAN TMP_DIR "/wm_noscan" // webMAN config file to skip on boot
#define WMREQUEST_FILE TMP_DIR "/wm_request" // webMAN request file
#define WMNET_DISABLED TMP_DIR "/wm_netdisabled" // webMAN config file to re-enable network
#define WMONLINE_GAMES WM_RES_PATH "/wm_online_ids.txt" // webMAN config file to skip disable network setting on these title ids
#define WMOFFLINE_GAMES WM_RES_PATH "/wm_offline_ids.txt" // webMAN config file to disable network setting on specific title ids (overrides wm_online_ids.txt)
#define LAST_GAME_TXT WMTMP "/last_game.txt"
#define LAST_GAMES_BIN WMTMP "/last_games.bin"
#define VSH_MENU_IMAGES "/dev_hdd0/plugins/images"
#define HDD0_GAME_DIR "/dev_hdd0/game/"
#define PKGLAUNCH_ID "PKGLAUNCH"
#define PKGLAUNCH_DIR HDD0_GAME_DIR PKGLAUNCH_ID
#define PKGLAUNCH_ICON PKGLAUNCH_DIR "/ICON0.PNG"
#define VSH_RESOURCE_DIR "/dev_flash/vsh/resource/"
#define SYSMAP_EMPTY_DIR VSH_RESOURCE_DIR "AAA" //redirect firmware update to empty folder (formerly redirected to "/dev_bdvd")
#define PS2_CLASSIC_TOGGLER "/dev_hdd0/classic_ps2"
#define PS2_CLASSIC_LAUCHER_DIR HDD0_GAME_DIR "PS2U10000"
#define PS2_CLASSIC_ISO_ICON PS2_CLASSIC_LAUCHER_DIR "/ICON0.PNG"
#define PS2_CLASSIC_PLACEHOLDER PS2_CLASSIC_LAUCHER_DIR "/USRDIR"
#define PS2_CLASSIC_ISO_CONFIG PS2_CLASSIC_LAUCHER_DIR "/USRDIR/CONFIG"
#define PS2_CLASSIC_ISO_PATH PS2_CLASSIC_LAUCHER_DIR "/USRDIR/ISO.BIN.ENC"
#define PSP_LAUNCHER_MINIS_ID "PSPM66820"
#define PSP_LAUNCHER_REMASTERS_ID "PSPC66820"
#define PSP_LAUNCHER_MINIS HDD0_GAME_DIR PSP_LAUNCHER_MINIS_ID
#define PSP_LAUNCHER_REMASTERS HDD0_GAME_DIR PSP_LAUNCHER_REMASTERS_ID
#define NONE -1
#define SYS_PPU_THREAD_NONE (sys_ppu_thread_t)NONE
#define SYS_EVENT_QUEUE_NONE (sys_event_queue_t)NONE
#define SYS_DEVICE_HANDLE_NONE (sys_device_handle_t)NONE
#define SYS_MEMORY_CONTAINER_NONE (sys_memory_container_t)NONE
//////////////////////////////////////
#define THREAD_NAME_SVR "wwwdt"
#define THREAD_NAME_WEB "wwwd"
#define THREAD_NAME_CMD "wwwd2"
#define THREAD_NAME_FTP "ftpdt"
#define THREAD_NAME_FTPD "ftpd"
#define THREAD_NAME_NET "netiso"
#define THREAD_NAME_NTFS "ntfsd"
#define THREAD_NAME_PSX_EJECT "ntfsd_eject"
#define THREAD_NAME_POLL "poll_thread"
#define THREAD_NAME_SND0 "snd0_thread"
#define THREAD_NAME_INSTALLPKG "install_pkg"
#define THREAD_NAME_NETSVR "netsvr"
#define THREAD_NAME_NETSVRD "netsvrd"
#define STOP_THREAD_NAME "wwwds"
#define THREAD_PRIO_HIGH 0x000
#define THREAD_PRIO 0x400
#define THREAD_PRIO_NET 0x500
#define THREAD_PRIO_FTP 0x600
#define THREAD_PRIO_POLL 0xA00
#define THREAD_PRIO_STOP 0xB00
#define THREAD_STACK_SIZE_6KB 0x01800UL
#define THREAD_STACK_SIZE_8KB 0x02000UL
#define THREAD_STACK_SIZE_16KB 0x04000UL
#define THREAD_STACK_SIZE_24KB 0x06000UL
#define THREAD_STACK_SIZE_32KB 0x08000UL
#define THREAD_STACK_SIZE_48KB 0x0C000UL
#define THREAD_STACK_SIZE_64KB 0x10000UL
#define THREAD_STACK_SIZE_96KB 0x18000UL
#define THREAD_STACK_SIZE_128KB 0x20000UL
#define THREAD_STACK_SIZE_192KB 0x30000UL
#define THREAD_STACK_SIZE_256KB 0x40000UL
#define THREAD_STACK_SIZE_FTP_SERVER THREAD_STACK_SIZE_6KB
#define THREAD_STACK_SIZE_FTP_CLIENT THREAD_STACK_SIZE_16KB
#define THREAD_STACK_SIZE_WEB_SERVER THREAD_STACK_SIZE_6KB
#define THREAD_STACK_SIZE_WEB_CLIENT THREAD_STACK_SIZE_48KB
#define THREAD_STACK_SIZE_NET_SERVER THREAD_STACK_SIZE_6KB
#define THREAD_STACK_SIZE_NET_CLIENT THREAD_STACK_SIZE_24KB
#define THREAD_STACK_SIZE_PS3MAPI_SVR THREAD_STACK_SIZE_6KB
#define THREAD_STACK_SIZE_PS3MAPI_CLI THREAD_STACK_SIZE_48KB
#define THREAD_STACK_SIZE_NET_ISO THREAD_STACK_SIZE_8KB
#define THREAD_STACK_SIZE_NTFS_ISO THREAD_STACK_SIZE_8KB
#define THREAD_STACK_SIZE_STOP_THREAD THREAD_STACK_SIZE_6KB
#define THREAD_STACK_SIZE_INSTALL_PKG THREAD_STACK_SIZE_6KB
#define THREAD_STACK_SIZE_POLL_THREAD THREAD_STACK_SIZE_32KB
#define THREAD_STACK_SIZE_UPDATE_XML THREAD_STACK_SIZE_128KB
#define THREAD_STACK_SIZE_MOUNT_GAME THREAD_STACK_SIZE_48KB
#define SYS_PPU_THREAD_CREATE_NORMAL 0x000
///////////// PS3MAPI BEGIN //////////////
#ifdef COBRA_ONLY
#define SYSCALL8_OPCODE_PS3MAPI 0x7777
#define PS3MAPI_OPCODE_SET_ACCESS_KEY 0x2000
#define PS3MAPI_OPCODE_REQUEST_ACCESS 0x2001
#define PS3MAPI_OPCODE_PCHECK_SYSCALL8 0x0094
#define PS3MAPI_OPCODE_PDISABLE_SYSCALL8 0x0093
// static u64 ps3mapi_key = 0;
static int pdisable_sc8 = NONE;
#define PS3MAPI_ENABLE_ACCESS_SYSCALL8 //if(syscalls_removed) { system_call_3(SC_COBRA_SYSCALL8, SYSCALL8_OPCODE_PS3MAPI, PS3MAPI_OPCODE_REQUEST_ACCESS, ps3mapi_key); }
#define PS3MAPI_DISABLE_ACCESS_SYSCALL8 //if(syscalls_removed && !is_mounting) { system_call_3(SC_COBRA_SYSCALL8, SYSCALL8_OPCODE_PS3MAPI, PS3MAPI_OPCODE_SET_ACCESS_KEY, ps3mapi_key); }
#define PS3MAPI_REENABLE_SYSCALL8 { system_call_2(SC_COBRA_SYSCALL8, SYSCALL8_OPCODE_PS3MAPI, PS3MAPI_OPCODE_PCHECK_SYSCALL8); pdisable_sc8 = (int)p1;} \
if(pdisable_sc8 > 0) { system_call_3(SC_COBRA_SYSCALL8, SYSCALL8_OPCODE_PS3MAPI, PS3MAPI_OPCODE_PDISABLE_SYSCALL8, 0); }
#define PS3MAPI_RESTORE_SC8_DISABLE_STATUS if(pdisable_sc8 > 0) { system_call_3(SC_COBRA_SYSCALL8, SYSCALL8_OPCODE_PS3MAPI, PS3MAPI_OPCODE_PDISABLE_SYSCALL8, pdisable_sc8); }
#else
#define PS3MAPI_ENABLE_ACCESS_SYSCALL8
#define PS3MAPI_DISABLE_ACCESS_SYSCALL8
#define PS3MAPI_REENABLE_SYSCALL8
#define PS3MAPI_RESTORE_SC8_DISABLE_STATUS
#endif
///////////// PS3MAPI END ////////////////
#define HTML_BASE_PATH "/dev_hdd0/xmlhost/game_plugin"
#define HEN_HFW_SETTINGS "/dev_hdd0/hen/hfw_settings.xml"
#define FB_XML "/dev_hdd0/xmlhost/game_plugin/fb.xml"
#ifdef COBRA_ONLY
#define MY_GAMES_XML HTML_BASE_PATH "/mygames.xml"
#else
#define MY_GAMES_XML HTML_BASE_PATH "/jbgames.xml"
#endif
#define MOBILE_HTML HTML_BASE_PATH "/mobile.html"
#define GAMELIST_JS HTML_BASE_PATH "/gamelist.js"
#ifndef EMBED_JS
#define COMMON_CSS HTML_BASE_PATH "/common.css"
#define COMMON_SCRIPT_JS HTML_BASE_PATH "/common.js"
#define FM_SCRIPT_JS HTML_BASE_PATH "/fm.js"
#define FS_SCRIPT_JS HTML_BASE_PATH "/fs.js"
#define GAMES_SCRIPT_JS HTML_BASE_PATH "/games.js"
#endif
#define JQUERY_LIB_JS HTML_BASE_PATH "/jquery.min.js"
#define JQUERY_UI_LIB_JS HTML_BASE_PATH "/jquery-ui.min.js"
#define DELETE_CACHED_GAMES {cellFsUnlink(WMTMP "/games.html"); cellFsUnlink(GAMELIST_JS);}
////////////
#define SC_GET_FREE_MEM (352)
#define SC_GET_PLATFORM_INFO (387)
#define SC_RING_BUZZER (392)
#define SC_FS_MOUNT (837)
#define SC_FS_UMOUNT (838)
#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 SYSCALL8_OPCODE_GET_MAMBA 0x7FFFULL
#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); }
////////////
#define WWWPORT (80)
#define FTPPORT (21)
#define NETPORT (38008)
#define PS3MAPIPORT (7887)
#define MAX_WWW_CC (255)
#define MAX_WWW_THREADS (8)
#define MAX_FTP_THREADS (8)
#define WWW_BACKLOG (2001)
#define FTP_BACKLOG (7)
#define NET_BACKLOG (4)
#define PS3MAPI_BACKLOG (4)
#define MAX_SLAUNCH_ITEMS 2000
int active_socket[4] = {NONE, NONE, NONE, NONE}; // 0=FTP, 1=WWW, 2=PS3MAPI, 3=PS3NETSRV
#define KB 1024UL
#define _2KB_ 2048UL
#define _4KB_ 4096UL
#define _6KB_ 6144UL
#define _8KB_ 8192UL
#define _12KB_ 12288UL
#define _32KB_ 32768UL
#define _64KB_ 65536UL
#define _128KB_ 131072UL
#define _192KB_ 196608UL
#define _256KB_ 262144UL
#define _384KB_ 393216UL
#define _512KB_ 524288UL
#define _640KB_ 655360UL
#define _1MB_ 0x0100000UL
#define _2MB_ 0x0200000UL
#define _3MB_ 0x0300000UL
#define _32MB_ 0x2000000UL
#define MIN_MEM _192KB_
static u32 BUFFER_SIZE_FTP;
static u32 BUFFER_SIZE_ALL;
static u32 BUFFER_SIZE;
static u32 BUFFER_SIZE_PSX;
static u32 BUFFER_SIZE_PSP;
static u32 BUFFER_SIZE_PS2;
static u32 BUFFER_SIZE_DVD;
#ifdef MOUNT_ROMS
static u32 BUFFER_SIZE_ROM = ( _32KB_ / 2);
#endif
#define MAX_PAGES ((BUFFER_SIZE_ALL / (_64KB_ * MAX_WWW_THREADS)) + 1)
////////////
static const u32 MODE = 0777;
static const u32 DMODE = (CELL_FS_S_IFDIR | 0777);
static const u32 NOSND = (S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH);
#define LINELEN 512 // file listing
#define MAX_LINE_LEN 640 // html games
#define STD_PATH_LEN 263 // standard path len (260 characters in NTFS - Windows 10 removed this limit in 2016)
#define MAX_PATH_LEN 512 // do not change!
#define MAX_TEXT_LEN 1300 // should not exceed HTML_RECV_SIZE
#define TITLE_ID_LEN 9
#define FAILED -1
#define HTML_RECV_SIZE 2048
#define HTML_RECV_LAST 2047
#define ip_size 0x10
#define CODE_HTTP_OK 200
#define CODE_BAD_REQUEST 400
#define CODE_PATH_NOT_FOUND 404
#define CODE_SERVER_BUSY 503
#define CODE_VIRTUALPAD 1200
#define CODE_INSTALL_PKG 1201
#define CODE_DOWNLOAD_FILE 1202
#define CODE_RETURN_TO_ROOT 1203
#define CODE_GOBACK 1222
#define CODE_CLOSE_BROWSER 1223
////////////
#ifdef COBRA_ONLY
#ifdef PS3NET_SERVER
static sys_ppu_thread_t thread_id_netsvr = SYS_PPU_THREAD_NONE;
#endif
#endif
static sys_ppu_thread_t thread_id_wwwd = SYS_PPU_THREAD_NONE;
static sys_ppu_thread_t thread_id_ftpd = SYS_PPU_THREAD_NONE;
static sys_ppu_thread_t thread_id_poll = SYS_PPU_THREAD_NONE;
#define START_DAEMON (0xC0FEBABE)
#define REFRESH_CONTENT (0xC0FEBAB0)
#define WM_FILE_REQUEST (0xC0FEBEB0)
typedef struct {
u32 total;
u32 avail;
} _meminfo;
static u8 profile = 0;
static u8 loading_html = 0;
static u8 refreshing_xml = 0;
#ifdef SYS_BGM
static u8 system_bgm = 0;
#endif
#define NTFS (12)
#define APP_GAME 0xFF
static bool show_info_popup = false;
static bool do_restart = false;
static bool payload_ps3hen = false;
#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 max_mapped = 0;
static int init_delay = 0;
static bool syscalls_removed = false;
static float c_firmware = 0.0f;
static u8 dex_mode = 0;
#ifdef SYS_ADMIN_MODE
static u8 sys_admin = 0;
static u8 pwd_tries = 0;
#else
static u8 sys_admin = 1;
#endif
#ifdef OFFLINE_INGAME
static s32 net_status = NONE;
#endif
static u64 SYSCALL_TABLE = 0;
static u64 LV2_OFFSET_ON_LV1; // value is set on detect_firmware -> 0x1000000 on 4.46, 0x8000000 on 4.76/4.78
enum is_binary_options
{
WEB_COMMAND = 0,
BINARY_FILE = 1,
FOLDER_LISTING = 2
};
enum get_name_options
{
NO_EXT = 0,
GET_WMTMP = 1,
NO_PATH = 2,
};
enum cp_mode_options
{
CP_MODE_NONE = 0,
CP_MODE_COPY = 1,
CP_MODE_MOVE = 2,
};
////////////////////////////////
typedef struct
{
u16 version;
u8 padding0[14];
u8 lang; //0=EN, 1=FR, 2=IT, 3=ES, 4=DE, 5=NL, 6=PT, 7=RU, 8=HU, 9=PL, 10=GR, 11=HR, 12=BG, 13=IN, 14=TR, 15=AR, 16=CN, 17=KR, 18=JP, 19=ZH, 20=DK, 21=CZ, 22=SK, 99=XX
// scan devices settings
u8 usb0;
u8 usb1;
u8 usb2;
u8 usb3;
u8 usb6;
u8 usb7;
u8 dev_sd;
u8 dev_ms;
u8 dev_cf;
u8 ntfs; // 1=enable internal prepNTFS to scan content
u8 padding1[5];
// scan content settings
u8 refr; // 1=disable content scan on startup
u8 foot; // buffer size during content scanning : 0=896KB,1=320KB,2=1280KB,3=512KB,4 to 7=1280KB
u8 cmask;
u8 nogrp;
u8 nocov;
u8 nosetup;
u8 rxvid;
u8 ps2l;
u8 pspl;
u8 tid;
u8 use_filename;
u8 launchpad_xml;
u8 launchpad_grp;
u8 ps3l;
u8 roms;
u8 mc_app; // allow allocation from app memory container
u8 info; // info level: 0=Path, 1=Path + ID, 2=ID, 3=None
u8 npdrm;
u8 padding2[14];
// start up settings
u8 wmstart; // 1=disable start up message (webMAN Loaded!)
u8 lastp;
u8 autob;
char autoboot_path[256];
u8 delay;
u8 bootd;
u8 boots;
u8 nospoof;
u8 blind;
u8 spp; //disable syscalls, offline: lock PSN, offline ingame
u8 noss; //no singstar
u8 nosnd0; //mute snd0.at3
u8 dsc; //disable syscalls if physical disc is inserted
u8 padding3[4];
// fan control settings
u8 fanc;
u8 temp0;
u8 temp1;
u8 manu;
u8 ps2temp;
u8 nowarn;
u8 minfan;
u8 padding4[9];
// combo settings
u8 nopad;
u8 keep_ccapi;
u32 combo;
u32 combo2;
u8 sc8mode; // 0/4=Remove cfw syscall disables syscall8 / PS3MAPI=disabled, 1=Keep syscall8 / PS3MAPI=enabled
u8 nobeep;
u8 padding5[20];
// ftp server settings
u8 bind;
u8 ftpd;
u16 ftp_port;
u8 ftp_timeout;
char ftp_password[20];
char allow_ip[16];
u8 padding6[7];
// net server settings
u8 netsrvd;
u16 netsrvp;
u8 padding7[13];
// net client settings
u8 netd[5];
u16 netp[5];
char neth[5][16];
u8 padding8[33];
// mount settings
u8 bus;
u8 fixgame;
u8 ps1emu;
u8 autoplay;
u8 ps2emu;
u8 ps2config;
u8 padding9[10];
// profile settings
u8 profile;
char uaccount[9];
u8 admin_mode;
u8 padding10[5];
// misc settings
u8 default_restart;
u8 poll; // poll usb
u32 rec_video_format;
u32 rec_audio_format;
u8 auto_power_off; // 0 = prevent auto power off on ftp, 1 = allow auto power off on ftp (also on install.ps3, download.ps3)
u8 padding12[5];
u8 homeb;
char home_url[255];
u8 sman;
u8 padding11[31];
// spoof console id
u8 sidps;
u8 spsid;
char vIDPS1[17];
char vIDPS2[17];
char vPSID1[17];
char vPSID2[17];
u8 padding13[34];
} /*__attribute__((packed))*/ WebmanCfg;
static u8 wmconfig[sizeof(WebmanCfg)];
static WebmanCfg *webman_config = (WebmanCfg*) wmconfig;
static u8 cconfig[sizeof(CobraConfig)];
static CobraConfig *cobra_config = (CobraConfig*) cconfig;
static int save_settings(void);
static void restore_settings(void);
////////////////////////////////
#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 MAX_ISO_PARTS (16)
#define ISO_EXTENSIONS ".cue|.iso.0|.bin|.img|.mdf"
static CellRtcTick rTick, gTick;
#ifdef GET_KLICENSEE
int npklic_struct_offset = 0; u8 klic_polling = 0;
#define KLICENSEE_SIZE 0x10
#define KLICENSEE_OFFSET (npklic_struct_offset)
#define KLIC_PATH_OFFSET (npklic_struct_offset+0x10)
#define KLIC_CONTENT_ID_OFFSET (npklic_struct_offset-0xA4)
#endif
static bool is_mamba = false;
static u16 cobra_version = 0;
static bool is_mounting = false;
static bool copy_aborted = false;
static u8 automount = 0;
#ifndef EMBED_JS
static bool css_exists = false;
static bool common_js_exists = false;
#endif
static char html_base_path[MAX_PATH_LEN];
static const char smonth[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static char drives[17][12] = {"/dev_hdd0", "/dev_usb000", "/dev_usb001", "/dev_usb002", "/dev_usb003", "/dev_usb006", "/dev_usb007", "/net0", "/net1", "/net2", "/net3", "/net4", "/dev_ntfs", "/dev_sd", "/dev_ms", "/dev_cf", "/dev_blind"};
static char paths [13][10] = {"GAMES", "GAMEZ", "PS3ISO", "BDISO", "DVDISO", "PS2ISO", "PSXISO", "PSXGAMES", "PSPISO", "ISO", "video", "GAMEI", "ROMS"};
#ifdef COPY_PS3
static char current_file[STD_PATH_LEN + 1];
static char cp_path[STD_PATH_LEN + 1]; // cut/copy/paste buffer
static u8 cp_mode = CP_MODE_NONE; // 0 = none / 1 = copy / 2 = cut/move
static void parse_script(const char *script_file);
static bool script_running = false;
#endif
#define ONLINE_TAG "[online]"
#define OFFLINE_TAG "[offline]"
#define AUTOPLAY_TAG " [auto]"
#define TYPE_ALL 0
#define TYPE_PS1 1
#define TYPE_PS2 2
#define TYPE_PS3 3
#define TYPE_PSP 4
#define TYPE_VID 5
#define TYPE_ROM 6
#define TYPE_MAX 7
static char wm_icons[14][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]
WM_ICONS_PATH "/icon_wm_bdv.png", //024.png [12]
WM_ICONS_PATH "/icon_wm_retro.png", //023.png [13]
};
#ifndef ENGLISH_ONLY
static bool use_custom_icon_path = false, use_icon_region = false;
static bool is_xmbmods_server = false;
#endif
static bool covers_exist[8];
static char fw_version[8] = "4.xx";
static char local_ip[16] = "127.0.0.1";
static void show_msg(char* msg);
static bool file_exists(const char* path);
static bool isDir(const char* path);
size_t read_file(const char *file, char *data, size_t size, s32 offset);
int save_file(const char *file, const char *mem, s64 size);
int wait_for(const char *path, u8 timeout);
static s64 val(const char *c);
#include "include/html.h"
#include "include/peek_poke.h"
#include "include/idps.h"
#include "include/led.h"
#include "include/vpad.h"
#include "include/socket.h"
#include "include/language.h"
#include "include/fancontrol.h"
#include "include/firmware.h"
#include "include/ntfs.h"
#ifdef USE_NTFS
static ntfs_md *mounts = NULL;
static int mountCount = NTFS_UNMOUNTED;
static bool skip_prepntfs = false;
static int prepNTFS(u8 clear);
#endif
int wwwd_start(size_t args, void *argp);
int wwwd_stop(void);
static void stop_prx_module(void);
static void unload_prx_module(void);
#ifdef REMOVE_SYSCALLS
static void remove_cfw_syscalls(bool keep_ccapi);
#ifdef PS3MAPI
static void restore_cfw_syscalls(void);
#endif
#endif
#ifdef PKG_HANDLER
static int installPKG(const char *pkgpath, char *msg);
#endif
#ifdef COBRA_ONLY
static void apply_remaps(void);
#endif
static void handleclient_www(u64 conn_s_p);
static void do_umount(bool clean);
static void mount_autoboot(void);
static bool mount_game(const char *_path, u8 do_eject);
#ifdef COBRA_ONLY
static void do_umount_iso(void);
static void unload_vsh_gui(void);
static void set_apphome(char *game_path);
#endif
static size_t get_name(char *name, const char *filename, u8 cache);
static void add_breadcrumb_trail(char *buffer, char *param);
static void get_cpursx(char *cpursx);
static void get_last_game(char *last_path);
static void add_game_info(char *buffer, char *templn, bool is_cpursx);
static void mute_snd0(bool scan_gamedir);
static bool from_reboot = false;
static bool is_busy = false;
static u8 mount_unk = EMU_OFF;
#include "include/eject_insert.h"
#ifdef COBRA_ONLY
#include "include/rawseciso.h"
#include "include/netclient.h"
#include "include/netserver.h"
#endif //#ifdef COBRA_ONLY
#include "include/webchat.h"
#include "include/vsh.h"
#include "include/file.h"
#include "include/ps2_disc.h"
#include "include/ps2_classic.h"
#include "include/xmb_savebmp.h"
#include "include/singstar.h"
#include "include/autopoweroff.h"
#include "include/gamedata.h"
#include "include/psxemu.h"
#include "include/debug_mem.h"
#include "include/fix_game.h"
#include "include/ftp.h"
#include "include/ps3mapi.h"
#include "include/stealth.h"
#include "include/video_rec.h"
#include "include/secure_file_id.h"
#include "include/cue_file.h"
#include "include/games_html.h"
#include "include/games_slaunch.h"
#include "include/games_xml.h"
#include "include/prepntfs.h"
#include "include/cpursx.h"
#include "include/setup.h"
#include "include/togglers.h"
#include "include/_mount.h"
#include "include/file_manager.h"
#include "include/pkg_handler.h"
#include "include/fancontrol2.h"
#include "include/md5.h"
#include "include/script.h"
static inline void _sys_ppu_thread_exit(u64 val)
{
system_call_1(SC_PPU_THREAD_EXIT, val); // prxloader = mandatory; cobra = optional; ccapi = don't use !!!
}
static inline sys_prx_id_t prx_get_module_id_by_address(void *addr)
{
system_call_1(SC_GET_PRX_MODULE_BY_ADDRESS, (u64)(u32)addr);
return (int)p1;
}
static void http_response(int conn_s, char *header, const char *url, int code, const char *msg)
{
u16 slen; *header = NULL;
if(code == CODE_VIRTUALPAD || code == CODE_GOBACK || code == CODE_CLOSE_BROWSER)
{
slen = sprintf(header, HTML_RESPONSE_FMT,
CODE_HTTP_OK, url, HTML_BODY, HTML_RESPONSE_TITLE, msg);
}
else
{
char body[_2KB_];
if(*msg == '/')
{sprintf(body, "%s : OK", msg+1); show_msg(body);}
else if(islike(msg, "http"))
sprintf(body, "<a style=\"%s\" href=\"%s\">%s</a>", HTML_URL_STYLE, msg, msg);
#ifdef PKG_HANDLER
else if(code == CODE_INSTALL_PKG || code == CODE_DOWNLOAD_FILE)
{
sprintf(body, "<style>a{%s}</style>%s", HTML_URL_STYLE, (code == CODE_INSTALL_PKG) ? "Installing " : "");
char *p = strchr((char*)msg, '\n');
if(p)
{
*p = NULL;
if(code == CODE_INSTALL_PKG) add_breadcrumb_trail(body, (char *)msg + 11); else strcat(body, msg);
if(code == CODE_DOWNLOAD_FILE || extcasecmp(pkg_path, ".p3t", 4) != 0) strcat(body, "<p>To: \0"); add_breadcrumb_trail(body, p + 5);
}
else
strcat(body, msg);
code = CODE_HTTP_OK;
}
#endif
else
sprintf(body, "%s", msg);
//if(ISDIGIT(*msg) && ( (code == CODE_SERVER_BUSY || code == CODE_BAD_REQUEST) )) show_msg((char*)body + 4);
#ifndef EMBED_JS
if(css_exists)
{
sprintf(header, "<LINK href=\"%s\" rel=\"stylesheet\" type=\"text/css\">", COMMON_CSS); strcat(body, header);
}
if(common_js_exists)
{
sprintf(header, SCRIPT_SRC_FMT, COMMON_SCRIPT_JS); strcat(body, header);
}
#endif
sprintf(header, "<hr>" HTML_BUTTON_FMT "%s",
HTML_BUTTON, " ◀ ", HTML_ONCLICK, ((code == CODE_RETURN_TO_ROOT) ? "/" : "javascript:history.back();"), HTML_BODY_END); strcat(body, header);
slen = sprintf(header, HTML_RESPONSE_FMT,
(code == CODE_RETURN_TO_ROOT) ? CODE_HTTP_OK : code, url, HTML_BODY, HTML_RESPONSE_TITLE, body);
}
send(conn_s, header, slen, 0);
sclose(&conn_s);
}
#ifdef SYS_ADMIN_MODE
static u8 check_password(char *param)
{
u8 ret = 0;
if((pwd_tries < 3) && (webman_config->ftp_password[0] != NULL))
{
char *pos = strstr(param, "pwd=");
if(pos > param)
{
pwd_tries++;
if(IS(pos + 4, webman_config->ftp_password)) {pwd_tries = 0, ret = 1;}
--pos; *pos = NULL;
}
}
return ret;
}
#endif
static void restore_settings(void)
{
#ifdef COBRA_ONLY
unload_vsh_plugin("VSH_MENU"); // unload vsh menu
unload_vsh_plugin("sLaunch"); // unload sLaunch
#endif
for(u8 n = 0; n < 4; n++)
if(active_socket[n]>NONE) sys_net_abort_socket(active_socket[n], SYS_NET_ABORT_STRICT_CHECK);
if(webman_config->fanc == DISABLED || webman_config->temp0 == FAN_AUTO)
{