Files
BinaryObjectScanner/BurnOutSharp/ProtectionType/UPX.cs
Matt Nadareski a42040d644 Add UPX checking
2020-10-26 23:30:06 -07:00

33 lines
906 B
C#

using System.Text;
namespace BurnOutSharp.ProtectionType
{
public class UPX
{
public static string CheckContents(byte[] fileContent, bool includePosition = false)
{
// UPX!
byte[] check = new byte[] { 0x55, 0x50, 0x58, 0x21 };
if (fileContent.Contains(check, out int position))
{
string version = GetVersion(fileContent, position);
return $"UPX {version}" + (includePosition ? $" (Index {position})" : string.Empty);
}
return null;
}
private static string GetVersion(byte[] fileContent, int index)
{
try
{
index -= 5;
return Encoding.ASCII.GetString(fileContent, index, 4);
}
catch
{
return "(Unknown Version)";
}
}
}
}