liblk

June 30, 2026 ยท View on GitHub

License GitHub Issues

liblk is a simple and tiny python library for manipulating LK (Little Kernel) images. It's flexible and has an easy-to-use API. The library requires Python 3.8 or higher.

Installation

sudo apt install python3-pip # If you don't have pip installed.
pip3 install --upgrade git+https://github.com/R0rt1z2/liblk

Examples

The folder examples contains a set of examples that aim to show how to use the library and highlight its features.

Quick Start

from liblk import LkImage
from liblk import Certificate

# Load an LK image
lk_image = LkImage("path/to/lk.img")

# Iterate through the partitions
for name, partition in lk_image.partitions.items():
    print(f"Partition: {name}, Size: {len(partition.data)} bytes")

# Apply a binary patch
lk_image.apply_patch("30b583b002ab", "00207047")

# Inspect a partition's cert2
lk = lk_image.partitions["lk"]
if lk.cert2 is not None:
    cert = Certificate.from_bytes(lk.cert2.data)
    print("cert2 matches contents:", lk.matches_cert2())
    print("embedded header hash:", cert.header_hash.hex())
    print("embedded image hash :", cert.image_hash.hex())

License

This project is licensed under the GPL-3.0 License - see the LICENSE file for details.