Skip to content

Commit

Permalink
Tweaks around naming conventions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lloyd Kinsella committed Aug 7, 2018
1 parent 5d8079e commit 28d5961
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 49 deletions.
13 changes: 9 additions & 4 deletions Src/Workshell.PE/Content/CLR/CLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,20 @@ namespace Workshell.PE.Content
{
public sealed class CLR : DataContent
{
internal CLR(PortableExecutableImage image, DataDirectory directory, Location location, CLRHeader header, CLRMetaData metaData) : base(image, directory, location)
private CLR(PortableExecutableImage image, DataDirectory directory, Location location, CLRHeader header, CLRMetaData metaData) : base(image, directory, location)
{
Header = header;
MetaData = metaData;
}

#region Static Methods

internal static async Task<CLR> LoadAsync(PortableExecutableImage image)
public static CLR Get(PortableExecutableImage image)
{
return GetAsync(image).GetAwaiter().GetResult();
}

public static async Task<CLR> GetAsync(PortableExecutableImage image)
{
if (!image.NTHeaders.DataDirectories.Exists(DataDirectoryType.CLRRuntimeHeader))
return null;
Expand All @@ -30,8 +35,8 @@ internal static async Task<CLR> LoadAsync(PortableExecutableImage image)
var fileOffset = calc.RVAToOffset(section, dataDirectory.VirtualAddress);
var imageBase = image.NTHeaders.OptionalHeader.ImageBase;
var location = new Location(fileOffset, dataDirectory.VirtualAddress, imageBase + dataDirectory.VirtualAddress, dataDirectory.Size, dataDirectory.Size, section);
var header = await CLRHeader.LoadAsync(image, location).ConfigureAwait(false);
var metaData = await CLRMetaData.LoadAsync(image, header).ConfigureAwait(false);
var header = await CLRHeader.GetAsync(image, location).ConfigureAwait(false);
var metaData = await CLRMetaData.GetAsync(image, header).ConfigureAwait(false);

return new CLR(image, dataDirectory, location, header, metaData);
}
Expand Down
2 changes: 1 addition & 1 deletion Src/Workshell.PE/Content/CLR/CLRHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal CLRHeader(Location location, IMAGE_COR20_HEADER header)

#region Static Methods

internal static async Task<CLRHeader> LoadAsync(PortableExecutableImage image, Location clrLocation)
internal static async Task<CLRHeader> GetAsync(PortableExecutableImage image, Location clrLocation)
{
var size = Marshal.SizeOf<IMAGE_COR20_HEADER>();
var location = new Location(clrLocation.FileOffset, clrLocation.RelativeVirtualAddress, clrLocation.VirtualAddress, size.ToUInt32(), size.ToUInt32(), clrLocation.Section);
Expand Down
2 changes: 1 addition & 1 deletion Src/Workshell.PE/Content/CLR/CLRMetaData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal CLRMetaData(PortableExecutableImage image, Location location, CLRMetaDa

#region Static Methods

internal static async Task<CLRMetaData> LoadAsync(PortableExecutableImage image, CLRHeader header)
internal static async Task<CLRMetaData> GetAsync(PortableExecutableImage image, CLRHeader header)
{
var calc = image.GetCalculator();
var imageBase = image.NTHeaders.OptionalHeader.ImageBase;
Expand Down
18 changes: 10 additions & 8 deletions Src/Workshell.PE/DataDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,23 @@ public async Task<DataContent> GetContentAsync()
case DataDirectoryType.LoadConfigTable:
return await LoadConfigurationDirectory.GetAsync(_image).ConfigureAwait(false);
case DataDirectoryType.TLSTable:
return await TLSDirectory.LoadAsync(_image).ConfigureAwait(false);
return await TLSDirectory.GetAsync(_image).ConfigureAwait(false);
case DataDirectoryType.CertificateTable:
return await Certificate.LoadAsync(_image).ConfigureAwait(false);
return await Certificate.GetAsync(_image).ConfigureAwait(false);
case DataDirectoryType.CLRRuntimeHeader:
return await CLR.LoadAsync(_image).ConfigureAwait(false);
return await CLR.GetAsync(_image).ConfigureAwait(false);
case DataDirectoryType.Debug:
return await DebugDirectory.LoadAsync(_image).ConfigureAwait(false);
return await DebugDirectory.GetAsync(_image).ConfigureAwait(false);
case DataDirectoryType.BaseRelocationTable:
return await RelocationTable.LoadAsync(_image).ConfigureAwait(false);
return await RelocationTable.GetAsync(_image).ConfigureAwait(false);
case DataDirectoryType.ExportTable:
return await ExportDirectory.LoadAsync(_image).ConfigureAwait(false);
return await ExportDirectory.GetAsync(_image).ConfigureAwait(false);
case DataDirectoryType.ImportTable:
return await ImportDirectory.LoadAsync(_image).ConfigureAwait(false);
return await ImportDirectory.GetAsync(_image).ConfigureAwait(false);
case DataDirectoryType.DelayImportDescriptor:
return await DelayedImportDirectory.LoadAsync(_image).ConfigureAwait(false);
return await DelayedImportDirectory.GetAsync(_image).ConfigureAwait(false);
case DataDirectoryType.ExceptionTable:
return await ExceptionTable.GetAsync(_image).ConfigureAwait(false);
default:
{
var calc = _image.GetCalculator();
Expand Down
9 changes: 7 additions & 2 deletions src/Workshell.PE/Content/Certificate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public enum CertificateType : ushort

public sealed class Certificate : DataContent
{
internal Certificate(PortableExecutableImage image, DataDirectory directory, Location location, WIN_CERTIFICATE cert) : base(image, directory, location)
private Certificate(PortableExecutableImage image, DataDirectory directory, Location location, WIN_CERTIFICATE cert) : base(image, directory, location)
{
Length = cert.dwLength;
Revision = cert.wRevision;
Expand All @@ -29,7 +29,12 @@ internal Certificate(PortableExecutableImage image, DataDirectory directory, Loc

#region Static Methods

public static async Task<Certificate> LoadAsync(PortableExecutableImage image)
public static Certificate Get(PortableExecutableImage image)
{
return GetAsync(image).GetAwaiter().GetResult();
}

public static async Task<Certificate> GetAsync(PortableExecutableImage image)
{
if (!image.NTHeaders.DataDirectories.Exists(DataDirectoryType.CertificateTable))
return null;
Expand Down
9 changes: 7 additions & 2 deletions src/Workshell.PE/Content/Debug/DebugDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public sealed class DebugDirectory : DataContent, IEnumerable<DebugDirectoryEntr
{
private readonly DebugDirectoryEntry[] _entries;

internal DebugDirectory(PortableExecutableImage image, DataDirectory directory, Location location, DebugDirectoryEntry[] entries) : base(image, directory, location)
private DebugDirectory(PortableExecutableImage image, DataDirectory directory, Location location, DebugDirectoryEntry[] entries) : base(image, directory, location)
{
_entries = entries;

Expand All @@ -24,7 +24,12 @@ internal DebugDirectory(PortableExecutableImage image, DataDirectory directory,

#region Static Methods

internal static async Task<DebugDirectory> LoadAsync(PortableExecutableImage image)
public DebugDirectory Get(PortableExecutableImage image)
{
return GetAsync(image).GetAwaiter().GetResult();
}

public static async Task<DebugDirectory> GetAsync(PortableExecutableImage image)
{
if (!image.NTHeaders.DataDirectories.Exists(DataDirectoryType.Debug))
return null;
Expand Down
25 changes: 15 additions & 10 deletions src/Workshell.PE/Content/Exports/ExportDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public sealed class ExportDirectory : DataContent
private readonly uint[] _functionNameAddresses;
private readonly ushort[] _functionOrdinals;

internal ExportDirectory(PortableExecutableImage image, DataDirectory dataDirectory, Location location, IMAGE_EXPORT_DIRECTORY directory,
private ExportDirectory(PortableExecutableImage image, DataDirectory dataDirectory, Location location, IMAGE_EXPORT_DIRECTORY directory,
string name, uint[] functionAddresses, uint[] functionNameAddresses, ushort[] functionOrdinals) : base(image, dataDirectory, location)
{
_name = name;
Expand All @@ -40,7 +40,12 @@ internal ExportDirectory(PortableExecutableImage image, DataDirectory dataDirect

#region Static Methods

internal static async Task<ExportDirectory> LoadAsync(PortableExecutableImage image)
public static ExportDirectory Get(PortableExecutableImage image)
{
return GetAsync(image).GetAwaiter().GetResult();
}

public static async Task<ExportDirectory> GetAsync(PortableExecutableImage image)
{
if (!image.NTHeaders.DataDirectories.Exists(DataDirectoryType.ExportTable))
return null;
Expand All @@ -65,10 +70,10 @@ internal static async Task<ExportDirectory> LoadAsync(PortableExecutableImage im
stream.Seek(offset.ToInt64(), SeekOrigin.Begin);

var exportDirectory = await stream.ReadStructAsync<IMAGE_EXPORT_DIRECTORY>(size).ConfigureAwait(false);
var name = await LoadNameAsync(calc, stream, exportDirectory).ConfigureAwait(false);
var functionAddresses = await LoadFunctionAddressesAsync(calc, stream, exportDirectory).ConfigureAwait(false);
var functionNameAddresses = await LoadFunctionNameAddressesAsync(calc, stream, exportDirectory).ConfigureAwait(false);
var functionOrdinals = await LoadFunctionOrdinalsAsync(calc, stream, exportDirectory).ConfigureAwait(false);
var name = await BuildNameAsync(calc, stream, exportDirectory).ConfigureAwait(false);
var functionAddresses = await BuildFunctionAddressesAsync(calc, stream, exportDirectory).ConfigureAwait(false);
var functionNameAddresses = await BuildFunctionNameAddressesAsync(calc, stream, exportDirectory).ConfigureAwait(false);
var functionOrdinals = await BuildFunctionOrdinalsAsync(calc, stream, exportDirectory).ConfigureAwait(false);

return new ExportDirectory(image, dataDirectory, location, exportDirectory, name, functionAddresses, functionNameAddresses, functionOrdinals);
}
Expand All @@ -78,7 +83,7 @@ internal static async Task<ExportDirectory> LoadAsync(PortableExecutableImage im
}
}

private static async Task<string> LoadNameAsync(LocationCalculator calc, Stream stream, IMAGE_EXPORT_DIRECTORY directory)
private static async Task<string> BuildNameAsync(LocationCalculator calc, Stream stream, IMAGE_EXPORT_DIRECTORY directory)
{
var builder = new StringBuilder(256);
var offset = calc.RVAToOffset(directory.Name).ToInt64();
Expand All @@ -100,7 +105,7 @@ private static async Task<string> LoadNameAsync(LocationCalculator calc, Stream
return builder.ToString();
}

private static async Task<uint[]> LoadFunctionAddressesAsync(LocationCalculator calc, Stream stream, IMAGE_EXPORT_DIRECTORY directory)
private static async Task<uint[]> BuildFunctionAddressesAsync(LocationCalculator calc, Stream stream, IMAGE_EXPORT_DIRECTORY directory)
{
var offset = calc.RVAToOffset(directory.AddressOfFunctions).ToInt64();

Expand All @@ -114,7 +119,7 @@ private static async Task<uint[]> LoadFunctionAddressesAsync(LocationCalculator
return results;
}

private static async Task<uint[]> LoadFunctionNameAddressesAsync(LocationCalculator calc, Stream stream, IMAGE_EXPORT_DIRECTORY directory)
private static async Task<uint[]> BuildFunctionNameAddressesAsync(LocationCalculator calc, Stream stream, IMAGE_EXPORT_DIRECTORY directory)
{
var offset = calc.RVAToOffset(directory.AddressOfNames).ToInt64();

Expand All @@ -128,7 +133,7 @@ private static async Task<uint[]> LoadFunctionNameAddressesAsync(LocationCalcula
return results;
}

private static async Task<ushort[]> LoadFunctionOrdinalsAsync(LocationCalculator calc, Stream stream, IMAGE_EXPORT_DIRECTORY directory)
private static async Task<ushort[]> BuildFunctionOrdinalsAsync(LocationCalculator calc, Stream stream, IMAGE_EXPORT_DIRECTORY directory)
{
var offset = calc.RVAToOffset(directory.AddressOfNameOrdinals).ToInt64();

Expand Down
6 changes: 3 additions & 3 deletions src/Workshell.PE/Content/Exports/ExportTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected ExportTable(PortableExecutableImage image, DataDirectory directory, Lo
public static async Task<ExportTable<uint>> GetFunctionAddressTableAsync(PortableExecutableImage image, ExportDirectory directory = null)
{
if (directory == null)
directory = await ExportDirectory.LoadAsync(image).ConfigureAwait(false);
directory = await ExportDirectory.GetAsync(image).ConfigureAwait(false);

var calc = image.GetCalculator();
var section = calc.RVAToSection(directory.AddressOfFunctions);
Expand Down Expand Up @@ -53,7 +53,7 @@ public static async Task<ExportTable<uint>> GetFunctionAddressTableAsync(Portabl
public static async Task<ExportTable<uint>> GetNameAddressTableAsync(PortableExecutableImage image, ExportDirectory directory = null)
{
if (directory == null)
directory = await ExportDirectory.LoadAsync(image).ConfigureAwait(false);
directory = await ExportDirectory.GetAsync(image).ConfigureAwait(false);

var calc = image.GetCalculator();
var section = calc.RVAToSection(directory.AddressOfNames);
Expand Down Expand Up @@ -87,7 +87,7 @@ public static async Task<ExportTable<uint>> GetNameAddressTableAsync(PortableExe
public static async Task<ExportTable<ushort>> GetOrdinalTableAsync(PortableExecutableImage image, ExportDirectory directory = null)
{
if (directory == null)
directory = await ExportDirectory.LoadAsync(image).ConfigureAwait(false);
directory = await ExportDirectory.GetAsync(image).ConfigureAwait(false);

var calc = image.GetCalculator();
var section = calc.RVAToSection(directory.AddressOfNameOrdinals);
Expand Down
2 changes: 1 addition & 1 deletion src/Workshell.PE/Content/Exports/Exports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ internal Exports(Export[] exports)

public static async Task<Exports> GetAsync(PortableExecutableImage image)
{
var directory = await ExportDirectory.LoadAsync(image).ConfigureAwait(false);
var directory = await ExportDirectory.GetAsync(image).ConfigureAwait(false);

if (directory == null)
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static async Task<DelayedImportAddressTables> GetAddressTableAsync(Portab
private static async Task<DelayedImportAddressTables> GetTableAsync(PortableExecutableImage image, DelayedImportDirectory directory, Func<DelayedImportDirectoryEntry, uint> thunkHandler)
{
if (directory == null)
directory = await DelayedImportDirectory.LoadAsync(image).ConfigureAwait(false);
directory = await DelayedImportDirectory.GetAsync(image).ConfigureAwait(false);

var calc = image.GetCalculator();
var stream = image.GetStream();
Expand Down
9 changes: 7 additions & 2 deletions src/Workshell.PE/Content/Imports/DelayedImportDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ namespace Workshell.PE.Content
{
public sealed class DelayedImportDirectory : ImportDirectoryBase<DelayedImportDirectoryEntry>
{
internal DelayedImportDirectory(PortableExecutableImage image, DataDirectory directory, Location location, DelayedImportDirectoryEntry[] entries) : base(image, directory, location, entries)
private DelayedImportDirectory(PortableExecutableImage image, DataDirectory directory, Location location, DelayedImportDirectoryEntry[] entries) : base(image, directory, location, entries)
{
}

#region Static Methods

internal static async Task<DelayedImportDirectory> LoadAsync(PortableExecutableImage image)
public static DelayedImportDirectory Get(PortableExecutableImage image)
{
return GetAsync(image).GetAwaiter().GetResult();
}

public static async Task<DelayedImportDirectory> GetAsync(PortableExecutableImage image)
{
if (!image.NTHeaders.DataDirectories.Exists(DataDirectoryType.DelayImportDescriptor))
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal DelayedImportHintNameTable(PortableExecutableImage image, DataDirectory
public static async Task<DelayedImportHintNameTable> GetAsync(PortableExecutableImage image, DelayedImportDirectory directory = null)
{
if (directory == null)
directory = await DelayedImportDirectory.LoadAsync(image).ConfigureAwait(false);
directory = await DelayedImportDirectory.GetAsync(image).ConfigureAwait(false);

var entries = new Dictionary<uint, Tuple<ulong, uint, ushort, string, bool>>();
var ilt = await DelayedImportAddressTables.GetLookupTableAsync(image, directory).ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion src/Workshell.PE/Content/Imports/DelayedImports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal DelayedImports(DelayedImportLibrary[] libraries) : base(libraries)

public static async Task<DelayedImports> GetAsync(PortableExecutableImage image)
{
var directory = await DelayedImportDirectory.LoadAsync(image).ConfigureAwait(false);
var directory = await DelayedImportDirectory.GetAsync(image).ConfigureAwait(false);

if (directory == null)
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Workshell.PE/Content/Imports/ImportAddressTables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static async Task<ImportAddressTables> GetAddressTableAsync(PortableExecu
private static async Task<ImportAddressTables> GetTableAsync(PortableExecutableImage image, ImportDirectory directory, Func<ImportDirectoryEntry, uint> thunkHandler)
{
if (directory == null)
directory = await ImportDirectory.LoadAsync(image).ConfigureAwait(false);
directory = await ImportDirectory.GetAsync(image).ConfigureAwait(false);

var calc = image.GetCalculator();
var stream = image.GetStream();
Expand Down
9 changes: 7 additions & 2 deletions src/Workshell.PE/Content/Imports/ImportDirectory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ namespace Workshell.PE.Content
{
public sealed class ImportDirectory : ImportDirectoryBase<ImportDirectoryEntry>
{
internal ImportDirectory(PortableExecutableImage image, DataDirectory directory, Location location, ImportDirectoryEntry[] entries) : base(image, directory, location, entries)
private ImportDirectory(PortableExecutableImage image, DataDirectory directory, Location location, ImportDirectoryEntry[] entries) : base(image, directory, location, entries)
{
}

#region Static Methods

internal static async Task<ImportDirectory> LoadAsync(PortableExecutableImage image)
public static ImportDirectory Get(PortableExecutableImage image)
{
return GetAsync(image).GetAwaiter().GetResult();
}

public static async Task<ImportDirectory> GetAsync(PortableExecutableImage image)
{
if (!image.NTHeaders.DataDirectories.Exists(DataDirectoryType.ImportTable))
return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Workshell.PE/Content/Imports/ImportHintNameTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal ImportHintNameTable(PortableExecutableImage image, DataDirectory direct
public static async Task<ImportHintNameTable> GetAsync(PortableExecutableImage image, ImportDirectory directory = null)
{
if (directory == null)
directory = await ImportDirectory.LoadAsync(image).ConfigureAwait(false);
directory = await ImportDirectory.GetAsync(image).ConfigureAwait(false);

var entries = new Dictionary<uint, Tuple<ulong, uint, ushort, string, bool>>();
var ilt = await ImportAddressTables.GetLookupTableAsync(image, directory).ConfigureAwait(false);
Expand Down
2 changes: 1 addition & 1 deletion src/Workshell.PE/Content/Imports/Imports.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal Imports(ImportLibrary[] libraries) : base(libraries)

public static async Task<Imports> GetAsync(PortableExecutableImage image)
{
var directory = await ImportDirectory.LoadAsync(image).ConfigureAwait(false);
var directory = await ImportDirectory.GetAsync(image).ConfigureAwait(false);

if (directory == null)
return null;
Expand Down
Loading

0 comments on commit 28d5961

Please sign in to comment.