DataDirectory virtual address is relative. Fix to suit.

This commit is contained in:
Alan Modra
2000-05-08 06:06:30 +00:00
parent bec02744ae
commit 18a28d4eee
2 changed files with 102 additions and 106 deletions

View File

@@ -1,3 +1,20 @@
2000-05-08 Alan Modra <alan@linuxcare.com.au>
* peigen.c (_bfd_pei_swap_aouthdr_out): Pass ImageBase to
add_data_entry. DataDirectory virtual address is relative.
(pe_print_idata): Account for relative DataDirectory virtual
addresses. Don't trash datasize inside POWERPC_LE_PE code.
(pe_print_edata): Similarly.
From Szabolcs Szakacsits <szaka@F-Secure.com>
* peigen.c (dir_names): Add Delay Import Directory.
(pe_print_idata): Always search for bfd section containing
idata address rather than looking up section name. Print this
section name rather than .idata.
(pe_print_edata): Similarly. Also print some fields as %08lx.
(_bfd_pe_print_private_bfd_data_common): Print Reserved1 field as
Win32Version.
2000-05-03 Mark Elbrecht <snowball3@bigfoot.com> 2000-05-03 Mark Elbrecht <snowball3@bigfoot.com>
* bfd/coff-go32.c (COFF_SECTION_ALIGNMENT_ENTRIES): Add entry for * bfd/coff-go32.c (COFF_SECTION_ALIGNMENT_ENTRIES): Add entry for

View File

