From 43554a68d31492569d88fe0c0c869c5b73ba9ec5 Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Mon, 25 May 2015 17:46:00 -0300 Subject: [PATCH] Add a hacky workaround for problematic carts This adds a few strategically placed dummy commands which skip the bad responses, allowing the cart to be dumped. --- source/gamecart/protocol.c | 7 +++++++ source/gamecart/protocol.h | 1 + source/main.c | 3 +++ 3 files changed, 11 insertions(+) diff --git a/source/gamecart/protocol.c b/source/gamecart/protocol.c index 54d84bf..d946cc5 100644 --- a/source/gamecart/protocol.c +++ b/source/gamecart/protocol.c @@ -189,3 +189,10 @@ void Cart_Secure_Init(u32 *buf, u32 *out) ioDelay(0xF0000); } } + +void Cart_Dummy(void) { + // Sends a dummy command to skip encrypted responses some problematic carts send. + u32 test; + const u32 A2_cmd[4] = { 0xA2000000, 0x00000000, rand1, rand2 }; + CTR_SendCommand(A2_cmd, 4, 1, 0x100822C, &test); +} diff --git a/source/gamecart/protocol.h b/source/gamecart/protocol.h index f65c864..1f43ba1 100644 --- a/source/gamecart/protocol.h +++ b/source/gamecart/protocol.h @@ -22,3 +22,4 @@ void Cart_Init(void); int Cart_IsInserted(void); u32 Cart_GetID(void); void Cart_Secure_Init(u32* buf, u32* out); +void Cart_Dummy(void); diff --git a/source/main.c b/source/main.c index 65ee6a1..cc19a3a 100644 --- a/source/main.c +++ b/source/main.c @@ -66,6 +66,7 @@ restart_program: u32 blocks = 1 * 1024 * 1024 / mediaUnit; //1MB of blocks // Read out the header 0x0000-0x1000 + Cart_Dummy(); CTR_CmdReadData(0, mediaUnit, 0x1000 / mediaUnit, target); u32 NCSD_magic = *(u32*)(&target[0x100]); @@ -105,6 +106,8 @@ restart_program: u8* read_ptr = target; while (read_ptr < target + target_buf_size && current_sector < cartSize) { + Cart_Dummy(); + Cart_Dummy(); CTR_CmdReadData(current_sector, mediaUnit, blocks, read_ptr); read_ptr += mediaUnit * blocks; current_sector += blocks;