1 #!/bin/sh !! 1 #! /bin/bash 2 # -------------------------------------------- !! 2 # extracts .config info from a [b]zImage file 3 # extract-ikconfig - Extract the .config file !! 3 # uses: binoffset (new), dd, zcat, strings, grep 4 # !! 4 # $arg1 is [b]zImage filename 5 # This will only work when the kernel was comp << 6 # << 7 # The obscure use of the "tr" filter is to wor << 8 # "grep" that report the byte offset of the li << 9 # << 10 # (c) 2009,2010 Dick Streefland <dick@streeflan << 11 # Licensed under the terms of the GNU General << 12 # -------------------------------------------- << 13 5 14 cf1='IKCFG_ST\037\213\010' !! 6 TMPFILE="" 15 cf2='0123456789' << 16 7 17 dump_config() !! 8 usage() 18 { 9 { 19 if pos=`tr "$cf1\n$cf2" "\n$cf2=" !! 10 echo " usage: extract-ikconfig [b]zImage_filename" 20 then << 21 pos=${pos%%:*} << 22 tail -c+$(($pos+8)) "$1" | zca << 23 if [ $? != 1 ] << 24 then # exit status must be << 25 cat $tmp1 << 26 exit 0 << 27 fi << 28 fi << 29 } 11 } 30 12 31 try_decompress() !! 13 clean_up() 32 { 14 { 33 for pos in `tr "$1\n$2" "\n$2=" < !! 15 if [ -z $ISCOMP ] 34 do !! 16 then 35 pos=${pos%%:*} !! 17 rm -f $TMPFILE 36 tail -c+$pos "$img" | $3 > $tm !! 18 fi 37 dump_config $tmp2 << 38 done << 39 } 19 } 40 20 41 # Check invocation: !! 21 if [ $# -lt 1 ] 42 me=${0##*/} !! 22 then 43 img=$1 !! 23 usage 44 if [ $# -ne 1 -o ! -s "$img" ] !! 24 exit >> 25 fi >> 26 >> 27 image=$1 >> 28 >> 29 # There are two gzip headers, as well as arches which don't compress their >> 30 # kernel. >> 31 GZHDR="0x1f 0x8b 0x08 0x00" >> 32 if [ `binoffset $image $GZHDR >/dev/null 2>&1 ; echo $?` -ne 0 ] >> 33 then >> 34 GZHDR="0x1f 0x8b 0x08 0x08" >> 35 if [ `binoffset $image $GZHDR >/dev/null 2>&1 ; echo $?` -ne 0 ] >> 36 then >> 37 ISCOMP=0 >> 38 fi >> 39 fi >> 40 >> 41 PID=$$ >> 42 >> 43 # Extract and uncompress the kernel image if necessary >> 44 if [ -z $ISCOMP ] >> 45 then >> 46 TMPFILE="/tmp/`basename $image`.vmlin.$PID" >> 47 dd if=$image bs=1 skip=`binoffset $image $GZHDR` 2> /dev/null | zcat > $TMPFILE >> 48 else >> 49 TMPFILE=$image >> 50 fi >> 51 >> 52 # Look for strings. >> 53 strings $TMPFILE | grep "CONFIG_BEGIN=n" > /dev/null >> 54 if [ $? -eq 0 ] 45 then 55 then 46 echo "Usage: $me <kernel-image>" >&2 !! 56 strings $TMPFILE | awk "/CONFIG_BEGIN=n/,/CONFIG_END=n/" > $image.oldconfig.$PID 47 exit 2 !! 57 else >> 58 echo "ERROR: Unable to extract kernel configuration information." >> 59 echo " This kernel image may not have the config info." >> 60 clean_up >> 61 exit 1 48 fi 62 fi 49 63 50 # Prepare temp files: !! 64 echo "Kernel configuration written to $image.oldconfig.$PID" 51 tmp1=/tmp/ikconfig$$.1 !! 65 clean_up 52 tmp2=/tmp/ikconfig$$.2 !! 66 exit 0 53 trap "rm -f $tmp1 $tmp2" 0 << 54 << 55 # Initial attempt for uncompressed images or o << 56 dump_config "$img" << 57 << 58 # That didn't work, so retry after decompressi << 59 try_decompress '\037\213\010' xy gunzip << 60 try_decompress '\3757zXZ\000' abcde unxz << 61 try_decompress 'BZh' xy bunzip2 << 62 try_decompress '\135\0\0\0' xxx unlzma << 63 try_decompress '\211\114\132' xy 'lzop -d' << 64 try_decompress '\002\041\114\030' xyy 'lz4 -d << 65 try_decompress '\050\265\057\375' xxx unzstd << 66 << 67 # Bail out: << 68 echo "$me: Cannot find kernel config." >&2 << 69 exit 1 <<
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.