Hacking 3DS rom dump info

raulpica

With your drill, thrust to the sky!
Former Staff
Joined
Oct 23, 2007
Messages
11,056
Trophies
0
Location
PowerLevel: 9001
XP
5,716
Country
Italy
Lol, all I know is that posting links to such sights is a no no gbatemp, might want to edit it out. Just warning you.
Friendly tip: if you report something, DON'T quote it, otherwise the infringing content will also be in YOUR post.

Thanks.
 

Pong20302000

making notes on everything
OP
Member
Joined
Sep 8, 2009
Messages
8,081
Trophies
2
Location
One's inner self
Website
3dsdb.com
XP
2,491
Country
Lol, all I know is that posting links to such sights is a no no gbatemp, might want to edit it out. Just warning you.

rom trimming is perfectly fine

edit:
maybe i missed something as an admin may have been halfway through editing LOL

So where can we find a 3DS rom trimmer? I don't want these huge untrimmed files, I like them small. (I trimmed my DS roms myself, keeping the Wi-Fi functionality in all of them.) My R4i 3DS Gold loads any trimmed DS rom I throw at it.

you cant trim the roms
the best way is to keep them packed in the .rar files for now as that would be roughly the trimmed size anyway
 

Rydian

Resident Furvert™
Member
Joined
Feb 4, 2010
Messages
27,880
Trophies
0
Age
36
Location
Cave Entrance, Watching Cyan Write Letters
Website
rydian.net
XP
9,111
Country
United States
Maybe emulators and rom loaders will eventually add support for 7zip. But nah, that would make too much sense require them to add in another library which increases the size and complexity of the compile which means more time spent each test build, and then they'd also have to deal with block versus individual compression and if a file has been compressed as a delta difference they would need to uncompress multiple files at once to load a single version of the ROM from the archive, and then they'd have to abide by both the GPL and the unRAR licenses/restrictions in order to distribute the libraries within the program anyways.

Something common, relatively-simple, and non-restricting like ZIP works.

7-zip is an archive and compression format and unsuitable for storing resources.
 

andibad

Soon™
Member
Joined
Sep 14, 2009
Messages
701
Trophies
0
Location
hospital
XP
247
Country
Indonesia
Something common, relatively-simple, and non-restricting like ZIP works.

7-zip is an archive and compression format and unsuitable for storing resources.
7-zip is used a lot cpu usage and memory .... than zip or rar.
but sometimes 7-zip is suitable for storing resources on limited space than rar or zip. and is opensource.
 
  • Like
Reactions: JayRo

porkiewpyne

Report-er
Supervisor
Joined
Jun 8, 2008
Messages
2,496
Trophies
2
XP
4,595
Country
Australia
7-zip is used a lot cpu usage and memory .... than zip or rar.
but sometimes 7-zip is suitable for storing resources on limited space than rar or zip. and is opensource.
And as far as I know, is used to a lesser extent compared to .zip and .rar. And you have to remember that some people are ....er... not that tech-savvy. Yea, I do know people who do not know what .rar is.
 

Rydian

Resident Furvert™
Member
Joined
Feb 4, 2010
Messages
27,880
Trophies
0
Age
36
Location
Cave Entrance, Watching Cyan Write Letters
Website
rydian.net
XP
9,111
Country
United States
but sometimes 7-zip is suitable for storing resources on limited space than rar or zip.
ROMs contain a lot of non-repeating data so the best compress comes from storing multiple versions of a RAM via delta differences, but that's a more complex operation to extract. They need to extract the base file and the changes, then apply them in RAM (opposed to a single extract).

and is opensource.
Doesn't mean "free to do whatever with", still gotta' abide by the licensing.
 

Rydian

Resident Furvert™
Member
Joined
Feb 4, 2010
Messages
27,880
Trophies
0
Age
36
Location
Cave Entrance, Watching Cyan Write Letters
Website
rydian.net
XP
9,111
Country
United States
7zip has the advantage of streaming...so it might be easier to run a rom from inside a 7z file than from inside a zip file.
From what I read, the streaming ability is just container-ability for multiple files, and doesn't actually do compression (since good compression needs to analyze the whole file/collection to discern the best patterns). In addition you don't actually run files inside of archives, they need to be extracted into RAM (or onto disk) anyways.
 

elisherer

