Compare commits

..

50 Commits

Author SHA1 Message Date
elseif
343fe653ee Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-24 14:37:08 +08:00
elseif
bfb4e91be7 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-24 14:19:57 +08:00
elseif
898d1c1789 Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-22 15:34:42 +08:00
elseif
e4167afbec Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-22 15:33:07 +08:00
elseif
aeaf99729f Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-22 15:27:06 +08:00
elseif
d125a063ce Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-22 15:22:40 +08:00
elseif
ce926f7cc9 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 17:45:20 +08:00
elseif
aea2da2a36 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 17:31:26 +08:00
elseif
c869dca3c1 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 17:23:14 +08:00
elseif
cbe8254d84 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 17:18:39 +08:00
elseif
331df17ee7 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 17:12:01 +08:00
elseif
35852182b2 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 16:30:46 +08:00
elseif
e0d1eb1a98 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 16:26:17 +08:00
elseif
0717a39c02 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 16:24:30 +08:00
elseif
4993be82a6 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 16:22:42 +08:00
elseif
0dbed4777f Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 16:17:23 +08:00
elseif
3b529862d1 Update README.md
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 15:43:29 +08:00
elseif
6da98653fc Update README_EN.md
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 15:43:02 +08:00
elseif
27e023fb28 Update README_EN.md
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 15:42:28 +08:00
elseif
df6b25a30e Update README.md
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 15:42:06 +08:00
elseif
60294067c7 Merge pull request #80 from emam06/patch-3
Update
2025-02-19 15:41:19 +08:00
elseif
d309253b06 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 11:12:54 +08:00
elseif
b3579cb363 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-19 11:09:18 +08:00
elseif
0f2c5e6081 Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-18 20:50:25 +08:00
elseif
8f59465bf0 Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-18 20:43:39 +08:00
elseif
736af6817b Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-18 20:33:03 +08:00
elseif
10a56eb673 Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-18 20:31:07 +08:00
elseif
6518dda504 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-18 15:42:28 +08:00
elseif
74e812fa2b Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-18 15:40:17 +08:00
elseif
810909828a Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-18 15:16:22 +08:00
elseif
49f4ad0a59 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-18 15:02:01 +08:00
elseif
ece607c8f7 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-18 15:01:10 +08:00
elseif
1426fc061a Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-17 12:44:05 +08:00
elseif
7579dadaea Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-17 12:29:48 +08:00
elseif
6b6669fb23 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-17 12:27:07 +08:00
elseif
5f603dcebc Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-11 17:47:22 +08:00
elseif
e1994f69d6 Update mikrotik_patch_6.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-07 13:43:33 +08:00
elseif
39af3326bd Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-07 03:39:14 +08:00
elseif
c657f2e736 Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-07 03:08:29 +08:00
elseif
a8dd672a66 Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-07 00:51:42 +08:00
elseif
cf01bbda4d Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-07 00:43:57 +08:00
elseif
1c9207d498 Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-07 00:40:47 +08:00
elseif
f1ed27cb52 Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-05 23:32:42 +08:00
elseif
8d38a80dd8 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-02-05 23:30:14 +08:00
elseif
f4af3671be Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-05 23:19:28 +08:00
elseif
2f0f0b1abb Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-05 23:01:27 +08:00
elseif
ea10a1a4c7 Update patch.py
Signed-off-by: elseif <elseif@live.cn>
2025-02-05 22:47:38 +08:00
emam06
bd03ecb963 Update
Signed-off-by: emam06 <egr7yco@gmail.com>
2025-01-27 15:17:41 +02:00
elseif
5b909283a0 Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-01-25 21:35:52 +08:00
elseif
289ea3a34f Update mikrotik_patch_7.yml
Signed-off-by: elseif <elseif@live.cn>
2025-01-25 03:15:17 +08:00
5 changed files with 137 additions and 48 deletions

View File

@@ -3,8 +3,8 @@ name: Patch Mikrotik RouterOS 6.x
on:
# push:
# branches: [ "main" ]
schedule:
- cron: "0 0 * * *"
# schedule:
# - cron: "0 0 * * *"
workflow_dispatch:
permissions:

View File

