From 7d95a43b4b3af59ae6291279cbd1a953cbe6d8c0 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Sat, 14 Jan 2023 23:26:52 -0800 Subject: [PATCH] Fix RCDATA issue --- BurnOutSharp.Wrappers/PortableExecutable.cs | 40 +++++++++++++-------- 1 file changed, 26 insertions(+), 14 deletions(-) diff --git a/BurnOutSharp.Wrappers/PortableExecutable.cs b/BurnOutSharp.Wrappers/PortableExecutable.cs index fe105fc5..04ddf034 100644 --- a/BurnOutSharp.Wrappers/PortableExecutable.cs +++ b/BurnOutSharp.Wrappers/PortableExecutable.cs @@ -2454,24 +2454,36 @@ namespace BurnOutSharp.Wrappers builder.AppendLine($"{padding}Application-defined resource found, not parsed yet"); // Then print the data, if needed - if (entry.Data[0] == 0x4D && entry.Data[1] == 0x5A) + if (entry.Data == null) { - builder.AppendLine($"{padding}Data: [Embedded Executable File]"); // TODO: Parse this out and print separately - } - else if (entry.Data[0] == 0x4D && entry.Data[1] == 0x53 && entry.Data[2] == 0x46 && entry.Data[3] == 0x54) - { - builder.AppendLine($"{padding}Data: [Embedded OLE Library File]"); // TODO: Parse this out and print separately + builder.AppendLine($"{padding}Data: [NULL] (This may indicate a very large resource)"); } else { - //if (entry.Data != null) - // builder.AppendLine($"{padding}Value (Byte Data): {BitConverter.ToString(entry.Data).Replace('-', ' ')}"); - //if (entry.Data != null) - // builder.AppendLine($"{padding}Value (ASCII): {Encoding.ASCII.GetString(entry.Data)}"); - //if (entry.Data != null) - // builder.AppendLine($"{padding}Value (UTF-8): {Encoding.UTF8.GetString(entry.Data)}"); - //if (entry.Data != null) - // builder.AppendLine($"{padding}Value (Unicode): {Encoding.Unicode.GetString(entry.Data)}"); + int offset = 0; + byte[] magic = entry.Data.ReadBytes(ref offset, Math.Min(entry.Data.Length, 16)); + + if (entry.Data[0] == 0x4D && entry.Data[1] == 0x5A) + { + builder.AppendLine($"{padding}Data: [Embedded Executable File]"); // TODO: Parse this out and print separately + } + else if (entry.Data[0] == 0x4D && entry.Data[1] == 0x53 && entry.Data[2] == 0x46 && entry.Data[3] == 0x54) + { + builder.AppendLine($"{padding}Data: [Embedded OLE Library File]"); // TODO: Parse this out and print separately + } + else + { + builder.AppendLine($"{padding}Data: {BitConverter.ToString(magic).Replace('-', ' ')} ..."); + + //if (entry.Data != null) + // builder.AppendLine($"{padding}Value (Byte Data): {BitConverter.ToString(entry.Data).Replace('-', ' ')}"); + //if (entry.Data != null) + // builder.AppendLine($"{padding}Value (ASCII): {Encoding.ASCII.GetString(entry.Data)}"); + //if (entry.Data != null) + // builder.AppendLine($"{padding}Value (UTF-8): {Encoding.UTF8.GetString(entry.Data)}"); + //if (entry.Data != null) + // builder.AppendLine($"{padding}Value (Unicode): {Encoding.Unicode.GetString(entry.Data)}"); + } } }