Crates.io | ipl3checksum |
lib.rs | ipl3checksum |
version | 1.2.0 |
source | src |
created_at | 2023-12-22 13:14:59.165916 |
updated_at | 2024-01-11 21:09:55.489146 |
description | Library to calculate the IPL3 checksum for N64 ROMs |
homepage | |
repository | https://github.com/decompollaborate/ipl3checksum |
max_upload_size | |
id | 1078329 |
size | 7,507,056 |
A library to calculate the IPL3 checksum for N64 ROMs.
Written in Rust. Python and C bindings available.
To calculate the checksum of a ROM:
import ipl3checksum
romBytes = # A big endian bytes-like object
cickind = ipl3checksum.CICKind.CIC_6102_7101
# or calculateChecksumAutodetect to let the library guess the correct CIC kind
checksum = ipl3checksum.calculateChecksum(romBytes, cickind)
# If this assert fails it is because the library was not able to compute the
# checksum, probably because the passed rom was too small
assert checksum is not None
print(f"{checksum[0]:08X}")
print(f"{checksum[1]:08X}")
This library also contains a CIC detector:
cickind = ipl3checksum.detectCIC(romBytes)
# Either a `ipl3checksum.CICKind` object or `None`` if was not able to detect
# the CIC kind
print(cickind)
[0x0, 0x40]
and a correct IPL3 is at [0x40, 0x1000]
0x1000
to 0x101000
), then the library expects the passed ROM to be at least
0x101000
bytes long, otherwise the library will reject the ROM.
First you need to install the library, one way of doing it is via pip
.
python3 -m pip install -U ipl3checksum
If you use a requirements.txt
file in your repository, then you can add
this library with the following line:
ipl3checksum>=1.1.0,<2.0.0
Now you can invoke the library from your script.
The unstable development version is located at the develop branch. PRs should be made into that branch instead of the main one.
Since this library uses Rust code then you'll need a Rust compiler installed
on your system. To build the Python bindings you'll also need maturin
installed via pip
.
The recommended way to install a locally cloned repo the following.
python3 -m pip install .
In case you want to mess with the latest development version without wanting to clone the repository, then you could use the following commands:
python3 -m pip uninstall ipl3checksum
python3 -m pip install git+https://github.com/Decompollaborate/ipl3checksum.git@develop
NOTE: Installing the development version is not recommended unless you know what you are doing. Proceed at your own risk.
See this crate at https://crates.io/crates/ipl3checksum.
To add this library to your project using Cargo:
cargo add ipl3checksum
Or add the following line manually to your Cargo.toml
file:
ipl3checksum = "1.1.0"
This library provides bindings to call this library from C code. They are available on the releases tab.
To build said bindings from source, enable the c_bindings
Rust feature:
cargo build --lib --features c_bindings
Headers are located at bindings/c/include.
Due to Rust requirements, linking the C bindings of this library when building a C program adds extra library dependencies. Those libraries are the following:
-lws2_32 -lntdll -lbcrypt -ladvapi32 -luserenv
Various examples for the Python bindings are provided in the frontends folder.
Those examples are distributed with the Python library as cli tools. Each one
of them can be executed with either ipl3checksum utilityname
or
python3 -m ipl3checksum utilityname
, for example ipl3checksum detect_cic
.
The list can be checked in runtime with ipl3checksum --help
. Suboptions for
each tool can be checked with ipl3checksum utilityname --help
.
check
: Checks if the checksum in the ROM matches the calculated one.detect_cic
: Tries to detect the cic used from the given big endian rom.sum
: Calculates the ipl3 checksum o a given big endian rom, allowing to
optionally update the checksum.This library follows Semantic Versioning. We try to always keep backwards compatibility, so no breaking changes should happen until a major release (i.e. jumping from 1.X.X to 2.0.0).
To see what changed on each release check either the CHANGELOG.md file or check the releases page on Github. You can also use this link to check the latest release.
This algorithm comes directly from the IPL3, which each variant is part of the first 0x1000 bytes of the rom of every retail N64 ROM.
There are various implementations floating around on the internet, but for this specific one was reverse-engineered by myself. I made this because I couldn't find a library to calculate this checksum, so I decided to reverse-engineer it myself instead of taking somebody else's work. It also was an interesting learning experience.
Most of the repository is licensed under the MIT license, but I also made a reference implementation that is part of the public domain (licensed under CC0-1.0), feel free to use it however you prefer (acknowledgment is always appreciated, but not required).
I'm not really the guy that can answer all your hunger for knowledge, but here are a few links that may be helpful: