- Multithreaded extraction

master
VollRagm 4 years ago
parent 20e566d9b7
commit 7d5fbfaaca

@ -12,8 +12,8 @@ namespace apphost_extract_v2
public static class FileChecker public static class FileChecker
{ {
private const string HASHFILE = "apphost-hashes.txt"; private const string HASHFILE = "apphost-hashes.txt";
private static SHA256Managed sha = new SHA256Managed();
private static string[] Hashes; private static string[] Hashes;
private static SHA256Managed sha = new SHA256Managed();
public static void Load() public static void Load()
{ {
@ -30,7 +30,11 @@ namespace apphost_extract_v2
public static bool IsKnownFile(byte[] buffer) 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); return Hashes.Contains(hash) || SignedByMS(buffer);
} }

@ -18,6 +18,10 @@ namespace apphost_extract_v2.Models
Header = new AppHostFileHeader(); Header = new AppHostFileHeader();
Log.Info($"Reading header at 0x{HEADER_OFFSET_PTR:X8}..."); Log.Info($"Reading header at 0x{HEADER_OFFSET_PTR:X8}...");
var headerAddress = BitConverter.ToInt32(fs.ReadBuffer(HEADER_OFFSET_PTR, 4)); 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); var headerBuffer = fs.ReadBuffer(headerAddress, HEADER_SIZE);
Header.Raw = headerBuffer; Header.Raw = headerBuffer;

@ -17,13 +17,16 @@ namespace apphost_extract_v2.Models
{ {
Header = new AppHostFileHeader(); Header = new AppHostFileHeader();
var headerAddress = BitConverter.ToInt32(fs.ReadBuffer(HEADER_OFFSET_PTR, 4)); 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); var headerBuffer = fs.ReadBuffer(headerAddress, HEADER_SIZE);
Log.Info($"Reading header at 0x{HEADER_OFFSET_PTR:X8}..."); Log.Info($"Reading header at 0x{HEADER_OFFSET_PTR:X8}...");
Header.Raw = headerBuffer; Header.Raw = headerBuffer;
Header.Path = Encoding.UTF8.GetString(fs.ReadBuffer(headerAddress + HEADER_SIZE, 0xC)); Header.Path = Encoding.UTF8.GetString(fs.ReadBuffer(headerAddress + HEADER_SIZE, 0xC));
Header.Manifest = ParseManifest(); Header.Manifest = ParseManifest();
} }
private AppHostManifest ParseManifest() private AppHostManifest ParseManifest()

@ -23,8 +23,8 @@ namespace apphost_extract_v2.General
{ {
Directory.CreateDirectory(outputDir); Directory.CreateDirectory(outputDir);
foreach(var fileEntry in Header.Manifest.FileEntries) //foreach(var fileEntry in Header.Manifest.FileEntries)
//Parallel.ForEach(Header.Manifest.FileEntries, fileEntry => Parallel.ForEach(Header.Manifest.FileEntries, fileEntry =>
{ {
try try
{ {
@ -47,7 +47,7 @@ namespace apphost_extract_v2.General
{ {
Log.Error($"Could not extract {fileEntry.Name}: {ex.Message}"); Log.Error($"Could not extract {fileEntry.Name}: {ex.Message}");
} }
}//); });
Console.WriteLine(); Console.WriteLine();
} }

@ -14,7 +14,7 @@ namespace apphost_extract_v2
FileChecker.Load(); FileChecker.Load();
var fileInfo = GetFileInfo(new string[] { "net5.0.2.exe" }); var fileInfo = GetFileInfo(args);
var apphostAnalyzer = new Analyzer(fileInfo); var apphostAnalyzer = new Analyzer(fileInfo);
var apphost = apphostAnalyzer.Open(); var apphost = apphostAnalyzer.Open();

@ -43,8 +43,11 @@ namespace apphost_extract_v2
public static byte[] ReadBuffer(this FileStream fs, long start, int length) public static byte[] ReadBuffer(this FileStream fs, long start, int length)
{ {
byte[] buff = new byte[length]; byte[] buff = new byte[length];
lock (fs)
{
fs.Seek(start, SeekOrigin.Begin); fs.Seek(start, SeekOrigin.Begin);
fs.Read(buff, 0, length); fs.Read(buff, 0, length);
}
return buff; return buff;
} }

Loading…
Cancel
Save