Skip to content

Commit 5f7390e

Browse files
author
John Dong
committed
Too many updates to cover
1 parent 86046b3 commit 5f7390e

7 files changed

+159
-81
lines changed

Patches/macros.S

+57-57
Original file line numberDiff line numberDiff line change
@@ -11,107 +11,107 @@
1111

1212
#;Arg0 is address, Arg1 is label used for handler
1313
.macro MAKEPATCH PAddress
14-
.if(\PAddress)
15-
#;Patch structure
16-
.set PatchAddr, \PAddress
17-
.long PatchAddr
18-
.long (9f - 0f) / 4 #;Length of patch in dwords
19-
.endif
14+
.if(\PAddress)
15+
#;Patch structure
16+
.set PatchAddr, \PAddress
17+
.long PatchAddr
18+
.long (9f - 0f) / 4 #;Length of patch in dwords
19+
.endif
2020
.endm
2121

2222
#;Arg0 is address, Arg1 is label used for handler
2323
.macro KMAKEPATCH PKAddress
24-
.if(\PKAddress)
25-
#;Patch structure
26-
.set PatchAddr, (\PKAddress-KBASE)
27-
.set RealAddr, (\PKAddress)
28-
.long PatchAddr
29-
.long (9f - 0f) / 4 #;Length of patch in dwords
30-
.endif
24+
.if(\PKAddress)
25+
#;Patch structure
26+
.set PatchAddr, (\PKAddress-KBASE)
27+
.set RealAddr, (\PKAddress)
28+
.long PatchAddr
29+
.long (9f - 0f) / 4 #;Length of patch in dwords
30+
.endif
3131
.endm
3232

3333
#;Arg0 is hook address, Arg1 is destination
3434
.macro MAKEHOOKL PKAddress PKDest
35-
.if(\PKAddress)
36-
#;Patch structure
37-
.set PatchAddr, (\PKAddress)
38-
.set RealAddr, (\PKAddress)
39-
.long PatchAddr
40-
.long (9f - 0f) / 4 #;Length of patch in dwords
41-
0:
42-
MAKEBRANCHL (\PKDest)
43-
9:
44-
.endif
35+
.if(\PKAddress)
36+
#;Patch structure
37+
.set PatchAddr, (\PKAddress)
38+
.set RealAddr, (\PKAddress)
39+
.long PatchAddr
40+
.long (9f - 0f) / 4 #;Length of patch in dwords
41+
0:
42+
MAKEBRANCHL (\PKDest)
43+
9:
44+
.endif
4545
.endm
4646

4747
#;Arg0 is hook address, Arg1 is destination
4848
.macro KMAKEHOOKL PKAddress PKDest
49-
.if(\PKAddress)
50-
#;Patch structure
51-
.set PatchAddr, (\PKAddress-KBASE)
52-
.set RealAddr, (\PKAddress)
53-
.long PatchAddr
54-
.long (9f - 0f) / 4 #;Length of patch in dwords
55-
0:
56-
MAKEBRANCHL (\PKDest-KBASE)
57-
9:
58-
.endif
49+
.if(\PKAddress)
50+
#;Patch structure
51+
.set PatchAddr, (\PKAddress-KBASE)
52+
.set RealAddr, (\PKAddress)
53+
.long PatchAddr
54+
.long (9f - 0f) / 4 #;Length of patch in dwords
55+
0:
56+
MAKEBRANCHL (\PKDest-KBASE)
57+
9:
58+
.endif
5959
.endm
6060

