From 7d5fbfaaca0133e6c4cf64d5357f0fd3be1778a2 Mon Sep 17 00:00:00 2001 From: VollRahm Date: Thu, 25 Feb 2021 19:52:51 +0100 Subject: [PATCH] - Multithreaded extraction --- src/apphost-extract/apphost-extract-v2/FileChecker.cs | 10 +++++++--- .../apphost-extract-v2/Models/ApphostFile30.cs | 4 ++++ .../apphost-extract-v2/Models/ApphostFile31.cs | 5 ++++- .../apphost-extract-v2/Models/General/IApphostFile.cs | 6 +++--- src/apphost-extract/apphost-extract-v2/Program.cs | 2 +- src/apphost-extract/apphost-extract-v2/Util.cs | 7 +++++-- 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/apphost-extract/apphost-extract-v2/FileChecker.cs b/src/apphost-extract/apphost-extract-v2/FileChecker.cs index f147c97..d152dd4 100644 --- a/src/apphost-extract/apphost-extract-v2/FileChecker.cs +++ b/src/apphost-extract/apphost-extract-v2/FileChecker.cs @@ -11,9 +11,9 @@ namespace apphost_extract_v2 { public static class FileChecker { - private const string HASHFILE = "apphost-hashes.txt"; - private static SHA256Managed sha = new SHA256Managed(); + private const string HASHFILE = "apphost-hashes.txt"; private static string[] Hashes; + private static SHA256Managed sha = new SHA256Managed(); public static void Load() { @@ -30,7 +30,11 @@ namespace apphost_extract_v2 public static bool IsKnownFile(byte[] buffer) { - var hash = BitConverter.ToString(sha.ComputeHash(buffer)).Replace("-", ""); + string hash = ""; + lock (sha) + { + hash = BitConverter.ToString(sha.ComputeHash(buffer)).Replace("-", ""); + } return Hashes.Contains(hash) || SignedByMS(buffer); } diff --git a/src/apphost-extract/apphost-extract-v2/Models/ApphostFile30.cs b/src/apphost-extract/apphost-extract-v2/Models/ApphostFile30.cs index 03f3e7a..e92b8db 100644 --- a/src/apphost-extract/apphost-extract-v2/Models/ApphostFile30.cs +++ b/src/apphost-extract/apphost-extract-v2/Models/ApphostFile30.cs @@ -18,6 +18,10 @@ namespace apphost_extract_v2.Models Header = new AppHostFileHeader(); Log.Info($"Reading header at 0x{HEADER_OFFSET_PTR:X8}..."); var headerAddress = BitConverter.ToInt32(fs.ReadBuffer(HEADER_OFFSET_PTR, 4)); + + if(headerAddress == 0) + Log.Fatal("The address of the Bundle header is 0 :/"); + var headerBuffer = fs.ReadBuffer(headerAddress, HEADER_SIZE); Header.Raw = headerBuffer; diff --git a/src/apphost-extract/apphost-extract-v2/Models/ApphostFile31.cs b/src/apphost-extract/apphost-extract-v2/Models/ApphostFile31.cs index f6d6785..506bd7d 100644 --- a/src/apphost-extract/apphost-extract-v2/Models/ApphostFile31.cs +++ b/src/apphost-extract/apphost-extract-v2/Models/ApphostFile31.cs @@ -17,13 +17,16 @@ namespace apphost_extract_v2.Models { Header = new AppHostFileHeader(); var headerAddress = BitConverter.ToInt32(fs.ReadBuffer(HEADER_OFFSET_PTR, 4)); + + if (headerAddress == 0) + Log.Fatal("The address of the Bundle header is 0 :/"); + var headerBuffer = fs.ReadBuffer(headerAddress, HEADER_SIZE); Log.Info($"Reading header at 0x{HEADER_OFFSET_PTR:X8}..."); Header.Raw = headerBuffer; Header.Path = Encoding.UTF8.GetString(fs.ReadBuffer(headerAddress + HEADER_SIZE, 0xC)); Header.Manifest = ParseManifest(); - } private AppHostManifest ParseManifest() diff --git a/src/apphost-extract/apphost-extract-v2/Models/General/IApphostFile.cs b/src/apphost-extract/apphost-extract-v2/Models/General/IApphostFile.cs index 21b7fe5..3ac1251 100644 --- a/src/apphost-extract/apphost-extract-v2/Models/General/IApphostFile.cs +++ b/src/apphost-extract/apphost-extract-v2/Models/General/IApphostFile.cs @@ -23,8 +23,8 @@ namespace apphost_extract_v2.General { Directory.CreateDirectory(outputDir); - foreach(var fileEntry in Header.Manifest.FileEntries) - //Parallel.ForEach(Header.Manifest.FileEntries, fileEntry => + //foreach(var fileEntry in Header.Manifest.FileEntries) + Parallel.ForEach(Header.Manifest.FileEntries, fileEntry => { try { @@ -47,7 +47,7 @@ namespace apphost_extract_v2.General { Log.Error($"Could not extract {fileEntry.Name}: {ex.Message}"); } - }//); + }); Console.WriteLine(); } diff --git a/src/apphost-extract/apphost-extract-v2/Program.cs b/src/apphost-extract/apphost-extract-v2/Program.cs index 34f505a..c1b5549 100644 --- a/src/apphost-extract/apphost-extract-v2/Program.cs +++ b/src/apphost-extract/apphost-extract-v2/Program.cs @@ -14,7 +14,7 @@ namespace apphost_extract_v2 FileChecker.Load(); - var fileInfo = GetFileInfo(new string[] { "net5.0.2.exe" }); + var fileInfo = GetFileInfo(args); var apphostAnalyzer = new Analyzer(fileInfo); var apphost = apphostAnalyzer.Open(); diff --git a/src/apphost-extract/apphost-extract-v2/Util.cs b/src/apphost-extract/apphost-extract-v2/Util.cs index 60fb6b9..65acb0a 100644 --- a/src/apphost-extract/apphost-extract-v2/Util.cs +++ b/src/apphost-extract/apphost-extract-v2/Util.cs @@ -43,8 +43,11 @@ namespace apphost_extract_v2 public static byte[] ReadBuffer(this FileStream fs, long start, int length) { byte[] buff = new byte[length]; - fs.Seek(start, SeekOrigin.Begin); - fs.Read(buff, 0, length); + lock (fs) + { + fs.Seek(start, SeekOrigin.Begin); + fs.Read(buff, 0, length); + } return buff; }