Skip to content

Commit 44ca6c9

Browse files
committed
test
1 parent 3269754 commit 44ca6c9

14 files changed

+195
-284
lines changed

BOUND.KELF

96.2 KB
Binary file not shown.

IOPRP_ARCADE.IMG

28.6 KB
Binary file not shown.

IOPRP_RETAIL.IMG

28.7 KB
Binary file not shown.

Makefile

+11-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,16 @@
88

99
EE_BIN = DONGLE_DUMPER.ELF
1010

11-
EE_OBJS = main.o modelname.o ioprp.o \
12-
usbd.o bdm.o bdmfs_fatfs.o usbmass_bd.o genvmc.o fileXio.o iomanX.o
11+
EE_OBJS = $(addsuffix .o, main downloadfile ioprp usbd bdm bdmfs_fatfs usbmass_bd fileXio iomanX secrsif_mechaemu)
12+
13+
TTY = UDP
14+
ifeq ($(TTY), PPC)
15+
EE_OBJS += ppctty.o
16+
EE_CFLAGS += -DTTY=1
17+
else ifeq ($(TTY), UDP)
18+
EE_OBJS += ps2dev9.o udptty_standalone.o
19+
EE_CFLAGS += -DTTY=2
20+
endif
1321

1422
EE_CFLAGS += -fdata-sections -ffunction-sections -DNEWLIB_PORT_AWARE
1523
EE_LDFLAGS += -Wl,--gc-sections
@@ -27,10 +35,7 @@ all: $(EE_BIN)
2735
clean:
2836
rm -rf $(EE_OBJS) $(EE_BIN)
2937

30-
ioprp.img:
31-
wget https://github.com/israpps/wLaunchELF_ISR/raw/system-2x6-support/iop/__precompiled/IOPRP_FILEIO.IMG -O $@
32-
33-
%.c: %.img
38+
ioprp.c: IOPRP_RETAIL.IMG
3439
bin2c $< $@ ioprp
3540

3641
vpath %.irx iop/

UNBOUND.KELF

96.2 KB
Binary file not shown.

downloadfile.c

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
2+
#include <stdbool.h>
3+
#include <tamtypes.h>
4+
#include <string.h>
5+
#include <kernel.h>
6+
#include <sifrpc.h>
7+
#include <loadfile.h>
8+
#include <stdio.h>
9+
#include "mechaemu_rpc.h"
10+
11+
#define DPRINTF(fmt, x...) printf(fmt, ##x)
12+
#define CHECK_RPC_INIT() if (!rpc_initialized) {DPRINTF("ERROR: Cannot call %s if RPC server is not initialized\n", __FUNCTION__); return -2;}
13+
14+
15+
static SifRpcClientData_t MechaEmuRPC;
16+
static int rpc_initialized = false;
17+
18+
19+
int mechaemu_init(void)
20+
{
21+
int retries = 100;
22+
if (rpc_initialized)
23+
{return 0;}
24+
25+
int E;
26+
while(retries--)
27+
{
28+
if((E = SifBindRpc(&MechaEmuRPC, MECHAEMU_RPC_IRX, 0)) < 0)
29+
{
30+
DPRINTF("Failed to bind RPC server for MECHAEMU (%d)\n", E);
31+
return SCE_EBINDMISS;
32+
}
33+
34+
if(MechaEmuRPC.server != NULL)
35+
break;
36+
37+
nopdelay();
38+
}
39+
40+
rpc_initialized = retries;
41+
42+
return (retries) ? 0 : ESRCH;
43+
}
44+
45+
#define RPC_BUFPARAM(x) &x, sizeof(x)
46+
int mechaemu_downloadfile(int port, int slot, void* KELFPointer)
47+
{
48+
CHECK_RPC_INIT();
49+
50+
struct DownLoadFileParam pkt;
51+
memset(&pkt, 0, sizeof(pkt));
52+
53+
pkt.port = port;
54+
pkt.slot = slot;
55+
memcpy(pkt.buffer, KELFPointer, sizeof(pkt.buffer)); //put 1kilobyte of the KELF into the RPC
56+
57+
if (SifCallRpc(&MechaEmuRPC, SECRME_DOWNLOADFILE, 0, RPC_BUFPARAM(pkt), RPC_BUFPARAM(pkt), NULL, NULL) < 0)
58+
{
59+
DPRINTF("%s: RPC ERROR\n", __FUNCTION__);
60+
return -SCE_ECALLMISS;
61+
}
62+
if (pkt.result) memcpy(KELFPointer, pkt.buffer, sizeof(pkt.buffer)); //copy back the kilobyte from RPC to the original pointer, kbit and kc changed
63+
return pkt.result;
64+
}

genvmc.h

-36
This file was deleted.

iop/secrsif_mechaemu.irx

1.79 KB
Binary file not shown.

iop/udptty_standalone.irx

9.97 KB
Binary file not shown.

ioprp.img

-11.2 KB
Binary file not shown.

main.c

