miorom 0.13.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (353) hide show
  1. miorom-0.13.0/LICENSE +21 -0
  2. miorom-0.13.0/PKG-INFO +326 -0
  3. miorom-0.13.0/README.md +298 -0
  4. miorom-0.13.0/pyproject.toml +142 -0
  5. miorom-0.13.0/setup.cfg +4 -0
  6. miorom-0.13.0/src/miorom/__init__.py +935 -0
  7. miorom-0.13.0/src/miorom/analysis_db.py +267 -0
  8. miorom-0.13.0/src/miorom/archive/__init__.py +39 -0
  9. miorom-0.13.0/src/miorom/archive/cascading.py +182 -0
  10. miorom-0.13.0/src/miorom/archive/container.py +69 -0
  11. miorom-0.13.0/src/miorom/archive/dissector.py +469 -0
  12. miorom-0.13.0/src/miorom/archive/dma.py +149 -0
  13. miorom-0.13.0/src/miorom/archive/master_table.py +117 -0
  14. miorom-0.13.0/src/miorom/archive/synthesizer.py +299 -0
  15. miorom-0.13.0/src/miorom/archive/toc_pair.py +232 -0
  16. miorom-0.13.0/src/miorom/archive/vfs.py +320 -0
  17. miorom-0.13.0/src/miorom/asm/__init__.py +106 -0
  18. miorom-0.13.0/src/miorom/asm/ap_bypass.py +198 -0
  19. miorom-0.13.0/src/miorom/asm/branch.py +219 -0
  20. miorom-0.13.0/src/miorom/asm/cheat.py +315 -0
  21. miorom-0.13.0/src/miorom/asm/codecave.py +81 -0
  22. miorom-0.13.0/src/miorom/asm/disambiguator.py +253 -0
  23. miorom-0.13.0/src/miorom/asm/disasm.py +793 -0
  24. miorom-0.13.0/src/miorom/asm/instruction_scanner.py +548 -0
  25. miorom-0.13.0/src/miorom/asm/jump_table.py +187 -0
  26. miorom-0.13.0/src/miorom/asm/literal_relocator.py +163 -0
  27. miorom-0.13.0/src/miorom/asm/micro_patcher.py +133 -0
  28. miorom-0.13.0/src/miorom/asm/prologue_scanner.py +80 -0
  29. miorom-0.13.0/src/miorom/asm/slicer.py +215 -0
  30. miorom-0.13.0/src/miorom/asm/snippet.py +421 -0
  31. miorom-0.13.0/src/miorom/asm/trampoline.py +252 -0
  32. miorom-0.13.0/src/miorom/asm/xref.py +225 -0
  33. miorom-0.13.0/src/miorom/audio/__init__.py +19 -0
  34. miorom-0.13.0/src/miorom/audio/adpcm.py +108 -0
  35. miorom-0.13.0/src/miorom/audio/n64_seq.py +102 -0
  36. miorom-0.13.0/src/miorom/audio/sdat.py +146 -0
  37. miorom-0.13.0/src/miorom/audio/sseq.py +388 -0
  38. miorom-0.13.0/src/miorom/audio/xa.py +216 -0
  39. miorom-0.13.0/src/miorom/cli/__init__.py +3 -0
  40. miorom-0.13.0/src/miorom/cli/main.py +666 -0
  41. miorom-0.13.0/src/miorom/compression/__init__.py +114 -0
  42. miorom-0.13.0/src/miorom/compression/carver.py +203 -0
  43. miorom-0.13.0/src/miorom/compression/heuristic.py +255 -0
  44. miorom-0.13.0/src/miorom/compression/huffman.py +287 -0
  45. miorom-0.13.0/src/miorom/compression/inspector.py +114 -0
  46. miorom-0.13.0/src/miorom/compression/lz10.py +156 -0
  47. miorom-0.13.0/src/miorom/compression/lz11.py +194 -0
  48. miorom-0.13.0/src/miorom/compression/rle.py +119 -0
  49. miorom-0.13.0/src/miorom/compression/speculative.py +175 -0
  50. miorom-0.13.0/src/miorom/compression/yaz0.py +161 -0
  51. miorom-0.13.0/src/miorom/core/__init__.py +127 -0
  52. miorom-0.13.0/src/miorom/core/bank_expander.py +217 -0
  53. miorom-0.13.0/src/miorom/core/binary.py +262 -0
  54. miorom-0.13.0/src/miorom/core/buffer.py +218 -0
  55. miorom-0.13.0/src/miorom/core/heap_builder.py +94 -0
  56. miorom-0.13.0/src/miorom/core/hex_diff.py +97 -0
  57. miorom-0.13.0/src/miorom/core/integrity.py +339 -0
  58. miorom-0.13.0/src/miorom/core/mapper.py +161 -0
  59. miorom-0.13.0/src/miorom/core/memory.py +113 -0
  60. miorom-0.13.0/src/miorom/core/multilevel_pointer.py +125 -0
  61. miorom-0.13.0/src/miorom/core/overlay_mapper.py +214 -0
  62. miorom-0.13.0/src/miorom/core/pointer.py +163 -0
  63. miorom-0.13.0/src/miorom/core/record_builder.py +113 -0
  64. miorom-0.13.0/src/miorom/core/rom_view.py +274 -0
  65. miorom-0.13.0/src/miorom/core/scanner.py +685 -0
  66. miorom-0.13.0/src/miorom/core/schema.py +665 -0
  67. miorom-0.13.0/src/miorom/core/signatures.py +70 -0
  68. miorom-0.13.0/src/miorom/core/string_carver.py +119 -0
  69. miorom-0.13.0/src/miorom/core/struct_profiler.py +382 -0
  70. miorom-0.13.0/src/miorom/core/symbol_map.py +242 -0
  71. miorom-0.13.0/src/miorom/core/vlq.py +114 -0
  72. miorom-0.13.0/src/miorom/debug/__init__.py +39 -0
  73. miorom-0.13.0/src/miorom/debug/buffer_analyzer.py +124 -0
  74. miorom-0.13.0/src/miorom/debug/client.py +104 -0
  75. miorom-0.13.0/src/miorom/debug/gdb_client.py +366 -0
  76. miorom-0.13.0/src/miorom/debug/protocols.py +15 -0
  77. miorom-0.13.0/src/miorom/debug/sanitizer.py +186 -0
  78. miorom-0.13.0/src/miorom/diff/__init__.py +27 -0
  79. miorom-0.13.0/src/miorom/diff/bindiff.py +248 -0
  80. miorom-0.13.0/src/miorom/diff/mapper.py +77 -0
  81. miorom-0.13.0/src/miorom/diff/patch_auditor.py +69 -0
  82. miorom-0.13.0/src/miorom/diff/porter.py +352 -0
  83. miorom-0.13.0/src/miorom/errors.py +97 -0
  84. miorom-0.13.0/src/miorom/formats/__init__.py +5 -0
  85. miorom-0.13.0/src/miorom/formats/batch.py +144 -0
  86. miorom-0.13.0/src/miorom/formats/csv_handler.py +199 -0
  87. miorom-0.13.0/src/miorom/formats/script_catalog.py +164 -0
  88. miorom-0.13.0/src/miorom/graphics/__init__.py +42 -0
  89. miorom-0.13.0/src/miorom/graphics/fast3d.py +237 -0
  90. miorom-0.13.0/src/miorom/graphics/image_bridge.py +124 -0
  91. miorom-0.13.0/src/miorom/graphics/mdec.py +186 -0
  92. miorom-0.13.0/src/miorom/graphics/n64_texture.py +271 -0
  93. miorom-0.13.0/src/miorom/graphics/palette.py +161 -0
  94. miorom-0.13.0/src/miorom/graphics/tilemap.py +140 -0
  95. miorom-0.13.0/src/miorom/graphics/tiles.py +182 -0
  96. miorom-0.13.0/src/miorom/graphics/tilesheet.py +315 -0
  97. miorom-0.13.0/src/miorom/helper/__init__.py +26 -0
  98. miorom-0.13.0/src/miorom/helper/cascading_relocator.py +121 -0
  99. miorom-0.13.0/src/miorom/helper/dual_table.py +178 -0
  100. miorom-0.13.0/src/miorom/helper/relocator.py +113 -0
  101. miorom-0.13.0/src/miorom/helper/string_pool.py +170 -0
  102. miorom-0.13.0/src/miorom/helper/tag_converter.py +159 -0
  103. miorom-0.13.0/src/miorom/link/__init__.py +47 -0
  104. miorom-0.13.0/src/miorom/link/dol.py +216 -0
  105. miorom-0.13.0/src/miorom/link/elf.py +255 -0
  106. miorom-0.13.0/src/miorom/link/heap.py +284 -0
  107. miorom-0.13.0/src/miorom/link/injector.py +412 -0
  108. miorom-0.13.0/src/miorom/link/relocator.py +329 -0
  109. miorom-0.13.0/src/miorom/naming.py +88 -0
  110. miorom-0.13.0/src/miorom/patch/__init__.py +125 -0
  111. miorom-0.13.0/src/miorom/patch/bank_crosser.py +112 -0
  112. miorom-0.13.0/src/miorom/patch/bps.py +213 -0
  113. miorom-0.13.0/src/miorom/patch/hunks.py +50 -0
  114. miorom-0.13.0/src/miorom/patch/ips.py +228 -0
  115. miorom-0.13.0/src/miorom/patch/patch_writer.py +229 -0
  116. miorom-0.13.0/src/miorom/patch/pointer_remapper.py +118 -0
  117. miorom-0.13.0/src/miorom/patch/pointerizer.py +205 -0
  118. miorom-0.13.0/src/miorom/patch/relocator.py +235 -0
  119. miorom-0.13.0/src/miorom/patch/slack.py +202 -0
  120. miorom-0.13.0/src/miorom/patch/xdelta.py +74 -0
  121. miorom-0.13.0/src/miorom/pipeline/__init__.py +27 -0
  122. miorom-0.13.0/src/miorom/pipeline/engine.py +400 -0
  123. miorom-0.13.0/src/miorom/platforms/__init__.py +43 -0
  124. miorom-0.13.0/src/miorom/platforms/cdrom/__init__.py +29 -0
  125. miorom-0.13.0/src/miorom/platforms/cdrom/cue.py +161 -0
  126. miorom-0.13.0/src/miorom/platforms/cdrom/disc.py +339 -0
  127. miorom-0.13.0/src/miorom/platforms/gb/__init__.py +4 -0
  128. miorom-0.13.0/src/miorom/platforms/gb/rom.py +155 -0
  129. miorom-0.13.0/src/miorom/platforms/gba/__init__.py +4 -0
  130. miorom-0.13.0/src/miorom/platforms/gba/rom.py +131 -0
  131. miorom-0.13.0/src/miorom/platforms/gc/__init__.py +16 -0
  132. miorom-0.13.0/src/miorom/platforms/gc/disc.py +418 -0
  133. miorom-0.13.0/src/miorom/platforms/gc/fst_injector.py +86 -0
  134. miorom-0.13.0/src/miorom/platforms/iso/__init__.py +3 -0
  135. miorom-0.13.0/src/miorom/platforms/iso/iso9660.py +229 -0
  136. miorom-0.13.0/src/miorom/platforms/md/__init__.py +21 -0
  137. miorom-0.13.0/src/miorom/platforms/md/rom.py +239 -0
  138. miorom-0.13.0/src/miorom/platforms/n64/__init__.py +29 -0
  139. miorom-0.13.0/src/miorom/platforms/n64/checksum.py +184 -0
  140. miorom-0.13.0/src/miorom/platforms/n64/rom.py +230 -0
  141. miorom-0.13.0/src/miorom/platforms/nds/__init__.py +33 -0
  142. miorom-0.13.0/src/miorom/platforms/nds/narc.py +241 -0
  143. miorom-0.13.0/src/miorom/platforms/nds/nftr.py +276 -0
  144. miorom-0.13.0/src/miorom/platforms/nds/rom.py +766 -0
  145. miorom-0.13.0/src/miorom/platforms/psx/__init__.py +6 -0
  146. miorom-0.13.0/src/miorom/platforms/psx/exe.py +55 -0
  147. miorom-0.13.0/src/miorom/platforms/psx/str.py +223 -0
  148. miorom-0.13.0/src/miorom/platforms/psx/tim.py +135 -0
  149. miorom-0.13.0/src/miorom/platforms/snes/__init__.py +3 -0
  150. miorom-0.13.0/src/miorom/platforms/snes/rom.py +177 -0
  151. miorom-0.13.0/src/miorom/platforms/wii/__init__.py +5 -0
  152. miorom-0.13.0/src/miorom/platforms/wii/brfnt.py +200 -0
  153. miorom-0.13.0/src/miorom/platforms/wii/tpl.py +260 -0
  154. miorom-0.13.0/src/miorom/platforms/wii/u8.py +376 -0
  155. miorom-0.13.0/src/miorom/project/__init__.py +28 -0
  156. miorom-0.13.0/src/miorom/project/assets.py +157 -0
  157. miorom-0.13.0/src/miorom/project/game.py +172 -0
  158. miorom-0.13.0/src/miorom/project/manager.py +217 -0
  159. miorom-0.13.0/src/miorom/project/protocols.py +29 -0
  160. miorom-0.13.0/src/miorom/project/rules.py +62 -0
  161. miorom-0.13.0/src/miorom/project/scaffold.py +106 -0
  162. miorom-0.13.0/src/miorom/py.typed +0 -0
  163. miorom-0.13.0/src/miorom/registry.py +62 -0
  164. miorom-0.13.0/src/miorom/result.py +107 -0
  165. miorom-0.13.0/src/miorom/rom/__init__.py +28 -0
  166. miorom-0.13.0/src/miorom/rom/base.py +32 -0
  167. miorom-0.13.0/src/miorom/rom/expander.py +213 -0
  168. miorom-0.13.0/src/miorom/rom/handlers/__init__.py +15 -0
  169. miorom-0.13.0/src/miorom/rom/handlers/cartridge.py +152 -0
  170. miorom-0.13.0/src/miorom/rom/handlers/gc.py +125 -0
  171. miorom-0.13.0/src/miorom/rom/handlers/iso9660.py +88 -0
  172. miorom-0.13.0/src/miorom/rom/handlers/narc.py +68 -0
  173. miorom-0.13.0/src/miorom/rom/handlers/nds.py +415 -0
  174. miorom-0.13.0/src/miorom/rom/handlers/u8.py +111 -0
  175. miorom-0.13.0/src/miorom/rom/manager.py +233 -0
  176. miorom-0.13.0/src/miorom/rom/protocols.py +19 -0
  177. miorom-0.13.0/src/miorom/save/__init__.py +20 -0
  178. miorom-0.13.0/src/miorom/save/checksum.py +107 -0
  179. miorom-0.13.0/src/miorom/save/diff_hunter.py +175 -0
  180. miorom-0.13.0/src/miorom/save/slots.py +89 -0
  181. miorom-0.13.0/src/miorom/scanner/__init__.py +61 -0
  182. miorom-0.13.0/src/miorom/scanner/crypto.py +200 -0
  183. miorom-0.13.0/src/miorom/scanner/deep.py +474 -0
  184. miorom-0.13.0/src/miorom/scanner/inspector.py +281 -0
  185. miorom-0.13.0/src/miorom/scanner/pattern.py +288 -0
  186. miorom-0.13.0/src/miorom/scanner/table_detector.py +497 -0
  187. miorom-0.13.0/src/miorom/scanner/triage.py +242 -0
  188. miorom-0.13.0/src/miorom/scanner/xref.py +357 -0
  189. miorom-0.13.0/src/miorom/script/__init__.py +105 -0
  190. miorom-0.13.0/src/miorom/script/archeology.py +109 -0
  191. miorom-0.13.0/src/miorom/script/ast.py +294 -0
  192. miorom-0.13.0/src/miorom/script/branch.py +346 -0
  193. miorom-0.13.0/src/miorom/script/compiler.py +166 -0
  194. miorom-0.13.0/src/miorom/script/control_flow.py +161 -0
  195. miorom-0.13.0/src/miorom/script/decompiler.py +205 -0
  196. miorom-0.13.0/src/miorom/script/engine.py +283 -0
  197. miorom-0.13.0/src/miorom/script/ir.py +81 -0
  198. miorom-0.13.0/src/miorom/script/lifter.py +431 -0
  199. miorom-0.13.0/src/miorom/script/opcode.py +84 -0
  200. miorom-0.13.0/src/miorom/script/paging_weaver.py +137 -0
  201. miorom-0.13.0/src/miorom/script/repacker.py +212 -0
  202. miorom-0.13.0/src/miorom/script/splicer.py +97 -0
  203. miorom-0.13.0/src/miorom/script/vm.py +261 -0
  204. miorom-0.13.0/src/miorom/script/vm_profiler.py +234 -0
  205. miorom-0.13.0/src/miorom/security.py +39 -0
  206. miorom-0.13.0/src/miorom/signature_db.py +140 -0
  207. miorom-0.13.0/src/miorom/text/__init__.py +78 -0
  208. miorom-0.13.0/src/miorom/text/aligner.py +166 -0
  209. miorom-0.13.0/src/miorom/text/bilingual_bridge.py +136 -0
  210. miorom-0.13.0/src/miorom/text/charmap.py +112 -0
  211. miorom-0.13.0/src/miorom/text/charmap_miner.py +147 -0
  212. miorom-0.13.0/src/miorom/text/dte_miner.py +142 -0
  213. miorom-0.13.0/src/miorom/text/font_builder.py +124 -0
  214. miorom-0.13.0/src/miorom/text/metrics_measurer.py +144 -0
  215. miorom-0.13.0/src/miorom/text/paginator.py +129 -0
  216. miorom-0.13.0/src/miorom/text/pipeline.py +216 -0
  217. miorom-0.13.0/src/miorom/text/pixel_wrapper.py +138 -0
  218. miorom-0.13.0/src/miorom/text/po_handler.py +254 -0
  219. miorom-0.13.0/src/miorom/text/relative_search.py +211 -0
  220. miorom-0.13.0/src/miorom/text/sanitizer.py +122 -0
  221. miorom-0.13.0/src/miorom/text/tag_validator.py +101 -0
  222. miorom-0.13.0/src/miorom/text/tags.py +61 -0
  223. miorom-0.13.0/src/miorom/text/template.py +47 -0
  224. miorom-0.13.0/src/miorom/text/textbox_sim.py +229 -0
  225. miorom-0.13.0/src/miorom/text/tokenizer.py +148 -0
  226. miorom-0.13.0/src/miorom/text/transcoder.py +172 -0
  227. miorom-0.13.0/src/miorom/text/transmuter.py +83 -0
  228. miorom-0.13.0/src/miorom/text/ttf_compiler.py +169 -0
  229. miorom-0.13.0/src/miorom/text/vwf.py +200 -0
  230. miorom-0.13.0/src/miorom/text/vwf_injector.py +149 -0
  231. miorom-0.13.0/src/miorom/text/wrapper.py +66 -0
  232. miorom-0.13.0/src/miorom.egg-info/PKG-INFO +326 -0
  233. miorom-0.13.0/src/miorom.egg-info/SOURCES.txt +351 -0
  234. miorom-0.13.0/src/miorom.egg-info/dependency_links.txt +1 -0
  235. miorom-0.13.0/src/miorom.egg-info/entry_points.txt +2 -0
  236. miorom-0.13.0/src/miorom.egg-info/requires.txt +5 -0
  237. miorom-0.13.0/src/miorom.egg-info/top_level.txt +1 -0
  238. miorom-0.13.0/tests/test_advanced_domains.py +149 -0
  239. miorom-0.13.0/tests/test_aligner.py +65 -0
  240. miorom-0.13.0/tests/test_archive_vfs.py +69 -0
  241. miorom-0.13.0/tests/test_asm.py +78 -0
  242. miorom-0.13.0/tests/test_asm_snippet.py +68 -0
  243. miorom-0.13.0/tests/test_audio.py +49 -0
  244. miorom-0.13.0/tests/test_audio_sseq.py +60 -0
  245. miorom-0.13.0/tests/test_auto_paginator.py +68 -0
  246. miorom-0.13.0/tests/test_auto_relocator.py +134 -0
  247. miorom-0.13.0/tests/test_bank_crosser.py +79 -0
  248. miorom-0.13.0/tests/test_bank_expander.py +95 -0
  249. miorom-0.13.0/tests/test_batch3_text_script_pointers.py +173 -0
  250. miorom-0.13.0/tests/test_batch4_runtime_and_safety.py +252 -0
  251. miorom-0.13.0/tests/test_benchmarks.py +16 -0
  252. miorom-0.13.0/tests/test_bilingual_bridge.py +85 -0
  253. miorom-0.13.0/tests/test_binary.py +50 -0
  254. miorom-0.13.0/tests/test_binary_struct_dogfooding.py +148 -0
  255. miorom-0.13.0/tests/test_buffer_analyzer.py +81 -0
  256. miorom-0.13.0/tests/test_buffer_mapper.py +106 -0
  257. miorom-0.13.0/tests/test_bytecode_branch_scanner.py +116 -0
  258. miorom-0.13.0/tests/test_carver.py +62 -0
  259. miorom-0.13.0/tests/test_cascading_archive.py +95 -0
  260. miorom-0.13.0/tests/test_compression.py +97 -0
  261. miorom-0.13.0/tests/test_compression_and_asm_primitives.py +95 -0
  262. miorom-0.13.0/tests/test_compression_heuristic.py +57 -0
  263. miorom-0.13.0/tests/test_control_flow.py +36 -0
  264. miorom-0.13.0/tests/test_control_tag_sanitizer.py +68 -0
  265. miorom-0.13.0/tests/test_cross_region_porter.py +139 -0
  266. miorom-0.13.0/tests/test_crypto_xref_bindiff.py +148 -0
  267. miorom-0.13.0/tests/test_csv_batch.py +58 -0
  268. miorom-0.13.0/tests/test_disasm_and_lifter.py +200 -0
  269. miorom-0.13.0/tests/test_dte.py +48 -0
  270. miorom-0.13.0/tests/test_elf_injector.py +459 -0
  271. miorom-0.13.0/tests/test_encoding_transmuter.py +38 -0
  272. miorom-0.13.0/tests/test_exceptions.py +30 -0
  273. miorom-0.13.0/tests/test_font_builder.py +55 -0
  274. miorom-0.13.0/tests/test_framework.py +130 -0
  275. miorom-0.13.0/tests/test_gdb_client.py +52 -0
  276. miorom-0.13.0/tests/test_gdb_scanner.py +66 -0
  277. miorom-0.13.0/tests/test_global_xref.py +38 -0
  278. miorom-0.13.0/tests/test_graphics.py +99 -0
  279. miorom-0.13.0/tests/test_graphics_mdec.py +33 -0
  280. miorom-0.13.0/tests/test_heap_builder_and_vlq.py +71 -0
  281. miorom-0.13.0/tests/test_helpers.py +90 -0
  282. miorom-0.13.0/tests/test_heuristic_dissector.py +123 -0
  283. miorom-0.13.0/tests/test_hex_diff_and_template.py +37 -0
  284. miorom-0.13.0/tests/test_image_bridge.py +33 -0
  285. miorom-0.13.0/tests/test_instruction_scanner.py +208 -0
  286. miorom-0.13.0/tests/test_integrity.py +162 -0
  287. miorom-0.13.0/tests/test_jump_table.py +128 -0
  288. miorom-0.13.0/tests/test_kwargs.py +306 -0
  289. miorom-0.13.0/tests/test_library_enhancements.py +437 -0
  290. miorom-0.13.0/tests/test_link.py +235 -0
  291. miorom-0.13.0/tests/test_literal_relocator.py +87 -0
  292. miorom-0.13.0/tests/test_master_table.py +56 -0
  293. miorom-0.13.0/tests/test_memory_and_signatures.py +47 -0
  294. miorom-0.13.0/tests/test_metrics_and_tags.py +72 -0
  295. miorom-0.13.0/tests/test_nds.py +179 -0
  296. miorom-0.13.0/tests/test_nftr.py +34 -0
  297. miorom-0.13.0/tests/test_overlay_mapper.py +58 -0
  298. miorom-0.13.0/tests/test_paging_weaver.py +52 -0
  299. miorom-0.13.0/tests/test_patch.py +64 -0
  300. miorom-0.13.0/tests/test_patch_writer.py +47 -0
  301. miorom-0.13.0/tests/test_patch_writer_txn.py +109 -0
  302. miorom-0.13.0/tests/test_pattern_scanner.py +76 -0
  303. miorom-0.13.0/tests/test_pipeline.py +78 -0
  304. miorom-0.13.0/tests/test_platforms.py +100 -0
  305. miorom-0.13.0/tests/test_platforms_cdrom.py +205 -0
  306. miorom-0.13.0/tests/test_platforms_gb.py +36 -0
  307. miorom-0.13.0/tests/test_platforms_gba_iso.py +109 -0
  308. miorom-0.13.0/tests/test_platforms_gc.py +110 -0
  309. miorom-0.13.0/tests/test_platforms_md.py +77 -0
  310. miorom-0.13.0/tests/test_platforms_n64.py +82 -0
  311. miorom-0.13.0/tests/test_platforms_snes_psx.py +95 -0
  312. miorom-0.13.0/tests/test_po_handler.py +69 -0
  313. miorom-0.13.0/tests/test_pointer.py +32 -0
  314. miorom-0.13.0/tests/test_pointer_remapper.py +76 -0
  315. miorom-0.13.0/tests/test_project_workflow.py +82 -0
  316. miorom-0.13.0/tests/test_property_based.py +128 -0
  317. miorom-0.13.0/tests/test_psx_str_xa.py +91 -0
  318. miorom-0.13.0/tests/test_record_builder.py +46 -0
  319. miorom-0.13.0/tests/test_relative_search.py +58 -0
  320. miorom-0.13.0/tests/test_rom_unpack_repack.py +390 -0
  321. miorom-0.13.0/tests/test_save.py +62 -0
  322. miorom-0.13.0/tests/test_scanner.py +112 -0
  323. miorom-0.13.0/tests/test_scanner_deep.py +193 -0
  324. miorom-0.13.0/tests/test_schema.py +150 -0
  325. miorom-0.13.0/tests/test_script.py +91 -0
  326. miorom-0.13.0/tests/test_script_ast.py +72 -0
  327. miorom-0.13.0/tests/test_script_decompiler.py +101 -0
  328. miorom-0.13.0/tests/test_script_repacker.py +64 -0
  329. miorom-0.13.0/tests/test_script_splicer.py +72 -0
  330. miorom-0.13.0/tests/test_security_extract_path.py +53 -0
  331. miorom-0.13.0/tests/test_slack.py +45 -0
  332. miorom-0.13.0/tests/test_slot_pointerizer.py +89 -0
  333. miorom-0.13.0/tests/test_sm83_snippet.py +132 -0
  334. miorom-0.13.0/tests/test_speculative_carver.py +36 -0
  335. miorom-0.13.0/tests/test_streaming_contract.py +34 -0
  336. miorom-0.13.0/tests/test_string_pipeline.py +199 -0
  337. miorom-0.13.0/tests/test_struct_profiler.py +63 -0
  338. miorom-0.13.0/tests/test_symbol_map.py +55 -0
  339. miorom-0.13.0/tests/test_symbolmap_import.py +72 -0
  340. miorom-0.13.0/tests/test_table_detector.py +105 -0
  341. miorom-0.13.0/tests/test_tags.py +30 -0
  342. miorom-0.13.0/tests/test_textbox_sim.py +51 -0
  343. miorom-0.13.0/tests/test_tilesheet.py +94 -0
  344. miorom-0.13.0/tests/test_toc_and_dual_table.py +114 -0
  345. miorom-0.13.0/tests/test_transcoder.py +72 -0
  346. miorom-0.13.0/tests/test_triage.py +56 -0
  347. miorom-0.13.0/tests/test_ttf_compiler.py +64 -0
  348. miorom-0.13.0/tests/test_universal_hook_and_cheat.py +223 -0
  349. miorom-0.13.0/tests/test_v2_finalization.py +70 -0
  350. miorom-0.13.0/tests/test_v3_library_contract.py +195 -0
  351. miorom-0.13.0/tests/test_vm_profiler.py +73 -0
  352. miorom-0.13.0/tests/test_vwf.py +45 -0
  353. miorom-0.13.0/tests/test_vwf_injector.py +75 -0
