mirror of
https://github.com/elseif/MikroTikPatch.git
synced 2026-08-30 03:55:51 +00:00
Compare commits
23 Commits
7.24rc3-ar
...
7.24.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a76352efa | ||
|
|
ea54dcf295 | ||
|
|
beb4435dba | ||
|
|
2c77a67e7d | ||
|
|
66667fc2ed | ||
|
|
39ae5ca66d | ||
|
|
486d4afe26 | ||
|
|
f984370098 | ||
|
|
d13e050198 | ||
|
|
daca50dced | ||
|
|
c126421897 | ||
|
|
2a4ad51ca9 | ||
|
|
a988945f52 | ||
|
|
e94750a0d8 | ||
|
|
489427c34f | ||
|
|
f7a2316049 | ||
|
|
7410c6dc6b | ||
|
|
fc1d950da6 | ||
|
|
622ba70c2a | ||
|
|
4761e53917 | ||
|
|
74a6a9c8dd | ||
|
|
e29a43041c | ||
|
|
3dc5e43434 |
67
.github/workflows/build_docker.yml
vendored
67
.github/workflows/build_docker.yml
vendored
@@ -7,14 +7,19 @@ on:
|
||||
required: false
|
||||
default: ''
|
||||
type: string
|
||||
|
||||
force:
|
||||
description: "Force rebuild even if version already exists"
|
||||
required: false
|
||||
default: false
|
||||
type: boolean
|
||||
|
||||
permissions:
|
||||
packages: write
|
||||
jobs:
|
||||
Prepare:
|
||||
runs-on: ubuntu-24.04
|
||||
outputs:
|
||||
MATRIX: ${{ steps.get_versions.outputs.MATRIX }}
|
||||
MATRIX: ${{ steps.filter_matrix.outputs.MATRIX }}
|
||||
steps:
|
||||
- name: Get versions and generate matrix
|
||||
id: get_versions
|
||||
@@ -51,13 +56,53 @@ jobs:
|
||||
echo "Generated matrix: $MATRIX"
|
||||
echo "MATRIX=$MATRIX" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Filter already-published versions from matrix
|
||||
id: filter_matrix
|
||||
env:
|
||||
IMAGE: "ghcr.io/${{ github.repository_owner }}/chr"
|
||||
FORCE: ${{ github.event.inputs.force == 'true' }}
|
||||
run: |
|
||||
MATRIX='${{ steps.get_versions.outputs.MATRIX }}'
|
||||
if [ "$FORCE" = "true" ]; then
|
||||
echo "Force mode enabled, skipping version existence check."
|
||||
FILTERED="$MATRIX"
|
||||
else
|
||||
FILTERED='[]'
|
||||
while read -r row; do
|
||||
VERSION=$(echo "$row" | jq -r '.version')
|
||||
CHANNEL=$(echo "$row" | jq -r '.channel')
|
||||
|
||||
set +e
|
||||
docker manifest inspect "${IMAGE}:${VERSION}" >/dev/null 2>&1
|
||||
RET=$?
|
||||
set -e
|
||||
|
||||
if [ "$RET" -eq 0 ]; then
|
||||
echo "Skipping already published version: ${VERSION}"
|
||||
else
|
||||
FILTERED=$(echo "$FILTERED" | jq -c --arg VERSION "$VERSION" --arg CHANNEL "$CHANNEL" '. + [{"version": $VERSION, "channel": $CHANNEL}]')
|
||||
fi
|
||||
done < <(echo "$MATRIX" | jq -c '.[]')
|
||||
fi
|
||||
|
||||
echo "Filtered matrix: $FILTERED"
|
||||
echo "MATRIX=$FILTERED" >> "$GITHUB_OUTPUT"
|
||||
|
||||
Build:
|
||||
if: needs.Prepare.outputs.MATRIX != '[]'
|
||||
runs-on: ubuntu-24.04
|
||||
needs: Prepare
|
||||
strategy:
|
||||
max-parallel: 1
|
||||
matrix:
|
||||
include: ${{ fromJson(needs.Prepare.outputs.MATRIX) }}
|
||||
include: ${{ fromJson(needs.Prepare.outputs.MATRIX != '[]' && needs.Prepare.outputs.MATRIX || '[{"version":"__NO_BUILD__","channel":""}]') }}
|
||||
env:
|
||||
TZ: 'Asia/Shanghai'
|
||||
VERSION: ${{ matrix.version }}
|
||||
@@ -72,6 +117,13 @@ jobs:
|
||||
echo "Version: ${{ env.VERSION }}"
|
||||
echo "Channel: ${{ env.CHANNEL }}"
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Download CHR image
|
||||
run: |
|
||||
# x86 架构
|
||||
@@ -79,6 +131,7 @@ jobs:
|
||||
wget -nv -O "amd64/chr-$VERSION.img.zip" \
|
||||
"https://github.com/elseif/MikroTikPatch/releases/download/$VERSION/chr-$VERSION-legacy-bios.img.zip"
|
||||
unzip "amd64/chr-$VERSION.img.zip" -d "amd64/"
|
||||
mv "amd64/chr-$VERSION-legacy-bios.img" "amd64/chr.img"
|
||||
rm "amd64/chr-$VERSION.img.zip"
|
||||
|
||||
# arm64 架构
|
||||
@@ -86,6 +139,7 @@ jobs:
|
||||
wget -nv -O "arm64/chr-$VERSION-arm64.img.zip" \
|
||||
"https://github.com/elseif/MikroTikPatch/releases/download/$VERSION-arm64/chr-$VERSION-arm64.img.zip"
|
||||
unzip "arm64/chr-$VERSION-arm64.img.zip" -d "arm64/"
|
||||
mv "arm64/chr-$VERSION-arm64.img" "arm64/chr.img"
|
||||
rm "arm64/chr-$VERSION-arm64.img.zip"
|
||||
|
||||
ls -la amd64/ arm64/
|
||||
@@ -185,13 +239,6 @@ jobs:
|
||||
ENTRYPOINT ["/start.sh"]
|
||||
EOF
|
||||
|
||||
- name: Log in to GitHub Container Registry
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v4
|
||||
|
||||
|
||||
36
.github/workflows/main.yml
vendored
36
.github/workflows/main.yml
vendored
@@ -35,25 +35,25 @@ jobs:
|
||||
release: true
|
||||
secrets: inherit
|
||||
|
||||
Patch_Testing_V7:
|
||||
if: |
|
||||
(github.event_name == 'schedule') ||
|
||||
(github.event_name == 'workflow_dispatch' && (github.event.inputs.version == 'all' || github.event.inputs.version == 'v7'))
|
||||
uses: ./.github/workflows/patch_v7.yml
|
||||
with:
|
||||
channel: testing
|
||||
release: true
|
||||
secrets: inherit
|
||||
# Patch_Testing_V7:
|
||||
# if: |
|
||||
# (github.event_name == 'schedule') ||
|
||||
# (github.event_name == 'workflow_dispatch' && (github.event.inputs.version == 'all' || github.event.inputs.version == 'v7'))
|
||||
# uses: ./.github/workflows/patch_v7.yml
|
||||
# with:
|
||||
# channel: testing
|
||||
# release: true
|
||||
# secrets: inherit
|
||||
|
||||
Patch_Development_V7:
|
||||
if: |
|
||||
(github.event_name == 'schedule') ||
|
||||
(github.event_name == 'workflow_dispatch' && (github.event.inputs.version == 'all' || github.event.inputs.version == 'v7'))
|
||||
uses: ./.github/workflows/patch_v7.yml
|
||||
with:
|
||||
channel: development
|
||||
release: true
|
||||
secrets: inherit
|
||||
# Patch_Development_V7:
|
||||
# if: |
|
||||
# (github.event_name == 'schedule') ||
|
||||
# (github.event_name == 'workflow_dispatch' && (github.event.inputs.version == 'all' || github.event.inputs.version == 'v7'))
|
||||
# uses: ./.github/workflows/patch_v7.yml
|
||||
# with:
|
||||
# channel: development
|
||||
# release: true
|
||||
# secrets: inherit
|
||||
|
||||
Patch_Stable_V6:
|
||||
if: |
|
||||
|
||||
154
.github/workflows/patch_v7.yml
vendored
154
.github/workflows/patch_v7.yml
vendored
@@ -10,8 +10,8 @@ on:
|
||||
options:
|
||||
- stable
|
||||
- long-term
|
||||
- testing
|
||||
- development
|
||||
# - testing
|
||||
# - development
|
||||
arch:
|
||||
description: 'Architecture (x86, arm64)'
|
||||
required: true
|
||||
@@ -378,6 +378,114 @@ jobs:
|
||||
if: matrix.arch == 'x86' && steps.cache-refind.outputs.cache-hit != 'true'
|
||||
run: wget -nv -O $BUILD_DIR/refind-bin-0.14.2.zip https://downloads.sourceforge.net/project/refind/0.14.2/refind-bin-0.14.2.zip
|
||||
|
||||
|
||||
- name: Build Alpine LiveCD
|
||||
if: matrix.arch == 'x86'
|
||||
run: |
|
||||
set -e
|
||||
YAML_URL="https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/latest-releases.yaml"
|
||||
ROOTFS_FILE=$(curl -sL "$YAML_URL" | grep -m1 'alpine-minirootfs.*\.tar\.gz' | awk '{print $NF}' | tr -d '"')
|
||||
echo "$ROOTFS_FILE"
|
||||
ROOTFS_URL="https://dl-cdn.alpinelinux.org/alpine/latest-stable/releases/x86_64/$ROOTFS_FILE"
|
||||
ROOTFS_DIR=$BUILD_DIR/rootfs
|
||||
mkdir -p $ROOTFS_DIR
|
||||
curl -# -L "$ROOTFS_URL" | tar -xzC $ROOTFS_DIR
|
||||
|
||||
sudo mount -v --bind /dev $ROOTFS_DIR/dev
|
||||
sudo mount -vt sysfs sysfs $ROOTFS_DIR/sys
|
||||
sudo mount -vt proc proc $ROOTFS_DIR/proc
|
||||
|
||||
cat << 'EOF' > $ROOTFS_DIR/etc/network/interfaces
|
||||
auto lo
|
||||
iface lo inet loopback
|
||||
auto eth0
|
||||
iface eth0 inet dhcp
|
||||
EOF
|
||||
|
||||
cat << 'EOF' > $ROOTFS_DIR/etc/inittab
|
||||
# /etc/inittab
|
||||
::sysinit:/sbin/openrc sysinit
|
||||
::sysinit:/sbin/openrc boot
|
||||
::wait:/sbin/openrc default
|
||||
tty1::respawn:/sbin/agetty --autologin root tty1 linux
|
||||
tty2::respawn:/sbin/agetty --autologin root tty2 linux
|
||||
tty3::respawn:/sbin/agetty --autologin root tty3 linux
|
||||
tty4::respawn:/sbin/agetty --autologin root tty4 linux
|
||||
ttyS0::respawn:/sbin/agetty --autologin root ttyS0 linux
|
||||
::ctrlaltdel:/sbin/reboot
|
||||
::shutdown:/sbin/openrc shutdown
|
||||
EOF
|
||||
|
||||
cp ./install_routeros.sh $ROOTFS_DIR/root/install_routeros.sh
|
||||
chmod +x $ROOTFS_DIR/root/install_routeros.sh
|
||||
cat << 'EOF' > $ROOTFS_DIR/root/.zprofile
|
||||
if [ -x /root/install_routeros.sh ]; then
|
||||
/root/install_routeros.sh
|
||||
fi
|
||||
EOF
|
||||
cp ./npkextract/npkextract $ROOTFS_DIR/bin/npkextract
|
||||
chmod +x $ROOTFS_DIR/bin/npkextract
|
||||
|
||||
cat << 'EOF' | sudo chroot $ROOTFS_DIR /usr/bin/env PATH=/usr/bin:/bin:/usr/sbin:/sbin /bin/sh
|
||||
set -e
|
||||
echo "nameserver 1.1.1.1" > /etc/resolv.conf
|
||||
apk update
|
||||
apk upgrade
|
||||
apk add alpine-base openrc busybox-mdev-openrc dhcpcd curl ca-certificates linux-lts linux-firmware-none
|
||||
apk add bash dialog sgdisk dosfstools e2fsprogs util-linux parted
|
||||
apk add zsh zsh-syntax-highlighting zsh-autosuggestions coreutils ncurses iproute2
|
||||
|
||||
rc-update add devfs sysinit
|
||||
rc-update add dmesg sysinit
|
||||
rc-update add mdev sysinit
|
||||
rc-update add hwdrivers sysinit
|
||||
rc-update add acpid boot
|
||||
rc-update add hostname boot
|
||||
rc-update add hwclock boot
|
||||
rc-update add modules boot
|
||||
rc-update add sysctl boot
|
||||
rc-update add bootmisc boot
|
||||
rc-update add dhcpcd boot
|
||||
rc-update add networking default
|
||||
|
||||
curl -o /root/.zshrc https://gitlab.com/kalilinux/packages/kali-defaults/-/raw/kali/master/etc/skel/.zshrc
|
||||
sed -i 's/^PROMPT_ALTERNATIVE=twoline/PROMPT_ALTERNATIVE=oneline/' /root/.zshrc
|
||||
sed -i 's/^NEWLINE_BEFORE_PROMPT=yes/NEWLINE_BEFORE_PROMPT=no/' /root/.zshrc
|
||||
sed -i 's|/usr/share/zsh-syntax-highlighting|/usr/share/zsh/plugins/zsh-syntax-highlighting|g' /root/.zshrc
|
||||
sed -i 's|/usr/share/zsh-autosuggestions|/usr/share/zsh/plugins/zsh-autosuggestions|g' /root/.zshrc
|
||||
|
||||
sed -i 's|^root:\(.*\):/bin/sh$|root:\1:/bin/zsh|' /etc/passwd
|
||||
sed -i 's/^root:.*/root:::0:::::/' /etc/shadow
|
||||
echo "" > /etc/motd
|
||||
sed -i 's/^features=.*/features="ata base cdrom network scsi nvme ext2 usb virtio"/' /etc/mkinitfs/mkinitfs.conf
|
||||
KERNEL_VERSION=$(ls /lib/modules | head -1)
|
||||
mkinitfs -k -t /tmp "$KERNEL_VERSION"
|
||||
rm -rf /lib/modules
|
||||
mv /tmp/lib/modules /lib
|
||||
depmod "$KERNEL_VERSION"
|
||||
ln -sf sbin/init /init
|
||||
|
||||
apk cache clean
|
||||
EOF
|
||||
|
||||
sudo umount -v $ROOTFS_DIR/dev
|
||||
sudo umount -v $ROOTFS_DIR/sys
|
||||
sudo umount -v $ROOTFS_DIR/proc
|
||||
|
||||
cp $ROOTFS_DIR/boot/vmlinuz-* $BUILD_DIR/vmlinuz
|
||||
|
||||
sudo rm -rf $ROOTFS_DIR/tmp/*
|
||||
sudo rm -rf $ROOTFS_DIR/boot/*
|
||||
sudo rm -rf $ROOTFS_DIR/var/cache/*
|
||||
|
||||
(cd "$ROOTFS_DIR" && sudo find . -print0 | sudo cpio --owner=root:root --null -H newc -o 2>/dev/null | xz -C crc32 -v9eT0 > $BUILD_DIR/initramfs.xz)
|
||||
sudo rm -rf $ROOTFS_DIR
|
||||
|
||||
size=$(stat -c %s "$BUILD_DIR/vmlinuz")
|
||||
printf "vmlinuz size : %d bytes (%.1f MB)\n" "$size" "$(echo "scale=1; $size/1024/1024" | bc)"
|
||||
size=$(stat -c %s "$BUILD_DIR/initramfs.xz")
|
||||
printf "initramfs size : %d bytes (%.1f MB)\n" "$size" "$(echo "scale=1; $size/1024/1024" | bc)"
|
||||
|
||||
- name: Create ISO & INSTALL image files
|
||||
run: |
|
||||
set -e
|
||||
@@ -395,9 +503,8 @@ jobs:
|
||||
sudo mount -o loop $BUILD_DIR/new_iso/efiboot.img $BUILD_DIR/efiboot
|
||||
python3 patch.py kernel $BUILD_DIR/efiboot/linux.x86_64 -O $BUILD_DIR/new_iso/isolinux/linux
|
||||
sudo umount $BUILD_DIR/efiboot
|
||||
#修改为16M,减小镜像体积
|
||||
rm -f $BUILD_DIR/new_iso/efiboot.img
|
||||
truncate --size 16M $BUILD_DIR/new_iso/efiboot.img
|
||||
truncate --size 64M $BUILD_DIR/new_iso/efiboot.img
|
||||
mkfs.vfat -n "Boot" $BUILD_DIR/new_iso/efiboot.img
|
||||
sudo mount -o loop,uid=$(id -u),gid=$(id -g) $BUILD_DIR/new_iso/efiboot.img $BUILD_DIR/efiboot
|
||||
mkdir -p $BUILD_DIR/efiboot/EFI/BOOT
|
||||
@@ -412,11 +519,32 @@ jobs:
|
||||
loader /linux.x86_64
|
||||
options "load_ramdisk=1 root=/dev/ram0 -install -cdrom debug"
|
||||
}
|
||||
menuentry "Alpine Linux LiveCD" {
|
||||
loader /vmlinuz
|
||||
initrd /initramfs.xz
|
||||
options "debug"
|
||||
}
|
||||
default_selection /EFI/BOOT/BOOTX64.EFI
|
||||
EOF
|
||||
cp -v $BUILD_DIR/new_iso/isolinux/linux $BUILD_DIR/efiboot/linux.x86_64
|
||||
cp -v $BUILD_DIR/vmlinuz $BUILD_DIR/efiboot/vmlinuz
|
||||
cp -v $BUILD_DIR/initramfs.xz $BUILD_DIR/efiboot/initramfs.xz
|
||||
sync
|
||||
sudo umount $BUILD_DIR/efiboot
|
||||
tee $BUILD_DIR/new_iso/isolinux/isolinux.cfg > /dev/null << 'EOF'
|
||||
default system
|
||||
timeout 50
|
||||
prompt 1
|
||||
label system
|
||||
kernel linux
|
||||
append load_ramdisk=1 -install -cdrom debug
|
||||
label alpine
|
||||
kernel vmlinuz
|
||||
append initrd=initramfs.xz debug
|
||||
EOF
|
||||
cp -v $BUILD_DIR/vmlinuz $BUILD_DIR/new_iso/isolinux/vmlinuz
|
||||
cp -v $BUILD_DIR/initramfs.xz $BUILD_DIR/new_iso/isolinux/initramfs.xz
|
||||
|
||||
xorriso -as mkisofs -o $PUBLISH_DIR/mikrotik-$VERSION$ARCH_EXT.iso \
|
||||
-V 'MikroTik' \
|
||||
-publisher "WWW.MIKROTIK.COM" \
|
||||
@@ -463,9 +591,9 @@ jobs:
|
||||
EOF
|
||||
tee $BUILD_DIR/install/syslinux.cfg > /dev/null << 'EOF'
|
||||
default system
|
||||
LABEL system
|
||||
KERNEL linux
|
||||
APPEND load_ramdisk=1 -install -hdd
|
||||
label system
|
||||
kernel linux
|
||||
append load_ramdisk=1 -install -hdd
|
||||
EOF
|
||||
NPK_FILES=($(find $BUILD_DIR/new_iso/*.npk))
|
||||
for ((i=1; i<=${#NPK_FILES[@]}; i++))
|
||||
@@ -623,7 +751,7 @@ jobs:
|
||||
truncate --size 128M $BUILD_DIR/chr-$VERSION$ARCH_EXT.img
|
||||
sgdisk \
|
||||
--zap-all \
|
||||
--set-alignment=8 \
|
||||
--set-alignment=1 \
|
||||
--new=1:34:+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" \
|
||||
--new=2:0:0 --typecode=2:8300 --change-name=2:"RouterOS" \
|
||||
--gpttombr=1:2 \
|
||||
@@ -632,7 +760,7 @@ jobs:
|
||||
printf '\x01' | dd of=$BUILD_DIR/mbr.bin bs=1 count=1 seek=336 conv=notrunc
|
||||
sgdisk \
|
||||
--zap-all \
|
||||
--set-alignment=8 \
|
||||
--set-alignment=1 \
|
||||
--new=1:34:+32M --typecode=1:EF00 --change-name=1:"RouterOS Boot" \
|
||||
--new=2:0:0 --typecode=2:8300 --change-name=2:"RouterOS" \
|
||||
$BUILD_DIR/chr-$VERSION$ARCH_EXT.img
|
||||
@@ -699,7 +827,7 @@ jobs:
|
||||
truncate --size 128M $BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img
|
||||
sgdisk \
|
||||
--zap-all \
|
||||
--set-alignment=8 \
|
||||
--set-alignment=1 \
|
||||
--new=1:34:+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" --attributes=1:set:2 \
|
||||
--new=2:0:-4096 --typecode=2:8300 --change-name=2:"RouterOS" \
|
||||
--gpttombr=1:2 \
|
||||
@@ -710,7 +838,7 @@ jobs:
|
||||
printf '\x80' | sudo dd of=$BUILD_DIR/mbr.bin bs=1 count=1 seek=446 conv=notrunc
|
||||
sgdisk \
|
||||
--zap-all \
|
||||
--set-alignment=8 \
|
||||
--set-alignment=1 \
|
||||
--new=1:34:+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" --attributes=1:set:2 \
|
||||
--new=2:0:-4096 --typecode=2:8300 --change-name=2:"RouterOS" \
|
||||
$BUILD_DIR/chr-$VERSION$ARCH_EXT-legacy-bios.img
|
||||
@@ -782,7 +910,7 @@ jobs:
|
||||
truncate --size 128M $BUILD_DIR/chr-$VERSION$ARCH_EXT.img
|
||||
sgdisk \
|
||||
--zap-all \
|
||||
--set-alignment=8 \
|
||||
--set-alignment=1 \
|
||||
--new=1:34:+32M --typecode=1:8300 --change-name=1:"RouterOS Boot" \
|
||||
--new=2:0:0 --typecode=2:8300 --change-name=2:"RouterOS" \
|
||||
--gpttombr=1:2 \
|
||||
@@ -791,7 +919,7 @@ jobs:
|
||||
printf '\x01' | dd of=$BUILD_DIR/mbr.bin bs=1 count=1 seek=336 conv=notrunc
|
||||
sgdisk \
|
||||
--zap-all \
|
||||
--set-alignment=8 \
|
||||
--set-alignment=1 \
|
||||
--new=1:34:+32M --typecode=1:EF00 --change-name=1:"RouterOS Boot" \
|
||||
--new=2:0:0 --typecode=2:8300 --change-name=2:"RouterOS" \
|
||||
$BUILD_DIR/chr-$VERSION$ARCH_EXT.img
|
||||
|
||||
Binary file not shown.
Binary file not shown.
10
index.html
10
index.html
@@ -442,9 +442,9 @@
|
||||
|
||||
// Fetch latest version numbers from MikroTik servers
|
||||
const loadingOverlay = document.getElementById("loading");
|
||||
const [routeros7_stable, routeros7_testing, routeros6_longterm, routeros6_stable] = await Promise.all([
|
||||
const [routeros7_stable, routeros7_longterm, routeros6_longterm, routeros6_stable] = await Promise.all([
|
||||
fetch_latest_versions(`https://upgrade.mikrotik.ltd/routeros/NEWESTa7.stable?ts=${Date.now()}`, "7.19.4"),
|
||||
fetch_latest_versions(`https://upgrade.mikrotik.ltd/routeros/NEWESTa7.testing?ts=${Date.now()}`, "7.20rc1"),
|
||||
fetch_latest_versions(`https://upgrade.mikrotik.ltd/routeros/NEWESTa7.long-term?ts=${Date.now()}`, "7.20rc1"),
|
||||
fetch_latest_versions(`https://upgrade.mikrotik.ltd/routeros/NEWEST6.long-term?ts=${Date.now()}`, "6.49.18"),
|
||||
fetch_latest_versions(`https://upgrade.mikrotik.ltd/routeros/NEWEST6.stable?ts=${Date.now()}`, "6.49.19"),
|
||||
]);
|
||||
@@ -456,7 +456,7 @@
|
||||
const downloads =[
|
||||
{
|
||||
title:"RouterOS v7",
|
||||
versions:[ { title:"Stable", version:routeros7_stable }, { title:"Testing", version:routeros7_testing } ],
|
||||
versions:[ { title:"Long-Term", version:routeros7_longterm },{ title:"Stable", version:routeros7_stable } ],
|
||||
groups: [
|
||||
{ title:"ARM64 / AMPERE", arch:"arm64", downloads:[ { title:"Main package", type:"main" }, { title:"Extra packages", type:"extra" }, { title:"ISO image for AMPERE", type:"iso" } ] },
|
||||
{ title:"X86", arch:"x86", downloads:[ { title:"Main package", type:"main" }, { title:"Extra packages", type:"extra" }, { title:"CD Image", type:"iso" }, { title:"Install image", type:"install" } ] },
|
||||
@@ -472,7 +472,7 @@
|
||||
},
|
||||
{
|
||||
title:"Cloud Hosted Router",
|
||||
versions:[ { title:"Long-Term", version:routeros6_longterm }, { title:"Stable", version:routeros6_stable }, { title:"Stable", version:routeros7_stable }, { title:"Testing", version:routeros7_testing } ],
|
||||
versions:[ { title:"Long-Term", version:routeros6_longterm }, { title:"Stable", version:routeros6_stable }, { title:"Long-Term", version:routeros7_longterm }, { title:"Stable", version:routeros7_stable } ],
|
||||
groups:[
|
||||
{ title:"X86", arch:"x86", downloads:[ { title:"Main package", type:"main" }, { title:"Extra packages", type:"extra" }, { title:"VHDX image", type:"vhdx" }, { title:"VMDK image", type:"vmdk" }, { title:"VDI image", type:"vdi" }, { title:"VirtualPC image", type:"vhd" }, { title:"Raw disk image", type:"img" }, { title:"OVA template", type:"ova" } ] },
|
||||
{ title:"ARM64 / AMPERE", arch:"arm64", downloads:[ { title:"Main package", type:"main" }, { title:"Extra packages", type:"extra" }, { title:"VHDX image", type:"vhdx" }, { title:"VMDK image", type:"vmdk" }, { title:"VDI image", type:"vdi" }, { title:"VirtualPC image", type:"vhd" }, { title:"Raw disk image", type:"img" } ] }
|
||||
@@ -709,8 +709,8 @@
|
||||
|
||||
// Generate version selection buttons
|
||||
versionBtnsContainer.innerHTML = `
|
||||
<button data-version="${routeros7_longterm}" class="px-3 py-1.5 text-sm font-medium rounded-md hover:bg-blue-200 dark:hover:bg-gray-600 transition-all">v7 Long-Term</button>
|
||||
<button data-version="${routeros7_stable}" class="px-3 py-1.5 text-sm font-medium rounded-md hover:bg-blue-200 dark:hover:bg-gray-600 transition-all">v7 Stable</button>
|
||||
<button data-version="${routeros7_testing}" class="px-3 py-1.5 text-sm font-medium rounded-md hover:bg-blue-200 dark:hover:bg-gray-600 transition-all">v7 Testing</button>
|
||||
<button data-version="${routeros6_longterm}" class="px-3 py-1.5 text-sm font-medium rounded-md hover:bg-blue-200 dark:hover:bg-gray-600 transition-all">v6 Long-Term</button>
|
||||
<button data-version="${routeros6_stable}" class="px-3 py-1.5 text-sm font-medium rounded-md hover:bg-blue-200 dark:hover:bg-gray-600 transition-all">v6 Stable</button>
|
||||
`;
|
||||
|
||||
1088
install_routeros.sh
Normal file
1088
install_routeros.sh
Normal file
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
39
npkextract/Makefile
Normal file
39
npkextract/Makefile
Normal file
@@ -0,0 +1,39 @@
|
||||
TOOLCHAIN_DIR ?= $(HOME)/musl-toolchains/i686-linux-musl-cross
|
||||
CROSS_COMPILE ?= $(TOOLCHAIN_DIR)/bin/i686-linux-musl-
|
||||
|
||||
CC = $(CROSS_COMPILE)gcc
|
||||
STRIP = $(CROSS_COMPILE)strip
|
||||
|
||||
TARGET = npkextract
|
||||
SRC = npkextract.c
|
||||
OBJ = $(SRC:.c=.o)
|
||||
|
||||
CFLAGS ?= -O2 -Wall -Wextra -D_GNU_SOURCE
|
||||
CFLAGS += -static -m32
|
||||
LDFLAGS += -static -s
|
||||
|
||||
|
||||
.PHONY: all clean info
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJ)
|
||||
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^
|
||||
@$(STRIP) --strip-all $(TARGET) 2>/dev/null || true
|
||||
@echo "=========================================================="
|
||||
@echo " Successfully built static binary: $(TARGET)"
|
||||
@ls -lh $(TARGET)
|
||||
@file $(TARGET) 2>/dev/null || true
|
||||
@echo "=========================================================="
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
info:
|
||||
@echo "Compiler: $(CC)"
|
||||
@echo "Strip: $(STRIP)"
|
||||
@echo "CFLAGS: $(CFLAGS)"
|
||||
@echo "LDFLAGS: $(LDFLAGS)"
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJ)
|
||||
BIN
npkextract/npkextract
Normal file
BIN
npkextract/npkextract
Normal file
Binary file not shown.
426
npkextract/npkextract.c
Normal file
426
npkextract/npkextract.c
Normal file
@@ -0,0 +1,426 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include <utime.h>
|
||||
|
||||
typedef struct {
|
||||
const unsigned char *source;
|
||||
size_t source_len;
|
||||
size_t tag;
|
||||
unsigned int bitcount;
|
||||
unsigned char *dest;
|
||||
size_t dest_len;
|
||||
size_t dest_cap;
|
||||
} TINF_DATA;
|
||||
|
||||
typedef struct {
|
||||
unsigned short table[16];
|
||||
unsigned short trans[288];
|
||||
} TINF_TREE;
|
||||
|
||||
static const unsigned char tinf_default_length_bits[30] = {
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 0, 127
|
||||
};
|
||||
|
||||
static const unsigned short tinf_default_length_base[30] = {
|
||||
3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0
|
||||
};
|
||||
|
||||
static const unsigned char tinf_default_dist_bits[30] = {
|
||||
0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13
|
||||
};
|
||||
|
||||
static const unsigned short tinf_default_dist_base[30] = {
|
||||
1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577
|
||||
};
|
||||
|
||||
static const unsigned char tinf_clcidx[19] = {
|
||||
16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15
|
||||
};
|
||||
|
||||
static unsigned int tinf_getbit(TINF_DATA *d) {
|
||||
if (!d->bitcount--) {
|
||||
d->tag = d->source_len ? *d->source++ : 0;
|
||||
if (d->source_len) d->source_len--;
|
||||
d->bitcount = 7;
|
||||
}
|
||||
unsigned int bit = d->tag & 1;
|
||||
d->tag >>= 1;
|
||||
return bit;
|
||||
}
|
||||
|
||||
static unsigned int tinf_read_bits(TINF_DATA *d, int num, int base) {
|
||||
unsigned int val = 0;
|
||||
if (num) {
|
||||
unsigned int limit = 1 << num;
|
||||
unsigned int mask;
|
||||
for (mask = 1; mask < limit; mask <<= 1) {
|
||||
if (tinf_getbit(d)) val += mask;
|
||||
}
|
||||
}
|
||||
return val + base;
|
||||
}
|
||||
|
||||
static void tinf_build_tree(TINF_TREE *t, const unsigned char *lengths, unsigned int num) {
|
||||
unsigned short offs[16];
|
||||
unsigned int i, sum = 0;
|
||||
|
||||
for (i = 0; i < 16; ++i) t->table[i] = 0;
|
||||
for (i = 0; i < num; ++i) t->table[lengths[i]]++;
|
||||
t->table[0] = 0;
|
||||
|
||||
for (i = 0; i < 16; ++i) {
|
||||
offs[i] = sum;
|
||||
sum += t->table[i];
|
||||
}
|
||||
|
||||
for (i = 0; i < num; ++i) {
|
||||
if (lengths[i]) t->trans[offs[lengths[i]]++] = i;
|
||||
}
|
||||
}
|
||||
|
||||
static int tinf_decode_symbol(TINF_DATA *d, const TINF_TREE *t) {
|
||||
int sum = 0, cur = 0, len = 0;
|
||||
do {
|
||||
cur = 2 * cur + tinf_getbit(d);
|
||||
len++;
|
||||
sum += t->table[len];
|
||||
cur -= t->table[len];
|
||||
} while (cur >= 0);
|
||||
return t->trans[sum + cur];
|
||||
}
|
||||
|
||||
static void tinf_build_fixed_trees(TINF_TREE *lt, TINF_TREE *dt) {
|
||||
unsigned char lengths[288];
|
||||
int i;
|
||||
for (i = 0; i <= 143; ++i) lengths[i] = 8;
|
||||
for (; i <= 255; ++i) lengths[i] = 9;
|
||||
for (; i <= 279; ++i) lengths[i] = 7;
|
||||
for (; i <= 287; ++i) lengths[i] = 8;
|
||||
tinf_build_tree(lt, lengths, 288);
|
||||
for (i = 0; i < 32; ++i) lengths[i] = 5;
|
||||
tinf_build_tree(dt, lengths, 32);
|
||||
}
|
||||
|
||||
static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) {
|
||||
while (1) {
|
||||
int sym = tinf_decode_symbol(d, lt);
|
||||
if (sym == 256) return 0;
|
||||
|
||||
if (sym < 256) {
|
||||
if (d->dest_len >= d->dest_cap) {
|
||||
size_t ncap = d->dest_cap ? d->dest_cap * 2 : 1024 * 1024;
|
||||
unsigned char *nd = realloc(d->dest, ncap);
|
||||
if (!nd) return -1;
|
||||
d->dest = nd;
|
||||
d->dest_cap = ncap;
|
||||
}
|
||||
d->dest[d->dest_len++] = (unsigned char)sym;
|
||||
} else {
|
||||
sym -= 257;
|
||||
int length = tinf_read_bits(d, tinf_default_length_bits[sym], tinf_default_length_base[sym]);
|
||||
int dist_sym = tinf_decode_symbol(d, dt);
|
||||
int dist = tinf_read_bits(d, tinf_default_dist_bits[dist_sym], tinf_default_dist_base[dist_sym]);
|
||||
|
||||
if (d->dest_len + length > d->dest_cap) {
|
||||
size_t ncap = (d->dest_len + length) * 2 + 1024 * 1024;
|
||||
unsigned char *nd = realloc(d->dest, ncap);
|
||||
if (!nd) return -1;
|
||||
d->dest = nd;
|
||||
d->dest_cap = ncap;
|
||||
}
|
||||
|
||||
unsigned char *src = d->dest + d->dest_len - dist;
|
||||
while (length--) {
|
||||
d->dest[d->dest_len++] = *src++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int tinf_inflate_uncompressed_block(TINF_DATA *d) {
|
||||
d->bitcount = 0;
|
||||
if (d->source_len < 4) return -1;
|
||||
unsigned int length = d->source[0] | (d->source[1] << 8);
|
||||
d->source += 4;
|
||||
d->source_len -= 4;
|
||||
if (d->source_len < length) return -1;
|
||||
|
||||
if (d->dest_len + length > d->dest_cap) {
|
||||
size_t ncap = d->dest_len + length + 1024 * 1024;
|
||||
unsigned char *nd = realloc(d->dest, ncap);
|
||||
if (!nd) return -1;
|
||||
d->dest = nd;
|
||||
d->dest_cap = ncap;
|
||||
}
|
||||
|
||||
memcpy(d->dest + d->dest_len, d->source, length);
|
||||
d->dest_len += length;
|
||||
d->source += length;
|
||||
d->source_len -= length;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int tinf_inflate_dynamic_block(TINF_DATA *d) {
|
||||
TINF_TREE lt, dt, ct;
|
||||
unsigned char lengths[288 + 32];
|
||||
unsigned int hlit = tinf_read_bits(d, 5, 257);
|
||||
unsigned int hdist = tinf_read_bits(d, 5, 1);
|
||||
unsigned int hclen = tinf_read_bits(d, 4, 4);
|
||||
unsigned int i, num;
|
||||
|
||||
unsigned char clen[19];
|
||||
memset(clen, 0, sizeof(clen));
|
||||
for (i = 0; i < hclen; ++i) clen[tinf_clcidx[i]] = tinf_read_bits(d, 3, 0);
|
||||
tinf_build_tree(&ct, clen, 19);
|
||||
|
||||
for (num = 0; num < hlit + hdist;) {
|
||||
int sym = tinf_decode_symbol(d, &ct);
|
||||
if (sym < 16) {
|
||||
lengths[num++] = sym;
|
||||
} else if (sym == 16) {
|
||||
unsigned char prev = lengths[num - 1];
|
||||
for (i = tinf_read_bits(d, 2, 3); i; --i) lengths[num++] = prev;
|
||||
} else if (sym == 17) {
|
||||
for (i = tinf_read_bits(d, 3, 3); i; --i) lengths[num++] = 0;
|
||||
} else {
|
||||
for (i = tinf_read_bits(d, 7, 11); i; --i) lengths[num++] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
tinf_build_tree(<, lengths, hlit);
|
||||
tinf_build_tree(&dt, lengths + hlit, hdist);
|
||||
return tinf_inflate_block_data(d, <, &dt);
|
||||
}
|
||||
|
||||
static unsigned char *zlib_decompress(const unsigned char *src, size_t src_len, size_t *out_len) {
|
||||
if (src_len < 2) return NULL;
|
||||
size_t offset = 0;
|
||||
// Check zlib header (RFC 1950)
|
||||
if ((src[0] * 256 + src[1]) % 31 == 0 && (src[0] & 0x0F) == 8) {
|
||||
offset = 2;
|
||||
if (src[1] & 0x20) offset += 4;
|
||||
}
|
||||
|
||||
TINF_DATA d;
|
||||
memset(&d, 0, sizeof(d));
|
||||
d.source = src + offset;
|
||||
d.source_len = src_len > offset ? src_len - offset : 0;
|
||||
d.dest_cap = src_len * 4 + 1024 * 1024;
|
||||
d.dest = malloc(d.dest_cap);
|
||||
if (!d.dest) return NULL;
|
||||
|
||||
int bfinal;
|
||||
do {
|
||||
bfinal = tinf_getbit(&d);
|
||||
int btype = tinf_read_bits(&d, 2, 0);
|
||||
|
||||
if (btype == 0) {
|
||||
if (tinf_inflate_uncompressed_block(&d) < 0) { free(d.dest); return NULL; }
|
||||
} else if (btype == 1) {
|
||||
TINF_TREE lt, dt;
|
||||
tinf_build_fixed_trees(<, &dt);
|
||||
if (tinf_inflate_block_data(&d, <, &dt) < 0) { free(d.dest); return NULL; }
|
||||
} else if (btype == 2) {
|
||||
if (tinf_inflate_dynamic_block(&d) < 0) { free(d.dest); return NULL; }
|
||||
} else {
|
||||
free(d.dest);
|
||||
return NULL;
|
||||
}
|
||||
} while (!bfinal);
|
||||
|
||||
*out_len = d.dest_len;
|
||||
return d.dest;
|
||||
}
|
||||
|
||||
static void mkdir_p(const char *dir) {
|
||||
char tmp[1024];
|
||||
snprintf(tmp, sizeof(tmp), "%s", dir);
|
||||
for (char *p = tmp + 1; *p; p++) {
|
||||
if (*p == '/') {
|
||||
*p = '\0';
|
||||
mkdir(tmp, 0755);
|
||||
*p = '/';
|
||||
}
|
||||
}
|
||||
mkdir(tmp, 0755);
|
||||
}
|
||||
|
||||
const char *get_part_name(uint32_t id) {
|
||||
switch (id) {
|
||||
case 0x01: return "NAME_INFO";
|
||||
case 0x02: return "DESCRIPTION";
|
||||
case 0x03: return "DEPENDENCIES";
|
||||
case 0x04: return "FILE_CONTAINER";
|
||||
case 0x07: return "INSTALL_SCRIPT";
|
||||
case 0x08: return "UNINSTALL_SCRIPT";
|
||||
case 0x09: return "SIGNATURE";
|
||||
case 0x10: return "ARCHITECTURE";
|
||||
case 0x11: return "PKG_CONFLICTS";
|
||||
case 0x12: return "PKG_INFO";
|
||||
case 0x13: return "FEATURES";
|
||||
case 0x14: return "PKG_FEATURES";
|
||||
case 0x15: return "SQUASHFS";
|
||||
case 0x16: return "NULL_BLOCK";
|
||||
case 0x17: return "GIT_COMMIT";
|
||||
case 0x18: return "CHANNEL";
|
||||
case 0x19: return "HEADER";
|
||||
default: return "UNKNOWN";
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "Usage: %s <package.npk> <output_directory>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *npk_path = argv[1];
|
||||
const char *out_dir = argv[2];
|
||||
|
||||
FILE *fp = fopen(npk_path, "rb");
|
||||
if (!fp) {
|
||||
fprintf(stderr, "Error: Failed to open NPK file '%s'\n", npk_path);
|
||||
return 1;
|
||||
}
|
||||
|
||||
fseek(fp, 0, SEEK_END);
|
||||
long file_size = ftell(fp);
|
||||
fseek(fp, 0, SEEK_SET);
|
||||
|
||||
printf("Parsing NPK: '%s' (%ld bytes)\n", npk_path, file_size);
|
||||
mkdir_p(out_dir);
|
||||
|
||||
int total_extracted = 0;
|
||||
long offset = 0;
|
||||
|
||||
while (offset + 6 <= file_size) {
|
||||
fseek(fp, offset, SEEK_SET);
|
||||
uint16_t id16;
|
||||
uint32_t size32;
|
||||
|
||||
if (fread(&id16, 2, 1, fp) != 1 || fread(&size32, 4, 1, fp) != 1) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (id16 > 0 && id16 <= 0x20 && size32 <= (uint32_t)(file_size - offset - 6)) {
|
||||
printf(" [Part 0x%02X: %-15s] offset=%ld, size=%u\n", id16, get_part_name(id16), offset, size32);
|
||||
|
||||
if (id16 == 0x04) { // FILE_CONTAINER
|
||||
unsigned char *zbuf = malloc(size32);
|
||||
if (zbuf && fread(zbuf, 1, size32, fp) == size32) {
|
||||
size_t decomp_len = 0;
|
||||
unsigned char *decomp = zlib_decompress(zbuf, size32, &decomp_len);
|
||||
if (decomp) {
|
||||
printf(" -> Decompressed FILE_CONTAINER: %zu bytes\n", decomp_len);
|
||||
|
||||
unsigned char *p = decomp;
|
||||
unsigned char *end = decomp + decomp_len;
|
||||
int item_idx = 0;
|
||||
|
||||
while (p + 30 <= end) {
|
||||
uint32_t fmode = *(uint32_t *)(p + 0);
|
||||
uint32_t fmtime = *(uint32_t *)(p + 8);
|
||||
uint32_t fsize = *(uint32_t *)(p + 24);
|
||||
uint16_t name_len = *(uint16_t *)(p + 28);
|
||||
p += 30;
|
||||
|
||||
if (p + name_len > end) {
|
||||
printf(" -> Header overrun: name_len=%u exceeds buffer\n", name_len);
|
||||
break;
|
||||
}
|
||||
|
||||
char fname[512] = {0};
|
||||
if (name_len >= sizeof(fname)) name_len = sizeof(fname) - 1;
|
||||
memcpy(fname, p, name_len);
|
||||
fname[name_len] = '\0';
|
||||
p += name_len;
|
||||
|
||||
if (p + fsize > end) {
|
||||
printf(" -> Data overrun: '%s' size=%u exceeds buffer\n", fname, fsize);
|
||||
break;
|
||||
}
|
||||
|
||||
char full_path[1024];
|
||||
snprintf(full_path, sizeof(full_path), "%s/%s", out_dir, fname);
|
||||
|
||||
char dir_path[1024];
|
||||
snprintf(dir_path, sizeof(dir_path), "%s", full_path);
|
||||
char *slash = strrchr(dir_path, '/');
|
||||
if (slash) { *slash = '\0'; mkdir_p(dir_path); }
|
||||
|
||||
if (S_ISDIR(fmode)) {
|
||||
mkdir_p(full_path);
|
||||
printf(" -> [%d] [DIR] %s/\n", ++item_idx, fname);
|
||||
} else if (S_ISLNK(fmode)) {
|
||||
char target[1024] = {0};
|
||||
size_t tlen = fsize < sizeof(target) ? fsize : sizeof(target) - 1;
|
||||
memcpy(target, p, tlen);
|
||||
unlink(full_path);
|
||||
symlink(target, full_path);
|
||||
printf(" -> [%d] [LINK] %s -> %s\n", ++item_idx, fname, target);
|
||||
total_extracted++;
|
||||
} else {
|
||||
FILE *out = fopen(full_path, "wb");
|
||||
if (out) {
|
||||
fwrite(p, 1, fsize, out);
|
||||
fclose(out);
|
||||
chmod(full_path, fmode ? (fmode & 07777) : 0644);
|
||||
|
||||
if (fmtime) {
|
||||
struct utimbuf ut;
|
||||
ut.actime = fmtime;
|
||||
ut.modtime = fmtime;
|
||||
utime(full_path, &ut);
|
||||
}
|
||||
|
||||
printf(" -> [%d] [FILE] %s (%u bytes, mode=%04o)\n", ++item_idx, fname, fsize, fmode & 07777);
|
||||
total_extracted++;
|
||||
} else {
|
||||
fprintf(stderr, "Warning: Failed to create file '%s'\n", full_path);
|
||||
}
|
||||
}
|
||||
|
||||
p += fsize;
|
||||
}
|
||||
|
||||
free(decomp);
|
||||
} else {
|
||||
printf(" -> ZLIB decompression failed for FILE_CONTAINER\n");
|
||||
}
|
||||
}
|
||||
if (zbuf) free(zbuf);
|
||||
} else if (id16 == 0x15) {
|
||||
char sq_file[1024];
|
||||
snprintf(sq_file, sizeof(sq_file), "%s/image.squashfs", out_dir);
|
||||
FILE *out = fopen(sq_file, "wb");
|
||||
if (out) {
|
||||
unsigned char buf[65536];
|
||||
uint32_t remaining = size32;
|
||||
while (remaining > 0) {
|
||||
size_t to_read = remaining > sizeof(buf) ? sizeof(buf) : remaining;
|
||||
size_t n = fread(buf, 1, to_read, fp);
|
||||
if (n == 0) break;
|
||||
fwrite(buf, 1, n, out);
|
||||
remaining -= n;
|
||||
}
|
||||
fclose(out);
|
||||
printf(" -> Extracted SQUASHFS image: %s (%u bytes)\n", sq_file, size32);
|
||||
total_extracted++;
|
||||
}
|
||||
}
|
||||
|
||||
offset += 6 + size32;
|
||||
continue;
|
||||
}
|
||||
|
||||
offset++;
|
||||
}
|
||||
|
||||
fclose(fp);
|
||||
printf("\nExtraction complete: %d item(s) extracted from NPK to '%s'.\n", total_extracted, out_dir);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user