Skip to content

Commit

Permalink
Work on the CLR content.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkinsella committed Jun 19, 2016
1 parent 94aa482 commit b49715e
Show file tree
Hide file tree
Showing 9 changed files with 342 additions and 219 deletions.
10 changes: 8 additions & 2 deletions Src/Demo Application/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ static void Main(string[] args)
//string file_name = Environment.GetCommandLineArgs()[0];
//string file_name = Assembly.GetEntryAssembly().Location;
//string file_name = @"C:\Windows\SysWOW64\kernel32.dll";
string file_name = @"C:\Windows\System32\kernel32.dll";
//string file_name = @"C:\Windows\System32\kernel32.dll";
//string file_name = @"C:\Windows\SysWOW64\shell32.dll";
//string file_name = @"C:\Windows\System32\shell32.dll";
//string file_name = @"C:\Windows\SysWOW64\xpsservices.dll";
//string file_name = @"c:\windows\system32\advapi32.dll";
//string file_name = @"P:\Workshell\dotNET Dependency Walker\Bin\Release\netdepends.exe";
string file_name = @"P:\Workshell\dotNET Dependency Walker\Bin\Debug\netdepends.exe";
//string file_name = @"C:\Users\Lloyd\Desktop\PE Related\Tools\PeInternals\x64\PeInternals.exe";
//string file_name = @"D:\Lloyd\Downloads\Win32DiskImager-0.9.5-install.exe";
string error_message;
Expand All @@ -37,6 +37,7 @@ static void Main(string[] args)

ExecutableImage image = ExecutableImage.FromFile(file_name);

/*
LoadConfigDirectory load_config = LoadConfigDirectory.Get(image);
Certificate cert = Certificate.Get(image);
DebugDirectory debug_dir = DebugDirectory.Get(image);
Expand All @@ -55,6 +56,11 @@ static void Main(string[] args)
Imports imports = Imports.Get(ilt,hint_name_table);
Resources resources = Resources.Get(image);
*/

CLR clr = CLR.Get(image);
CLRHeader header = CLRHeader.Get(clr);
CLRMetaData meta_data = CLRMetaData.Get(header);

Console.ReadKey();
}
Expand Down
131 changes: 131 additions & 0 deletions Src/Workshell.PE/Content/CLR/CLR.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Workshell.PE.Native;

namespace Workshell.PE
{

public sealed class CLR : ExecutableImageContent
{

internal CLR(DataDirectory dataDirectory, Location dataLocation) : base(dataDirectory,dataLocation)
{
}

#region Static Methods

public static CLR Get(ExecutableImage image)
{
if (!image.NTHeaders.DataDirectories.Exists(DataDirectoryType.CLRRuntimeHeader))
return null;

DataDirectory directory = image.NTHeaders.DataDirectories[DataDirectoryType.CLRRuntimeHeader];

if (DataDirectory.IsNullOrEmpty(directory))
return null;

LocationCalculator calc = directory.Directories.Image.GetCalculator();
Section section = calc.RVAToSection(directory.VirtualAddress);
ulong file_offset = calc.RVAToOffset(section, directory.VirtualAddress);
ulong image_base = directory.Directories.Image.NTHeaders.OptionalHeader.ImageBase;
Location location = new Location(file_offset, directory.VirtualAddress, image_base + directory.VirtualAddress, directory.Size, directory.Size, section);
CLR result = new CLR(directory, location);

return result;
}

/*
public static CLRMetaData GetMetaData(CLRHeader header)
{
LocationCalculator calc = header.CLR.DataDirectory.Directories.Image.GetCalculator();
ulong image_base = header.CLR.DataDirectory.Directories.Image.NTHeaders.OptionalHeader.ImageBase;
uint rva = header.MetaDataAddress;
ulong va = image_base + rva;
ulong offset = calc.RVAToOffset(rva);
uint size = header.MetaDataSize;
Section section = calc.RVAToSection(rva);
Location location = new Location(offset, rva, va, size, size, section);
//CLRMetaDataHeader meta_data_header = new CLRMetaDataHeader(this, header);
//CLRMetaDataStreamTable stream_table = new CLRMetaDataStreamTable(this, imageBase);
//CLRMetaDataStreamCollection streams = new CLRMetaDataStreamCollection(this, imageBase);
CLRMetaData meta_data = new CLRMetaData(header.CLR, location, header);
return meta_data;
}
*/

#endregion

}

/*
public sealed class CLRContent : DataDirectoryContent
{
private CLRHeader header;
private CLRMetaData meta_data;
internal CLRContent(DataDirectory dataDirectory, ulong imageBase) : base(dataDirectory, imageBase)
{
LocationCalculator calc = DataDirectory.Directories.Reader.GetCalculator();
Stream stream = DataDirectory.Directories.Reader.GetStream();
LoadHeader(calc, stream, imageBase);
LoadMetaData(calc, stream, imageBase);
}
#region Methods
private void LoadHeader(LocationCalculator calc, Stream stream, ulong imageBase)
{
ulong offset = calc.RVAToOffset(DataDirectory.VirtualAddress);
uint size = Convert.ToUInt32(Utils.SizeOf<IMAGE_COR20_HEADER>());
Location location = new Location(offset,DataDirectory.VirtualAddress,imageBase + DataDirectory.VirtualAddress,size,size);
Section section = calc.RVAToSection(DataDirectory.VirtualAddress);
stream.Seek(Convert.ToInt64(offset),SeekOrigin.Begin);
IMAGE_COR20_HEADER clr_header = Utils.Read<IMAGE_COR20_HEADER>(stream,Convert.ToInt32(size));
header = new CLRHeader(this,clr_header,location,section);
}
private void LoadMetaData(LocationCalculator calc, Stream stream, ulong imageBase)
{
meta_data = new CLRMetaData(this,imageBase);
}
#endregion
#region Properties
public CLRHeader Header
{
get
{
return header;
}
}
public CLRMetaData MetaData
{
get
{
return meta_data;
}
}
#endregion
}
*/

}
77 changes: 0 additions & 77 deletions Src/Workshell.PE/Content/CLR/CLRContent.cs

This file was deleted.

Loading

0 comments on commit b49715e

Please sign in to comment.