Skip to content

Commit

Permalink
Improve build detection in dumper
Browse files Browse the repository at this point in the history
  • Loading branch information
Marlamin committed Dec 12, 2023
1 parent 6a07fc4 commit fab7133
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions code/C#/DBDefsDumper/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ static void Main(string[] args)
{
var chunkSize = 1024;

// Find version
var buildPattern = new byte?[] { 0x42, 0x75, 0x69, 0x6C, 0x64, 0x20, null, null, null, null, null, 0x20, 0x28, null, null, null, null, null, 0x29, 0x20, 0x28 };
var buildPatternLength = buildPattern.Length;

var build = "";
var patternOverride = "";

Expand All @@ -50,8 +46,13 @@ static void Main(string[] args)
}
}

// Find version
var buildPattern = new byte?[] { 0x42, 0x75, 0x69, 0x6C, 0x64, 0x20, null, null, null, null, null, 0x20, 0x28, null, null, null, null, null, 0x29, 0x20, 0x28 };
var buildPatternLength = buildPattern.Length;

if (build == "")
{
Console.WriteLine("No build given, scanning executable for \"Build ????? (?????) (\"");
while (true)
{
if ((bin.BaseStream.Length - bin.BaseStream.Position) < chunkSize)
Expand Down Expand Up @@ -79,9 +80,45 @@ static void Main(string[] args)
}
}

if (build == "")
{
Console.WriteLine("No build found, rescanning executable for \"Build ????? (??????) (\"");
bin.BaseStream.Position = 0;

buildPattern = new byte?[] { 0x42, 0x75, 0x69, 0x6C, 0x64, 0x20, null, null, null, null, null, 0x20, 0x28, null, null, null, null, null, null, 0x29, 0x20, 0x28 };
buildPatternLength = buildPattern.Length;

while (true)
{
if ((bin.BaseStream.Length - bin.BaseStream.Position) < chunkSize)
{
break;
}

var posInStack = Search(bin.ReadBytes(chunkSize), buildPattern);

if (posInStack != chunkSize)
{
var matchPos = bin.BaseStream.Position - chunkSize + posInStack;

bin.BaseStream.Position = matchPos;
bin.ReadBytes(6);
var buildNumber = new string(bin.ReadChars(5));
bin.ReadBytes(2);
var patch = new string(bin.ReadChars(6));
build = patch + "." + buildNumber;
}
else
{
bin.BaseStream.Position = bin.BaseStream.Position - buildPatternLength;
}
}
}

if (build == "")
{
// Retry with backup pattern (crash log output)
Console.WriteLine("No build found, rescanning executable for \"0x00<Version> \"");
bin.BaseStream.Position = 0;

buildPattern = new byte?[] { 0x00, 0x3C, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x3E, 0x20 }; // <Version>
Expand Down Expand Up @@ -116,7 +153,10 @@ static void Main(string[] args)
break;
}
}
build = sb.ToString();

// Filter out second pattern match of "<Version> %s%s" by checking if build is formatted correctly
if (sb.ToString().Split('.').Length == 4)
build = sb.ToString();
}
else
{
Expand All @@ -130,7 +170,8 @@ static void Main(string[] args)
// Retry with RenderService pattern..
bin.BaseStream.Position = 0;

buildPattern = new byte?[] { 0x52, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, null, null, null, null, null, 0x00 }; // <Version>
Console.WriteLine("No build found, rescanning executable for \"RenderService ?????0x00\"");
buildPattern = new byte?[] { 0x52, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x20, null, null, null, null, null, 0x00 }; // RenderService ?????0x00
buildPatternLength = buildPattern.Length;

while (true)
Expand Down

0 comments on commit fab7133

Please sign in to comment.