6161
#;Arg0 is hook address, Arg1 is destination
6262
.macro KMAKEHOOK PKAddress PKDest
63-
.if(\PKAddress)
64-
#;Patch structure
65-
.set PatchAddr, (\PKAddress-KBASE)
66-
.set RealAddr, (\PKAddress)
67-
.long PatchAddr
68-
.long (9f - 0f) / 4 #;Length of patch in dwords
69-
0:
70-
MAKEBRANCH (\PKDest-KBASE)
71-
9:
72-
.endif
63+
.if(\PKAddress)
64+
#;Patch structure
65+
.set PatchAddr, (\PKAddress-KBASE)
66+
.set RealAddr, (\PKAddress)
67+
.long PatchAddr
68+
.long (9f - 0f) / 4 #;Length of patch in dwords
69+
0:
70+
MAKEBRANCH (\PKDest-KBASE)
71+
9:
72+
.endif
7373
.endm
7474

7575
#;Arg0 is destination address
7676
.macro MAKEBRANCH DAddress
77-
.if(\DAddress)
77+
.if(\DAddress)
7878
#;Patch structure
79-
b \DAddress - ((.-0b)+PatchAddr)
80-
.endif
79+
b \DAddress - ((.-0b)+PatchAddr)
80+
.endif
8181
.endm
8282

8383
#;Arg0 is destination address
8484
.macro MAKEBRANCHL DAddress
85-
.if(\DAddress)
85+
.if(\DAddress)
8686
#;Patch structure
87-
bl \DAddress - ((.-0b)+PatchAddr)
88-
.endif
87+
bl \DAddress - ((.-0b)+PatchAddr)
88+
.endif
8989
.endm
9090

9191
#;Arg0 is destination address
9292
.macro KMAKEBRANCH DAddress
93-
.if(\DAddress)
93+
.if(\DAddress)
9494
#;Patch structure
95-
b (\DAddress-KBASE) - ((.-0b)+PatchAddr)
96-
.endif
95+
b (\DAddress-KBASE) - ((.-0b)+PatchAddr)
96+
.endif
9797
.endm
9898

9999
#;Arg0 is destination address
100100
.macro KMAKEBRANCHL DAddress
101-
.if(\DAddress)
101+
.if(\DAddress)
102102
#;Patch structure
103-
bl (\DAddress-KBASE) - ((.-0b)+PatchAddr)
104-
.endif
103+
bl (\DAddress-KBASE) - ((.-0b)+PatchAddr)
104+
.endif
105105
.endm
106106

107107
#;Arg0 is destination address
108108
.macro BLMAKEBRANCH DAddress
109-
#;Patch structure
109+
#;Patch structure
110110
b \DAddress - ((.-0b)+PatchAddr)
111111
.endm
112112

113113
#;Arg0 is destination address
114114
.macro BLMAKEBRANCHL DAddress
115-
#;Patch structure
115+
#;Patch structure
116116
bl \DAddress - ((.-0b)+PatchAddr)
117117
.endm

Patches/remap_bootanim_17559.S

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# A patch to remap the bootanim from flash to the HDD
2+
3+
.include "macros.S"
4+
5+
.set HvxPostOutput, 0x80061000
6+
.set AniStartBootAnimation, 0x80061730
7+
.set SataDiskInitialize, 0x8015DB18
8+
.set SataCdRomInitialize, 0x8015D678
9+
10+
# set new bootanim path
11+
KMAKEPATCH 0x80166C00
12+
0:
13+
.string "\\Device\\Harddisk0\\Partition1\\bootanim.xex\0"
14+
.align 2
15+
9:
16+
17+
# initialize SATA driver before bootanim
18+
KMAKEPATCH 0x80061298
19+
0:
20+
# li r3, 0x73
21+
# KMAKEBRANCHL HvxPostOutput
22+
nop
23+
nop
24+
# init HDD before bootanim
25+
KMAKEBRANCHL SataDiskInitialize
26+
# li r3, 0x72
27+
# KMAKEBRANCHL HvxPostOutput
28+
nop
29+
nop
30+
li r3, 0
31+
KMAKEBRANCHL AniStartBootAnimation
32+
# init DVD after bootanim
33+
KMAKEBRANCHL SataCdRomInitialize
34+
9:
35+
36+
# remove bound path limit, set new bootanim path, and remove the minimum bootanim version
37+
KMAKEPATCH 0x80061754
38+
0:
39+
lis r11, -0x7FEA # r11 = 0x80160000
40+
addi r3, r11, 0x6C00 # r3 = r11 + 0x6C00
41+
addi r6, r1, 0x50 # unmodified
42+
li r5, 0 # minimum version
43+
li r4, 9 # flags
44+
9:
45+
46+
# ============================================================================
47+
.long 0xFFFFFFFF
48+
# ============================================================================

