Reverse Engineering 'n NES
Lucas Pinheiro
SOBRE O NES
- Lançado 1983 (JP) e 1985(US)
- Ricoh 2C02 - Paint Picture Unit
- Ricoh 2A03@1.79mhz - Microprocessador
- 2Kbytes RAM - Main RAM
- Memory Map, Bank Switch, Mapper [...]
- Grandes nomes como Mario, Mega Man, Mother, Metroid [...]
- Um 6502 com pequenas modificações.
- 8 bits
- 6502 foi utilizado no Apple II, alguns consoles da Atari, C64 [...]
- Audio Processing Unit (APU)
Ricoh 2A03
Ricoh 2A03
Memory Map
Address Range | Size | Device |
---|---|---|
$0000-$07FF | $0800 | 2KB internal RAM |
$0800-$1FFF | $1800 | Mirrors of $0000-$07FF |
$2000-$2007 | $0008 | NES PPU registers |
$4000-$4017 | $0018 | NES APU and I/O registers |
$4020-$FFFF | $BFE0 | Cartridge space: PRG ROM, PRG RAM, and mapper registers (See Note) |
Fonte: http://wiki.nesdev.com/w/index.php/CPU_memory_map
Mapper/Bank Switch
Fonte: http://kevtris.org/mappers/mmc1/NES_SLROM.jpg
Um pouco sobre 6502
Register | Size | Desc |
---|---|---|
A | 8 bits | Accumlator |
X | 8 bits | General Purpose Register |
Y | 8 bits | General Purpose Register |
Flag | 8 bits | Overflow, Negative, Interrupt [...] |
SP | 16 bits | Stack Segment Register |
PC | 16 bits | Program Counter |
Um pouco sobre 6502
Instrução | Exemplo | Descrição |
---|---|---|
LDA | LDA #$1C | A = $1C |
STA | STA $35 | mem[$25] = A |
AND | AND #$25 | A = A & 25 |
CMP | CMP #3 | Compara valor em A com 3 |
BEQ | BEQ _endereço_ | Desvia se o resultado do CMP for igual por exemplo |
PC | 16 bits | Endereço da próxima instrução |
Mais informações: http://e-tradition.net/bytes/6502/6502_instruction_set.html
Um pouco sobre 6502
if (a == 0x25) {
/** do something 1 *//
} else {
a = 0x0;
}
Breaking Mega Man 2
- Editor Hexadecimal: Linux: Bless, Windows: HxD
- IDA Pro: Versão utilizada 6.8
- NES Plugins: http://www.romhacking.net/utilities/627/
- Emulador de NES com debugger: FCEUX
Ferramentas utilizadas
Breaking Mega Man 2
- Apenas os plugins bankswitch e nesldr foram utilizados
- O bankswitch.plw deve ficar na pasta plugins do IDA
- O nes.ldw na pasta loaders do IDA
Oh wait!
Breaking Mega Man 2
Análise Estática vs Análise Dinâmica
Breaking Mega Man 2
Vamos a prática !
Breaking Mega Man 2
Dúvidas ?
deck
By St4rk
deck
- 712