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,700
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: 295

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,700
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
  • K3Nv2 @ K3Nv2:
    I should add a 256gb card in mine and load like 100ps1 titles to it eventually I will
  • HiradeGirl @ HiradeGirl:
    Will you play them all?
  • HiradeGirl @ HiradeGirl:
    I've only ever played Castlevania Symphony of the Night from PS1.
  • K3Nv2 @ K3Nv2:
    We don't play games here
  • Xdqwerty @ Xdqwerty:
    @HiradeGirl, I dont have one of those but gbarunner2 in twilight menu works quite decently for me
  • Psionic Roshambo @ Psionic Roshambo:
    Don't get me wrong GBA absolutely had some great games but overall the sound and graphics just meh to me
  • K3Nv2 @ K3Nv2:
    The remastered crash bandicoot was pretty decent ngl
  • HiradeGirl @ HiradeGirl:
    @Xdqwerty I had a NDS long ago, but L and R broke very fast.
  • HiradeGirl @ HiradeGirl:
    My sister had a N3DS XL and it suffered the same fate.
  • Xdqwerty @ Xdqwerty:
    @HiradeGirl the L button barely worked at all in the dsi i previously had
  • Xdqwerty @ Xdqwerty:
    my dad bought me a dsi identical to that one
  • K3Nv2 @ K3Nv2:
    That could be an easy fix without even opening it with some ipa maybe unless the entire button broke
  • HiradeGirl @ HiradeGirl:
    That´s why I never got any handheld before the Switch.
  • Xdqwerty @ Xdqwerty:
    @Psionic Roshambo, thats why patches exist
  • K3Nv2 @ K3Nv2:
    Ds games are best played on a DS emulation is fine but having actual hardware is better obviously
    +1
  • K3Nv2 @ K3Nv2:
    Or N3ds/2Ds
  • Xdqwerty @ Xdqwerty:
    @K3Nv2, or most "gimmicky" consoles
  • K3Nv2 @ K3Nv2:
    Nah the dual screen makes them better because that's how they were developed for
    +1
  • HiradeGirl @ HiradeGirl:
    Wii U is also great.
  • HiradeGirl @ HiradeGirl:
    For DS games.
  • HiradeGirl @ HiradeGirl:
    Also, 3DS games through NTR streaming on Wii U.
  • HiradeGirl @ HiradeGirl:
    It's very cool.
  • HiradeGirl @ HiradeGirl:
    Even playable.
  • K3Nv2 @ K3Nv2:
    If you can have main game on big screen and touch lay out on wiiu tablet I can see that
  • Xdqwerty @ Xdqwerty:
    @HiradeGirl, I have a broken o3ds xl
    Xdqwerty @ Xdqwerty: @HiradeGirl, I have a broken o3ds xl