Skip to content

Commit

Permalink
Various changes around integer types.
Browse files Browse the repository at this point in the history
  • Loading branch information
lkinsella committed Oct 11, 2019
1 parent 74b7095 commit 63e4fb4
Show file tree
Hide file tree
Showing 49 changed files with 1,194 additions and 1,127 deletions.
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 @@ -103,7 +103,7 @@ internal static async Task<CLRHeader> GetAsync(PortableExecutableImage image, Lo
var location = new Location(image, clrLocation.FileOffset, clrLocation.RelativeVirtualAddress, clrLocation.VirtualAddress, size.ToUInt32(), size.ToUInt32(), clrLocation.Section);
var stream = image.GetStream();

stream.Seek(clrLocation.FileOffset.ToInt64(), SeekOrigin.Begin);
stream.Seek(clrLocation.FileOffset, SeekOrigin.Begin);

IMAGE_COR20_HEADER header;

Expand Down
4 changes: 3 additions & 1 deletion Src/Workshell.PE/Content/CLR/CLRMetaDataHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,14 @@ public static async Task<CLRMetaDataHeader> LoadAsync(PortableExecutableImage im
var offset = mdLocation.FileOffset;
var section = mdLocation.Section;

stream.Seek(offset.ToInt64(), SeekOrigin.Begin);
stream.Seek(offset, SeekOrigin.Begin);

var signature = await stream.ReadUInt32Async().ConfigureAwait(false);

if (signature != CLR_METADATA_SIGNATURE)
{
throw new PortableExecutableImageException(image, "Incorrect signature found in CLR meta-data header.");
}

var majorVersion = await stream.ReadUInt16Async().ConfigureAwait(false);
var minorVersion = await stream.ReadUInt16Async().ConfigureAwait(false);
Expand Down
8 changes: 5 additions & 3 deletions Src/Workshell.PE/Content/CLR/CLRMetaDataStreamTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static async Task<CLRMetaDataStreamTable> LoadAsync(PortableExecutableIma
var rva = calc.OffsetToRVA(offset);
var va = imageBase + rva;
var entries = await LoadTableAsync(image, header, offset, imageBase).ConfigureAwait(false);
ulong size = 0;
var size = 0L;

foreach (var strm in entries)
{
Expand All @@ -75,11 +75,11 @@ public static async Task<CLRMetaDataStreamTable> LoadAsync(PortableExecutableIma
}
}

private static async Task<CLRMetaDataStreamTableEntry[]> LoadTableAsync(PortableExecutableImage image, CLRMetaDataHeader header, ulong baseOffset, ulong imageBase)
private static async Task<CLRMetaDataStreamTableEntry[]> LoadTableAsync(PortableExecutableImage image, CLRMetaDataHeader header, long baseOffset, ulong imageBase)
{
var stream = image.GetStream();

stream.Seek(baseOffset.ToInt64(),SeekOrigin.Begin);
stream.Seek(baseOffset,SeekOrigin.Begin);

var entries = new List<CLRMetaDataStreamTableEntry>();
var offset = baseOffset;
Expand All @@ -104,7 +104,9 @@ private static async Task<CLRMetaDataStreamTableEntry[]> LoadTableAsync(Portable
size += 1;

if (b <= 0)
{
break;
}

streamName.Append((char)b);
}
Expand Down
24 changes: 23 additions & 1 deletion Src/Workshell.PE/Content/LoadConfigurationCodeIntegrity.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
using System;
#region License
// Copyright(c) Workshell Ltd
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#endregion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
6 changes: 3 additions & 3 deletions Src/Workshell.PE/DOSHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ internal DOSHeader(PortableExecutableImage image, IMAGE_DOS_HEADER dosHeader, ul
_image = image;
_header = dosHeader;

Location = new Location(image, 0, 0, imageBase, Size.ToUInt32(), Size.ToUInt32());
Location = new Location(image, 0, 0, imageBase, Size, Size);
}

#region Methods
Expand All @@ -71,7 +71,7 @@ public async Task<byte[]> GetBytesAsync()

#region Static Properties

public static int Size { get; } = Utils.SizeOf<IMAGE_DOS_HEADER>();
public static uint Size { get; } = Utils.SizeOf<IMAGE_DOS_HEADER>().ToUInt32();

#endregion

Expand Down Expand Up @@ -134,7 +134,7 @@ public async Task<byte[]> GetBytesAsync()
public ushort[] Reserved2 => _header.e_res_2;

[FieldAnnotation("File address of new header", Order = 19)]
public int FileAddressNewHeader => _header.e_lfanew;
public uint FileAddressNewHeader => _header.e_lfanew;

#endregion
}
Expand Down
4 changes: 2 additions & 2 deletions Src/Workshell.PE/DOSStub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ public sealed class DOSStub : ISupportsLocation, ISupportsBytes
{
private readonly PortableExecutableImage _image;

internal DOSStub(PortableExecutableImage image, ulong stubOffset, uint stubSize, ulong imageBase)
internal DOSStub(PortableExecutableImage image, uint stubOffset, uint stubSize, ulong imageBase)
{
_image = image;

Location = new Location(image, stubOffset, Convert.ToUInt32(stubOffset), imageBase + stubOffset, stubSize, stubSize);
Location = new Location(image, stubOffset, stubOffset, imageBase + stubOffset, stubSize, stubSize);
}

#region Methods
Expand Down
Loading

0 comments on commit 63e4fb4

Please sign in to comment.