From d60e5b3d5e151c3809221bd1e9af56ec600f31c6 Mon Sep 17 00:00:00 2001 From: Lloyd Kinsella Date: Sun, 17 Jan 2016 23:35:18 +0000 Subject: [PATCH] * Added enumerator support for ImportLibrary to ImportContent.cs * Fixed up small issue with large addresses. --- Src/Demo Application/Program.cs | 3 +- Src/Workshell.PE/Imports/ImportContent.cs | 40 ++++++++++++++++++- Src/Workshell.PE/Imports/ImportLookupTable.cs | 3 +- .../Imports/ImportLookupTableEntry.cs | 6 +-- 4 files changed, 45 insertions(+), 7 deletions(-) diff --git a/Src/Demo Application/Program.cs b/Src/Demo Application/Program.cs index 0a3cd0f..1519e6d 100644 --- a/Src/Demo Application/Program.cs +++ b/Src/Demo Application/Program.cs @@ -16,8 +16,9 @@ static void Main(string[] args) { //string file_name = Environment.GetCommandLineArgs()[0]; //string file_name = @"C:\Windows\SysWOW64\kernel32.dll"; - string file_name = @"C:\Windows\SysWOW64\shell32.dll"; + //string file_name = @"C:\Windows\SysWOW64\shell32.dll"; //string file_name = @"C:\Windows\SysWOW64\xpsservices.dll"; + string file_name = @"c:\windows\system32\advapi32.dll"; ExeReader reader = ExeReader.FromFile(file_name); Section[] sections = reader.Sections.ToArray(); diff --git a/Src/Workshell.PE/Imports/ImportContent.cs b/Src/Workshell.PE/Imports/ImportContent.cs index 1f72004..53039b5 100644 --- a/Src/Workshell.PE/Imports/ImportContent.cs +++ b/Src/Workshell.PE/Imports/ImportContent.cs @@ -36,7 +36,7 @@ public DataDirectoryType DirectoryType } - public class ImportContent : SectionContent, ILocationSupport, IRawDataSupport + public class ImportContent : SectionContent, ILocationSupport, IRawDataSupport, IEnumerable { private StreamLocation location; @@ -61,6 +61,16 @@ internal ImportContent(DataDirectory dataDirectory, Section section) : base(data #region Methods + public IEnumerator GetEnumerator() + { + return libraries.GetEnumerator(); + } + + System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + public byte[] GetBytes() { Stream stream = Section.Sections.Reader.Stream; @@ -230,6 +240,8 @@ private void LoadLibraries(Stream stream) } } } + + //libraries = libraries.OrderBy(lib => lib.Name).ToList(); } #endregion @@ -268,6 +280,32 @@ public ImportHintNameTable HintNameTable } } + public int Count + { + get + { + return libraries.Count; + } + } + + public ImportLibrary this[int index] + { + get + { + return libraries[index]; + } + } + + public ImportLibrary this[string libraryName] + { + get + { + ImportLibrary library = libraries.FirstOrDefault(lib => String.Compare(libraryName,lib.Name,StringComparison.OrdinalIgnoreCase) == 0); + + return library; + } + } + #endregion } diff --git a/Src/Workshell.PE/Imports/ImportLookupTable.cs b/Src/Workshell.PE/Imports/ImportLookupTable.cs index df37f32..d7e8ba4 100644 --- a/Src/Workshell.PE/Imports/ImportLookupTable.cs +++ b/Src/Workshell.PE/Imports/ImportLookupTable.cs @@ -53,9 +53,8 @@ internal ImportLookupTable(ImportLookupTables lookupTables, ImportDirectoryEntry } } - uint address = Convert.ToUInt32(table_entry); StreamLocation entry_location = new StreamLocation(offset,size); - ImportLookupTableEntry entry = new ImportLookupTableEntry(this,entry_location,address,ordinal); + ImportLookupTableEntry entry = new ImportLookupTableEntry(this,entry_location,table_entry,ordinal); entries.Add(entry); diff --git a/Src/Workshell.PE/Imports/ImportLookupTableEntry.cs b/Src/Workshell.PE/Imports/ImportLookupTableEntry.cs index bd5c870..e9ae6f2 100644 --- a/Src/Workshell.PE/Imports/ImportLookupTableEntry.cs +++ b/Src/Workshell.PE/Imports/ImportLookupTableEntry.cs @@ -13,10 +13,10 @@ public class ImportLookupTableEntry : ILocationSupport, IRawDataSupport private ImportLookupTable table; private StreamLocation location; - private uint address; + private ulong address; private int ordinal; - internal ImportLookupTableEntry(ImportLookupTable lookupTable, StreamLocation streamLoc, uint entryAddress, int entryOrdinal) + internal ImportLookupTableEntry(ImportLookupTable lookupTable, StreamLocation streamLoc, ulong entryAddress, int entryOrdinal) { table = lookupTable; location = streamLoc; @@ -65,7 +65,7 @@ public StreamLocation Location } } - public uint Address + public ulong Address { get {