All Projects → mattcurrie → Mgbdis

mattcurrie / Mgbdis

Licence: mit
Game Boy ROM disassembler with RGBDS compatible output

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Mgbdis

Reko
Reko is a binary decompiler.
Stars: ✭ 942 (+619.08%)
Mutual labels:  disassembler, reverse-engineering
Redasm
The OpenSource Disassembler
Stars: ✭ 1,042 (+695.42%)
Mutual labels:  disassembler, reverse-engineering
Medusa
An open source interactive disassembler
Stars: ✭ 946 (+622.14%)
Mutual labels:  disassembler, reverse-engineering
Ghidra
Ghidra is a software reverse engineering (SRE) framework
Stars: ✭ 30,371 (+23083.97%)
Mutual labels:  disassembler, reverse-engineering
X64dbg
An open-source x64/x32 debugger for windows.
Stars: ✭ 37,825 (+28774.05%)
Mutual labels:  disassembler, reverse-engineering
Dithumb
Minimal ARM/Thumb linear sweep disassembler similar to objdump
Stars: ✭ 5 (-96.18%)
Mutual labels:  disassembler, reverse-engineering
Pince
A reverse engineering tool that'll supply the place of Cheat Engine for linux
Stars: ✭ 987 (+653.44%)
Mutual labels:  disassembler, reverse-engineering
Pokeyellow
Disassembly of Pokemon Yellow
Stars: ✭ 383 (+192.37%)
Mutual labels:  gameboy, reverse-engineering
Bap
Binary Analysis Platform
Stars: ✭ 1,385 (+957.25%)
Mutual labels:  disassembler, reverse-engineering
Panopticon
A libre cross-platform disassembler.
Stars: ✭ 1,376 (+950.38%)
Mutual labels:  disassembler, reverse-engineering
Vivisect
Stars: ✭ 672 (+412.98%)
Mutual labels:  disassembler, reverse-engineering
Poketcg
Disassembly of Pokémon TCG
Stars: ✭ 125 (-4.58%)
Mutual labels:  gameboy, reverse-engineering
Die Engine
DIE engine
Stars: ✭ 648 (+394.66%)
Mutual labels:  disassembler, reverse-engineering
Ret Sync
ret-sync is a set of plugins that helps to synchronize a debugging session (WinDbg/GDB/LLDB/OllyDbg2/x64dbg) with IDA/Ghidra/Binary Ninja disassemblers.
Stars: ✭ 896 (+583.97%)
Mutual labels:  disassembler, reverse-engineering
Capstone
Capstone disassembly/disassembler framework: Core (Arm, Arm64, BPF, EVM, M68K, M680X, MOS65xx, Mips, PPC, RISCV, Sparc, SystemZ, TMS320C64x, Web Assembly, X86, X86_64, XCore) + bindings.
Stars: ✭ 5,374 (+4002.29%)
Mutual labels:  disassembler, reverse-engineering
Peasauce
Peasauce Interactive Disassembler
Stars: ✭ 33 (-74.81%)
Mutual labels:  disassembler, reverse-engineering
Pwndbg
Exploit Development and Reverse Engineering with GDB Made Easy
Stars: ✭ 4,178 (+3089.31%)
Mutual labels:  disassembler, reverse-engineering
Scratchabit
Easily retargetable and hackable interactive disassembler with IDAPython-compatible plugin API
Stars: ✭ 369 (+181.68%)
Mutual labels:  disassembler, reverse-engineering
Pokepinball
Disassembly of Pokémon Pinball
Stars: ✭ 77 (-41.22%)
Mutual labels:  gameboy, reverse-engineering
Bin2llvm
A binary to LLVM translator
Stars: ✭ 108 (-17.56%)
Mutual labels:  disassembler, reverse-engineering

mgbdis

A Game Boy ROM disassembler.