I ♥ 3DS
Member
Joined
Dec 16, 2009
Messages
778
Trophies
0
Location
3dbrew.org
Website
www.sherer.co.il
XP
392
Country
Iceland
From what I read, the streaming ability is just container-ability for multiple files, and doesn't actually do compression (since good compression needs to analyze the whole file/collection to discern the best patterns). In addition you don't actually run files inside of archives, they need to be extracted into RAM (or onto disk) anyways.
If that would have been the case then there was no benefit on using any of the compressions over the others and just use uncompression before play. 7z files can start reading chunks from a file inside the archive without decompressing all of it (as I did in 3dsexplorer... I can open the header of a rom file inside a 7z file, doing that on a zip file is more difficult).

EDIT: i think gz is even better.
 

Rydian

Resident Furvert™
Member
Joined
Feb 4, 2010
Messages
27,880
Trophies
0
Age
36
Location
Cave Entrance, Watching Cyan Write Letters
Website
rydian.net
XP
9,111
Country
United States
If that would have been the case then there was no benefit on using any of the compressions over the others and just use uncompression before play. 7z files can start reading chunks from a file inside the archive without decompressing all of it (as I did in 3dsexplorer... I can open the header of a rom file inside a 7z file, doing that on a zip file is more difficult).

EDIT: i think gz is even better.
From what I read the 7z format does use solid/block compression.

I guess the concern is if the user has a collection of 7z ROMs (each archive containing the various versions of a single game release), or if they have their whole collection in one archive.
 

elisherer

I ♥ 3DS
Member
Joined
Dec 16, 2009
Messages
778
Trophies
0
Location
3dbrew.org
Website
www.sherer.co.il
XP
392
Country
Iceland
From what I read the 7z format does use solid/block compression.

I guess the concern is if the user has a collection of 7z ROMs (each archive containing the various versions of a single game release), or if they have their whole collection in one archive.
You are right, and that's the emulators makers' job to decide wisely. I suggest packing each in its own archive (as 3dsexplorer reads them today).
 

Jayro

MediCat USB Dev
Developer
Joined
Jul 23, 2012
Messages
13,085
Trophies
4
Location
WA State
Website
ko-fi.com
XP
17,297
Country
United States
This is why I prefer ROM trimmers to compressed archives... No extraction needed, and usually a smaller file. .__.

But I always trim my own ROMs, so I KNOW I have a good ROM. I never batch trim either. I trim, test in Desmume, test on my R4i 3DS Gold, THEN decide to either keep, or re-trim the ROM. So far I haven't had any trouble with the specific ROM trimmers I use for GBA and DS.
 

Rydian

Resident Furvert™
Member
Joined
Feb 4, 2010
Messages
27,880
Trophies
0
Age
36
Location
Cave Entrance, Watching Cyan Write Letters
Website
rydian.net
XP
9,111
Country
United States
Yeah for archiving 7-zip with delta differences for multiple versions of a ROM is great (I like ROM sites that do that, so I can grab an exact revision for a patch or investigation), but for saving space on the device, trimming is best nowadays. It'll use less space per-ROM at load time anyways since you don't need to have duplicates (compressed and uncompressed), load time is faster, etc.
 
  • Like
Reactions: JayRo

elisherer

I ♥ 3DS
Member
Joined
Dec 16, 2009
Messages
778
Trophies
0
Location
3dbrew.org
Website
www.sherer.co.il
XP
392
Country
Iceland
We still dont know id the 3ds support trimming because it seems it has a lot going on the power of two because of the encryption. the trimmed rom would have to be encrypted too... but all that are just speculations.. i'll stop talking about that now.
 
  • Like
Reactions: Rydian

Ris312

Well-Known Member
Newcomer
Joined
Mar 5, 2011
Messages
59
Trophies
0
XP
92
Country
in a 3DS rom, at offset 0x300 is a 4 byte value stored in little endian that is the used ROM size in bytes,
on the few 3DS roms that I've checked, they all seem to be filled with FF's after that point.

