mirror of
https://github.com/elseif/MikroTikPatch.git
synced 2026-08-26 10:05:50 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2b9db1436c | ||
|
|
6dccdda7bb | ||
|
|
1d0b4f9563 | ||
|
|
ce13b4b959 | ||
|
|
3f98072f2d | ||
|
|
ceb85aaf72 |
76
.github/workflows/mikrotik_patch_7.yml
vendored
76
.github/workflows/mikrotik_patch_7.yml
vendored
@@ -7,13 +7,14 @@ on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
arch:
|
||||
description: 'Architecture (x86, arm64)'
|
||||
description: 'Architecture (x86, arm64, arm)'
|
||||
required: true
|
||||
default: 'x86'
|
||||
type: choice
|
||||
options:
|
||||
- x86
|
||||
- arm64
|
||||
- arm
|
||||
channel:
|
||||
description: 'Channel (stable, testing)'
|
||||
required: true
|
||||
@@ -85,6 +86,7 @@ jobs:
|
||||
else
|
||||
BUILD_TIME=$(date +'%s')
|
||||
RELEASE=true
|
||||
MATRIX_JSON='[{"arch":"x86","channel":"stable"},{"arch":"arm64","channel":"stable"},{"arch":"arm","channel":"stable"},{"arch":"x86","channel":"testing"},{"arch":"arm64","channel":"testing"},{"arch":"arm","channel":"testing"}]'
|
||||
MATRIX_JSON='[{"arch":"x86","channel":"stable"},{"arch":"arm64","channel":"stable"},{"arch":"x86","channel":"testing"},{"arch":"arm64","channel":"testing"}]'
|
||||
fi
|
||||
echo "BUILD_TIME=$BUILD_TIME" >> $GITHUB_OUTPUT
|
||||
@@ -141,6 +143,8 @@ jobs:
|
||||
cat CHANGELOG
|
||||
if [[ "${{ matrix.arch }}" == "arm64" ]]; then
|
||||
echo "ARCH=-arm64" >> $GITHUB_ENV
|
||||
elif [[ "${{ matrix.arch }}" == "arm" ]]; then
|
||||
echo "ARCH=-arm" >> $GITHUB_ENV
|
||||
else
|
||||
echo "ARCH=" >> $GITHUB_ENV
|
||||
fi
|
||||
@@ -179,6 +183,14 @@ jobs:
|
||||
sudo chmod +x ./option-root/bin/busybox
|
||||
sudo cp keygen/keygen_aarch64 ./option-root/bin/keygen
|
||||
sudo chmod +x ./option-root/bin/keygen
|
||||
elif [ "${{ matrix.arch }}" == "arm" ]; then
|
||||
sudo cp busybox/busybox_arm ./option-root/bin/busybox
|
||||
sudo chmod +x ./option-root/bin/busybox
|
||||
sudo cp keygen/keygen_arm ./option-root/bin/keygen
|
||||
sudo chmod +x ./option-root/bin/keygen
|
||||
else
|
||||
echo "Unsupported architecture: ${{ matrix.arch }}"
|
||||
exit 1
|
||||
fi
|
||||
sudo chmod +x ./busybox/busybox_x86
|
||||
COMMANDS=$(./busybox/busybox_x86 --list)
|
||||
@@ -188,9 +200,11 @@ jobs:
|
||||
sudo mksquashfs option-root option.sfs -quiet -comp xz -no-xattrs -b 256k
|
||||
sudo rm -rf option-root
|
||||
if [ "${{ matrix.arch }}" == "x86" ]; then
|
||||
sudo wget -O cpython.tar.gz -nv https://github.com/indygreg/python-build-standalone/releases/download/20241016/cpython-3.11.10+20241016-x86_64-unknown-linux-musl-install_only_stripped.tar.gz
|
||||
sudo wget -O cpython.tar.gz -nv https://github.com/indygreg/python-build-standalone/releases/download/20250708/cpython-3.11.13+20250708-x86_64-unknown-linux-musl-install_only_stripped.tar.gz
|
||||
elif [ "${{ matrix.arch }}" == "arm64" ]; then
|
||||
sudo wget -O cpython.tar.gz -nv https://github.com/indygreg/python-build-standalone/releases/download/20241016/cpython-3.11.10+20241016-aarch64-unknown-linux-gnu-install_only_stripped.tar.gz
|
||||
sudo wget -O cpython.tar.gz -nv https://github.com/indygreg/python-build-standalone/releases/download/20250708/cpython-3.11.13+20250708-aarch64-unknown-linux-gnu-install_only_stripped.tar.gz
|
||||
elif [ "${{ matrix.arch }}" == "arm" ]; then
|
||||
sudo wget -O cpython.tar.gz -nv https://github.com/indygreg/python-build-standalone/releases/download/20250708/cpython-3.11.13+20250708-armv7-unknown-linux-gnueabi-install_only_stripped.tar.gz
|
||||
fi
|
||||
sudo tar -xf cpython.tar.gz
|
||||
sudo rm cpython.tar.gz
|
||||
@@ -200,7 +214,7 @@ jobs:
|
||||
sudo rm -rf ./python
|
||||
|
||||
- name: Cache mikrotik-${{ env.LATEST_VERSION }}${{ env.ARCH }}.iso
|
||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && (matrix.arch == 'x86' || matrix.arch == 'arm64')
|
||||
id: cache-mikrotik
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
@@ -209,13 +223,13 @@ jobs:
|
||||
key: mikrotik-${{ env.LATEST_VERSION }}${{ env.ARCH }}
|
||||
|
||||
- name: Get mikrotik-${{ env.LATEST_VERSION }}${{ env.ARCH }}.iso
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && steps.cache-mikrotik.outputs.cache-hit != 'true'
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && steps.cache-mikrotik.outputs.cache-hit != 'true' && (matrix.arch == 'x86' || matrix.arch == 'arm64')
|
||||
run: |
|
||||
sudo wget -nv -O mikrotik.iso https://download.mikrotik.com/routeros/$LATEST_VERSION/mikrotik-$LATEST_VERSION$ARCH.iso
|
||||
|
||||
|
||||
- name: Patch mikrotik-${{ env.LATEST_VERSION }}${{ env.ARCH }}.iso
|
||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && (matrix.arch == 'x86' || matrix.arch == 'arm64')
|
||||
run: |
|
||||
sudo apt-get install -y mkisofs xorriso > /dev/null
|
||||
sudo mkdir ./iso
|
||||
@@ -233,7 +247,7 @@ jobs:
|
||||
sudo cp -f routeros-$LATEST_VERSION$ARCH.npk ./new_iso/
|
||||
sudo -E python3 npk.py create ./new_iso/gps-$LATEST_VERSION$ARCH.npk ./option-$LATEST_VERSION$ARCH.npk option ./option.sfs -desc="busybox"
|
||||
sudo cp option-$LATEST_VERSION$ARCH.npk ./new_iso/
|
||||
sudo -E python3 npk.py create ./new_iso/gps-$LATEST_VERSION$ARCH.npk ./python3-$LATEST_VERSION$ARCH.npk python3 ./python3.sfs -desc="python 3.11.9"
|
||||
sudo -E python3 npk.py create ./new_iso/gps-$LATEST_VERSION$ARCH.npk ./python3-$LATEST_VERSION$ARCH.npk python3 ./python3.sfs -desc="python 3.11.13"
|
||||
sudo cp python3-$LATEST_VERSION$ARCH.npk ./new_iso/
|
||||
sudo mkdir ./efiboot
|
||||
sudo mount -o loop ./new_iso/efiboot.img ./efiboot
|
||||
@@ -279,7 +293,7 @@ jobs:
|
||||
cd ..
|
||||
|
||||
- name: Cache chr-${{ env.LATEST_VERSION }}${{ env.ARCH }}.img.zip
|
||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && (matrix.arch == 'x86' || matrix.arch == 'arm64')
|
||||
id: cache-chr-img
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
@@ -288,7 +302,7 @@ jobs:
|
||||
key: chr-${{ env.LATEST_VERSION }}${{ env.ARCH }}.img
|
||||
|
||||
- name: Get chr-${{ env.LATEST_VERSION }}${{ env.ARCH }}.img
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && steps.cache-chr-img.outputs.cache-hit != 'true'
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && steps.cache-chr-img.outputs.cache-hit != 'true' && (matrix.arch == 'x86' || matrix.arch == 'arm64')
|
||||
run: |
|
||||
sudo wget -nv -O chr.img.zip https://download.mikrotik.com/routeros/$LATEST_VERSION/chr-$LATEST_VERSION$ARCH.img.zip
|
||||
sudo unzip chr.img.zip
|
||||
@@ -296,7 +310,7 @@ jobs:
|
||||
sudo mv chr-$LATEST_VERSION$ARCH.img chr.img
|
||||
|
||||
- name: Create chr-${{ env.LATEST_VERSION }}${{ env.ARCH }}.img
|
||||
if: steps.get_latest.outputs.has_new_version == 'true'
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && (matrix.arch == 'x86' || matrix.arch == 'arm64')
|
||||
run: |
|
||||
sudo modprobe nbd
|
||||
sudo apt-get install -y qemu-utils > /dev/null
|
||||
@@ -397,7 +411,49 @@ jobs:
|
||||
sudo rm chr-$LATEST_VERSION$ARCH.vhdx
|
||||
sudo rm chr-$LATEST_VERSION$ARCH.vdi
|
||||
sudo rm chr-$LATEST_VERSION$ARCH.img
|
||||
|
||||
- name: Cache all_packages-${{ matrix.arch }}-$LATEST_VERSION.zip
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch != 'x86' && matrix.arch != 'arm64'
|
||||
id: cache-all-packages
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: all_packages.zip
|
||||
key: all_packages-${{ matrix.arch }}-$LATEST_VERSION.zip
|
||||
|
||||
- name: Get all_packages-${{ matrix.arch }}-$LATEST_VERSION.zip
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && steps.cache-all-packages.outputs.cache-hit != 'true' && matrix.arch != 'x86' && matrix.arch != 'arm64'
|
||||
run: |
|
||||
sudo wget -nv -O all_packages.zip https://download.mikrotik.com/routeros/$LATEST_VERSION/all_packages-${{ matrix.arch }}-$LATEST_VERSION.zip
|
||||
|
||||
- name: Cache Main package routeros-${{ env.LATEST_VERSION }}${{ env.ARCH }}.npk
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch != 'x86' && matrix.arch != 'arm64'
|
||||
id: cache-main-package
|
||||
uses: actions/cache@v4
|
||||
with:
|
||||
path: routeros.npk
|
||||
key: routeros-${{ env.LATEST_VERSION }}${{ env.ARCH }}.npk
|
||||
|
||||
- name: Get Main package routeros-${{ env.LATEST_VERSION }}${{ env.ARCH }}.npk
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && steps.cache-main-package.outputs.cache-hit != 'true' && matrix.arch != 'x86' && matrix.arch != 'arm64'
|
||||
run: |
|
||||
sudo wget -nv -O routeros.npk https://download.mikrotik.com/routeros/$LATEST_VERSION/routeros-$LATEST_VERSION$ARCH.npk
|
||||
|
||||
- name: Patch all_packages-${{ matrix.arch }}-$LATEST_VERSION.zip
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch != 'x86' && matrix.arch != 'arm64'
|
||||
run: |
|
||||
sudo unzip all_packages.zip -d ./all_packages
|
||||
sudo cp routeros.npk routeros-$LATEST_VERSION$ARCH.npk
|
||||
sudo -E python3 patch.py npk routeros-$LATEST_VERSION$ARCH.npk
|
||||
NPK_FILES=$(find ./all_packages/*.npk)
|
||||
for file in $NPK_FILES; do
|
||||
sudo -E python3 npk.py sign $file $file
|
||||
done
|
||||
sudo cp -f routeros-$LATEST_VERSION$ARCH.npk ./all_packages/routeros-$LATEST_VERSION$ARCH.npk
|
||||
sudo -E python3 npk.py create ./all_packages/gps-$LATEST_VERSION$ARCH.npk ./all_packages/option-$LATEST_VERSION$ARCH.npk option ./option.sfs -desc="busybox"
|
||||
sudo -E python3 npk.py create ./all_packages/gps-$LATEST_VERSION$ARCH.npk ./all_packages/python3-$LATEST_VERSION$ARCH.npk python3 ./python3.sfs -desc="python 3.11.13"
|
||||
cd ./all_packages
|
||||
sudo zip ../all_packages-${{ matrix.arch }}-$LATEST_VERSION.zip *.npk
|
||||
cd ..
|
||||
|
||||
- name: Cache refind
|
||||
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && env.RELEASE == 'true'
|
||||
|
||||
Binary file not shown.
BIN
busybox/busybox_arm
Normal file
BIN
busybox/busybox_arm
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
keygen/keygen_arm
Normal file
BIN
keygen/keygen_arm
Normal file
Binary file not shown.
32
patch.py
32
patch.py
@@ -24,7 +24,7 @@ def replace_key(old,new,data,name=''):
|
||||
data = replace_chunks(old_chunks, new_chunks, data,name)
|
||||
arch = os.getenv('ARCH') or 'x86'
|
||||
arch = arch.replace('-', '')
|
||||
if arch == 'arm64':
|
||||
if arch in ['arm64','arm']:
|
||||
old_chunks = [old[i:i+4] for i in range(0, len(old), 4)]
|
||||
new_chunks = [new[i:i+4] for i in range(0, len(new), 4)]
|
||||
old_bytes = old_chunks[4] + old_chunks[5] + old_chunks[2] + old_chunks[0] + old_chunks[1] + old_chunks[6] + old_chunks[7]
|
||||
@@ -32,9 +32,35 @@ def replace_key(old,new,data,name=''):
|
||||
if old_bytes in data:
|
||||
print(f'{name} public key patched {old[:16].hex().upper()}...')
|
||||
data = data.replace(old_bytes,new_bytes)
|
||||
old_codes = [bytes.fromhex('793583E2'),bytes.fromhex('FD3A83E2'),bytes.fromhex('193D83E2')]
|
||||
new_codes = [bytes.fromhex('FF34A0E3'),bytes.fromhex('753C83E2'),bytes.fromhex('FC3083E2')]
|
||||
old_codes = [bytes.fromhex('793583E2'),bytes.fromhex('FD3A83E2'),bytes.fromhex('193D83E2')] #0x1e400000+0xfd000+0x640
|
||||
new_codes = [bytes.fromhex('FF34A0E3'),bytes.fromhex('753C83E2'),bytes.fromhex('FC3083E2')] #0xff0075fc= 0xff000000+0x7500+0xfc
|
||||
data = replace_chunks(old_codes, new_codes, data,name)
|
||||
else:
|
||||
def conver_chunks(data:bytes):
|
||||
ret = [
|
||||
(data[2] << 16) | (data[1] << 8) | data[0] | ((data[3] << 24) & 0x03000000),
|
||||
(data[3] >> 2) | (data[4] << 6) | (data[5] << 14) | ((data[6] << 22) & 0x1C00000),
|
||||
(data[6] >> 3) | (data[7] << 5) | (data[8] << 13) | ((data[9] << 21) & 0x3E00000),
|
||||
(data[9] >> 5) | (data[10] << 3) | (data[11] << 11) | ((data[12] << 19) & 0x1F80000),
|
||||
(data[12] >> 6) | (data[13] << 2) | (data[14] << 10) | (data[15] << 18),
|
||||
data[16] | (data[17] << 8) | (data[18] << 16) | ((data[19] << 24) & 0x01000000),
|
||||
(data[19] >> 1) | (data[20] << 7) | (data[21] << 15) | ((data[22] << 23) & 0x03800000),
|
||||
(data[22] >> 3) | (data[23] << 5) | (data[24] << 13) | ((data[25] << 21) & 0x1E00000),
|
||||
(data[25] >> 4) | (data[26] << 4) | (data[27] << 12) | ((data[28] << 20) & 0x3F00000),
|
||||
(data[28] >> 6) | (data[29] << 2) | (data[30] << 10) | (data[31] << 18)
|
||||
]
|
||||
return [struct.pack('<I', x ) for x in ret]
|
||||
old_chunks = conver_chunks(old)
|
||||
new_chunks = conver_chunks(new)
|
||||
old_bytes = b''.join([v for i,v in enumerate(old_chunks) if i != 8])
|
||||
new_bytes = b''.join([v for i,v in enumerate(new_chunks) if i != 8])
|
||||
if old_bytes in data:
|
||||
print(f'{name} public key patched {old[:16].hex().upper()}...')
|
||||
data = data.replace(old_bytes,new_bytes)
|
||||
old_codes = [bytes.fromhex('713783E2'),bytes.fromhex('223A83E2'),bytes.fromhex('8D3F83E2')] #0x1C40000+0x22000+0x234
|
||||
new_codes = [bytes.fromhex('973303E3'),bytes.fromhex('DD3883E3'),bytes.fromhex('033483E3')] #0x03DD3397 = 0x3397|0x00DD0000|0x03000000
|
||||
data = replace_chunks(old_codes, new_codes, data,name)
|
||||
|
||||
return data
|
||||
|
||||
def patch_bzimage(data:bytes,key_dict:dict):
|
||||
|
||||
Reference in New Issue
Block a user