-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathmcsp_rpc.c
235 lines (190 loc) · 7.07 KB
/
mcsp_rpc.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
/*
_____ ___ ____
____| | ____| PS2 Open Source Project
| ___| |____
---------------------------------------------------------------------------
Copyright (C) 2008 - Neme & jimmikaelkael (www.psx-scene.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the Free McBoot License.
This program and any related documentation is provided "as is"
WITHOUT ANY WARRANTIES, either express or implied, including, but not
limited to, implied warranties of fitness for a particular purpose. The
entire risk arising out of use or performance of the software remains
with you.
In no event shall the author be liable for any damages whatsoever
(including, without limitation, damages to your hardware or equipment,
environmental damage, loss of health, or any kind of pecuniary loss)
arising out of the use of or inability to use this software or
documentation, even if the author has been advised of the possibility of
such damages.
You should have received a copy of the Free McBoot License along with
this program; if not, please report at psx-scene :
http://psx-scene.com/forums/freevast/
---------------------------------------------------------------------------
mcsp_rpc.c
*/
#include <tamtypes.h>
#include <kernel.h>
#include <sifrpc.h>
#include <stdio.h>
#include <string.h>
//#include <sysclib.h>
#define MCSP_IRX 0x0A0A0A0
int mcsp_rpc_Init(void);
int MC_OSD_Scan(u16 port, u16 slot, char *file, u16 size);
int MC_Dummies_Patch(u16 port, u16 slot, void *file_entry, int num_entries, int linking_cluster, int filesize, void *return_entry);
int MC_Dummies_UnPatch(u16 port, u16 slot, void* uninstall_entry, u16 num_entries, u32 linked_filesize, u16 linked_cluster);
static SifRpcClientData_t mcsp __attribute__((aligned(64)));
static int Rpc_Buffer[1024] __attribute__((aligned(64)));
typedef struct {
char name [16];
u16 size_name;
int page;
} fileentry;
typedef struct {
u16 attr;
u32 size;
u16 entry_cluster;
char name [16];
} returnentry;
typedef struct {
u32 ret;
u16 port;
u16 slot;
fileentry file_entry[42];
int num_entries;
int linking_cluster;
int filesize;
char uninstall_file [0x40];
} Rpc_Packet_Send_MC_DUMMIES_PATCH;
typedef struct {
u32 ret;
returnentry return_entry[42];
} Rpc_Packet_Return_MC_DUMMIES_PATCH;
typedef struct {
u32 ret;
u16 port;
u16 slot;
char file [0x40];
u16 size;
} Rpc_Packet_Send_MC_OSD_SCAN;
typedef struct {
u32 ret;
u16 port;
u16 slot;
returnentry uninstall_entry[42];
u16 num_entries;
u32 linked_filesize;
u16 linked_cluster; // 1024 bytes buffer limit reached !!!
} Rpc_Packet_Send_MC_DUMMIES_UNPATCH;
int MCSP_Inited = 0;
//--------------------------------------------------------------
int mcspBindRpc(void) {
int ret;
int retryCount = 0x1000;
while(retryCount--) {
ret = SifBindRpc( &mcsp, MCSP_IRX, 0);
if ( ret < 0) {
printf("MCSP: EE Bind RPC Error.\n");
return -1;
}
if (mcsp.server != 0){
printf("MCSP: EE Bind RPC Set.\n");
break;
}
// short delay
ret = 0x10000;
while(ret--) asm("nop\nnop\nnop\nnop");
}
MCSP_Inited = 1;
return retryCount;
}
//--------------------------------------------------------------
int mcsp_rpc_Init(void)
{
mcspBindRpc();
if(!MCSP_Inited)
{
printf("\tmcsp RPC Init failed\n");
return -1;
}
return 1;
}
//--------------------------------------------------------------
int MC_OSD_Scan(u16 port, u16 slot, char *file, u16 size)
{
Rpc_Packet_Send_MC_OSD_SCAN *Packet = (Rpc_Packet_Send_MC_OSD_SCAN *)Rpc_Buffer;
if(!MCSP_Inited)
{
printf("\tmcsp not Inited\n");
return -1;
}
Packet->port = port;
Packet->slot = slot;
Packet->size = size;
sprintf(Packet->file,"%s", file);
if ((SifCallRpc(&mcsp, 1, 0, (void*)Rpc_Buffer, sizeof(Rpc_Packet_Send_MC_OSD_SCAN), (void*)Rpc_Buffer, sizeof(int),0,0)) < 0)
{
printf("\tmcsp MC_OSD_Scan: RPC error\n");
return -1;
}
return Packet->ret;
}
//--------------------------------------------------------------
int MC_Dummies_Patch(u16 port, u16 slot, void *file_entry, int num_entries, int linking_cluster, int filesize, void *return_entry)
{
Rpc_Packet_Send_MC_DUMMIES_PATCH *Packet = (Rpc_Packet_Send_MC_DUMMIES_PATCH *)Rpc_Buffer;
if(!MCSP_Inited)
{
printf("\tmcsp not Inited\n");
return -1;
}
Packet->port = port;
Packet->slot = slot;
Packet->num_entries = num_entries;
Packet->linking_cluster = linking_cluster;
Packet->filesize = filesize;
memcpy(Packet->file_entry, file_entry, sizeof(Packet->file_entry));
if ((SifCallRpc(&mcsp, 2, 0, (void*)Rpc_Buffer, sizeof(Rpc_Packet_Send_MC_DUMMIES_PATCH), (void*)Rpc_Buffer, sizeof(Rpc_Packet_Return_MC_DUMMIES_PATCH),0,0)) < 0)
{
printf("\tmcsp MC_Dummies_Patch: RPC error\n");
return -1;
}
Rpc_Packet_Return_MC_DUMMIES_PATCH *r_Packet = (Rpc_Packet_Return_MC_DUMMIES_PATCH *)Rpc_Buffer;
memcpy(return_entry, r_Packet->return_entry, sizeof(r_Packet->return_entry));
return r_Packet->ret;
}
//--------------------------------------------------------------
int MC_Dummies_UnPatch(u16 port, u16 slot, void* uninstall_entry, u16 num_entries, u32 linked_filesize, u16 linked_cluster)
{
Rpc_Packet_Send_MC_DUMMIES_UNPATCH *Packet = (Rpc_Packet_Send_MC_DUMMIES_UNPATCH *)Rpc_Buffer;
returnentry *uninst_entry = (returnentry *)uninstall_entry;
int i;
if(!MCSP_Inited)
{
printf("\tmcsp not Inited\n");
return -1;
}
Packet->port = port;
Packet->slot = slot;
Packet->num_entries = num_entries;
Packet->linked_filesize = linked_filesize;
Packet->linked_cluster = linked_cluster;
for (i = 0; i < num_entries; i++)
{
memcpy(Packet->uninstall_entry[i].name, uninst_entry[i].name, sizeof(Packet->uninstall_entry[i].name));
Packet->uninstall_entry[i].size = uninst_entry[i].size;
Packet->uninstall_entry[i].entry_cluster = uninst_entry[i].entry_cluster;
Packet->uninstall_entry[i].attr = uninst_entry[i].attr;
//printf ("%s attr:%04x size:%d cluster:%d\n", Packet->uninstall_entry[i].name, Packet->uninstall_entry[i].attr, Packet->uninstall_entry[i].size, Packet->uninstall_entry[i].entry_cluster);
}
if ((SifCallRpc(&mcsp, 3, 0, (void*)Rpc_Buffer, sizeof(Rpc_Packet_Send_MC_DUMMIES_UNPATCH), (void*)Rpc_Buffer, sizeof(Rpc_Packet_Send_MC_DUMMIES_UNPATCH),0,0)) < 0)
{
printf("\tmcsp MC_Dummies_UnPatch: RPC error\n");
return -1;
}
return Packet->ret;
}
//--------------------------------------------------------------
// end mcsp_rpc.c
//--------------------------------------------------------------