mirror of
https://github.com/elseif/MikroTikPatch
synced 2026-07-17 18:49:41 +00:00
modified: .github/workflows/build_v7.yml
deleted: package.py modified: patch.py
This commit is contained in:
parent
fbdba025ba
commit
f9d2554725
2
.github/workflows/build_v7.yml
vendored
2
.github/workflows/build_v7.yml
vendored
@ -151,6 +151,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
sudo apt-get update > /dev/null
|
sudo apt-get update > /dev/null
|
||||||
sudo apt-get install -y zip unzip squashfs-tools jq > /dev/null
|
sudo apt-get install -y zip unzip squashfs-tools jq > /dev/null
|
||||||
|
sudo apt-get install -y python3-crcmod python3-pefile python3-pyelftools > /dev/null
|
||||||
|
|
||||||
if [ "$ARCH" == "x86" ]; then
|
if [ "$ARCH" == "x86" ]; then
|
||||||
ARCH_EXT=""
|
ARCH_EXT=""
|
||||||
@ -234,7 +235,6 @@ jobs:
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
EOF
|
EOF
|
||||||
sudo apt-get install python3-crcmod > /dev/null
|
|
||||||
HASH=$(python3 -E <<EOF
|
HASH=$(python3 -E <<EOF
|
||||||
import hashlib, crcmod, sys
|
import hashlib, crcmod, sys
|
||||||
with open('$BUILD_DIR/option.jg','rb') as f:
|
with open('$BUILD_DIR/option.jg','rb') as f:
|
||||||
|
|||||||
32
package.py
32
package.py
@ -1,32 +0,0 @@
|
|||||||
def install_package(package, version="upgrade", index_url='https://mirrors.aliyun.com/pypi/simple/'):
|
|
||||||
from sys import executable
|
|
||||||
from subprocess import check_call
|
|
||||||
result = False
|
|
||||||
try:
|
|
||||||
if version.lower() == "upgrade":
|
|
||||||
result = check_call([executable, "-m", "pip", "install", package, "--upgrade", "-i", index_url])
|
|
||||||
else:
|
|
||||||
from pkg_resources import get_distribution
|
|
||||||
current_package_version = None
|
|
||||||
try:
|
|
||||||
current_package_version = get_distribution(package)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
if current_package_version is None or current_package_version != version:
|
|
||||||
installation_sign = "==" if ">=" not in version else ""
|
|
||||||
result = check_call([executable, "-m", "pip", "install", package + installation_sign + version, "-i", index_url])
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
result = -1
|
|
||||||
return result
|
|
||||||
def check_package(package):
|
|
||||||
from importlib import import_module
|
|
||||||
try:
|
|
||||||
import_module(package)
|
|
||||||
return True
|
|
||||||
except ImportError:
|
|
||||||
return False
|
|
||||||
def check_install_package(packages):
|
|
||||||
for package in packages:
|
|
||||||
if not check_package(package):
|
|
||||||
install_package(package)
|
|
||||||
12
patch.py
12
patch.py
@ -1,5 +1,7 @@
|
|||||||
import subprocess,lzma
|
import subprocess,lzma
|
||||||
import struct,os,re,tempfile
|
import struct,os,re,tempfile
|
||||||
|
import pefile
|
||||||
|
from elftools.elf.elffile import ELFFile
|
||||||
from npk import NovaPackage,NpkPartID,NpkFileContainer
|
from npk import NovaPackage,NpkPartID,NpkFileContainer
|
||||||
|
|
||||||
def replace_chunks(old_chunks,new_chunks,data,name):
|
def replace_chunks(old_chunks,new_chunks,data,name):
|
||||||
@ -200,10 +202,6 @@ def patch_pe(data: bytes,key_dict:dict):
|
|||||||
return new_data
|
return new_data
|
||||||
|
|
||||||
def build_efi(input_file, output_file):
|
def build_efi(input_file, output_file):
|
||||||
from package import check_install_package
|
|
||||||
check_install_package(['pyelftools','pefile'])
|
|
||||||
from elftools.elf.elffile import ELFFile
|
|
||||||
import pefile
|
|
||||||
def find_xz_streams(data:bytes):
|
def find_xz_streams(data:bytes):
|
||||||
streams = []
|
streams = []
|
||||||
XZ_HEADER_MAGIC = b'\xFD7zXZ\x00\x00\x01'
|
XZ_HEADER_MAGIC = b'\xFD7zXZ\x00\x00\x01'
|
||||||
@ -255,9 +253,6 @@ def build_efi(input_file, output_file):
|
|||||||
def patch_netinstall(key_dict: dict,input_file,output_file=None):
|
def patch_netinstall(key_dict: dict,input_file,output_file=None):
|
||||||
netinstall = open(input_file,'rb').read()
|
netinstall = open(input_file,'rb').read()
|
||||||
if netinstall[:2] == b'MZ':
|
if netinstall[:2] == b'MZ':
|
||||||
from package import check_install_package
|
|
||||||
check_install_package(['pefile'])
|
|
||||||
import pefile
|
|
||||||
ROUTEROS_BOOT = {
|
ROUTEROS_BOOT = {
|
||||||
129:{'arch':'power','name':'Powerboot'},
|
129:{'arch':'power','name':'Powerboot'},
|
||||||
130:{'arch':'e500','name':'e500_boot'},
|
130:{'arch':'e500','name':'e500_boot'},
|
||||||
@ -296,7 +291,6 @@ def patch_netinstall(key_dict: dict,input_file,output_file=None):
|
|||||||
pe.set_bytes_at_rva(rva,new_data)
|
pe.set_bytes_at_rva(rva,new_data)
|
||||||
pe.write(output_file or input_file)
|
pe.write(output_file or input_file)
|
||||||
elif netinstall[:4] == b'\x7FELF':
|
elif netinstall[:4] == b'\x7FELF':
|
||||||
import re
|
|
||||||
# 83 00 00 00 C4 68 C4 0B 5A C2 04 08 10 9E 52 00
|
# 83 00 00 00 C4 68 C4 0B 5A C2 04 08 10 9E 52 00
|
||||||
# 8A 00 00 00 C3 68 C4 0B 6A 60 57 08 C0 3D 54 00
|
# 8A 00 00 00 C3 68 C4 0B 6A 60 57 08 C0 3D 54 00
|
||||||
# 81 00 00 00 D3 68 C4 0B 2A 9E AB 08 5C 1B 78 00
|
# 81 00 00 00 D3 68 C4 0B 2A 9E AB 08 5C 1B 78 00
|
||||||
@ -363,8 +357,6 @@ def patch_kernel(data:bytes,key_dict):
|
|||||||
|
|
||||||
def patch_loader(loader_file):
|
def patch_loader(loader_file):
|
||||||
try:
|
try:
|
||||||
from package import check_install_package
|
|
||||||
check_install_package(['pyelftools'])
|
|
||||||
from loader.patch_loader import patch_loader as do_patch_loader
|
from loader.patch_loader import patch_loader as do_patch_loader
|
||||||
arch = os.getenv('ARCH') or 'x86'
|
arch = os.getenv('ARCH') or 'x86'
|
||||||
arch = arch.replace('-', '')
|
arch = arch.replace('-', '')
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user