23
23
#include <sbv_patches.h>
24
24
#include <ps2sdkapi.h>
25
25
#include <string.h>
26
+ #include <stdlib.h>
27
+ #include <malloc.h>
26
28
#include <sys/stat.h>
27
- #include "genvmc.h"
28
- const char * ModelNameGet (void );
29
- int ModelNameInit (void );
30
- uint16_t getConsoleID ();
29
+ #include "mechaemu_rpc.h"
30
+
31
31
32
32
typedef struct {
33
33
int id ;
34
34
int ret ;
35
35
} modinfo_t ;
36
36
37
- modinfo_t sio2man , mcman , mcserv , usbd , bdm , fatfs , usbmass , genvmc , fileXio , iomanX ;
37
+ modinfo_t sio2man , mcman , mcserv , usbd , bdm , fatfs , usbmass , genvmc , fileXio , iomanX , secrsif_mechaemu ;
38
38
#define EXTERN_MODULE (_irx ) extern unsigned char _irx[]; extern unsigned int size_##_irx
39
39
EXTERN_MODULE (ioprp );
40
40
EXTERN_MODULE (usbd_irx );
@@ -44,106 +44,136 @@ EXTERN_MODULE(usbmass_bd_irx);
44
44
EXTERN_MODULE (genvmc_irx );
45
45
EXTERN_MODULE (fileXio_irx );
46
46
EXTERN_MODULE (iomanX_irx );
47
+ EXTERN_MODULE (secrsif_mechaemu_irx );
48
+ #if TTY == 1
49
+ EXTERN_MODULE (ppctty_irx );
50
+ #elif TTY == 2
51
+ EXTERN_MODULE (ps2dev9_irx );
52
+ EXTERN_MODULE (udptty_standalone_irx );
53
+ #endif
47
54
#define LOADMODULE (_irx , ret ) SifExecModuleBuffer(&_irx, size_##_irx, 0, NULL, ret)
48
55
#define LOADMODULEFILE (path , ret ) SifLoadStartModule(path, 0, NULL, ret)
49
56
#define MODULE_OK (id , ret ) (id >= 0 && ret != 1)
50
- #define INFORM (x ) scr_setfontcolor(MODULE_OK(x.id, x.ret) ? 0x00cc00 : 0x0000cc);scr_printf("\t %s: id:%d ret:%d (%s)\n ", #x, x.id, x.ret, MODULE_OK(x.id, x.ret) ? "OK" : "ERR")
57
+ #define INFORM (x ) scr_setfontcolor(MODULE_OK(x.id, x.ret) ? 0x00cc00 : 0x0000cc);scr_printf(" %s: id:%d ret:%d - %-8s ", #x, x.id, x.ret, MODULE_OK(x.id, x.ret) ? "OK\r " : "ERR\n"); usleep(500000);
51
58
int loadusb ();
52
59
53
60
char ROMVER [15 ];
54
61
int loadmodulemc ();
55
-
62
+ #define MCPORT 0
56
63
int main (int argc , char * * argv ) {
57
- sio_puts ("# dongle dumper start\n# BuilDate: " __DATE__ " " __TIME__ "\n" );
64
+ sio_puts ("> mechaemu update binder\n> BuilDate: " __DATE__ " " __TIME__ "\n" );
58
65
while (!SifIopRebootBuffer (ioprp , size_ioprp )) {}; // we need homebrew FILEIO
59
- sio_puts ("# Waiting for SifIopSync()" );
66
+ sio_puts ("> Waiting for SifIopSync()" );
60
67
while (!SifIopSync ()) {}; // wait for IOP to reboot
61
- sio_puts ("# startup services" );
68
+ sio_puts ("> startup services" );
62
69
SifInitIopHeap (); // Initialize SIF services for loading modules and files.
63
70
SifLoadFileInit ();
64
71
fioInit ();
65
- SifLoadStartModule ( "rom0:CDVDFSV" , 0 , NULL , NULL );
72
+
66
73
init_scr ();
67
74
scr_setCursor (0 );
68
- sio_puts ("# pull romver" );
75
+ sleep (2 );
76
+ sio_puts ("> pull romver" );
69
77
memset (ROMVER , 0 , sizeof (ROMVER ));
70
78
GetRomName (ROMVER );
71
- scr_printf (".\n\t ===== Namco System 246/256 security dongle dumper =====\n" );
72
- scr_printf ("\tCoded by El_isra. genvmc module borrowed from OPL\n" );
73
- scr_printf ("\thttps://github.com/israpps/system2x6-dongle-dumper\n" );
74
- scr_printf ("\tROMVER: %s\n" , ROMVER );
75
- ModelNameInit ();
76
- scr_printf ("\tConsole model: %s\n" , ModelNameGet ());
77
- scr_printf ("\tConsole ID: 0x%x\n" , getConsoleID ());
78
- scr_printf ("\tMachineType: %04i\n" , MachineType ());
79
+ //scr_printf("\tConsole model: %s\n", ModelNameGet());
80
+ //scr_printf("\tConsole ID: 0x%x\n", getConsoleID());
81
+ //scr_printf("\tMachineType: %04i\n", MachineType());
79
82
sbv_patch_enable_lmb (); // patch modload to support SifExecModuleBuffer
80
83
sbv_patch_disable_prefix_check (); // remove security from MODLOAD
84
+
85
+ #if TTY == 1
86
+ LOADMODULE (ppctty_irx , NULL );
87
+ #elif TTY == 2
88
+ LOADMODULE (ps2dev9_irx , NULL );
89
+ LOADMODULE (udptty_standalone_irx , NULL );
90
+ #endif
91
+ scr_printf (".\n\t ===== MECHAEMU Update binder =====\n" );
92
+ scr_printf ("\tCoded by El_isra. genvmc module borrowed from OPL\n" );
93
+ //scr_printf("\thttps://github.com/israpps/system2x6-dongle-dumper\n");
94
+ scr_printf ("\tROMVER: %s\n" , ROMVER );
95
+ //ModelNameInit();
96
+
81
97
82
- if (!(ROMVER [4 ] == 'T' && ROMVER [5 ] == 'Z' )) {
83
- scr_setfontcolor (0x0000FF );
84
- scr_printf ("\tthis PS2 is NOT a namco system 246.\n\taborting...\n" );
85
- goto tosleep ;
86
- }
87
98
if (!loadusb ()) goto tosleep ;
88
99
100
+ secrsif_mechaemu .id = LOADMODULE (secrsif_mechaemu_irx , & secrsif_mechaemu .ret );
101
+ INFORM (secrsif_mechaemu );
102
+ if (mechaemu_init ()) {
103
+ scr_printf ("\tCannot connect to secrsif_mechaemu.irx\n" );
104
+ goto brk ;
105
+ }
89
106
iomanX .id = LOADMODULE (iomanX_irx , & iomanX .ret );
90
107
INFORM (iomanX );
91
108
fileXio .id = LOADMODULE (fileXio_irx , & fileXio .ret );
92
109
INFORM (fileXio );
93
110
if (MODULE_OK (fileXio .id , fileXio .ret )) {
111
+ scr_printf ("\nConnecting to filexio.irx...\r" );
94
112
fileXioInit ();
95
113
} else {
96
- scr_printf ("\tFailed to load fileXio. aborting dump...\n" );
97
- goto tosleep ;
114
+ scr_printf ("\n\ tFailed to load fileXio. aborting dump...\n" );
115
+ goto brk ;
98
116
}
99
117
if (loadmodulemc () == 0 ) {
100
- scr_setfontcolor (0xffffff );
101
- int ret ;
102
- createVMCparam_t p ;
103
- statusVMCparam_t vmc_stats ;
104
- memset (& p , 0 , sizeof (createVMCparam_t ));
105
- const char * cardpath = "mass:COH-H10020.bin" ;
106
- strcpy (p .VMC_filename , cardpath );
107
- p .VMC_card_slot = 0 ; // 0=slot 1, 1=slot 2
108
- p .VMC_thread_priority = 0xf ;
109
- scr_printf ("\trequesting dump to '%s': " , cardpath );
110
- ret = fileXioDevctl ("genvmc:" , GENVMC_DEVCTL_CREATE_VMC , (void * )& p , sizeof (p ), NULL , 0 );
111
- if (ret == 0 ) {
112
- scr_printf (" OK\n" );
113
- } else {
114
- scr_printf (" Error %d\n" , ret );
115
- goto tosleep ;
118
+ scr_setfontcolor (0xFFFFFF );
119
+ scr_printf ("\n" );
120
+ uint8_t * buf ;
121
+ const char * UNBOUND = "UNBOUND.KELF" ;
122
+ const char * BOUND = "BOUND.KELF" ;
123
+ int fd = open (UNBOUND , O_RDONLY );
124
+
125
+ if (fd < 0 ) {
126
+ scr_printf ("\tcant open '%s' (%d %s)...\n" , UNBOUND , fd , strerror (fd ));
127
+ goto brk ;
128
+ }
129
+ int size = lseek (fd , 0 , SEEK_END );
130
+ scr_printf ("\tKELF size is %d\n" , size );
131
+ if (size < 0 ) {
132
+ goto brk ;
116
133
}
134
+ lseek (fd , 0 , SEEK_SET );
135
+ if ((buf = memalign (64 , size )) != NULL ) {
136
+ if ((read (fd , buf , size )) != size ) {
137
+ close (fd );
138
+ scr_printf ("\tcannot read whole KELF: %d bytes\n" , size );
139
+ goto brk ;
140
+ } else {
141
+ scr_printf ("\tBinding update to memory card on mc%d:\n" , MCPORT );
142
+ int result = mechaemu_downloadfile (MCPORT , 0 , buf );
143
+ if (result ) {
144
+ scr_printf ("\tBinding complete. writing KELF to '%s'\n" , BOUND );
145
+ int outfd = open (BOUND , O_WRONLY | O_CREAT | O_TRUNC );
146
+ if (outfd >= 0 )
147
+ {
148
+ int written = write (outfd , buf , size );
149
+ if (written != size ) {
150
+ result = - EIO ;
151
+ }
152
+ close (outfd );
153
+ } else {
154
+ scr_printf ("\tmechaemu_downloadfile(%d, 0): error\n" , MCPORT );
155
+ result = - EIO ;
156
+ }
117
157
118
- memset (& vmc_stats , 0 , sizeof (statusVMCparam_t ));
119
- scr_printf ("\twaiting VMC file creation...\n" );
120
- scr_setfontcolor (0x009090 );
121
- int x = 0 ;
122
- while (1 ) {
123
- x = 20 ;
124
- ret = fileXioDevctl ("genvmc:" , GENVMC_DEVCTL_STATUS , NULL , 0 , (void * )& vmc_stats , sizeof (vmc_stats ));
125
- if (vmc_stats .VMC_progress > 20 && vmc_stats .VMC_progress < 50 ) scr_setfontcolor (0x00aaaa );
126
- if (vmc_stats .VMC_progress > 50 && vmc_stats .VMC_progress < 80 ) scr_setfontcolor (0x00aa00 );
127
- if (vmc_stats .VMC_progress > 80 ) scr_setfontcolor (0x00ff00 );
128
- if (ret == 0 ) {
129
- scr_printf ("\tprogress: %d: %-30s\r" , vmc_stats .VMC_progress , vmc_stats .VMC_msg );
130
- if (vmc_stats .VMC_status == GENVMC_STAT_AVAIL ) {
131
- scr_printf ("\n" );
132
- break ;
158
+ } else {
159
+ scr_printf ("\tmechaemu_downloadfile(%d, 0): error\n" , MCPORT );
160
+ goto brk ;
133
161
}
134
162
}
135
-
136
- while (-- x );
163
+ } else {
164
+ close (fd );
165
+ scr_printf ("\tcannot allocate %d bytes\n" , size );
166
+ goto brk ;
137
167
}
138
- scr_setfontcolor (0xffffff );
139
- scr_printf ("\n\tDone%-30s\n" , "" );
140
- scr_printf ("\tVMC status = %d\n" , vmc_stats .VMC_error );
141
168
}
169
+ brk :
170
+ scr_printf ("Program execution end. exiting to OSDSYS in 2 minutes\n" );
142
171
sleep (120 );
143
172
return 0 ;
144
173
tosleep :
145
174
SleepThread ();
146
175
}
176
+
147
177
int loadusb () {
148
178
usbd .id = LOADMODULE (usbd_irx , & usbd .ret );
149
179
INFORM (usbd );
@@ -193,16 +223,13 @@ int loadmodulemc() {
193
223
}
194
224
//mcserv.id = LOADMODULEFILE("mass:/MCSERV", &mcserv.ret);
195
225
//if (!MODULE_OK(mcserv.id, mcserv.ret))
196
- mcserv .id = LOADMODULEFILE ("rom0:MCSERV" , & mcserv .ret );
226
+ /* mcserv.id = LOADMODULEFILE("rom0:MCSERV", &mcserv.ret);
197
227
INFORM(mcserv);
198
228
if (!MODULE_OK(mcserv.id, mcserv.ret)) {
199
229
return -1;
200
- }
201
- genvmc .id = LOADMODULE (genvmc_irx , & genvmc .ret ); // modified genvmc module that auths card with I_McDetectCard2. this should reset the watchdog before begining dump
202
- INFORM (genvmc );
203
- if (!MODULE_OK (genvmc .id , genvmc .ret )) {
204
- return -1 ;
205
- }
230
+ }*/
231
+
232
+
206
233
return 0 ;
207
234
}
208
235
0 commit comments