forked from aldostools/webMAN-MOD
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
3583 lines (2907 loc) · 107 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
#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"
#ifdef REX_ONLY
#ifndef DEX_SUPPORT
#define DEX_SUPPORT 1
#endif
#endif
#include "types.h"
#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/vshnet.h"
#include "vsh/explore_plugin.h"
#define _game_TitleID _game_info+0x04
#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
#ifdef CCAPI
#define EDITION " [CCAPI]"
#else
#define EDITION " [nonCobra]"
#endif
#undef PS3MAPI
#endif
#ifdef LAST_FIRMWARE_ONLY
#undef DECR_SUPPORT
#undef FIX_GAME
#endif
#ifdef PKG_LAUNCHER
#define MOUNT_ROMS 1
#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 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 WM_VERSION "1.45.04 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 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_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 TMP_DIR "/wm_online_ids.txt" // webMAN config file to skip disable network setting on these title ids
#define WMOFFLINE_GAMES TMP_DIR "/wm_offline_ids.txt" // webMAN config file to disable network setting on specific title ids (overrides wm_online_ids.txt)
#define VSH_MENU_IMAGES "/dev_hdd0/plugins/images"
#define HDD0_GAME_DIR "/dev_hdd0/game/"
#define SYSMAP_PS3_UPDATE "/dev_flash/vsh/resource/AAA" //redirect firmware update to empty folder (formerly redirected to "/dev_bdvd")
#define PS2_CLASSIC_TOGGLER "/dev_hdd0/classic_ps2"
#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 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
///////////// 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 uint64_t 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 //////////////
#ifdef WM_REQUEST
#ifdef WEB_CHAT
#define DELETE_TURNOFF {do_umount(false); cellFsUnlink("/dev_hdd0/tmp/turnoff"); cellFsUnlink(WMREQUEST_FILE); cellFsUnlink(WMCHATFILE);}
#else
#define DELETE_TURNOFF {do_umount(false); cellFsUnlink("/dev_hdd0/tmp/turnoff"); cellFsUnlink(WMREQUEST_FILE);}
#endif
#else
#ifdef WM_CUSTOM_COMBO
#undef WM_CUSTOM_COMBO
#endif
#ifdef WEB_CHAT
#define DELETE_TURNOFF {do_umount(false); cellFsUnlink("/dev_hdd0/tmp/turnoff"); cellFsUnlink(WMCHATFILE);}
#else
#define DELETE_TURNOFF {do_umount(false); cellFsUnlink("/dev_hdd0/tmp/turnoff");}
#endif
#endif
#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_INSTALLPKG "install_pkg"
#define THREAD_NAME_NETSVR "netsvr"
#define THREAD_NAME_NETSVRD "netsvrd"
#define STOP_THREAD_NAME "wwwds"
#define THREAD_PRIO -0x1d8
#define THREAD_PRIO_FTP -0x10
#define THREAD_PRIO_NET -0x1d8
#define THREAD_PRIO_STOP 0x000
#define THREAD_STACK_SIZE_8KB 0x2000
#define THREAD_STACK_SIZE_64KB 0x10000
#define SYS_PPU_THREAD_CREATE_NORMAL 0x000
////////////
#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"
#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 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 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 _1MB_ 1048576UL
#define _32MB_ 33554432UL
#define MIN_MEM _192KB_
static u32 BUFFER_SIZE_FTP = ( _128KB_);
static u32 BUFFER_SIZE_ALL = ( 896*KB);
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_);
#ifdef MOUNT_ROMS
static u32 BUFFER_SIZE_ROM = ( _32KB_ / 2);
#endif
#define MAX_PAGES (BUFFER_SIZE_ALL / _64KB_)
////////////
#define MODE 0777
#define DMODE (CELL_FS_S_IFDIR | MODE)
#define LINELEN 512 // file listing
#define MAX_LINE_LEN 640 // html games
#define MAX_PATH_LEN 512 // do not change!
#define MAX_TEXT_LEN 2000 // should not exceed HTML_RECV_SIZE
#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_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
#define IS_ON_XMB (View_Find("game_plugin") == 0)
#define IS_INGAME (View_Find("game_plugin") != 0)
////////////
#ifdef COBRA_ONLY
#ifndef LITE_EDITION
static sys_ppu_thread_t thread_id_net = SYS_PPU_THREAD_NONE;
#endif
static sys_ppu_thread_t thread_id_ntfs = SYS_PPU_THREAD_NONE;
#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 {
uint32_t total;
uint32_t avail;
} _meminfo;
static uint8_t profile = 0;
static uint8_t loading_html = 0;
static uint8_t refreshing_xml = 0;
#ifdef SYS_BGM
static uint8_t system_bgm = 0;
#endif
#define NTFS (12)
#define PERSIST 100
static bool show_info_popup = false;
static bool do_restart = false;
#ifdef USE_DEBUG
static int debug_s = -1;
static char debug[256];
#endif
static volatile uint8_t wm_unload_combo = 0;
static volatile uint8_t working = 1;
static uint8_t max_mapped = 0;
#ifdef COBRA_ONLY
static const uint8_t cobra_mode = 1;
#else
static const uint8_t cobra_mode = 0;
#endif
static bool syscalls_removed = false;
static float c_firmware = 0.0f;
static uint8_t dex_mode = 0;
#ifdef SYS_ADMIN_MODE
static uint8_t sys_admin = 0;
static uint8_t pwd_tries = 0;
#else
static uint8_t sys_admin = 1;
#endif
#ifdef OFFLINE_INGAME
static int32_t 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
{
uint16_t version;
uint8_t padding0[14];
uint8_t lang;
// scan devices settings
uint8_t usb0;
uint8_t usb1;
uint8_t usb2;
uint8_t usb3;
uint8_t usb6;
uint8_t usb7;
uint8_t dev_sd;
uint8_t dev_ms;
uint8_t dev_cf;
uint8_t padding1[6];
// scan content settings
uint8_t refr;
uint8_t foot;
uint8_t cmask;
uint8_t nogrp;
uint8_t nocov;
uint8_t nosetup;
uint8_t rxvid;
uint8_t ps2l;
uint8_t pspl;
uint8_t tid;
uint8_t use_filename;
uint8_t launchpad_xml;
uint8_t launchpad_grp;
uint8_t ps3l;
uint8_t roms;
uint8_t padding2[17];
// start up settings
uint8_t wmstart;
uint8_t lastp;
uint8_t autob;
char autoboot_path[256];
uint8_t delay;
uint8_t bootd;
uint8_t boots;
uint8_t nospoof;
uint8_t blind;
uint8_t spp; //disable syscalls, offline: lock PSN, offline ingame
uint8_t noss; //no singstar
uint8_t nosnd0; //no snd0.at3
uint8_t padding3[5];
// fan control settings
uint8_t fanc;
uint8_t temp0;
uint8_t temp1;
uint8_t manu;
uint8_t ps2temp;
uint8_t nowarn;
uint8_t minfan;
uint8_t padding4[9];
// combo settings
uint8_t nopad;
uint8_t keep_ccapi;
uint32_t combo;
uint32_t combo2;
uint8_t padding5[22];
// ftp server settings
uint8_t bind;
uint8_t ftpd;
uint16_t ftp_port;
uint8_t ftp_timeout;
char ftp_password[20];
char allow_ip[16];
uint8_t padding6[7];
// net server settings
uint8_t netsrvd;
uint16_t netsrvp;
uint8_t padding7[13];
// net client settings
uint8_t netd[5];
uint16_t netp[5];
char neth[5][16];
uint8_t padding8[33];
// mount settings
uint8_t bus;
uint8_t fixgame;
uint8_t ps1emu;
uint8_t autoplay;
uint8_t padding9[12];
// profile settings
uint8_t profile;
char uaccount[9];
uint8_t admin_mode;
uint8_t padding10[5];
// misc settings
uint8_t default_restart;
uint8_t poll; // poll usb
uint32_t rec_video_format;
uint32_t rec_audio_format;
uint8_t auto_power_off; // 0 = prevent auto power off on ftp, 1 = allow auto power off on ftp (also on install.ps3, download.ps3)
uint8_t padding12[5];
uint8_t homeb;
char home_url[255];
uint8_t padding11[32];
// spoof console id
uint8_t sidps;
uint8_t spsid;
char vIDPS1[17];
char vIDPS2[17];
char vPSID1[17];
char vPSID2[17];
uint8_t padding13[34];
} /*__attribute__((packed))*/ WebmanCfg;
static uint8_t wmconfig[sizeof(WebmanCfg)];
static WebmanCfg *webman_config = (WebmanCfg*) wmconfig;
static int save_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 ".iso.0|.cue|.img|.mdf|.bin"
static CellRtcTick rTick, gTick;
#ifdef GET_KLICENSEE
int npklic_struct_offset = 0; uint8_t 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 uint16_t cobra_version = 0;
static bool is_mounting = false;
static bool copy_aborted = false;
#ifndef EMBED_JS
static bool css_exists = false;
static bool common_js_exists = false;
#endif
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[16][12] = {"/dev_hdd0", "/dev_usb000", "/dev_usb001", "/dev_usb002", "/dev_usb003", "/dev_usb006", "/dev_usb007", "/net0", "/net1", "/net2", "/net3", "/net4", "/ext", "/dev_sd", "/dev_ms", "/dev_cf"};
static char paths [13][12] = {"GAMES", "GAMEZ", "PS3ISO", "BDISO", "DVDISO", "PS2ISO", "PSXISO", "PSXGAMES", "PSPISO", "ISO", "video", "GAMEI", "ROMS"};
#ifdef COPY_PS3
static char cp_path[MAX_PATH_LEN]; // cut/copy/paste buffer
static uint8_t cp_mode = CP_MODE_NONE; // 0 = none / 1 = copy / 2 = cut/move
#endif
#define ONLINE_TAG "[online]"
#define OFFLINE_TAG "[offline]"
#define AUTOPLAY_TAG " [auto]"
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]
};
#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 int isDir(const char* path);
size_t read_file(const char *file, char *data, size_t size, int32_t offset);
int save_file(const char *file, const char *mem, int64_t size);
int waitfor(const char *path, uint8_t timeout);
#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"
int wwwd_start(uint64_t arg);
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
static void handleclient(u64 conn_s_p);
static void do_umount(bool clean);
static void mount_autoboot(void);
static bool mount_with_mm(const char *_path, u8 do_eject);
#ifdef COBRA_ONLY
static void do_umount_iso(void);
#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 bool from_reboot = false;
static bool is_busy = false;
#ifdef COPY_PS3
static char current_file[MAX_PATH_LEN];
#endif
#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/file.h"
#include "include/vsh.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/games_html.h"
#include "include/games_xml.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"
static inline void _sys_ppu_thread_exit(uint64_t 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, (uint64_t)(uint32_t)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, HTTP_RESPONSE_TITLE_LEN + strlen(msg), HTML_BODY, HTML_RESPONSE_TITLE, msg);
}
else
{
char templn[_2KB_];
if(*msg == '/')
{sprintf(templn, "%s : OK", msg+1); show_msg(templn);}
else if(islike(msg, "http"))
sprintf(templn, "<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(templn, "<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(templn, (char *)msg + 11); else strcat(templn, msg);
if(code == CODE_DOWNLOAD_FILE || extcasecmp(pkg_path, ".p3t", 4) != 0) strcat(templn, "<p>To: \0"); add_breadcrumb_trail(templn, p + 5);
}
else
strcat(templn, msg);
code = CODE_HTTP_OK;
}
#endif
else
sprintf(templn, "%s", msg);
if(ISDIGIT(*msg) && ( (code == CODE_SERVER_BUSY || code == CODE_BAD_REQUEST) )) show_msg((char*)templn + 4);
#ifndef EMBED_JS
if(css_exists)
{
sprintf(header, "<LINK href=\"%s\" rel=\"stylesheet\" type=\"text/css\">", COMMON_CSS); strcat(templn, header);
}
if(common_js_exists)
{
sprintf(header, SCRIPT_SRC_FMT, COMMON_SCRIPT_JS); strcat(templn, header);
}
#endif
sprintf(header, "<hr>" HTML_BUTTON_FMT "%s",
HTML_BUTTON, " ◀ ", HTML_ONCLICK, ((code == CODE_RETURN_TO_ROOT) ? "/" : "javascript:window.history.back();"), HTML_BODY_END); strcat(templn, header);
slen = sprintf(header, HTML_RESPONSE_FMT,
(code == CODE_RETURN_TO_ROOT) ? CODE_HTTP_OK : code, url, HTTP_RESPONSE_TITLE_LEN + strlen(templn), HTML_BODY, HTML_RESPONSE_TITLE, templn);
}
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 char *prepare_html(char *pbuffer, char *templn, char *param, u8 is_ps3_http, u8 is_cpursx, bool mount_ps3)
{
sprintf(pbuffer, HTML_HEADER); char *buffer = pbuffer + HTML_HEADER_SIZE;
if(is_cpursx)
buffer += concat(buffer, "<meta http-equiv=\"refresh\" content=\"6;URL=/cpursx.ps3\">");
if(mount_ps3) {strcat(buffer, HTML_BODY); return buffer;}
buffer += concat(buffer,
"<head><title>webMAN MOD</title>"
"<style>"
"a{" HTML_URL_STYLE "}"
"#rxml,#rhtm,#rcpy,#wmsg{position:fixed;top:40%;left:30%;width:40%;height:90px;z-index:5;border:5px solid #ccc;border-radius:25px;padding:10px;color:#fff;text-align:center;background-image:-webkit-gradient(linear,0 0,0 100%,color-stop(0,#999),color-stop(0.02,#666),color-stop(1,#222));background-image:-moz-linear-gradient(top,#999,#666 2%,#222);display:none;}"
"</style>"); // fallback style if external css fails
#ifndef EMBED_JS
if(param[1] == 0)
{
// minimize times that these files are checked (at startup & root)
css_exists = file_exists(COMMON_CSS);
common_js_exists = file_exists(COMMON_SCRIPT_JS);
}
if(css_exists)
{
sprintf(templn, "<LINK href=\"%s\" rel=\"stylesheet\" type=\"text/css\">", COMMON_CSS); buffer += concat(buffer, templn);
}
else
#endif
{
buffer += concat(buffer,
"<style type=\"text/css\"><!--\r\n"
"a.s:active{color:#F0F0F0;}"
"a:link{color:#909090;}"
"a.f:active{color:#F8F8F8;}"
"a,a.f:link,a:visited{color:#D0D0D0;}");
if(!is_cpursx)
buffer += concat(buffer,
"a.d:link{color:#D0D0D0;background:0px 2px url('data:image/gif;base64,R0lGODlhEAAMAIMAAOenIumzLbmOWOuxN++9Me+1Pe+9QvDAUtWxaffKXvPOcfTWc/fWe/fWhPfckgAAACH5BAMAAA8ALAAAAAAQAAwAAARQMI1Agzk4n5Sa+84CVNUwHAz4KWzLMo3SzDStOkrHMO8O2zmXsAXD5DjIJEdxyRie0KfzYChYr1jpYVAweb/cwrMbAJjP54AXwRa433A2IgIAOw==') no-repeat;padding:0 0 0 20px;}"
"a.w:link{color:#D0D0D0;background:url('data:image/gif;base64,R0lGODlhDgAQAIMAAAAAAOfn5+/v7/f39////////////////////////////////////////////wAAACH5BAMAAA8ALAAAAAAOABAAAAQx8D0xqh0iSHl70FxnfaDohWYloOk6papEwa5g37gt5/zO475fJvgDCW8gknIpWToDEQA7') no-repeat;padding:0 0 0 20px;}");
buffer += concat(buffer,
"a:active,a:active:hover,a:visited:hover,a:link:hover{color:#FFFFFF;}"
".list{display:inline;}"
#ifdef PS3MAPI
"table{border-spacing:0;border-collapse:collapse;}"
".la{text-align:left;float:left}.ra{text-align:right;float:right;}"
#endif
"input:focus{border:2px solid #0099FF;}"
".propfont{font-family:\"Courier New\",Courier,monospace;text-shadow:1px 1px #101010;}"
"body{background-color:#101010}body,a.s,td,th{color:#F0F0F0;white-space:nowrap");
//if(file_exists("/dev_hdd0/xmlhost/game_plugin/background.jpg"))
// buffer += concat(buffer, "background-image: url(\"/dev_hdd0/xmlhost/game_plugin/background.jpg\");");
if(is_ps3_http == 2)
buffer += concat(buffer, "width:800px;}");
else
buffer += concat(buffer, "}");
if(!islike(param, "/setup.ps3")) buffer += concat(buffer, "td+td{text-align:right;white-space:nowrap}");
if(islike(param, "/index.ps3"))
{
buffer += concat(buffer,
".gc{float:left;overflow:hidden;position:relative;text-align:center;width:280px;height:260px;margin:3px;border:1px dashed grey;}"
".ic{position:absolute;top:5px;right:5px;left:5px;bottom:40px;}");
if(is_ps3_http == 1)
buffer += concat(buffer, ".gi{height:210px;width:267px;");
else
buffer += concat(buffer, ".gi{max-height:210px;max-width:260px;");
buffer += concat(buffer,
"position:absolute;bottom:0px;top:0px;left:0px;right:0px;margin:auto;}"
".gn{position:absolute;height:38px;bottom:0px;right:7px;left:7px;text-align:center;}");
}
buffer += concat(buffer, ".bu{background:#444;}.bf{background:#121;}--></style>");
}
if(param[1] != NULL && !strstr(param, ".ps3")) {buffer += concat(buffer, "<base href=\""); urlenc(templn, param); strcat(templn, "/\">"); buffer += concat(buffer, templn);}
if(is_ps3_http == 1)
{sprintf(templn, "<style>%s</style>", ".gi{height:210px;width:267px"); buffer += concat(buffer, templn);}
sprintf(templn, "</head>%s", HTML_BODY); buffer += concat(buffer, templn);
char slider[40]; if(file_exists(MOBILE_HTML)) sprintf(slider, " [<a href=\"/games.ps3\">Slider</a>]"); else *slider = NULL;
if(sys_admin)
{
#ifdef PS3MAPI
#ifdef WEB_CHAT
sprintf(templn, "webMAN " WM_VERSION " %s <font style=\"font-size:18px\">[<a href=\"/\">%s</a>] [<a href=\"/index.ps3\">%s</a>]%s [<a href=\"/chat.ps3\">Chat</a>] [<a href=\"/home.ps3mapi\">PS3MAPI</a>] [<a href=\"/setup.ps3\">%s</a>]</b>", STR_TRADBY, STR_FILES, STR_GAMES, slider, STR_SETUP);
#else
sprintf(templn, "webMAN " WM_VERSION " %s <font style=\"font-size:18px\">[<a href=\"/\">%s</a>] [<a href=\"/index.ps3\">%s</a>]%s [<a href=\"/home.ps3mapi\">PS3MAPI</a>] [<a href=\"/setup.ps3\">%s</a>]</b>", STR_TRADBY, STR_FILES, STR_GAMES, slider, STR_SETUP );
#endif
#else
#ifdef WEB_CHAT
sprintf(templn, "webMAN " WM_VERSION " %s <font style=\"font-size:18px\">[<a href=\"/\">%s</a>] [<a href=\"/index.ps3\">%s</a>]%s [<a href=\"/chat.ps3\">Chat</a>] [<a href=\"/setup.ps3\">%s</a>]</b>", STR_TRADBY, STR_FILES, STR_GAMES, slider, STR_SETUP);
#else
sprintf(templn, "webMAN " WM_VERSION " %s <font style=\"font-size:18px\">[<a href=\"/\">%s</a>] [<a href=\"/index.ps3\">%s</a>]%s [<a href=\"/setup.ps3\">%s</a>]</b>", STR_TRADBY, STR_FILES, STR_GAMES, slider, STR_SETUP );
#endif
#endif
}
#ifdef SYS_ADMIN_MODE
else
sprintf(templn, "webMAN " WM_VERSION " %s <font style=\"font-size:18px\">[<a href=\"/\">%s</a>] [<a href=\"/index.ps3\">%s</a>]%s</b>", STR_TRADBY, STR_FILES, STR_GAMES, slider);
#endif
buffer += concat(buffer, templn);
return buffer;
}
static void handleclient(u64 conn_s_p)
{
int conn_s = (int)conn_s_p; // main communications socket
size_t header_len;
sys_addr_t sysmem = NULL;
char param[HTML_RECV_SIZE];
int fd;
char *file_query = param + HTML_RECV_LAST; *file_query = NULL;
if(conn_s_p == START_DAEMON || conn_s_p == REFRESH_CONTENT)
{
if(conn_s_p == START_DAEMON)
{
vshnet_setUpdateUrl("http://127.0.0.1/dev_hdd0/ps3-updatelist.txt"); // custom update file
#ifndef ENGLISH_ONLY
update_language();