Getting uname information from a compressed kernel image

后端 未结 2 589
别那么骄傲
别那么骄傲 2021-02-09 06:14

Is there a good way to extract the same information that uname does from a compressed kernel image? I want this to be able to check the dog tags of kernel sitting in dormant mtd

2条回答
  •  梦如初夏
    2021-02-09 06:42

    For Linux image compressed with gzip, use this:

    dd if=arch/arm/boot/zImage bs=1 skip=$(LC_ALL=C grep -a -b -o $'\x1f\x8b\x08\x00\x00\x00\x00\x00' arch/arm/boot/zImage | head -n 1 | cut -d ':' -f 1) | zcat | grep -a 'Linux version'
    

    For Linux image compressed with xz, use this:

    dd if=arch/arm/boot/zImage bs=1 skip=$(LC_ALL=C grep -a -b -o $'\xFD\x37\x7A\x58\x5A\x00' arch/arm/boot/zImage | head -n 1 | cut -d ':' -f 1) | xzcat | grep -a 'Linux version'
    

    Because the image file contains data after the end of the compressed stream, you'll get an error you can ignore.

    The string constant appears to be part of the frozen userspace visible kernel API:

    http://git.kernel.org/?p=linux/kernel/git/torvalds/linux.git;a=blob;f=init/version.c;hb=HEAD#l40

提交回复
热议问题