Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
miso-xyz authored May 25, 2021
1 parent 5f996be commit ff73ecc
Show file tree
Hide file tree
Showing 5 changed files with 270 additions and 0 deletions.
160 changes: 160 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using dnlib.DotNet;
using dnlib.DotNet.Emit;
using dnlib.DotNet.Writer;

namespace SinUnfuscator
{
class Program
{
public static ModuleDefMD asm;
public static string path;

static void fixLengthCalls()
{
foreach (TypeDef type in asm.Types)
{
foreach (MethodDef methods in type.Methods)
{
if (!methods.HasBody) { continue; }
for (int x = 0; x < methods.Body.Instructions.Count; x++)
{
Instruction inst = methods.Body.Instructions[x];
if (inst.OpCode.Equals(OpCodes.Call))
{
if (inst.Operand.ToString().Contains("System.String::get_Length"))
{
int newLen = inst.Operand.ToString().Length;
methods.Body.Instructions[x - 1].OpCode = OpCodes.Ldc_I4;
methods.Body.Instructions[x - 1].Operand = newLen;
methods.Body.Instructions.Remove(inst);
}
}
}
}
}
}

static void removeJunk()
{
asm.EntryPoint.DeclaringType.Name = "Entrypoint";
for (int x_type = 0; x_type < asm.Types.Count; x_type++)
{
TypeDef type = asm.Types[x_type];
if (type.IsGlobalModuleType) { type.Name = "<Module>"; }
if (type.HasInterfaces)
{
bool wasInterfaceObf = false;
foreach (InterfaceImpl intrface in type.Interfaces)
{
if (intrface.Interface == type)
{
asm.Types.RemoveAt(x_type);
x_type--;
wasInterfaceObf = true;
break;
}
}
if (wasInterfaceObf) { continue; }
}
for (int x_methods = 0; x_methods < type.Methods.Count; x_methods++)
{
MethodDef methods = type.Methods[x_methods];
if (!methods.HasBody) { continue; }
methods.Body.KeepOldMaxStack = true;
for (int x_inst = 0; x_inst < methods.Body.Instructions.Count; x_inst++)
{
Instruction inst = methods.Body.Instructions[x_inst];
switch (inst.OpCode.Code)
{
case Code.Ret:
if (methods.Body.Instructions[x_inst - 1].OpCode.Equals(OpCodes.Ldc_I4) && methods.Body.Instructions[x_inst - 2].OpCode.Equals(OpCodes.Ldc_I4))
{
type.Methods.RemoveAt(x_methods);
x_methods--;
}
break;
case Code.Call:
if (inst.Operand.ToString().Contains("System.Convert::FromBase64String")) { methods.Name = "StringDecoder"; }
if (inst.Operand.ToString().Contains("<Module>::Initialize")) { methods.Name = ".cctor"; }
break;
}
}
}
if (!type.HasMethods) { asm.Types.RemoveAt(x_type); x_type--; }
}
}

static void fixStrings()
{
foreach (TypeDef type in asm.Types)
{
foreach (MethodDef methods in type.Methods)
{
if (!methods.HasBody) { continue; }
for (int x = 0; x < methods.Body.Instructions.Count; x++)
{
if (x + 1 >= methods.Body.Instructions.Count) { continue; }
Instruction inst = methods.Body.Instructions[x];
if (inst.OpCode.Equals(OpCodes.Ldstr) && methods.Body.Instructions[x + 1].OpCode.Equals(OpCodes.Call))
{
if (methods.Body.Instructions[x + 1].Operand.ToString().Contains("<Module>::StringDecoder"))
{
inst.Operand = Encoding.UTF8.GetString(Convert.FromBase64String(inst.Operand.ToString()));
methods.Body.Instructions.RemoveAt(x + 1);
}
}
}
}
}
}

static void disableProtections()
{
foreach (TypeDef type in asm.Types)
{
if (type.IsGlobalModuleType)
{
type.Methods.Clear();
}
}
}

static void Main(string[] args)
{
Console.Title = "SinUnfuscator";
Console.WriteLine();
Console.WriteLine(" SinUnfuscator by misonothx - SaintFuscator Deobfuscator");
Console.WriteLine(" |- https://github.com/miso-xyz/SinUnfuscator/");
Console.WriteLine();
path = args[0];
asm = ModuleDefMD.Load(args[0]);
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(" Removing Junk...");
removeJunk();
Console.WriteLine(" Decoding Strings...");
fixStrings();
Console.WriteLine(" Simplifying Length Calls...");
fixLengthCalls();
Console.WriteLine(" Removing Protections...");
disableProtections();
ModuleWriterOptions moduleWriterOptions = new ModuleWriterOptions(asm);
moduleWriterOptions.MetadataOptions.Flags |= MetadataFlags.PreserveAll;
moduleWriterOptions.Logger = DummyLogger.NoThrowInstance;
NativeModuleWriterOptions nativeModuleWriterOptions = new NativeModuleWriterOptions(asm, true);
nativeModuleWriterOptions.MetadataOptions.Flags |= MetadataFlags.PreserveAll;
nativeModuleWriterOptions.Logger = DummyLogger.NoThrowInstance;
if (asm.IsILOnly) { asm.Write(Path.GetFileNameWithoutExtension(path) + "-SinUnfuscator" + Path.GetExtension(path)); }
else { asm.NativeWrite(Path.GetFileNameWithoutExtension(path) + "-SinUnfuscator" + Path.GetExtension(path)); }
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine(" Successfully cleaned! (saved as '" + Path.GetFileNameWithoutExtension(path) + "-SinUnfuscator" + Path.GetExtension(path) + "')");
Console.ResetColor();
Console.WriteLine(" Press any key to exit...");
Console.ReadKey();
}
}
}
36 changes: 36 additions & 0 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("SinUnfuscator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SinUnfuscator")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("9025aba8-60df-40d4-804f-6538880714fe")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
67 changes: 67 additions & 0 deletions SinUnfuscator.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{BDA5D9C2-E6B1-44CC-B143-FB921188A13B}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>SinUnfuscator</RootNamespace>
<AssemblyName>SinUnfuscator</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<PlatformTarget>x86</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>ax_chara.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="dnlib, Version=1.6.0.0, Culture=neutral, PublicKeyToken=50e96378b6e77999, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>bin\Debug\dnlib.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="ax_chara.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
7 changes: 7 additions & 0 deletions SinUnfuscator.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<StartArguments>
</StartArguments>
</PropertyGroup>
</Project>
Binary file added ax_chara.ico
Binary file not shown.

0 comments on commit ff73ecc

Please sign in to comment.