Features

  • Generates assembly code compatible with RGBDS (v0.3.8+ recommended, see Notes)
  • Supports ROMs with multiple banks
  • Supports .sym files to define labels, code, data, text and image blocks
  • Outputs a makefile to rebuild the ROM
  • Uses defines from hardware.inc v2.7 for hardware registers (source)
  • Slow on large ROMs

Usage

Disassemble a ROM:

./mgbdis.py some-game.gb

Default output is to the disassembly directory. You can verify the result of the disassembly by running make and then checking the game.gb (or game.gbc) file created:

cd disassembly && make

There are also a number of options available to control the formatting and instruction style of the generated assembly code. You can view these by running:

./mgbdis.py -h

Symbol Files

Symbol files allow you to indicate where code, data, test and image data blocks are in the ROM.

The instructions of the Game Boy CPU (SM83) have different lengths, and data can be interleaved with code in the ROM, so it is not possible to always accurately identify where an instruction starts and stops. Defining code blocks in a symbol file can help to avoid problems with mgbdis trying to disassemble in the middle of an instruction.

If you do not have a symbol file, you can try generating one with my Game Boy emulator - Beaten Dying Moon. It can generate a symbol file with code block definitions based on the the addresses of the instructions that have actually been executed while you have been playing the game, avoiding instruction alignment issues.

To use a symbol file with mgbdis, it should exist in the same directory as the ROM and have the same name, except change the extension to be .sym.

All values (except for image widths) should be in hexadecimal. Entries start with a bank number followed by the address in memory.

Block types can be defined by using the .code, .data, .text, and .image magic labels, followed by the length of the block in bytes.

Code

Adding a label for some code:

03:47f2 Read_Joypad_State

Data

Adding a label for 512 bytes of data:

0d:4800 Level_Data
0d:4800 .data:200

Text

Adding a label for 16 bytes of text:

00:3d00 Character_Name
00:3d00 .text:10

Image

The .image magic label allows you to define blocks of 1 or 2 bits per pixel tile data in the ROM. Images are output as PNG files in the /gfx directory of the disassembly, and are converted back to 1bpp or 2bpp tile data by the makefile using rgbgfx. If a label is specified at the address of the image block then it will be used for the name of the PNG file.

The block length in bytes should be a multiple of 16, as each tile requires 16 bytes of image data.

The image width in pixels can be specified as a decimal number prefixed with w. The width value should be a multiple of 8, and the combination of block length and image width must result in a rectangluar image without any empty tiles. The default image width is 128 pixels, or if the block length indicates an odd number of tiles, then an image with a single row of tiles will be generated.

The palette is a byte sized value which selects the shades of grey to use when generating the image. It uses the same format as the BGP register at 0xFF47. The value can be specified in hexidecimal prefixed with p. The default palette is E4.

The default is to treat it as 2 bits per pixel tile data. A 1bpp option can be supplied to treat the data as 1 bit per pixel tile data.

Adding a label for 1280 bytes of tile data, with a width of 128 pixels and palette 0xE4:

02:791a Title_Screen_Tile_Data
02:791a .image:500:w128,pe4

Resulting image:

Imgur

Example for 1bpp tile data:

05:4000 Font
05:4000 .image:200:w128,1bpp

Resulting image:

Imgur

Notes

  • For constant expressions, RGBDS will by default optimise instructions like LD [$FF40],a to LDH [$FF00+40],a, so these are encoded as data bytes using a macro to ensure exact reproduction of the original ROM (thanks to ISSOtm). RGBDS >= v0.3.7 has an option to disable this optimisation. Use --disable-auto-ldh with mgbdis to disable the macro.
  • RGBDS automatically adds NOP instructions after STOP and HALT, so the disassembler will output these as data bytes if the instruction is not followed by a NOP in the original ROM. Use --disable-halt-nops with mgbdis to instruct RGBDS to disable inserting automatic NOP instructions after HALT instructions.
  • RGBDS v0.3.6 has an off by one error for some JR instructions, causing the assembled ROM to not match the original.
  • RGBDS v0.3.7 rgbfix generates an invalid global checksum in the ROM header, causing the assembled ROM to not match the original.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].