A Swift port of Rom Patcher JS by Marc Robledo. This project provides a Swift package for applying and creating ROM patches, with a command-line interface provided as an example implementation.
Note: Patch creation has not been thoroughly tested yet.
RomPatcherSwift is a Swift package that enables ROM patching functionality in Swift applications. It's a direct port of the popular Rom Patcher JS library with Swift-specific features and optimizations, maintaining compatibility with the same patch formats and features.
- Support for multiple patch formats (BPS, UPS, IPS)
- Efficient binary file handling with
BinFileclass - Built-in performance monitoring
- Consistent API across patch formats
- Example CLI implementation
- Cross-platform support (macOS, iOS)
- Swift 5.9 or later
- macOS 13.0+ or iOS 16.0+
Add RomPatcherSwift to your project's dependencies in Package.swift:
dependencies: [
.package(url: "https://github.com/jschoeny/RomPatcherSwift.git", from: "1.0.0")
]- Clone the repository:
git clone https://github.com/jschoeny/RomPatcherSwift.git
cd RomPatcherSwift- Build the package:
# Debug build
swift build
# Release build
swift build -c releaseThe CLI tool is provided for easy testing of the package.
.build/release/rom-patcher --help
Usage:
rom-patcher patch <rom_file> <patch_file> [options]
rom-patcher create <original_rom> <modified_rom> [options]
Options:
--validate-checksum Validate checksum
--add-header Add temporary header
--remove-header Remove ROM header temporarily
--fix-checksum Fix known ROM header checksum
--format <format> Patch format (ips, bps, ups)The package provides a consistent API through three main components:
-
BinFile: Core binary file handling with methods for:
- Reading/writing different data types
- File operations (save, slice, copy)
- Hash calculations (CRC32, MD5, SHA-1)
-
Patch Protocol: Standard interface implemented by all patch formats:
apply(to:validate:)- Apply patch to ROMexport()- Create patch filevalidateSource(_:headerSize:)- Validate source ROMgetValidationInfo()- Get validation details
-
Format Implementations: Each patch format follows the same pattern:
- Consistent error handling
- Format-specific optimizations
- Validation and checksum support (when applicable)
Basic usage example:
import BinFile
import RomPatcherCore
// Load ROM and patch files
let romFile = try BinFile(source: "original.rom")
let patchFile = try BinFile(source: "patch.bps")
// Create patcher instance
let patcher = RomPatcher()
// Parse and apply patch
let patch = try patcher.parsePatchFile(patchFile)
let patchedRom = try patcher.applyPatch(romFile: romFile, patch: patch)
// Save patched ROM
try patchedRom.setFullName(newName: "patched", newExtension: "rom")
try patchedRom.save()# Build the package
swift build
# Build with optimizations
swift build -c releaseThe package includes a PerformanceMonitor class for identifying bottlenecks:
let monitor = PerformanceMonitor(functionName: "myFunction")
// ... code to monitor ...
monitor.measure("operation name")
monitor.printMeasurementResults()Only available in the debug build. Automatically disabled in release builds.
- Fork the repository
- Create a feature branch
- Implement your changes
- Submit a pull request
Please ensure:
- Code follows Swift style guidelines
- New features include performance monitoring when applicable
- Documentation is updated
This project is licensed under the MIT License - see the LICENSE.md file for details.
- Rom Patcher JS by Marc Robledo
- Licensed under MIT License
- Copyright (c) 2017-2024 Marc Robledo
- Copyright (c) 2025 Jared Schoeny
- Maintains MIT License
- Includes Swift-specific optimizations and language features
- Jared Schoeny (Port maintainer)
- Marc Robledo (Original author)