+97-70
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@
2323
#include <sbv_patches.h>
2424
#include <ps2sdkapi.h>
2525
#include <string.h>
26+
#include <stdlib.h>
27+
#include <malloc.h>
2628
#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+
3131

3232
typedef struct {
3333
int id;
3434
int ret;
3535
} modinfo_t;
3636

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;
3838
#define EXTERN_MODULE(_irx) extern unsigned char _irx[]; extern unsigned int size_##_irx
3939
EXTERN_MODULE(ioprp);
4040
EXTERN_MODULE(usbd_irx);
@@ -44,106 +44,136 @@ EXTERN_MODULE(usbmass_bd_irx);
4444
EXTERN_MODULE(genvmc_irx);
4545
EXTERN_MODULE(fileXio_irx);
4646
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
4754
#define LOADMODULE(_irx, ret) SifExecModuleBuffer(&_irx, size_##_irx, 0, NULL, ret)
4855
#define LOADMODULEFILE(path, ret) SifLoadStartModule(path, 0, NULL, ret)
4956
#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);
5158
int loadusb();
5259

5360
char ROMVER[15];
5461
int loadmodulemc();
55-
62+
#define MCPORT 0
5663
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");
5865
while (!SifIopRebootBuffer(ioprp, size_ioprp)) {}; // we need homebrew FILEIO
59-
sio_puts("# Waiting for SifIopSync()");
66+
sio_puts("> Waiting for SifIopSync()");
6067
while (!SifIopSync()) {}; // wait for IOP to reboot
61-
sio_puts("# startup services");
68+
sio_puts("> startup services");
6269
SifInitIopHeap(); // Initialize SIF services for loading modules and files.
6370
SifLoadFileInit();
6471
fioInit();
65-
SifLoadStartModule("rom0:CDVDFSV", 0, NULL, NULL);
72+
6673
init_scr();
6774
scr_setCursor(0);
68-
sio_puts("# pull romver");
75+
sleep(2);
76+
sio_puts("> pull romver");
6977
memset(ROMVER, 0, sizeof(ROMVER));
7078
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());
7982
sbv_patch_enable_lmb(); // patch modload to support SifExecModuleBuffer
8083
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+
8197

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-
}
8798
if (!loadusb()) goto tosleep;
8899

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+
}
89106
iomanX.id = LOADMODULE(iomanX_irx, &iomanX.ret);
90107
INFORM(iomanX);
91108
fileXio.id = LOADMODULE(fileXio_irx, &fileXio.ret);
92109
INFORM(fileXio);
93110
if (MODULE_OK(fileXio.id, fileXio.ret)) {
111+
scr_printf("\nConnecting to filexio.irx...\r");
94112
fileXioInit();
95113
} 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;
98116
}
99117
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;
116133
}
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+
}
117157

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;
133161
}
134162
}
135-
136-
while(--x);
163+
} else {
164+
close(fd);
165+
scr_printf("\tcannot allocate %d bytes\n", size);
166+
goto brk;
137167
}
138-
scr_setfontcolor(0xffffff);
139-
scr_printf("\n\tDone%-30s\n", "");
140-
scr_printf("\tVMC status = %d\n", vmc_stats.VMC_error);
141168
}
169+
brk:
170+
scr_printf("Program execution end. exiting to OSDSYS in 2 minutes\n");
142171
sleep(120);
143172
return 0;
144173
tosleep:
145174
SleepThread();
146175
}
176+
147177
int loadusb() {
148178
usbd.id = LOADMODULE(usbd_irx, &usbd.ret);
149179
INFORM(usbd);
@@ -193,16 +223,13 @@ int loadmodulemc() {
193223
}
194224
//mcserv.id = LOADMODULEFILE("mass:/MCSERV", &mcserv.ret);
195225
//if (!MODULE_OK(mcserv.id, mcserv.ret))
196-
mcserv.id = LOADMODULEFILE("rom0:MCSERV", &mcserv.ret);
226+
/* mcserv.id = LOADMODULEFILE("rom0:MCSERV", &mcserv.ret);
197227
INFORM(mcserv);
198228
if (!MODULE_OK(mcserv.id, mcserv.ret)) {
199229
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+
206233
return 0;
207234
}
208235

mechaemu_rpc.h

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#ifndef MECHAEMU_RPC
2+
#define MECHAEMU_RPC
3+
4+
#include <stdint.h>
5+
#include <errno.h>
6+
7+
struct DownLoadFileParam
8+
{
9+
int32_t port, slot;
10+
uint8_t buffer[0x400];
11+
12+
int32_t result;
13+
};
14+
15+
#define MECHAEMU_RPC_IRX (0x10245) // 0x10000 + `M` `E` `C` `H` `A` `E` `M` `U`
16+
#define SECRME_DOWNLOADFILE (0x358) // 0x100 + `D` `O` `W` `N` `L` `O` `A` `D`
17+
18+
19+
20+
int mechaemu_init(void);
21+
int mechaemu_downloadfile(int port, int slot, void* KELFPointer);
22+
23+
#endif

0 commit comments

Comments
 (0)