Skip to content

Commit

Permalink
Fixed issue with empty hint name tables in Imports and Delayed Imports.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkinsella committed Nov 4, 2016
1 parent 182eae0 commit 4a542aa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,27 @@ public static DelayImportHintNameTable Get(DelayImportDirectory directory)
}
}

var first_entry = entries.Values.MinBy(tuple => tuple.Item1);
var last_entry = entries.Values.MaxBy(tuple => tuple.Item1);
Location location;

ulong table_offset = first_entry.Item1;
uint table_size = ((last_entry.Item1 + last_entry.Item2) - table_offset).ToUInt32();
if (entries.Count > 0)
{
var first_entry = entries.Values.MinBy(tuple => tuple.Item1);
var last_entry = entries.Values.MaxBy(tuple => tuple.Item1);

ulong table_offset = first_entry.Item1;
uint table_size = ((last_entry.Item1 + last_entry.Item2) - table_offset).ToUInt32();

uint table_rva = calc.OffsetToRVA(table_offset);
ulong image_base = directory.DataDirectory.Directories.Image.NTHeaders.OptionalHeader.ImageBase;
ulong table_va = image_base + table_rva;
Section table_section = calc.RVAToSection(table_rva);

uint table_rva = calc.OffsetToRVA(table_offset);
ulong image_base = directory.DataDirectory.Directories.Image.NTHeaders.OptionalHeader.ImageBase;
ulong table_va = image_base + table_rva;
Section table_section = calc.RVAToSection(table_rva);
Location location = new Location(table_offset, table_rva, table_va, table_size, table_size, table_section);
location = new Location(table_offset, table_rva, table_va, table_size, table_size, table_section);
}
else
{
location = new Location(0, 0, 0, 0, 0, null);
}

DelayImportHintNameTable hint_name_table = new DelayImportHintNameTable(directory.DataDirectory, location, entries.Values.ToArray());

Expand Down
28 changes: 19 additions & 9 deletions Src/Workshell.PE/Content/Imports/ImportHintNameTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,17 +195,27 @@ public static ImportHintNameTable Get(ImportDirectory directory)
}
}

var first_entry = entries.Values.MinBy(tuple => tuple.Item1);
var last_entry = entries.Values.MaxBy(tuple => tuple.Item1);
Location location;

ulong table_offset = first_entry.Item1;
uint table_size = ((last_entry.Item1 + last_entry.Item2) - table_offset).ToUInt32();
if (entries.Count > 0)
{
var first_entry = entries.Values.MinBy(tuple => tuple.Item1);
var last_entry = entries.Values.MaxBy(tuple => tuple.Item1);

ulong table_offset = first_entry.Item1;
uint table_size = ((last_entry.Item1 + last_entry.Item2) - table_offset).ToUInt32();

uint table_rva = calc.OffsetToRVA(table_offset);
ulong image_base = directory.DataDirectory.Directories.Image.NTHeaders.OptionalHeader.ImageBase;
ulong table_va = image_base + table_rva;
Section table_section = calc.RVAToSection(table_rva);

uint table_rva = calc.OffsetToRVA(table_offset);
ulong image_base = directory.DataDirectory.Directories.Image.NTHeaders.OptionalHeader.ImageBase;
ulong table_va = image_base + table_rva;
Section table_section = calc.RVAToSection(table_rva);
Location location = new Location(table_offset, table_rva, table_va, table_size, table_size, table_section);
location = new Location(table_offset, table_rva, table_va, table_size, table_size, table_section);
}
else
{
location = new Location(0, 0, 0, 0, 0, null);
}

ImportHintNameTable hint_name_table = new ImportHintNameTable(directory.DataDirectory, location, entries.Values.ToArray());

Expand Down

0 comments on commit 4a542aa

Please sign in to comment.