Emulator 板


LINE

http://dknute.livejournal.com/ This is what M1-type NAOMI cart looks like: And that is what it took to figure out how the FPGA handles the protected data: Cracking this nut took plenty of time and hard work. Originally I planned on explaining this in great detail, with photos and screenshots, but in the end decided not to. Sadly, most people couldn't care less (as long as they get to play "free" games) and/or consider this black magic that is best left to nerds and otherwise smelly people. So, I'm going to post the source code. Those of you that can parse C should find it somewhat interesting, those that can't are probably reading wrong blog. /* This is a concept version of M1 decoder. It's fully functional, except for clarity it doesn't handle cases where the data stream ends and you want to keep reading - to add that functionality just move input buffer cursor to next 4-byte boundary and restart decoding (by re-reading dictionary again). The source includes a brute-force exhaustive cracker (takes about an hour for a decent CPU). Pattern compare with just 4 bytes might return some very close but not correct XOR masks so I decided on 6. Due to the simplification I explained above it's theoreticaly possible for the cracker to fail (if there is EOS symbol in the first 6 decoded bytes), but that is highly unlikely. D. */ #include <stdint.h> #include <stdio.h> #include <string.h> #include <time.h> #define CRACKER uint8_t ReadByte (); void StoreByte (uint8_t b); void ShiftIn (); void Decode (uint32_t mask); //------------------------------------------------------------------------- int s_in_len, s_in_pos; uint8_t* s_input; uint8_t s_xor [4]; uint8_t s_dict [111]; int s_subst; int s_out_len, s_out_cnt; uint8_t* s_output; int s_shift, s_bits; //------------------------------------------------------------------------- uint8_t ReadByte () { uint8_t v; switch (s_in_pos & 3) { case 0: v = s_input [s_in_pos + 3]; v ^= s_input [s_in_pos + 1]; break; case 1: v = s_input [s_in_pos + 1]; v ^= s_input [s_in_pos - 1]; break; case 2: v = s_input [s_in_pos - 1]; break; case 3: v = s_input [s_in_pos - 3]; break; } v ^= s_xor [s_in_pos & 3]; s_in_pos++; return v; } //------------------------------------------------------------------------- void StoreByte (uint8_t b) { if (s_subst && s_out_cnt >= 2) b = s_output [s_out_cnt - 2] - b; s_output [s_out_cnt] = b; s_out_cnt++; } //------------------------------------------------------------------------- void ShiftIn () { s_shift <<= 8; s_shift |= ReadByte (); s_bits += 8; } //------------------------------------------------------------------------- void Decode (uint32_t mask) { int i, eos; s_xor [0] = (uint8_t)mask; s_xor [1] = (uint8_t)(mask >> 8); s_xor [2] = (uint8_t)(mask >> 16); s_xor [3] = (uint8_t)(mask >> 24); // byte dictionary s_in_pos = 0; for (i = 0; i < 111; i++) s_dict [i] = ReadByte (); // control bits s_subst = (s_dict [0] & 64) ? 1 : 0; // command stream s_out_cnt = 0, eos = 0; s_shift = 0, s_bits = 0; while (!eos && s_in_pos < s_in_len) { int code, addr, t; if (s_bits < 2) ShiftIn (); code = (s_shift >> (s_bits - 2)) & 3; switch (code) { case 0: // 00-aa if (s_bits < 4) ShiftIn (); addr = (s_shift >> (s_bits - 4)) & 3; s_bits -= 4; if (addr == 0) { // quotation if (s_bits < 8) ShiftIn (); t = (s_shift >> (s_bits - 8)) & 255; s_bits -= 8; StoreByte (t); break; } StoreByte (s_dict [addr]); break; case 1: if (s_bits < 5) ShiftIn (); t = (s_shift >> (s_bits - 3)) & 1; if (t == 0) { // 010-aa addr = (s_shift >> (s_bits - 5)) & 3; addr += 4; s_bits -= 5; } else { // 011-aaa if (s_bits < 6) ShiftIn (); addr = (s_shift >> (s_bits - 6)) & 7; addr += 8; s_bits -= 6; } StoreByte (s_dict [addr]); break; case 2: if (s_bits < 7) ShiftIn (); // 10-aaaaa addr = (s_shift >> (s_bits - 7)) & 31; addr += 16; s_bits -= 7; StoreByte (s_dict [addr]); break; case 3: if (s_bits < 8) ShiftIn (); // 11-aaaaaa addr = (s_shift >> (s_bits - 8)) & 63; addr += 48; s_bits -= 8; if (addr == 111) // end of stream eos = 1; else StoreByte (s_dict [addr]); break; } } } //------------------------------------------------------------------------- int main (int ia, char *ta []) { char* name; FILE* f; uint32_t m, x; time_t t1, t2; uint8_t pattern [6]; int t; name = (ia < 2) ? (char*)"input.bin" : ta [1]; f = fopen (name, "rb"); if (f == NULL) { printf ("File open error: %s\n", name); return 1; } fseek (f, 0, SEEK_END); s_in_len = ftell (f); if (s_in_len < 112) { printf ("File too short: %s\n", name); return 1; } s_input = new uint8_t [s_in_len]; fseek (f, 0, SEEK_SET); fread (s_input, 1, s_in_len, f); fclose (f); s_out_len = (s_in_len - 111) * 2; s_output = new uint8_t [s_out_len]; name = (ia < 3) ? (char*)"pattern.bin" : ta [2]; f = fopen (name, "rb"); if (f == NULL) { printf ("File open error: %s\n", name); return 1; } if (fread (pattern, 1, 6, f) < 6) { printf ("File too short: %s\n", name); return 1; } fclose (f); // 840-0030 / AH! MY GODDESS QUIZ GAME: 0xCD9B4896 // 840-0039 / Giant Gram 2000: 0x7F805C3F // 840-0084 / Virtua Tennis 2: 0x2D2D4743 // 840-0098 / Shootout Pool: 0xA0F37CA7 // 840-0106 / Virtua Fighter 4 Evolution: 0x1E5BB0CD // 840-0128 / Shootout Pool Prize: 0x9DBDE9CD // 840-0136 / Shootout Pool Medal: 0x9DBDE9CD // 840-0140 / Kick'4'Cash: 0x820857C9 // 840-0150 / MKG TKOB 2K3 2ND VER1.003-: 0x3892FB3A // 841-0007 / Marvel vs. Capcom 2: 0xC18B6E7C #ifdef CRACKER x = 0, time (&t1); t = s_in_len; s_in_len = 0x88; for (m = ~0; m != 0; m--) #else m = 0xCD9B4896; #endif { Decode (m); #ifdef CRACKER if (memcmp (s_output, pattern, 6) == 0) { printf ("XOR mask: 0x%08X\n", m); break; } if (x - m > 1024) { x = m; time (&t2); if (t1 != t2) { t1 = t2; printf ("0x%08X...\n", m); fflush (stdout); } } #endif } #ifdef CRACKER s_in_len = t; Decode (m); #endif f = fopen ("output.bin", "wb"); if (f == NULL) return 1; fwrite (s_output, 1, s_out_cnt, f); fclose (f); return 0; } Also, NAOMI Test 12/7. I don't have time to work on T13 lately and I'm not going to rush it, so you get this instead. I experimented a lot on this code - it might be actually less stable than the previous version. On the bright side, Power Stone is playable now. Should be, anyway :) --



