From 8ffa1f155395e13683f8710a50960c615d7eab30 Mon Sep 17 00:00:00 2001 From: Patrick Huesmann Date: Wed, 18 Oct 2023 12:22:42 +0200 Subject: [PATCH] Make installable package --- .gitignore | 1 + pyproject.toml | 24 +++++++++++++++++++ requirements.txt | 3 --- src/unisoc_unlock/__init__.py | 0 src/unisoc_unlock/__main__.py | 3 +++ src/unisoc_unlock/bundled_adb/__init__.py | 0 .../unisoc_unlock/bundled_adb}/common.py | 0 .../unisoc_unlock/bundled_adb}/fastboot.py | 0 .../bundled_adb}/usb_exceptions.py | 0 unisoc-unlock.py => src/unisoc_unlock/cli.py | 9 +++++-- .../unisoc_unlock/rsa4096_vbmeta.pem | 0 11 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements.txt create mode 100644 src/unisoc_unlock/__init__.py create mode 100644 src/unisoc_unlock/__main__.py create mode 100644 src/unisoc_unlock/bundled_adb/__init__.py rename {bundled_adb => src/unisoc_unlock/bundled_adb}/common.py (100%) rename {bundled_adb => src/unisoc_unlock/bundled_adb}/fastboot.py (100%) rename {bundled_adb => src/unisoc_unlock/bundled_adb}/usb_exceptions.py (100%) rename unisoc-unlock.py => src/unisoc_unlock/cli.py (89%) rename rsa4096_vbmeta.pem => src/unisoc_unlock/rsa4096_vbmeta.pem (100%) diff --git a/.gitignore b/.gitignore index 8a7b46b..6588c1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ __pycache__ /.venv +/dist diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..f35bd32 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,24 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "unisoc_unlock" +version = "0.0.1" +authors = [ + { name="Patrick Huesmann", email="info@patrick-huesmann.de" }, +] +description = "Tool for unlocking a Unisoc/Spreadtrum Android bootloader" +readme = "README.md" +requires-python = ">=3.6" +dependencies = [ + "libusb1", + "pycryptodome" +] + +[project.urls] +"Homepage" = "https://github.com/pypa/sampleproject" + +[project.scripts] +unisoc_unlock = "unisoc_unlock.cli:main" + diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a0eec86..0000000 --- a/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -libusb1 -pycryptodome - diff --git a/src/unisoc_unlock/__init__.py b/src/unisoc_unlock/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/unisoc_unlock/__main__.py b/src/unisoc_unlock/__main__.py new file mode 100644 index 0000000..4e28416 --- /dev/null +++ b/src/unisoc_unlock/__main__.py @@ -0,0 +1,3 @@ +from .cli import main + +main() diff --git a/src/unisoc_unlock/bundled_adb/__init__.py b/src/unisoc_unlock/bundled_adb/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bundled_adb/common.py b/src/unisoc_unlock/bundled_adb/common.py similarity index 100% rename from bundled_adb/common.py rename to src/unisoc_unlock/bundled_adb/common.py diff --git a/bundled_adb/fastboot.py b/src/unisoc_unlock/bundled_adb/fastboot.py similarity index 100% rename from bundled_adb/fastboot.py rename to src/unisoc_unlock/bundled_adb/fastboot.py diff --git a/bundled_adb/usb_exceptions.py b/src/unisoc_unlock/bundled_adb/usb_exceptions.py similarity index 100% rename from bundled_adb/usb_exceptions.py rename to src/unisoc_unlock/bundled_adb/usb_exceptions.py diff --git a/unisoc-unlock.py b/src/unisoc_unlock/cli.py similarity index 89% rename from unisoc-unlock.py rename to src/unisoc_unlock/cli.py index ed91907..da6265e 100755 --- a/unisoc-unlock.py +++ b/src/unisoc_unlock/cli.py @@ -1,7 +1,8 @@ #!/usr/bin/env python3 +import os import sys -from bundled_adb import fastboot, usb_exceptions +from .bundled_adb import fastboot, usb_exceptions from Crypto.Signature import PKCS1_v1_5 from Crypto.Hash import SHA256 from Crypto.PublicKey import RSA @@ -52,7 +53,11 @@ def main(): print(f'OEM ID: {oem_id.id}') id = oem_id.id.ljust(2*64, '0') id_raw = base64.b16decode(id, casefold=True) - sgn = sign_token(id_raw, 'rsa4096_vbmeta.pem') + pemfile = os.path.join( + os.path.dirname(__file__), + 'rsa4096_vbmeta.pem' + ) + sgn = sign_token(id_raw, pemfile) print('Download signature') dev.Download(io.BytesIO(sgn), source_len=len(sgn)) diff --git a/rsa4096_vbmeta.pem b/src/unisoc_unlock/rsa4096_vbmeta.pem similarity index 100% rename from rsa4096_vbmeta.pem rename to src/unisoc_unlock/rsa4096_vbmeta.pem