forked from Based-Skid/iLaunchELF
-
Notifications
You must be signed in to change notification settings - Fork 5
/
misc.c
212 lines (164 loc) · 5.32 KB
/
misc.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
#include <errno.h>
#include <loadfile.h>
#include <sbv_patches.h>
#include "malloc.h"
#include "VTSPS2-HBDL.h"
#include "include/pad.h"
// Modules
extern unsigned char freesio2[];
extern unsigned int size_freesio2;
extern unsigned char iomanX[];
extern unsigned int size_iomanX;
extern unsigned char fileXio[];
extern unsigned int size_fileXio;
extern unsigned char freepad[];
extern unsigned int size_freepad;
extern unsigned char poweroff[];
extern unsigned int size_poweroff;
extern unsigned char mcman[];
extern unsigned int size_mcman;
extern unsigned char mcserv[];
extern unsigned int size_mcserv;
extern unsigned char ps2dev9[];
extern unsigned int size_ps2dev9;
extern unsigned char netman[];
extern unsigned int size_netman;
extern unsigned char smap[];
extern unsigned int size_smap;
extern unsigned char ps2ipnm[];
extern unsigned int size_ps2ipnm;
extern unsigned char ps2ips[];
extern unsigned int size_ps2ips;
extern unsigned char ps2http[];
extern unsigned int size_ps2http;
extern unsigned char usbd[];
extern unsigned int size_usbd;
extern unsigned char usbhdfsd[];
extern unsigned int size_usbhdfsd;
static void ResetIOP()
{
SifInitRpc(0); //Initialize SIFRPC and SIFCMD. Although seemingly unimportant, this will update the addresses on the EE, which can prevent a crash from happening around the IOP reboot.
while(!SifIopReset("", 0)){}; //Reboot IOP with default modules (empty command line)
while(!SifIopSync()){} //Wait for IOP to finish rebooting.
SifInitRpc(0); //Initialize SIFRPC and SIFCMD.
SifLoadFileInit(); //Initialize LOADFILE RPC.
// SBV Patches Are Not part of a Normal IOP Reset.
sbv_patch_enable_lmb(); //SBV Patches
sbv_patch_disable_prefix_check(); //SBV Patch Load Executable IRX And ELF Files From User-Writable Storage
//sbv_patch_user_mem_clear(0x00100000); // You Can Specify a Starting Address for the Wipe
//sbv_patch_user_mem_clear(0x02000000); // Disable Clear Memory With LoadExecPS2() when 0x02000000 is passed as an arg
}
static void gotoOSDSYS(void)
{
ResetIOP();
LoadExecPS2("rom0:OSDSYS", 0, NULL);
}
// might be better off immediatley returning and exiting if certain modules don't load idk but this looks neater.. for now..
int loadModules(void)
{
int ret;
ret = SifExecModuleBuffer(&freesio2, size_freesio2, 0, NULL, NULL);
if (ret < 0)
printf("Failed to Load freesio2 sw module");
ret = SifExecModuleBuffer(&iomanX, size_iomanX, 0, NULL, NULL);
if (ret < 0)
printf("Failed to Load iomanx sw module");
ret = SifExecModuleBuffer(&freepad, size_freepad, 0, NULL, NULL);
if (ret < 0)
printf("Failed to Load freepad sw module");
ret = SifExecModuleBuffer(&mcman, size_mcman, 0, NULL, NULL);
if (ret < 0)
printf("Failed to Load mcman sw module");
ret = SifExecModuleBuffer(&mcserv, size_mcserv, 0, NULL, NULL);
if (ret < 0)
printf("Failed to Load mcserv sw module");
ret = SifExecModuleBuffer(&ps2dev9, size_ps2dev9, 0, NULL, NULL);
if (ret < 0)
printf(" Could not load ps2dev9.IRX! %d\n", ret);
ret = SifExecModuleBuffer(&netman, size_netman, 0, NULL, NULL);
if (ret < 0)
printf(" Could not load netman.IRX! %d\n", ret);
ret = SifExecModuleBuffer(&smap, size_smap, 0, NULL, NULL);
if (ret < 0)
printf(" Could not load smap.IRX! %d\n", ret);
ret = SifExecModuleBuffer(&ps2ipnm, size_ps2ipnm, 0, NULL, NULL);
if (ret < 0)
printf(" Could not load ps2ip.IRX! %d\n", ret);
ret = SifExecModuleBuffer(&ps2ips, size_ps2ips, 0, NULL, NULL);
if (ret < 0)
printf(" Could not load ps2ips.IRX! %d\n", ret);
ps2ip_init(); //interesting place to put it..
ret = SifExecModuleBuffer(&ps2http, size_ps2http, 0, NULL, NULL);
if (ret < 0)
printf(" Could not load ps2http.IRX! %d\n", ret);
ret = SifExecModuleBuffer(&usbd, size_usbd, 0, NULL, NULL);
if (ret < 0)
printf(" Could not load usbd.IRX! %d\n", ret);
ret = SifExecModuleBuffer(&usbhdfsd, size_usbhdfsd, 0, NULL, NULL);
if (ret < 0)
printf(" Could not load usbhdfsd.IRX! %d\n", ret);
return ret;
}
void init(void)
{
int ret;
ResetIOP();
ret = loadModules();
if (ret < 0)
gotoOSDSYS();
pad_init();
}
void deinit(int browser)
{
menuEnd();
guiEnd();
if (browser)
gotoOSDSYS();
}
// This function is public domain -- Will Hartung 4/9/09 */
// Modifications, public domain as well, by Antti Haapala, 11/10/17
// - Switched to getc on 5/23/19 */
// if typedef doesn't exist (msvc, blah)
//typedef intptr_t ssize_t;
ssize_t getline(char **lineptr, size_t *n, FILE *stream)
{
size_t pos;
int c;
if (lineptr == NULL || stream == NULL || n == NULL) {
errno = EINVAL;
return -1;
}
c = getc(stream);
if (c == EOF) {
return -1;
}
if (*lineptr == NULL) {
*lineptr = malloc(128);
if (*lineptr == NULL) {
return -1;
}
*n = 128;
}
pos = 0;
while(c != EOF) {
if (pos + 1 >= *n) {
size_t new_size = *n + (*n >> 2);
if (new_size < 128) {
new_size = 128;
}
char *new_ptr = realloc(*lineptr, new_size);
if (new_ptr == NULL) {
return -1;
}
*n = new_size;
*lineptr = new_ptr;
}
((unsigned char *)(*lineptr))[pos ++] = c;
if (c == '\n') {
break;
}
c = getc(stream);
}
(*lineptr)[pos] = '\0';
return pos;
}