Homebrew How to extract Title ID from a cia?

  • Thread starter Thread starter Damian666
  • Start date Start date
  • Views Views 4,483
  • Replies Replies 11

Damian666

Coder from Hell
Member
Joined
Mar 24, 2010
Messages
671
Reaction score
152
Trophies
1
Age
47
Location
In your code...
Website
damian666.16mb.com
XP
1,736
Country
Netherlands
I want to know how I can find the ID, I want to use it to make a small program to rename cia's etc.

some have the CTR-**** as string in them, which is easy, but some lack these, so that's not good...

any ideas?
 
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
 
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

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
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
 
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