mirror of
https://github.com/SabreTools/BinaryObjectScanner.git
synced 2026-09-23 15:24:45 +00:00
Improve version detection (#29)
* Improve version detection * Address comments * Address comments Co-authored-by: Matt Nadareski <mnadareski@outlook.com>
This commit is contained in:
@@ -1,13 +1,32 @@
|
||||
namespace BurnOutSharp.PackerType
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace BurnOutSharp.PackerType
|
||||
{
|
||||
// TODO: Add extraction and better version detection
|
||||
public class PECompact : IContentCheck
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
public string CheckContents(string file, byte[] fileContent, bool includePosition = false)
|
||||
{
|
||||
// "PEC2"
|
||||
byte?[] check = new byte?[] { 0x50, 0x45, 0x43, 0x32 };
|
||||
// Another possible version string for version 1 is "PECO" (50 45 43 4F)
|
||||
|
||||
// "pec1"
|
||||
byte?[] check = new byte?[] { 0x70, 0x65, 0x63, 0x31 };
|
||||
if (fileContent.FirstPosition(check, out int position, end: 2048))
|
||||
return "PE Compact 1" + (includePosition ? $" (Index {position})" : string.Empty);
|
||||
|
||||
// "PEC2"
|
||||
check = new byte?[] { 0x50, 0x45, 0x43, 0x32 };
|
||||
if (fileContent.FirstPosition(check, out position, end: 2048))
|
||||
{
|
||||
int version = BitConverter.ToInt16(fileContent, position + 4);
|
||||
return $"PE Compact 2 v{version}" + (includePosition ? $" (Index {position})" : string.Empty);
|
||||
}
|
||||
|
||||
// "PECompact2"
|
||||
check = new byte?[] { 0x50, 0x45, 0x43, 0x6F, 0x6D, 0x70, 0x61, 0x63, 0x74, 0x32 };
|
||||
if (fileContent.FirstPosition(check, out position))
|
||||
return "PE Compact 2" + (includePosition ? $" (Index {position})" : string.Empty);
|
||||
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user