Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6.0.0-beta.1 #566

Merged
merged 91 commits into from
Jun 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
6858900
Initial concept RuntimeContexts.
Washi1337 Jan 10, 2024
f5e3c08
Let assembly resolver use custom reader parameters and pass along run…
Washi1337 Jan 28, 2024
4a1e351
Merge branch 'development' into feature/runtime-contexts
Washi1337 Mar 5, 2024
5cf5ddf
Simplify assembly resolver creation
Washi1337 Mar 5, 2024
0f6880c
Add ModuleDefinition::EnumerateTableMembers.
Washi1337 Mar 6, 2024
0e6c2a0
Conditionally replace System.Text.Json with SimpleJSON.
Washi1337 Mar 16, 2024
4c25a82
Use Utf8String for PESection::Name
Washi1337 Mar 16, 2024
51c6d80
Add TypeMemoryLayout::IsReferenceOrContainsReferences.
Washi1337 Mar 16, 2024
8b2318d
Merge pull request #538 from Washi1337/feature/embedded-json
Washi1337 Mar 17, 2024
5a10c72
Add .net35 target for AsmResolver.
Washi1337 Mar 17, 2024
1f1b617
Add .net35 target for AsmResolver.PE.File and AsmResolver.PE.
Washi1337 Mar 17, 2024
7d3d6f9
Add .net35 target for AsmResolver.DotNet.
Washi1337 Mar 17, 2024
c443a6e
Add .net35 target for AsmResolver.Symbols.Pdb and AsmResolver.PE.Wind…
Washi1337 Mar 17, 2024
b14b9e6
Add .net35 target for all packages in src/.
Washi1337 Mar 17, 2024
39981e2
Replace GetRuntimeMethods with GetMethods.
Washi1337 Mar 17, 2024
befa155
Add MemoryMappedFileShim
Windows10CE Mar 20, 2024
074b623
Port MemoryMappedDataSource and friends
Windows10CE Mar 21, 2024
cbc1389
Code style
Windows10CE Mar 21, 2024
e20aafe
Merge pull request #539 from Washi1337/feature/is-ref-or-contains-refs
Washi1337 Mar 24, 2024
d150e58
BUGFIX: Mono facades resolution. Add singleton instances for default …
Washi1337 Apr 10, 2024
2fc1872
Add BundleAssemblyResolver.
Washi1337 Apr 10, 2024
f1e84cd
Add missing dependencies to benchmark project.
Washi1337 Apr 10, 2024
2b4897c
Switch MappedMappedDataSource to UnmanagedDataSource
Windows10CE Apr 11, 2024
b503358
Add .NET 9 to the list of known core libraries
ds5678 Apr 14, 2024
5985b60
Use direct module reader params constructor.
Washi1337 Apr 15, 2024
e8055ae
Merge pull request #537 from Washi1337/feature/runtime-contexts
Washi1337 Apr 15, 2024
ce3274b
Merge pull request #548 from ds5678/dotnet-9-knowncorlib
Washi1337 Apr 19, 2024
2f89321
BUGFIX: Consider fnptr signatures in SignatureComparer::GetHashCode. …
Washi1337 Apr 19, 2024
e815b85
Refactor ResourceDirectory::InsertOrReplaceEntry and IWin32Resource::…
Washi1337 Apr 19, 2024
e788c65
Update docs on new InsertOrReplaceEntry.
Washi1337 Apr 19, 2024
0780c51
Merge pull request #553 from Washi1337/feature/win32-insert-into-dir
Washi1337 Apr 28, 2024
7b27c91
Initial refactor PE file builders.
Washi1337 May 7, 2024
60b9155
Start unmanaged PE file builder.
Washi1337 May 8, 2024
c00049a
Patch existing segments when possible in unmanaged PE file builder.
Washi1337 May 8, 2024
bb269a1
Add IAT and VTable trampolines.
Washi1337 May 12, 2024
100d242
BUGFIX: Map existing slot symbols to new slot symbols.
Washi1337 May 12, 2024
7e5e8f5
Add set accessors for PropertyDefinition.GetMethod and PropertyDefini…
ds5678 May 12, 2024
03c16f9
Set accessor parity for EventDefinition
ds5678 May 12, 2024
1c35a57
Add unit test
ds5678 May 13, 2024
c5802a6
Merge pull request #555 from ds5678/property-definition-set-accessors
Washi1337 May 15, 2024
a1af121
Add IInputFile.BaseAddress
Windows10CE May 17, 2024
5dab107
Add platform-specific address table slot initializers for imported da…
Washi1337 May 17, 2024
429844a
Merge pull request #544 from Windows10CE/mmio-net35
Washi1337 May 17, 2024
c2a3c5a
Resolve compiler warnings.
Washi1337 May 17, 2024
a640a82
Merge pull request #540 from Washi1337/feature/net35-monomod
Washi1337 May 17, 2024
b1ded1f
BUGFIX: Resolve concurrency issue in string heap caches.
Washi1337 May 17, 2024
1fb9ccd
Bump to alpha version.
Washi1337 May 17, 2024
3471b20
BUGFIX: If `#Schema` heap is present force `IsEncMetadata` to true
ElektroKill May 19, 2024
21e168a
BUGFIX: Use case-insensitive comparison for heap names in EnC metadata
ElektroKill May 19, 2024
e521fc5
Add support for #JTD stream which enforces 4 byte table indices
ElektroKill May 19, 2024
fac88fa
Fix nullability warnings
ElektroKill May 19, 2024
8864567
Add new builder flag to force the usage of EnC metadata
ElektroKill May 28, 2024
b30b140
Addressed feedback
ElektroKill May 28, 2024
02005ab
`EnC` -> `Enc`
ElektroKill May 29, 2024
24461bf
Merge pull request #557 from ElektroKill/feature/metadata-format-quirks
Washi1337 May 30, 2024
9dcd903
Merge branch 'development' into feature/new-pe-file-builders
Washi1337 Jun 2, 2024
7592154
Add documentation for the new PE file builder APIs.
Washi1337 Jun 2, 2024
95a0f58
Remove redundant usings and identifiers.
Washi1337 Jun 2, 2024
988efa3
Merge pull request #554 from Washi1337/feature/new-pe-file-builders
Washi1337 Jun 2, 2024
ab5335b
Flatten namespaces in AsmResolver.PE.File
Washi1337 Jun 2, 2024
5ba5761
Flatten redundant namespaces in AsmResolver.PE.
Washi1337 Jun 2, 2024
dca6bdd
Flatten redundant namespaces in AsmResolver.DotNet.
Washi1337 Jun 2, 2024
a8d65f8
Flatten metadata namespaces.
Washi1337 Jun 2, 2024
c53c212
Flatten AsmResolver.PE.Debug
Washi1337 Jun 2, 2024
95590c2
Adding missing changes.
Washi1337 Jun 2, 2024
76a87fb
Remove redundant namespace qualifier.
Washi1337 Jun 3, 2024
36eeac9
Merge pull request #560 from Washi1337/feature/reduce-namespace-nesting
Washi1337 Jun 3, 2024
167928b
Remove IPEFile interface.
Washi1337 Jun 3, 2024
61b05f6
Remove IPEImage interface.
Washi1337 Jun 3, 2024
6c3f553
Remove IDotNetDirectory and IMetadata.
Washi1337 Jun 3, 2024
fe9d41b
Remove IExportDirectory.
Washi1337 Jun 3, 2024
a34651a
Remove IImportedModule.
Washi1337 Jun 3, 2024
fe610dd
Remove ITlsDirectory.
Washi1337 Jun 3, 2024
9848edd
Remove IResourceData and IResourceDirectory.
Washi1337 Jun 3, 2024
79b7a01
Update docs.
Washi1337 Jun 3, 2024
9ecc97a
Merge pull request #561 from Washi1337/feature/reduce-redundant-abstr…
Washi1337 Jun 4, 2024
bf80344
Add missing methodimpl flags.
Washi1337 Jun 7, 2024
c7bc9f6
Move IBinaryStreamWriter and BinaryStreamWriterExtensions into Binary…
Washi1337 Jun 7, 2024
1c2cbf4
Use BinaryPrimitives when available.
Washi1337 Jun 7, 2024
3f78f84
Merge pull request #562 from Washi1337/feature/flatten-binarystreamwr…
Washi1337 Jun 9, 2024
9a72de4
Set default reader error listener to EmptyErrorListener.Instance.
Washi1337 Jun 12, 2024
0195bbc
Update docs on new error handling defaults.
Washi1337 Jun 12, 2024
19a2c30
Use empty error listener by default for PDB reading.
Washi1337 Jun 12, 2024
94ce619
Rewritten IconResource in a more intuitive API that preserves LCIDs.
Washi1337 Jun 12, 2024
4ffa208
Add docs on win32 resources. Let StringTable implement IDictionary<st…
Washi1337 Jun 12, 2024
d781876
Merge pull request #564 from Washi1337/feature/empty-error-listener-o…
Washi1337 Jun 13, 2024
5d21f10
Merge pull request #565 from Washi1337/feature/revamp-icon-resources
Washi1337 Jun 13, 2024
db55ce2
Bump version, update README.md.
Washi1337 Jun 13, 2024
5b76046
Clarify on IAT trampolining
Washi1337 Jun 15, 2024
c5b9045
Resolve compiler warnings.
Washi1337 Jun 15, 2024
105f129
Add docs on RuntimeContext.
Washi1337 Jun 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ csharp_preferred_modifier_order = public, private, protected, internal, new, abs
csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = false:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_new_line_before_open_brace = all
dotnet_style_parentheses_in_arithmetic_binary_operators = never_if_unnecessary:none
dotnet_style_parentheses_in_other_binary_operators = never_if_unnecessary:none
dotnet_style_parentheses_in_relational_binary_operators = never_if_unnecessary:none
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<RepositoryUrl>https://github.com/Washi1337/AsmResolver</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<LangVersion>10</LangVersion>
<Version>5.5.1</Version>
<Version>6.0.0-beta.1</Version>
<Deterministic>true</Deterministic>
<UseArtifactsOutput>true</UseArtifactsOutput>
</PropertyGroup>
Expand Down
3 changes: 1 addition & 2 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
The MIT License (MIT)
=====================

