A modern, cross-platform C++ library for applying binary patches in IPS, UPS, and BPS formats created with usage for ROM hacks in mind, but I believe it can be used for anything.
- Supports IPS, UPS, and BPS patch formats
- Clean, modern API with RAII, move semantics
- Works on Windows, Linux, macOS, and other POSIX systems
- Optional memory-mapped I/O for fast file processing
- Core library has no external dependencies
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
cmake --build .BUILD_SHARED_LIBS: Build as shared library (default: ON)BUILD_STATIC_LIBS: Build static libraries (default: ON)IUB_ENABLE_MMAP: Enable memory-mapped I/O (default: ON)BUILD_EXAMPLES: Build example programs (default: OFF)BUILD_TESTS: Build unit tests (default: ON)BUILD_BENCHMARKS: Build benchmarks (default: OFF)BUILD_TOOLS: Build command-line tools (default: ON)
This directory contains CMake modules for integrating IUBPatchLib into your project.
There are several ways to use IUBPatchLib in your CMake-based project:
After installing IUBPatchLib system-wide, you can use find_package:
cmake_minimum_required(VERSION 3.20)
project(myproj)
find_package(iubpatch REQUIRED)
add_executable(myapp main.cc)
target_link_libraries(myapp PRIVATE iubpatch::iubpatch)If you have pkg-config available:
find_package(PkgConfig REQUIRED)
pkg_check_modules(IUBPATCH REQUIRED iubpatch)
add_executable(myapp main.cc)
target_link_libraries(myapp PRIVATE ${IUBPATCH_LIBRARIES})
target_include_directories(myapp PRIVATE ${IUBPATCH_INCLUDE_DIRS})
target_compile_options(myapp PRIVATE ${IUBPATCH_CFLAGS_OTHER})To include IUBPatchLib directly in your project:
include(FetchContent)
FetchContent_Declare(
iubpatch
GIT_REPOSITORY https://github.com/advnpzn/IUBPatchLib.git
GIT_TAG main
)
FetchContent_MakeAvailable(iubpatch)
add_executable(myapp main.cc)
target_link_libraries(myapp PRIVATE iubpatch::iubpatch)#include <iubpatch/apply.h>
#include <iostream>
int main() {
auto result = iubpatch::apply_patch(
"game.ips",
"game.rom",
"game_patched.rom"
);
if (result) {
std::cout << "Patch applied!\n";
return 0;
} else {
std::cerr << "Error: " << result.error().message << "\n";
return 1;
}
}After find_package(iubpatch), the following variables are available:
iubpatch_FOUND- TRUE if foundiubpatch_VERSION- Version stringiubpatch_INCLUDE_DIRS- Include directoriesiubpatch_LIBRARIES- Libraries to link (iubpatch::iubpatch)iubpatch_WITH_MMAP- Whether mmap support is enabled
find_package(iubpatch 0.1.0 REQUIRED)
if(iubpatch_VERSION VERSION_LESS "0.2.0")
message(STATUS "Using IUBPatchLib ${iubpatch_VERSION}")
endif()#include "iubpatch/apply.h"
// Simple patch application
auto result = iubpatch::apply_patch("game.ips", "game.rom", "game_patched.rom");
if (result) {
std::cout << "Patch applied successfully!\n";
} else {
std::cerr << "Error: " << result.error().message << "\n";
}
// With options
iubpatch::PatchOptions options;
options.verify_checksums = true;
options.create_backup = true;
auto result = iubpatch::apply_patch("game.ups", "game.rom", "game_patched.rom", options);
// Get patch information
auto info = iubpatch::get_patch_info("game.bps");
if (info) {
std::cout << "Format: " << iubpatch::format_to_string(info->format) << "\n";
std::cout << "Source size: " << info->src_size << " bytes\n";
std::cout << "Target size: " << info->target_size << " bytes\n";
}# Apply a patch
iubpatch-cli apply game.ips game.rom game_patched.rom
# Get patch information
iubpatch-cli info game.bps
# Validate patch
iubpatch-cli validate game.ups game.rom
# Apply with options
iubpatch-cli apply game.bps game.rom game_patched.rom --backup --no-mmapCheck this for LICENSE.
Contributions welcome! Please create an issue or raise a PR. I will review and merge it given that the tests pass.