Today PlayStation 3 developer Naehrwert has blogged (nwert.wordpress.com/2012/06/02/reversing-tb-part-1-the-vm/) on reversing the TB (True Blue JB2 PS3 Dongle) Part 1: The VM with details below, to quote:
Thanks to oct0xor (twitter.com/#!/oct0xor) we could get our hands on the decrypted TB payload (stage 2). Of course the first thing to do is to fire it up in IDA, our favourite tool of the trade. The entry code of the payload looks like this:
Code:
01 1337C0DE00000000 _start:
02 1337C0DE00000000
03 1337C0DE00000000 .set var_58, -0x58
04 1337C0DE00000000 .set arg_10, 0x10
05 1337C0DE00000000
06 1337C0DE00000000 mflr r0
07 1337C0DE00000004 bl loc_1337C0DE00000008
08 1337C0DE00000008 1337C0DE00000008 loc_1337C0DE00000008:
09 1337C0DE00000008 mflr r3
10 1337C0DE0000000C lis r4, 0 # 8
11 1337C0DE00000010 addi r4, r4, 8 # 8
12 1337C0DE00000014 subf. r3, r4, r3
13 1337C0DE00000018 beq skip_reloc
14 1337C0DE0000001C li r6, 0
15 1337C0DE00000020 oris r6, r6, 0x1337
16 1337C0DE00000024 ori r6, r6, 0xC0DE
17 1337C0DE00000028 lis r4, 1 # 0xA848
18 1337C0DE0000002C addi r4, r4, -0x57B8 # 0xA848
19 1337C0DE00000030 lis r5, 1 # 0x10D18
20 1337C0DE00000034 addi r5, r5, 0xD18 # 0x10D18
21 1337C0DE00000038 subf. r5, r4, r5
22 1337C0DE0000003C beq skip_reloc
23 1337C0DE00000040 srdi. r5, r5, 3
24 1337C0DE00000044 mtctr r5
25 1337C0DE00000048 add r4, r4, r3
26 1337C0DE0000004C
27 1337C0DE0000004C reloc_loop:
28 1337C0DE0000004C ld r5, 0(r4)
29 1337C0DE00000050 srdi r7, r5, 32
30 1337C0DE00000054 cmpw r7, r6
31 1337C0DE00000058 bne skip_rewrite
32 1337C0DE0000005C clrldi r5, r5, 32
33 1337C0DE00000060 add r5, r5, r3
34 1337C0DE00000064 std r5, 0(r4)
35 1337C0DE00000068
36 1337C0DE00000068 skip_rewrite:
37 1337C0DE00000068 addi r4, r4, 8
38 1337C0DE0000006C bdnz reloc_loop
39 1337C0DE00000070
40 1337C0DE00000070 skip_reloc:
41 1337C0DE00000070 std r0, arg_10(r1)
42 1337C0DE00000074 stdu r1, -0x80(r1)
43 1337C0DE00000078 std r2, 0x80+var_58(r1)
44 1337C0DE0000007C lis r4, 1 # 0x17E40
45 1337C0DE00000080 addi r4, r4, 0x7E40 # 0x17E40
46 1337C0DE00000084 add r2, r4, r3
47 1337C0DE00000088 bl payload_main
In the first loop it will relocate itself using 0x1337C0DE as an identifier for the upper 32 bits and rewrite that to the actual base. The disassembly above was already loaded using 0x1337C0DE00000000 as base. While scrolling through the data section at the end of the payload one quickly figures out that the RTOC is 0x1337C0DE00017E40.
As I was analyzing the code I found a sub that was basically just a really big switch with random looking case values. Once I reversed the sub at 0x1337C0DE00002578 and some of the following ones and analyzed their usage in the switch sub, I knew that I was looking at a fricking virtual machine.
Code:
1 1337C0DE00002578 vm_push_word_0:
2 1337C0DE00002578 ld r11, off_1337C0DE00010128 # stack_ptr
3 1337C0DE0000257C ld r9, 0(r11)
4 1337C0DE00002580 addi r0, r9, 4
5 1337C0DE00002584 std r0, 0(r11)
6 1337C0DE00002588 stw r3, 4(r9)
7 1337C0DE0000258C blr
Paranoid TB developers even used XOR-tables to obfuscate the VM instructions and data. The virtual machine is mostly stack based but the instructions let you work using registers too. The next thing to do is to reverse all the instructions and write a disassembler and emulator. Here (pastie.org/4015202) is some code to unscramble the embeded vm binary for further investigation. I’m going to write more about this topic in the future.
Code:
/*! XOR table 1. */
u8 xor_table_1[0x100] = //16*16
{
0x62, 0xC5, 0xEE, 0xFC, 0xC8, 0x2E, 0x59, 0xF3, 0x1D, 0x32, 0x20, 0xED, 0xD8, 0xA3, 0xD2, 0xB8,
0x7D, 0x16, 0x11, 0x6A, 0x41, 0x94, 0x25, 0x1E, 0x80, 0x21, 0xE9, 0xE7, 0x0A, 0xB3, 0x39, 0xF0,
0xBA, 0x97, 0xC3, 0xCF, 0x36, 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E, 0xF0, 0xE2, 0x1B, 0x3A,
0x99, 0x5B, 0xB6, 0x62, 0x61, 0xD8, 0x17, 0xD5, 0xBD, 0x63, 0x10, 0x6F, 0xF6, 0xB7, 0xA4, 0xD3,
0x39, 0x5C, 0xA5, 0x63, 0xFB, 0xE8, 0xEE, 0x9E, 0x4B, 0x05, 0x11, 0x43, 0x95, 0xFE, 0xC1, 0xF6,
0x5E, 0x46, 0xD8, 0x7A, 0x51, 0xC6, 0xCD, 0x77, 0x80, 0x0C, 0x9D, 0xAF, 0x6B, 0x59, 0xAD, 0xAE,
0x39, 0x3C, 0xD4, 0x2C, 0x95, 0x2A, 0x4D, 0x50, 0x75, 0xB0, 0xB1, 0x7F, 0x79, 0x9C, 0x10, 0x5E,
0x33, 0x7A, 0x1A, 0x05, 0x0F, 0xF5, 0x49, 0xC2, 0xA6, 0x4C, 0x1E, 0x82, 0x23, 0xB8, 0xA8, 0x3D,
0x2D, 0xFB, 0xE2, 0xB0, 0x37, 0x45, 0x30, 0xFF, 0x3F, 0xD4, 0x2D, 0x81, 0x10, 0x0A, 0xCB, 0x51,
0x9C, 0xAF, 0xC2, 0x68, 0x65, 0x53, 0x44, 0x61, 0x14, 0xE1, 0xF4, 0x5A, 0xD2, 0xC8, 0x25, 0xDD
};
//Unscramble the vm binary.
{
int i;
for(i = 0x9AC; i < 0x3824; i++)
*(vmbin + i) ^= xor_table_1[i & 0xFF];
for(i = 0x382C; i < 0x3A08; i++)
*(vmbin + i) ^= xor_table_2[i & 0xFF];
}
From shad__ on IRC for TB DRM dongle users: EBOOT.BIN
[shad__] if it can help, you can play tb eboot without tb plugged in. Just, patch sys_sm_shutdown call in TB update pkg and unplugg Tb dongle then press x to exit.It will exit without reset lv1 and lv2.
[shad__] POC:
http://www.mediafire.com/?z42clbkhjju1khy[shad__] Now you can share your dongle with your friends
[shad__] was
~chatzilla@55.219.73.86.rev.sfr.net * New Now Know How
Also this weekend Team E3DIY claim that they have also managed to run all PlayStation 3 games on 3.55 PS3 CFW (similar to TB/JB2) but they will likely peddle another dongle to do it unfortunately instead of a free PS3 scene solution.
Finally from oct0xor (via twitter.com/#!/oct0xor):
ps3usercheat skip r4=%x,r5=%x main_EBOOT.BIN main_vsh.self
I can decrypt TrueBlue Stage 2, Cobra EBOOT.BIN, ps3usercheat cheatlist.dat and lv2 stage 1 and 2, right on PC. pic.twitter.com/b2awqYLv
You really can call me "DongleBreaker" now Thanks to flat_z who was with me all along