-
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.
Merge branch 'develop' into pei-changes
- Loading branch information
Showing
22 changed files
with
1,671 additions
and
128 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,43 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 15 | ||
VisualStudioVersion = 15.0.27703.2042 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Workshell.PE", "src\Workshell.PE\Workshell.PE.csproj", "{2DF6E85A-7269-46C6-9032-1C3A8F029AE3}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Workshell.PE.Resources", "src\Workshell.PE.Resources\Workshell.PE.Resources.csproj", "{DBED9C9E-0B8C-46B5-AE1D-865722B68E44}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{85C1A49C-0316-4C2D-B2E3-17B1F8200EE7}" | ||
ProjectSection(SolutionItems) = preProject | ||
src\CommonAssemblyInfo.cs = src\CommonAssemblyInfo.cs | ||
readme.md = readme.md | ||
EndProjectSection | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {D281E078-262D-4616-9157-CE1C42C0026C} | ||
EndGlobalSection | ||
EndGlobal | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 16 | ||
VisualStudioVersion = 16.0.29503.13 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Workshell.PE", "src\Workshell.PE\Workshell.PE.csproj", "{2DF6E85A-7269-46C6-9032-1C3A8F029AE3}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Workshell.PE.Resources", "src\Workshell.PE.Resources\Workshell.PE.Resources.csproj", "{DBED9C9E-0B8C-46B5-AE1D-865722B68E44}" | ||
EndProject | ||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{85C1A49C-0316-4C2D-B2E3-17B1F8200EE7}" | ||
ProjectSection(SolutionItems) = preProject | ||
src\CommonAssemblyInfo.cs = src\CommonAssemblyInfo.cs | ||
readme.md = readme.md | ||
EndProjectSection | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Workshell.PE.Tests", "tests\Workshell.PE.Tests\Workshell.PE.Tests.csproj", "{8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{2DF6E85A-7269-46C6-9032-1C3A8F029AE3}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{DBED9C9E-0B8C-46B5-AE1D-865722B68E44}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{8A5FC684-11D6-4902-B0E0-7FEBC36BA21F}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {D281E078-262D-4616-9157-CE1C42C0026C} | ||
EndGlobalSection | ||
EndGlobal |
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 |
---|---|---|
@@ -1,89 +1,90 @@ | ||
# Workshell PE Class Library | ||
|
||
[](https://github.com/Workshell/pe/blob/master/license.txt) | ||
[](https://www.nuget.org/packages/Workshell.PE/) | ||
|
||
This is a class library for reading the Portable Executable file format convering all the major data sections including: | ||
|
||
* Core Headers (DOS, File, Optional) | ||
* Section Table | ||
* Debug Directory | ||
* Relocations | ||
* Imports | ||
* Delayed Imports | ||
* Exports | ||
* Resources | ||
* TLS | ||
* Load Configuration | ||
* Certificates | ||
* .NET | ||
|
||
For help getting started please see the wiki. Any suggestions for improvements and ideas welcome. | ||
|
||
|
||
## Installation | ||
|
||
Stable builds are available as NuGet packages. You can install it via the Package Manager or via the Package Manager Console: | ||
|
||
``` | ||
Install-Package Workshell.PE | ||
Install-Package Workshell.PE.Resources | ||
``` | ||
|
||
|
||
## Basic Usage | ||
|
||
You begin by calling `PortableExecutableImage.FromFileAsync(string)` to load the executable image, such as: | ||
|
||
``` | ||
var image = await PortableExecutableImage.FromFileAsync("user32.dll"); | ||
``` | ||
|
||
You can then retireve information from the image. Some information is retrieved in a direct manor, like a lot of the core | ||
header information, for example: | ||
|
||
``` | ||
var imageBase = image.NTHeaders.OptionalHeader.ImageBase; | ||
``` | ||
|
||
And some information is indirect via classes that work on the image. If you wanted all the exports for example: | ||
|
||
``` | ||
var exports = await Exports.GetAsync(image); | ||
``` | ||
|
||
You can then iterate each export: | ||
|
||
``` | ||
foreach(var export in exports) | ||
{ | ||
Console.WriteLine(export.Name); | ||
} | ||
``` | ||
|
||
At present there is no real documentation so the best option is to explore the source code and experiment! | ||
|
||
If you have questions please do get in touch we're always happy to help. | ||
|
||
|
||
## MIT 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 | ||
# Workshell PE Class Library | ||
|
||
[](https://github.com/Workshell/pe/blob/master/license.txt) | ||
[](https://www.nuget.org/packages/Workshell.PE/) | ||
[](https://dev.azure.com/Workshell-DevOps/Workshell%20PE/_build/latest?definitionId=2&branchName=master) | ||
|
||
This is a class library for reading the Portable Executable file format convering all the major data sections including: | ||
|
||
* Core Headers (DOS, File, Optional) | ||
* Section Table | ||
* Debug Directory | ||
* Relocations | ||
* Imports | ||
* Delayed Imports | ||
* Exports | ||
* Resources | ||
* TLS | ||
* Load Configuration | ||
* Certificates | ||
* .NET | ||
|
||
For help getting started please see the wiki. Any suggestions for improvements and ideas welcome. | ||
|
||
|
||
## Installation | ||
|
||
Stable builds are available as NuGet packages. You can install it via the Package Manager or via the Package Manager Console: | ||
|
||
``` | ||
Install-Package Workshell.PE | ||
Install-Package Workshell.PE.Resources | ||
``` | ||
|
||
|
||
## Basic Usage | ||
|
||
You begin by calling `PortableExecutableImage.FromFileAsync(string)` to load the executable image, such as: | ||
|
||
``` | ||
var image = await PortableExecutableImage.FromFileAsync("user32.dll"); | ||
``` | ||
|
||
You can then retireve information from the image. Some information is retrieved in a direct manor, like a lot of the core | ||
header information, for example: | ||
|
||
``` | ||
var imageBase = image.NTHeaders.OptionalHeader.ImageBase; | ||
``` | ||
|
||
And some information is indirect via classes that work on the image. If you wanted all the exports for example: | ||
|
||
``` | ||
var exports = await Exports.GetAsync(image); | ||
``` | ||
|
||
You can then iterate each export: | ||
|
||
``` | ||
foreach(var export in exports) | ||
{ | ||
Console.WriteLine(export.Name); | ||
} | ||
``` | ||
|
||
At present there is no real documentation so the best option is to explore the source code and experiment! | ||
|
||
If you have questions please do get in touch we're always happy to help. | ||
|
||
|
||
## MIT 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. |
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,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
using FluentAssertions; | ||
using NUnit.Framework; | ||
|
||
namespace Workshell.PE.Tests | ||
{ | ||
[TestFixture] | ||
public sealed class DOSHeaderTests | ||
{ | ||
[Test] | ||
public void DOSHeader_Is_Not_Null() | ||
{ | ||
var file = TestingUtils.GetFileFromResources(TestingUtils.GetRandomTestFilename()); | ||
|
||
using (var image = PortableExecutableImage.FromStream(file)) | ||
{ | ||
image.DOSHeader.Should().NotBeNull(); | ||
} | ||
} | ||
|
||
[TestCase("clrtest.any.dll", 0x0090)] | ||
[TestCase("clrtest.x86.dll", 0x0090)] | ||
[TestCase("clrtest.x64.dll", 0x0090)] | ||
[TestCase("nativetest.x86.dll", 0x0050)] | ||
[TestCase("nativetest.x64.dll", 0x0050)] | ||
public void Bytes_On_Last_Page_Of_File_Is_Correct(string fileName, int expectedValue) | ||
{ | ||
var file = TestingUtils.GetFileFromResources(fileName); | ||
|
||
using (var image = PortableExecutableImage.FromStream(file)) | ||
{ | ||
var value = image.DOSHeader.BytesOnLastPage; | ||
|
||
value.Should().Be(Convert.ToUInt16(expectedValue)); | ||
} | ||
} | ||
|
||
[TestCase("clrtest.any.dll", 0x0040)] | ||
[TestCase("clrtest.x86.dll", 0x0040)] | ||
[TestCase("clrtest.x64.dll", 0x0040)] | ||
[TestCase("nativetest.x86.dll", 0x0040)] | ||
[TestCase("nativetest.x64.dll", 0x0040)] | ||
public void File_Address_Relocation_Table_Is_Correct(string fileName, int expectedValue) | ||
{ | ||
var file = TestingUtils.GetFileFromResources(fileName); | ||
|
||
using (var image = PortableExecutableImage.FromStream(file)) | ||
{ | ||
var value = image.DOSHeader.FileAddressRelocationTable; | ||
|
||
value.Should().Be(Convert.ToUInt16(expectedValue)); | ||
} | ||
} | ||
|
||
[TestCase("clrtest.any.dll", 0x00000080)] | ||
[TestCase("clrtest.x86.dll", 0x00000080)] | ||
[TestCase("clrtest.x64.dll", 0x00000080)] | ||
[TestCase("nativetest.x86.dll", 0x00000100)] | ||
[TestCase("nativetest.x64.dll", 0x00000100)] | ||
public void File_Address_New_Header_Is_Correct(string fileName, int expectedValue) | ||
{ | ||
var file = TestingUtils.GetFileFromResources(fileName); | ||
|
||
using (var image = PortableExecutableImage.FromStream(file)) | ||
{ | ||
var value = image.DOSHeader.FileAddressNewHeader; | ||
|
||
value.Should().Be(expectedValue); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.