hansbonini/sega2asm

GitHub: hansbonini/sega2asm

专为世嘉 Genesis/Mega Drive 平台打造的 ROM 反汇编与资源拆分工具,支持双 CPU 反汇编、二十余种压缩格式自动解压以及图形音频资源提取。

Stars: 21 | Forks: 2

# sega2asm **Sega Mega Drive / Genesis ROM 反汇编与拆分工具** 灵感来源于 [ethteck/splat](https://github.com/ethteck/splat) 和 [nathancassano/snes2asm](https://github.com/nathancassano/snes2asm)。 68000 反汇编器基于 [Clownacy/clown68000](https://github.com/Clownacy/clown68000)。 Z80 反汇编器基于 [Clownacy/clownz80](https://github.com/Clownacy/clownz80)。 汇编输出兼容 [Clownacy/clownassembler](https://github.com/Clownacy/clownassembler) (asm68k clone)。 ## 功能特性 | 段类型 | 输出 | 描述 | |---|---|---| | `header` | `.asm` | ROM 头 + 中断向量表 | | `m68k` | `.asm` | Motorola 68000 反汇编 | | `z80` | `.asm` | Zilog Z80 反汇编 (声音 CPU) | | `gfx` | `.png` + `.bin` | 原始 4bpp 图块图形 → PNG 图表 | | `gfxcomp` | `.png` + `.bin` | 压缩图形 (自动解压) | | `pcm` | `.wav` | 原始 PCM 采样 → WAV (默认 7040 Hz) | | `psg` | `.mid` | SN76489 PSG 寄存器流 → MIDI | | `text` | `.txt` | 带可选字符映射解码的文本 | | `bin` | `.bin` | 原始二进制数据块 | … **支持的压缩格式:** - `none` – 无压缩,数据原样复制。 - `nemesis` – Konami “Nemesis” 图块压缩器。 - `kosinski` – Kosinski LZ 风格方案。 - `kosinskiplus` – 扩展 Kosinski 变体。 - `enigma` – Enigma 位打包压缩器。 - `segard` – SegaRD 图形压缩。(用于 Altered Beast)。 - `saxman`, `saxman_noheader` – Sonic the Hedgehog 2 使用的格式,用于压缩其声音引擎和音乐数据(实际上是 Haruhiko Okumura 1989 年 LZSS 格式的轻微修改版)。 - `comper` – 其他社区开发的格式,专为 Motorola 68000 上的解压速度而设计。这以牺牲压缩率为代价。 - `rocket` – Rocket Knight 压缩。 - `faxman` – Saxman 的修改版,旨在压缩 SMPS 音乐数据时生成更小的文件。 - `rage` – Streets of Rage 风格的比特流压缩器(用于 SOR 等)。 - `chameleon` – Kid Chameleon 压缩。 - `lznamco` – Namco LZ (Ball Jacks, Klax, Marvel Land, Pac-Attack, PacMan 2, Phelios …)。 - `lzstrike` – 与 Namco 相同但具有 0x800 窗口 (Desert/Jungle/Urban Strike)。 - `lztechnosoft` – Technosoft 变体,无大小头 (Elemental Master)。 - `lzkonami1` – Konami 的第一个 LZ (Animaniacs, Contra Hard Corps, Lethal Enforcers II, Sparkster …)。 - `lzkonami2` – Konami 的第二个 LZ (Castlevania Bloodlines, Rocket Knight, TMNT Hyperstone, Sunset Riders …)。 - `lzkonami3` – Konami 的第三个 LZ (Castlevania Bloodlines, Lethal Enforcers, TMNT Tournament Fighters …)。 - `lzancient` – Ancient/LucasArts 压缩器 (Beyond Oasis, Streets of Rage 2)。 - `lztose` – Tose LZ (Dragon Ball Z: Buyuu Retsuden)。 - `lznextech` / `lzwolfteam` – Nextech/WolfTeam LZ (Crusader of Centy, El Viento, Granada, Earnest Evans, Final Zone, Ranger-X, Zan Yasha …)。 - `lzsti` – Comix Zone 使用的 STI LZ。 - `rlesc` – Software Creations RLE (Maximum Carnage, Venom, The Tick, Cutthroat Island …)。 - `rnc`, `rnc1`, `rnc2` – Rob Northen Compression 方法 1/2(通用,见于各种移植和工具中)。 - `lzcompile` – Compile Co. Ltd. 命令字节方案 (Puyo Puyo, Aleste / MUSHA, GG Aleste, Puyo Puyo 2, Power Strike II …)。回溯引用使用 256 字节循环历史记录;输出以 4 字节块缓冲。 - `itl` – I.T.L. (Sega) 非零字节 + XOR 块压缩器 (Bonanza Bros, 以及其他 I.T.L. 开发的 Sega 游戏)。 - `lzfactor5` – Factor 5 LZ(版本 1:11 位窗口 / 版本 2:16 位窗口;从头自动检测)。用于 Factor 5 Mega Drive 游戏。 - `lzbeam` – Beam Software LZ:可变宽度 Elias 编码计数 + 绝对回溯引用(位宽源自写入位置);命令位存储在单独的附加比特流中 (Shadowrun, Batman Returns, Judge Dredd …)。 **标签与符号:** - 以多种格式读取 `symbols.txt` (name=addr, addr:name, 空格分隔) - 用于反汇编中的分支目标、跳转和数据标签 **字符映射 (Charmap):** - 标准 `.tbl` 格式 (兼容 THINGY / WindHex) - 用于 `text` 段和 `m68k` 段中的 `dc.b` 字符串提示 ## 安装 ``` git clone https://github.com/you/sega2asm cd sega2asm go build -o sega2asm . ``` 需要 Go 1.21+。 ## 用法 ``` sega2asm [options] Options: -c Configuration YAML file -s Symbols file (overrides config) -t Charmap TBL file (overrides config) -v Verbose output --dry-run Parse config & symbols, print plan, no file writes --version Show version ``` ### 快速开始 ``` sega2asm -c example/sonic1.yaml -s example/symbols.txt -t example/charmap.tbl -v ``` ## 配置 YAML ``` name: sonic1 sha1: "" # Optional SHA1 for ROM verification options: platform: genesis # genesis | megadrive region: ntsc # ntsc | pal basename: sonic1 base_path: ./out # Root output directory target_path: ./roms/sonic1.md # Input ROM file asm_path: asm # Sub-dir for .asm files asset_path: assets # Sub-dir for graphics/audio build_path: build symbols_path: ./symbols.txt charmap_path: ./charmap.tbl header_output: true # Write main .asm include file segments: - name: header type: header start: 0x000000 end: 0x000200 - name: main_code type: m68k start: 0x000200 end: 0x040000 hints: - offset: 0x0000 # relative to segment start type: code label: EntryPoint - offset: 0x0E00 type: data_long length: 32 label: LevelPtrs - name: sound_driver type: z80 start: 0x040000 end: 0x042000 - name: art_sonic type: gfxcomp compression: nemesis start: 0x050000 end: 0x052000 - name: sfx_jump type: pcm sample_rate: 7040 start: 0x080000 end: 0x081000 - name: music_ghz type: psg start: 0x090000 end: 0x091000 - name: credits_text type: text encoding: charmap start: 0x0B0000 end: 0x0B0200 ``` ## 符号文件格式 接受以下所有格式: ``` ; C-style or semicolon comments are ignored LabelName = $00A000 ; splat style LabelName = 0x00A000 $00A000 LabelName ; address-first 00A000:LabelName ; colon separated 00A000 LabelName ; hex space name ``` ## 字符映射 TBL 格式 标准 THINGY / WindHex `.tbl` 格式: ``` ; comment 00= ; byte 00 = empty / terminator 01=A 0D=\n FF= ``` 支持多字节键: ``` 8141=ア 8142=イ ``` ## 提示类型 (内联反汇编控制) | 类型 | 发出的指令 | |---|---| | `code` | 正常反汇编 | | `data_byte` | `dc.b $XX` 每字节 | | `data_word` | `dc.w $XXXX` 每字 | | `data_long` | `dc.l $XXXXXXXX` 每长字 | | `text` | `dc.b 'string',0` (字符映射解码) | | `skip` | `even` (对齐填充) | ## 项目布局 (输出) ``` out/ ├── asm/ │ ├── m68k/ │ │ └── main_code.asm │ ├── z80/ │ │ └── sound_driver.asm │ ├── header/ │ │ └── header.asm │ └── sonic1.asm ← main include file └── assets/ ├── gfxcomp/ │ └── art_sonic.png ├── pcm/ │ └── sfx_jump.wav ├── psg/ │ └── music_ghz.mid └── text/ └── credits_text.txt ``` ## 参考 - [ethteck/splat](https://github.com/ethteck/splat) - [Clownacy/clownassembler](https://github.com/Clownacy/clownassembler) - [Clownacy/clown68000](https://github.com/Clownacy/clown68000) - [Clownacy/clownz80](https://github.com/Clownacy/clownz80) - [Clownacy/clownnemesis](https://github.com/Clownacy/clownnemesis) - [Clownacy/clownlzss](https://github.com/Clownacy/clownlzss) - [hansbonini/smd_alteredbeast](https://github.com/hansbonini/smd_alteredbeast)
标签:EVTX分析, Golang, Kosinski, M68k, Mega Drive, Motorola 68000, Nemesis, ROM, Sega Genesis, Wayback Machine, Z80, 世嘉, 二进制分析, 二进制发布, 云安全监控, 云安全运维, 云资产清单, 代码拆分, 仿真器, 反汇编, 复古游戏, 安全编程, 开源工具, 快速连接, 数据解压, 日志审计, 汇编语言, 游戏开发, 逆向工程, 静态分析