This patch adds a new function, guestfs_file_arch, which is like
guestfs_file but specifically intended to determine the architecture
of binaries and libraries.
Usage is:
guestfs_file_arch (g, "/bin/ls")
==> "x86_64" (or whatever)
What it can do:
- ELF binaries
- ELF shared libraries
- Windows Win32 and Win64 binaries
- Windows Win32 and Win64 DLLs
- Linux kernel modules
- Linux new-style initrd images
- some non-x86 Linux vmlinuz kernels
What it can't do:
- static libraries (libfoo.a)
- Linux old-style initrd as compressed ext2 filesystem (RHEL 3)
- x86 Linux vmlinuz kernels
- ancient stuff like a.out, COFF binaries
It turns out that x86 vmlinuz (ie. bzImage) is virtually impossible to
unpack. It consists of an amalgam of 16 bit code, 32 bit code (even
on x86-64) and compressed kernel. The only way to unpack it would be
to either uncompress the compressed kernel, or else reverse the (32
bit) CPU detection code. Neither is very realistic, but I left in
some commented-out code to show you how far I got.
An easy LKML patch for someone would be to add the required
architecture into the setup header so we can just read it out
directly, or maybe someone else can see something I've missed.
Initrd unpacking is relatively simple. We unpack the initrd and look
for some known binaries inside it. This seems to work OK on all the
new-style initrds I tested it against.
Finally, in order to run the tests we need binaries from lots of
different architectures. Obviously building these is difficult, as it
would require a cross-compiler. So instead I've proposed we just add
them into the images/ directory. These come "without source", but the
source is just:
main(){}
for the binaries, and (literally) the empty file for the libraries.
Hope that doesn't annoy any purists.
Rich.
--
Richard Jones, Emerging Technologies, Red Hat
http://et.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines. Boot with a
live CD or over the network (PXE) and turn machines into Xen guests.
http://et.redhat.com/~rjones/virt-p2v