Homebrew How to extract Title ID from a cia?

Rinnegatamante

Well-Known Member
Member
Joined
Nov 24, 2014
Messages
3,162
Trophies
2
Age
29
Location
Bologna
Website
rinnegatamante.it
XP
4,857
Country
Italy
yeah, I read file in a string, then search for CTR-, mostly works, but also very unreliable :(

that's why I try title id now, so if I read it correctly, its at hex 0x3A50 ?

Yes, at least for a good amount of CIA files:
3a50.png
 

Damian666

Coder from Hell
OP
Member
Joined
Mar 24, 2010
Messages
671
Trophies
1
Age
45
Location
In your code...
Website
damian666.16mb.com
XP
1,699
Country
Netherlands
yeah... still not very reliable I'm afraid >.<

if you drag a file on this prog, it should show the ID, but not always...

if you just click it, it asks to select a cia file.

your program has a id, but things like the hbl cia doesn't...
 

Attachments

  • Cia_ID_Cmdline.rar
    468.3 KB · Views: 294

RainThunder

Well-Known Member
Member
Joined
Jun 22, 2012
Messages
212
Trophies
0
Location
Hanoi
XP
351
Country
You can extract titleid of CIA files from its tmd. Read here and here for more info.

Code:
#!/usr/bin/env python2

import os
import sys
from struct import unpack

if not os.path.isfile(sys.argv[1]):
    sys.exit(0)

cia_file = open(sys.argv[1], 'r+b')
cia_header = cia_file.read(0x20)

# Find offset for tmd
cert_offset = 0x2040
cert_size = unpack('<I', cia_header[0x08:0x0C])[0]
tik_size = unpack('<I', cia_header[0x0C:0x10])[0]
tmd_size = unpack('<I', cia_header[0x10:0x14])[0]
tmd_offset = cert_offset + cert_size + 0x30 + tik_size
print format(tmd_offset, '08x')

# Read titleid from tmd
cia_file.seek(tmd_offset + 0x18C)
titleid = format(unpack('>Q', cia_file.read(0x8))[0], '016x')
print 'TitleID: ' + titleid

cia_file.close()
 
Last edited by RainThunder,
  • Like
Reactions: tranxuanthang

Damian666

Coder from Hell
OP
Member
Joined
Mar 24, 2010
Messages
671
Trophies
1
Age
45
Location
In your code...
Website
damian666.16mb.com
XP
1,699
Country
Netherlands
You can extract titleid of CIA files from its tmd. Read here and here for more info.

Code:
#!/usr/bin/env python2

import os
import sys
from struct import unpack

if not os.path.isfile(sys.argv[1]):
    sys.exit(0)

cia_file = open(sys.argv[1], 'r+b')
cia_header = cia_file.read(0x20)

# Find offset for tmd
cert_offset = 0x2040
cert_size = unpack('<I', cia_header[0x08:0x0C])[0]
tik_size   = unpack('<I', cia_header[0x0C:0x10])[0]
tmd_size = unpack('<I', cia_header[0x10:0x14])[0]
tmd_offset = cert_offset + cert_size + 0x30 + tik_size
print format(tmd_offset, '08x')

# Read titleid from tmd
cia_file.seek(tmd_offset + 0x18C)
titleid = format(unpack('>Q', cia_file.read(0x8))[0], '016x')
print 'TitleID: ' + titleid

cia_file.close()

that py code works nicely, now I have to figure out to get that to vb or something :P
 

Luglige

hiatus
Member
Joined
Jan 24, 2016
Messages
1,414
Trophies
1
Location
under your bed
XP
883
Country
Antarctica
I love rom hacking (SNES and NES are my favorites) but I wanna learn to "Rom hack" 3ds or something like that. I know that SNES and 3DS are way different (i think) but it would be cool to learn about it. Maybe I'll learn someday
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: Everything is connected