Tuesday, January 29, 2013

Romhacking misconceptions

Today I'd like to talk about a few common misconceptions when hacking.

"I can't hex"

Look bro, I don't care who you are "hex" is not an action. It's a type of counting system
01-0F, and so on.

Just forget the term hex if it bothers you that much. Just refer to it as data however.

If you see 0x

Such as 0x0BADC0DE the 0x indicates we're using the hexadecimal system.

Now when you pull up a ROM in a hex editor, you'll see this

This image shows many things, but you're probably confused.

This is called a GBA header. It's of course stored in a binary data format. But since we know it's a GBA game header, we can just find the header structure on google and apply the info.

Here's the structure

0x000h 4 ROM Entry Point (32bit ARM branch opcode, eg. "B rom_start")  0x004h 156 Nintendo Logo (compressed bitmap, required!)
 0x0A0h 12 Game Title (uppercase ascii, max 12 characters)
 0x0ACh 4 Game Code (uppercase ascii, 4 characters)
 0x0B0h 2 Maker Code (uppercase ascii, 2 characters)
 0x0B2h 1 Fixed value (must be 96h, required!)
 0x0B3h 1 Main unit code (00h for current GBA models)
0x0B4h 1 Device type (usually 00h)
 0x0B5h 7 Reserved Area (should be zero filled)
 0x0BCh 1 Software version (usually 00h)
 0x0BDh 1 Complement check (header checksum, required!)
 0x0BEh 2 Reserved Area (should be zero filled)

So according to this, the first 4 bytes are an assembly instruction on where to start the game.
Then is a compressed image(Yes, that's stored in our hexadecimal data format)

Then so on.

Data is nothing to be scared of. The editors you use, the game itself relies on 
the data.

Let's move on to pointers.

They're scary for a lot of newbies. I didn't quite get them when I first started,but now I rely on them.

It's super simple

it's just address+0x8000000 and it's stored backwards in the rom

So the pointer 0x08123456 would be stored in rom at 56 34 12 08

Codes uses the pointer to get the address of the data.
Just add 0x8000000 for ROM pointers. Simple no?

Assembly is just a way of seeing the data as somewhat readable

nop instead of 0x46c0.

It's not hard and just needs to be learned.

If you have any questions, leave a comment. I'll get back to you.

No comments:

Post a Comment