View Single Post
Posts: 2,802 | Thanked: 4,491 times | Joined on Nov 2007
#194
Originally Posted by maacruz View Post
I do not do perl, too arcane for me to learn, but I'll happyly use your code snippet.
While you're at it, why don't you add the equivalent of "if filesize(Z)<$l: exit(1)" before truncate?
Just for the hell of it, I had a go at doing it in a shell script, using only what's provided by busybox and without "cheating" by using other interpreters like awk, sed etc. It turned out to be surprisingly tricky to get the 32bit int in decimal format without having something like od(1), but here goes anyway:

Code:
#!/bin/sh

dd if=zImage-backup of=l skip=44 count=4 bs=1
b=$(echo $(echo -n '0000' | cmp -l l | cut -c3-5))
read a b c d <<EOF
$b
EOF
rm l

eval $(printf "l=\$(( (((0$d \* 256 + 0$c) \* 256 + 0$b) \* 256 + 0$a) ))")

s=$(echo $(ls -l zImage-backup) | cut -f5 -d" ")
if [ "$s" -gt "$l" ] ; then
        dd if=zImage-backup bs=$l count=1 of=zImage-backup.new && \
        mv -f zImage-backup.new zImage-backup
fi
Improvements welcome ;-)