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

Commit

Permalink
Match method signatures in reobfuscation
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Feb 15, 2021
1 parent 1b4c68d commit 81696bc
Show file tree
Hide file tree
Showing 3 changed files with 25 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.2.5</Version>
<Version>0.2.6</Version>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/NuclearPowered/Reactor.OxygenFilter</RepositoryUrl>
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
Expand Down
3 changes: 2 additions & 1 deletion Reactor.OxygenFilter.MSBuild/Reobfuscate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ void ReobfuscateType(TypeReference t)
}

// get same method from obfuscated assembly
MethodReference definition = typeDefinition.GetMethods().Single(x => x.Name == obfuscated);
var signature = deobfuscatedCall.GetSignature(t => GetObfuscated(t) ?? t.FullName);
MethodReference definition = typeDefinition.GetMethods().Single(x => x.Name == obfuscated && x.GetSignature() == signature);

// obfuscate generics
if (deobfuscatedCallReference is GenericInstanceMethod generic)
Expand Down
25 changes: 22 additions & 3 deletions Reactor.OxygenFilter/Extensions.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Linq;
using System.Text;
using Mono.Cecil;
Expand All @@ -11,11 +12,29 @@ public static bool IsObfuscated(this string text)
return text.Length == 11 && text.All(char.IsUpper);
}

public static string GetSignature(this MethodDefinition methodDefinition)
public static string GetSignature(this MethodDefinition methodDefinition, Func<TypeDefinition, string> map = null)
{
map ??= provider => provider.FullName;

string MapIfResolved(TypeReference typeReference)
{
TypeDefinition resolved = null;

try
{
resolved = typeReference.Resolve();
}
catch
{
// ignored
}

return resolved != null ? map(resolved) : typeReference.FullName;
}

var sb = new StringBuilder();

sb.Append(methodDefinition.ReturnType.FullName);
sb.Append(MapIfResolved(methodDefinition.ReturnType));
sb.Append(" ");

sb.Append("(");
Expand All @@ -31,7 +50,7 @@ public static string GetSignature(this MethodDefinition methodDefinition)
if (parameterType is SentinelType)
sb.Append("...,");

sb.Append(parameterType.FullName);
sb.Append(MapIfResolved(parameterType));
}
}

Expand Down

0 comments on commit 81696bc

Please sign in to comment.