From 22d1b6e1f8b193795b27e54bb4251aeccc5b0c62 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 10 Mar 2018 16:52:38 +0000 Subject: [PATCH] Correct handling of BeOS resource index. --- libexeinfo/BeOS/Consts.cs | 2 +- libexeinfo/BeOS/Resources.cs | 22 ++++++++++++++-------- libexeinfo/PE/PE.cs | 4 ++-- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/libexeinfo/BeOS/Consts.cs b/libexeinfo/BeOS/Consts.cs index 2bde376..e1d093e 100644 --- a/libexeinfo/BeOS/Consts.cs +++ b/libexeinfo/BeOS/Consts.cs @@ -26,7 +26,7 @@ namespace libexeinfo.BeOS { - static class Consts + public static class Consts { internal const int RESOURCES_HEADER_MAGIC = 0x444F1000; diff --git a/libexeinfo/BeOS/Resources.cs b/libexeinfo/BeOS/Resources.cs index 5838e44..2a91307 100644 --- a/libexeinfo/BeOS/Resources.cs +++ b/libexeinfo/BeOS/Resources.cs @@ -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(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(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]); diff --git a/libexeinfo/PE/PE.cs b/libexeinfo/PE/PE.cs index debbe2d..1aa100c 100644 --- a/libexeinfo/PE/PE.cs +++ b/libexeinfo/PE/PE.cs @@ -54,7 +54,7 @@ namespace libexeinfo public Version[] Versions; public ResourceNode WindowsResourcesRoot; WindowsHeader64 winHeader; - public BeOS.ResourceTypeBlock[] beosResources; + public BeOS.ResourceTypeBlock[] BeosResources; /// /// Initializes a new instance of the 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 {