Skip to content

Commit

Permalink
* Added enumerator support for ImportLibrary to ImportContent.cs
Browse files Browse the repository at this point in the history
* Fixed up small issue with large addresses.
  • Loading branch information
lkinsella committed Jan 17, 2016
1 parent 7d0c11f commit d60e5b3
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Src/Demo Application/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
40 changes: 39 additions & 1 deletion Src/Workshell.PE/Imports/ImportContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public DataDirectoryType DirectoryType

}

public class ImportContent : SectionContent, ILocationSupport, IRawDataSupport
public class ImportContent : SectionContent, ILocationSupport, IRawDataSupport, IEnumerable<ImportLibrary>
{

private StreamLocation location;
Expand All @@ -61,6 +61,16 @@ internal ImportContent(DataDirectory dataDirectory, Section section) : base(data

#region Methods

public IEnumerator<ImportLibrary> GetEnumerator()
{
return libraries.GetEnumerator();
}

System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
{
return GetEnumerator();
}

public byte[] GetBytes()
{
Stream stream = Section.Sections.Reader.Stream;
Expand Down Expand Up @@ -230,6 +240,8 @@ private void LoadLibraries(Stream stream)
}
}
}

//libraries = libraries.OrderBy(lib => lib.Name).ToList();
}

#endregion
Expand Down Expand Up @@ -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

}
Expand Down
3 changes: 1 addition & 2 deletions Src/Workshell.PE/Imports/ImportLookupTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 3 additions & 3 deletions Src/Workshell.PE/Imports/ImportLookupTableEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,7 +65,7 @@ public StreamLocation Location
}
}

public uint Address
public ulong Address
{
get
{
Expand Down

0 comments on commit d60e5b3

Please sign in to comment.