Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
archshift updates, mixups seed crypto fix, titlekey dumper (nand) check
more thoroughly.
  • Loading branch information
Shadowtrance committed Jul 29, 2015
1 parent 9c5a36b commit 44d1138
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ gateway: $(OUTPUT_D)
@[ -d $(BUILD) ] || mkdir -p $(BUILD)
@make --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile EXEC_METHOD=GATEWAY
cp tools/LauncherTemplate.dat $(OUTPUT_D)/Launcher.dat
python tools/insert.py $(OUTPUT_D)/Launcher.dat $(OUTPUT).bin 0x16D8D0
dd if=$(OUTPUT).bin of=$(OUTPUT_D)/Launcher.dat bs=1497296 seek=1 conv=notrunc

bootstrap: $(OUTPUT_D)
@cd $(CURDIR)/brahma_loader && mkdir -p data
Expand Down
1 change: 1 addition & 0 deletions scripts/cdn_download.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
# This script is old and shitty

import os
Expand Down
1 change: 1 addition & 0 deletions scripts/dump_ticket_keys.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/usr/bin/env python
# This script is awful, but it 'works for me'(TM)

import sys
Expand Down
2 changes: 1 addition & 1 deletion scripts/ncchinfo_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def parseNCCH(fh, offs=0, idx=0, titleId='', standAlone=1):
data = data + parseNCCHSection(header, ncchSection.exefs, 0, 0, 1, tab)
data = data + genOutName(titleId, ncsdPartitions[idx], b'exefs_norm')
entries += 1
if uses7xCrypto:
if uses7xCrypto or usesSeedCrypto:
data = data + parseNCCHSection(header, ncchSection.exefs, uses7xCrypto, usesSeedCrypto, 0, tab)
data = data + genOutName(titleId, ncsdPartitions[idx], b'exefs_7x')
entries += 1
Expand Down
2 changes: 2 additions & 0 deletions scripts/print_ticket_keys.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

import struct
import os
import sys
Expand Down
2 changes: 2 additions & 0 deletions scripts/sdinfo_gen.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

import sys
import os
import struct
Expand Down
65 changes: 65 additions & 0 deletions scripts/seeddb_gen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import struct,os,sys
from binascii import hexlify

def GetIDandSEED(filename):
tids = []
seeds = []
with open(filename,'rb') as savefile:
savedata = savefile.read()
while savedata.find('SEEDDB')>=0:
SBoffset = savedata.find('SEEDDB')
tidoffset = (struct.unpack('<I',savedata[SBoffset+24:SBoffset+28])[0] - 1) * 4096 + SBoffset - 52 + 4096
seedoffset = tidoffset + 16000
titlecount = struct.unpack('<I',savedata[tidoffset-4092:tidoffset-4088])[0]
try:
for i in range(titlecount):
tid = savedata[tidoffset:tidoffset+8]
seed = savedata[seedoffset:seedoffset+16]
if not tid in tids:
tids.append(tid)
seeds.append(seed)
print 'TitleID: ' + hexlify(reverseByteArray(tid)),' SEED: ' + hexlify(seed)
tidoffset += 8
seedoffset += 16
except:
print 'No SEED found in this partition.'
finally:
savedata = savedata[seedoffset:]
return tids,seeds

def reverseByteArray(bytearr):
outarr = ''
for i in range(0, bytearr.__len__())[::-1]:
outarr += bytearr[i]
return outarr

if __name__ == '__main__':
tids = []
seeds = []
if len(sys.argv)<2:
print 'Usage: seeddb_gen.py file(s)'
sys.exit()

if '-h'in sys.argv or '-help' in sys.argv:
print 'Usage: seeddb_gen.py file(s)\n'
print "SEEDDB is stored in 'nand:\\data<console-unique>\\sysdata\\0001000f\\'"
print 'Decyrpt NAND FAT16 partition and dump these files for this script.'
sys.exit()

for filename in sys.argv[1:]:
titleid,seed = GetIDandSEED(filename)
tids += titleid
seeds += seed

if len(tids)<1:
print 'No SEED found.'
sys.exit()

outpath = os.path.join(os.path.dirname(os.path.realpath(sys.argv[0])), 'seeddb.bin')
with open(outpath,'wb') as seeddb:
print '\nGenerating seeddb.bin ...'
seeddb.write(struct.pack('<I',len(tids)))
seeddb.write('\x00'*12)
for i in range(len(tids)):
seeddb.write(tids[i]+seeds[i]+('\x00'*8))
print 'done!'
6 changes: 4 additions & 2 deletions source/decryptor/decryptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#define NAND_SECTOR_SIZE 0x200
#define SECTORS_PER_READ (BUFFER_MAX_SIZE / NAND_SECTOR_SIZE)

// #define sdmmc_nand_readsectors sdmmc_sdcard_readsectors
// #define sdmmc_nand_writesectors sdmmc_sdcard_writesectors

// From https://github.com/profi200/Project_CTR/blob/master/makerom/pki/prod.h#L19
static const u8 common_keyy[6][16] = {
Expand Down Expand Up @@ -164,7 +166,7 @@ u32 DecryptTitlekeysNand(void)
u32 read_bytes = min(NAND_SECTOR_SIZE * SECTORS_PER_READ, (size - t_offset));
ShowProgress(t_offset, size);
DecryptNandToMem(buffer, offset + t_offset, read_bytes, ctrnand_info);
for (u32 i = 0x158; i < read_bytes - NAND_SECTOR_SIZE; i += NAND_SECTOR_SIZE) {
for (u32 i = 0; i < read_bytes - NAND_SECTOR_SIZE; i++) {
if(memcmp(buffer + i, (u8*) "Root-CA00000003-XS0000000c", 26) == 0) {
u32 exid;
titleId = buffer + i + 0x9C;
Expand Down Expand Up @@ -277,7 +279,7 @@ u32 NcchPadgen()
PadInfo padInfo = {.setKeyY = 1, .size_mb = info->entries[i].size_mb};
memcpy(padInfo.CTR, info->entries[i].CTR, 16);
memcpy(padInfo.filename, info->entries[i].filename, 112);
if (info->entries[i].uses7xCrypto && info->entries[i].usesSeedCrypto) {
if (info->entries[i].usesSeedCrypto) {
u8 keydata[32];
memcpy(keydata, info->entries[i].keyY, 16);
u32 found_seed = 0;
Expand Down

0 comments on commit 44d1138

Please sign in to comment.