You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Reflection.PortableExecutable;
|
|
using System.Text;
|
|
|
|
namespace apphost_extract_v2.General
|
|
{
|
|
public abstract class IApphostFile
|
|
{
|
|
internal FileStream FileStream;
|
|
public PEHeaders PEHeader;
|
|
public AppHostFileHeader Header;
|
|
|
|
public IApphostFile(FileStream fs, PEHeaders peheader)
|
|
{
|
|
FileStream = fs;
|
|
PEHeader = peheader;
|
|
}
|
|
|
|
public void ExtractAll(string outputDir)
|
|
{
|
|
Directory.CreateDirectory(outputDir);
|
|
foreach (var fileEntry in Header.Manifest.FileEntries)
|
|
{
|
|
try
|
|
{
|
|
var bytes = FileStream.ReadBuffer(fileEntry.Offset, fileEntry.Size);
|
|
var name = fileEntry.Name;
|
|
var filePath = Path.Combine(outputDir, name);
|
|
File.WriteAllBytes(filePath, bytes);
|
|
|
|
Log.Critical($"Extracted {name}");
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error($"Could not extract {fileEntry.Name}: {ex.Message}");
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
public abstract void Close();
|
|
}
|
|
}
|