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

Commit

Permalink
Deobfuscate custom attributes on all members
Browse files Browse the repository at this point in the history
  • Loading branch information
js6pak committed Feb 7, 2021
1 parent d07cefd commit c7e3950
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 4 deletions.
1 change: 0 additions & 1 deletion Reactor.Greenhouse/Generation/TypeContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text.RegularExpressions;
using Mono.Cecil;
Expand Down
2 changes: 2 additions & 0 deletions Reactor.OxygenFilter.MSBuild/Deobfuscate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ public override bool Execute()
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 });
Expand Down
1 change: 1 addition & 0 deletions Reactor.OxygenFilter.MSBuild/GenerateReferences.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public override bool Execute()

if (skip)
{
Log.LogMessage("Skipping reference generation");
return true;
}

Expand Down
4 changes: 4 additions & 0 deletions Reactor.OxygenFilter.MSBuild/LoadMappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public override bool Execute()

if (File.Exists(Mappings))
{
Log.LogMessage("Loading mappings from " + Mappings);
Context.MappingsJson = File.ReadAllText(Mappings);
return true;
}
Expand All @@ -34,10 +35,13 @@ public override bool Execute()

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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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)" />
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.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>
Expand Down
13 changes: 12 additions & 1 deletion Reactor.OxygenFilter.MSBuild/Reobfuscate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,18 @@ public override bool Execute()
}
}

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)
{
Expand All @@ -111,7 +122,7 @@ void ReobfuscateType(TypeReference t)
}
}

foreach (var customAttribute in type.CustomAttributes)
foreach (var customAttribute in customAttributeProvider.CustomAttributes)
{
TypeReference lastType = null;

Expand Down

0 comments on commit c7e3950

Please sign in to comment.