1#!/bin/sh 2# extracts .config info from a [b]zImage file 3# uses: binoffset (new), dd, zcat, strings, grep 4# $arg1 is [b]zImage filename 5 6binoffset="./scripts/binoffset" 7test -e $binoffset || cc -o $binoffset ./scripts/binoffset.c || exit 1 8 9IKCFG_ST="0x49 0x4b 0x43 0x46 0x47 0x5f 0x53 0x54" 10IKCFG_ED="0x49 0x4b 0x43 0x46 0x47 0x5f 0x45 0x44" 11dump_config() { 12 file="$1" 13 14 start=`$binoffset $file $IKCFG_ST 2>/dev/null` 15 [ "$?" != "0" ] && start="-1" 16 if [ "$start" -eq "-1" ]; then 17 return 18 fi 19 end=`$binoffset $file $IKCFG_ED 2>/dev/null` 20 21 start=`expr $start + 8` 22 size=`expr $end - $start` 23 24 dd if="$file" ibs=1 skip="$start" count="$size" 2>/dev/null | zcat 25 26 clean_up 27 exit 0 28} 29 30 31usage() 32{ 33 echo " usage: extract-ikconfig [b]zImage_filename" 34} 35 36clean_up() 37{ 38 if [ "$TMPFILE" != "" ]; then 39 rm -f $TMPFILE 40 fi 41} 42 43if [ $# -lt 1 ] 44then 45 usage 46 exit 1 47fi 48 49TMPFILE=`mktemp -t ikconfig-XXXXXX` || exit 1 50image="$1" 51 52# vmlinux: Attempt to dump the configuration from the file directly 53dump_config "$image" 54 55GZHDR1="0x1f 0x8b 0x08 0x00" 56GZHDR2="0x1f 0x8b 0x08 0x08" 57 58# vmlinux.gz: Check for a compressed images 59off=`$binoffset "$image" $GZHDR1 2>/dev/null` 60[ "$?" != "0" ] && off="-1" 61if [ "$off" -eq "-1" ]; then 62 off=`$binoffset "$image" $GZHDR2 2>/dev/null` 63 [ "$?" != "0" ] && off="-1" 64fi 65if [ "$off" -eq "0" ]; then 66 zcat <"$image" >"$TMPFILE" 67 dump_config "$TMPFILE" 68elif [ "$off" -ne "-1" ]; then 69 (dd ibs="$off" skip=1 count=0 && dd bs=512k) <"$image" 2>/dev/null | \ 70 zcat >"$TMPFILE" 71 dump_config "$TMPFILE" 72fi 73 74echo "ERROR: Unable to extract kernel configuration information." 75echo " This kernel image may not have the config info." 76 77clean_up 78exit 1 79