-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Lloyd Kinsella
committed
Aug 8, 2018
1 parent
28d5961
commit d3f9e4a
Showing
27 changed files
with
526 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Workshell.PE.Content | ||
{ | ||
public sealed class ResourceData : DataContent | ||
{ | ||
internal ResourceData(PortableExecutableImage image, DataDirectory dataDirectory, Location location, ResourceDataEntry entry) : base(image, dataDirectory, location) | ||
{ | ||
Entry = entry; | ||
} | ||
|
||
#region Methods | ||
|
||
public void CopyTo(Stream stream) | ||
{ | ||
CopyToAsync(stream).GetAwaiter().GetResult(); | ||
} | ||
|
||
public async Task CopyToAsync(Stream stream) | ||
{ | ||
var buffer = await GetBytesAsync().ConfigureAwait(false); | ||
|
||
await stream.WriteAsync(buffer, 0, buffer.Length).ConfigureAwait(false); | ||
} | ||
|
||
#endregion | ||
|
||
#region Properties | ||
|
||
public ResourceDataEntry Entry { get; } | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
using Workshell.PE.Annotations; | ||
using Workshell.PE.Extensions; | ||
using Workshell.PE.Native; | ||
|
||
namespace Workshell.PE.Content | ||
{ | ||
public sealed class ResourceDataEntry : DataContent | ||
{ | ||
private ResourceData _data; | ||
|
||
internal ResourceDataEntry(PortableExecutableImage image, DataDirectory dataDirectory, Location location, ResourceDirectoryEntry directoryEntry) : base(image, dataDirectory, location) | ||
{ | ||
_data = null; | ||
|
||
DirectoryEntry = directoryEntry; | ||
} | ||
|
||
#region Methods | ||
|
||
public ResourceData GetData() | ||
{ | ||
if (_data == null) | ||
{ | ||
var calc = Image.GetCalculator(); | ||
var rva = OffsetToData; | ||
var va = Image.NTHeaders.OptionalHeader.ImageBase + rva; | ||
var offset = calc.RVAToOffset(rva); | ||
var size = Size; | ||
var section = calc.RVAToSection(rva); | ||
var location = new Location(offset, rva, va, size, size, section); | ||
|
||
_data = new ResourceData(Image, DataDirectory, location, this); | ||
} | ||
|
||
return _data; | ||
} | ||
|
||
internal async Task LoadAsync() | ||
{ | ||
var stream = Image.GetStream(); | ||
|
||
stream.Seek(Location.FileOffset.ToInt64(), SeekOrigin.Begin); | ||
|
||
try | ||
{ | ||
var entry = await stream.ReadStructAsync<IMAGE_RESOURCE_DATA_ENTRY>().ConfigureAwait(false); | ||
|
||
OffsetToData = entry.OffsetToData; | ||
Size = entry.Size; | ||
CodePage = entry.CodePage; | ||
Reserved = entry.Reserved; | ||
} | ||
catch (Exception ex) | ||
{ | ||
throw new PortableExecutableImageException(Image, "Could not read resource data entry from stream.", ex); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region Properties | ||
|
||
public ResourceDirectoryEntry DirectoryEntry { get; } | ||
|
||
[FieldAnnotation("Offset to Data")] | ||
public uint OffsetToData { get; private set; } | ||
|
||
[FieldAnnotation("Size")] | ||
public uint Size { get; private set; } | ||
|
||
[FieldAnnotation("Code Page")] | ||
public uint CodePage { get; private set; } | ||
|
||
[FieldAnnotation("Reserved")] | ||
public uint Reserved { get; private set; } | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.