Copyright © `2016-2021 Washi`
Copyright © `2016-2024 Washi`

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
Expand All @@ -23,4 +23,3 @@ 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.

36 changes: 21 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Discord](https://img.shields.io/discord/961647807591243796.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/Y7DTBkbhJJ)

AsmResolver is a Portable Executable (PE) inspection library that is able to read, modify and write executable files. This includes .NET modules as well as native images. The library exposes high-level representations of the PE, while still allowing the user to access low-level structures.
AsmResolver is a library for reading, modifying and reconstructing Portable Executable (PE) files. It supports PE images running natively on Windows, as well as images containing managed (.NET) metadata.

AsmResolver is released under the MIT license.

Expand All @@ -16,15 +16,19 @@ AsmResolver has a lot of features. Below is a non-exhaustive list of the highlig

- [x] Create, read, modify, write and patch PE files.
- [x] Full access to sections, data directories and their interpretations.
- [x] Rich support for .NET modules with an intuitive API similar to `System.Reflection`.
- [x] Import Address Table (IAT) reconstruction and trampolining.
- [x] Full control over the layout of the final PE file output.
- [x] Rich support for various Win32 resource types.
- [x] Rich support for .NET metadata with an intuitive API similar to `System.Reflection`.
- [x] Managed, native and dynamic method body support.
- [x] Easy metadata importing and cloning.
- [x] Managed resource file serializers and deserializers.
- [x] Support for AppHost / SingleFileHost bundles.
- [x] Support for ReadyToRun binaries.
- [x] Read PDB symbols.
- [x] Support for ReadyToRun (R2R) binaries.
- [x] Rich read support for PDB and PortablePdb symbols.
- [x] Fully managed cross-platform API (No DIA or similar required).
- [x] .NET Standard 2.0 compatible.
- [x] .NET 3.5 compatible.
- [x] Cross-platform (Windows and *nix, .NET standard 2.0 and Mono compatible).
- [x] Documented.
- [x] Unit tested.

Expand All @@ -35,6 +39,12 @@ AsmResolver has a lot of features. Below is a non-exhaustive list of the highlig
- [API Reference](https://docs.washi.dev/asmresolver/api/core/AsmResolver.html)


## Support

- [Issue Tracker](https://github.com/Washi1337/AsmResolver/issues)
- [Discussion Board](https://github.com/washi1337/asmresolver/discussions)
- [Discord](https://discord.gg/Y7DTBkbhJJ)

## Binaries

Stable Builds:
Expand All @@ -54,7 +64,7 @@ Nightly Builds:

## Compiling

The solution can be built using the .NET SDK or an IDE that works with it (e.g., Visual Studio and JetBrains Rider). The main packages target LTS versions of various .NET runtimes (.NET Standard 2.0, .NET Core 3.1 and .NET 6.0).
The solution can be built using the .NET SDK or an IDE that works with it (e.g., Visual Studio and JetBrains Rider). The main packages target LTS versions of various .NET runtimes (.NET 3.5, .NET Standard 2.0, .NET Standard 2.1, .NET Core 3.1, .NET 6.0, .NET 8.0).

To build the project from the command line, use:
```bash
Expand All @@ -65,26 +75,22 @@ To run all tests, use:
```bash
$ dotnet test
```
For running the tests successfully, you will need to have various versions of .NET installed (ranging from .NET Framework to .NET Core 3.1 and .NET 5+), as the unit tests verify reading binaries targeting various .NET runtimes.
For running the tests successfully, you will need to have additional versions of .NET installed (including STS versions or versions declared EOL), as the unit tests verify reading binaries targeting various .NET runtimes.
To run the tests successfully on MacOS and Linux, `mono` and `wine` are expected to be installed as well.


## Contributing

- See [CONTRIBUTING.md](CONTRIBUTING.md).


## Support

- [Issue Tracker](https://github.com/Washi1337/AsmResolver/issues)
- [Discussion Board](github.com/washi1337/asmresolver/discussions)
- [Discord](https://discord.gg/Y7DTBkbhJJ)


## Acknowledgments

AsmResolver started as a hobby project but has grown into a community project with various contributors. Without these people, AsmResolver would not have been where it is today!

- Special thanks to all the people who contributed [directly with code commits](https://github.com/Washi1337/AsmResolver/graphs/contributors).
- Special thanks to all the people who contributed [directly with code commits](https://github.com/Washi1337/AsmResolver/graphs/contributors) or monetarily via [GitHub sponsors](https://github.com/sponsors/Washi1337).

- Special thanks to the people at [@MonoMod](https://github.com/MonoMod) for helping with .NET 3.5 compatibility.

- Another big thank you to all the people that suggested new features, provided feedback on the API design, have done extensive testing, and/or reported bugs on the [issue board](https://github.com/Washi1337/AsmResolver/issues), by e-mail, or through DMs.

Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
- master

image: Visual Studio 2022
version: 5.5.1-master-build.{build}
version: 6.0.0-master-build.{build}
configuration: Release

skip_commits:
Expand Down Expand Up @@ -33,7 +33,7 @@
- development

image: Visual Studio 2022
version: 5.5.1-dev-build.{build}
version: 6.0.0-dev-build.{build}
configuration: Release

skip_commits:
Expand Down
15 changes: 8 additions & 7 deletions docs/guides/dotnet/advanced-module-reading.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Advanced Module Reading

Advanced users might need to configure AsmResolver\'s module reader. For
example, instead of letting the module reader throw exceptions upon
reading invalid data, errors should be ignored and recovered from. Other
example, instead of letting the module reader ignore exceptions upon
reading invalid data, errors could be collected or thrown. Other
uses might include changing the way the underlying PE or method bodies
are read. These kinds of settings can be configured using the
`ModuleReaderParameters` class.
Expand Down Expand Up @@ -33,23 +33,24 @@ parameters.PEReaderParameters = new PEReaderParameters
};
```

For example, this can be in particular useful if you want to let
AsmResolver ignore and recover from invalid data in the input file:
For example, this can be in particular useful if you want to customize the
way AsmResolver deals with invalid data.

``` csharp
parameters.PEReaderParameters.ErrorListener = EmptyErrorListener.Instance;
parameters.PEReaderParameters.ErrorListener = ThrowErrorListener.Instance;
```

Alternatively, this property can also be set through the constructor of
the `ModuleReaderParameters` class directly:

``` csharp
var parameters = new ModuleReaderParameters(EmptyErrorListener.Instance);
var parameters = new ModuleReaderParameters(ThrowErrorListener.Instance);
```

For more information on customizing the underlying PE image reading
process, see [Advanced PE Image Reading](../peimage/advanced-pe-reading.md).


## Changing working directory

Modules often depend on other assemblies. These assemblies often are
Expand Down Expand Up @@ -154,7 +155,7 @@ public class CustomFieldRvaDataReader : FieldRvaDataReader
public override ISegment ResolveFieldData(
IErrorListener listener,
Platform platform,
IDotNetDirectory directory,
DotNetDirectory directory,
in FieldRvaRow fieldRvaRow)
{
// ...
Expand Down
39 changes: 36 additions & 3 deletions docs/guides/dotnet/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var module = ModuleDefinition.FromReader(reader);
```

``` csharp
IPEImage peImage = ...
PEImage peImage = ...
var module = ModuleDefinition.FromImage(peImage);
```

Expand Down Expand Up @@ -90,6 +90,36 @@ IntPtr hInstance = Marshal.GetHINSTANCE(module);
var module = ModuleDefinition.FromModuleBaseAddress(hInstance);
```

For more information on customizing the reading process, see [Advanced Module Reading](advanced-module-reading.md).


## Opening multiple .NET modules using Runtime Contexts

By default, AsmResolver auto-detects the runtime the module originally targets, and each module assumes their own set of caches and resolved dependencies.

To force a module to be loaded as a specific runtime, define a `RuntimeContext` with the provided runtime info:

```csharp
// Define a context targeting .NET Core 3.1.
var context = new RuntimeContext(new DotNetRuntimeInfo(DotNetRuntimeInfo.NetCoreApp, new Version(3, 1)));

// Load module within the context.
var module = ModuleDefinition.FromFile(@"C:\Path\To\File.exe", new ModuleReaderParameters(context));
```

Modules can also be loaded explicitly into an existing context from another module:

```csharp
ModuleDefinition primaryModule = ...;

// Load a module within the same context as the primary module.
var secondaryModule = ModuleDefinition.FromFile("C:\Path\To\Dependency.dll", new ModuleReaderParameters(primaryModule.RuntimeContext));
```

Reusing an existing context ensures that the same target runtime is assumed, and that equivalent assembly references resolve to the same assembly definition instances.
This provides additional caching performance, and avoids many problems when processing multiple files at once.


## Writing a .NET module

Writing a .NET module can be done through one of the `Write` method
Expand Down Expand Up @@ -131,7 +161,7 @@ var assembly = AssemblyDefinition.FromFile(@"C:\myfile.exe");
```

``` csharp
IPEFile peFile = ...
PEFile peFile = ...
var assembly = AssemblyDefinition.FromFile(peFile);
```

Expand All @@ -141,7 +171,7 @@ var assembly = AssemblyDefinition.FromReader(reader);
```

``` csharp
IPEImage peImage = ...
PEImage peImage = ...
var assembly = AssemblyDefinition.FromImage(peImage);
```

Expand All @@ -153,6 +183,9 @@ using var service = new MemoryMappedFileService();
var assembly = AssemblyDefinition.FromFile(service.OpenFile(@"C:\myfile.exe"));
```

For more information on customizing the reading process, see [Advanced Module Reading](advanced-module-reading.md).


## Writing a .NET assembly

Writing a .NET assembly can be done through one of the `Write` method
Expand Down
2 changes: 1 addition & 1 deletion docs/guides/dotnet/bundles.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ manifest.WriteUsingTemplate(
> [!NOTE]
> `BundleManifest` and `BundlerParameters` also define overloads of the
> `WriteUsingTemplate` and `FromTemplate` / `FromExistingBundle`
> respectively, taking `byte[]`, `IDataSource` or `IPEImage` instances
> respectively, taking `byte[]`, `IDataSource` or `PEImage` instances
> instead of file paths.


Expand Down
2 changes: 1 addition & 1 deletion docs/guides/dotnet/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ In short, this means the following:

The third layer of abstraction is the highest level of abstraction for a
.NET assembly that AsmResolver provides. All objects exposed by this
layer are completely mutable and can be serialized back to a `IPEImage`
layer are completely mutable and can be serialized back to a `PEImage`
from the second layer, to a `PEFile` from the first layer, or to the
disk.
Loading