PS2SDK
PS2 Homebrew Libraries
Loading...
Searching...
No Matches
MechaAuth.c
1#include <stdio.h>
2#include <cdvdman.h>
3#include <sysclib.h>
4
5#include "secrman.h"
6
7#include "main.h"
8#include "MechaAuth.h"
9
10#if 0
11static void _printf3(const char *format, ...);
12#endif
13
14// 0x00001570
15#if 0
16static void _printf3(const char *format, ...){
17
18}
19#endif
20
21// 0x00001588
22int SendMechaCommand(int command, const void *input, unsigned short int length, void *output)
23{
24 unsigned int i;
25
26 _printf3("mecha command:%02x param:", (unsigned char)command);
27 for (i = 0; i < length; i++) {
28 _printf3(" %02x", ((unsigned char *)input)[i]);
29 }
30 _printf3("\n");
31
32 return sceCdApplySCmd((unsigned char)command, (void *)input, length, output);
33}
34
35// 0x00001634
36int mechacon_auth_80(int cnum)
37{
38 unsigned char ret[16], parameter[16];
39
40 parameter[0] = cnum;
41
42 if (SendMechaCommand(0x80, parameter, 1, ret) == 0) {
43 return 0;
44 }
45
46 if (ret[0] != 0) {
47 return 0;
48 }
49
50 return 1;
51}
52
53// 0x0000167c
54int mechacon_auth_81(int cnum)
55{
56 unsigned char ret[16], parameter[16];
57
58 parameter[0] = cnum;
59
60 if (SendMechaCommand(0x81, parameter, 1, ret) == 0) {
61 return 0;
62 }
63
64 if (ret[0] != 0) {
65 return 0;
66 }
67
68 return 1;
69}
70
71// 0x000016c4
72int mechacon_auth_82(const void *buffer, const void *buffer2)
73{
74 unsigned char ret[16], parameters[16];
75 unsigned int i;
76
77 for (i = 0; i < 8; i++) {
78 parameters[i] = ((unsigned char *)buffer)[i];
79 parameters[8 + i] = ((unsigned char *)buffer2)[i];
80 }
81
82 if (SendMechaCommand(0x82, parameters, 16, ret) == 0) {
83 return 0;
84 }
85
86 if (ret[0] != 0) {
87 return 0;
88 }
89
90 return 1;
91}
92
93// 0x00001740
94int mechacon_auth_83(const void *buffer)
95{
96 unsigned char ret[16], parameters[16];
97
98 memcpy(parameters, buffer, 8);
99
100 if (SendMechaCommand(0x83, parameters, 8, ret) == 0) {
101 return 0;
102 }
103
104 if (ret[0] != 0) {
105 return 0;
106 }
107
108 return 1;
109}
110
111// 0x000017ac
112int mechacon_auth_84(void *buffer, void *buffer2)
113{
114 unsigned char ret[16];
115
116 if (SendMechaCommand(0x84, NULL, 0, ret) == 0) {
117 return 0;
118 }
119
120 if (ret[0] != 0) {
121 return 0;
122 }
123
124 memcpy(buffer, &ret[1], 8);
125 memcpy(buffer2, &ret[9], 4);
126
127 return 1;
128}
129
130// 0x0000185c
131int mechacon_auth_85(void *buffer, void *buffer2)
132{
133 unsigned char ret[16];
134
135 if (SendMechaCommand(0x85, NULL, 0, ret) == 0) {
136 return 0;
137 }
138
139 if (ret[0] != 0) {
140 return 0;
141 }
142
143 memcpy(buffer, &ret[1], 4);
144 memcpy(buffer2, &ret[5], 8);
145
146 return 1;
147}
148
149// 0x0000190c
150int mechacon_auth_86(void *buffer, void *buffer2)
151{
152 unsigned char ret[16], parameters[16];
153 unsigned int i;
154
155 for (i = 0; i < 8; i++) {
156 parameters[i] = ((unsigned char *)buffer)[i];
157 parameters[8 + i] = ((unsigned char *)buffer2)[i];
158 }
159
160 if (SendMechaCommand(0x86, parameters, 16, ret) != 0) {
161 return 0;
162 }
163
164 if (ret[0] != 0) {
165 return 0;
166 }
167
168 return 1;
169}
170
171// 0x00001988
172int mechacon_auth_87(void *buffer)
173{
174 unsigned char ret[16], parameters[16];
175
176 memcpy(parameters, buffer, 8);
177
178 if (SendMechaCommand(0x87, parameters, 8, ret) == 0) {
179 return 0;
180 }
181
182 if (ret[0] != 0) {
183 return 0;
184 }
185
186 return 1;
187}
188
189// 0x000019f4
190int mechacon_auth_88(void)
191{
192 unsigned char ret[16];
193
194 if (SendMechaCommand(0x88, NULL, 0, ret) == 0) {
195 return 0;
196 }
197
198 if (ret[0] != 0) {
199 return 0;
200 }
201
202 return 1;
203}
204
205// 0x00001b88
206int write_HD_start(unsigned char mode, int cnum, int arg2, unsigned short int HeaderLength)
207{
208 unsigned char ret[16], parameters[16];
209
210 parameters[0] = mode;
211 parameters[1] = (unsigned char)HeaderLength;
212 parameters[2] = (unsigned char)(HeaderLength >> 8);
213 parameters[3] = cnum;
214 parameters[4] = arg2;
215
216 if (SendMechaCommand(0x90, parameters, 5, ret) == 0) {
217 return 0;
218 }
219
220 if (ret[0] != 0) {
221 return 0;
222 }
223
224 return 1;
225}
226
227// 0x00001a88
228int write_data(const void *buffer, unsigned short int length)
229{
230 unsigned char ret[16], input[16];
231
232 if (length > 16) {
233 return 0;
234 }
235
236 memcpy(input, buffer, length);
237
238 if (SendMechaCommand(0x8D, input, length, ret) == 0) {
239 return 0;
240 }
241
242 if (ret[0] != 0) {
243 return 0;
244 }
245
246 return 1;
247}
248
249// 0x00001a38
250int pol_cal_cmplt(void)
251{
252 unsigned char ret[16];
253
254 do {
255 if (SendMechaCommand(0x8F, NULL, 0, ret) == 0) {
256 return 0;
257 }
258 } while (ret[0] == 1);
259
260 if (ret[0] != 0) {
261 return 0;
262 }
263
264 return 1;
265}
266
267// 0x00001c98
268int func_00001c98(unsigned short int size)
269{
270 unsigned char params[16], ret[16];
271
272 params[0] = (unsigned char)size;
273 params[1] = (unsigned char)(size >> 8);
274
275 if (SendMechaCommand(0x93, params, 2, ret) == 0) {
276 return 0;
277 }
278
279 if (ret[0] != 0) {
280 return 0;
281 }
282
283 return 1;
284}
285
286// 0x00001be4
287int get_BIT_length(unsigned short int *BitLength)
288{
289 unsigned char ret[16];
290
291 if (SendMechaCommand(0x91, NULL, 0, ret) == 0) {
292 return 0;
293 }
294
295 if (ret[0] != 0) {
296 return 0;
297 }
298
299 *BitLength = ret[1] + ((int)ret[2] << 8);
300
301 return 1;
302}
303
304// 0x00001b00
305int func_00001b00(void *data, unsigned short int length)
306{
307 unsigned char ret[16];
308
309 if (length > 16) {
310 return 0;
311 }
312
313 if (SendMechaCommand(0x8E, NULL, 0, ret) == 0) {
314 return 0;
315 }
316
317 // NOTE: ret[0] check is omitted here
318
319 memcpy(data, ret, length);
320
321 return 1;
322}
323
324// 0x00001c48
325int mechacon_set_block_size(unsigned short int size)
326{
327 unsigned char ret[16], parameters[16];
328
329 parameters[0] = (unsigned char)size;
330 parameters[1] = (unsigned char)(size >> 8);
331
332 if (SendMechaCommand(0x92, parameters, 2, ret) == 0) {
333 return 0;
334 }
335
336 if (ret[0] != 0) {
337 return 0;
338 }
339
340 return 1;
341}
342
343// 0x00001ce8
344int _PreEncryptKbit1(void *kbit1)
345{
346 unsigned char ret[16];
347
348 if (SendMechaCommand(0x94, NULL, 0, ret) == 0) {
349 return 0;
350 }
351
352 if (ret[0] != 0) {
353 return 0;
354 }
355
356 memcpy(kbit1, &ret[1], 8);
357
358 return 1;
359}
360
361// 0x00001d64
362int _PreEncryptKbit2(void *kbit2)
363{
364 unsigned char ret[16];
365
366 if (SendMechaCommand(0x95, NULL, 0, ret) == 0) {
367 return 0;
368 }
369
370 if (ret[0] != 0) {
371 return 0;
372 }
373
374 memcpy(kbit2, &ret[1], 8);
375
376 return 1;
377}
378
379// 0x00001de0
380int _PreEncryptKc1(void *kc1)
381{
382 unsigned char ret[16];
383
384 if (SendMechaCommand(0x96, NULL, 0, ret) == 0) {
385 return 0;
386 }
387
388 if (ret[0] != 0) {
389 return 0;
390 }
391
392 memcpy(kc1, &ret[1], 8);
393
394 return 1;
395}
396
397// 0x00001e5c
398int _PreEncryptKc2(void *kc2)
399{
400 unsigned char ret[16];
401
402 if (SendMechaCommand(0x97, NULL, 0, ret) == 0) {
403 return 0;
404 }
405
406 if (ret[0] != 0) {
407 return 0;
408 }
409
410 memcpy(kc2, &ret[1], 8);
411
412 return 1;
413}
414
415// 0x00001ed8
416int func_00001ed8(void *icvps2)
417{
418 unsigned char ret[16];
419
420 if (SendMechaCommand(0x98, NULL, 0, ret) == 0) {
421 return 0;
422 }
423
424 if (ret[0] != 0) {
425 return 0;
426 }
427
428 memcpy(icvps2, &ret[1], 8);
429
430 return 1;
431}
int sceCdApplySCmd(u8 cmdNum, const void *inBuff, u16 inBuffSize, void *outBuff)