-
-
Save anonymous/c3225054e6681a39be16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# FILENAME: repack.v4.1.sh | |
# AUTHOR: dmz | |
# SOURCE: http://7200emu.hacki.at/viewtopic.php?t=9074 | |
# DISCLAIMER: All information provided here are solely for self-education and investigation purposes. Provided AS-IS without any warranties. | |
VERSION=4.1 | |
IMAGE=$1 | |
CWD=`pwd` | |
[ -z "$IMAGE" ] && IMAGE=$CWD/asa842-k8.bin | |
echo "Repack script version: $VERSION" | |
if [ ! -f "$IMAGE" ]; then | |
echo "USAGE: repack.sh /path/to/asa/image" | |
exit 1; | |
fi | |
XXD=`which xxd` | |
ISOLINUX_BIN=/usr/share/syslinux/isolinux.bin | |
MKISOFS=`which mkisofs` | |
if [ ! -x "$XXD" ]; then | |
echo "ERROR: xxd command not found" | |
echo "Install 'vim' or 'vim-enhanced' package to get it" | |
exit 1; | |
fi | |
CREATEISO=no | |
if [ -x "$MKISOFS" -a -e "$ISOLINUX_BIN" ]; then | |
echo "Detected syslinux/cdrtools - ISO will be created" | |
CREATEISO=yes | |
else | |
echo "no syslinux/cdrtools - ISO creation skipped" | |
fi | |
BASE_NAME=`basename "$IMAGE"` | |
case "$BASE_NAME" in | |
'asa842-k8.bin') # ASA 8.4(2) | |
dd skip=102400 if="$IMAGE" of="$CWD/asa842-vmlinuz" bs=1 count=1359344 | |
dd skip=1461744 if="$IMAGE" of="$CWD/asa842-initrd-original.gz" bs=1 | |
TMP_DIR=`mktemp -d` | |
pushd $TMP_DIR | |
gunzip -c "$CWD/asa842-initrd-original.gz" | cpio -i --no-absolute-filenames --make-directories | |
find . | cpio -o -H newc | gzip -9 > "$CWD/asa842-initrd-original.gz" | |
sed -i -e "s/\(VERBOSE=\).*/\1yes/" etc/init.d/rcS | |
sed -i -e "s/echo -n/echo/" etc/init.d/S10udev | |
sed -i -e "s#^fi\$#fi\ngrep -q shell /proc/cmdline\n[ \$? == 0 ] \&\& echo '/bin/sh' >> /tmp/run_cmd#" asa/scripts/rcS | |
sed -i -e "/mount/d" asa/scripts/format_flash.sh | |
sed -i -e "s#mount=0#if [ ! -e /dev/hda1 ]; then /asa/scripts/format_flash.sh /dev/hda1 0 0 /dev/hda; fi\nmount=0#" asa/scripts/rcS.common | |
xxd -r -g 2 -c 16 - asa/bin/lina <<END | |
02716a0: a1c0 ab32 0a55 89e5 83e8 1283 f80b eb10 | |
037f350: a1c0 ab32 0a55 89e5 83e8 1283 f80b eb10 | |
06f4da0: 848b 0100 0083 3dc0 ab32 0aff 0f85 ae00 | |
06f4df0: 85db c705 40a8 1a0a 0000 0000 0f84 a200 | |
06f5170: 0085 c075 2be8 160b 98ff 8d95 f4f4 ffff | |
06f5c50: c30f 8589 0000 00c7 4424 084f 0200 00c7 | |
06f5ce0: b801 0000 00d3 e0a9 0000 f43f 0f85 65ff | |
06f5d10: 1400 0000 e827 9ae0 0089 c290 8d74 2600 | |
0c42a60: e8bb 3f00 0085 c00f 84b0 fbff ff8d 7600 | |
0c42a70: e8ab 3f00 0085 c089 85e8 feff ff0f 849a | |
0c42b80: 5424 0889 4424 04c7 0424 0000 0000 e925 | |
0c42b90: 0200 00e9 0bff ffff e813 9aff ff8d 7600 | |
0c42db0: feff ff90 8d74 2600 8d46 02c7 45c0 0000 | |
0c42dc0: 0000 8945 c4c7 45c8 0000 0000 e89f f5ff | |
0c42dd0: ff90 9090 e9ca fcff ff8d b426 0000 0000 | |
0c4a670: 3bff 8db6 0000 0000 8b45 e4c7 45c0 0100 | |
1502bf0: 83c4 245b 5dc3 6690 85db 75f2 a1c0 ab32 | |
15505a0: e94b 0000 0098 60bb 098d b426 0000 0000 | |
1550f50: c0ab 320a 83e8 1283 f80b eb0c 31c0 c9c3 | |
1551060: c0ab 320a 83e8 1283 f80b eb0c 31c0 c9c3 | |
1552c10: 42ee 83f8 0b0f 8589 1100 00ba 7160 bb09 | |
1b6f350: 4f53 5449 4300 4153 4120 3535 3230 0043 | |
END | |
xxd -r -g 2 -c 2 - asa/bin/lina <<END | |
0c425d8: 0f85 | |
0c425ef: eb77 | |
0c43813: 770b | |
END | |
find . | cpio -o -H newc | gzip -9 > "$CWD/asa842-initrd.gz" | |
popd | |
rm -rf $TMP_DIR | |
if [ "$CREATEISO" == "yes" ]; then | |
TMP_DIR=`mktemp -d` | |
pushd $TMP_DIR | |
mkdir isolinux | |
cp $ISOLINUX_BIN isolinux/ | |
cp $CWD/asa842-vmlinuz . | |
cp $CWD/asa842-initrd.gz . | |
cp $CWD/asa842-initrd-original.gz . | |
cat >isolinux/isolinux.cfg <<EEND | |
serial 0 | |
display boot.txt | |
prompt 1 | |
default asa | |
label asa | |
kernel /asa842_vmlinuz | |
append initrd=/asa842_initrd.gz ide_generic.probe_mask=0x01 ide_core.chs=0.0:980,16,32 auto nousb console=ttyS0 bigphysarea=65536 | |
label asa-orig | |
kernel /asa842_vmlinuz | |
append initrd=/asa842_initrd_original.gz ide_generic.probe_mask=0x01 ide_core.chs=0.0:980,16,32 auto nousb console=ttyS0 bigphysarea=65536 | |
EEND | |
cat >isolinux/boot.txt <<EEND | |
asa - ASA 8.4(2) (DEFAULT) | |
asa-orig - ASA 8.4(2) original | |
Press <ENTER> to boot default image | |
Type 'asa shell<ENTER>' to gain shell access | |
Type 'asa-orig<ENTER>' to boot original initrd | |
EEND | |
$MKISOFS -o $CWD/asa.iso -l \ | |
-b isolinux/isolinux.bin -c isolinux/boot.cat \ | |
-no-emul-boot -boot-load-size 4 -boot-info-table \ | |
./ | |
popd | |
rm -rf $TMP_DIR | |
fi | |
;; | |
*) # Default case | |
echo "Version <$BASE_NAME> is not supported!" | |
exit 1; | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment