- Multithreaded extraction

master
VollRagm 4 years ago
parent 20e566d9b7
commit 7d5fbfaaca

@ -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);
}

@ -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;

@ -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()

@ -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();
}

@ -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();

@ -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;
}

Loading…
Cancel
Save