XeCrypt.py

+11-7
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@
3535
XECRYPT_SD_SALT = b"XBOX_ROM_4"
3636
BUFFER_SIZE = 4096
3737

38-
UINT8_MASK = 0xFF
39-
UINT16_MASK = 0xFFFF
40-
UINT32_MASK = 0xFFFFFFFF
41-
UINT64_MASK = 0xFFFFFFFFFFFFFFFF
42-
UINT128_MASK = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
38+
UINT8_MASK = int.from_bytes(b"\xFF", "little")
39+
UINT16_MASK = int.from_bytes(b"\xFF" * 2, "little")
40+
UINT32_MASK = int.from_bytes(b"\xFF" * 4, "little")
41+
UINT64_MASK = int.from_bytes(b"\xFF" * 8, "little")
42+
UINT128_MASK = int.from_bytes(b"\xFF" * 16, "little")
4343

4444
# public key sizes
4545
XECRYPT_RSAPUB_1024_SIZE = 0x90
@@ -443,11 +443,15 @@ def reset(self) -> None:
443443
def new(key: Union[bytes, bytearray]):
444444
return XeCryptRc4(key)
445445

446-
def encrypt(self, data: Union[bytes, bytearray]) -> bytes:
446+
# encrypt and decrypt are exactly the same for RC4
447+
def crypt(self, data: Union[bytes, bytearray]) -> bytes:
447448
return self._cipher.encrypt(data)
448449

450+
def encrypt(self, data: Union[bytes, bytearray]) -> bytes:
451+
return self.crypt(data)
452+
449453
def decrypt(self, data: Union[bytes, bytearray]) -> bytes:
450-
return self._cipher.decrypt(data)
454+
return self.crypt(data)
451455

452456
# DES
453457
class XeCryptDes:

assembler.py

+32-9
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,28 @@
66

77
REG_EXP = re.compile(r"(r\d+)")
88

9+
# 0x80066354 = li r4, 0
10+
# 0x80066358 = addi r3, r11, 0xC00
11+
# 0x80066360 = li r5, 0
12+
913
def main() -> None:
1014
print("Xbox 360 Interactive Assembler")
1115

16+
addr = 0
17+
line_split = None
1218
ks = Ks(KS_ARCH_PPC, KS_MODE_PPC32 + KS_MODE_BIG_ENDIAN)
1319

1420
capturing = False
1521
code_lines = []
1622
while True:
23+
line_split = None
1724
line = input("ASM> ").strip()
25+
if ": " in line:
26+
line_split = line.split(": ")
27+
1828
# commands
1929
if line.lower() in ["exit", "quit", "close"]:
30+
print("Done!")
2031
break
2132
elif line.lower() in ["start", "begin"]:
2233
code_lines = []
@@ -41,17 +52,29 @@ def main() -> None:
4152
continue
4253

