mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-04-24 23:30:07 +00:00
Rewrite PE accelerator table extension
This commit is contained in:
@@ -394,28 +394,34 @@ namespace BurnOutSharp.Builder
|
||||
/// <summary>
|
||||
/// Read resource data as an accelerator table resource
|
||||
/// </summary>
|
||||
/// <param name="data">Data to parse into an accelerator table resource</param>
|
||||
/// <param name="offset">Offset into the byte array</param>
|
||||
/// <param name="data">Resource data entry to parse into an accelerator table resource</param>
|
||||
/// <returns>A filled accelerator table resource on success, null on error</returns>
|
||||
public static Models.PortableExecutable.AcceleratorTableEntry[] AsAcceleratorTableResource(this byte[] data, ref int offset)
|
||||
public static Models.PortableExecutable.AcceleratorTableEntry[] AsAcceleratorTableResource(this Models.PortableExecutable.ResourceDataEntry entry)
|
||||
{
|
||||
// If we have data that's invalid for this resource type, we can't do anything
|
||||
if (data == null || data.Length % 8 != 0)
|
||||
if (entry?.Data == null || entry.Data.Length % 8 != 0)
|
||||
return null;
|
||||
|
||||
// Get the number of entries
|
||||
int count = data.Length / 8;
|
||||
int count = entry.Data.Length / 8;
|
||||
|
||||
// Initialize the iterator
|
||||
int offset = 0;
|
||||
|
||||
// Create the output object
|
||||
var table = new Models.PortableExecutable.AcceleratorTableEntry[count];
|
||||
|
||||
// Read in the table
|
||||
var table = new Models.PortableExecutable.AcceleratorTableEntry[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
var entry = new Models.PortableExecutable.AcceleratorTableEntry();
|
||||
entry.Flags = (Models.PortableExecutable.AcceleratorTableFlags)data.ReadUInt16(ref offset);
|
||||
entry.Ansi = data.ReadUInt16(ref offset);
|
||||
entry.Id = data.ReadUInt16(ref offset);
|
||||
entry.Padding = data.ReadUInt16(ref offset);
|
||||
table[i] = entry;
|
||||
var acceleratorTableEntry = new Models.PortableExecutable.AcceleratorTableEntry();
|
||||
|
||||
acceleratorTableEntry.Flags = (Models.PortableExecutable.AcceleratorTableFlags)entry.Data.ReadUInt16(ref offset);
|
||||
acceleratorTableEntry.Ansi = entry.Data.ReadUInt16(ref offset);
|
||||
acceleratorTableEntry.Id = entry.Data.ReadUInt16(ref offset);
|
||||
acceleratorTableEntry.Padding = entry.Data.ReadUInt16(ref offset);
|
||||
|
||||
table[i] = acceleratorTableEntry;
|
||||
}
|
||||
|
||||
return table;
|
||||
|
||||
@@ -1147,7 +1147,6 @@ namespace ExecutableTest
|
||||
// TODO: Print out per-type data
|
||||
if (types != null && types.Count > 0 && types[0] is uint resourceType)
|
||||
{
|
||||
int offset = 0;
|
||||
switch ((BurnOutSharp.Models.PortableExecutable.ResourceType)resourceType)
|
||||
{
|
||||
case BurnOutSharp.Models.PortableExecutable.ResourceType.RT_CURSOR:
|
||||
@@ -1186,7 +1185,7 @@ namespace ExecutableTest
|
||||
Console.WriteLine($"{padding}Font resource found, not parsed yet");
|
||||
break;
|
||||
case BurnOutSharp.Models.PortableExecutable.ResourceType.RT_ACCELERATOR:
|
||||
var acceleratorTable = entry.Data.AsAcceleratorTableResource(ref offset);
|
||||
var acceleratorTable = entry.AsAcceleratorTableResource();
|
||||
if (acceleratorTable == null)
|
||||
{
|
||||
Console.WriteLine($"{padding}Accelerator table resource found, but malformed");
|
||||
|
||||
Reference in New Issue
Block a user