-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
11105 lines (9562 loc) · 776 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 <arpa/inet.h>
#include <netinet/in.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>
//#define ENGLISH_ONLY 1 // uncomment for english only version
//#define USE_DEBUG 1
//#define EXTRA_FEAT 1
//#define CCAPI 1 // uncomment for ccapi release
#define COBRA_ONLY 1 // comment out for ccapi/non-cobra release
//#define REX_ONLY 1 // shortcuts for REBUG REX CFWs / comment out for usual CFW
//#define LITE_EDITION 1 // no ps3netsrv support, smaller memory footprint
#include "types.h"
#include "common.h"
#include "printf.h"
#include "cobra/storage.h"
#ifdef COBRA_ONLY
#include "cobra/cobra.h"
#include "cobra/netiso.h"
#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 SYS_COBRA_PATH "/dev_blind/sys/"
#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 WM_VERSION "1.34.07 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 WMNOSCAN "/dev_hdd0/tmp/wm_noscan" // webMAN config file
#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 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_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_PRX_MODULE_BY_ADDRESS (461)
#define SC_STOP_PRX_MODULE (482)
#define SC_PPU_THREAD_EXIT (41)
#define SC_SYS_POWER (379)
#define SYS_SOFT_REBOOT 0x200
//#define SYS_HARD_REBOOT 0x1200
#define SYS_REBOOT 0x8201
#define SYS_SHUTDOWN 0x1100
#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 MB 1048576UL
#define FAILED -1
#define FTP_RECV_SIZE 2048
#define HTML_RECV_SIZE 1024
static u32 BUFFER_SIZE_FTP = ( 128*KB);
static u32 BUFFER_SIZE = ( 448*KB);
static u32 BUFFER_SIZE_PSX = ( 160*KB);
static u32 BUFFER_SIZE_PSP = ( 32*KB);
static u32 BUFFER_SIZE_PS2 = ( 64*KB);
static u32 BUFFER_SIZE_DVD = ( 192*KB);
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 MIN(a, b) ((a) <= (b) ? (a) : (b))
#define ABS(a) (((a) < 0) ? -(a) : (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 IS_COPY 9
#define COPY_WHOLE_FILE 0
#define MOUNT_EXT_GDATA 2
#define START_DAEMON (0xC0FEBABE)
#define REFRESH_CONTENT (0xC0FEBAB0)
#define LV1_UPPER_MEMORY 0x8000000001000000ULL
#define LV2_UPPER_MEMORY 0x8000000000800000ULL
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 numtracks;
uint16_t port;
uint8_t pad[6];
ScsiTrackDescriptor tracks[1];
} __attribute__((packed)) netiso_args;
#endif
typedef struct
{
uint64_t device;
uint32_t emu_mode;
uint32_t num_sections;
uint32_t num_tracks;
} __attribute__((packed)) rawseciso_args;
static uint32_t *sections, *sections_size;
static uint32_t num_sections;
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 extgd = 0;
static u8 profile = 0;
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
static uint64_t discsize;
static int is_cd2352;
static uint8_t *cd_cache;
static uint32_t cached_cd_sector=0x80000000;
#endif
#define NTFS (10)
#define 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;
#define MAX_LAST_GAMES (5)
typedef struct
{
uint8_t last;
char game[MAX_LAST_GAMES][512];
} __attribute__((packed)) _lastgames;
static _lastgames lastgames;
#ifdef USE_DEBUG
static int debug_s=-1;
static char debug[256];
#endif
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 = SYSCALL_TABLE_465;
#ifndef COBRA_ONLY
static bool save_libfs_new=true;
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 fanm; //unused
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;
} __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)
#ifdef REX_ONLY
#define REBUGMODE (1<<13)
#define NORMAMODE (1<<14)
#define DEBUGMENU (1<<15)
#endif
#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
uint64_t get_fan_policy_offset=0;
uint64_t set_fan_policy_offset=0;
char *strcasestr(const char *s1, const char *s2);
int set_gamedata_status(u8 status, bool do_mount);
void set_buffer_sizes();
void get_idps_psid();
void no_singstar_icon();
void enable_dev_blind(char *msg);
void reset_settings(void);
int save_settings(void);
static u64 backup[6];
static u8 wmconfig[sizeof(WebmanCfg)];
static WebmanCfg *webman_config = (WebmanCfg*) wmconfig;
static char ftp_password[20]="";
static char smonth[12][4]={"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static char drives[11][12]={"/dev_hdd0", "/dev_usb000", "/dev_usb001", "/dev_usb002", "/dev_usb003", "/dev_usb006", "/dev_usb007", "/net0", "/net1", "/net2", "/ext"};
static char paths [11][12]={"GAMES", "GAMEZ", "PS3ISO", "BDISO", "DVDISO", "PS2ISO", "PSXISO", "PSXGAMES", "PSPISO", "ISO", "video"};
static char wm_icons[12][60]={"/dev_hdd0/tmp/wm_icons/icon_wm_album_ps3.png", //024.png [0]
"/dev_hdd0/tmp/wm_icons/icon_wm_album_psx.png", //026.png [1]
"/dev_hdd0/tmp/wm_icons/icon_wm_album_ps2.png", //025.png [2]
"/dev_hdd0/tmp/wm_icons/icon_wm_album_psp.png", //022.png [3]
"/dev_hdd0/tmp/wm_icons/icon_wm_album_dvd.png", //023.png [4]
"/dev_hdd0/tmp/wm_icons/icon_wm_ps3.png", //024.png [5]
"/dev_hdd0/tmp/wm_icons/icon_wm_psx.png", //026.png [6]
"/dev_hdd0/tmp/wm_icons/icon_wm_ps2.png", //025.png [7]
"/dev_hdd0/tmp/wm_icons/icon_wm_psp.png", //022.png [8]
"/dev_hdd0/tmp/wm_icons/icon_wm_dvd.png", //023.png [9]
"/dev_hdd0/tmp/wm_icons/icon_wm_settings.png", //icon/icon_home.png [10]
"/dev_hdd0/tmp/wm_icons/icon_wm_eject.png" //icon/icon_home.png [11]
};
static bool covers_exist[7];
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
#define STR_TRADBY ""
#define STR_FILES "Files"
#define STR_GAMES "Games"
#define STR_SETUP "Setup"
#define STR_HOME "Home"
#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_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_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"
#define STR_NOSINGSTAR "Remove SingStar icon"
#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_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=\"/dev_hdd0/xmlhost/game_plugin/mygames.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
char lang_code[3] = "";
char STR_TRADBY[150] = "";
char STR_FILES[30] = "Files";
char STR_GAMES[30] = "Games";
char STR_SETUP[30] = "Setup";
char STR_HOME[30] = "Home";
char STR_EJECT[50] = "Eject";
char STR_INSERT[50] = "Insert";
char STR_UNMOUNT[50] = "Unmount";
char STR_COPY[50] = "Copy Folder";
char STR_REFRESH[50] = "Refresh";
char STR_SHUTDOWN[50] = "Shutdown";
char STR_RESTART[50] = "Restart";
char STR_BYTE[10] = "b";
char STR_KILOBYTE[10] = "KB";
char STR_MEGABYTE[10] = "MB";
char STR_GIGABYTE[10] = "GB";
char STR_COPYING[30] = "Copying";
char STR_CPYDEST[30] = "Destination";
char STR_CPYFINISH[30] = "Copy Finished!";
char STR_CPYABORT[50] = "Copy aborted!";
char STR_DELETE[50] = "Delete";
char STR_SCAN1[100] = "Scan these devices";
char STR_SCAN2[100] = "Scan for content";
char STR_PSPL[100] = "Show PSP Launcher";
char STR_PS2L[100] = "Show PS2 Classic Launcher";
char STR_VIDLG[30] = "Video";
char STR_LPG[100] = "Load last-played game on startup";
char STR_AUTOB[150] = "Check for /dev_hdd0/PS3ISO/AUTOBOOT.ISO on startup";
char STR_DELAYAB[200] = "Delay loading of AUTOBOOT.ISO/last-game (Disc Auto-start)";
char STR_DEVBL[150] = "Enable /dev_blind (writable /dev_flash) on startup";
char STR_CONTSCAN[150] = "Disable content scan on startup";
char STR_USBPOLL[100] = "Disable USB polling";
char STR_FTPSVC[100] = "Disable FTP service";
char STR_COMBOS[100] = "Disable all PAD shortcuts";
char STR_MMCOVERS[100] = "Disable multiMAN covers";
char STR_ACCESS[100] = "Disable remote access to FTP/WWW services";
char STR_NOSETUP[150] = "Disable webMAN Setup entry in \"webMAN Games\"";
char STR_NOSPOOF[100] = "Disable firmware version spoofing";
char STR_NOGRP[100] = "Disable grouping of content in \"webMAN Games\"";
char STR_NOWMDN[200] = "Disable startup notification of WebMAN on the XMB";
char STR_NOSINGSTAR[100] = "Remove SingStar icon";
char STR_TITLEID[200] = "Include the ID as part of the title of the game";
char STR_FANCTRL[120] = "Enable dynamic fan control";
char STR_NOWARN[120] = "Disable temperature warnings";
char STR_AUTOAT[100] = "Auto at";
char STR_LOWEST[30] = "Lowest";
char STR_FANSPEED[80] = "fan speed";
char STR_MANUAL[30] = "Manual";
char STR_PS2EMU[100] = "PS2 Emulator";
char STR_LANGAMES[100] = "Scan for LAN games/videos";
char STR_ANYUSB[100] = "Wait for any USB device to be ready";
char STR_ADDUSB[150] = "Wait additionally for each selected USB device to be ready";
char STR_SPOOFID[150] = "Change idps and psid in lv2 memory at system startup";
char STR_DELCFWSYS[200] = "Disable lv1&lv2 peek&poke syscalls (6,7,9,10,36) and delete history files at system startup";
char STR_MEMUSAGE[100] = "Plugin memory usage";
char STR_PLANG[100] = "Plugin language";
char STR_PROFILE[30] = "Profile";
char STR_DEFAULT[30] = "Default";
char STR_COMBOS2[100] = "XMB/In-Game PAD SHORTCUTS";
char STR_FAILSAFE[100] = "FAIL SAFE";
char STR_SHOWTEMP[100] = "SHOW TEMP";
char STR_SHOWIDPS[100] = "SHOW IDPS";
char STR_PREVGAME[100] = "PREV GAME";
char STR_NEXTGAME[100] = "NEXT GAME";
char STR_SHUTDOWN2[100] = "SHUTDOWN ";
char STR_RESTART2[100] = "RESTART ";
char STR_DELCFWSYS2[100] = "DEL CFW SYSCALLS";
char STR_UNLOADWM[100] = "UNLOAD WM";
char STR_FANCTRL2[100] = "CTRL FAN";
char STR_FANCTRL4[100] = "CTRL DYN FAN";
char STR_FANCTRL5[100] = "CTRL MIN FAN";
char STR_UPDN[20] = "↑/↓"; //↑/↓
char STR_LFRG[20] = "←/→"; //←/→
#ifdef COBRA_ONLY
char STR_DISCOBRA[100] = "COBRA TOGGLE";
#endif
#ifdef REX_ONLY
char STR_RBGMODE[100] = "RBG MODE TOGGLE";
char STR_RBGNORM[100] = "NORM MODE TOGGLE";
char STR_RBGMENU[100] = "MENU TOGGLE";
#endif
char STR_SAVE[30] = "Save";
char STR_SETTINGSUPD[250] = "Settings updated.<br><br>Click <a href=\"/restart.ps3\">here</a> to restart your PLAYSTATION®3 system.";
char STR_ERROR[30] = "Error!";
char STR_MYGAMES[50] = "webMAN Games";
char STR_LOADGAMES[80] = "Load games with webMAN";
char STR_WMSETUP[50] = "webMAN Setup";
char STR_WMSETUP2[50] = "Setup webMAN options";
char STR_EJECTDISC[50] = "Eject Disc";
char STR_UNMOUNTGAME[100] = "Unmount current game";
char STR_WMSTART[50] = "webMAN loaded!";
char STR_WMUNL[80] = "webMAN unloaded!";
char STR_CFWSYSALRD[130] = "CFW Syscalls already disabled";
char STR_CFWSYSRIP[130] = "Removal History files & CFW Syscalls in progress...";
char STR_RMVCFWSYS[130] = "History files & CFW Syscalls deleted OK!";
char STR_RMVCFWSYSF[130] = "Failed to remove CFW Syscalls";
char STR_RMVWMCFG[130] = "webMAN config reset in progress...";
char STR_RMVWMCFGOK[130] = "Done! Restart within 3 seconds";
char STR_PS3FORMAT[50] = "PS3 format games";
char STR_PS2FORMAT[50] = "PS2 format games";
char STR_PS1FORMAT[50] = "PSOne format games";
char STR_PSPFORMAT[50] = "PSP\xE2\x84\xA2 format games";
char STR_VIDFORMAT[50] = "Blu-ray\xE2\x84\xA2 and DVD";
char STR_VIDEO[50] = "Video content";
char STR_LAUNCHPSP[100] = "Launch PSP ISO mounted through webMAN or mmCM";
char STR_LAUNCHPS2[100] = "Launch PS2 Classic";
char STR_GAMEUM[50] = "Game unmounted.";
char STR_EJECTED[50] = "Disc ejected.";
char STR_LOADED[50] = "Disc inserted.";
char STR_GAMETOM[50] = "Game to mount";
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.";
char STR_PSPLOADED[230] = "Game loaded successfully. Start the game using <b>PSP Launcher</b>.<hr/>";
char STR_PS2LOADED[230] = "Game loaded successfully. Start the game using <b>PS2 Classic Launcher</b>.<hr/>";
char STR_LOADED2[50] = "loaded ";
char STR_MOVIETOM[50] = "Movie to mount";
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.";
char STR_XMLRF[200] = "Game list refreshed (<a href=\"/dev_hdd0/xmlhost/game_plugin/mygames.xml\">mygames.xml</a>).<br>Click <a href=\"/restart.ps3\">here</a> to restart your PLAYSTATION®3 system now.";
char STR_STORAGE[50] = "System storage";
char STR_MEMORY[50] = "Memory available";
char STR_MBFREE[50] = "MB free";
char STR_KBFREE[50] = "KB free";
char STR_FANCTRL3[50] = "Fan control:";
char STR_ENABLED[50] = "Enabled";
char STR_DISABLED[50] = "Disabled";
char STR_FANCH0[50] = "Fan setting changed:";
char STR_FANCH1[50] = "MAX TEMP: ";
char STR_FANCH2[50] = "FAN SPEED: ";
char STR_FANCH3[50] = "MIN FAN SPEED: ";
char STR_OVERHEAT[100] = "System overheat warning!";
char STR_OVERHEAT2[100] = " OVERHEAT DANGER!\r\nFAN SPEED INCREASED!";
char STR_NOTFOUND[50] = "Not found!";
char COVERS_PATH[100] = "";
#endif
int wwwd_start(uint64_t arg);
int wwwd_stop(void);
#ifdef COBRA_ONLY
static int remote_stat(int s, char *path, int *is_directory, int64_t *file_size, uint64_t *mtime, uint64_t *ctime, uint64_t *atime, int *abort_connection);
#endif
static inline void get_temperature(u32 _dev, u32 *_temp);
void fan_control(u8 temp0, u8 maxtemp);
static inline void led(u64 color, u64 mode);
void restore_fan(u8 settemp);
int savefile(char *file, char *mem, u64 size);
int filecopy(char *file1, char *file2, uint64_t maxbytes);
int folder_copy(char *path1, char *path2);
void absPath(char* absPath_s, const char* path, const char* cwd);
int isDir(const char* path);
int ssplit(const char* str, char* left, int lmaxlen, char* right, int rmaxlen);
int slisten(int port, int backlog);
void sclose(int *socket_e);
int del(char *path, bool recursive);
int import_edats(char *path1, char *path2);
void update_language();
void detect_firmware();
void remove_cfw_syscalls();
void delete_history(bool delete_folders);
bool language(const char *file_str, char *default_str);
void block_online_servers();
char h2a(char hex);
void strenc(char *dst, char *src);
int my_atoi(const char *c);
static void do_umount(bool clean);
static void do_umount_iso(void);
static void mount_with_mm(const char *_path, u8 do_eject);
void eject_insert(u8 eject, u8 insert);
bool copy_in_progress = false;
bool copy_aborted = false;
bool is_busy = false;
bool is_mounting = false;
void show_msg(char* msg);
//void show_msg2(char* msg);
//int (*_cellGcmIoOffsetToAddress)(uint32_t, void**) = NULL;
int (*vshtask_notify)(int, const char *) = NULL;
#ifndef LITE_EDITION
//#include "vsh/xmb_plugin.h"
//#include "vsh/rec_plugin.h"
//#include "vsh/game_plugin.h"
#include "vsh/system_plugin.h"
#endif
int (*vshmain_is_ss_enabled)() = NULL;
int (*set_SSHT_)(int) = NULL;
int opd[2] = {0,0};
void * getNIDfunc(const char * vsh_module, uint32_t fnid);
void * getNIDfunc(const char * vsh_module, uint32_t fnid)
{
// 0x10000 = ELF
// 0x10080 = segment 2 start
// 0x10200 = code start
uint32_t table = (*(uint32_t*)0x1008C) + 0x984; // vsh table address
// uint32_t table = (*(uint32_t*)0x1002C) + 0x214 - 0x10000; // vsh table address
// uint32_t table = 0x63A9D4;
while(((uint32_t)*(uint32_t*)table) != 0)
{
uint32_t* export_stru_ptr = (uint32_t*)*(uint32_t*)table; // ptr to export stub, size 2C, "sys_io" usually... Exports:0000000000635BC0 stru_635BC0: ExportStub_s <0x1C00, 1, 9, 0x39, 0, 0x2000000, aSys_io, ExportFNIDTable_sys_io, ExportStubTable_sys_io>
const char* lib_name_ptr = (const char*)*(uint32_t*)((char*)export_stru_ptr + 0x10);
if(strncmp(vsh_module, lib_name_ptr, strlen(lib_name_ptr))==0)
{
// we got the proper export struct
uint32_t lib_fnid_ptr = *(uint32_t*)((char*)export_stru_ptr + 0x14);
uint32_t lib_func_ptr = *(uint32_t*)((char*)export_stru_ptr + 0x18);
uint16_t count = *(uint16_t*)((char*)export_stru_ptr + 6); // number of exports
for(int i=0;i<count;i++)
{
if(fnid == *(uint32_t*)((char*)lib_fnid_ptr + i*4))
{
// take adress from OPD
return (void**)*((uint32_t*)(lib_func_ptr) + i);
}
}
}
table=table+4;
}
return 0;
}
void show_msg(char* msg)
{
if(!vshtask_notify)
vshtask_notify = (void*)((int)getNIDfunc("vshtask", 0xA02D46E7));
if(vshtask_notify)
vshtask_notify(0, msg);
}
#ifndef LITE_EDITION
/*
void log(char * buffer)
{
console_write(buffer);
int fd;
if(cellFsOpen("/dev_hdd0/plugins/webMAN_MOD.log", CELL_FS_O_RDWR|CELL_FS_O_CREAT|CELL_FS_O_APPEND, &fd, NULL, 0) == CELL_OK)
{
uint64_t nrw; int size = strlen(buffer);
cellFsWrite(fd, buffer, size, &nrw);
}
cellFsClose(fd);
}
void show_msg2(char* msg) // usage: show_msg2(L"text");
{
if(View_Find("xmb_plugin") != 0)
{
xmb2_interface = (xmb_plugin_xmb2 *)plugin_GetInterface(View_Find("xmb_plugin"),'XMB2');
xmb2_interface->DoUnk22(msg);
}
}
*/
void saveBMP()
{
if(View_Find("game_plugin") == 0)
{
system_interface = (system_plugin_interface *)plugin_GetInterface(View_Find("system_plugin"),1); // 1=regular xmb, 3=ingame xmb (doesnt work)
CellRtcDateTime t;
cellRtcGetCurrentClockLocalTime(&t);
cellFsMkdir((char*)"/dev_hdd0/PICTURE", 0777);
char bmp[0x50];
vsh_sprintf(bmp,"/dev_hdd0/PICTURE/ScreenShot_%04d.%02d.%02d_%02d_%02d_%02d.bmp",t.year,t.month,t.day,t.hour,t.minute,t.second);
system_interface->saveBMP(bmp);
show_msg(bmp);
}
}
#endif
#ifndef COBRA_ONLY
void string_to_lv2(char* path, u64 addr);
void add_to_map(char *path1, char *path2);
#endif
uint64_t peekq(uint64_t addr);
void pokeq( uint64_t addr, uint64_t val);
void poke_lv1( uint64_t addr, uint64_t val);
u32 lv2peek32(u64 addr);
void lv2poke32(u64 addr, u32 value);
u32 lv2peek32(u64 addr)
{
u32 ret = (u32) (peekq(addr) >> 32ULL);
return ret;
}
void lv2poke32(u64 addr, u32 value)
{
pokeq(addr, (((u64) value) <<32) | (peekq(addr) & 0xffffffffULL));
}
#define PS3 (1<<0)
#define PS2 (1<<1)
#define PS1 (1<<2)
#define PSP (1<<3)
#define BLU (1<<4)
#define DVD (1<<5)
#define RED 0
#define GREEN 1
#define YELLOW 2
#define OFF 0
#define ON 1
#define BLINK 2
static inline void led(u64 color, u64 mode)
{
system_call_2(SC_SYS_CONTROL_LED, (u64)color, (u64)mode);
}
static inline void get_temperature(u32 _dev, u32 *_temp)
{
system_call_2(SC_GET_TEMPERATURE, (u64)_dev, (u64)_temp);
}
static int sys_sm_set_fan_policy(u8 arg0, u8 arg1, u8 arg2)
{
system_call_3(SC_SET_FAN_POLICY, (u64) arg0, (u64) arg1, (u64) arg2);
return_to_user_prog(int);
}
static int sys_sm_get_fan_policy(u8 id, u8 *st, u8 *mode, u8 *speed, u8 *unknown)
{