Skip to content
This repository has been archived by the owner on Jul 26, 2021. It is now read-only.

Commit

Permalink
Fix AssemblyResolver issues
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Feb 23, 2021
1 parent f2631d3 commit d31b0a3
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
16 changes: 16 additions & 0 deletions Reactor.OxygenFilter.MSBuild/AssemblyResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Collections.Generic;
using Mono.Cecil;

namespace Reactor.OxygenFilter.MSBuild
{
public class AssemblyResolver : DefaultAssemblyResolver
{
protected override AssemblyDefinition SearchDirectory(AssemblyNameReference name, IEnumerable<string> directories, ReaderParameters parameters)
{
if (name.Name == "netstandard")
return null;

return base.SearchDirectory(name, directories, parameters);
}
}
}
13 changes: 11 additions & 2 deletions Reactor.OxygenFilter.MSBuild/Deobfuscate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,21 @@ public override bool Execute()

var mappings = JsonConvert.DeserializeObject<Mappings>(Context.MappingsJson);

var resolver = new DefaultAssemblyResolver();
var resolver = new AssemblyResolver();
resolver.AddSearchDirectory(Path.Combine(Context.MappedPath, "references"));
resolver.AddSearchDirectory(Path.Combine(AmongUs, "BepInEx", "core"));
resolver.AddSearchDirectory(Path.Combine(AmongUs, "BepInEx", "plugins"));
resolver.AddSearchDirectory(Path.Combine(AmongUs, "BepInEx", "unhollowed"));

var readerParameters = new ReaderParameters { AssemblyResolver = resolver };

// quick fix for reactor plugin having different file name than assembly name
resolver.ResolveFailure += (_, reference) =>
{
var files = Directory.GetFiles(Path.Combine(AmongUs, "BepInEx", "plugins"), $"{reference.Name}-*.dll");
return files.Length == 1 ? AssemblyDefinition.ReadAssembly(files.Single(), readerParameters) : null;
};

var deobfuscated = new List<string>();

foreach (var input in Input)
Expand All @@ -58,7 +67,7 @@ public override bool Execute()

using var stream = File.Open(input, FileMode.Open, FileAccess.Read, FileShare.Read);

using var moduleDefinition = ModuleDefinition.ReadModule(stream, new ReaderParameters { AssemblyResolver = resolver });
using var moduleDefinition = ModuleDefinition.ReadModule(stream, readerParameters);
var toDeobfuscate = new Dictionary<MemberReference, string>();

foreach (var type in moduleDefinition.GetTypeReferences())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<LangVersion>latest</LangVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

<Version>0.2.7</Version>
<Version>0.2.8</Version>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/NuclearPowered/Reactor.OxygenFilter</RepositoryUrl>
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
Expand Down
4 changes: 2 additions & 2 deletions Reactor.OxygenFilter.MSBuild/Reobfuscate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ private static string GetObfuscated(ICustomAttributeProvider cap)
public override bool Execute()
{
using var stream = File.Open(Input, FileMode.Open, FileAccess.ReadWrite);
var resolver = new DefaultAssemblyResolver();
var resolver = new AssemblyResolver();

var obfuscatedAssembly = AssemblyDefinition.ReadAssembly(Path.Combine(AmongUs, "BepInEx", "unhollowed", "Assembly-CSharp.dll"));

Expand All @@ -41,7 +41,7 @@ public override bool Execute()
{
foreach (var referencedAssembly in referencedAssemblies)
{
if (referencedAssembly.Name.FullName == reference.FullName)
if (referencedAssembly.Name.Name == reference.Name)
{
return referencedAssembly;
}
Expand Down

0 comments on commit d31b0a3

Please sign in to comment.