From d190b003c4197c321c88cdc4fa19fdd08a15f273 Mon Sep 17 00:00:00 2001 From: Lloyd Kinsella Date: Fri, 1 Jul 2016 20:44:55 +0100 Subject: [PATCH] Added calls on Imports and Exports making it easier to get an instance from just an ExecutabeImage. --- .../Content/Delayed Imports/DelayImports.cs | 21 ++++++++++++++++ Src/Workshell.PE/Content/Exports/Exports.cs | 25 +++++++++++++++++++ Src/Workshell.PE/Content/Imports/Imports.cs | 20 +++++++++++++++ 3 files changed, 66 insertions(+) diff --git a/Src/Workshell.PE/Content/Delayed Imports/DelayImports.cs b/Src/Workshell.PE/Content/Delayed Imports/DelayImports.cs index a61d5d4..d28d53d 100644 --- a/Src/Workshell.PE/Content/Delayed Imports/DelayImports.cs +++ b/Src/Workshell.PE/Content/Delayed Imports/DelayImports.cs @@ -22,6 +22,27 @@ internal DelayImports(Tuple> libraries = new List>(); diff --git a/Src/Workshell.PE/Content/Exports/Exports.cs b/Src/Workshell.PE/Content/Exports/Exports.cs index ee16159..dce3ef0 100644 --- a/Src/Workshell.PE/Content/Exports/Exports.cs +++ b/Src/Workshell.PE/Content/Exports/Exports.cs @@ -80,6 +80,31 @@ internal Exports(Export[] exports) #region Static Methods + public static Exports Get(ExecutableImage image) + { + ExportDirectory directory = ExportDirectory.Get(image); + + if (directory == null) + return null; + + ExportTable function_addresses = ExportTable.GetFunctionAddressTable(directory); + + if (function_addresses == null) + return null; + + ExportTable name_addresses = ExportTable.GetNameAddressTable(directory); + + if (name_addresses == null) + return null; + + ExportTable ordinals = ExportTable.GetOrdinalTable(directory); + + if (ordinals == null) + return null; + + return Get(directory, function_addresses, name_addresses, ordinals); + } + public static Exports Get(ExportDirectory directory, ExportTable functionAddresses, ExportTable nameAddresses, ExportTable ordinals) { LocationCalculator calc = directory.DataDirectory.Directories.Image.GetCalculator(); diff --git a/Src/Workshell.PE/Content/Imports/Imports.cs b/Src/Workshell.PE/Content/Imports/Imports.cs index 8ab9d6e..4c6ac25 100644 --- a/Src/Workshell.PE/Content/Imports/Imports.cs +++ b/Src/Workshell.PE/Content/Imports/Imports.cs @@ -22,6 +22,26 @@ internal Imports(Tuple[] importLi #region Static Methods + public static Imports Get(ExecutableImage image) + { + ImportDirectory directory = ImportDirectory.Get(image); + + if (directory == null) + return null; + + ImportAddressTables ilt = ImportAddressTables.GetLookupTable(directory); + + if (ilt == null) + return null; + + ImportHintNameTable hnt = ImportHintNameTable.Get(directory); + + if (hnt == null) + return null; + + return Get(ilt, hnt); + } + public static Imports Get(ImportAddressTables ilt, ImportHintNameTable hnTable) { List> libraries = new List>();