Correct handling of BeOS resource index.

This commit is contained in:
2018-03-10 16:52:38 +00:00
parent 0b669a62bf
commit 22d1b6e1f8
3 changed files with 17 additions and 11 deletions

View File

@@ -26,7 +26,7 @@
namespace libexeinfo.BeOS
{
static class Consts
public static class Consts
{
internal const int RESOURCES_HEADER_MAGIC = 0x444F1000;

View File

@@ -23,7 +23,6 @@ namespace libexeinfo.BeOS
if(header.magic != Consts.RESOURCES_HEADER_MAGIC) return null;
ResourceIndexEntry[] indexes = new ResourceIndexEntry[header.resource_count];
pos = header.index_section_offset;
buffer = new byte[Marshal.SizeOf(typeof(ResourceIndexSectionHeader))];
if(pos + buffer.Length > data.Length) return null;
@@ -33,7 +32,11 @@ namespace libexeinfo.BeOS
BigEndianMarshal.ByteArrayToStructureLittleEndian<ResourceIndexSectionHeader>(buffer);
pos += (uint)buffer.Length;
for(int i = 0; i < header.resource_count; i++)
ResourceIndexEntry[] indexes =
new ResourceIndexEntry[(indexHeader.index_section_size -
Marshal.SizeOf(typeof(ResourceIndexSectionHeader))) /
Marshal.SizeOf(typeof(ResourceIndexEntry))];
for(int i = 0; i < indexes.Length; i++)
{
buffer = new byte[Marshal.SizeOf(typeof(ResourceIndexEntry))];
Array.Copy(data, pos, buffer, 0, buffer.Length);
@@ -88,10 +91,10 @@ namespace libexeinfo.BeOS
id = infos[i].id,
index = infos[i].index,
name = names[i],
data = new byte[indexes[i].size]
data = new byte[indexes[infos[i].index - 1].size]
};
Array.Copy(data, indexes[i].offset, rez.data, 0, rez.data.Length);
Array.Copy(data, indexes[infos[i].index - 1].offset, rez.data, 0, rez.data.Length);
thisRezzes.Add(rez);
rezzes.Remove(types[i]);
@@ -118,7 +121,6 @@ namespace libexeinfo.BeOS
if(header.magic != Consts.RESOURCES_HEADER_MAGIC) return null;
ResourceIndexEntry[] indexes = new ResourceIndexEntry[header.resource_count];
pos = header.index_section_offset;
buffer = new byte[Marshal.SizeOf(typeof(ResourceIndexSectionHeader))];
if(pos + buffer.Length > data.Length) return null;
@@ -128,7 +130,11 @@ namespace libexeinfo.BeOS
BigEndianMarshal.ByteArrayToStructureBigEndian<ResourceIndexSectionHeader>(buffer);
pos += (uint)buffer.Length;
for(int i = 0; i < header.resource_count; i++)
ResourceIndexEntry[] indexes =
new ResourceIndexEntry[(indexHeader.index_section_size -
Marshal.SizeOf(typeof(ResourceIndexSectionHeader))) /
Marshal.SizeOf(typeof(ResourceIndexEntry))];
for(int i = 0; i < indexes.Length; i++)
{
buffer = new byte[Marshal.SizeOf(typeof(ResourceIndexEntry))];
Array.Copy(data, pos, buffer, 0, buffer.Length);
@@ -183,10 +189,10 @@ namespace libexeinfo.BeOS
id = infos[i].id,
index = infos[i].index,
name = names[i],
data = new byte[indexes[i].size]
data = new byte[indexes[infos[i].index - 1].size]
};
Array.Copy(data, indexes[i].offset, rez.data, 0, rez.data.Length);
Array.Copy(data, indexes[infos[i].index - 1].offset, rez.data, 0, rez.data.Length);
thisRezzes.Add(rez);
rezzes.Remove(types[i]);

View File

@@ -54,7 +54,7 @@ namespace libexeinfo
public Version[] Versions;
public ResourceNode WindowsResourcesRoot;
WindowsHeader64 winHeader;
public BeOS.ResourceTypeBlock[] beosResources;
public BeOS.ResourceTypeBlock[] BeosResources;
/// <summary>
/// Initializes a new instance of the <see cref="T:libexeinfo.PE" /> class.
@@ -389,7 +389,7 @@ namespace libexeinfo
buffer = new byte[rsrc.sizeOfRawData];
BaseStream.Position = rsrc.pointerToRawData;
BaseStream.Read(buffer, 0, buffer.Length);
beosResources = BeOS.Resources.Decode(buffer);
BeosResources = BeOS.Resources.Decode(buffer);
}
else
{