so in theory you can make a rom trimmer by:
1. check the 4 bytes offset 0x100, if it is 4E435344 in hex (NCSD) then its most likely a 3DS rom
(if not then give an error like 'Not a 3DS Rom')
2. reading 4 bytes at offset 0x300 and reverse the bytes (note: its stored as little-endian)
for example: 00 2C BD 1B = 1B BD 2C 00
3. convert that hex value into decimal to get the size in bytes. (example: 1B BD 2C 00 = 465,382,400 bytes)
4. cut the file at that point (or to be safe, check if all the data after that point is FFs, if not then give an error (e.g unable to be trimmed)

To restore the rom back to normal:
1. read 4 bytes at offset 0x104 and reverse the bytes (note: stored as little-endian)
(example: 00 00 10 00 = 00 10 00 00)
2. convert it to decimal (00 10 00 00 = 1,048,576)
3. then multiply by 512 which is the sector size (is it fixed to 512 or is there is an offset that contains the sector size?)
4. that will give you the full rom size in bytes (1,048,576 * 512 = 536,870,912)
5. then you just pad the file with FF's so it is the size of the full rom in bytes.
e.g 536,870,912 (Full Rom Size) minus 465,382,400 (Trimmed Size) means you need to add: 71,488,512 bytes of FF's.

The encrypted part of a 3DS Rom won't compress much, its only the FF section at the end of the rom that does,
because of the encryption, xdelta differences won't work and will end up being the full used size of the rom,
and merging 'region variant' games in an archive with solid compression won't help compression either
and will end up being the size of the ALL the games used rom size as only the FF part will compress.
(Unless a way to decrypt and then re-encrypt the roms is found, xdeltas and merging roms won't save any space)


After you trim a 3DS Rom you'll find that the trimmed size is almost the same as the compressed filesize,
So you could store 3DS roms trimmed to save a bit of space without having to have them compressed.
(and in the future if the roms needed to be full size, then you can just restore them to the original size)
 
  • Like
Reactions: pelago

PsyBlade

Snake Charmer
Member
Joined
Jul 30, 2009
Messages
2,204
Trophies
0
Location
Sol III
XP
458
Country
Gambia, The
seems to work fine for me
the trimmed files were actually smaller that the ones compressed with gzip and bzip2


quick and dirty 3ds rom trimmer:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
import sys, io, struct
 
print "trimming {} Bytes".format(sys.argv[1]),
rom = io.open(sys.argv[1], "rb+")
rom.seek(0x100)
assert rom.read(4).decode("ascii") == "NCSD"
fullsize = struct.unpack("<I",rom.read(4))[0] << 9
rom.seek(0x300)
trimsize = struct.unpack("<I",rom.read(4))[0]
rom.seek(trimsize)
while rom.tell() < fullsize:
    data = rom.read1(1<<16)
    if data == "": break
    assert min(data) == "\xff"
assert rom.read1(1<<8) == ""
assert rom.tell() <= fullsize
rom.truncate(trimsize)
rom.close()
print "to {} Bytes".format(trimsize)

and untrimmer:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
import sys, io, struct
 
print "untrimming {}".format(sys.argv[1]),
rom = io.open(sys.argv[1], "rb+")
rom.seek(0x100)
assert rom.read(4).decode("ascii") == "NCSD"
fullsize = struct.unpack("<I",rom.read(4))[0] << 9
rom.seek(0x300)
trimsize = struct.unpack("<I",rom.read(4))[0]
rom.seek(trimsize)
assert rom.read1(1<<8) == ""
assert rom.tell() == trimsize
while rom.tell() < fullsize:
    rom.write("\xff"*min(1<<16,fullsize-rom.tell()))
rom.close()
print "to {} Bytes".format(fullsize)
 

abdelmajidtolba

Active Member
Newcomer
Joined
Dec 21, 2011
Messages
33
Trophies
0
Age
39
Location
Saudi Arabia
XP
87
Country
Mauritania
Now ,guys,guys wait a second...
Explain in Human language , i stopped coding when came across pointers so i dont have a clue on how this piece code should be used (saved as bat file,recompiled ...etc)
mind to share a little of your wisdom.
(I trimmed my DS roms myself, keeping the Wi-Fi functionality in all of them.)
if trimming removes fucntionnality i hope you rot in hell !!!
For now the hole 3ds roms are 148 7z packed.
If trimming removes 30-40 Gb im all for it ,if not ,well ill see as one of various ''Mess with Original Backup'' LOL.

@Pong : expect a huge pack ill made will all icons ,High res covers for the 3ds (around 200 mb).
For a feature rom manager with high res cover (maybe??),cause i dont know about you guys but we reached 2013 (56K modem and dinosaurs are long gone) and my eyes hurts trying to read 3ds back or front covers.

@Ris312
Where have i seen this pseudo? an impression of Deja vu .
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Xdqwerty @ Xdqwerty: https://www.youtube.com/watch?v=2e1d3daJ0HE