4354
# parse as assembly
44-
line = REG_EXP.sub(r"%\1", line)
4555
try:
46-
(code, line_num) = ks.asm(line)
47-
code = bytes(code)
48-
if capturing:
49-
code_lines.append((line, code))
56+
if len(line_split) == 2:
57+
line_split[1] = REG_EXP.sub(r"%\1", line_split[1])
58+
(code, line_num) = ks.asm(line_split[1], int(line_split[0], 16))
59+
code = bytes(code)
60+
if capturing:
61+
code_lines.append((line_split[1], code))
62+
else:
63+
print(code.hex().upper())
64+
code = ", ".join([f"0x{x:02X}" for x in code])
65+
code = f"BYTE code[] = {{ {code} }}; // {line_split[1]}"
66+
print(code)
5067
else:
51-
print(code.hex().upper())
52-
code = ", ".join([f"0x{x:02X}" for x in code])
53-
code = f"BYTE code[] = {{ {code} }}; // {line}"
54-
print(code)
68+
line = REG_EXP.sub(r"%\1", line)
69+
(code, line_num) = ks.asm(line)
70+
code = bytes(code)
71+
if capturing:
72+
code_lines.append((line, code))
73+
else:
74+
print(code.hex().upper())
75+
code = ", ".join([f"0x{x:02X}" for x in code])
76+
code = f"BYTE code[] = {{ {code} }}; // {line}"
77+
print(code)
5578
except Exception as e:
5679
print(e.message)
5780

patch_compile.py

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ def main() -> None:
1313
assemble_patch("Patches/Zero/SD/sd_17489_patches.S", "Output/Zero/xell.bin", PATCH_DIR)
1414
assemble_patch("Patches/Spoofy.S", "Output/Spoofy.bin", PATCH_DIR)
1515

16+
assemble_patch("Patches/remap_bootanim_17559.S", "Output/remap_bootanim_17559.bin", PATCH_DIR)
17+
1618
# assemble_patch("C://Users/John/Desktop/BlowFuselines.S", r"C://Users/John/Desktop/BlowFuselines.bin", PATCH_DIR)
1719

1820
vfuses_data = Path("Output/Zero/vfuses_17489.bin").read_bytes()

scratch.py

+3-5
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
from XeCrypt import *
66

77
def main() -> None:
8-
pub_key = Path("Keys/Master_pub.bin").read_bytes()
9-
kv_data = Path("KV/banned.bin").read_bytes()
10-
11-
# this CPU key is banned!
12-
print(XeCryptKeyVaultVerify(bytes.fromhex("9179C6012E1ECD5EE5378335AC99C960"), kv_data, pub_key))
8+
_1bl_key = PY_XECRYPT_RSA_KEY(Path("Keys/1BL_pub.bin").read_bytes())
9+
print(_1bl_key.n)
10+
print(_1bl_key.e)
1311

1412
if __name__ == "__main__":
1513
main()

se_patcher.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ def main() -> None:
1313
sd_data = bytearray(Path("Output/Winchester/sd_17489.bin").read_bytes())
1414
se_data = bytearray(Path("Output/Winchester/hypervisor.bin").read_bytes() + Path("Output/Winchester/kernel.exe").read_bytes())
1515

16+
sd_data = apply_patches(sd_data, Path("C://Users/John/Desktop/patch.bin").read_bytes())
17+
1618
# apply patches
17-
se_data = apply_patches(se_data, Path("Output/Zero/HVK.bin").read_bytes())
19+
# se_data = apply_patches(se_data, Path("Output/Zero/HVK.bin").read_bytes())
1820
# compress SE
19-
se_data = bytearray(compress_se(se_data))
21+
# se_data = bytearray(compress_se(se_data))
22+
se_data = bytearray(0x20) + se_data
2023
# magic, build, QFE, flags, and entry point
2124
pack_into(">2s 3H I", se_data, 0, b"SE", 17559, 0x8000, 0, 0)
2225
# get length of SE without padding
@@ -26,7 +29,7 @@ def main() -> None:
2629
# set SE size
2730
pack_into(">I", se_data, 0xC, se_len_nopad)
2831
# append padding AFTER
29-
se_data += (b"\x00" * calc_pad_size(se_len_nopad))
32+
# se_data += (b"\x00" * calc_pad_size(se_len_nopad))
3033
# compute SE hash
3134
se_hash = XeCryptRotSumSha(se_data[:0x10] + se_data[0x20:])
3235
# patch SE hash into SD

0 commit comments

Comments
 (0)