From 162e6dd552e7555e1c7b4bf369ee110697d62934 Mon Sep 17 00:00:00 2001 From: VollRahm Date: Fri, 22 Jan 2021 19:51:07 +0100 Subject: [PATCH] Implemented part of the File structure --- .../apphost-extract/AppHostFile.cs | 41 +++++++++++++ .../apphost-extract/AppHostFileEntry.cs | 12 ++++ .../apphost-extract/AppHostFileHeader.cs | 40 ++++++++++++ .../apphost-extract/AppHostManifest.cs | 19 ++++++ src/apphost-extract/apphost-extract/Log.cs | 61 +++++++++++++++++++ .../apphost-extract/Program.cs | 3 + .../apphost-extract/apphost-extract.csproj | 4 ++ 7 files changed, 180 insertions(+) create mode 100644 src/apphost-extract/apphost-extract/AppHostFile.cs create mode 100644 src/apphost-extract/apphost-extract/AppHostFileEntry.cs create mode 100644 src/apphost-extract/apphost-extract/AppHostFileHeader.cs create mode 100644 src/apphost-extract/apphost-extract/AppHostManifest.cs create mode 100644 src/apphost-extract/apphost-extract/Log.cs diff --git a/src/apphost-extract/apphost-extract/AppHostFile.cs b/src/apphost-extract/apphost-extract/AppHostFile.cs new file mode 100644 index 0000000..f04ce35 --- /dev/null +++ b/src/apphost-extract/apphost-extract/AppHostFile.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace apphost_extract +{ + public class AppHostFile + { + private FileStream FileStream; + + public AppHostFileHeader Header { get; set; } + + + public AppHostFile(FileStream fileStream) + { + FileStream = fileStream; + Header = new AppHostFileHeader(FileStream); + } + + + public static AppHostFile Open(string path) + { + if (!File.Exists(path)) Log.Fatal("File not found."); + + try + { + FileStream fs = new FileStream(path, FileMode.Open, FileAccess.ReadWrite); + AppHostFile file = new AppHostFile(fs); + return file; + } + catch(Exception ex) + { + Log.Fatal($"Exception when trying to open file: {ex.Message}"); + return null; + } + } + } +} diff --git a/src/apphost-extract/apphost-extract/AppHostFileEntry.cs b/src/apphost-extract/apphost-extract/AppHostFileEntry.cs new file mode 100644 index 0000000..05bc4ea --- /dev/null +++ b/src/apphost-extract/apphost-extract/AppHostFileEntry.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace apphost_extract +{ + public class AppHostFileEntry + { + } +} diff --git a/src/apphost-extract/apphost-extract/AppHostFileHeader.cs b/src/apphost-extract/apphost-extract/AppHostFileHeader.cs new file mode 100644 index 0000000..cb672c3 --- /dev/null +++ b/src/apphost-extract/apphost-extract/AppHostFileHeader.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace apphost_extract +{ + public class AppHostFileHeader + { + private const int HEADER_OFFSET = 0x1DE7E2; + private const int HEADER_SIZE = 0xD; + + private byte[] Raw; + + public byte PathLength { get; set; } + public string Path { get; set; } + public int EmbeddedFilesCount { get; set; } + + public AppHostManifest Manifest { get; set; } + + public AppHostFileHeader(FileStream File) + { + File.Seek(HEADER_OFFSET, SeekOrigin.Begin); + byte[] headerBuffer = new byte[HEADER_SIZE]; + File.Read(headerBuffer, 0, HEADER_SIZE); + Raw = headerBuffer; + PathLength = Raw[0xC]; + + byte[] stringBuffer = new byte[PathLength]; + File.Read(stringBuffer, 0, stringBuffer.Length); + Path = Encoding.UTF8.GetString(stringBuffer); + + Manifest = new AppHostManifest(File, BitConverter.ToInt32(Raw, 0x8)); + } + + + } +} diff --git a/src/apphost-extract/apphost-extract/AppHostManifest.cs b/src/apphost-extract/apphost-extract/AppHostManifest.cs new file mode 100644 index 0000000..9dff1b5 --- /dev/null +++ b/src/apphost-extract/apphost-extract/AppHostManifest.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace apphost_extract +{ + public class AppHostManifest + { + public IReadOnlyList FileEntries { get; set; } + + public AppHostManifest(FileStream File, int embeddedFileCount) + { + + } + } +} diff --git a/src/apphost-extract/apphost-extract/Log.cs b/src/apphost-extract/apphost-extract/Log.cs new file mode 100644 index 0000000..1dc267c --- /dev/null +++ b/src/apphost-extract/apphost-extract/Log.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +public static class Log +{ + public static void Critical(object value) + { + Color(ConsoleColor.Magenta); + Console.WriteLine("[!] " + value.ToString()); + Color(); + } + + public static void Info(object value) + { + Color(ConsoleColor.Cyan); + Console.WriteLine("[+] " + value.ToString()); + } + + public static bool QueryYesNo(string question) + { + var input = QueryString(question); + if (input.ToLower().StartsWith("y")) return true; + else return false; + } + + public static string QueryString(string question) + { + Color(ConsoleColor.Yellow); + Console.Write("[?] " + question); + Color(); + return Console.ReadLine(); + } + + public static void Info(object value, ConsoleColor color) + { + Color(color); + Console.WriteLine("[+] " + value.ToString()); + } + + public static void Error(object value) + { + Color(ConsoleColor.Red); + Console.WriteLine("[-] " + value.ToString()); + Color(); + } + + public static void Fatal(object value) + { + Error(value); + Console.ReadLine(); + Environment.Exit(0); + } + + private static void Color(ConsoleColor color = ConsoleColor.White) + { + Console.ForegroundColor = color; + } +} diff --git a/src/apphost-extract/apphost-extract/Program.cs b/src/apphost-extract/apphost-extract/Program.cs index 34a69a5..6266206 100644 --- a/src/apphost-extract/apphost-extract/Program.cs +++ b/src/apphost-extract/apphost-extract/Program.cs @@ -10,6 +10,9 @@ namespace apphost_extract { static void Main(string[] args) { + string path = "testapp.exe"; + var file = AppHostFile.Open(path); + } } } diff --git a/src/apphost-extract/apphost-extract/apphost-extract.csproj b/src/apphost-extract/apphost-extract/apphost-extract.csproj index 86d3a6d..5b4c330 100644 --- a/src/apphost-extract/apphost-extract/apphost-extract.csproj +++ b/src/apphost-extract/apphost-extract/apphost-extract.csproj @@ -43,6 +43,10 @@ + + + +