mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-05-17 15:47:05 +00:00
Safeguard all PE virtual address uses
This commit is contained in:
@@ -843,14 +843,19 @@ namespace BurnOutSharp.Builder
|
||||
if (exportDirectoryTable.NameRVA != 0)
|
||||
{
|
||||
offset = (int)exportDirectoryTable.NameRVA.ConvertVirtualAddress(sections);
|
||||
string name = data.ReadString(ref offset, System.Text.Encoding.ASCII);
|
||||
if (offset != 0)
|
||||
{
|
||||
string name = data.ReadString(ref offset, Encoding.ASCII);
|
||||
exportDirectoryTable.Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
// Address table
|
||||
if (exportDirectoryTable.AddressTableEntries != 0 && exportDirectoryTable.ExportAddressTableRVA != 0)
|
||||
{
|
||||
offset = (int)exportDirectoryTable.ExportAddressTableRVA.ConvertVirtualAddress(sections);
|
||||
if (offset != 0)
|
||||
{
|
||||
var exportAddressTable = new ExportAddressTableEntry[exportDirectoryTable.AddressTableEntries];
|
||||
|
||||
for (int i = 0; i < exportDirectoryTable.AddressTableEntries; i++)
|
||||
@@ -866,11 +871,14 @@ namespace BurnOutSharp.Builder
|
||||
|
||||
exportTable.ExportAddressTable = exportAddressTable;
|
||||
}
|
||||
}
|
||||
|
||||
// Name pointer table
|
||||
if (exportDirectoryTable.NumberOfNamePointers != 0 && exportDirectoryTable.NamePointerRVA != 0)
|
||||
{
|
||||
offset = (int)exportDirectoryTable.NamePointerRVA.ConvertVirtualAddress(sections);
|
||||
if (offset != 0)
|
||||
{
|
||||
var namePointerTable = new ExportNamePointerTable();
|
||||
|
||||
namePointerTable.Pointers = new uint[exportDirectoryTable.NumberOfNamePointers];
|
||||
@@ -882,11 +890,14 @@ namespace BurnOutSharp.Builder
|
||||
|
||||
exportTable.NamePointerTable = namePointerTable;
|
||||
}
|
||||
}
|
||||
|
||||
// Ordinal table
|
||||
if (exportDirectoryTable.NumberOfNamePointers != 0 && exportDirectoryTable.OrdinalTableRVA != 0)
|
||||
{
|
||||
offset = (int)exportDirectoryTable.OrdinalTableRVA.ConvertVirtualAddress(sections);
|
||||
if (offset != 0)
|
||||
{
|
||||
var exportOrdinalTable = new ExportOrdinalTable();
|
||||
|
||||
exportOrdinalTable.Indexes = new ushort[exportDirectoryTable.NumberOfNamePointers];
|
||||
@@ -898,22 +909,26 @@ namespace BurnOutSharp.Builder
|
||||
|
||||
exportTable.OrdinalTable = exportOrdinalTable;
|
||||
}
|
||||
}
|
||||
|
||||
// Name table
|
||||
if (exportDirectoryTable.NumberOfNamePointers != 0 && exportDirectoryTable.NameRVA != 0)
|
||||
{
|
||||
offset = (int)exportDirectoryTable.NameRVA.ConvertVirtualAddress(sections);
|
||||
if (offset != 0)
|
||||
{
|
||||
var exportNameTable = new ExportNameTable();
|
||||
|
||||
exportNameTable.Strings = new string[exportDirectoryTable.NumberOfNamePointers];
|
||||
for (int i = 0; i < exportDirectoryTable.NumberOfNamePointers; i++)
|
||||
{
|
||||
string str = data.ReadString(ref offset, System.Text.Encoding.ASCII);
|
||||
string str = data.ReadString(ref offset, Encoding.ASCII);
|
||||
exportNameTable.Strings[i] = str;
|
||||
}
|
||||
|
||||
exportTable.ExportNameTable = exportNameTable;
|
||||
}
|
||||
}
|
||||
|
||||
return exportTable;
|
||||
}
|
||||
@@ -965,10 +980,13 @@ namespace BurnOutSharp.Builder
|
||||
if (importDirectoryTableEntry.NameRVA != 0)
|
||||
{
|
||||
int nameAddress = (int)importDirectoryTableEntry.NameRVA.ConvertVirtualAddress(sections);
|
||||
string name = data.ReadString(ref nameAddress, System.Text.Encoding.ASCII);
|
||||
if (nameAddress != 0)
|
||||
{
|
||||
string name = data.ReadString(ref nameAddress, Encoding.ASCII);
|
||||
importDirectoryTableEntry.Name = name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Lookup tables
|
||||
var importLookupTables = new Dictionary<int, ImportLookupTableEntry[]>();
|
||||
@@ -979,6 +997,8 @@ namespace BurnOutSharp.Builder
|
||||
if (importDirectoryTableEntry.ImportLookupTableRVA != 0)
|
||||
{
|
||||
int tableAddress = (int)importDirectoryTableEntry.ImportLookupTableRVA.ConvertVirtualAddress(sections);
|
||||
if (tableAddress != 0)
|
||||
{
|
||||
var entryLookupTable = new List<ImportLookupTableEntry>();
|
||||
|
||||
while (true)
|
||||
@@ -1016,6 +1036,7 @@ namespace BurnOutSharp.Builder
|
||||
importLookupTables[i] = entryLookupTable.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
importTable.ImportLookupTables = importLookupTables;
|
||||
|
||||
@@ -1028,6 +1049,8 @@ namespace BurnOutSharp.Builder
|
||||
if (importDirectoryTableEntry.ImportAddressTableRVA != 0)
|
||||
{
|
||||
int tableAddress = (int)importDirectoryTableEntry.ImportAddressTableRVA.ConvertVirtualAddress(sections);
|
||||
if (tableAddress != 0)
|
||||
{
|
||||
var entryAddressTable = new List<ImportAddressTableEntry>();
|
||||
|
||||
while (true)
|
||||
@@ -1056,6 +1079,7 @@ namespace BurnOutSharp.Builder
|
||||
importAddressTables[i] = entryAddressTable.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
importTable.ImportAddressTables = importAddressTables;
|
||||
|
||||
@@ -1078,10 +1102,13 @@ namespace BurnOutSharp.Builder
|
||||
for (int i = 0; i < hintNameTableEntryAddresses.Count; i++)
|
||||
{
|
||||
int hintNameTableEntryAddress = hintNameTableEntryAddresses[i];
|
||||
if (hintNameTableEntryAddress == 0)
|
||||
continue;
|
||||
|
||||
var hintNameTableEntry = new HintNameTableEntry();
|
||||
|
||||
hintNameTableEntry.Hint = data.ReadUInt16(ref hintNameTableEntryAddress);
|
||||
hintNameTableEntry.Name = data.ReadString(ref hintNameTableEntryAddress, System.Text.Encoding.ASCII);
|
||||
hintNameTableEntry.Name = data.ReadString(ref hintNameTableEntryAddress, Encoding.ASCII);
|
||||
|
||||
importHintNameTable.Add(hintNameTableEntry);
|
||||
}
|
||||
@@ -2049,16 +2076,21 @@ namespace BurnOutSharp.Builder
|
||||
if (exportDirectoryTable.NameRVA != 0)
|
||||
{
|
||||
uint nameAddress = exportDirectoryTable.NameRVA.ConvertVirtualAddress(sections);
|
||||
if (nameAddress != 0)
|
||||
{
|
||||
data.Seek(nameAddress, SeekOrigin.Begin);
|
||||
|
||||
string name = data.ReadString(System.Text.Encoding.ASCII);
|
||||
string name = data.ReadString(Encoding.ASCII);
|
||||
exportDirectoryTable.Name = name;
|
||||
}
|
||||
}
|
||||
|
||||
// Address table
|
||||
if (exportDirectoryTable.AddressTableEntries != 0 && exportDirectoryTable.ExportAddressTableRVA != 0)
|
||||
{
|
||||
uint exportAddressTableAddress = exportDirectoryTable.ExportAddressTableRVA.ConvertVirtualAddress(sections);
|
||||
if (exportAddressTableAddress != 0)
|
||||
{
|
||||
data.Seek(exportAddressTableAddress, SeekOrigin.Begin);
|
||||
|
||||
var exportAddressTable = new ExportAddressTableEntry[exportDirectoryTable.AddressTableEntries];
|
||||
@@ -2076,11 +2108,14 @@ namespace BurnOutSharp.Builder
|
||||
|
||||
exportTable.ExportAddressTable = exportAddressTable;
|
||||
}
|
||||
}
|
||||
|
||||
// Name pointer table
|
||||
if (exportDirectoryTable.NumberOfNamePointers != 0 && exportDirectoryTable.NamePointerRVA != 0)
|
||||
{
|
||||
uint namePointerTableAddress = exportDirectoryTable.NamePointerRVA.ConvertVirtualAddress(sections);
|
||||
if (namePointerTableAddress != 0)
|
||||
{
|
||||
data.Seek(namePointerTableAddress, SeekOrigin.Begin);
|
||||
|
||||
var namePointerTable = new ExportNamePointerTable();
|
||||
@@ -2094,11 +2129,14 @@ namespace BurnOutSharp.Builder
|
||||
|
||||
exportTable.NamePointerTable = namePointerTable;
|
||||
}
|
||||
}
|
||||
|
||||
// Ordinal table
|
||||
if (exportDirectoryTable.NumberOfNamePointers != 0 && exportDirectoryTable.OrdinalTableRVA != 0)
|
||||
{
|
||||
uint ordinalTableAddress = exportDirectoryTable.OrdinalTableRVA.ConvertVirtualAddress(sections);
|
||||
if (ordinalTableAddress != 0)
|
||||
{
|
||||
data.Seek(ordinalTableAddress, SeekOrigin.Begin);
|
||||
|
||||
var exportOrdinalTable = new ExportOrdinalTable();
|
||||
@@ -2112,11 +2150,14 @@ namespace BurnOutSharp.Builder
|
||||
|
||||
exportTable.OrdinalTable = exportOrdinalTable;
|
||||
}
|
||||
}
|
||||
|
||||
// Name table
|
||||
if (exportDirectoryTable.NumberOfNamePointers != 0 && exportDirectoryTable.NameRVA != 0)
|
||||
{
|
||||
uint nameTableAddress = exportDirectoryTable.NameRVA.ConvertVirtualAddress(sections);
|
||||
if (nameTableAddress != 0)
|
||||
{
|
||||
data.Seek(nameTableAddress, SeekOrigin.Begin);
|
||||
|
||||
var exportNameTable = new ExportNameTable();
|
||||
@@ -2130,6 +2171,7 @@ namespace BurnOutSharp.Builder
|
||||
|
||||
exportTable.ExportNameTable = exportNameTable;
|
||||
}
|
||||
}
|
||||
|
||||
return exportTable;
|
||||
}
|
||||
@@ -2182,7 +2224,7 @@ namespace BurnOutSharp.Builder
|
||||
uint nameAddress = importDirectoryTableEntry.NameRVA.ConvertVirtualAddress(sections);
|
||||
data.Seek(nameAddress, SeekOrigin.Begin);
|
||||
|
||||
string name = data.ReadString(System.Text.Encoding.ASCII);
|
||||
string name = data.ReadString(Encoding.ASCII);
|
||||
importDirectoryTableEntry.Name = name;
|
||||
}
|
||||
}
|
||||
@@ -2304,7 +2346,7 @@ namespace BurnOutSharp.Builder
|
||||
var hintNameTableEntry = new HintNameTableEntry();
|
||||
|
||||
hintNameTableEntry.Hint = data.ReadUInt16();
|
||||
hintNameTableEntry.Name = data.ReadString(System.Text.Encoding.ASCII);
|
||||
hintNameTableEntry.Name = data.ReadString(Encoding.ASCII);
|
||||
|
||||
importHintNameTable.Add(hintNameTableEntry);
|
||||
}
|
||||
@@ -2403,7 +2445,7 @@ namespace BurnOutSharp.Builder
|
||||
|
||||
// Read the data from the offset
|
||||
offset = resourceDataEntry.DataRVA.ConvertVirtualAddress(sections);
|
||||
if (offset > 0)
|
||||
if (offset != 0)
|
||||
{
|
||||
data.Seek(offset, SeekOrigin.Begin);
|
||||
resourceDataEntry.Data = data.ReadBytes((int)resourceDataEntry.Size);
|
||||
@@ -2430,7 +2472,7 @@ namespace BurnOutSharp.Builder
|
||||
|
||||
// Read the data from the offset
|
||||
offset = resourceDataEntry.DataRVA.ConvertVirtualAddress(sections);
|
||||
if (offset > 0)
|
||||
if (offset != 0)
|
||||
{
|
||||
data.Seek(offset, SeekOrigin.Begin);
|
||||
resourceDataEntry.Data = data.ReadBytes((int)resourceDataEntry.Size);
|
||||
|
||||
Reference in New Issue
Block a user