※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.126.232.106







like.gif 您可能會有興趣的文章
icon.png[問題/行為] 貓晚上進房間會不會有憋尿問題
icon.pngRe: [閒聊] 選了錯誤的女孩成為魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一張
icon.png[心得] EMS高領長版毛衣.墨小樓MC1002
icon.png[分享] 丹龍隔熱紙GE55+33+22
icon.png[問題] 清洗洗衣機
icon.png[尋物] 窗台下的空間
icon.png[閒聊] 双極の女神1 木魔爵
icon.png[售車] 新竹 1997 march 1297cc 白色 四門
icon.png[討論] 能從照片感受到攝影者心情嗎
icon.png[狂賀] 賀賀賀賀 賀!島村卯月!總選舉NO.1
icon.png[難過] 羨慕白皮膚的女生
icon.png閱讀文章
icon.png[黑特]
icon.png[問題] SBK S1安裝於安全帽位置
icon.png[分享] 舊woo100絕版開箱!!
icon.pngRe: [無言] 關於小包衛生紙
icon.png[開箱] E5-2683V3 RX480Strix 快睿C1 簡單測試
icon.png[心得] 蒼の海賊龍 地獄 執行者16PT
icon.png[售車] 1999年Virage iO 1.8EXi
icon.png[心得] 挑戰33 LV10 獅子座pt solo
icon.png[閒聊] 手把手教你不被桶之新手主購教學
icon.png[分享] Civic Type R 量產版官方照無預警流出
icon.png[售車] Golf 4 2.0 銀色 自排
icon.png[出售] Graco提籃汽座(有底座)2000元誠可議
icon.png[問題] 請問補牙材質掉了還能再補嗎?(台中半年內
icon.png[問題] 44th 單曲 生寫竟然都給重複的啊啊!
icon.png[心得] 華南紅卡/icash 核卡
icon.png[問題] 拔牙矯正這樣正常嗎
icon.png[贈送] 老莫高業 初業 102年版
icon.png[情報] 三大行動支付 本季掀戰火
icon.png[寶寶] 博客來Amos水蠟筆5/1特價五折
icon.pngRe: [心得] 新鮮人一些面試分享
icon.png[心得] 蒼の海賊龍 地獄 麒麟25PT
icon.pngRe: [閒聊] (君の名は。雷慎入) 君名二創漫畫翻譯
icon.pngRe: [閒聊] OGN中場影片:失蹤人口局 (英文字幕)
icon.png[問題] 台灣大哥大4G訊號差
icon.png[出售] [全國]全新千尋侘草LED燈, 水草

請輸入看板名稱,例如:Tech_Job 或 站內搜尋

TOP