image: Allow manipulation of i386 PE/COFF files

Replace struct image->aouthdr with a union of the 32- and 64-bit a.out
header definitions, and abstract the relevant parsing code into the
image_pecoff_parse_{32,64} functions.

We also move all references of data in the a.out header to these
functions, so we don't need to lookup the machine types elsewhere.

Based on a patch by Maxim Kammerer <mk@dee.su>.

Signed-off-by: Jeremy Kerr <jeremy.kerr@canonical.com>
This commit is contained in:
Jeremy Kerr 2012-08-10 16:26:14 +08:00
parent e027b87cff
commit e1b58d6ccb
2 changed files with 89 additions and 23 deletions

12
image.h
View file

@ -54,7 +54,12 @@ struct image {
uint32_t *checksum;
struct external_PEI_DOS_hdr *doshdr;
struct external_PEI_IMAGE_hdr *pehdr;
PEPAOUTHDR *aouthdr;
union {
PEPAOUTHDR *aout_64;
PEAOUTHDR *aout_32;
void *addr;
} aouthdr;
unsigned int aouthdr_size;
struct data_dir_entry *data_dir;
struct data_dir_entry *data_dir_sigtable;
struct external_scnhdr *scnhdr;
@ -63,6 +68,11 @@ struct image {
void *cert_table;
int cert_table_size;
/* We cache a few values from the aout header, so we don't have to
* keep checking whether to use the 32- or 64-bit version */
uint32_t file_alignment;
uint32_t header_size;
/* Regions that are included in the image hash: populated
* during image parsing, then used during the hash process.
*/