Romhacking => Programming => Topic started by: Lynol on July 22, 2021, 12:09:08 pm

Title: how to create programs for unpacking files and archives
Post by: Lynol on July 22, 2021, 12:09:08 pm
hello everyone. I'm having trouble again. how do I create programs to unpack files? Someone can give a link to a video with examples or articles on this topic(also with examples). I will be very happy. Thank you in advance. And sorry for my bad English(I'm from Russia)
Title: Re: how to create programs for unpacking files and archives
Post by: Cyneprepou4uk on July 22, 2021, 12:48:33 pm

Гугли алгоритмы сжатия zip
Title: Re: how to create programs for unpacking files and archives
Post by: FAST6191 on July 22, 2021, 02:16:46 pm
I don't have anything in Russian, though there are some very good Russian ROM hackers. being two links good to start with. Something there might be useful.

There are some programs that are scripting languages, or have plugin support. You can often program these to do what you want without having to make a full program to do it yourself. has many programs for extracting things, and many will have source code you can look at. is an example of a scripting program, though do read the license it comes with.

Generally though files have a few aspects

1) Any kind of file details, including names of things it contains.

2) Pointers.

3) Data itself.

Unpacking is typically using the pointers to locate the files and then slicing off each part of the data section into its own file. If the game does not have pointers we have seen some programs do detection methods for things (some GBA editors, Golden Sun ones, being among the more noted). If there is compression then that too.

You can do a crude version of this without much programming skill. I like a program called filecutter ( ) but there are others. With that you can tell it to slice this many bytes out at this point in the file. Make a batch file containing a few hundred commands and you have your extraction script for that file at least. For a ROM that will be the same for everybody and same forever then that is not so bad. You can get the locations and lengths from the pointers which a hex editor can dump (if you know a pointer and the next pointer you can subtract and get length, assuming length is not there as part of it all).

If you don't want to do that then you need a programming language that can take in files, read things in binary, and write files back out. This is not all programming languages but it is most of them; C, C++, C#, python, java, ruby, Lua... all good for that. Stuff that will be harder or more annoying is usually web languages (php, javascript, HTML), things focused mostly on text (perl, latex), things for maths (R, matlab) and databases (sql has many forms, and the modern world probably wants to include nosql), though many of those in more modern forms will do the job as well.
Neither of those are Russian but my usual two links for people wanting to learn general programming and not assembly. Hopefully you can find a translation of some of those books mentioned (many have them to many languages).

If the additional file details are relevant you probably want to note them as well. For instance sound files might note what volume to play things, what instruments to use, what speed to play things and a few other things like that.

Also if you aim to one day repack them you will likely want to note any relevant information, file ordering or the like that simple files might not have to use to recreate the file so it works with the game.

There are hundreds of arrangements of parts of files just for a basic archive, and hundreds of little quirks. For instance in one case on the DS I had a file format that shifted its numbers (effectively multiplied them by 4) for reasons best known to itself. Another common DS archive format called NARC has the high bits of its pointers set if the file is a subdirectory within the archive. This sort of thing can take a long time to learn and to spot, however it is pretty much the definition of what ROM hacking is.
For examples of formats
Several of those pages will use a format to describe the contents based around what C programmers will use so might want to learn that even if you don't learn/use C in your extraction program.
Title: Re: how to create programs for unpacking files and archives
Post by: komeyria55 on October 12, 2021, 02:49:55 pm
Two popular programs are WinZip * and 7-Zip *. Both of these allow you to unzip and zip with two clicks: Here, I have right-clicked on the zipped file and selected "Extract to here." "Extract" is the same thing as "unzip." Windows also sometimes places "Extract files" links in toolbars which may be useful to you.

To extract:
A file or folder, open the archive and drag the file or folder to the location you require.
The entire contents of the archive, select Extract All from the shortcut menu and follow the instructions.
Title: Re: how to create programs for unpacking files and archives
Post by: MysticLord on October 13, 2021, 05:04:24 am
DeepL is the best automatic translation website I've seen. It's much better than Google translate. I recommend it.

DeepL - это лучший сайт автоматического перевода, который я видел. Он намного лучше, чем Google translate. Я рекомендую его.