miorom-0.13.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SuchMioko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
miorom-0.13.0/PKG-INFO ADDED
@@ -0,0 +1,326 @@
1
+ Metadata-Version: 2.4
2
+ Name: miorom
3
+ Version: 0.13.0
4
+ Summary: A Python library for ROM hacking and game reverse engineering
5
+ Author-email: MiokoTech <miokotech@gmail.com>
6
+ License: MIT
7
+ Keywords: romhacking,rom-hacking,game-hacking,reverse-engineering,game-reverse-engineering,binary-analysis,game-localization,fan-translation,game-modding,binary-patching,binary-parser,decompilation,disassembler,bytecode-vm,elf-linker,code-injection,nintendo,wii,gamecube,nintendo-ds,nds,gba,gameboy-advance,gameboy,n64,nintendo-64,snes,super-nintendo,playstation,ps1,psx,sega-genesis,megadrive,powerpc,mips,arm,split-pointer,code-cave,trampoline-hook,dol-executable,iso9660,u8-archive,narc,sdat,sseq,brfnt,nftr,tpl-texture,tim-image,toc-archive,dual-table,lz10,lz11,yaz0,rle-compression,huffman,ips-patch,bps-patch,xdelta,rom-patcher,variable-width-font,vwf,font-metrics,word-wrapper,textbox-simulator,string-scanner,pointer-table,charmap,ttf-compiler,dolphin-emulator,gdb-stub,memory-inspection,live-patching,shannon-entropy
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
11
+ Classifier: Topic :: Software Development :: Disassemblers
12
+ Classifier: Topic :: Games/Entertainment
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.9
15
+ Classifier: Programming Language :: Python :: 3.10
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
19
+ Classifier: Programming Language :: Python :: 3.14
20
+ Requires-Python: >=3.9
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0; extra == "dev"
25
+ Requires-Dist: hypothesis>=6.0; extra == "dev"
26
+ Requires-Dist: pytest-benchmark>=4.0; extra == "dev"
27
+ Dynamic: license-file
28
+
29
+ # MioROM
30
+
31
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
32
+ [![Python: 3.10+](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://www.python.org/)
33
+ [![Tests: 468 Passed](https://img.shields.io/badge/Tests-468%20Passed-brightgreen.svg)](tests/)
34
+ [![Platforms: Multi-Console](https://img.shields.io/badge/Platforms-NDS%20%7C%20Wii%20%7C%20GC%20%7C%20N64%20%7C%20GBA%20%7C%20SNES%20%7C%20PS1-orange.svg)](docs/API_REFERENCE.md)
35
+
36
+ **MioROM** is an advanced, modular Python framework and low-level primitive library for ROM hacking, game localization engineering, and binary reverse engineering.
37
+
38
+ Designed with a **library-first philosophy** (analogous to `ndspy` and `pwntools`), MioROM provides foundational building blocks, platform container parsers, instruction scanners, and pointer recalculation engines required to build reliable, reproducible game extraction, translation, and repacking pipelines in pure Python.
39
+
40
+ ---
41
+
42
+ ## Documentation
43
+
44
+ - [API Reference and Architecture Guide](docs/API_REFERENCE.md) - Comprehensive index of all subpackages and 60+ core classes.
45
+ - [Binary and Assembly Primitives Guide](docs/BINARY_PRIMITIVES.md) - Technical guide for low-level patching, micro-assembly, struct serialization, and symbol mapping.
46
+ - [Command-Line Interface (CLI) Reference](docs/CLI_REFERENCE.md) - Complete manual for `miorom` terminal tools (`unpack`, `repack`, `inspect`, `scan`, etc.).
47
+ - [Console Platform & Format Reference](docs/PLATFORMS.md) - Deep dive into NDS, Wii/GC, PS1, N64, GBA, SNES, and Mega Drive formats.
48
+ - [End-to-End Localization Workflow Guide](docs/WORKFLOW_GUIDE.md) - 6-phase walkthrough from untouched ROM to distributed patch.
49
+ - [Adding New Platforms (Plugin Guide)](docs/PLUGIN_GUIDE.md) - Registering custom `BaseRomHandler` implementations without forking MioROM.
50
+ - [Library Contracts](docs/LIBRARY_CONTRACTS.md) - Serialization, streaming, structured exceptions, patch composition, pipeline extension, and structural-typing contracts.
51
+ - [Security Guide](docs/SECURITY.md) - Path traversal / zip-slip protection and the checklist for safely extracting untrusted archives.
52
+
53
+ ---
54
+
55
+ ## Installation
56
+
57
+ ### From GitHub
58
+
59
+ Install directly using `pip`:
60
+
61
+ ```bash
62
+ pip install git+https://github.com/MiokoTech/miorom.git
63
+ ```
64
+
65
+ ### From Source (Development Mode)
66
+
67
+ ```bash
68
+ git clone https://github.com/MiokoTech/miorom.git
69
+ cd miorom
70
+ pip install -e .
71
+ ```
72
+
73
+ To run the verification test suite:
74
+
75
+ ```bash
76
+ pytest
77
+ ```
78
+
79
+ ---
80
+
81
+ ## Platform Support Matrix
82
+
83
+ MioROM provides native parsers, serializers, and filesystem handlers across multiple retro and modern console architectures without external binary dependencies:
84
+
85
+ | Platform | Containers & Filesystems | Executables & Formats | Text, Fonts & Compression |
86
+ | :--- | :--- | :--- | :--- |
87
+ | **Nintendo DS** | `.nds` ROM, NARC (`.narc`) archives, FAT | ARM9/ARM7 binaries, overlays | NFTR fonts, SDAT audio, LZ10, LZ11, RLE |
88
+ | **Nintendo Wii / GameCube** | Optical Disc (`.iso`, `.gcm`), U8 (`.arc`, `.szs`), FST | DOL executables, ELF objects | BRFNT fonts, TPL textures, Yaz0 |
89
+ | **Game Boy Advance** | `.gba` ROM, Cartridge headers | ARM/Thumb relative branches | BGR555 palettes, 4bpp tiles, Complement CRC |
90
+ | **Nintendo 64** | `.z64` (BE), `.v64` (Swapped), `.n64` (LE) | MIPS split-pointer scanner | IPL3 CIC checksum verification (all variants) |
91
+ | **Super Nintendo** | `.sfc`, `.smc` (LoROM / HiROM / ExHiROM) | 65816 memory mapping | 2bpp/4bpp planar tiles, 16-bit complement CRC |
92
+ | **PlayStation 1** | Optical Disc (ISO9660, CUE/BIN multi-track) | PS-X EXE, STR video, CD-XA audio | TIM textures, MDEC video bitstreams, EDC/ECC |
93
+ | **Sega Genesis / Mega Drive** | `.md`, `.bin`, `.smd` (Interleaved de-interleaving) | 68000 header & SRAM registers | 16-bit big-endian ROM checksum recalculation |
94
+
95
+ ---
96
+
97
+ ## Core Pillars & Capabilities
98
+
99
+ ### 1. Low-Level Binary Manipulation & Patching
100
+ - **`BinaryReader` & `BinaryWriter`**: High-performance stream I/O with dynamic endianness switching (`<` / `>`), temporary context seeking (`with reader.at(offset): ...`), and boundary alignment padding.
101
+ - **`PatchWriter`**: Fluent binary patch emitter with automatic cursor tracking, range replacements, and instant IPS distribution patch generation.
102
+ - **`RecordBuilder`**: Fluent struct writer constructing binary headers and packed records with fixed-width strings, Pascal strings, and memory alignment without brittle format strings.
103
+ - **`RelocatableBuffer`**: Immutable pristine snapshot buffer preventing offset drift across chained text edits, recalculating all registered pointers in a single pass.
104
+ - **`HexDiffHighlighter`**: Terminal verification tool rendering colorized ANSI hex diffs (green for additions, red for original bytes) before writing changes to disk.
105
+ - **`SymbolMap`**: Memory and ROM address annotator with export to No$GBA (`.sym`), Dolphin (`.map`), and Ghidra CSV labels.
106
+
107
+ ### 2. Disassembly, Assembly & Static Analysis
108
+ - **`UniversalDisassembler`**: Multi-architecture disassembler supporting PowerPC, ARM32, Thumb-16, and MIPS without native C dependencies.
109
+ - **`AsmSnippet`**: Pure-Python micro-assembler for compiling small ARM32 and MIPS instruction sequences (branches, loads, calls, returns) without external toolchains.
110
+ - **`PPCInstructionScanner` & `MIPSInstructionScanner`**: Searches binary executables for split-pointer load pairs (`lis` + `addi` / `lui` + `addiu`) and patches them in-place.
111
+ - **`CodeCaveFinder` & `TrampolineHook`**: Locates contiguous unused padding bytes (`0x00`/`0xFF`) and constructs 5-instruction trampolines preserving original opcodes.
112
+ - **`AntiPiracyBypasser`**: Scans and applies surgical patches to NDS cartridge checks, checksum verification loops, and PowerPC integrity branches.
113
+
114
+ ### 3. Pointer Tables & Relocation Engines
115
+ - **`PointerTable` & `PointerEntry`**: Manages absolute, relative, segmented, and flagged pointers (`offset + flags`) with 1:1 relocation.
116
+ - **`MultiLevelPointerTable`**: Resolves cascading multi-tier pointer hierarchies (Chapter -> Scene -> Text Block).
117
+ - **`ByteOffsetMapper`**: Computes exact 1:1 address relocation using Longest Common Subsequence (LCS) alignment when text data expands.
118
+ - **`FarPointerRelocator` & `RomLayoutExpander`**: Relocates binary assets into expanded ROM memory banks (GBA 32MB, N64 64MB) with automatic hardware checksum repairs.
119
+
120
+ ### 4. Text, Typography & Localization Engineering
121
+ - **`PixelWordWrapper` & `FontMetrics`**: Measures dialogue lines against true on-screen pixel boundaries for Variable-Width Fonts (VWF), preventing textbox overflows.
122
+ - **`TrieTranscoder`**: High-performance greedy longest-prefix transcoder for Dual-Tile Encoding (DTE), Byte-Pair Encoding (BPE), and custom `.tbl` character tables.
123
+ - **`GameTextTemplate`**: Bidirectional dialogue template engine with dynamic control tags and reverse parameter extraction.
124
+ - **`StringAligner`**: Correlates and transfers translated strings between regional releases (e.g. Japanese v1.0 to USA v1.1) despite shifted or inserted rows.
125
+ - **`PoHandler`**: Two-way bridge connecting game text to GNU gettext PO files for standard translation toolchains (Weblate, Crowdin, Poedit).
126
+
127
+ ### 5. Filesystem, Containers & Disc Images
128
+ - **`RomManager`**: Unified auto-detecting ROM unpacker and repacker for NDS, GameCube/Wii ISO, U8 Archive, NARC, ISO9660, and Cartridges.
129
+ - **`ISO9660` & `CueBinDisc`**: Pure-Python optical disc filesystem parser and injector with LBA sector reallocation and ECMA-130 EDC/ECC recalculation.
130
+ - **`VirtualFileSystem` (VFS)**: In-memory hierarchical filesystem layer allowing transparent archive mounting, file browsing, and in-place node editing.
131
+ - **`FstInjector`**: In-place GameCube and Wii File System Table modifier without external tools like `wit` or `gcit`.
132
+
133
+ ### 6. Compression, Audio & Graphics Codecs
134
+ - **Nintendo BIOS Compression**: LZ10 (0x10), LZ11 (0x11), RLE (0x30), and Huffman 4/8-bit (0x24, 0x28).
135
+ - **Nintendo Yaz0**: Ubiquitous compression across N64, GameCube, Wii, and Switch.
136
+ - **Tile Graphics Engine**: 1bpp, 2bpp (GB/NES), 4bpp chunky/planar (SNES/GBA/NDS), and 8bpp codecs with `TileReducer` deduplication.
137
+ - **Pillow / PNG Bridge (`ImageBridge`)**: Two-way converter between game tilemaps/palettes and standard PNG images.
138
+ - **Audio & Video**: PlayStation CD-XA ADPCM decoder, Nintendo DS SDAT sound container, and PS1 MDEC / STR movie demuxer.
139
+
140
+ ---
141
+
142
+ ## Quickstart Guide
143
+
144
+ ### 1. Universal ROM Unpack and Repack
145
+
146
+ MioROM automatically detects container and ROM formats from magic headers, unpacks system binaries to `sys/` and assets to `root/`, and repacks with hardware checksum fixes:
147
+
148
+ ```python
149
+ from miorom import unpack_rom, repack_rom
150
+
151
+ # Unpack any supported ROM (NDS, ISO, NARC, U8 ARC, Cartridge)
152
+ meta = unpack_rom("game.nds", "unpacked/")
153
+ print(f"Format: {meta['format']}, Files: {meta.get('file_count')}")
154
+
155
+ # Modify assets in unpacked/root/ or binaries in unpacked/sys/...
156
+
157
+ # Repack cleanly into a compliant, bootable ROM
158
+ repack_rom("unpacked/", "game_patched.nds")
159
+ ```
160
+
161
+ ### 2. Surgical Binary Patching with `PatchWriter` and `HexDiffHighlighter`
162
+
163
+ Apply precise in-memory modifications, verify the binary changes visually, and export standard distribution patches:
164
+
165
+ ```python
166
+ from miorom.patch import PatchWriter
167
+ from miorom.core import HexDiffHighlighter
168
+
169
+ rom_data = open("arm9.bin", "rb").read()
170
+ writer = PatchWriter(rom_data)
171
+
172
+ # Apply contiguous writes and pointer updates
173
+ writer.write_at(0x00014000, b"TRANSLATED_TEXT\x00")
174
+ writer.write_u32_at(0x00010004, 0x02014000, endian="<")
175
+
176
+ patched_data = writer.apply()
177
+
178
+ # Visually verify modified bytes in terminal
179
+ HexDiffHighlighter.print_diff(
180
+ original=rom_data,
181
+ modified=patched_data,
182
+ offset=0x00010000,
183
+ size=32,
184
+ use_color=True,
185
+ )
186
+
187
+ # Export as an IPS distribution patch
188
+ with open("patch.ips", "wb") as f:
189
+ f.write(writer.build_ips())
190
+ ```
191
+
192
+ ### 3. Assembling Micro-Assembly Routines with `AsmSnippet`
193
+
194
+ Emit standalone ARM32 or MIPS routines without requiring external cross-compiler toolchains:
195
+
196
+ ```python
197
+ from miorom.asm import AsmSnippet
198
+
199
+ # Assemble an ARM32 hook routine
200
+ arm = AsmSnippet.arm("<")
201
+ arm.push(["r4", "r5", "lr"])
202
+ arm.mov_imm("r0", 42)
203
+ arm.add_imm("r1", "r0", 10)
204
+ arm.bx("lr")
205
+ machine_code = arm.emit()
206
+
207
+ # Output: 20 bytes of ARM32 machine code ready for code cave injection
208
+ ```
209
+
210
+ ### 4. Serializing Structs and Records with `RecordBuilder`
211
+
212
+ Construct binary table records, fixed-width entries, and headers cleanly:
213
+
214
+ ```python
215
+ from miorom.core import RecordBuilder
216
+
217
+ entry = (
218
+ RecordBuilder(endian="<")
219
+ .u32(0x1001) # Item ID
220
+ .fixed_str("Elixir", length=16, pad_byte=0x00) # Fixed-length string
221
+ .pascal_str("Fully restores HP/MP", length_size=1) # Pascal string
222
+ .u16(999) # Price
223
+ .align(4) # Word alignment
224
+ .build()
225
+ )
226
+ ```
227
+
228
+ ### 5. String Relocation and Pointer Recalculation
229
+
230
+ Safely expand game dialogue strings while recalculating internal pointer tables via LCS alignment:
231
+
232
+ ```python
233
+ from miorom import RelocatableBuffer
234
+
235
+ # Load a script segment
236
+ buf = RelocatableBuffer.load("dialogue.bin")
237
+
238
+ # Register pointer offsets and dynamic size headers
239
+ buf.register_anchored_field(pos=0x00, size=2, anchor_type="size_delta")
240
+ buf.register_pointer(pos=0x04, size=2, endian="<")
241
+ buf.register_pointer(pos=0x06, size=2, endian="<")
242
+
243
+ # Perform chained text replacements safely
244
+ buf.replace_text("Hello", "Good morning, adventurer!")
245
+ buf.replace_text("Item found.", "You have obtained a rare treasure!")
246
+
247
+ # Recalculate all registered pointers in one pass
248
+ report = buf.relocate_all()
249
+ buf.save("dialogue_expanded.bin")
250
+ ```
251
+
252
+ ### 6. Variable-Width Font (VWF) Word Wrapping
253
+
254
+ Validate and wrap dialogue lines using exact on-screen pixel metrics instead of naive character counts:
255
+
256
+ ```python
257
+ from miorom.text import BitmapFont, PixelWordWrapper
258
+
259
+ # Initialize font with proportional glyph metrics
260
+ font = BitmapFont(default_height=12, default_advance=8)
261
+ font.set_character_advance("i", 3)
262
+ font.set_character_advance("W", 12)
263
+
264
+ wrapper = PixelWordWrapper(font=font, max_pixel_width=220, max_lines=3)
265
+ result = wrapper.wrap("Welcome to the kingdom of Norad! We hope your journey was pleasant.")
266
+
267
+ print(f"Total lines: {len(result.lines)}, Fits in textbox: {result.fits}")
268
+ for line in result.lines:
269
+ print(f"Line ({line.pixel_width}px): {line.text}")
270
+ ```
271
+
272
+ ---
273
+
274
+ ## Architecture and Source Layout
275
+
276
+ ```text
277
+ miorom/
278
+ ├── pyproject.toml # Build system and dependency specifications
279
+ ├── README.md # Project overview and quickstart
280
+ ├── docs/
281
+ │ ├── API_REFERENCE.md # Comprehensive 60+ class API reference
282
+ │ ├── BINARY_PRIMITIVES.md # Low-level primitives developer guide
283
+ │ ├── CLI_REFERENCE.md # Terminal command manual
284
+ │ ├── PLATFORMS.md # Per-console format specifications
285
+ │ ├── WORKFLOW_GUIDE.md # 6-phase localization pipeline walkthrough
286
+ │ ├── PLUGIN_GUIDE.md # Custom BaseRomHandler registration guide
287
+ │ ├── LIBRARY_CONTRACTS.md # Serialization, streaming, extensibility contracts
288
+ │ └── SECURITY.md # Untrusted-archive extraction safety guide
289
+ ├── src/miorom/
290
+ │ ├── core/ # Stream I/O, Structs, Relocation, SymbolMap, HexDiff
291
+ │ ├── patch/ # IPS, BPS, Xdelta, and PatchWriter
292
+ │ ├── asm/ # Universal disassembler, AsmSnippet, Hooks, Anti-piracy
293
+ │ ├── script/ # ScriptVM, AST decompiler, IR lifter, Repackers
294
+ │ ├── text/ # VWF wrapper, CharMap, DTE, PO handler, Aligner
295
+ │ ├── platforms/ # NDS, Wii/GC, N64, GBA, GB, SNES, PSX, MD, ISO9660, CD-ROM
296
+ │ ├── graphics/ # Tile codecs (1-8bpp), Palettes, TileReducer, ImageBridge
297
+ │ ├── compression/ # LZ10, LZ11, RLE, Yaz0, Huffman, Heuristic LZSS
298
+ │ ├── audio/ # SDAT, IMA-ADPCM, CD-XA audio decoders and WAV builders
299
+ │ ├── save/ # Checksum calculators (CRC16/32, Fletcher) and DualSlotSave
300
+ │ ├── archive/ # Container unpackers and in-memory VirtualFileSystem (VFS)
301
+ │ ├── link/ # In-ROM ELF32 object linker and cave injector
302
+ │ ├── rom/ # Universal ROM unpacker and repacker manager
303
+ │ ├── scanner/ # Deep signature inspector, entropy profiling, crypto scans
304
+ │ └── cli/ # Command-line interface commands
305
+ └── tests/ # Pytest verification suite (405 unit tests)
306
+ ```
307
+
308
+ ---
309
+
310
+ ## Contributing & Testing
311
+
312
+ Contributions are welcome. Please ensure that all changes include comprehensive unit tests and pass the entire test suite:
313
+
314
+ ```bash
315
+ # Run all unit tests
316
+ pytest
317
+
318
+ # Run tests with coverage reporting
319
+ pytest --cov=miorom tests/
320
+ ```
321
+
322
+ ---
323
+
324
+ ## License
325
+
326
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
@@ -0,0 +1,298 @@
1
+ # MioROM
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
4
+ [![Python: 3.10+](https://img.shields.io/badge/Python-3.10%2B-blue.svg)](https://www.python.org/)
5
+ [![Tests: 468 Passed](https://img.shields.io/badge/Tests-468%20Passed-brightgreen.svg)](tests/)
6
+ [![Platforms: Multi-Console](https://img.shields.io/badge/Platforms-NDS%20%7C%20Wii%20%7C%20GC%20%7C%20N64%20%7C%20GBA%20%7C%20SNES%20%7C%20PS1-orange.svg)](docs/API_REFERENCE.md)
7
+
8
+ **MioROM** is an advanced, modular Python framework and low-level primitive library for ROM hacking, game localization engineering, and binary reverse engineering.
9
+
10
+ Designed with a **library-first philosophy** (analogous to `ndspy` and `pwntools`), MioROM provides foundational building blocks, platform container parsers, instruction scanners, and pointer recalculation engines required to build reliable, reproducible game extraction, translation, and repacking pipelines in pure Python.
11
+
12
+ ---
13
+
14
+ ## Documentation
15
+
16
+ - [API Reference and Architecture Guide](docs/API_REFERENCE.md) - Comprehensive index of all subpackages and 60+ core classes.
17
+ - [Binary and Assembly Primitives Guide](docs/BINARY_PRIMITIVES.md) - Technical guide for low-level patching, micro-assembly, struct serialization, and symbol mapping.
18
+ - [Command-Line Interface (CLI) Reference](docs/CLI_REFERENCE.md) - Complete manual for `miorom` terminal tools (`unpack`, `repack`, `inspect`, `scan`, etc.).
19
+ - [Console Platform & Format Reference](docs/PLATFORMS.md) - Deep dive into NDS, Wii/GC, PS1, N64, GBA, SNES, and Mega Drive formats.
20
+ - [End-to-End Localization Workflow Guide](docs/WORKFLOW_GUIDE.md) - 6-phase walkthrough from untouched ROM to distributed patch.
21
+ - [Adding New Platforms (Plugin Guide)](docs/PLUGIN_GUIDE.md) - Registering custom `BaseRomHandler` implementations without forking MioROM.
22
+ - [Library Contracts](docs/LIBRARY_CONTRACTS.md) - Serialization, streaming, structured exceptions, patch composition, pipeline extension, and structural-typing contracts.
23
+ - [Security Guide](docs/SECURITY.md) - Path traversal / zip-slip protection and the checklist for safely extracting untrusted archives.
24
+
25
+ ---
26
+
27
+ ## Installation
28
+
29
+ ### From GitHub
30
+
31
+ Install directly using `pip`:
32
+
33
+ ```bash
34
+ pip install git+https://github.com/MiokoTech/miorom.git
35
+ ```
36
+
37
+ ### From Source (Development Mode)
38
+
39
+ ```bash
40
+ git clone https://github.com/MiokoTech/miorom.git
41
+ cd miorom
42
+ pip install -e .
43
+ ```
44
+
45
+ To run the verification test suite:
46
+
47
+ ```bash
48
+ pytest
49
+ ```
50
+
51
+ ---
52
+
53
+ ## Platform Support Matrix
54
+
55
+ MioROM provides native parsers, serializers, and filesystem handlers across multiple retro and modern console architectures without external binary dependencies:
56
+
57
+ | Platform | Containers & Filesystems | Executables & Formats | Text, Fonts & Compression |
58
+ | :--- | :--- | :--- | :--- |
59
+ | **Nintendo DS** | `.nds` ROM, NARC (`.narc`) archives, FAT | ARM9/ARM7 binaries, overlays | NFTR fonts, SDAT audio, LZ10, LZ11, RLE |
60
+ | **Nintendo Wii / GameCube** | Optical Disc (`.iso`, `.gcm`), U8 (`.arc`, `.szs`), FST | DOL executables, ELF objects | BRFNT fonts, TPL textures, Yaz0 |
61
+ | **Game Boy Advance** | `.gba` ROM, Cartridge headers | ARM/Thumb relative branches | BGR555 palettes, 4bpp tiles, Complement CRC |
62
+ | **Nintendo 64** | `.z64` (BE), `.v64` (Swapped), `.n64` (LE) | MIPS split-pointer scanner | IPL3 CIC checksum verification (all variants) |
63
+ | **Super Nintendo** | `.sfc`, `.smc` (LoROM / HiROM / ExHiROM) | 65816 memory mapping | 2bpp/4bpp planar tiles, 16-bit complement CRC |
64
+ | **PlayStation 1** | Optical Disc (ISO9660, CUE/BIN multi-track) | PS-X EXE, STR video, CD-XA audio | TIM textures, MDEC video bitstreams, EDC/ECC |
65
+ | **Sega Genesis / Mega Drive** | `.md`, `.bin`, `.smd` (Interleaved de-interleaving) | 68000 header & SRAM registers | 16-bit big-endian ROM checksum recalculation |
66
+
67
+ ---
68
+
69
+ ## Core Pillars & Capabilities
70
+
71
+ ### 1. Low-Level Binary Manipulation & Patching
72
+ - **`BinaryReader` & `BinaryWriter`**: High-performance stream I/O with dynamic endianness switching (`<` / `>`), temporary context seeking (`with reader.at(offset): ...`), and boundary alignment padding.
73
+ - **`PatchWriter`**: Fluent binary patch emitter with automatic cursor tracking, range replacements, and instant IPS distribution patch generation.
74
+ - **`RecordBuilder`**: Fluent struct writer constructing binary headers and packed records with fixed-width strings, Pascal strings, and memory alignment without brittle format strings.
75
+ - **`RelocatableBuffer`**: Immutable pristine snapshot buffer preventing offset drift across chained text edits, recalculating all registered pointers in a single pass.
76
+ - **`HexDiffHighlighter`**: Terminal verification tool rendering colorized ANSI hex diffs (green for additions, red for original bytes) before writing changes to disk.
77
+ - **`SymbolMap`**: Memory and ROM address annotator with export to No$GBA (`.sym`), Dolphin (`.map`), and Ghidra CSV labels.
78
+
79
+ ### 2. Disassembly, Assembly & Static Analysis
80
+ - **`UniversalDisassembler`**: Multi-architecture disassembler supporting PowerPC, ARM32, Thumb-16, and MIPS without native C dependencies.
81
+ - **`AsmSnippet`**: Pure-Python micro-assembler for compiling small ARM32 and MIPS instruction sequences (branches, loads, calls, returns) without external toolchains.
82
+ - **`PPCInstructionScanner` & `MIPSInstructionScanner`**: Searches binary executables for split-pointer load pairs (`lis` + `addi` / `lui` + `addiu`) and patches them in-place.
83
+ - **`CodeCaveFinder` & `TrampolineHook`**: Locates contiguous unused padding bytes (`0x00`/`0xFF`) and constructs 5-instruction trampolines preserving original opcodes.
84
+ - **`AntiPiracyBypasser`**: Scans and applies surgical patches to NDS cartridge checks, checksum verification loops, and PowerPC integrity branches.
85
+
86
+ ### 3. Pointer Tables & Relocation Engines
87
+ - **`PointerTable` & `PointerEntry`**: Manages absolute, relative, segmented, and flagged pointers (`offset + flags`) with 1:1 relocation.
88
+ - **`MultiLevelPointerTable`**: Resolves cascading multi-tier pointer hierarchies (Chapter -> Scene -> Text Block).
89
+ - **`ByteOffsetMapper`**: Computes exact 1:1 address relocation using Longest Common Subsequence (LCS) alignment when text data expands.
90
+ - **`FarPointerRelocator` & `RomLayoutExpander`**: Relocates binary assets into expanded ROM memory banks (GBA 32MB, N64 64MB) with automatic hardware checksum repairs.
91
+
92
+ ### 4. Text, Typography & Localization Engineering
93
+ - **`PixelWordWrapper` & `FontMetrics`**: Measures dialogue lines against true on-screen pixel boundaries for Variable-Width Fonts (VWF), preventing textbox overflows.
94
+ - **`TrieTranscoder`**: High-performance greedy longest-prefix transcoder for Dual-Tile Encoding (DTE), Byte-Pair Encoding (BPE), and custom `.tbl` character tables.
95
+ - **`GameTextTemplate`**: Bidirectional dialogue template engine with dynamic control tags and reverse parameter extraction.
96
+ - **`StringAligner`**: Correlates and transfers translated strings between regional releases (e.g. Japanese v1.0 to USA v1.1) despite shifted or inserted rows.
97
+ - **`PoHandler`**: Two-way bridge connecting game text to GNU gettext PO files for standard translation toolchains (Weblate, Crowdin, Poedit).
98
+
99
+ ### 5. Filesystem, Containers & Disc Images
100
+ - **`RomManager`**: Unified auto-detecting ROM unpacker and repacker for NDS, GameCube/Wii ISO, U8 Archive, NARC, ISO9660, and Cartridges.
101
+ - **`ISO9660` & `CueBinDisc`**: Pure-Python optical disc filesystem parser and injector with LBA sector reallocation and ECMA-130 EDC/ECC recalculation.
102
+ - **`VirtualFileSystem` (VFS)**: In-memory hierarchical filesystem layer allowing transparent archive mounting, file browsing, and in-place node editing.
103
+ - **`FstInjector`**: In-place GameCube and Wii File System Table modifier without external tools like `wit` or `gcit`.
104
+
105
+ ### 6. Compression, Audio & Graphics Codecs
106
+ - **Nintendo BIOS Compression**: LZ10 (0x10), LZ11 (0x11), RLE (0x30), and Huffman 4/8-bit (0x24, 0x28).
107
+ - **Nintendo Yaz0**: Ubiquitous compression across N64, GameCube, Wii, and Switch.
108
+ - **Tile Graphics Engine**: 1bpp, 2bpp (GB/NES), 4bpp chunky/planar (SNES/GBA/NDS), and 8bpp codecs with `TileReducer` deduplication.
109
+ - **Pillow / PNG Bridge (`ImageBridge`)**: Two-way converter between game tilemaps/palettes and standard PNG images.
110
+ - **Audio & Video**: PlayStation CD-XA ADPCM decoder, Nintendo DS SDAT sound container, and PS1 MDEC / STR movie demuxer.
111
+
112
+ ---
113
+
114
+ ## Quickstart Guide
115
+
116
+ ### 1. Universal ROM Unpack and Repack
117
+
118
+ MioROM automatically detects container and ROM formats from magic headers, unpacks system binaries to `sys/` and assets to `root/`, and repacks with hardware checksum fixes:
119
+
120
+ ```python
121
+ from miorom import unpack_rom, repack_rom
122
+
123
+ # Unpack any supported ROM (NDS, ISO, NARC, U8 ARC, Cartridge)
124
+ meta = unpack_rom("game.nds", "unpacked/")
125
+ print(f"Format: {meta['format']}, Files: {meta.get('file_count')}")
126
+
127
+ # Modify assets in unpacked/root/ or binaries in unpacked/sys/...
128
+
129
+ # Repack cleanly into a compliant, bootable ROM
130
+ repack_rom("unpacked/", "game_patched.nds")
131
+ ```
132
+
133
+ ### 2. Surgical Binary Patching with `PatchWriter` and `HexDiffHighlighter`
134
+
135
+ Apply precise in-memory modifications, verify the binary changes visually, and export standard distribution patches:
136
+
137
+ ```python
138
+ from miorom.patch import PatchWriter
139
+ from miorom.core import HexDiffHighlighter
140
+
141
+ rom_data = open("arm9.bin", "rb").read()
142
+ writer = PatchWriter(rom_data)
143
+
144
+ # Apply contiguous writes and pointer updates
145
+ writer.write_at(0x00014000, b"TRANSLATED_TEXT\x00")
146
+ writer.write_u32_at(0x00010004, 0x02014000, endian="<")
147
+
148
+ patched_data = writer.apply()
149
+
150
+ # Visually verify modified bytes in terminal
151
+ HexDiffHighlighter.print_diff(
152
+ original=rom_data,
153
+ modified=patched_data,
154
+ offset=0x00010000,
155
+ size=32,
156
+ use_color=True,
157
+ )
158
+
159
+ # Export as an IPS distribution patch
160
+ with open("patch.ips", "wb") as f:
161
+ f.write(writer.build_ips())
162
+ ```
163
+
164
+ ### 3. Assembling Micro-Assembly Routines with `AsmSnippet`
165
+
166
+ Emit standalone ARM32 or MIPS routines without requiring external cross-compiler toolchains:
167
+
168
+ ```python
169
+ from miorom.asm import AsmSnippet
170
+
171
+ # Assemble an ARM32 hook routine
172
+ arm = AsmSnippet.arm("<")
173
+ arm.push(["r4", "r5", "lr"])
174
+ arm.mov_imm("r0", 42)
175
+ arm.add_imm("r1", "r0", 10)
176
+ arm.bx("lr")
177
+ machine_code = arm.emit()
178
+
179
+ # Output: 20 bytes of ARM32 machine code ready for code cave injection
180
+ ```
181
+
182
+ ### 4. Serializing Structs and Records with `RecordBuilder`
183
+
184
+ Construct binary table records, fixed-width entries, and headers cleanly:
185
+
186
+ ```python
187
+ from miorom.core import RecordBuilder
188
+
189
+ entry = (
190
+ RecordBuilder(endian="<")
191
+ .u32(0x1001) # Item ID
192
+ .fixed_str("Elixir", length=16, pad_byte=0x00) # Fixed-length string
193
+ .pascal_str("Fully restores HP/MP", length_size=1) # Pascal string
194
+ .u16(999) # Price
195
+ .align(4) # Word alignment
196
+ .build()
197
+ )
198
+ ```
199
+
200
+ ### 5. String Relocation and Pointer Recalculation
201
+
202
+ Safely expand game dialogue strings while recalculating internal pointer tables via LCS alignment:
203
+
204
+ ```python
205
+ from miorom import RelocatableBuffer
206
+
207
+ # Load a script segment
208
+ buf = RelocatableBuffer.load("dialogue.bin")
209
+
210
+ # Register pointer offsets and dynamic size headers
211
+ buf.register_anchored_field(pos=0x00, size=2, anchor_type="size_delta")
212
+ buf.register_pointer(pos=0x04, size=2, endian="<")
213
+ buf.register_pointer(pos=0x06, size=2, endian="<")
214
+
215
+ # Perform chained text replacements safely
216
+ buf.replace_text("Hello", "Good morning, adventurer!")
217
+ buf.replace_text("Item found.", "You have obtained a rare treasure!")
218
+
219
+ # Recalculate all registered pointers in one pass
220
+ report = buf.relocate_all()
221
+ buf.save("dialogue_expanded.bin")
222
+ ```
223
+
224
+ ### 6. Variable-Width Font (VWF) Word Wrapping
225
+
226
+ Validate and wrap dialogue lines using exact on-screen pixel metrics instead of naive character counts:
227
+
228
+ ```python
229
+ from miorom.text import BitmapFont, PixelWordWrapper
230
+
231
+ # Initialize font with proportional glyph metrics
232
+ font = BitmapFont(default_height=12, default_advance=8)
233
+ font.set_character_advance("i", 3)
234
+ font.set_character_advance("W", 12)
235
+
236
+ wrapper = PixelWordWrapper(font=font, max_pixel_width=220, max_lines=3)
237
+ result = wrapper.wrap("Welcome to the kingdom of Norad! We hope your journey was pleasant.")
238
+
239
+ print(f"Total lines: {len(result.lines)}, Fits in textbox: {result.fits}")
240
+ for line in result.lines:
241
+ print(f"Line ({line.pixel_width}px): {line.text}")
242
+ ```
243
+
244
+ ---
245
+
246
+ ## Architecture and Source Layout
247
+
248
+ ```text
249
+ miorom/
250
+ ├── pyproject.toml # Build system and dependency specifications
251
+ ├── README.md # Project overview and quickstart
252
+ ├── docs/
253
+ │ ├── API_REFERENCE.md # Comprehensive 60+ class API reference
254
+ │ ├── BINARY_PRIMITIVES.md # Low-level primitives developer guide
255
+ │ ├── CLI_REFERENCE.md # Terminal command manual
256
+ │ ├── PLATFORMS.md # Per-console format specifications
257
+ │ ├── WORKFLOW_GUIDE.md # 6-phase localization pipeline walkthrough
258
+ │ ├── PLUGIN_GUIDE.md # Custom BaseRomHandler registration guide
259
+ │ ├── LIBRARY_CONTRACTS.md # Serialization, streaming, extensibility contracts
260
+ │ └── SECURITY.md # Untrusted-archive extraction safety guide
261
+ ├── src/miorom/
262
+ │ ├── core/ # Stream I/O, Structs, Relocation, SymbolMap, HexDiff
263
+ │ ├── patch/ # IPS, BPS, Xdelta, and PatchWriter
264
+ │ ├── asm/ # Universal disassembler, AsmSnippet, Hooks, Anti-piracy
265
+ │ ├── script/ # ScriptVM, AST decompiler, IR lifter, Repackers
266
+ │ ├── text/ # VWF wrapper, CharMap, DTE, PO handler, Aligner
267
+ │ ├── platforms/ # NDS, Wii/GC, N64, GBA, GB, SNES, PSX, MD, ISO9660, CD-ROM
268
+ │ ├── graphics/ # Tile codecs (1-8bpp), Palettes, TileReducer, ImageBridge
269
+ │ ├── compression/ # LZ10, LZ11, RLE, Yaz0, Huffman, Heuristic LZSS
270
+ │ ├── audio/ # SDAT, IMA-ADPCM, CD-XA audio decoders and WAV builders
271
+ │ ├── save/ # Checksum calculators (CRC16/32, Fletcher) and DualSlotSave
272
+ │ ├── archive/ # Container unpackers and in-memory VirtualFileSystem (VFS)
273
+ │ ├── link/ # In-ROM ELF32 object linker and cave injector
274
+ │ ├── rom/ # Universal ROM unpacker and repacker manager
275
+ │ ├── scanner/ # Deep signature inspector, entropy profiling, crypto scans
276
+ │ └── cli/ # Command-line interface commands
277
+ └── tests/ # Pytest verification suite (405 unit tests)
278
+ ```
279
+
280
+ ---
281
+
282
+ ## Contributing & Testing
283
+
284
+ Contributions are welcome. Please ensure that all changes include comprehensive unit tests and pass the entire test suite:
285
+
286
+ ```bash
287
+ # Run all unit tests
288
+ pytest
289
+
290
+ # Run tests with coverage reporting
291
+ pytest --cov=miorom tests/
292
+ ```
293
+
294
+ ---
295
+
296
+ ## License
297
+
298
+ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.