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

Commit

Permalink
Fallback to obfuscated names in generic fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Jan 3, 2021
1 parent e6f5afb commit 346cf1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<LangVersion>latest</LangVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>

<Version>0.1.4</Version>
<Version>0.1.5</Version>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/NuclearPowered/Reactor.OxygenFilter</RepositoryUrl>
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
Expand Down
13 changes: 9 additions & 4 deletions Reactor.OxygenFilter.MSBuild/Reobfuscate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public override bool Execute()
using var stream = File.Open(Input, FileMode.Open, FileAccess.ReadWrite);
var resolver = new DefaultAssemblyResolver();

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

resolver.ResolveFailure += (_, reference) =>
{
foreach (var referencedAssembly in ReferencedAssemblies)
Expand All @@ -48,6 +50,11 @@ public override bool Execute()
}
}

if (reference.FullName == obfuscatedAssembly.Name.FullName)
{
return obfuscatedAssembly;
}

return null;
};

Expand Down Expand Up @@ -166,8 +173,6 @@ public override bool Execute()
}
}

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

// fix generic methods
foreach (var methodDefinition in moduleDefinition.GetAllTypes().SelectMany(x => x.Methods))
{
Expand Down Expand Up @@ -196,11 +201,11 @@ public override bool Execute()
type = type.DeclaringType;
}

var typeDefinition = obfuscatedAssembly.GetType(GetObfuscated(hierarchy.First()));
var typeDefinition = obfuscatedAssembly.MainModule.GetType(GetObfuscated(hierarchy.First()) ?? hierarchy.First().FullName);

foreach (var element in hierarchy.Skip(1))
{
typeDefinition = typeDefinition.NestedTypes.Single(x => x.Name == GetObfuscated(element));
typeDefinition = typeDefinition.NestedTypes.Single(x => x.Name == (GetObfuscated(element) ?? element.Name));
}

// get same method from obfuscated assembly
Expand Down

0 comments on commit 346cf1b

Please sign in to comment.