mirror of
https://github.com/elseif/MikroTikPatch.git
synced 2025-01-23 05:25:00 +03:00
modified: .gitignore
modified: npk.py modified: patch.py
This commit is contained in:
parent
0ce6484e60
commit
0ff0485a87
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
||||
__pycache__/
|
||||
.vscode/
|
||||
venv/
|
||||
app/
|
||||
test_*.py
|
5
npk.py
5
npk.py
@ -102,7 +102,6 @@ class NpkInfo:
|
||||
def build_time(self,value:datetime):
|
||||
self._build_time = int(value.timestamp())
|
||||
|
||||
|
||||
class NpkNameInfo(NpkInfo):
|
||||
_format = '<16s4sI12s'
|
||||
def __init__(self,name:str,version:str,build_time=datetime.now(),unknow=b'\x00'*12):
|
||||
@ -171,7 +170,6 @@ class Package:
|
||||
def __iter__(self):
|
||||
for part in self._parts:
|
||||
yield part
|
||||
|
||||
def __getitem__(self, id:NpkPartID):
|
||||
for part in self._parts:
|
||||
if part.id == id:
|
||||
@ -313,8 +311,6 @@ class NovaPackage(Package):
|
||||
assert int.from_bytes(data[4:8],'little') == len(data) - 8, 'Invalid Nova Package Size'
|
||||
return NovaPackage(data[8:])
|
||||
|
||||
|
||||
|
||||
if __name__=='__main__':
|
||||
parser = argparse.ArgumentParser(description='nova package creator and editor')
|
||||
subparsers = parser.add_subparsers(dest="command")
|
||||
@ -335,7 +331,6 @@ if __name__=='__main__':
|
||||
kcdsa_public_key = bytes.fromhex(os.environ['CUSTOM_LICENSE_PUBLIC_KEY'])
|
||||
eddsa_public_key = bytes.fromhex(os.environ['CUSTOM_NPK_SIGN_PUBLIC_KEY'])
|
||||
|
||||
|
||||
if args.command =='sign':
|
||||
print(f'Signing {args.input}')
|
||||
npk = NovaPackage.load(args.input)
|
||||
|
12
patch.py
12
patch.py
@ -108,7 +108,6 @@ def patch_elf(data: bytes,key_dict:dict):
|
||||
initrd_xz = find_7zXZ_data(data)
|
||||
return patch_initrd_xz(initrd_xz,key_dict)
|
||||
|
||||
|
||||
def patch_pe(data: bytes,key_dict:dict):
|
||||
vmlinux_xz = find_7zXZ_data(data)
|
||||
vmlinux = lzma.decompress(vmlinux_xz)
|
||||
@ -266,8 +265,7 @@ def run_shell_command(command):
|
||||
process = subprocess.run(command, shell=True, check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
return process.stdout, process.stderr
|
||||
|
||||
|
||||
def patch_npk_package(package,key_dict,kcdsa_private_key,eddsa_private_key):
|
||||
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:
|
||||
@ -280,8 +278,6 @@ def patch_npk_package(package,key_dict,kcdsa_private_key,eddsa_private_key):
|
||||
elif item.name == b'boot/initrd.rgz':
|
||||
print(f'patch {item.name} ...')
|
||||
item.data = patch_kernel(item.data,key_dict)
|
||||
open('initrd.rgz','wb').write(item.data)
|
||||
|
||||
package[NpkPartID.FILE_CONTAINER].data = file_container.serialize()
|
||||
try:
|
||||
squashfs_file = 'squashfs-root.sfs'
|
||||
@ -298,6 +294,7 @@ def patch_npk_package(package,key_dict,kcdsa_private_key,eddsa_private_key):
|
||||
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}")
|
||||
run_shell_command(f'echo -e "\n https://github.com/elseif/MikroTikPatch" | sudo tee -a {os.path.join(extract_dir,"nova/lib/console/logo.txt")}')
|
||||
print(f"pack {extract_dir} ...")
|
||||
run_shell_command(f"rm -f {squashfs_file}")
|
||||
_, stderr = run_shell_command(f"mksquashfs {extract_dir} {squashfs_file} -quiet -comp xz -no-xattrs -b 256k")
|
||||
@ -313,10 +310,9 @@ def patch_npk_file(key_dict,kcdsa_private_key,eddsa_private_key,input_file,outpu
|
||||
npk = NovaPackage.load(input_file)
|
||||
if len(npk._packages) > 0:
|
||||
for package in npk._packages:
|
||||
patch_npk_package(package,key_dict,kcdsa_private_key,eddsa_private_key)
|
||||
patch_npk_package(package,key_dict)
|
||||
else:
|
||||
patch_npk_package(npk,key_dict,kcdsa_private_key,eddsa_private_key)
|
||||
|
||||
patch_npk_package(npk,key_dict)
|
||||
npk.sign(kcdsa_private_key,eddsa_private_key)
|
||||
npk.save(output_file or input_file)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user