@@ -2,10 +2,36 @@ name: Patch Mikrotik RouterOS 7.x
on:
# push:
# branches: [ "main" ]
schedule:
- cron: "0 0 * * *"
# schedule:
# - cron: "0 0 * * *"
workflow_dispatch:
inputs:
arch:
description: 'Architecture (x86, arm64)'
required: true
default: 'x86'
type: choice
options:
- x86
- arm64
channel:
description: 'Channel (stable, testing)'
required: true
default: 'stable'
type: choice
options:
- stable
- testing
version:
description: "Version ('', 7.17, 7.17.1, 7.17.2,...)"
required: false
default: ''
type: string
buildtime:
description: "Build Time"
required: false
default: ''
type: string
permissions:
contents: write
@@ -35,15 +61,21 @@ jobs:
steps:
- name: Set build time
id: set_buildtime
run: echo "BUILD_TIME=$(date +'%s')" >> $GITHUB_OUTPUT
run: |
_BUILD_TIME=${{ github.event.inputs.buildtime }}
if [ -z "$_BUILD_TIME" ]; then
echo "BUILD_TIME=$(date +'%s')" >> $GITHUB_OUTPUT
else
echo "BUILD_TIME=$_BUILD_TIME" >> $GITHUB_OUTPUT
fi
Patch_RouterOS:
needs: Set_BuildTime
runs-on: ubuntu-22.04
strategy:
matrix:
arch: [x86,arm64]
channel: [stable, testing]
arch: ${{ fromJSON(format('["{0}"]', github.event.inputs.arch || 'x86')) }}
channel: ${{ fromJSON(format('["{0}"]', github.event.inputs.channel || 'stable')) }}
env:
TZ: 'Asia/Shanghai'
LATEST_VERSION: ""
@@ -61,7 +93,10 @@ jobs:
id: get_latest
run: |
echo $(uname -a)
LATEST_VERSION=$(wget -nv -O - https://${{ env.MIKRO_UPGRADE_URL }}/routeros/NEWESTa7.${{ matrix.channel }} | cut -d ' ' -f1)
LATEST_VERSION=${{ github.event.inputs.version }}
if [ -z "$_LATEST_VERSION" ]; then
LATEST_VERSION=$(wget -nv -O - https://${{ env.MIKRO_UPGRADE_URL }}/routeros/NEWESTa7.${{ matrix.channel }} | cut -d ' ' -f1)
fi
echo Latest Version:$LATEST_VERSION
if [ "${{ github.event_name }}" == "schedule" ]; then
_LATEST_VERSION=$(wget -nv -O - https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/NEWESTa7.${{ matrix.channel }} | cut -d ' ' -f1)
@@ -85,7 +120,17 @@ jobs:
ARCH='-arm64'
echo "ARCH=$ARCH" >> $GITHUB_ENV
fi
echo "{\"arch\": \"${{ matrix.arch }}\", \"channel\": \"${{ matrix.channel }}\", \"latest_version\": \"$LATEST_VERSION\",\"build_time\": \"$BUILD_TIME\"}" > latest_version_${{ matrix.arch }}_${{ matrix.channel }}.json
has_patched_npk=false
if wget -nv --spider https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/$LATEST_VERSION/routeros-$LATEST_VERSION$ARCH.npk; then
echo "RouterOS NPK file exists, attempting to download..."
if wget -nv -O routeros-$LATEST_VERSION$ARCH.npk https://${{ env.CUSTOM_UPGRADE_URL }}/routeros/$LATEST_VERSION/routeros-$LATEST_VERSION$ARCH.npk; then
echo "RouterOS NPK file downloaded successfully."
has_patched_npk=true
fi
fi
echo "has_patched_npk=$has_patched_npk" >> $GITHUB_OUTPUT
echo "{\"arch\": \"${{ matrix.arch }}\", \"channel\": \"${{ matrix.channel }}\", \"latest_version\": \"$LATEST_VERSION\",\"build_time\": \"$BUILD_TIME\",\"patched\": \"$has_patched_npk\"}" > latest_version_${{ matrix.arch }}_${{ matrix.channel }}.json
sudo apt-get update > /dev/null
- name: Upload artifacts
@@ -94,7 +139,7 @@ jobs:
with:
name: latest_version_${{ matrix.arch }}_${{ matrix.channel }}
path: latest_version_${{ matrix.arch }}_${{ matrix.channel }}.json
- name: Cache Squashfs
if: steps.get_latest.outputs.has_new_version == 'true'
id: cache-squashfs
@@ -140,7 +185,7 @@ jobs:
sudo rm -rf ./python
- name: Cache NetInstall ${{ env.LATEST_VERSION }}
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86'
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.get_latest.outputs.has_patched_npk == 'true'
id: cache-netinstall
uses: actions/cache@v4
with:
@@ -150,13 +195,13 @@ jobs:
key: netinstall-${{ env.LATEST_VERSION }}
- name: Get netinstall ${{ env.LATEST_VERSION }}
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.cache-netinstall.outputs.cache-hit != 'true'
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.cache-netinstall.outputs.cache-hit != 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
run: |
sudo wget -nv -O netinstall.zip https://download.mikrotik.com/routeros/$LATEST_VERSION/netinstall-$LATEST_VERSION.zip
sudo wget -nv -O netinstall.tar.gz https://download.mikrotik.com/routeros/$LATEST_VERSION/netinstall-$LATEST_VERSION.tar.gz
- name: Patch netinstall ${{ env.LATEST_VERSION }}
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86'
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.get_latest.outputs.has_patched_npk == 'true'
run: |
sudo unzip netinstall.zip
sudo -E python3 patch.py netinstall netinstall.exe
@@ -191,13 +236,17 @@ jobs:
sudo rsync -a ./iso/ ./new_iso/
sudo umount ./iso
sudo rm -rf ./iso
sudo mv ./new_iso/routeros-$LATEST_VERSION$ARCH.npk ./
sudo -E python3 patch.py npk routeros-$LATEST_VERSION$ARCH.npk
if [ "${{ steps.get_latest.outputs.has_patched_npk }}" == "false" ]; then
sudo mv ./new_iso/routeros-$LATEST_VERSION$ARCH.npk ./
sudo -E python3 patch.py npk routeros-$LATEST_VERSION$ARCH.npk
else
sudo -E python3 npk.py sign routeros-$LATEST_VERSION$ARCH.npk routeros-$LATEST_VERSION$ARCH.npk
fi
NPK_FILES=$(find ./new_iso/*.npk)
for file in $NPK_FILES; do
sudo -E python3 npk.py sign $file $file
done
sudo cp routeros-$LATEST_VERSION$ARCH.npk ./new_iso/
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"
@@ -246,7 +295,7 @@ jobs:
cd ..
- name: Cache refind
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86'
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.get_latest.outputs.has_patched_npk == 'true'
id: cache-refind
uses: actions/cache@v4
with:
@@ -254,11 +303,11 @@ jobs:
key: refind
- name: Get refind
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.cache-refind.outputs.cache-hit != 'true'
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.cache-refind.outputs.cache-hit != 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
run: sudo wget -nv -O refind-bin-0.14.2.zip https://nchc.dl.sourceforge.net/project/refind/0.14.2/refind-bin-0.14.2.zip
- name: Create install-image-${{ env.LATEST_VERSION }}.img
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86'
if: steps.get_latest.outputs.has_new_version == 'true' && matrix.arch == 'x86' && steps.get_latest.outputs.has_patched_npk == 'true'
run: |
sudo modprobe nbd
sudo apt-get install -y qemu-utils extlinux > /dev/null
@@ -296,7 +345,7 @@ jobs:
sudo rm ./install-image-$LATEST_VERSION.img
- 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' && steps.get_latest.outputs.has_patched_npk == 'true'
id: cache-chr-img
uses: actions/cache@v4
with:
@@ -305,7 +354,7 @@ jobs:
key: chr-${{ env.LATEST_VERSION }}-${{ matrix.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' && steps.get_latest.outputs.has_patched_npk == 'true'
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
@@ -313,7 +362,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' && steps.get_latest.outputs.has_patched_npk == 'true'
run: |
sudo modprobe nbd
sudo apt-get install -y qemu-utils > /dev/null
@@ -419,9 +468,14 @@ jobs:
- name: Upload Files
if: steps.get_latest.outputs.has_new_version == 'true'
run: |
sudo mkdir -p ./publish/$LATEST_VERSION
sudo cp CHANGELOG ./publish/$LATEST_VERSION/
sudo cp ./all_packages/*.npk ./publish/$LATEST_VERSION/
if [ "${{ steps.get_latest.outputs.has_patched_npk }}" == "false" ]; then
OUTDIR="$LATEST_VERSION-UNDONE"
else
OUTDIR="$LATEST_VERSION"
fi
sudo mkdir -p ./publish/$OUTDIR
sudo cp CHANGELOG ./publish/$OUTDIR/
sudo cp ./all_packages/*.npk ./publish/$OUTDIR/
sudo chown -R root:root ./publish/
sudo apt-get install -y lftp ssh sshpass > /dev/null 2>&1
sudo -E lftp -u ${{ secrets.SSH_USERNAME }},'${{ secrets.SSH_PASSWORD }}' sftp://${{ secrets.SSH_SERVER }}:${{ secrets.SSH_PORT }} <<EOF
@@ -439,7 +493,7 @@ jobs:
--data '{"purge_everything": true}'
- name: Delete Release tag ${{ env.LATEST_VERSION }} ${{ matrix.arch }}
if: steps.get_latest.outputs.has_new_version == 'true'
if: steps.get_latest.outputs.has_new_version == 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
run: |
HEADER="Authorization: token ${{ secrets.GITHUB_TOKEN }}"
RELEASE_INFO=$(curl -s -H $HEADER https://api.github.com/repos/${{ github.repository }}/releases/tags/$LATEST_VERSION$ARCH)
@@ -455,7 +509,7 @@ jobs:
fi
- name: Create Release tag ${{ env.LATEST_VERSION }} ${{ matrix.arch }}
if: steps.get_latest.outputs.has_new_version == 'true'
if: steps.get_latest.outputs.has_new_version == 'true' && steps.get_latest.outputs.has_patched_npk == 'true'
uses: softprops/action-gh-release@v2
with:
name: "RouterOS ${{ env.LATEST_VERSION }} ${{ matrix.arch }}"
@@ -484,13 +538,20 @@ jobs:
- name: Create Packages CSV File
run: |
sudo apt-get install ssh sshpass
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_SERVER }} "chown -R 32768:32768 /rw/disk/${{ secrets.SSH_DIRECTORY }}/"
for file in artifacts/latest_version_*.json; do
arch_channel=$(basename "$file" .json | sed 's/latest_version_//')
arch=$(echo "$arch_channel" | cut -d'_' -f1)
channel=$(echo "$arch_channel" | cut -d'_' -f2)
latest_version=$(jq -r '.latest_version' "$file")
build_time=$(jq -r '.build_time' "$file")
echo "Arch: $arch, Channel: $channel, Latest Version: $latest_version,Build Time: $build_time"
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_SERVER }} "echo $latest_version $build_time | tee /rw/disk/${{ secrets.SSH_DIRECTORY }}/NEWESTa7.$channel; /rw/disk/${{ secrets.SSH_DIRECTORY }}/packages.sh /rw/disk/${{ secrets.SSH_DIRECTORY }}/$latest_version"
if [ -f "$file" ]; then
arch=$(jq -r '.arch' "$file")
channel=$(jq -r '.channel' "$file")
latest_version=$(jq -r '.latest_version' "$file")
build_time=$(jq -r '.build_time' "$file")
has_patched_npk=$(jq -r '.patched' "$file")
echo "Arch: $arch, Channel: $channel, Latest Version: $latest_version,Build Time: $build_time,Has Patched NPK: $has_patched_npk"
if [ "$has_patched_npk" == "false" ]; then
OUTDIR="$latest_version-UNDONE"
else
OUTDIR="$latest_version"
fi
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_SERVER }} "echo $latest_version $build_time | tee /rw/disk/${{ secrets.SSH_DIRECTORY }}/NEWESTa7.$channel; /rw/disk/${{ secrets.SSH_DIRECTORY }}/packages.sh /rw/disk/${{ secrets.SSH_DIRECTORY }}/$OUTDIR"
fi
done
sshpass -p "${{ secrets.SSH_PASSWORD }}" ssh -o StrictHostKeyChecking=no -p ${{ secrets.SSH_PORT }} ${{ secrets.SSH_USERNAME }}@${{ secrets.SSH_SERVER }} "chown -R 32768:32768 /rw/disk/${{ secrets.SSH_DIRECTORY }}/"

View File

@@ -1,3 +1,5 @@
[![Patch Mikrotik RouterOS 6.x](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_6.yml/badge.svg)](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_6.yml)
[![Patch Mikrotik RouterOS 7.x](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_7.yml/badge.svg)](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_7.yml)
# MikroTik RouterOS Patch [[English](README_EN.md)]
### [[Discord](https://discord.gg/keV6MWQFtX)] [[Telegram](https://t.me/mikrotikpatch)] [[Keygen(Telegram Bot)](https://t.me/ROS_Keygen_Bot)]
@@ -50,3 +52,4 @@

View File

@@ -1,3 +1,5 @@
[![Patch Mikrotik RouterOS 6.x](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_6.yml/badge.svg)](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_6.yml)
[![Patch Mikrotik RouterOS 7.x](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_7.yml/badge.svg)](https://github.com/elseif/MikroTikPatch/actions/workflows/mikrotik_patch_7.yml)
# MikroTik RouterOS Patch [[中文](README.md)]
### [[Discord](https://discord.gg/keV6MWQFtX)] [[Telegram](https://t.me/mikrotikpatch)] [[Keygen(Telegram Bot)](https://t.me/ROS_Keygen_Bot)]
@@ -44,4 +46,3 @@

View File

@@ -1,7 +1,34 @@
import subprocess,lzma
import struct,os
import struct,os,re
from npk import NovaPackage,NpkPartID,NpkFileContainer
def replace_chunks(old_chunks,new_chunks,data,name):
pattern_parts = [re.escape(chunk) + b'(.{0,6})' for chunk in old_chunks[:-1]]
pattern_parts.append(re.escape(old_chunks[-1]))
pattern_bytes = b''.join(pattern_parts)
pattern = re.compile(pattern_bytes, flags=re.DOTALL)
def replace_match(match):
replaced = b''.join([new_chunks[i] + match.group(i+1) for i in range(len(new_chunks) - 1)])
replaced += new_chunks[-1]
print(f'{name} public key patched {b"".join(old_chunks)[:16].hex().upper()}...')
return replaced
return re.sub(pattern, replace_match, data)
def replace_key(old,new,data,name=''):
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)]
data = replace_chunks(old_chunks, new_chunks, data,name)
if os.environ['ARCH'] == '-arm64' and os.environ['LATEST_VERSION'] == '7.17.2':
old_bytes = old_chunks[4] + old_chunks[5] + old_chunks[2] + old_chunks[0] + old_chunks[1] + old_chunks[6] + old_chunks[7]
new_bytes = new_chunks[4] + new_chunks[5] + new_chunks[2] + new_chunks[0] + new_chunks[1] + new_chunks[6] + new_chunks[7]
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')]
data = replace_chunks(old_codes, new_codes, data,name)
return data
def patch_bzimage(data:bytes,key_dict:dict):
PE_TEXT_SECTION_OFFSET = 414
HEADER_PAYLOAD_OFFSET = 584
@@ -22,9 +49,7 @@ def patch_bzimage(data:bytes,key_dict:dict):
initramfs = initramfs[:cpio_offset2]
new_initramfs = initramfs
for old_public_key,new_public_key in key_dict.items():
if old_public_key in new_initramfs:
print(f'initramfs public key patched {old_public_key[:16].hex().upper()}...')
new_initramfs = new_initramfs.replace(old_public_key,new_public_key)
new_initramfs = replace_key(old_public_key,new_public_key,new_initramfs,'initramfs')
new_vmlinux = vmlinux.replace(initramfs,new_initramfs)
new_vmlinux_xz = lzma.compress(new_vmlinux,check=lzma.CHECK_CRC32,filters=[
{"id": lzma.FILTER_X86},
@@ -83,9 +108,7 @@ def patch_initrd_xz(initrd_xz:bytes,key_dict:dict,ljust=True):
initrd = lzma.decompress(initrd_xz)
new_initrd = initrd
for old_public_key,new_public_key in key_dict.items():
if old_public_key in new_initrd:
print(f'initrd public key patched {old_public_key[:16].hex().upper()}...')
new_initrd = new_initrd.replace(old_public_key,new_public_key)
new_initrd = replace_key(old_public_key,new_public_key,new_initrd,'initrd')
preset = 6
new_initrd_xz = lzma.compress(new_initrd,check=lzma.CHECK_CRC32,filters=[{"id": lzma.FILTER_LZMA2, "preset": preset }] )
while len(new_initrd_xz) > len(initrd_xz) and preset < 9:
@@ -254,14 +277,15 @@ def patch_kernel(data:bytes,key_dict):
def patch_squashfs(path,key_dict):
for root, dirs, files in os.walk(path):
for file in files:
if file =='loader':
continue
file = os.path.join(root,file)
if os.path.isfile(file):
data = open(file,'rb').read()
for old_public_key,new_public_key in key_dict.items():
if old_public_key in data:
print(f'{file} public key patched {old_public_key[:16].hex().upper()}...')
data = data.replace(old_public_key,new_public_key)
open(file,'wb').write(data)
_data = replace_key(old_public_key,new_public_key,data,file)
if _data != data:
open(file,'wb').write(_data)
url_dict = {
os.environ['MIKRO_LICENCE_URL'].encode():os.environ['CUSTOM_LICENCE_URL'].encode(),
os.environ['MIKRO_UPGRADE_URL'].encode():os.environ['CUSTOM_UPGRADE_URL'].encode(),