diff --git a/.github/workflows/mikrotik_patch_7.yml b/.github/workflows/mikrotik_patch_7.yml index c5b3005..bca8c33 100644 --- a/.github/workflows/mikrotik_patch_7.yml +++ b/.github/workflows/mikrotik_patch_7.yml @@ -88,9 +88,13 @@ jobs: if [ "${{ matrix.arch }}" == "x86" ]; then sudo cp busybox/busybox_x86 ./option-root/bin/busybox sudo chmod +x ./option-root/bin/busybox + sudo cp keygen/keygen_x86 ./option-root/bin/keygen + sudo chmod +x ./option-root/bin/keygen elif [ "${{ matrix.arch }}" == "arm64" ]; then sudo cp busybox/busybox_aarch64 ./option-root/bin/busybox sudo chmod +x ./option-root/bin/busybox + sudo cp keygen/keygen_aarch64 ./option-root/bin/keygen + sudo chmod +x ./option-root/bin/keygen fi sudo chmod +x ./busybox/busybox_x86 COMMANDS=$(./busybox/busybox_x86 --list) diff --git a/mikro.py b/mikro.py index 83df543..5f4f759 100644 --- a/mikro.py +++ b/mikro.py @@ -192,20 +192,16 @@ def mikro_kcdsa_verify(data:bytes, signature:bytes, public_key:bytes)->bool: #y^2 = x^3 + ax^2 + x x = FieldElement(Tools.bytestoint_le(public_key), curve.p) YY = ((x**3) + (curve.a * x**2) + x).sqrt() - public_keys = [] - for y in YY: - public_keys += [AffineCurvePoint(int(x), int(y), curve)] - + public_keys = [AffineCurvePoint(int(x), int(y), curve) for y in YY] data_hash = bytearray(mikro_sha256(data)) nonce_hash = signature[:16] - signature = signature[16:] + signature = Tools.bytestoint_le(signature[16:]) for i in range(16): data_hash[8+i] ^= nonce_hash[i] data_hash[0] &= 0xF8 data_hash[31] &= 0x7F data_hash[31] |= 0x40 data_hash = Tools.bytestoint_le(data_hash) - signature = Tools.bytestoint_le(signature) for public_key in public_keys: nonce = int((public_key * signature + curve.G * data_hash).x) if mikro_sha256(Tools.inttobytes_le(nonce,32))[:len(nonce_hash)] == nonce_hash: diff --git a/patch.py b/patch.py index 5c2d8dc..a864c79 100644 --- a/patch.py +++ b/patch.py @@ -269,38 +269,22 @@ def patch_npk_package(package,key_dict): if package[NpkPartID.NAME_INFO].data.name == 'system': file_container = NpkFileContainer.unserialize_from(package[NpkPartID.FILE_CONTAINER].data) for item in file_container: - if item.name == b'boot/EFI/BOOT/BOOTX64.EFI': - print(f'patch {item.name} ...') - item.data = patch_kernel(item.data,key_dict) - elif item.name == b'boot/kernel': - print(f'patch {item.name} ...') - item.data = patch_kernel(item.data,key_dict) - elif item.name == b'boot/initrd.rgz': + if item.name in [b'boot/EFI/BOOT/BOOTX64.EFI',b'boot/kernel',b'boot/initrd.rgz']: print(f'patch {item.name} ...') item.data = patch_kernel(item.data,key_dict) package[NpkPartID.FILE_CONTAINER].data = file_container.serialize() - try: - squashfs_file = 'squashfs-root.sfs' - extract_dir = 'squashfs-root' - open(squashfs_file,'wb').write(package[NpkPartID.SQUASHFS].data) - print(f"extract {squashfs_file} ...") - run_shell_command(f"unsquashfs -d {extract_dir} {squashfs_file}") - patch_squashfs(extract_dir,key_dict) - keygen = os.path.join(extract_dir,'bin/keygen') - if 'ARCH' in os.environ and os.environ['ARCH'] =='': - run_shell_command(f"sudo cp keygen/keygen_x86 {keygen}") - run_shell_command(f"sudo chmod a+x {keygen}") - elif 'ARCH' in os.environ and os.environ['ARCH'] == '-arm64': - run_shell_command(f"sudo cp keygen/keygen_aarch64 {keygen}") - run_shell_command(f"sudo chmod a+x {keygen}") - logo = os.path.join(extract_dir,"nova/lib/console/logo.txt") - run_shell_command(f"sudo sed -i '1d' {logo}") - run_shell_command(f"sudo sed -i '8s#.*# elseif@live.cn https://github.com/elseif/MikroTikPatch#' {logo}") - print(f"pack {extract_dir} ...") - run_shell_command(f"rm -f {squashfs_file}") - run_shell_command(f"mksquashfs {extract_dir} {squashfs_file} -quiet -comp xz -no-xattrs -b 256k") - except Exception as e: - print(e) + squashfs_file = 'squashfs-root.sfs' + extract_dir = 'squashfs-root' + open(squashfs_file,'wb').write(package[NpkPartID.SQUASHFS].data) + print(f"extract {squashfs_file} ...") + run_shell_command(f"unsquashfs -d {extract_dir} {squashfs_file}") + patch_squashfs(extract_dir,key_dict) + logo = os.path.join(extract_dir,"nova/lib/console/logo.txt") + run_shell_command(f"sudo sed -i '1d' {logo}") + run_shell_command(f"sudo sed -i '8s#.*# elseif@live.cn https://github.com/elseif/MikroTikPatch#' {logo}") + print(f"pack {extract_dir} ...") + run_shell_command(f"rm -f {squashfs_file}") + run_shell_command(f"mksquashfs {extract_dir} {squashfs_file} -quiet -comp xz -no-xattrs -b 256k") print(f"clean ...") run_shell_command(f"rm -rf {extract_dir}") package[NpkPartID.SQUASHFS].data = open(squashfs_file,'rb').read()