Deobfuscate custom attributes on all members

This commit is contained in:
js6pak committed 2021-02-07 14:08:09 +01:00
1 parent d07cefd219
commit c7e3950c98
7 files changed
+33 -4

No files matched your search

@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using Mono.Cecil;
@@ -54,6 +54,8 @@ namespace Reactor.OxygenFilter.MSBuild
continue;
}
Log.LogMessage("Deobfuscating " + input);
using var stream = File.Open(input, FileMode.Open, FileAccess.Read, FileShare.Read);
using var moduleDefinition = ModuleDefinition.ReadModule(stream, new ReaderParameters { AssemblyResolver = resolver });
@@ -41,6 +41,7 @@ namespace Reactor.OxygenFilter.MSBuild
if (skip)
{
Log.LogMessage("Skipping reference generation");
return true;
}
@@ -20,6 +20,7 @@ namespace Reactor.OxygenFilter.MSBuild
if (File.Exists(Mappings))
{
Log.LogMessage("Loading mappings from " + Mappings);
Context.MappingsJson = File.ReadAllText(Mappings);
return true;
}
@@ -34,10 +35,13 @@ namespace Reactor.OxygenFilter.MSBuild
if (File.Exists(file))
{
Log.LogMessage("Loading mappings from " + file);
Context.MappingsJson = File.ReadAllText(file);
return true;
}
Log.LogMessage("Downloading mappings from " + Mappings);
var httpClient = new HttpClient();
var json = httpClient.GetStringAsync($"https://github.com/{repo}/releases/download/{version}/{GameVersion}.json").GetAwaiter().GetResult();
@@ -1,4 +1,4 @@
<Project TreatAsLocalProperty="TaskFolder;TaskAssembly">
<Project TreatAsLocalProperty="TaskFolder;TaskAssembly" InitialTargets="Validation">
<PropertyGroup>
<IsNetCoreApp Condition="$(MSBuildRuntimeType) == 'Core'">true</IsNetCoreApp>
<IsNetCoreApp Condition="$(IsNetCoreApp) == ''">false</IsNetCoreApp>
@@ -7,11 +7,23 @@
<TaskAssembly>$(MSBuildThisFileDirectory)..\lib\$(TaskFolder)\Reactor.OxygenFilter.MSBuild.dll</TaskAssembly>
</PropertyGroup>
<PropertyGroup Condition="$(GamePlatform) == ''">
<GamePlatform>Steam</GamePlatform>
</PropertyGroup>
<UsingTask TaskName="LoadMappings" AssemblyFile="$(TaskAssembly)" />
<UsingTask TaskName="GenerateReferences" AssemblyFile="$(TaskAssembly)" />
<UsingTask TaskName="Reobfuscate" AssemblyFile="$(TaskAssembly)" />
<UsingTask TaskName="Deobfuscate" AssemblyFile="$(TaskAssembly)" />
<Target Name="Validation">
<Error Condition=" !Exists('$(AmongUs)') "
Text="Couldn't find game path, make sure to set AmongUs environment variable" />
<Error Condition=" '$(GameVersion)' == '' "
Text="Game version is not set (make sure to set GamePlatform environment variable if you are using reactor template)" />
</Target>
<Target Name="WarnAboutTargetFramework" BeforeTargets="PrepareForBuild" Condition=" '$(TargetFramework)' != 'netstandard2.1' ">
<!-- TODO link to docs explaining why netstandard is better -->
<Warning Text="Your project is not targetting netstandard2.1, you probably want to change that." File="$(MSBuildProjectFullPath)" />
@@ -4,7 +4,7 @@
<LangVersion>latest</LangVersion>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Version>0.2.4</Version>
<Version>0.2.5</Version>
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/NuclearPowered/Reactor.OxygenFilter</RepositoryUrl>
<PackageLicenseExpression>LGPL-3.0-or-later</PackageLicenseExpression>
+12 -1
View File
@@ -94,7 +94,18 @@ namespace Reactor.OxygenFilter.MSBuild
}
}
var customAttributeProviders = new List<ICustomAttributeProvider>();
foreach (var type in moduleDefinition.GetAllTypes())
{
customAttributeProviders.Add(type);
customAttributeProviders.AddRange(type.Events);
customAttributeProviders.AddRange(type.Fields);
customAttributeProviders.AddRange(type.Methods);
customAttributeProviders.AddRange(type.Properties);
}
foreach (var customAttributeProvider in customAttributeProviders)
{
void ReobfuscateType(TypeReference t)
{
@@ -111,7 +122,7 @@ namespace Reactor.OxygenFilter.MSBuild
}
}
foreach (var customAttribute in type.CustomAttributes)
foreach (var customAttribute in customAttributeProvider.CustomAttributes)
{
TypeReference lastType = null;