extract-ikconfig 1.9 KB

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