Skip to content

Commit

Permalink
Added basic CLR support.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkinsella committed Feb 13, 2016
1 parent 10a229e commit acdac68
Show file tree
Hide file tree
Showing 11 changed files with 1,127 additions and 3 deletions.
6 changes: 3 additions & 3 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\Release\netdepends.exe";
//string file_name = @"C:\Users\Lloyd\Desktop\PE Related\Tools\PeInternals\x64\PeInternals.exe";
string error_message;

Expand All @@ -43,7 +43,7 @@ static void Main(string[] args)
if (content == null)
continue;

if (content.DataDirectory.DirectoryType == DataDirectoryType.BaseRelocationTable)
if (content.DataDirectory.DirectoryType == DataDirectoryType.CLRRuntimeHeader)
{

}
Expand Down
73 changes: 73 additions & 0 deletions Src/Workshell.PE/Content/CLR/CLRContent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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 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

}

}
71 changes: 71 additions & 0 deletions Src/Workshell.PE/Content/CLR/CLRDataDirectory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Workshell.PE.Native;

namespace Workshell.PE
{

public sealed class CLRDataDirectory
{

private IMAGE_DATA_DIRECTORY data_dir;

internal CLRDataDirectory(IMAGE_DATA_DIRECTORY dataDirectory)
{
data_dir = dataDirectory;
}

#region Static Methods

public static bool IsNullOrEmpty(DataDirectory dataDirectory)
{
if (dataDirectory == null)
return true;

if (dataDirectory.VirtualAddress == 0)
return true;

if (dataDirectory.Size == 0)
return true;

return false;
}

#endregion

#region Methods

public override string ToString()
{
return String.Format("0x{0:X8}+{1}",data_dir.VirtualAddress,data_dir.Size);
}

#endregion

#region Properties

public uint VirtualAddress
{
get
{
return data_dir.VirtualAddress;
}
}

public uint Size
{
get
{
return data_dir.Size;
}
}

#endregion

}

}
Loading

0 comments on commit acdac68

Please sign in to comment.