Re: [PATCH v3] scripts: add extract-vmlinux

From: Ian Campbell
Date: Fri Aug 19 2011 - 02:57:27 EST


On Tue, 2011-08-16 at 10:46 +0200, Corentin Chary wrote:
> This script can be used to extract vmlinux from a compressed
> kernel image (bzImage, etc..). It's inspired from (a subset of)
> extract-ikconfig.

FWIW I wrote the attached way back when, it uses the payload_* fields in
the bzImage to find the payload rather than scanning (these are present
in bzImages from somewhere in the mid 2.6.2x range). I'd be happy to
license it under the GPLv2 if that is helpful.

> It's something a lot of people have been looking for (mainly
> people with xen < 4 that doesn't support bzImages at all).

xen 3.4 does, doesn't it (at least the tip of 3.4-testing.hg does)? And
I thought e.g. RHEL5 (which uses an older base version) had it
backported. Possibly what is missing is support for all the various
compression options.

Ian.
--
Ian Campbell


How do I get HOME?
#include <stdio.h>
#include <fcntl.h>
#include <stdint.h>
#include <unistd.h>

#include <inttypes.h>

#include <err.h>

#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>

int main(int argc, char **argv)
{
int fd;
struct stat sb;
void *p;
uint8_t *hdr;
int setup_sectors;
uint32_t compressed_payload_offset;
uint32_t compressed_payload_length;

if (argc != 2)
errx(1, "usage: bzexplode <bzImage>");

fd = open(argv[1], O_RDONLY);
if (fd < 0)
err(1, "open");

if (fstat(fd, &sb) < 0)
err(1, "fstat");

p = mmap(0, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
if (p == MAP_FAILED)
err(1, "mmap");

hdr = p;
setup_sectors = hdr[0x1f1];
compressed_payload_offset = *(uint32_t*)&hdr[0x248];

fprintf(stderr, "setup sectors %d\n", setup_sectors);

compressed_payload_offset += (setup_sectors+1) * 512;

//compressed_payload_length = *(uint32_t*)(p + compressed_payload_offset - 4);
compressed_payload_length = *(uint32_t*)&hdr[0x24c];

fprintf(stderr, "compressed_payload_offset %"PRIx32" (abs)\n",
compressed_payload_offset);
fprintf(stderr, "compressed_payload_length %"PRIx32"\n",
compressed_payload_length);

write(1,
p + compressed_payload_offset,
compressed_payload_length);
return 0;
}

Attachment: signature.asc
Description: This is a digitally signed message part