@@ -566,7 +566,7 @@ _bfd_pei_swap_aouthdr_out (abfd, in, out)
/* first null out all data directory entries .. */ /* first null out all data directory entries .. */
memset (extra->DataDirectory, sizeof (extra->DataDirectory), 0); memset (extra->DataDirectory, sizeof (extra->DataDirectory), 0);
add_data_entry (abfd, extra, 0, ".edata", 0); add_data_entry (abfd, extra, 0, ".edata", ib);
/* Don't call add_data_entry for .idata$2 or .idata$5. It's done in /* Don't call add_data_entry for .idata$2 or .idata$5. It's done in
bfd_coff_final_link where all the required information is bfd_coff_final_link where all the required information is
@@ -574,11 +574,11 @@ _bfd_pei_swap_aouthdr_out (abfd, in, out)
/* However, until other .idata fixes are made (pending patch), the /* However, until other .idata fixes are made (pending patch), the
entry for .idata is needed for backwards compatability. FIXME. */ entry for .idata is needed for backwards compatability. FIXME. */
add_data_entry (abfd, extra, 1, ".idata" ,0); add_data_entry (abfd, extra, 1, ".idata" , ib);
add_data_entry (abfd, extra, 2, ".rsrc" ,0); add_data_entry (abfd, extra, 2, ".rsrc" , ib);
add_data_entry (abfd, extra, 3, ".pdata", 0); add_data_entry (abfd, extra, 3, ".pdata", ib);
/* For some reason, the virtual size (which is what's set by /* For some reason, the virtual size (which is what's set by
add_data_entry) for .reloc is not the same as the size recorded add_data_entry) for .reloc is not the same as the size recorded
@@ -586,7 +586,7 @@ _bfd_pei_swap_aouthdr_out (abfd, in, out)
but since it's the best we've got, use it. It does do the right but since it's the best we've got, use it. It does do the right
thing for .pdata. */ thing for .pdata. */
if (pe_data (abfd)->has_reloc_section) if (pe_data (abfd)->has_reloc_section)
add_data_entry (abfd, extra, 5, ".reloc", 0); add_data_entry (abfd, extra, 5, ".reloc", ib);
{ {
asection *sec; asection *sec;
@@ -973,7 +973,7 @@ static char * dir_names[IMAGE_NUMBEROF_DIRECTORY_ENTRIES] =
N_ ("Load Configuration Directory"), N_ ("Load Configuration Directory"),
N_ ("Bound Import Directory"), N_ ("Bound Import Directory"),
N_ ("Import Address Table Directory"), N_ ("Import Address Table Directory"),
N_ ("Reserved"), N_ ("Delay Import Directory"),
N_ ("Reserved"), N_ ("Reserved"),
N_ ("Reserved") N_ ("Reserved")
}; };
@@ -995,8 +995,8 @@ pe_print_idata (abfd, vfile)
{ {
FILE *file = (FILE *) vfile; FILE *file = (FILE *) vfile;
bfd_byte *data = 0; bfd_byte *data = 0;
asection *section = bfd_get_section_by_name (abfd, ".idata"); asection *section;
unsigned long adj; bfd_signed_vma adj;
#ifdef POWERPC_LE_PE #ifdef POWERPC_LE_PE
asection *rel_section = bfd_get_section_by_name (abfd, ".reldata"); asection *rel_section = bfd_get_section_by_name (abfd, ".reldata");
@@ -1011,33 +1011,23 @@ pe_print_idata (abfd, vfile)
pe_data_type *pe = pe_data (abfd); pe_data_type *pe = pe_data (abfd);
struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr; struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
if (section != NULL) bfd_vma addr;
{
datasize = bfd_section_size (abfd, section);
dataoff = 0;
if (datasize == 0)
return true;
fprintf (file, _("\nThe import table is the .idata section\n"));
}
else
{
/* idata buried in some other section: e.g. KERNEL32.DLL. */
bfd_vma addr, size;
addr = extra->DataDirectory[1].VirtualAddress; addr = extra->DataDirectory[1].VirtualAddress;
size = extra->DataDirectory[1].Size; datasize = extra->DataDirectory[1].Size;
if (addr == 0 || size == 0) if (addr == 0 || datasize == 0)
return true; return true;
addr += extra->ImageBase;
for (section = abfd->sections; section != NULL; section = section->next) for (section = abfd->sections; section != NULL; section = section->next)
{ {
if (addr >= section->vma if (addr >= section->vma
&& addr < section->vma + bfd_section_size(abfd,section)) && addr < section->vma + bfd_section_size(abfd,section))
break; break;
} }
if (section == NULL) if (section == NULL)
{ {
fprintf (file, fprintf (file,
@@ -1049,8 +1039,6 @@ pe_print_idata (abfd, vfile)
section->name, (unsigned long) addr); section->name, (unsigned long) addr);
dataoff = addr - section->vma; dataoff = addr - section->vma;
datasize = size;
}
#ifdef POWERPC_LE_PE #ifdef POWERPC_LE_PE
if (rel_section != 0 && bfd_section_size (abfd, rel_section) != 0) if (rel_section != 0 && bfd_section_size (abfd, rel_section) != 0)
@@ -1067,13 +1055,12 @@ pe_print_idata (abfd, vfile)
bfd_vma start_address; bfd_vma start_address;
bfd_byte *data = 0; bfd_byte *data = 0;
int offset; int offset;
data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd, data = (bfd_byte *) bfd_malloc ((size_t) bfd_section_size (abfd,
rel_section)); rel_section));
if (data == NULL && bfd_section_size (abfd, rel_section) != 0) if (data == NULL && bfd_section_size (abfd, rel_section) != 0)
return false; return false;
datasize = bfd_section_size (abfd, rel_section);
bfd_get_section_contents (abfd, bfd_get_section_contents (abfd,
rel_section, rel_section,
(PTR) data, 0, (PTR) data, 0,
@@ -1100,7 +1087,8 @@ pe_print_idata (abfd, vfile)
#endif #endif
fprintf(file, fprintf(file,
_("\nThe Import Tables (interpreted .idata section contents)\n")); _("\nThe Import Tables (interpreted %s section contents)\n"),
section->name);
fprintf(file, fprintf(file,
_(" vma: Hint Time Forward DLL First\n")); _(" vma: Hint Time Forward DLL First\n"));
fprintf(file, fprintf(file,
@@ -1114,7 +1102,7 @@ pe_print_idata (abfd, vfile)
if (! bfd_get_section_contents (abfd, section, (PTR) data, 0, secsize)) if (! bfd_get_section_contents (abfd, section, (PTR) data, 0, secsize))
return false; return false;
adj = - section->vma; adj = section->vma - extra->ImageBase;
for (i = 0; i < datasize; i += onaline) for (i = 0; i < datasize; i += onaline)
{ {
@@ -1127,9 +1115,8 @@ pe_print_idata (abfd, vfile)
bfd_size_type j; bfd_size_type j;
char *dll; char *dll;
fprintf (file, /* print (i + extra->DataDirectory[1].VirtualAddress) */
" %08lx\t", fprintf (file, " %08lx\t", (unsigned long) (i + adj + dataoff));
(unsigned long int) (i + section->vma + dataoff));
if (i + 20 > datasize) if (i + 20 > datasize)
{ {
@@ -1153,14 +1140,14 @@ pe_print_idata (abfd, vfile)
if (hint_addr == 0 && first_thunk == 0) if (hint_addr == 0 && first_thunk == 0)
break; break;
dll = (char *) data + dll_name - section->vma + dataoff; dll = (char *) data + dll_name - adj;
fprintf(file, _("\n\tDLL Name: %s\n"), dll); fprintf(file, _("\n\tDLL Name: %s\n"), dll);
if (hint_addr != 0) if (hint_addr != 0)
{ {
fprintf (file, _("\tvma: Hint/Ord Member-Name\n")); fprintf (file, _("\tvma: Hint/Ord Member-Name\n"));
idx = hint_addr + adj; idx = hint_addr - adj;
for (j = 0; j < datasize; j += 4) for (j = 0; j < datasize; j += 4)
{ {
@@ -1176,8 +1163,8 @@ pe_print_idata (abfd, vfile)
int ordinal; int ordinal;
char *member_name; char *member_name;
ordinal = bfd_get_16 (abfd, data + member + adj); ordinal = bfd_get_16 (abfd, data + member - adj);
member_name = (char *) data + member + adj + 2; member_name = (char *) data + member - adj + 2;
fprintf (file, "\t%04lx\t %4d %s", fprintf (file, "\t%04lx\t %4d %s",
member, ordinal, member_name); member, ordinal, member_name);
} }
@@ -1188,7 +1175,7 @@ pe_print_idata (abfd, vfile)
&& first_thunk != 0 && first_thunk != 0
&& first_thunk != hint_addr) && first_thunk != hint_addr)
fprintf (file, "\t%04lx", fprintf (file, "\t%04lx",
bfd_get_32 (abfd, data + first_thunk + adj + j)); bfd_get_32 (abfd, data + first_thunk - adj + j));
fprintf (file, "\n"); fprintf (file, "\n");
} }
@@ -1199,7 +1186,7 @@ pe_print_idata (abfd, vfile)
int differ = 0; int differ = 0;
int idx2; int idx2;
idx2 = first_thunk + adj; idx2 = first_thunk - adj;
for (j = 0; j < datasize; j += 4) for (j = 0; j < datasize; j += 4)
{ {
@@ -1232,8 +1219,8 @@ pe_print_idata (abfd, vfile)
else else
{ {
ordinal = bfd_get_16(abfd, ordinal = bfd_get_16(abfd,
data + iat_member + adj); data + iat_member - adj);
member_name = (char *) data + iat_member + adj + 2; member_name = (char *) data + iat_member - adj + 2;
fprintf(file, "\t%04lx\t %4d %s\n", fprintf(file, "\t%04lx\t %4d %s\n",
iat_member, ordinal, member_name); iat_member, ordinal, member_name);
} }
@@ -1265,13 +1252,13 @@ pe_print_edata (abfd, vfile)
{ {
FILE *file = (FILE *) vfile; FILE *file = (FILE *) vfile;
bfd_byte *data = 0; bfd_byte *data = 0;
asection *section = bfd_get_section_by_name (abfd, ".edata"); asection *section;
bfd_size_type datasize; bfd_size_type datasize;
bfd_size_type dataoff; bfd_size_type dataoff;
bfd_size_type i; bfd_size_type i;
int adj; bfd_signed_vma adj;
struct EDT_type struct EDT_type
{ {
long export_flags; /* reserved - should be zero */ long export_flags; /* reserved - should be zero */
@@ -1290,29 +1277,22 @@ pe_print_edata (abfd, vfile)
pe_data_type *pe = pe_data (abfd); pe_data_type *pe = pe_data (abfd);
struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr; struct internal_extra_pe_aouthdr *extra = &pe->pe_opthdr;
if (section != NULL) bfd_vma addr;
{
datasize = bfd_section_size (abfd, section);
dataoff = 0;
fprintf (file, _("\nThe export table is the .edata section\n"));
}
else
{
/* edata is buried in some other section: e.g. NTDLL.DLL. */
bfd_vma addr, size;
addr = extra->DataDirectory[0].VirtualAddress; addr = extra->DataDirectory[0].VirtualAddress;
size = extra->DataDirectory[0].Size; datasize = extra->DataDirectory[0].Size;
if (addr == 0 || size == 0) if (addr == 0 || datasize == 0)
return true; return true;
addr += extra->ImageBase;
for (section = abfd->sections; section != NULL; section = section->next) for (section = abfd->sections; section != NULL; section = section->next)
{ {
if (addr >= section->vma if (addr >= section->vma
&& addr < section->vma + bfd_section_size (abfd, section)) && addr < section->vma + bfd_section_size (abfd, section))
break; break;
} }
if (section == NULL) if (section == NULL)
{ {
fprintf (file, fprintf (file,
@@ -1323,12 +1303,10 @@ pe_print_edata (abfd, vfile)
fprintf (file, _("\nThere is an export table in %s at 0x%lx\n"), fprintf (file, _("\nThere is an export table in %s at 0x%lx\n"),
section->name, (unsigned long) addr); section->name, (unsigned long) addr);
datasize = size;
dataoff = addr - section->vma; dataoff = addr - section->vma;
}
data = (bfd_byte *) bfd_malloc (datasize); data = (bfd_byte *) bfd_malloc (datasize);
if (data == NULL && datasize != 0) if (data == NULL)
return false; return false;
if (! bfd_get_section_contents (abfd, section, (PTR) data, dataoff, if (! bfd_get_section_contents (abfd, section, (PTR) data, dataoff,
@@ -1348,11 +1326,12 @@ pe_print_edata (abfd, vfile)
edt.npt_addr = bfd_get_32(abfd, data+32); edt.npt_addr = bfd_get_32(abfd, data+32);
edt.ot_addr = bfd_get_32(abfd, data+36); edt.ot_addr = bfd_get_32(abfd, data+36);
adj = - (section->vma + dataoff); adj = section->vma - extra->ImageBase + dataoff;
/* Dump the EDT first first */ /* Dump the EDT first first */
fprintf(file, fprintf(file,
_("\nThe Export Tables (interpreted .edata section contents)\n\n")); _("\nThe Export Tables (interpreted %s section contents)\n\n"),
section->name);
fprintf(file, fprintf(file,
_("Export Flags \t\t\t%lx\n"), (unsigned long) edt.export_flags); _("Export Flags \t\t\t%lx\n"), (unsigned long) edt.export_flags);
@@ -1367,7 +1346,7 @@ pe_print_edata (abfd, vfile)
_("Name \t\t\t\t")); _("Name \t\t\t\t"));
fprintf_vma (file, edt.name); fprintf_vma (file, edt.name);
fprintf (file, fprintf (file,
" %s\n", data + edt.name + adj); " %s\n", data + edt.name - adj);
fprintf(file, fprintf(file,
_("Ordinal Base \t\t\t%ld\n"), edt.base); _("Ordinal Base \t\t\t%ld\n"), edt.base);
@@ -1376,11 +1355,11 @@ pe_print_edata (abfd, vfile)
_("Number in:\n")); _("Number in:\n"));
fprintf(file, fprintf(file,
_("\tExport Address Table \t\t%lx\n"), _("\tExport Address Table \t\t%08lx\n"),
edt.num_functions); edt.num_functions);
fprintf(file, fprintf(file,
_("\t[Name Pointer/Ordinal] Table\t%lu\n"), edt.num_names); _("\t[Name Pointer/Ordinal] Table\t%08lx\n"), edt.num_names);
fprintf(file, fprintf(file,
_("Table Addresses\n")); _("Table Addresses\n"));
@@ -1418,7 +1397,7 @@ pe_print_edata (abfd, vfile)
for (i = 0; i < edt.num_functions; ++i) for (i = 0; i < edt.num_functions; ++i)
{ {
bfd_vma eat_member = bfd_get_32 (abfd, bfd_vma eat_member = bfd_get_32 (abfd,
data + edt.eat_addr + (i * 4) + adj); data + edt.eat_addr + (i * 4) - adj);
bfd_vma eat_actual = eat_member; bfd_vma eat_actual = eat_member;
bfd_vma edata_start = bfd_get_section_vma (abfd, section); bfd_vma edata_start = bfd_get_section_vma (abfd, section);
bfd_vma edata_end = edata_start + datasize; bfd_vma edata_end = edata_start + datasize;
@@ -1433,7 +1412,7 @@ pe_print_edata (abfd, vfile)
fprintf (file, fprintf (file,
"\t[%4ld] +base[%4ld] %04lx %s -- %s\n", "\t[%4ld] +base[%4ld] %04lx %s -- %s\n",
(long) i, (long) (i + edt.base), eat_member, (long) i, (long) (i + edt.base), eat_member,
_("Forwarder RVA"), data + eat_member + adj); _("Forwarder RVA"), data + eat_member - adj);
} }
else else
{ {
@@ -1455,14 +1434,14 @@ pe_print_edata (abfd, vfile)
bfd_vma name_ptr = bfd_get_32(abfd, bfd_vma name_ptr = bfd_get_32(abfd,
data + data +
edt.npt_addr edt.npt_addr
+ (i*4) + adj); + (i*4) - adj);
char *name = (char *) data + name_ptr + adj; char *name = (char *) data + name_ptr - adj;
bfd_vma ord = bfd_get_16(abfd, bfd_vma ord = bfd_get_16(abfd,
data + data +
edt.ot_addr edt.ot_addr
+ (i*2) + adj); + (i*2) - adj);
fprintf(file, fprintf(file,
"\t[%4ld] %s\n", (long) ord, name); "\t[%4ld] %s\n", (long) ord, name);
@@ -1740,7 +1719,7 @@ _bfd_pe_print_private_bfd_data_common (abfd, vfile)
fprintf (file,"MinorImageVersion\t%d\n", i->MinorImageVersion); fprintf (file,"MinorImageVersion\t%d\n", i->MinorImageVersion);
fprintf (file,"MajorSubsystemVersion\t%d\n", i->MajorSubsystemVersion); fprintf (file,"MajorSubsystemVersion\t%d\n", i->MajorSubsystemVersion);
fprintf (file,"MinorSubsystemVersion\t%d\n", i->MinorSubsystemVersion); fprintf (file,"MinorSubsystemVersion\t%d\n", i->MinorSubsystemVersion);
fprintf (file,"Reserved1\t\t%08lx\n", i->Reserved1); fprintf (file,"Win32Version\t\t%08lx\n", i->Reserved1);
fprintf (file,"SizeOfImage\t\t%08lx\n", i->SizeOfImage); fprintf (file,"SizeOfImage\t\t%08lx\n", i->SizeOfImage);
fprintf (file,"SizeOfHeaders\t\t%08lx\n", i->SizeOfHeaders); fprintf (file,"SizeOfHeaders\t\t%08lx\n", i->SizeOfHeaders);
fprintf (file,"CheckSum\t\t%08lx\n", i->CheckSum); fprintf (file,"CheckSum\t\t%08lx\n", i->CheckSum);