├── VERSION ├── .gitattributes ├── ConfuserEx ├── Resources │ ├── CREDITS │ ├── New.png │ ├── Error.png │ ├── Open.png │ ├── Save.png │ ├── Tools.png │ ├── Decode.png │ ├── TeamLogo.png │ └── FontAwesome.otf ├── ConfuserEx.ico ├── App.xaml.cs ├── ViewModel │ ├── IViewModel.cs │ ├── UI │ │ ├── TabViewModel.cs │ │ └── AboutTabVM.cs │ ├── StringItem.cs │ ├── Project │ │ └── ProjectSettingVM.cs │ └── ViewModelBase.cs ├── Properties │ └── AssemblyInfo.cs ├── packages.config ├── EnumValuesExtension.cs ├── app.config ├── Views.xaml ├── InvertBoolConverter.cs ├── BrushToColorConverter.cs ├── BoolToVisibilityConverter.cs ├── Views │ ├── ProjectModuleView.xaml.cs │ ├── ProjectRuleView.xaml.cs │ ├── ProtectTabView.xaml │ └── ProjectTabAdvancedView.xaml.cs ├── App.xaml ├── CompComboBox.xaml.cs ├── ComponentConverter.cs ├── MainWindow.xaml.cs └── Skin.cs ├── Build ├── 7z.exe ├── Build.cmd ├── files.lst ├── UpdateVersion.csproj └── UpdateVersion.cs ├── ConfuserEx.snk ├── .gitmodules ├── additional ├── Icon.pdn ├── Icon16.pdn ├── Icon256.pdn ├── Icon32.pdn ├── Icon48.pdn ├── Icon64.pdn ├── ilspy.crproj └── pdn.crproj ├── deps └── Ookii.Dialogs.Wpf.dll ├── .vs └── Confuser2 │ └── DesignTimeBuild │ └── .dtbcache ├── Confuser.Protections ├── Resources │ ├── Mode.cs │ ├── IEncodeMode.cs │ ├── REContext.cs │ ├── ResourceProtection.cs │ ├── NormalMode.cs │ └── DynamicMode.cs ├── Constants │ ├── Mode.cs │ ├── EncodeElements.cs │ ├── IEncodeMode.cs │ ├── CEContext.cs │ ├── ConstantProtection.cs │ └── NormalMode.cs ├── Properties │ └── AssemblyInfo.cs ├── ControlFlow │ ├── IPredicate.cs │ ├── ManglerBase.cs │ ├── NormalPredicate.cs │ ├── ControlFlowProtection.cs │ └── ExpressionPredicate.cs ├── ReferenceProxy │ ├── IRPEncoding.cs │ ├── RPContext.cs │ ├── NormalEncoding.cs │ └── ReferenceProxyProtection.cs ├── AntiTamper │ ├── IModeHandler.cs │ ├── IKeyDeriver.cs │ ├── NormalDeriver.cs │ └── DynamicDeriver.cs ├── TypeScrambler │ ├── Scrambler │ │ ├── Analyzers │ │ │ ├── TypeRefAnalyzer.cs │ │ │ ├── MethodSpecAnalyzer.cs │ │ │ ├── ContextAnalyzer.cs │ │ │ ├── MethodDefAnalyzer.cs │ │ │ ├── MemberRefAnalyzer.cs │ │ │ └── ContextAnalyzerFactory.cs │ │ ├── Rewriter │ │ │ └── Instructions │ │ │ │ ├── TypeDefInstructionRewriter.cs │ │ │ │ ├── TypeRefInstructionRewriter.cs │ │ │ │ ├── MethodSpecInstructionRewriter.cs │ │ │ │ ├── MethodDefInstructionRewriter.cs │ │ │ │ ├── InstructionRewriter.cs │ │ │ │ └── InstructionRewriterFactory.cs │ │ ├── ScannedType.cs │ │ └── TypeRewriter.cs │ ├── TypeScrambleProtection.cs │ ├── ScramblePhase.cs │ └── TypeService.cs ├── Compress │ ├── IKeyDeriver.cs │ ├── DynamicDeriver.cs │ └── CompressorContext.cs └── AntiILDasmProtection.cs ├── .nuget └── NuGet.Config ├── Confuser.Core ├── Properties │ └── AssemblyInfo.cs ├── UnreachableException.cs ├── Protection.cs ├── ConfuserException.cs ├── Project │ ├── Patterns │ │ ├── NotOperator.cs │ │ ├── OrOperator.cs │ │ ├── AndOperator.cs │ │ ├── NameFunction.cs │ │ ├── FullNameFunction.cs │ │ ├── PatternExpression.cs │ │ ├── HasAttrFunction.cs │ │ ├── DeclTypeFunction.cs │ │ ├── ModuleFunction.cs │ │ ├── InheritsFunction.cs │ │ ├── NamespaceFunction.cs │ │ ├── LiteralExpression.cs │ │ ├── PatternFunction.cs │ │ ├── IsPublicFunction.cs │ │ ├── PatternOperator.cs │ │ ├── IsTypeFunction.cs │ │ ├── MemberTypeFunction.cs │ │ └── MatchFunction.cs │ └── InvalidPatternException.cs ├── LZMA │ ├── Compress │ │ └── LZ │ │ │ └── IMatchFinder.cs │ └── Common │ │ ├── OutBuffer.cs │ │ ├── CRC.cs │ │ └── InBuffer.cs ├── ProtectionPreset.cs ├── ProtectionTargets.cs ├── ProtectionSettings.cs ├── Services │ └── RuntimeService.cs ├── MarkerResult.cs ├── ConfuserComponent.cs ├── ModuleWriterListener.cs ├── ProtectionDependencyAttributes.cs ├── ProtectionPhase.cs ├── NullLogger.cs ├── API │ └── IDataStore.cs ├── ConfuserParameters.cs ├── ServiceRegistry.cs └── ModuleSorter.cs ├── Confuser.Renamer ├── Properties │ └── AssemblyInfo.cs ├── BAML │ ├── IBAMLReference.cs │ ├── BamlDocument.cs │ ├── BAMLPropertyReference.cs │ └── BAMLStringReference.cs ├── RenameMode.cs ├── INameReference.cs ├── IRenamer.cs ├── References │ ├── BAMLTypeReference.cs │ ├── MemberRefReference.cs │ ├── BAMLEnumReference.cs │ ├── CAMemberReference.cs │ ├── TypeRefReference.cs │ ├── StringTypeReference.cs │ ├── ResourceReference.cs │ ├── BAMLAttributeReference.cs │ ├── BAMLConverterMemberReference.cs │ ├── BAMLConverterTypeReference.cs │ └── BAMLPathTypeReference.cs ├── PostRenamePhase.cs ├── RickRoller.cs └── ReversibleRenamer.cs ├── Confuser.Runtime ├── Properties │ └── AssemblyInfo.cs ├── antinet │ ├── ABOUT │ └── HandleProcessCorruptedStateExceptionsAttribute.cs ├── AntiDebug.Antinet.cs ├── Mutation.cs ├── AntiDebug.Safe.cs └── AntiTamper.Normal.cs ├── Confuser.CLI └── Properties │ └── AssemblyInfo.cs ├── UnitTest ├── App.config ├── GenericTest.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs └── UnitTest.csproj ├── Confuser.DynCipher ├── AST │ ├── Statement.cs │ ├── VariableExpression.cs │ ├── ArrayIndexExpression.cs │ ├── Variable.cs │ ├── AssignmentStatement.cs │ ├── LiteralExpression.cs │ ├── LoopStatement.cs │ ├── StatementBlock.cs │ ├── UnaryOpExpression.cs │ ├── BinOpExpression.cs │ └── Expression.cs ├── Properties │ └── AssemblyInfo.cs ├── Elements │ ├── CryptoElement.cs │ ├── AddKey.cs │ ├── BinOp.cs │ ├── RotateBit.cs │ └── Swap.cs ├── DynCipherComponent.cs ├── DynCipherService.cs ├── Transforms │ ├── ExpansionTransform.cs │ ├── ConvertVariables.cs │ ├── NormalizeBinOpTransform.cs │ └── MulToShiftTransform.cs └── Generation │ └── CipherGenContext.cs ├── GlobalAssemblyInfo.Template.cs ├── appveyor.yml ├── .github └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── .gitignore ├── LICENSE └── docs └── DeclarativeObfuscation.txt /VERSION: -------------------------------------------------------------------------------- 1 | 1.0.0 -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.cs diff=csharp 2 | -------------------------------------------------------------------------------- /ConfuserEx/Resources/CREDITS: -------------------------------------------------------------------------------- 1 | Icons adapted from http://flaticons.net -------------------------------------------------------------------------------- /Build/7z.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/Build/7z.exe -------------------------------------------------------------------------------- /ConfuserEx.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/ConfuserEx.snk -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "dnlib"] 2 | path = dnlib 3 | url = https://github.com/yck1509/dnlib.git 4 | -------------------------------------------------------------------------------- /additional/Icon.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/additional/Icon.pdn -------------------------------------------------------------------------------- /additional/Icon16.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/additional/Icon16.pdn -------------------------------------------------------------------------------- /additional/Icon256.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/additional/Icon256.pdn -------------------------------------------------------------------------------- /additional/Icon32.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/additional/Icon32.pdn -------------------------------------------------------------------------------- /additional/Icon48.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/additional/Icon48.pdn -------------------------------------------------------------------------------- /additional/Icon64.pdn: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/additional/Icon64.pdn -------------------------------------------------------------------------------- /ConfuserEx/ConfuserEx.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/ConfuserEx/ConfuserEx.ico -------------------------------------------------------------------------------- /ConfuserEx/Resources/New.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/ConfuserEx/Resources/New.png -------------------------------------------------------------------------------- /deps/Ookii.Dialogs.Wpf.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/deps/Ookii.Dialogs.Wpf.dll -------------------------------------------------------------------------------- /ConfuserEx/Resources/Error.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/ConfuserEx/Resources/Error.png -------------------------------------------------------------------------------- /ConfuserEx/Resources/Open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/ConfuserEx/Resources/Open.png -------------------------------------------------------------------------------- /ConfuserEx/Resources/Save.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/ConfuserEx/Resources/Save.png -------------------------------------------------------------------------------- /ConfuserEx/Resources/Tools.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/ConfuserEx/Resources/Tools.png -------------------------------------------------------------------------------- /ConfuserEx/Resources/Decode.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/ConfuserEx/Resources/Decode.png -------------------------------------------------------------------------------- /ConfuserEx/Resources/TeamLogo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/ConfuserEx/Resources/TeamLogo.png -------------------------------------------------------------------------------- /ConfuserEx/Resources/FontAwesome.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/ConfuserEx/Resources/FontAwesome.otf -------------------------------------------------------------------------------- /.vs/Confuser2/DesignTimeBuild/.dtbcache: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/XenocodeRCE/neo-ConfuserEx/HEAD/.vs/Confuser2/DesignTimeBuild/.dtbcache -------------------------------------------------------------------------------- /ConfuserEx/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | 4 | namespace ConfuserEx { 5 | public partial class App : Application { } 6 | } -------------------------------------------------------------------------------- /Confuser.Protections/Resources/Mode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Protections.Resources { 4 | internal enum Mode { 5 | Normal, 6 | Dynamic 7 | } 8 | } -------------------------------------------------------------------------------- /ConfuserEx/ViewModel/IViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConfuserEx.ViewModel { 4 | public interface IViewModel { 5 | TModel Model { get; } 6 | } 7 | } -------------------------------------------------------------------------------- /Confuser.Protections/Constants/Mode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Protections.Constants { 4 | internal enum Mode { 5 | Normal, 6 | Dynamic, 7 | x86 8 | } 9 | } -------------------------------------------------------------------------------- /ConfuserEx/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | [assembly: AssemblyTitle("ConfuserEx")] 5 | [assembly: AssemblyDescription("ConfuserEx GUI")] -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Confuser.Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | [assembly: AssemblyTitle("ConfuserEx Core")] 5 | [assembly: AssemblyDescription("Core framework of ConfuserEx")] -------------------------------------------------------------------------------- /Confuser.Renamer/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | [assembly: AssemblyTitle("ConfuserEx Renamer")] 5 | [assembly: AssemblyDescription("Renaming analysis of ConfuserEx")] -------------------------------------------------------------------------------- /Confuser.Runtime/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | [assembly: AssemblyTitle("ConfuserEx Runtime")] 5 | [assembly: AssemblyDescription("Runtime library of ConfuserEx")] -------------------------------------------------------------------------------- /Confuser.CLI/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | [assembly: AssemblyTitle("ConfuserEx Command-line")] 5 | [assembly: AssemblyDescription("Command-line interface of ConfuserEx")] -------------------------------------------------------------------------------- /UnitTest/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Confuser.Protections/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | [assembly: AssemblyTitle("ConfuserEx Protections")] 5 | [assembly: AssemblyDescription("Protections and packers of ConfuserEx")] -------------------------------------------------------------------------------- /Confuser.DynCipher/AST/Statement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.DynCipher.AST { 4 | public abstract class Statement { 5 | public object Tag { get; set; } 6 | public abstract override string ToString(); 7 | } 8 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | 4 | [assembly: AssemblyTitle("ConfuserEx Dynamic Cipher Library")] 5 | [assembly: AssemblyDescription("Cipher generator of ConfuserEx")] -------------------------------------------------------------------------------- /Confuser.Renamer/BAML/IBAMLReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Renamer.BAML { 4 | internal interface IBAMLReference { 5 | bool CanRename(string oldName, string newName); 6 | void Rename(string oldName, string newName); 7 | } 8 | } -------------------------------------------------------------------------------- /ConfuserEx/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Confuser.Protections/Constants/EncodeElements.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Protections.Constants { 4 | [Flags] 5 | internal enum EncodeElements { 6 | Strings = 1, 7 | Numbers = 2, 8 | Primitive = 4, 9 | Initializers = 8 10 | } 11 | } -------------------------------------------------------------------------------- /Build/Build.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | %windir%\microsoft.net\framework\v4.0.30319\msbuild ..\Confuser2.sln /p:Configuration=Release "/p:Platform=Any CPU" 4 | 5 | IF %ERRORLEVEL% NEQ 0 GOTO err 6 | 7 | 7z a ConfuserEx_bin.zip -tzip @files.lst 8 | EXIT /B 0 9 | 10 | :err 11 | PAUSE 12 | EXIT /B 1 -------------------------------------------------------------------------------- /Confuser.Runtime/antinet/ABOUT: -------------------------------------------------------------------------------- 1 | antinet --- Code to prevent a managed .NET debugger/profiler from working 2 | Official site: https://bitbucket.org/0xd4d/antinet 3 | 4 | Written by de4dot@gmail.com 5 | Modified by Ki for use in ConfuserEx 6 | 7 | The source code in this folder is in the public domain. -------------------------------------------------------------------------------- /Confuser.DynCipher/AST/VariableExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.DynCipher.AST { 4 | public class VariableExpression : Expression { 5 | public Variable Variable { get; set; } 6 | 7 | public override string ToString() { 8 | return Variable.Name; 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /Confuser.Renamer/RenameMode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Renamer { 4 | public enum RenameMode { 5 | Empty = 0x0, 6 | Unicode = 0x1, 7 | ASCII = 0x2, 8 | Letters = 0x3, 9 | 10 | Decodable = 0x10, 11 | Sequential = 0x11, 12 | Reversible = 0x12, 13 | 14 | Debug = 0x20 15 | } 16 | } -------------------------------------------------------------------------------- /Confuser.Runtime/antinet/HandleProcessCorruptedStateExceptionsAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace System.Runtime.ExceptionServices { 4 | [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] 5 | internal class HandleProcessCorruptedStateExceptionsAttribute : Attribute { 6 | 7 | } 8 | } -------------------------------------------------------------------------------- /Confuser.Protections/ControlFlow/IPredicate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dnlib.DotNet.Emit; 4 | 5 | namespace Confuser.Protections.ControlFlow { 6 | internal interface IPredicate { 7 | void Init(CilBody body); 8 | void EmitSwitchLoad(IList instrs); 9 | int GetSwitchKey(int key); 10 | } 11 | } -------------------------------------------------------------------------------- /Confuser.Renamer/INameReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | 4 | namespace Confuser.Renamer { 5 | public interface INameReference { 6 | bool UpdateNameReference(ConfuserContext context, INameService service); 7 | 8 | bool ShouldCancelRename(); 9 | } 10 | 11 | public interface INameReference : INameReference { } 12 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/AST/ArrayIndexExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.DynCipher.AST { 4 | public class ArrayIndexExpression : Expression { 5 | public Expression Array { get; set; } 6 | public int Index { get; set; } 7 | 8 | public override string ToString() { 9 | return string.Format("{0}[{1}]", Array, Index); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/AST/Variable.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.DynCipher.AST { 4 | public class Variable { 5 | public Variable(string name) { 6 | Name = name; 7 | } 8 | 9 | public string Name { get; set; } 10 | public object Tag { get; set; } 11 | 12 | public override string ToString() { 13 | return Name; 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Confuser.Protections/ReferenceProxy/IRPEncoding.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | using dnlib.DotNet.Emit; 4 | 5 | namespace Confuser.Protections.ReferenceProxy { 6 | internal interface IRPEncoding { 7 | Instruction[] EmitDecode(MethodDef init, RPContext ctx, Instruction[] arg); 8 | int Encode(MethodDef init, RPContext ctx, int value); 9 | } 10 | } -------------------------------------------------------------------------------- /UnitTest/GenericTest.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UnitTest 8 | { 9 | internal class GenericTest where T : IEnumerable 10 | { 11 | public IEnumerable GetReverse(T input) => input.Reverse(); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /Confuser.DynCipher/AST/AssignmentStatement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.DynCipher.AST { 4 | public class AssignmentStatement : Statement { 5 | public Expression Target { get; set; } 6 | public Expression Value { get; set; } 7 | 8 | public override string ToString() { 9 | return string.Format("{0} = {1};", Target, Value); 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /ConfuserEx/ViewModel/UI/TabViewModel.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConfuserEx.ViewModel { 4 | public abstract class TabViewModel : ViewModelBase { 5 | protected TabViewModel(AppVM app, string header) { 6 | App = app; 7 | Header = header; 8 | } 9 | 10 | public AppVM App { get; private set; } 11 | public string Header { get; private set; } 12 | } 13 | } -------------------------------------------------------------------------------- /UnitTest/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace UnitTest 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | Console.Write("Hello o/"); 14 | Console.ReadKey(); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Confuser.Protections/AntiTamper/IModeHandler.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | 4 | namespace Confuser.Protections.AntiTamper { 5 | internal interface IModeHandler { 6 | void HandleInject(AntiTamperProtection parent, ConfuserContext context, ProtectionParameters parameters); 7 | void HandleMD(AntiTamperProtection parent, ConfuserContext context, ProtectionParameters parameters); 8 | } 9 | } -------------------------------------------------------------------------------- /Confuser.Protections/Resources/IEncodeMode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dnlib.DotNet; 4 | using dnlib.DotNet.Emit; 5 | 6 | namespace Confuser.Protections.Resources { 7 | internal interface IEncodeMode { 8 | IEnumerable EmitDecrypt(MethodDef init, REContext ctx, Local block, Local key); 9 | uint[] Encrypt(uint[] data, int offset, uint[] key); 10 | } 11 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/AST/LiteralExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.DynCipher.AST { 4 | public class LiteralExpression : Expression { 5 | public uint Value { get; set; } 6 | 7 | public static implicit operator LiteralExpression(uint val) { 8 | return new LiteralExpression { Value = val }; 9 | } 10 | 11 | public override string ToString() { 12 | return Value.ToString("x8") + "h"; 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /ConfuserEx/ViewModel/StringItem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace ConfuserEx.ViewModel { 4 | public class StringItem : IViewModel { 5 | public StringItem(string item) { 6 | Item = item; 7 | } 8 | 9 | public string Item { get; private set; } 10 | 11 | string IViewModel.Model { 12 | get { return Item; } 13 | } 14 | 15 | public override string ToString() { 16 | return Item; 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /Confuser.Runtime/AntiDebug.Antinet.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Runtime { 4 | static partial class AntiDebugAntinet { 5 | static void Initialize() { 6 | if (!InitializeAntiDebugger()) 7 | Environment.FailFast(null); 8 | InitializeAntiProfiler(); 9 | if (IsProfilerAttached) { 10 | Environment.FailFast(null); 11 | PreventActiveProfilerFromReceivingProfilingMessages(); 12 | } 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /ConfuserEx/EnumValuesExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows.Markup; 3 | 4 | namespace ConfuserEx { 5 | public class EnumValuesExtension : MarkupExtension { 6 | readonly Type enumType; 7 | 8 | public EnumValuesExtension(Type enumType) { 9 | this.enumType = enumType; 10 | } 11 | 12 | public override object ProvideValue(IServiceProvider serviceProvider) { 13 | return Enum.GetValues(enumType); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /Confuser.Core/UnreachableException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Core { 4 | /// 5 | /// The exception that is thrown when supposedly unreachable code is executed. 6 | /// 7 | public class UnreachableException : SystemException { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | public UnreachableException() : 12 | base("Unreachable code reached.") { } 13 | } 14 | } -------------------------------------------------------------------------------- /GlobalAssemblyInfo.Template.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | 3 | [assembly: AssemblyProduct("ConfuserEx")] 4 | [assembly: AssemblyCompany("Ki")] 5 | [assembly: AssemblyCopyright("Copyright (C) Ki 2014")] 6 | 7 | #if DEBUG 8 | 9 | [assembly: AssemblyConfiguration("Debug")] 10 | #else 11 | 12 | [assembly: AssemblyConfiguration("Release")] 13 | #endif 14 | 15 | [assembly: AssemblyVersion("{{VER}}")] 16 | [assembly: AssemblyFileVersion("{{VER}}")] 17 | [assembly: AssemblyInformationalVersion("{{TAG}}")] -------------------------------------------------------------------------------- /Confuser.Renamer/IRenamer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using dnlib.DotNet; 4 | 5 | namespace Confuser.Renamer { 6 | public interface IRenamer { 7 | void Analyze(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def); 8 | void PreRename(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def); 9 | void PostRename(ConfuserContext context, INameService service, ProtectionParameters parameters, IDnlibDef def); 10 | } 11 | } -------------------------------------------------------------------------------- /Confuser.Protections/Constants/IEncodeMode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dnlib.DotNet; 4 | using dnlib.DotNet.Emit; 5 | 6 | namespace Confuser.Protections.Constants { 7 | internal interface IEncodeMode { 8 | IEnumerable EmitDecrypt(MethodDef init, CEContext ctx, Local block, Local key); 9 | uint[] Encrypt(uint[] data, int offset, uint[] key); 10 | 11 | object CreateDecoder(MethodDef decoder, CEContext ctx); 12 | uint Encode(object data, CEContext ctx, uint id); 13 | } 14 | } -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Analyzers/TypeRefAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Confuser.Protections.TypeScramble.Scrambler.Analyzers { 9 | class TypeRefAnalyzer : ContextAnalyzer { 10 | public override void Process(ScannedMethod m, TypeRef o) { 11 | 12 | m.RegisterGeneric(o.ToTypeSig()); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Confuser.DynCipher/AST/LoopStatement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | 4 | namespace Confuser.DynCipher.AST { 5 | // i.e. for loop 6 | public class LoopStatement : StatementBlock { 7 | public int Begin { get; set; } 8 | public int Limit { get; set; } 9 | 10 | public override string ToString() { 11 | var ret = new StringBuilder(); 12 | ret.AppendFormat("for (int i = {0}; i < {1}; i++)", Begin, Limit); 13 | ret.AppendLine(); 14 | ret.Append(base.ToString()); 15 | return ret.ToString(); 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /Confuser.Renamer/BAML/BamlDocument.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Confuser.Renamer.BAML { 5 | internal class BamlDocument : List { 6 | public string DocumentName { get; set; } 7 | 8 | public string Signature { get; set; } 9 | public BamlVersion ReaderVersion { get; set; } 10 | public BamlVersion UpdaterVersion { get; set; } 11 | public BamlVersion WriterVersion { get; set; } 12 | 13 | public struct BamlVersion { 14 | public ushort Major; 15 | public ushort Minor; 16 | } 17 | } 18 | } -------------------------------------------------------------------------------- /ConfuserEx/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ConfuserEx/Views.xaml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Confuser.Core/Protection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Core { 4 | /// 5 | /// Base class of Confuser protections. 6 | /// 7 | /// 8 | /// A parameterless constructor must exists in derived classes to enable plugin discovery. 9 | /// 10 | public abstract class Protection : ConfuserComponent { 11 | /// 12 | /// Gets the preset this protection is in. 13 | /// 14 | /// The protection's preset. 15 | public abstract ProtectionPreset Preset { get; } 16 | } 17 | } -------------------------------------------------------------------------------- /Confuser.Protections/Compress/IKeyDeriver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Confuser.Core; 4 | using Confuser.Core.Services; 5 | using dnlib.DotNet; 6 | using dnlib.DotNet.Emit; 7 | 8 | namespace Confuser.Protections.Compress { 9 | internal enum Mode { 10 | Normal, 11 | Dynamic 12 | } 13 | 14 | internal interface IKeyDeriver { 15 | void Init(ConfuserContext ctx, RandomGenerator random); 16 | uint[] DeriveKey(uint[] a, uint[] b); 17 | IEnumerable EmitDerivation(MethodDef method, ConfuserContext ctx, Local dst, Local src); 18 | } 19 | } -------------------------------------------------------------------------------- /Confuser.Protections/AntiTamper/IKeyDeriver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Confuser.Core; 4 | using Confuser.Core.Services; 5 | using dnlib.DotNet; 6 | using dnlib.DotNet.Emit; 7 | 8 | namespace Confuser.Protections.AntiTamper { 9 | internal enum Mode { 10 | Normal, 11 | Dynamic 12 | } 13 | 14 | internal interface IKeyDeriver { 15 | void Init(ConfuserContext ctx, RandomGenerator random); 16 | uint[] DeriveKey(uint[] a, uint[] b); 17 | IEnumerable EmitDerivation(MethodDef method, ConfuserContext ctx, Local dst, Local src); 18 | } 19 | } -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | version: '{build}' 2 | image: Visual Studio 2017 3 | configuration: Release 4 | platform: Any CPU 5 | skip_commits: 6 | files: 7 | - doc/* 8 | - readme.md 9 | - license.md 10 | 11 | nuget: 12 | disable_publish_on_pr: true 13 | 14 | install: 15 | - cmd: git submodule update --init --recursive 16 | 17 | before_build: 18 | - cmd: msbuild Confuser2.sln /t:Restore /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" 19 | 20 | build: 21 | project: Confuser2.sln 22 | verbosity: minimal 23 | 24 | artifacts: 25 | - path: Release/bin 26 | name: ConfuserEx 27 | -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Analyzers/MethodSpecAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Confuser.Protections.TypeScramble.Scrambler.Analyzers { 9 | class MethodSpecAnalyzer : ContextAnalyzer { 10 | public override void Process(ScannedMethod m, MethodSpec o) { 11 | 12 | foreach (var t in o.GenericInstMethodSig.GenericArguments) { 13 | m.RegisterGeneric(t); 14 | } 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /Confuser.DynCipher/AST/StatementBlock.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace Confuser.DynCipher.AST { 6 | public class StatementBlock : Statement { 7 | public StatementBlock() { 8 | Statements = new List(); 9 | } 10 | 11 | public IList Statements { get; private set; } 12 | 13 | public override string ToString() { 14 | var sb = new StringBuilder(); 15 | sb.AppendLine("{"); 16 | foreach (Statement i in Statements) 17 | sb.AppendLine(i.ToString()); 18 | sb.AppendLine("}"); 19 | return sb.ToString(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/AST/UnaryOpExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.DynCipher.AST { 4 | public enum UnaryOps { 5 | Not, 6 | Negate 7 | } 8 | 9 | public class UnaryOpExpression : Expression { 10 | public Expression Value { get; set; } 11 | public UnaryOps Operation { get; set; } 12 | 13 | public override string ToString() { 14 | string op; 15 | switch (Operation) { 16 | case UnaryOps.Not: 17 | op = "~"; 18 | break; 19 | case UnaryOps.Negate: 20 | op = "-"; 21 | break; 22 | default: 23 | throw new Exception(); 24 | } 25 | return op + Value; 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/Elements/CryptoElement.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core.Services; 3 | using Confuser.DynCipher.Generation; 4 | 5 | namespace Confuser.DynCipher.Elements { 6 | internal abstract class CryptoElement { 7 | public CryptoElement(int count) { 8 | DataCount = count; 9 | DataIndexes = new int[count]; 10 | } 11 | 12 | public int DataCount { get; private set; } 13 | public int[] DataIndexes { get; private set; } 14 | 15 | public abstract void Initialize(RandomGenerator random); 16 | public abstract void Emit(CipherGenContext context); 17 | public abstract void EmitInverse(CipherGenContext context); 18 | } 19 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | 5 | --- 6 | 7 | **Is your feature request related to a problem? Please describe.** 8 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 9 | 10 | **Describe the solution you'd like** 11 | A clear and concise description of what you want to happen. 12 | 13 | **Describe alternatives you've considered** 14 | A clear and concise description of any alternative solutions or features you've considered. 15 | 16 | **Additional context** 17 | Add any other context or screenshots about the feature request here. 18 | -------------------------------------------------------------------------------- /Confuser.Protections/ControlFlow/ManglerBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dnlib.DotNet.Emit; 4 | 5 | namespace Confuser.Protections.ControlFlow { 6 | internal abstract class ManglerBase { 7 | protected static IEnumerable GetAllBlocks(ScopeBlock scope) { 8 | foreach (BlockBase child in scope.Children) { 9 | if (child is InstrBlock) 10 | yield return (InstrBlock)child; 11 | else { 12 | foreach (InstrBlock block in GetAllBlocks((ScopeBlock)child)) 13 | yield return block; 14 | } 15 | } 16 | } 17 | 18 | public abstract void Mangle(CilBody body, ScopeBlock root, CFContext ctx); 19 | } 20 | } -------------------------------------------------------------------------------- /Confuser.Core/ConfuserException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Core { 4 | /// 5 | /// The exception that is thrown when a handled error occurred during the protection process. 6 | /// 7 | public class ConfuserException : Exception { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | /// The inner exception, or null if no exception is associated with the error. 12 | public ConfuserException(Exception innerException) 13 | : base("Exception occurred during the protection process.", innerException) { } 14 | } 15 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/NotOperator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// The NOT operator. 7 | /// 8 | public class NotOperator : PatternOperator { 9 | internal const string OpName = "not"; 10 | 11 | /// 12 | public override string Name { 13 | get { return OpName; } 14 | } 15 | 16 | /// 17 | public override bool IsUnary { 18 | get { return true; } 19 | } 20 | 21 | /// 22 | public override object Evaluate(IDnlibDef definition) { 23 | return !(bool)OperandA.Evaluate(definition); 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /Confuser.Protections/Resources/REContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using Confuser.Core.Services; 4 | using Confuser.DynCipher; 5 | using Confuser.Renamer; 6 | using dnlib.DotNet; 7 | 8 | namespace Confuser.Protections.Resources { 9 | internal class REContext { 10 | public ConfuserContext Context; 11 | 12 | public FieldDef DataField; 13 | public TypeDef DataType; 14 | public IDynCipherService DynCipher; 15 | public MethodDef InitMethod; 16 | public IMarkerService Marker; 17 | 18 | public Mode Mode; 19 | 20 | public IEncodeMode ModeHandler; 21 | public ModuleDef Module; 22 | public INameService Name; 23 | public RandomGenerator Random; 24 | } 25 | } -------------------------------------------------------------------------------- /Build/files.lst: -------------------------------------------------------------------------------- 1 | ..\Release\bin\Confuser.CLI.exe 2 | ..\Release\bin\Confuser.CLI.pdb 3 | ..\Release\bin\Confuser.Core.* 4 | ..\Release\bin\Confuser.DynCipher.* 5 | ..\Release\bin\Confuser.Protections.* 6 | ..\Release\bin\Confuser.Renamer.* 7 | ..\Release\bin\Confuser.Runtime.* 8 | ..\Release\bin\dnlib.* 9 | ..\Release\bin\ConfuserEx.exe 10 | ..\Release\bin\ConfuserEx.exe.config 11 | ..\Release\bin\ConfuserEx.pdb 12 | ..\Release\bin\System.Threading.dll 13 | ..\Release\bin\GalaSoft.MvvmLight.Extras.WPF4.dll 14 | ..\Release\bin\GalaSoft.MvvmLight.WPF4.dll 15 | ..\Release\bin\Microsoft.Practices.ServiceLocation.dll 16 | ..\Release\bin\Ookii.Dialogs.Wpf.dll 17 | ..\Release\bin\System.Windows.Interactivity.dll -------------------------------------------------------------------------------- /Confuser.Renamer/References/BAMLTypeReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using Confuser.Renamer.BAML; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Renamer.References { 7 | internal class BAMLTypeReference : INameReference { 8 | readonly TypeInfoRecord rec; 9 | readonly TypeSig sig; 10 | 11 | public BAMLTypeReference(TypeSig sig, TypeInfoRecord rec) { 12 | this.sig = sig; 13 | this.rec = rec; 14 | } 15 | 16 | public bool UpdateNameReference(ConfuserContext context, INameService service) { 17 | rec.TypeFullName = sig.ReflectionFullName; 18 | return true; 19 | } 20 | 21 | public bool ShouldCancelRename() { 22 | return false; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Confuser.Renamer/References/MemberRefReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using dnlib.DotNet; 4 | 5 | namespace Confuser.Renamer.References { 6 | public class MemberRefReference : INameReference { 7 | readonly IDnlibDef memberDef; 8 | readonly MemberRef memberRef; 9 | 10 | public MemberRefReference(MemberRef memberRef, IDnlibDef memberDef) { 11 | this.memberRef = memberRef; 12 | this.memberDef = memberDef; 13 | } 14 | 15 | public bool UpdateNameReference(ConfuserContext context, INameService service) { 16 | memberRef.Name = memberDef.Name; 17 | return true; 18 | } 19 | 20 | public bool ShouldCancelRename() { 21 | return false; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Confuser.Renamer/References/BAMLEnumReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using Confuser.Renamer.BAML; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Renamer.References { 7 | internal class BAMLEnumReference : INameReference { 8 | readonly FieldDef enumField; 9 | readonly PropertyRecord rec; 10 | 11 | public BAMLEnumReference(FieldDef enumField, PropertyRecord rec) { 12 | this.enumField = enumField; 13 | this.rec = rec; 14 | } 15 | 16 | public bool UpdateNameReference(ConfuserContext context, INameService service) { 17 | rec.Value = enumField.Name; 18 | return true; 19 | } 20 | 21 | public bool ShouldCancelRename() { 22 | return false; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Confuser.Renamer/References/CAMemberReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using dnlib.DotNet; 4 | 5 | namespace Confuser.Renamer.References { 6 | internal class CAMemberReference : INameReference { 7 | readonly IDnlibDef definition; 8 | readonly CANamedArgument namedArg; 9 | 10 | public CAMemberReference(CANamedArgument namedArg, IDnlibDef definition) { 11 | this.namedArg = namedArg; 12 | this.definition = definition; 13 | } 14 | 15 | public bool UpdateNameReference(ConfuserContext context, INameService service) { 16 | namedArg.Name = definition.Name; 17 | return true; 18 | } 19 | 20 | public bool ShouldCancelRename() { 21 | return false; 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /Confuser.Renamer/References/TypeRefReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using dnlib.DotNet; 4 | 5 | namespace Confuser.Renamer.References { 6 | public class TypeRefReference : INameReference { 7 | readonly TypeDef typeDef; 8 | readonly TypeRef typeRef; 9 | 10 | public TypeRefReference(TypeRef typeRef, TypeDef typeDef) { 11 | this.typeRef = typeRef; 12 | this.typeDef = typeDef; 13 | } 14 | 15 | public bool UpdateNameReference(ConfuserContext context, INameService service) { 16 | typeRef.Namespace = typeDef.Namespace; 17 | typeRef.Name = typeDef.Name; 18 | return true; 19 | } 20 | 21 | public bool ShouldCancelRename() { 22 | return false; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | 5 | --- 6 | 7 | **Describe the bug** 8 | A clear and concise description of what the bug is. 9 | 10 | **To Reproduce** 11 | Steps to reproduce the behavior: 12 | 1. Go to '...' 13 | 2. Click on '....' 14 | 3. Scroll down to '....' 15 | 4. See error 16 | 17 | **Expected behavior** 18 | A clear and concise description of what you expected to happen. 19 | 20 | **Screenshots** 21 | If applicable, add screenshots to help explain your problem. 22 | 23 | **File (optional)** 24 | Either share a link to download the file or e-mail it to me. 25 | 26 | 27 | **Additional context** 28 | Add any other context about the problem here. 29 | -------------------------------------------------------------------------------- /Confuser.Core/LZMA/Compress/LZ/IMatchFinder.cs: -------------------------------------------------------------------------------- 1 | // IMatchFinder.cs 2 | 3 | using System; 4 | using System.IO; 5 | 6 | namespace SevenZip.Compression.LZ { 7 | internal interface IInWindowStream { 8 | 9 | void SetStream(Stream inStream); 10 | void Init(); 11 | void ReleaseStream(); 12 | Byte GetIndexByte(Int32 index); 13 | UInt32 GetMatchLen(Int32 index, UInt32 distance, UInt32 limit); 14 | UInt32 GetNumAvailableBytes(); 15 | 16 | } 17 | 18 | internal interface IMatchFinder : IInWindowStream { 19 | 20 | void Create(UInt32 historySize, UInt32 keepAddBufferBefore, 21 | UInt32 matchMaxLen, UInt32 keepAddBufferAfter); 22 | 23 | UInt32 GetMatches(UInt32[] distances); 24 | void Skip(UInt32 num); 25 | 26 | } 27 | } -------------------------------------------------------------------------------- /Confuser.Renamer/References/StringTypeReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using dnlib.DotNet; 4 | using dnlib.DotNet.Emit; 5 | 6 | namespace Confuser.Renamer.References { 7 | public class StringTypeReference : INameReference { 8 | readonly Instruction reference; 9 | readonly TypeDef typeDef; 10 | 11 | public StringTypeReference(Instruction reference, TypeDef typeDef) { 12 | this.reference = reference; 13 | this.typeDef = typeDef; 14 | } 15 | 16 | public bool UpdateNameReference(ConfuserContext context, INameService service) { 17 | reference.Operand = typeDef.ReflectionFullName; 18 | return true; 19 | } 20 | 21 | public bool ShouldCancelRename() { 22 | return false; 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/OrOperator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// The OR operator. 7 | /// 8 | public class OrOperator : PatternOperator { 9 | internal const string OpName = "or"; 10 | 11 | /// 12 | public override string Name { 13 | get { return OpName; } 14 | } 15 | 16 | /// 17 | public override bool IsUnary { 18 | get { return false; } 19 | } 20 | 21 | /// 22 | public override object Evaluate(IDnlibDef definition) { 23 | var a = (bool)OperandA.Evaluate(definition); 24 | if (a) return true; 25 | return (bool)OperandB.Evaluate(definition); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /ConfuserEx/InvertBoolConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Globalization; 4 | using System.Windows.Data; 5 | 6 | namespace ConfuserEx { 7 | internal class InvertBoolConverter : IValueConverter { 8 | public static readonly InvertBoolConverter Instance = new InvertBoolConverter(); 9 | InvertBoolConverter() { } 10 | 11 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { 12 | Debug.Assert(value is bool); 13 | Debug.Assert(targetType == typeof(bool)); 14 | return !(bool)value; 15 | } 16 | 17 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { 18 | throw new NotSupportedException(); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/AndOperator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// The AND operator. 7 | /// 8 | public class AndOperator : PatternOperator { 9 | internal const string OpName = "and"; 10 | 11 | /// 12 | public override string Name { 13 | get { return OpName; } 14 | } 15 | 16 | /// 17 | public override bool IsUnary { 18 | get { return false; } 19 | } 20 | 21 | /// 22 | public override object Evaluate(IDnlibDef definition) { 23 | var a = (bool)OperandA.Evaluate(definition); 24 | if (!a) return false; 25 | return (bool)OperandB.Evaluate(definition); 26 | } 27 | } 28 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/NameFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// A function that compare the name of definition. 7 | /// 8 | public class NameFunction : PatternFunction { 9 | internal const string FnName = "name"; 10 | 11 | /// 12 | public override string Name { 13 | get { return FnName; } 14 | } 15 | 16 | /// 17 | public override int ArgumentCount { 18 | get { return 1; } 19 | } 20 | 21 | /// 22 | public override object Evaluate(IDnlibDef definition) { 23 | object name = Arguments[0].Evaluate(definition); 24 | return definition.Name == name.ToString(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /ConfuserEx/BrushToColorConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Globalization; 3 | using System.Windows.Data; 4 | using System.Windows.Media; 5 | 6 | namespace ConfuserEx { 7 | public class BrushToColorConverter : IValueConverter { 8 | public static readonly BrushToColorConverter Instance = new BrushToColorConverter(); 9 | BrushToColorConverter() { } 10 | 11 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { 12 | var brush = value as SolidColorBrush; 13 | if (brush != null) 14 | return brush.Color; 15 | return null; 16 | } 17 | 18 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { 19 | throw new NotImplementedException(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /Confuser.Core/ProtectionPreset.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Core { 4 | /// 5 | /// Various presets of protections. 6 | /// 7 | public enum ProtectionPreset { 8 | /// The protection does not belong to any preset. 9 | None = 0, 10 | 11 | /// The protection provides basic security. 12 | Minimum = 1, 13 | 14 | /// The protection provides normal security for public release. 15 | Normal = 2, 16 | 17 | /// The protection provides better security with observable performance impact. 18 | Aggressive = 3, 19 | 20 | /// The protection provides strongest security with possible incompatibility. 21 | Maximum = 4 22 | } 23 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/FullNameFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// A function that compare the full name of definition. 7 | /// 8 | public class FullNameFunction : PatternFunction { 9 | internal const string FnName = "full-name"; 10 | 11 | /// 12 | public override string Name { 13 | get { return FnName; } 14 | } 15 | 16 | /// 17 | public override int ArgumentCount { 18 | get { return 1; } 19 | } 20 | 21 | /// 22 | public override object Evaluate(IDnlibDef definition) { 23 | object name = Arguments[0].Evaluate(definition); 24 | return definition.FullName == name.ToString(); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Confuser.Renamer/References/ResourceReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using dnlib.DotNet; 4 | 5 | namespace Confuser.Renamer.References { 6 | internal class ResourceReference : INameReference { 7 | readonly string format; 8 | readonly Resource resource; 9 | readonly TypeDef typeDef; 10 | 11 | public ResourceReference(Resource resource, TypeDef typeDef, string format) { 12 | this.resource = resource; 13 | this.typeDef = typeDef; 14 | this.format = format; 15 | } 16 | 17 | public bool UpdateNameReference(ConfuserContext context, INameService service) { 18 | resource.Name = string.Format(format, typeDef.ReflectionFullName); 19 | return true; 20 | } 21 | 22 | public bool ShouldCancelRename() { 23 | return false; 24 | } 25 | } 26 | } -------------------------------------------------------------------------------- /ConfuserEx/ViewModel/UI/AboutTabVM.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Linq; 4 | using System.Windows.Input; 5 | using System.Windows.Media.Imaging; 6 | using GalaSoft.MvvmLight.Command; 7 | 8 | namespace ConfuserEx.ViewModel { 9 | internal class AboutTabVM : TabViewModel { 10 | public AboutTabVM(AppVM app) 11 | : base(app, "About") { 12 | var decoder = new IconBitmapDecoder(new Uri("pack://application:,,,/ConfuserEx.ico"), BitmapCreateOptions.DelayCreation, BitmapCacheOption.OnDemand); 13 | 14 | Icon = decoder.Frames.First(frame => frame.Width == 64); 15 | } 16 | 17 | public ICommand LaunchBrowser { 18 | get { return new RelayCommand(site => Process.Start(site)); } 19 | } 20 | 21 | public BitmapSource Icon { get; private set; } 22 | } 23 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/PatternExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dnlib.DotNet; 4 | 5 | namespace Confuser.Core.Project.Patterns { 6 | /// 7 | /// A pattern expression. 8 | /// 9 | public abstract class PatternExpression { 10 | /// 11 | /// Evaluates the expression on the specified definition. 12 | /// 13 | /// The definition. 14 | /// The result value. 15 | public abstract object Evaluate(IDnlibDef definition); 16 | 17 | /// 18 | /// Serializes the expression into tokens. 19 | /// 20 | /// The output list of tokens. 21 | public abstract void Serialize(IList tokens); 22 | } 23 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/HasAttrFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// A function that indicate whether the item has the given custom attribute. 7 | /// 8 | public class HasAttrFunction : PatternFunction { 9 | internal const string FnName = "has-attr"; 10 | 11 | /// 12 | public override string Name { 13 | get { return FnName; } 14 | } 15 | 16 | /// 17 | public override int ArgumentCount { 18 | get { return 1; } 19 | } 20 | 21 | /// 22 | public override object Evaluate(IDnlibDef definition) { 23 | string attrName = Arguments[0].Evaluate(definition).ToString(); 24 | return definition.CustomAttributes.IsDefined(attrName); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Analyzers/ContextAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace Confuser.Protections.TypeScramble.Scrambler.Analyzers { 8 | public abstract class ContextAnalyzer { 9 | 10 | public abstract Type TargetType(); 11 | 12 | public abstract void ProcessOperand(ScannedMethod m, object o); 13 | } 14 | 15 | 16 | public abstract class ContextAnalyzer : ContextAnalyzer { 17 | public override Type TargetType() => typeof(T); 18 | public abstract void Process(ScannedMethod m, T o); 19 | public override void ProcessOperand(ScannedMethod m, object o) { 20 | Process(m, (T)o); 21 | } 22 | 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /Confuser.Protections/ControlFlow/NormalPredicate.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dnlib.DotNet.Emit; 4 | 5 | namespace Confuser.Protections.ControlFlow { 6 | internal class NormalPredicate : IPredicate { 7 | readonly CFContext ctx; 8 | bool inited; 9 | int xorKey; 10 | 11 | public NormalPredicate(CFContext ctx) { 12 | this.ctx = ctx; 13 | } 14 | 15 | public void Init(CilBody body) { 16 | if (inited) 17 | return; 18 | 19 | xorKey = ctx.Random.NextInt32(); 20 | inited = true; 21 | } 22 | 23 | public void EmitSwitchLoad(IList instrs) { 24 | instrs.Add(Instruction.Create(OpCodes.Ldc_I4, xorKey)); 25 | instrs.Add(Instruction.Create(OpCodes.Xor)); 26 | } 27 | 28 | public int GetSwitchKey(int key) { 29 | return key ^ xorKey; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /ConfuserEx/BoolToVisibilityConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Globalization; 4 | using System.Windows; 5 | using System.Windows.Data; 6 | 7 | namespace ConfuserEx { 8 | internal class BoolToVisibilityConverter : IValueConverter { 9 | public static readonly BoolToVisibilityConverter Instance = new BoolToVisibilityConverter(); 10 | BoolToVisibilityConverter() { } 11 | 12 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { 13 | Debug.Assert(value is bool); 14 | Debug.Assert(targetType == typeof(Visibility)); 15 | return (bool)value ? Visibility.Visible : Visibility.Collapsed; 16 | } 17 | 18 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { 19 | throw new NotSupportedException(); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | #ignore thumbnails created by windows 3 | Thumbs.db 4 | #Ignore files build by Visual Studio 5 | *.obj 6 | *.exe 7 | *.pdb 8 | *.user 9 | *.aps 10 | *.pch 11 | *.vspscc 12 | *_i.c 13 | *_p.c 14 | *.ncb 15 | *.suo 16 | *.tlb 17 | *.tlh 18 | *.bak 19 | *.cache 20 | *.ilk 21 | *.log 22 | [Bb]in 23 | [Dd]ebug*/ 24 | *.lib 25 | *.sbr 26 | obj/ 27 | [Rr]elease*/ 28 | _ReSharper*/ 29 | [Tt]est[Rr]esult* 30 | 31 | !packages/*/build/ 32 | packages/ 33 | /Confuser.Test 34 | *.sln.* 35 | gh-pages/ 36 | GlobalAssemblyInfo.cs 37 | /Build/*.zip 38 | !Build/7z.exe 39 | .vs/Confuser2/v15/Server/sqlite3/db.lock 40 | .vs/Confuser2/v15/Server/sqlite3/storage.ide 41 | .vs/Confuser2/v15/Server/sqlite3/storage.ide-shm 42 | .vs/Confuser2/v15/Server/sqlite3/storage.ide-wal 43 | dbg/dbg.csproj 44 | dbg/Program.cs 45 | dbg/app.config 46 | dbg/Properties/AssemblyInfo.cs 47 | Confuser2.sln 48 | -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Rewriter/Instructions/TypeDefInstructionRewriter.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using dnlib.DotNet.Emit; 8 | 9 | namespace Confuser.Protections.TypeScramble.Scrambler.Rewriter.Instructions { 10 | class TypeDefInstructionRewriter : InstructionRewriter { 11 | public override void ProcessOperand(TypeService service, MethodDef method, IList body, ref int index, TypeDef operand) { 12 | ScannedItem t = service.GetItem(operand.MDToken); 13 | if (t == null) { 14 | return; 15 | } 16 | body[index].Operand = new TypeSpecUser(t.CreateGenericTypeSig(service.GetItem(method.DeclaringType.MDToken))); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Rewriter/Instructions/TypeRefInstructionRewriter.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using dnlib.DotNet.Emit; 8 | 9 | namespace Confuser.Protections.TypeScramble.Scrambler.Rewriter.Instructions { 10 | class TypeRefInstructionRewriter : InstructionRewriter { 11 | public override void ProcessOperand(TypeService service, MethodDef method, IList body, ref int index, TypeRef operand) { 12 | ScannedItem current = service.GetItem(method.MDToken); 13 | if (current == null) { 14 | return; 15 | } 16 | 17 | body[index].Operand = new TypeSpecUser(current.ConvertToGenericIfAvalible(operand.ToTypeSig())); 18 | 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Analyzers/MethodDefAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Confuser.Protections.TypeScramble.Scrambler.Analyzers { 9 | class MethodDefAnalyzer : ContextAnalyzer { 10 | private TypeService service; 11 | 12 | public MethodDefAnalyzer(TypeService _service) { 13 | service = _service; 14 | } 15 | public override void Process(ScannedMethod m, MethodDef o) { 16 | var sc = service.GetItem(o.MDToken) as ScannedMethod; 17 | if(sc != null) { 18 | 19 | foreach (var regTypes in sc.TrueTypes) { 20 | m.RegisterGeneric(regTypes); 21 | } 22 | } 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Analyzers/MemberRefAnalyzer.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Confuser.Protections.TypeScramble.Scrambler.Analyzers { 9 | class MemberRefAnalyzer : ContextAnalyzer { 10 | public override void Process(ScannedMethod m, MemberRef o) { 11 | 12 | TypeSig sig = null; 13 | 14 | if (o.Class is TypeRef) { 15 | sig = (o.Class as TypeRef)?.ToTypeSig(); 16 | 17 | } 18 | 19 | if (o.Class is TypeSpec) { 20 | sig = (o.Class as TypeSpec)?.ToTypeSig(); 21 | } 22 | if (sig != null) { 23 | m.RegisterGeneric(sig); 24 | } 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Confuser.DynCipher/DynCipherComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | 4 | namespace Confuser.DynCipher { 5 | internal class DynCipherComponent : ConfuserComponent { 6 | public const string _ServiceId = "Confuser.DynCipher"; 7 | 8 | public override string Name { 9 | get { return "Dynamic Cipher"; } 10 | } 11 | 12 | public override string Description { 13 | get { return "Provides dynamic cipher generation services."; } 14 | } 15 | 16 | public override string Id { 17 | get { return _ServiceId; } 18 | } 19 | 20 | public override string FullId { 21 | get { return _ServiceId; } 22 | } 23 | 24 | protected override void Initialize(ConfuserContext context) { 25 | context.Registry.RegisterService(_ServiceId, typeof(IDynCipherService), new DynCipherService()); 26 | } 27 | 28 | protected override void PopulatePipeline(ProtectionPipeline pipeline) { 29 | // 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Confuser.Renamer/BAML/BAMLPropertyReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using Confuser.Core; 4 | 5 | namespace Confuser.Renamer.BAML { 6 | internal class BAMLPropertyReference : IBAMLReference { 7 | PropertyRecord rec; 8 | 9 | public BAMLPropertyReference(PropertyRecord rec) { 10 | this.rec = rec; 11 | } 12 | 13 | public bool CanRename(string oldName, string newName) { 14 | return true; 15 | } 16 | 17 | public void Rename(string oldName, string newName) { 18 | var value = rec.Value; 19 | if (value.IndexOf(oldName, StringComparison.OrdinalIgnoreCase) != -1) 20 | value = newName; 21 | else if (oldName.EndsWith(".baml")) { 22 | Debug.Assert(newName.EndsWith(".baml")); 23 | value = newName.Substring(0, newName.Length - 5) + ".xaml"; 24 | } 25 | else 26 | throw new UnreachableException(); 27 | rec.Value = "pack://application:,,,/" + value; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/DeclTypeFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// A function that compare the full name of declaring type. 7 | /// 8 | public class DeclTypeFunction : PatternFunction { 9 | internal const string FnName = "decl-type"; 10 | 11 | /// 12 | public override string Name { 13 | get { return FnName; } 14 | } 15 | 16 | /// 17 | public override int ArgumentCount { 18 | get { return 1; } 19 | } 20 | 21 | /// 22 | public override object Evaluate(IDnlibDef definition) { 23 | if (!(definition is IMemberDef) || ((IMemberDef)definition).DeclaringType == null) 24 | return false; 25 | object fullName = Arguments[0].Evaluate(definition); 26 | return ((IMemberDef)definition).DeclaringType.FullName == fullName.ToString(); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/Elements/AddKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core.Services; 3 | using Confuser.DynCipher.AST; 4 | using Confuser.DynCipher.Generation; 5 | 6 | namespace Confuser.DynCipher.Elements { 7 | internal class AddKey : CryptoElement { 8 | public AddKey(int index) 9 | : base(0) { 10 | Index = index; 11 | } 12 | 13 | public int Index { get; private set; } 14 | 15 | public override void Initialize(RandomGenerator random) { } 16 | 17 | void EmitCore(CipherGenContext context) { 18 | Expression val = context.GetDataExpression(Index); 19 | 20 | context.Emit(new AssignmentStatement { 21 | Value = val ^ context.GetKeyExpression(Index), 22 | Target = val 23 | }); 24 | } 25 | 26 | public override void Emit(CipherGenContext context) { 27 | EmitCore(context); 28 | } 29 | 30 | public override void EmitInverse(CipherGenContext context) { 31 | EmitCore(context); 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/ModuleFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// A function that compare the module of definition. 7 | /// 8 | public class ModuleFunction : PatternFunction { 9 | internal const string FnName = "module"; 10 | 11 | /// 12 | public override string Name { 13 | get { return FnName; } 14 | } 15 | 16 | /// 17 | public override int ArgumentCount { 18 | get { return 1; } 19 | } 20 | 21 | /// 22 | public override object Evaluate(IDnlibDef definition) { 23 | if (!(definition is IOwnerModule) && !(definition is IModule)) 24 | return false; 25 | object name = Arguments[0].Evaluate(definition); 26 | if (definition is IModule) 27 | return ((IModule)definition).Name == name.ToString(); 28 | return ((IOwnerModule)definition).Module.Name == name.ToString(); 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /Confuser.Core/ProtectionTargets.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Core { 4 | /// 5 | /// Targets of protection. 6 | /// 7 | [Flags] 8 | public enum ProtectionTargets { 9 | /// Type definitions. 10 | Types = 1, 11 | 12 | /// Method definitions. 13 | Methods = 2, 14 | 15 | /// Field definitions. 16 | Fields = 4, 17 | 18 | /// Event definitions. 19 | Events = 8, 20 | 21 | /// Property definitions. 22 | Properties = 16, 23 | 24 | /// All member definitions (i.e. type, methods, fields, events and properties). 25 | AllMembers = Types | Methods | Fields | Events | Properties, 26 | 27 | /// Module definitions. 28 | Modules = 32, 29 | 30 | /// All definitions (i.e. All member definitions and modules). 31 | AllDefinitions = AllMembers | Modules 32 | } 33 | } -------------------------------------------------------------------------------- /Confuser.Renamer/PostRenamePhase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using dnlib.DotNet; 4 | 5 | namespace Confuser.Renamer { 6 | internal class PostRenamePhase : ProtectionPhase { 7 | public PostRenamePhase(NameProtection parent) 8 | : base(parent) { } 9 | 10 | public override bool ProcessAll { 11 | get { return true; } 12 | } 13 | 14 | public override ProtectionTargets Targets { 15 | get { return ProtectionTargets.AllDefinitions; } 16 | } 17 | 18 | public override string Name { 19 | get { return "Post-renaming"; } 20 | } 21 | 22 | protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { 23 | var service = (NameService)context.Registry.GetService(); 24 | 25 | foreach (IRenamer renamer in service.Renamers) { 26 | foreach (IDnlibDef def in parameters.Targets) 27 | renamer.PostRename(context, service, parameters, def); 28 | context.CheckCancellation(); 29 | } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Confuser.Renamer/References/BAMLAttributeReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using Confuser.Renamer.BAML; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Renamer.References { 7 | internal class BAMLAttributeReference : INameReference { 8 | readonly AttributeInfoRecord attrRec; 9 | readonly IDnlibDef member; 10 | readonly PropertyRecord propRec; 11 | 12 | public BAMLAttributeReference(IDnlibDef member, AttributeInfoRecord rec) { 13 | this.member = member; 14 | attrRec = rec; 15 | } 16 | 17 | public BAMLAttributeReference(IDnlibDef member, PropertyRecord rec) { 18 | this.member = member; 19 | propRec = rec; 20 | } 21 | 22 | public bool UpdateNameReference(ConfuserContext context, INameService service) { 23 | if (attrRec != null) 24 | attrRec.Name = member.Name; 25 | else 26 | propRec.Value = member.Name; 27 | return true; 28 | } 29 | 30 | public bool ShouldCancelRename() { 31 | return false; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /ConfuserEx/ViewModel/Project/ProjectSettingVM.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core.Project; 3 | 4 | namespace ConfuserEx.ViewModel { 5 | public class ProjectSettingVM : ViewModelBase, IViewModel> { 6 | readonly ProjectVM parent; 7 | readonly SettingItem setting; 8 | 9 | public ProjectSettingVM(ProjectVM parent, SettingItem setting) { 10 | this.parent = parent; 11 | this.setting = setting; 12 | } 13 | 14 | public string Id { 15 | get { return setting.Id; } 16 | set { 17 | if (SetProperty(setting.Id != value, val => setting.Id = val, value, "Id")) 18 | parent.IsModified = true; 19 | } 20 | } 21 | 22 | public SettingItemAction Action { 23 | get { return setting.Action; } 24 | set { 25 | if (SetProperty(setting.Action != value, val => setting.Action = val, value, "Action")) 26 | parent.IsModified = true; 27 | } 28 | } 29 | 30 | SettingItem IViewModel>.Model { 31 | get { return setting; } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Rewriter/Instructions/MethodSpecInstructionRewriter.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using dnlib.DotNet.Emit; 8 | 9 | namespace Confuser.Protections.TypeScramble.Scrambler.Rewriter.Instructions { 10 | class MethodSpecInstructionRewriter : InstructionRewriter { 11 | public override void ProcessOperand(TypeService service, MethodDef method, IList body, ref int index, MethodSpec operand) { 12 | 13 | ScannedMethod t = service.GetItem(method.MDToken) as ScannedMethod; 14 | 15 | if (t != null) { 16 | 17 | var generics = operand.GenericInstMethodSig.GenericArguments.Select(x => t.ConvertToGenericIfAvalible(x)); 18 | 19 | operand.GenericInstMethodSig = new GenericInstMethodSig(generics.ToArray()); 20 | } 21 | 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /ConfuserEx/ViewModel/ViewModelBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | 5 | namespace ConfuserEx.ViewModel { 6 | public class ViewModelBase : INotifyPropertyChanged { 7 | // http://stackoverflow.com/a/1316417/462805 8 | 9 | public event PropertyChangedEventHandler PropertyChanged; 10 | 11 | protected virtual void OnPropertyChanged(string property) { 12 | if (PropertyChanged != null) 13 | PropertyChanged(this, new PropertyChangedEventArgs(property)); 14 | } 15 | 16 | protected bool SetProperty(ref T field, T value, string property) { 17 | if (!EqualityComparer.Default.Equals(field, value)) { 18 | field = value; 19 | OnPropertyChanged(property); 20 | return true; 21 | } 22 | return false; 23 | } 24 | 25 | protected bool SetProperty(bool changed, Action setter, T value, string property) { 26 | if (changed) { 27 | setter(value); 28 | OnPropertyChanged(property); 29 | return true; 30 | } 31 | return false; 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/DynCipherService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core.Services; 3 | using Confuser.DynCipher.AST; 4 | using Confuser.DynCipher.Generation; 5 | 6 | namespace Confuser.DynCipher { 7 | public interface IDynCipherService { 8 | void GenerateCipherPair(RandomGenerator random, out StatementBlock encrypt, out StatementBlock decrypt); 9 | void GenerateExpressionPair(RandomGenerator random, Expression var, Expression result, int depth, out Expression expression, out Expression inverse); 10 | } 11 | 12 | internal class DynCipherService : IDynCipherService { 13 | public void GenerateCipherPair(RandomGenerator random, out StatementBlock encrypt, out StatementBlock decrypt) { 14 | CipherGenerator.GeneratePair(random, out encrypt, out decrypt); 15 | } 16 | 17 | public void GenerateExpressionPair(RandomGenerator random, Expression var, Expression result, int depth, out Expression expression, out Expression inverse) { 18 | ExpressionGenerator.GeneratePair(random, var, result, depth, out expression, out inverse); 19 | } 20 | } 21 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/InheritsFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// A function that indicate whether the type inherits from the specified type. 7 | /// 8 | public class InheritsFunction : PatternFunction { 9 | internal const string FnName = "inherits"; 10 | 11 | /// 12 | public override string Name { 13 | get { return FnName; } 14 | } 15 | 16 | /// 17 | public override int ArgumentCount { 18 | get { return 1; } 19 | } 20 | 21 | /// 22 | public override object Evaluate(IDnlibDef definition) { 23 | string name = Arguments[0].Evaluate(definition).ToString(); 24 | 25 | var type = definition as TypeDef; 26 | if (type == null && definition is IMemberDef) 27 | type = ((IMemberDef)definition).DeclaringType; 28 | if (type == null) 29 | return false; 30 | 31 | if (type.InheritsFrom(name) || type.Implements(name)) 32 | return true; 33 | 34 | return false; 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /Confuser.Runtime/Mutation.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | internal class Mutation { 4 | public static readonly int KeyI0 = 0; 5 | public static readonly int KeyI1 = 1; 6 | public static readonly int KeyI2 = 2; 7 | public static readonly int KeyI3 = 3; 8 | public static readonly int KeyI4 = 4; 9 | public static readonly int KeyI5 = 5; 10 | public static readonly int KeyI6 = 6; 11 | public static readonly int KeyI7 = 7; 12 | public static readonly int KeyI8 = 8; 13 | public static readonly int KeyI9 = 9; 14 | public static readonly int KeyI10 = 10; 15 | public static readonly int KeyI11 = 11; 16 | public static readonly int KeyI12 = 12; 17 | public static readonly int KeyI13 = 13; 18 | public static readonly int KeyI14 = 14; 19 | public static readonly int KeyI15 = 15; 20 | 21 | public static T Placeholder(T val) { 22 | return val; 23 | } 24 | 25 | public static T Value() { 26 | return default(T); 27 | } 28 | 29 | public static T Value(Arg0 arg0) { 30 | return default(T); 31 | } 32 | 33 | public static void Crypt(uint[] data, uint[] key) { } 34 | } -------------------------------------------------------------------------------- /ConfuserEx/Views/ProjectModuleView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Windows; 3 | using System.Windows.Controls; 4 | using ConfuserEx.ViewModel; 5 | using Ookii.Dialogs.Wpf; 6 | 7 | namespace ConfuserEx.Views { 8 | public partial class ProjectModuleView : Window { 9 | readonly ProjectModuleVM module; 10 | 11 | public ProjectModuleView(ProjectModuleVM module) { 12 | InitializeComponent(); 13 | this.module = module; 14 | DataContext = module; 15 | PwdBox.IsEnabled = !string.IsNullOrEmpty(PathBox.Text); 16 | } 17 | 18 | void Done(object sender, RoutedEventArgs e) { 19 | DialogResult = true; 20 | } 21 | 22 | void PathBox_TextChanged(object sender, TextChangedEventArgs e) { 23 | PwdBox.IsEnabled = !string.IsNullOrEmpty(PathBox.Text); 24 | } 25 | 26 | void ChooseSNKey(object sender, RoutedEventArgs e) { 27 | var ofd = new VistaOpenFileDialog(); 28 | ofd.Filter = "Supported Key Files (*.snk, *.pfx)|*.snk;*.pfx|All Files (*.*)|*.*"; 29 | if (ofd.ShowDialog() ?? false) { 30 | module.SNKeyPath = ofd.FileName; 31 | } 32 | } 33 | } 34 | } -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Rewriter/Instructions/MethodDefInstructionRewriter.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using dnlib.DotNet.Emit; 8 | 9 | namespace Confuser.Protections.TypeScramble.Scrambler.Rewriter.Instructions 10 | { 11 | class MethodDefInstructionRewriter : InstructionRewriter { 12 | public override void ProcessOperand(TypeService service, MethodDef method, IList body, ref int index, MethodDef operand) { 13 | 14 | ScannedMethod tMethod = service.GetItem(operand.MDToken) as ScannedMethod; 15 | ScannedItem currentMethod = service.GetItem(method.MDToken) as ScannedMethod; 16 | 17 | if (tMethod != null) { 18 | 19 | var newspec = new MethodSpecUser(tMethod.TargetMethod, tMethod.CreateGenericMethodSig(currentMethod)); 20 | 21 | body[index].Operand = newspec; 22 | } 23 | 24 | 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Analyzers/ContextAnalyzerFactory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Confuser.Protections.TypeScramble.Scrambler.Analyzers { 9 | public class ContextAnalyzerFactory : IEnumerable { 10 | 11 | public Dictionary Analyzers = new Dictionary(); 12 | private ScannedMethod targetMethod; 13 | public ContextAnalyzerFactory(ScannedMethod m) { 14 | targetMethod = m; 15 | } 16 | 17 | public void Add(ContextAnalyzer a) { 18 | Analyzers.Add(a.TargetType(), a); 19 | } 20 | 21 | public void Analyze(object o) { 22 | ContextAnalyzer a; 23 | Analyzers.TryGetValue(o.GetType().BaseType, out a); 24 | a?.ProcessOperand(targetMethod, o); 25 | } 26 | 27 | public IEnumerator GetEnumerator() { 28 | return Analyzers.Values.GetEnumerator(); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Confuser.Runtime/AntiDebug.Safe.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Threading; 4 | 5 | namespace Confuser.Runtime { 6 | internal static class AntiDebugSafe { 7 | static void Initialize() { 8 | string x = "COR"; 9 | var env = typeof(Environment); 10 | var method = env.GetMethod("GetEnvironmentVariable", new[] { typeof(string) }); 11 | if (method != null && 12 | "1".Equals(method.Invoke(null, new object[] { x + "_ENABLE_PROFILING" }))) 13 | Environment.FailFast(null); 14 | 15 | var thread = new Thread(Worker); 16 | thread.IsBackground = true; 17 | thread.Start(null); 18 | } 19 | 20 | static void Worker(object thread) { 21 | var th = thread as Thread; 22 | if (th == null) { 23 | th = new Thread(Worker); 24 | th.IsBackground = true; 25 | th.Start(Thread.CurrentThread); 26 | Thread.Sleep(500); 27 | } 28 | while (true) { 29 | if (Debugger.IsAttached || Debugger.IsLogging()) 30 | Environment.FailFast(null); 31 | 32 | if (!th.IsAlive) 33 | Environment.FailFast(null); 34 | 35 | Thread.Sleep(1000); 36 | } 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Build/UpdateVersion.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Release 5 | AnyCPU 6 | {1e74b523-aa86-42a0-8116-fff7cebfcba7} 7 | Exe 8 | UpdateVersion 9 | UpdateVersion 10 | v2.0 11 | 12 | 13 | false 14 | None 15 | true 16 | .\ 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Rewriter/Instructions/InstructionRewriter.cs: -------------------------------------------------------------------------------- 1 | using dnlib.DotNet; 2 | using dnlib.DotNet.Emit; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Threading.Tasks; 8 | 9 | namespace Confuser.Protections.TypeScramble.Scrambler.Rewriter.Instructions { 10 | abstract class InstructionRewriter { 11 | 12 | public abstract void ProcessInstruction(TypeService service, MethodDef method, IList body, ref int index, Instruction i); 13 | public abstract Type TargetType(); 14 | } 15 | 16 | abstract class InstructionRewriter : InstructionRewriter { 17 | 18 | public override void ProcessInstruction(TypeService service, MethodDef method, IList body, ref int index, Instruction i) { 19 | ProcessOperand(service, method, body, ref index, (T)i.Operand); 20 | } 21 | public override Type TargetType() => typeof(T); 22 | 23 | public abstract void ProcessOperand(TypeService service, MethodDef method, IList body, ref int index, T operand); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /Confuser.Core/Project/InvalidPatternException.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Core.Project { 4 | /// 5 | /// The exception that is thrown when attempted to parse an invalid pattern. 6 | /// 7 | public class InvalidPatternException : Exception { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | /// The message that describes the error. 12 | public InvalidPatternException(string message) 13 | : base(message) { } 14 | 15 | /// 16 | /// Initializes a new instance of the class. 17 | /// 18 | /// The error message that explains the reason for the exception. 19 | /// 20 | /// The exception that is the cause of the current exception, or a null reference (Nothing in 21 | /// Visual Basic) if no inner exception is specified. 22 | /// 23 | public InvalidPatternException(string message, Exception innerException) 24 | : base(message, innerException) { } 25 | } 26 | } -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/TypeScrambleProtection.cs: -------------------------------------------------------------------------------- 1 | using Confuser.Core; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace Confuser.Protections.TypeScramble { 9 | class TypeScrambleProtection : Protection { 10 | public override ProtectionPreset Preset => ProtectionPreset.None; 11 | 12 | public override string Name => "Type Scrambler"; 13 | 14 | public override string Description => "Replaces types with generics"; 15 | 16 | public override string Id => "typescramble"; 17 | 18 | public override string FullId => "BahNahNah.typescramble"; 19 | 20 | protected override void Initialize(ConfuserContext context) { 21 | context.Registry.RegisterService(FullId, typeof(TypeService), new TypeService(context)); 22 | } 23 | 24 | protected override void PopulatePipeline(ProtectionPipeline pipeline) { 25 | pipeline.InsertPreStage(PipelineStage.Inspection, new AnalyzePhase(this)); 26 | pipeline.InsertPostStage(PipelineStage.Inspection, new ScramblePhase(this)); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ConfuserEx is licensed under MIT license. 2 | 3 | ---------------- 4 | 5 | Copyright (c) 2014 yck1509 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all 15 | copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 23 | SOFTWARE. -------------------------------------------------------------------------------- /Confuser.Renamer/References/BAMLConverterMemberReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using Confuser.Renamer.BAML; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Renamer.References { 7 | internal class BAMLConverterMemberReference : INameReference { 8 | readonly IDnlibDef member; 9 | readonly PropertyRecord rec; 10 | readonly TypeSig sig; 11 | readonly BAMLAnalyzer.XmlNsContext xmlnsCtx; 12 | 13 | public BAMLConverterMemberReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, IDnlibDef member, PropertyRecord rec) { 14 | this.xmlnsCtx = xmlnsCtx; 15 | this.sig = sig; 16 | this.member = member; 17 | this.rec = rec; 18 | } 19 | 20 | public bool UpdateNameReference(ConfuserContext context, INameService service) { 21 | string typeName = sig.ReflectionName; 22 | string prefix = xmlnsCtx.GetPrefix(sig.ReflectionNamespace, sig.ToBasicTypeDefOrRef().ResolveTypeDefThrow().Module.Assembly); 23 | if (!string.IsNullOrEmpty(prefix)) 24 | typeName = prefix + ":" + typeName; 25 | rec.Value = typeName + "." + member.Name; 26 | return true; 27 | } 28 | 29 | public bool ShouldCancelRename() { 30 | return false; 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /additional/ilspy.crproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/NamespaceFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.RegularExpressions; 3 | using dnlib.DotNet; 4 | 5 | namespace Confuser.Core.Project.Patterns { 6 | /// 7 | /// A function that compare the namespace of definition. 8 | /// 9 | public class NamespaceFunction : PatternFunction { 10 | internal const string FnName = "namespace"; 11 | 12 | /// 13 | public override string Name { 14 | get { return FnName; } 15 | } 16 | 17 | /// 18 | public override int ArgumentCount { 19 | get { return 1; } 20 | } 21 | 22 | /// 23 | public override object Evaluate(IDnlibDef definition) { 24 | if (!(definition is TypeDef) && !(definition is IMemberDef)) 25 | return false; 26 | var ns = "^" + Arguments[0].Evaluate(definition).ToString() + "$"; 27 | 28 | var type = definition as TypeDef; 29 | if (type == null) 30 | type = ((IMemberDef)definition).DeclaringType; 31 | 32 | if (type == null) 33 | return false; 34 | 35 | while (type.IsNested) 36 | type = type.DeclaringType; 37 | 38 | return type != null && Regex.IsMatch(type.Namespace ?? "", ns); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/AST/BinOpExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.DynCipher.AST { 4 | public enum BinOps { 5 | Add, 6 | Sub, 7 | Div, 8 | Mul, 9 | Or, 10 | And, 11 | Xor, 12 | Lsh, 13 | Rsh 14 | } 15 | 16 | public class BinOpExpression : Expression { 17 | public Expression Left { get; set; } 18 | public Expression Right { get; set; } 19 | public BinOps Operation { get; set; } 20 | 21 | public override string ToString() { 22 | string op; 23 | switch (Operation) { 24 | case BinOps.Add: 25 | op = "+"; 26 | break; 27 | case BinOps.Sub: 28 | op = "-"; 29 | break; 30 | case BinOps.Div: 31 | op = "/"; 32 | break; 33 | case BinOps.Mul: 34 | op = "*"; 35 | break; 36 | case BinOps.Or: 37 | op = "|"; 38 | break; 39 | case BinOps.And: 40 | op = "&"; 41 | break; 42 | case BinOps.Xor: 43 | op = "^"; 44 | break; 45 | case BinOps.Lsh: 46 | op = "<<"; 47 | break; 48 | case BinOps.Rsh: 49 | op = ">>"; 50 | break; 51 | default: 52 | throw new Exception(); 53 | } 54 | return string.Format("({0} {1} {2})", Left, op, Right); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Confuser.Protections/ReferenceProxy/RPContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Confuser.Core; 4 | using Confuser.Core.Services; 5 | using Confuser.DynCipher; 6 | using Confuser.Renamer; 7 | using dnlib.DotNet; 8 | using dnlib.DotNet.Emit; 9 | 10 | namespace Confuser.Protections.ReferenceProxy { 11 | internal enum Mode { 12 | Mild, 13 | Strong, 14 | Ftn 15 | } 16 | 17 | internal enum EncodingType { 18 | Normal, 19 | Expression, 20 | x86 21 | } 22 | 23 | internal class RPContext { 24 | public ReferenceProxyProtection Protection; 25 | public CilBody Body; 26 | public HashSet BranchTargets; 27 | public ConfuserContext Context; 28 | public Dictionary Delegates; 29 | public int Depth; 30 | public IDynCipherService DynCipher; 31 | public EncodingType Encoding; 32 | public IRPEncoding EncodingHandler; 33 | public int InitCount; 34 | public bool InternalAlso; 35 | public IMarkerService Marker; 36 | public MethodDef Method; 37 | public Mode Mode; 38 | 39 | public RPMode ModeHandler; 40 | public ModuleDef Module; 41 | public INameService Name; 42 | public RandomGenerator Random; 43 | public bool TypeErasure; 44 | } 45 | } -------------------------------------------------------------------------------- /Confuser.Protections/Resources/ResourceProtection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using Confuser.Protections.Resources; 4 | 5 | namespace Confuser.Protections { 6 | [BeforeProtection("Ki.ControlFlow"), AfterProtection("Ki.Constants")] 7 | internal class ResourceProtection : Protection { 8 | public const string _Id = "resources"; 9 | public const string _FullId = "Ki.Resources"; 10 | public const string _ServiceId = "Ki.Resources"; 11 | 12 | public override string Name { 13 | get { return "Resources Protection"; } 14 | } 15 | 16 | public override string Description { 17 | get { return "This protection encodes and compresses the embedded resources."; } 18 | } 19 | 20 | public override string Id { 21 | get { return _Id; } 22 | } 23 | 24 | public override string FullId { 25 | get { return _FullId; } 26 | } 27 | 28 | public override ProtectionPreset Preset { 29 | get { return ProtectionPreset.Normal; } 30 | } 31 | 32 | protected override void Initialize(ConfuserContext context) { } 33 | 34 | protected override void PopulatePipeline(ProtectionPipeline pipeline) { 35 | pipeline.InsertPreStage(PipelineStage.ProcessModule, new InjectPhase(this)); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /ConfuserEx/App.xaml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | Resources/#FontAwesome 17 | 18 | 19 | -------------------------------------------------------------------------------- /Confuser.Core/ProtectionSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Confuser.Core { 5 | /// 6 | /// Protection settings for a certain component 7 | /// 8 | public class ProtectionSettings : Dictionary> { 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | public ProtectionSettings() { } 13 | 14 | /// 15 | /// Initializes a new instance of the class 16 | /// from an existing . 17 | /// 18 | /// The settings to copy from. 19 | public ProtectionSettings(ProtectionSettings settings) { 20 | if (settings == null) 21 | return; 22 | 23 | foreach (var i in settings) 24 | Add(i.Key, new Dictionary(i.Value)); 25 | } 26 | 27 | /// 28 | /// Determines whether the settings is empty. 29 | /// 30 | /// true if the settings is empty; otherwise, false. 31 | public bool IsEmpty() { 32 | return Count == 0; 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /Confuser.Protections/Resources/NormalMode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dnlib.DotNet; 4 | using dnlib.DotNet.Emit; 5 | 6 | namespace Confuser.Protections.Resources { 7 | internal class NormalMode : IEncodeMode { 8 | public IEnumerable EmitDecrypt(MethodDef init, REContext ctx, Local block, Local key) { 9 | for (int i = 0; i < 0x10; i++) { 10 | yield return Instruction.Create(OpCodes.Ldloc, block); 11 | yield return Instruction.Create(OpCodes.Ldc_I4, i); 12 | yield return Instruction.Create(OpCodes.Ldloc, block); 13 | yield return Instruction.Create(OpCodes.Ldc_I4, i); 14 | yield return Instruction.Create(OpCodes.Ldelem_U4); 15 | yield return Instruction.Create(OpCodes.Ldloc, key); 16 | yield return Instruction.Create(OpCodes.Ldc_I4, i); 17 | yield return Instruction.Create(OpCodes.Ldelem_U4); 18 | yield return Instruction.Create(OpCodes.Xor); 19 | yield return Instruction.Create(OpCodes.Stelem_I4); 20 | } 21 | } 22 | 23 | public uint[] Encrypt(uint[] data, int offset, uint[] key) { 24 | var ret = new uint[key.Length]; 25 | for (int i = 0; i < key.Length; i++) 26 | ret[i] = data[i + offset] ^ key[i]; 27 | return ret; 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/LiteralExpression.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dnlib.DotNet; 4 | 5 | namespace Confuser.Core.Project.Patterns { 6 | /// 7 | /// A literal expression. 8 | /// 9 | public class LiteralExpression : PatternExpression { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The literal. 14 | public LiteralExpression(object literal) { 15 | Literal = literal; 16 | } 17 | 18 | /// 19 | /// Gets the value of literal. 20 | /// 21 | /// The value of literal. 22 | public object Literal { get; private set; } 23 | 24 | /// 25 | public override object Evaluate(IDnlibDef definition) { 26 | return Literal; 27 | } 28 | 29 | /// 30 | public override void Serialize(IList tokens) { 31 | if (Literal is bool) { 32 | var value = (bool)Literal; 33 | tokens.Add(new PatternToken(TokenType.Identifier, value.ToString().ToLowerInvariant())); 34 | } 35 | else 36 | tokens.Add(new PatternToken(TokenType.Literal, Literal.ToString())); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Confuser.Core/LZMA/Common/OutBuffer.cs: -------------------------------------------------------------------------------- 1 | // OutBuffer.cs 2 | 3 | using System; 4 | using System.IO; 5 | 6 | namespace SevenZip.Buffer { 7 | internal class OutBuffer { 8 | 9 | private readonly byte[] m_Buffer; 10 | private readonly uint m_BufferSize; 11 | private uint m_Pos; 12 | private ulong m_ProcessedSize; 13 | private Stream m_Stream; 14 | 15 | public OutBuffer(uint bufferSize) { 16 | m_Buffer = new byte[bufferSize]; 17 | m_BufferSize = bufferSize; 18 | } 19 | 20 | public void SetStream(Stream stream) { 21 | m_Stream = stream; 22 | } 23 | 24 | public void FlushStream() { 25 | m_Stream.Flush(); 26 | } 27 | 28 | public void CloseStream() { 29 | m_Stream.Close(); 30 | } 31 | 32 | public void ReleaseStream() { 33 | m_Stream = null; 34 | } 35 | 36 | public void Init() { 37 | m_ProcessedSize = 0; 38 | m_Pos = 0; 39 | } 40 | 41 | public void WriteByte(byte b) { 42 | m_Buffer[m_Pos++] = b; 43 | if (m_Pos >= m_BufferSize) 44 | FlushData(); 45 | } 46 | 47 | public void FlushData() { 48 | if (m_Pos == 0) 49 | return; 50 | m_Stream.Write(m_Buffer, 0, (int)m_Pos); 51 | m_Pos = 0; 52 | } 53 | 54 | public ulong GetProcessedSize() { 55 | return m_ProcessedSize + m_Pos; 56 | } 57 | 58 | } 59 | } -------------------------------------------------------------------------------- /Confuser.Core/Services/RuntimeService.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Reflection; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Core.Services { 7 | internal class RuntimeService : IRuntimeService { 8 | ModuleDef rtModule; 9 | 10 | /// 11 | public TypeDef GetRuntimeType(string fullName) { 12 | if (rtModule == null) { 13 | Module module = typeof(RuntimeService).Assembly.ManifestModule; 14 | string rtPath = "Confuser.Runtime.dll"; 15 | if (module.FullyQualifiedName[0] != '<') 16 | rtPath = Path.Combine(Path.GetDirectoryName(module.FullyQualifiedName), rtPath); 17 | rtModule = ModuleDefMD.Load(rtPath, new ModuleCreationOptions() { TryToLoadPdbFromDisk = true }); 18 | rtModule.EnableTypeDefFindCache = true; 19 | } 20 | return rtModule.Find(fullName, true); 21 | } 22 | } 23 | 24 | /// 25 | /// Provides methods to obtain runtime library injection type. 26 | /// 27 | public interface IRuntimeService { 28 | /// 29 | /// Gets the specified runtime type for injection. 30 | /// 31 | /// The full name of the runtime type. 32 | /// The requested runtime type. 33 | TypeDef GetRuntimeType(string fullName); 34 | } 35 | } -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/ScannedType.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using dnlib.DotNet; 7 | 8 | namespace Confuser.Protections.TypeScramble.Scrambler { 9 | public class ScannedType : ScannedItem { 10 | public TypeDef TargetType { get; private set; } 11 | 12 | public ScannedType(TypeDef _t) { 13 | TargetType = _t; 14 | } 15 | 16 | public override void Scan() { 17 | foreach(var field in TargetType.Fields) { 18 | RegisterGeneric(field.FieldType); 19 | } 20 | } 21 | 22 | public override void PrepairGenerics() { 23 | foreach (var generic in Generics.Values) { 24 | TargetType.GenericParameters.Add(generic); 25 | } 26 | 27 | 28 | foreach (var field in TargetType.Fields) { 29 | field.FieldType = ConvertToGenericIfAvalible(field.FieldType); 30 | } 31 | } 32 | 33 | public override MDToken GetToken() => TargetType.MDToken; 34 | 35 | public override ClassOrValueTypeSig GetTarget() { 36 | return TargetType.TryGetClassOrValueTypeSig(); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/PatternFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// A pattern function. 7 | /// 8 | public abstract class PatternFunction : PatternExpression { 9 | /// 10 | /// Gets the name of function. 11 | /// 12 | /// The name. 13 | public abstract string Name { get; } 14 | 15 | /// 16 | /// Gets the number of arguments of the function. 17 | /// 18 | /// The number of arguments. 19 | public abstract int ArgumentCount { get; } 20 | 21 | /// 22 | /// Gets or sets the arguments of function. 23 | /// 24 | /// The arguments. 25 | public IList Arguments { get; set; } 26 | 27 | /// 28 | public override void Serialize(IList tokens) { 29 | tokens.Add(new PatternToken(TokenType.Identifier, Name)); 30 | tokens.Add(new PatternToken(TokenType.LParens)); 31 | for (int i = 0; i < Arguments.Count; i++) { 32 | if (i != 0) 33 | tokens.Add(new PatternToken(TokenType.Comma)); 34 | Arguments[i].Serialize(tokens); 35 | } 36 | tokens.Add(new PatternToken(TokenType.RParens)); 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /Confuser.Core/MarkerResult.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using dnlib.DotNet; 4 | 5 | namespace Confuser.Core { 6 | /// 7 | /// Result of the marker. 8 | /// 9 | public class MarkerResult { 10 | /// 11 | /// Initializes a new instance of the class. 12 | /// 13 | /// The modules. 14 | /// The packer. 15 | /// The external modules. 16 | public MarkerResult(IList modules, Packer packer, IList extModules) { 17 | Modules = modules; 18 | Packer = packer; 19 | ExternalModules = extModules; 20 | } 21 | 22 | /// 23 | /// Gets a list of modules that is marked. 24 | /// 25 | /// The list of modules. 26 | public IList Modules { get; private set; } 27 | 28 | /// 29 | /// Gets a list of external modules. 30 | /// 31 | /// The list of external modules. 32 | public IList ExternalModules { get; private set; } 33 | 34 | /// 35 | /// Gets the packer if exists. 36 | /// 37 | /// The packer, or null if no packer exists. 38 | public Packer Packer { get; private set; } 39 | } 40 | } -------------------------------------------------------------------------------- /Confuser.Protections/Constants/CEContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Confuser.Core; 4 | using Confuser.Core.Services; 5 | using Confuser.DynCipher; 6 | using Confuser.Renamer; 7 | using dnlib.DotNet; 8 | using dnlib.DotNet.Emit; 9 | 10 | namespace Confuser.Protections.Constants { 11 | internal class CEContext { 12 | public ConfuserContext Context; 13 | public ConstantProtection Protection; 14 | public ModuleDef Module; 15 | 16 | public FieldDef BufferField; 17 | public FieldDef DataField; 18 | public TypeDef DataType; 19 | public MethodDef InitMethod; 20 | 21 | public int DecoderCount; 22 | public List> Decoders; 23 | 24 | public EncodeElements Elements; 25 | public List EncodedBuffer; 26 | 27 | public Mode Mode; 28 | public IEncodeMode ModeHandler; 29 | 30 | public IDynCipherService DynCipher; 31 | public IMarkerService Marker; 32 | public INameService Name; 33 | public RandomGenerator Random; 34 | 35 | public TypeDef CfgCtxType; 36 | public MethodDef CfgCtxCtor; 37 | public MethodDef CfgCtxNext; 38 | public Dictionary>> ReferenceRepl; 39 | } 40 | 41 | internal class DecoderDesc { 42 | public object Data; 43 | public byte InitializerID; 44 | public byte NumberID; 45 | public byte StringID; 46 | } 47 | } -------------------------------------------------------------------------------- /Confuser.Renamer/References/BAMLConverterTypeReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using Confuser.Renamer.BAML; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Renamer.References { 7 | internal class BAMLConverterTypeReference : INameReference { 8 | readonly PropertyRecord propRec; 9 | readonly TypeSig sig; 10 | readonly TextRecord textRec; 11 | readonly BAMLAnalyzer.XmlNsContext xmlnsCtx; 12 | 13 | public BAMLConverterTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, PropertyRecord rec) { 14 | this.xmlnsCtx = xmlnsCtx; 15 | this.sig = sig; 16 | propRec = rec; 17 | } 18 | 19 | public BAMLConverterTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, TextRecord rec) { 20 | this.xmlnsCtx = xmlnsCtx; 21 | this.sig = sig; 22 | textRec = rec; 23 | } 24 | 25 | public bool UpdateNameReference(ConfuserContext context, INameService service) { 26 | string name = sig.ReflectionName; 27 | string prefix = xmlnsCtx.GetPrefix(sig.ReflectionNamespace, sig.ToBasicTypeDefOrRef().ResolveTypeDefThrow().Module.Assembly); 28 | if (!string.IsNullOrEmpty(prefix)) 29 | name = prefix + ":" + name; 30 | if (propRec != null) 31 | propRec.Value = name; 32 | else 33 | textRec.Value = name; 34 | return true; 35 | } 36 | 37 | public bool ShouldCancelRename() { 38 | return false; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/Rewriter/Instructions/InstructionRewriterFactory.cs: -------------------------------------------------------------------------------- 1 | using Confuser.Core; 2 | using dnlib.DotNet; 3 | using dnlib.DotNet.Emit; 4 | using System; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace Confuser.Protections.TypeScramble.Scrambler.Rewriter.Instructions { 12 | class InstructionRewriterFactory : IEnumerable { 13 | 14 | private Dictionary RewriterDefinitions = new Dictionary(); 15 | 16 | public void Add(InstructionRewriter i) { 17 | RewriterDefinitions.Add(i.TargetType(), i); 18 | } 19 | 20 | public void Process(TypeService service, MethodDef method, IList c, int index) { 21 | Instruction current = c[index]; 22 | if(current.Operand == null) { 23 | return; 24 | } 25 | InstructionRewriter rw; 26 | if(RewriterDefinitions.TryGetValue(current.Operand.GetType().BaseType, out rw)) { 27 | rw.ProcessInstruction(service, method, c, ref index, current); 28 | } 29 | } 30 | 31 | public IEnumerator GetEnumerator() { 32 | return RewriterDefinitions.Values.GetEnumerator(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /Confuser.Core/LZMA/Common/CRC.cs: -------------------------------------------------------------------------------- 1 | // Common/CRC.cs 2 | 3 | using System; 4 | 5 | namespace SevenZip { 6 | internal class CRC { 7 | 8 | public static readonly uint[] Table; 9 | 10 | private uint _value = 0xFFFFFFFF; 11 | 12 | static CRC() { 13 | Table = new uint[256]; 14 | const uint kPoly = 0xEDB88320; 15 | for (uint i = 0; i < 256; i++) { 16 | uint r = i; 17 | for (int j = 0; j < 8; j++) 18 | if ((r & 1) != 0) 19 | r = (r >> 1) ^ kPoly; 20 | else 21 | r >>= 1; 22 | Table[i] = r; 23 | } 24 | } 25 | 26 | public void Init() { 27 | _value = 0xFFFFFFFF; 28 | } 29 | 30 | public void UpdateByte(byte b) { 31 | _value = Table[(((byte)(_value)) ^ b)] ^ (_value >> 8); 32 | } 33 | 34 | public void Update(byte[] data, uint offset, uint size) { 35 | for (uint i = 0; i < size; i++) 36 | _value = Table[(((byte)(_value)) ^ data[offset + i])] ^ (_value >> 8); 37 | } 38 | 39 | public uint GetDigest() { 40 | return _value ^ 0xFFFFFFFF; 41 | } 42 | 43 | private static uint CalculateDigest(byte[] data, uint offset, uint size) { 44 | var crc = new CRC(); 45 | // crc.Init(); 46 | crc.Update(data, offset, size); 47 | return crc.GetDigest(); 48 | } 49 | 50 | private static bool VerifyDigest(uint digest, byte[] data, uint offset, uint size) { 51 | return (CalculateDigest(data, offset, size) == digest); 52 | } 53 | 54 | } 55 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/Transforms/ExpansionTransform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Confuser.DynCipher.AST; 4 | 5 | namespace Confuser.DynCipher.Transforms { 6 | internal class ExpansionTransform { 7 | static bool ProcessStatement(Statement st, StatementBlock block) { 8 | if (st is AssignmentStatement) { 9 | var assign = (AssignmentStatement)st; 10 | if (assign.Value is BinOpExpression) { 11 | var exp = (BinOpExpression)assign.Value; 12 | if ((exp.Left is BinOpExpression || exp.Right is BinOpExpression) && 13 | exp.Left != assign.Target) { 14 | block.Statements.Add(new AssignmentStatement { 15 | Target = assign.Target, 16 | Value = exp.Left 17 | }); 18 | block.Statements.Add(new AssignmentStatement { 19 | Target = assign.Target, 20 | Value = new BinOpExpression { 21 | Left = assign.Target, 22 | Operation = exp.Operation, 23 | Right = exp.Right 24 | } 25 | }); 26 | return true; 27 | } 28 | } 29 | } 30 | block.Statements.Add(st); 31 | return false; 32 | } 33 | 34 | public static void Run(StatementBlock block) { 35 | bool workDone; 36 | do { 37 | workDone = false; 38 | Statement[] copy = block.Statements.ToArray(); 39 | block.Statements.Clear(); 40 | foreach (Statement st in copy) 41 | workDone |= ProcessStatement(st, block); 42 | } while (workDone); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/IsPublicFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// A function that indicate the visibility of members. 7 | /// 8 | public class IsPublicFunction : PatternFunction { 9 | internal const string FnName = "is-public"; 10 | 11 | /// 12 | public override string Name { 13 | get { return FnName; } 14 | } 15 | 16 | /// 17 | public override int ArgumentCount { 18 | get { return 0; } 19 | } 20 | 21 | /// 22 | public override object Evaluate(IDnlibDef definition) { 23 | var member = definition as IMemberDef; 24 | if (member == null) 25 | return false; 26 | 27 | var declType = ((IMemberDef)definition).DeclaringType; 28 | while (declType != null) { 29 | if (!declType.IsPublic) 30 | return false; 31 | declType = declType.DeclaringType; 32 | } 33 | 34 | if (member is MethodDef) 35 | return ((MethodDef)member).IsPublic; 36 | if (member is FieldDef) 37 | return ((FieldDef)member).IsPublic; 38 | if (member is PropertyDef) 39 | return ((PropertyDef)member).IsPublic(); 40 | if (member is EventDef) 41 | return ((EventDef)member).IsPublic(); 42 | if (member is TypeDef) 43 | return ((TypeDef)member).IsPublic || ((TypeDef)member).IsNestedPublic; 44 | 45 | throw new NotSupportedException(); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Confuser.Protections/ReferenceProxy/NormalEncoding.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Confuser.Core.Services; 4 | using Confuser.DynCipher; 5 | using dnlib.DotNet; 6 | using dnlib.DotNet.Emit; 7 | 8 | namespace Confuser.Protections.ReferenceProxy { 9 | internal class NormalEncoding : IRPEncoding { 10 | readonly Dictionary> keys = new Dictionary>(); 11 | 12 | public Instruction[] EmitDecode(MethodDef init, RPContext ctx, Instruction[] arg) { 13 | Tuple key = GetKey(ctx.Random, init); 14 | var ret = new List(); 15 | if (ctx.Random.NextBoolean()) { 16 | ret.Add(Instruction.Create(OpCodes.Ldc_I4, key.Item1)); 17 | ret.AddRange(arg); 18 | } 19 | else { 20 | ret.AddRange(arg); 21 | ret.Add(Instruction.Create(OpCodes.Ldc_I4, key.Item1)); 22 | } 23 | ret.Add(Instruction.Create(OpCodes.Mul)); 24 | return ret.ToArray(); 25 | } 26 | 27 | public int Encode(MethodDef init, RPContext ctx, int value) { 28 | Tuple key = GetKey(ctx.Random, init); 29 | return value * key.Item2; 30 | } 31 | 32 | Tuple GetKey(RandomGenerator random, MethodDef init) { 33 | Tuple ret; 34 | if (!keys.TryGetValue(init, out ret)) { 35 | int key = random.NextInt32() | 1; 36 | keys[init] = ret = Tuple.Create(key, (int)MathsUtils.modInv((uint)key)); 37 | } 38 | return ret; 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/PatternOperator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace Confuser.Core.Project.Patterns { 5 | /// 6 | /// A pattern operator. 7 | /// 8 | public abstract class PatternOperator : PatternExpression { 9 | /// 10 | /// Gets the name of operator. 11 | /// 12 | /// The name. 13 | public abstract string Name { get; } 14 | 15 | /// 16 | /// Gets a value indicating whether this is an unary operator. 17 | /// 18 | /// true if this is an unary operator; otherwise, false. 19 | public abstract bool IsUnary { get; } 20 | 21 | /// 22 | /// Gets or sets the first operand. 23 | /// 24 | /// The first operand. 25 | public PatternExpression OperandA { get; set; } 26 | 27 | /// 28 | /// Gets or sets the second operand. 29 | /// 30 | /// The second operand. 31 | public PatternExpression OperandB { get; set; } 32 | 33 | /// 34 | public override void Serialize(IList tokens) { 35 | if (IsUnary) { 36 | tokens.Add(new PatternToken(TokenType.Identifier, Name)); 37 | OperandA.Serialize(tokens); 38 | } 39 | else { 40 | OperandA.Serialize(tokens); 41 | tokens.Add(new PatternToken(TokenType.Identifier, Name)); 42 | OperandB.Serialize(tokens); 43 | } 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /Confuser.Core/ConfuserComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Core { 4 | /// 5 | /// Represent a component in Confuser 6 | /// 7 | public abstract class ConfuserComponent { 8 | /// 9 | /// Gets the name of component. 10 | /// 11 | /// The name of component. 12 | public abstract string Name { get; } 13 | 14 | /// 15 | /// Gets the description of component. 16 | /// 17 | /// The description of component. 18 | public abstract string Description { get; } 19 | 20 | /// 21 | /// Gets the identifier of component used by users. 22 | /// 23 | /// The identifier of component. 24 | public abstract string Id { get; } 25 | 26 | /// 27 | /// Gets the full identifier of component used in Confuser. 28 | /// 29 | /// The full identifier of component. 30 | public abstract string FullId { get; } 31 | 32 | /// 33 | /// Initializes the component. 34 | /// 35 | /// The working context. 36 | protected internal abstract void Initialize(ConfuserContext context); 37 | 38 | /// 39 | /// Inserts protection stages into processing pipeline. 40 | /// 41 | /// The processing pipeline. 42 | protected internal abstract void PopulatePipeline(ProtectionPipeline pipeline); 43 | } 44 | } -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/ScramblePhase.cs: -------------------------------------------------------------------------------- 1 | using Confuser.Core; 2 | using Confuser.Protections.TypeScramble.Scrambler; 3 | using dnlib.DotNet; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Confuser.Protections.TypeScramble { 11 | class ScramblePhase : ProtectionPhase { 12 | 13 | public ScramblePhase(TypeScrambleProtection parent) : base(parent){ 14 | } 15 | 16 | public override ProtectionTargets Targets => ProtectionTargets.Types | ProtectionTargets.Methods | ProtectionTargets.Modules; 17 | 18 | public override string Name =>"Type scrambler"; 19 | 20 | protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { 21 | 22 | var rewriter = new TypeRewriter(context); 23 | rewriter.ApplyGeterics(); 24 | 25 | foreach (IDnlibDef def in parameters.Targets.WithProgress(context.Logger)) { 26 | 27 | switch (def) { 28 | 29 | case MethodDef md: 30 | if (md.HasBody) { 31 | rewriter.Process(md); 32 | } 33 | break; 34 | case ModuleDef mod: 35 | rewriter.ImportCode(mod); 36 | break; 37 | } 38 | 39 | context.CheckCancellation(); 40 | } 41 | 42 | 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /ConfuserEx/CompComboBox.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Windows; 4 | using System.Windows.Controls; 5 | using Confuser.Core; 6 | 7 | namespace ConfuserEx { 8 | public partial class CompComboBox : UserControl { 9 | public static readonly DependencyProperty ComponentsProperty = DependencyProperty.Register("Components", typeof(IEnumerable), typeof(CompComboBox), new UIPropertyMetadata(null)); 10 | public static readonly DependencyProperty SelectedComponentProperty = DependencyProperty.Register("SelectedComponent", typeof(ConfuserComponent), typeof(CompComboBox), new UIPropertyMetadata(null)); 11 | public static readonly DependencyProperty ArgumentsProperty = DependencyProperty.Register("Arguments", typeof(Dictionary), typeof(CompComboBox), new UIPropertyMetadata(null)); 12 | 13 | public CompComboBox() { 14 | InitializeComponent(); 15 | } 16 | 17 | public IEnumerable Components { 18 | get { return (IEnumerable)GetValue(ComponentsProperty); } 19 | set { SetValue(ComponentsProperty, value); } 20 | } 21 | 22 | public ConfuserComponent SelectedComponent { 23 | get { return (ConfuserComponent)GetValue(SelectedComponentProperty); } 24 | set { SetValue(SelectedComponentProperty, value); } 25 | } 26 | 27 | public Dictionary Arguments { 28 | get { return (Dictionary)GetValue(ArgumentsProperty); } 29 | set { SetValue(ArgumentsProperty, value); } 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /Confuser.Core/ModuleWriterListener.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | using dnlib.DotNet.Writer; 4 | 5 | namespace Confuser.Core { 6 | /// 7 | /// The listener of module writer event. 8 | /// 9 | public class ModuleWriterListener : IModuleWriterListener { 10 | /// 11 | void IModuleWriterListener.OnWriterEvent(ModuleWriterBase writer, ModuleWriterEvent evt) { 12 | if (evt == ModuleWriterEvent.PESectionsCreated) 13 | NativeEraser.Erase(writer as NativeModuleWriter, writer.Module as ModuleDefMD); 14 | if (OnWriterEvent != null) { 15 | OnWriterEvent(writer, new ModuleWriterListenerEventArgs(evt)); 16 | } 17 | } 18 | 19 | /// 20 | /// Occurs when a module writer event is triggered. 21 | /// 22 | public event EventHandler OnWriterEvent; 23 | } 24 | 25 | /// 26 | /// Indicates the triggered writer event. 27 | /// 28 | public class ModuleWriterListenerEventArgs : EventArgs { 29 | /// 30 | /// Initializes a new instance of the class. 31 | /// 32 | /// The triggered writer event. 33 | public ModuleWriterListenerEventArgs(ModuleWriterEvent evt) { 34 | WriterEvent = evt; 35 | } 36 | 37 | /// 38 | /// Gets the triggered writer event. 39 | /// 40 | /// The triggered writer event. 41 | public ModuleWriterEvent WriterEvent { get; private set; } 42 | } 43 | } -------------------------------------------------------------------------------- /ConfuserEx/ComponentConverter.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Globalization; 5 | using System.Linq; 6 | using System.Windows; 7 | using System.Windows.Data; 8 | using Confuser.Core; 9 | 10 | namespace ConfuserEx { 11 | internal class ComponentConverter : Freezable, IValueConverter { 12 | public static readonly DependencyProperty ComponentsProperty = DependencyProperty.Register("Components", typeof(IList), typeof(ComponentConverter), new UIPropertyMetadata(null)); 13 | 14 | public IList Components { 15 | get { return (IList)GetValue(ComponentsProperty); } 16 | set { SetValue(ComponentsProperty, value); } 17 | } 18 | 19 | public object Convert(object value, Type targetType, object parameter, CultureInfo culture) { 20 | Debug.Assert(value is string || value == null); 21 | Debug.Assert(targetType == typeof(ConfuserComponent)); 22 | Debug.Assert(Components != null); 23 | 24 | if (value == null) return null; 25 | return Components.Single(comp => comp.Id == (string)value); 26 | } 27 | 28 | public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { 29 | Debug.Assert(value is ConfuserComponent || value == null); 30 | Debug.Assert(targetType == typeof(string)); 31 | 32 | if (value == null) return null; 33 | return ((ConfuserComponent)value).Id; 34 | } 35 | 36 | protected override Freezable CreateInstanceCore() { 37 | return new ComponentConverter(); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/IsTypeFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Text.RegularExpressions; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Core.Project.Patterns { 7 | /// 8 | /// A function that indicate the type of type(?). 9 | /// 10 | public class IsTypeFunction : PatternFunction { 11 | internal const string FnName = "is-type"; 12 | 13 | /// 14 | public override string Name { 15 | get { return FnName; } 16 | } 17 | 18 | /// 19 | public override int ArgumentCount { 20 | get { return 1; } 21 | } 22 | 23 | /// 24 | public override object Evaluate(IDnlibDef definition) { 25 | TypeDef type = definition as TypeDef; 26 | if (type == null && definition is IMemberDef) 27 | type = ((IMemberDef)definition).DeclaringType; 28 | if (type == null) 29 | return false; 30 | 31 | string typeRegex = Arguments[0].Evaluate(definition).ToString(); 32 | 33 | var typeType = new StringBuilder(); 34 | 35 | if (type.IsEnum) 36 | typeType.Append("enum "); 37 | 38 | if (type.IsInterface) 39 | typeType.Append("interface "); 40 | 41 | if (type.IsValueType) 42 | typeType.Append("valuetype "); 43 | 44 | if (type.IsDelegate()) 45 | typeType.Append("delegate "); 46 | 47 | if (type.IsAbstract) 48 | typeType.Append("abstract "); 49 | 50 | if (type.IsNested) 51 | typeType.Append("nested "); 52 | 53 | if (type.IsSerializable) 54 | typeType.Append("serializable "); 55 | 56 | return Regex.IsMatch(typeType.ToString(), typeRegex); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /Confuser.Core/ProtectionDependencyAttributes.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Core { 4 | /// 5 | /// Indicates the must initialize before the specified protections. 6 | /// 7 | [AttributeUsage(AttributeTargets.Class)] 8 | public class BeforeProtectionAttribute : Attribute { 9 | /// 10 | /// Initializes a new instance of the class. 11 | /// 12 | /// The full IDs of the specified protections. 13 | public BeforeProtectionAttribute(params string[] ids) { 14 | Ids = ids; 15 | } 16 | 17 | /// 18 | /// Gets the full IDs of the specified protections. 19 | /// 20 | /// The IDs of protections. 21 | public string[] Ids { get; private set; } 22 | } 23 | 24 | /// 25 | /// Indicates the must initialize after the specified protections. 26 | /// 27 | [AttributeUsage(AttributeTargets.Class)] 28 | public class AfterProtectionAttribute : Attribute { 29 | /// 30 | /// Initializes a new instance of the class. 31 | /// 32 | /// The full IDs of the specified protections. 33 | public AfterProtectionAttribute(params string[] ids) { 34 | Ids = ids; 35 | } 36 | 37 | /// 38 | /// Gets the full IDs of the specified protections. 39 | /// 40 | /// The IDs of protections. 41 | public string[] Ids { get; private set; } 42 | } 43 | } -------------------------------------------------------------------------------- /Confuser.Protections/ControlFlow/ControlFlowProtection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using Confuser.Protections.ControlFlow; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Protections { 7 | public interface IControlFlowService { 8 | void ExcludeMethod(ConfuserContext context, MethodDef method); 9 | } 10 | 11 | internal class ControlFlowProtection : Protection, IControlFlowService { 12 | public const string _Id = "ctrl flow"; 13 | public const string _FullId = "Ki.ControlFlow"; 14 | public const string _ServiceId = "Ki.ControlFlow"; 15 | 16 | public override string Name { 17 | get { return "Control Flow Protection"; } 18 | } 19 | 20 | public override string Description { 21 | get { return "This protection mangles the code in the methods so that decompilers cannot decompile the methods."; } 22 | } 23 | 24 | public override string Id { 25 | get { return _Id; } 26 | } 27 | 28 | public override string FullId { 29 | get { return _FullId; } 30 | } 31 | 32 | public override ProtectionPreset Preset { 33 | get { return ProtectionPreset.Normal; } 34 | } 35 | 36 | public void ExcludeMethod(ConfuserContext context, MethodDef method) { 37 | ProtectionParameters.GetParameters(context, method).Remove(this); 38 | } 39 | 40 | protected override void Initialize(ConfuserContext context) { 41 | context.Registry.RegisterService(_ServiceId, typeof(IControlFlowService), this); 42 | } 43 | 44 | protected override void PopulatePipeline(ProtectionPipeline pipeline) { 45 | pipeline.InsertPreStage(PipelineStage.OptimizeMethods, new ControlFlowPhase(this)); 46 | } 47 | } 48 | } -------------------------------------------------------------------------------- /Confuser.Renamer/References/BAMLPathTypeReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using Confuser.Renamer.BAML; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Renamer.References { 7 | internal class BAMLPathTypeReference : INameReference { 8 | readonly PropertyPathPart attachedDP; 9 | readonly PropertyPathIndexer indexer; 10 | readonly TypeSig sig; 11 | readonly BAMLAnalyzer.XmlNsContext xmlnsCtx; 12 | 13 | public BAMLPathTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, PropertyPathIndexer indexer) { 14 | this.xmlnsCtx = xmlnsCtx; 15 | this.sig = sig; 16 | this.indexer = indexer; 17 | attachedDP = null; 18 | } 19 | 20 | public BAMLPathTypeReference(BAMLAnalyzer.XmlNsContext xmlnsCtx, TypeSig sig, PropertyPathPart attachedDP) { 21 | this.xmlnsCtx = xmlnsCtx; 22 | this.sig = sig; 23 | indexer = null; 24 | this.attachedDP = attachedDP; 25 | } 26 | 27 | public bool UpdateNameReference(ConfuserContext context, INameService service) { 28 | string name = sig.ReflectionName; 29 | string prefix = xmlnsCtx.GetPrefix(sig.ReflectionNamespace, sig.ToBasicTypeDefOrRef().ResolveTypeDefThrow().Module.Assembly); 30 | if (!string.IsNullOrEmpty(prefix)) 31 | name = prefix + ":" + name; 32 | if (indexer != null) { 33 | indexer.Type = name; 34 | } 35 | else { 36 | string oldType, property; 37 | attachedDP.ExtractAttachedDP(out oldType, out property); 38 | attachedDP.Name = string.Format("({0}.{1})", name, property); 39 | } 40 | return true; 41 | } 42 | 43 | public bool ShouldCancelRename() { 44 | return false; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /UnitTest/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // Les informations générales relatives à un assembly dépendent de 6 | // l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations 7 | // associées à un assembly. 8 | [assembly: AssemblyTitle("UnitTest")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("UnitTest")] 13 | [assembly: AssemblyCopyright("Copyright © 2018")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly 18 | // aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de 19 | // COM, affectez la valeur true à l'attribut ComVisible sur ce type. 20 | [assembly: ComVisible(false)] 21 | 22 | // Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM 23 | [assembly: Guid("e98490bb-63e5-492d-b14e-304de928f81a")] 24 | 25 | // Les informations de version pour un assembly se composent des quatre valeurs suivantes : 26 | // 27 | // Version principale 28 | // Version secondaire 29 | // Numéro de build 30 | // Révision 31 | // 32 | // Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut 33 | // en utilisant '*', comme indiqué ci-dessous : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /Confuser.DynCipher/Transforms/ConvertVariables.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.DynCipher.AST; 3 | 4 | namespace Confuser.DynCipher.Transforms { 5 | internal class ConvertVariables { 6 | static Expression ReplaceVar(Expression exp, Variable buff) { 7 | if (exp is VariableExpression) { 8 | if (((VariableExpression)exp).Variable.Name[0] != 'v') return exp; 9 | return new ArrayIndexExpression { 10 | Array = new VariableExpression { Variable = buff }, 11 | Index = (int)(exp as VariableExpression).Variable.Tag 12 | }; 13 | } 14 | if (exp is ArrayIndexExpression) { 15 | ((ArrayIndexExpression)exp).Array = ReplaceVar(((ArrayIndexExpression)exp).Array, buff); 16 | } 17 | else if (exp is BinOpExpression) { 18 | ((BinOpExpression)exp).Left = ReplaceVar(((BinOpExpression)exp).Left, buff); 19 | ((BinOpExpression)exp).Right = ReplaceVar(((BinOpExpression)exp).Right, buff); 20 | } 21 | else if (exp is UnaryOpExpression) { 22 | ((UnaryOpExpression)exp).Value = ReplaceVar(((UnaryOpExpression)exp).Value, buff); 23 | } 24 | return exp; 25 | } 26 | 27 | static Statement ReplaceVar(Statement st, Variable buff) { 28 | if (st is AssignmentStatement) { 29 | ((AssignmentStatement)st).Value = ReplaceVar(((AssignmentStatement)st).Value, buff); 30 | ((AssignmentStatement)st).Target = ReplaceVar(((AssignmentStatement)st).Target, buff); 31 | } 32 | return st; 33 | } 34 | 35 | public static void Run(StatementBlock block) { 36 | var mainBuff = new Variable("{BUFFER}"); 37 | for (int i = 0; i < block.Statements.Count; i++) 38 | block.Statements[i] = ReplaceVar(block.Statements[i], mainBuff); 39 | } 40 | } 41 | } -------------------------------------------------------------------------------- /Confuser.Core/LZMA/Common/InBuffer.cs: -------------------------------------------------------------------------------- 1 | // InBuffer.cs 2 | 3 | using System; 4 | using System.IO; 5 | 6 | namespace SevenZip.Buffer { 7 | internal class InBuffer { 8 | 9 | private readonly byte[] m_Buffer; 10 | private readonly uint m_BufferSize; 11 | private uint m_Limit; 12 | private uint m_Pos; 13 | private ulong m_ProcessedSize; 14 | private Stream m_Stream; 15 | private bool m_StreamWasExhausted; 16 | 17 | public InBuffer(uint bufferSize) { 18 | m_Buffer = new byte[bufferSize]; 19 | m_BufferSize = bufferSize; 20 | } 21 | 22 | public void Init(Stream stream) { 23 | m_Stream = stream; 24 | m_ProcessedSize = 0; 25 | m_Limit = 0; 26 | m_Pos = 0; 27 | m_StreamWasExhausted = false; 28 | } 29 | 30 | public bool ReadBlock() { 31 | if (m_StreamWasExhausted) 32 | return false; 33 | m_ProcessedSize += m_Pos; 34 | int aNumProcessedBytes = m_Stream.Read(m_Buffer, 0, (int)m_BufferSize); 35 | m_Pos = 0; 36 | m_Limit = (uint)aNumProcessedBytes; 37 | m_StreamWasExhausted = (aNumProcessedBytes == 0); 38 | return (!m_StreamWasExhausted); 39 | } 40 | 41 | 42 | public void ReleaseStream() { 43 | // m_Stream.Close(); 44 | m_Stream = null; 45 | } 46 | 47 | public bool ReadByte(byte b) // check it 48 | { 49 | if (m_Pos >= m_Limit) 50 | if (!ReadBlock()) 51 | return false; 52 | b = m_Buffer[m_Pos++]; 53 | return true; 54 | } 55 | 56 | public byte ReadByte() { 57 | // return (byte)m_Stream.ReadByte(); 58 | if (m_Pos >= m_Limit) 59 | if (!ReadBlock()) 60 | return 0xFF; 61 | return m_Buffer[m_Pos++]; 62 | } 63 | 64 | public ulong GetProcessedSize() { 65 | return m_ProcessedSize + m_Pos; 66 | } 67 | 68 | } 69 | } -------------------------------------------------------------------------------- /Confuser.Renamer/BAML/BAMLStringReference.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using Confuser.Core; 4 | using dnlib.DotNet.Emit; 5 | 6 | namespace Confuser.Renamer.BAML { 7 | public class BAMLStringReference : IBAMLReference { 8 | Instruction instr; 9 | 10 | public BAMLStringReference(Instruction instr) { 11 | this.instr = instr; 12 | } 13 | 14 | public bool CanRename(string oldName, string newName) { 15 | // TODO: Other protection interfering 16 | return instr.OpCode.Code == Code.Ldstr; 17 | } 18 | 19 | public void Rename(string oldName, string newName) { 20 | var value = (string)instr.Operand; 21 | if (value.IndexOf(oldName, StringComparison.OrdinalIgnoreCase) != -1) 22 | value = newName; 23 | else if (oldName.EndsWith(".baml")) { 24 | Debug.Assert(newName.EndsWith(".baml")); 25 | /* 26 | * Nik's patch for maintaining relative paths. If the xaml file is referenced in this manner 27 | * "/some.namespace;component/somefolder/somecontrol.xaml" 28 | * then we want to keep the relative path and namespace intact. We should be obfuscating it like this - /some.namespace;component/somefolder/asjdjh2398498dswk.xaml 29 | * */ 30 | //value = newName.Substring(0, newName.Length - 5) + ".xaml"; 31 | value = value.Replace(oldName.Replace(".baml", string.Empty, StringComparison.InvariantCultureIgnoreCase), 32 | newName.Replace(".baml", String.Empty, StringComparison.InvariantCultureIgnoreCase), 33 | StringComparison.InvariantCultureIgnoreCase); 34 | } 35 | else 36 | throw new UnreachableException(); 37 | instr.Operand = value; 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /Build/UpdateVersion.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | 5 | public static class Program { 6 | public static int Main(string[] args) { 7 | if (args.Length != 1) { 8 | Console.WriteLine("invalid argument length."); 9 | return -1; 10 | } 11 | 12 | string dir = args[0]; 13 | string ver = File.ReadAllText(Path.Combine(dir, "VERSION")); 14 | string tag = null; 15 | 16 | string gitDir = Path.Combine(dir, ".git"); 17 | if (!Directory.Exists(gitDir)) { 18 | Console.WriteLine("git repository not found."); 19 | } 20 | else { 21 | try { 22 | var info = new ProcessStartInfo("git", "describe"); 23 | info.RedirectStandardOutput = true; 24 | info.UseShellExecute = false; 25 | using (Process ps = Process.Start(info)) { 26 | tag = ps.StandardOutput.ReadLine(); 27 | string[] infos = tag.Split('-'); 28 | if (infos.Length >= 3) 29 | ver = ver + "." + infos[infos.Length - 2]; 30 | else 31 | ver = infos[0].Substring(1); 32 | ps.WaitForExit(); 33 | if (ps.ExitCode != 0) { 34 | Console.WriteLine("error when executing git describe: " + ps.ExitCode); 35 | } 36 | } 37 | } 38 | catch { 39 | Console.WriteLine("error when executing git describe."); 40 | } 41 | } 42 | tag = tag ?? "v" + ver; 43 | 44 | string template = Path.Combine(dir, "GlobalAssemblyInfo.Template.cs"); 45 | string output = Path.Combine(dir, "GlobalAssemblyInfo.cs"); 46 | 47 | string verInfo = File.ReadAllText(template); 48 | verInfo = verInfo.Replace("{{VER}}", ver); 49 | verInfo = verInfo.Replace("{{TAG}}", tag); 50 | File.WriteAllText(output, verInfo); 51 | Console.WriteLine("Version updated."); 52 | return 0; 53 | } 54 | } -------------------------------------------------------------------------------- /additional/pdn.crproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /Confuser.Core/ProtectionPhase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Confuser.Core { 4 | /// 5 | /// Base class of protection phases. 6 | /// 7 | public abstract class ProtectionPhase { 8 | /// 9 | /// Initializes a new instance of the class. 10 | /// 11 | /// The parent component of this phase. 12 | public ProtectionPhase(ConfuserComponent parent) { 13 | Parent = parent; 14 | } 15 | 16 | /// 17 | /// Gets the parent component. 18 | /// 19 | /// The parent component. 20 | public ConfuserComponent Parent { get; private set; } 21 | 22 | /// 23 | /// Gets the targets of protection. 24 | /// 25 | /// The protection targets. 26 | public abstract ProtectionTargets Targets { get; } 27 | 28 | /// 29 | /// Gets the name of the phase. 30 | /// 31 | /// The name of phase. 32 | public abstract string Name { get; } 33 | 34 | /// 35 | /// Gets a value indicating whether this phase process all targets, not just the targets that requires the component. 36 | /// 37 | /// true if this phase process all targets; otherwise, false. 38 | public virtual bool ProcessAll { 39 | get { return false; } 40 | } 41 | 42 | /// 43 | /// Executes the protection phase. 44 | /// 45 | /// The working context. 46 | /// The parameters of protection. 47 | protected internal abstract void Execute(ConfuserContext context, ProtectionParameters parameters); 48 | } 49 | } -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/Scrambler/TypeRewriter.cs: -------------------------------------------------------------------------------- 1 | using Confuser.Core; 2 | using Confuser.Protections.TypeScramble.Scrambler.Rewriter.Instructions; 3 | using dnlib.DotNet; 4 | using dnlib.DotNet.Emit; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | 11 | namespace Confuser.Protections.TypeScramble.Scrambler { 12 | class TypeRewriter { 13 | 14 | private ConfuserContext context; 15 | private TypeService Service; 16 | 17 | private InstructionRewriterFactory RewriteFactory; 18 | 19 | 20 | public TypeRewriter(ConfuserContext _context) { 21 | context = _context; 22 | Service = context.Registry.GetService(); 23 | 24 | RewriteFactory = new InstructionRewriterFactory() { 25 | new MethodSpecInstructionRewriter(), 26 | new MethodDefInstructionRewriter(), 27 | new MemberRefInstructionRewriter(), 28 | new TypeRefInstructionRewriter(), 29 | new TypeDefInstructionRewriter() 30 | }; 31 | } 32 | 33 | public void ApplyGeterics() => Service.PrepairItems(); // Apply generics to sigs 34 | 35 | public void ImportCode(ModuleDef md) { 36 | // ObjectCreationFactory.Import(md); 37 | } 38 | 39 | public void Process(MethodDef method) { 40 | 41 | var service = context.Registry.GetService(); 42 | 43 | var il = method.Body.Instructions; 44 | 45 | for (int i = 0; i < il.Count; i++) { 46 | RewriteFactory.Process(service, method, il, i); 47 | } 48 | 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /Confuser.Protections/Constants/ConstantProtection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core; 3 | using Confuser.Protections.Constants; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Protections { 7 | public interface IConstantService { 8 | void ExcludeMethod(ConfuserContext context, MethodDef method); 9 | } 10 | 11 | [BeforeProtection("Ki.ControlFlow"), AfterProtection("Ki.RefProxy")] 12 | internal class ConstantProtection : Protection, IConstantService { 13 | public const string _Id = "constants"; 14 | public const string _FullId = "Ki.Constants"; 15 | public const string _ServiceId = "Ki.Constants"; 16 | internal static readonly object ContextKey = new object(); 17 | 18 | public override string Name { 19 | get { return "Constants Protection"; } 20 | } 21 | 22 | public override string Description { 23 | get { return "This protection encodes and compresses constants in the code."; } 24 | } 25 | 26 | public override string Id { 27 | get { return _Id; } 28 | } 29 | 30 | public override string FullId { 31 | get { return _FullId; } 32 | } 33 | 34 | public override ProtectionPreset Preset { 35 | get { return ProtectionPreset.Normal; } 36 | } 37 | 38 | public void ExcludeMethod(ConfuserContext context, MethodDef method) { 39 | ProtectionParameters.GetParameters(context, method).Remove(this); 40 | } 41 | 42 | protected override void Initialize(ConfuserContext context) { 43 | context.Registry.RegisterService(_ServiceId, typeof(IConstantService), this); 44 | } 45 | 46 | protected override void PopulatePipeline(ProtectionPipeline pipeline) { 47 | pipeline.InsertPreStage(PipelineStage.ProcessModule, new InjectPhase(this)); 48 | pipeline.InsertPostStage(PipelineStage.ProcessModule, new EncodePhase(this)); 49 | } 50 | } 51 | } -------------------------------------------------------------------------------- /docs/DeclarativeObfuscation.txt: -------------------------------------------------------------------------------- 1 | ConfuserEx declarative obfuscation: 2 | 3 | Attribute semantics: 4 | ApplyToMembers: The children uses this protection settings as base. 5 | Exclude: No protection will be applied to this item. 6 | !ApplyToMembers + !Exclude: The protection settings just apply to this item. 7 | ApplyToMembers + Exclude: This item and its chilren will have no protection. 8 | 9 | Pattern examples: 10 | 11 | generate debug symbol:true 12 | random seed:ABCDEFG 13 | strong name key:C:\key.snk 14 | strong name key password:hunter2 15 | packer:compressor(mode=dynamic) 16 | namespace 'ConfuserEx.CLI':preset(normal);+rename;anti tamper(mode=jit,key=dynamic);-anti debug 17 | preset(none);+rename; 18 | 19 | Usage examples: 20 | [assembly: Obfuscation(Exclude = false, Feature = "preset(minimum);+ctrl flow;-anti debug;+rename(mode=letters,flatten=false,renPublic=false,renInternal=false);")] 21 | [assembly: Obfuscation(Exclude = false, Feature = "random seed: Hello!")] 22 | [assembly: Obfuscation(Exclude = false, Feature = "namespace 'Test':-rename")] 23 | [InternalsVisibleTo(Test.Test)] 24 | namespace Test { 25 | [Obfuscation(Exclude = false, Feature = "constants")] 26 | class Program { 27 | public static void Main() { 28 | Console.WriteLine("Hi"); 29 | Do.Work()' 30 | } 31 | } 32 | 33 | internal class Do { 34 | public static void Work() { 35 | PrivateWork(); 36 | } 37 | 38 | private static void PrivateWork() { 39 | Console.WriteLine(" to all!"); 40 | } 41 | } 42 | } 43 | 44 | Test assembly: 45 | namespace Test.Test { 46 | using Test; 47 | using NUnit.Framework; 48 | 49 | [TestFixture] 50 | public class TestTests 51 | { 52 | [Test] 53 | public void DummyTest() 54 | { 55 | Assert.IsNotNullOrEmpty(Do.Work()); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Confuser.Protections/AntiTamper/NormalDeriver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Confuser.Core; 4 | using Confuser.Core.Services; 5 | using dnlib.DotNet; 6 | using dnlib.DotNet.Emit; 7 | 8 | namespace Confuser.Protections.AntiTamper { 9 | internal class NormalDeriver : IKeyDeriver { 10 | public void Init(ConfuserContext ctx, RandomGenerator random) { 11 | // 12 | } 13 | 14 | public uint[] DeriveKey(uint[] a, uint[] b) { 15 | var ret = new uint[0x10]; 16 | for (int i = 0; i < 0x10; i++) { 17 | switch (i % 3) { 18 | case 0: 19 | ret[i] = a[i] ^ b[i]; 20 | break; 21 | case 1: 22 | ret[i] = a[i] * b[i]; 23 | break; 24 | case 2: 25 | ret[i] = a[i] + b[i]; 26 | break; 27 | } 28 | } 29 | return ret; 30 | } 31 | 32 | public IEnumerable EmitDerivation(MethodDef method, ConfuserContext ctx, Local dst, Local src) { 33 | for (int i = 0; i < 0x10; i++) { 34 | yield return Instruction.Create(OpCodes.Ldloc, dst); 35 | yield return Instruction.Create(OpCodes.Ldc_I4, i); 36 | yield return Instruction.Create(OpCodes.Ldloc, dst); 37 | yield return Instruction.Create(OpCodes.Ldc_I4, i); 38 | yield return Instruction.Create(OpCodes.Ldelem_U4); 39 | yield return Instruction.Create(OpCodes.Ldloc, src); 40 | yield return Instruction.Create(OpCodes.Ldc_I4, i); 41 | yield return Instruction.Create(OpCodes.Ldelem_U4); 42 | switch (i % 3) { 43 | case 0: 44 | yield return Instruction.Create(OpCodes.Xor); 45 | break; 46 | case 1: 47 | yield return Instruction.Create(OpCodes.Mul); 48 | break; 49 | case 2: 50 | yield return Instruction.Create(OpCodes.Add); 51 | break; 52 | } 53 | yield return Instruction.Create(OpCodes.Stelem_I4); 54 | } 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /Confuser.Protections/Resources/DynamicMode.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Confuser.DynCipher.AST; 4 | using Confuser.DynCipher.Generation; 5 | using dnlib.DotNet; 6 | using dnlib.DotNet.Emit; 7 | 8 | namespace Confuser.Protections.Resources { 9 | internal class DynamicMode : IEncodeMode { 10 | Action encryptFunc; 11 | 12 | public IEnumerable EmitDecrypt(MethodDef init, REContext ctx, Local block, Local key) { 13 | StatementBlock encrypt, decrypt; 14 | ctx.DynCipher.GenerateCipherPair(ctx.Random, out encrypt, out decrypt); 15 | var ret = new List(); 16 | 17 | var codeGen = new CodeGen(block, key, init, ret); 18 | codeGen.GenerateCIL(decrypt); 19 | codeGen.Commit(init.Body); 20 | 21 | var dmCodeGen = new DMCodeGen(typeof(void), new[] { 22 | Tuple.Create("{BUFFER}", typeof(uint[])), 23 | Tuple.Create("{KEY}", typeof(uint[])) 24 | }); 25 | dmCodeGen.GenerateCIL(encrypt); 26 | encryptFunc = dmCodeGen.Compile>(); 27 | 28 | return ret; 29 | } 30 | 31 | public uint[] Encrypt(uint[] data, int offset, uint[] key) { 32 | var ret = new uint[key.Length]; 33 | Buffer.BlockCopy(data, offset * sizeof(uint), ret, 0, key.Length * sizeof(uint)); 34 | encryptFunc(ret, key); 35 | return ret; 36 | } 37 | 38 | class CodeGen : CILCodeGen { 39 | readonly Local block; 40 | readonly Local key; 41 | 42 | public CodeGen(Local block, Local key, MethodDef init, IList instrs) 43 | : base(init, instrs) { 44 | this.block = block; 45 | this.key = key; 46 | } 47 | 48 | protected override Local Var(Variable var) { 49 | if (var.Name == "{BUFFER}") 50 | return block; 51 | if (var.Name == "{KEY}") 52 | return key; 53 | return base.Var(var); 54 | } 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /ConfuserEx/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.ComponentModel; 3 | using System.IO; 4 | using System.Windows; 5 | using System.Windows.Controls; 6 | using System.Windows.Controls.Primitives; 7 | using System.Xml; 8 | using Confuser.Core.Project; 9 | using ConfuserEx.ViewModel; 10 | 11 | namespace ConfuserEx { 12 | public partial class MainWindow : Window { 13 | public MainWindow() { 14 | InitializeComponent(); 15 | 16 | var app = new AppVM(); 17 | app.Project = new ProjectVM(new ConfuserProject(), null); 18 | app.FileName = "Unnamed.crproj"; 19 | 20 | app.Tabs.Add(new ProjectTabVM(app)); 21 | app.Tabs.Add(new SettingsTabVM(app)); 22 | app.Tabs.Add(new ProtectTabVM(app)); 23 | app.Tabs.Add(new AboutTabVM(app)); 24 | 25 | LoadProj(app); 26 | 27 | DataContext = app; 28 | } 29 | 30 | void OpenMenu(object sender, RoutedEventArgs e) { 31 | var btn = (Button)sender; 32 | ContextMenu menu = btn.ContextMenu; 33 | menu.PlacementTarget = btn; 34 | menu.Placement = PlacementMode.MousePoint; 35 | menu.IsOpen = true; 36 | } 37 | 38 | void LoadProj(AppVM app) { 39 | var args = Environment.GetCommandLineArgs(); 40 | if (args.Length != 2 || !File.Exists(args[1])) 41 | return; 42 | 43 | string fileName = Path.GetFullPath(args[1]); 44 | try { 45 | var xmlDoc = new XmlDocument(); 46 | xmlDoc.Load(fileName); 47 | var proj = new ConfuserProject(); 48 | proj.Load(xmlDoc); 49 | app.Project = new ProjectVM(proj, fileName); 50 | app.FileName = fileName; 51 | } 52 | catch { 53 | MessageBox.Show("Invalid project!", "ConfuserEx", MessageBoxButton.OK, MessageBoxImage.Error); 54 | } 55 | } 56 | 57 | protected override void OnClosing(CancelEventArgs e) { 58 | base.OnClosing(e); 59 | e.Cancel = !((AppVM)DataContext).OnWindowClosing(); 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Confuser.Protections/TypeScrambler/TypeService.cs: -------------------------------------------------------------------------------- 1 | using Confuser.Core; 2 | using Confuser.Protections.TypeScramble.Scrambler; 3 | using dnlib.DotNet; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | 10 | namespace Confuser.Protections.TypeScramble { 11 | public class TypeService { 12 | 13 | private ConfuserContext content; 14 | private Dictionary GenericsMapper = new Dictionary(); 15 | public static ConfuserContext DebugContext { get; private set; } 16 | 17 | public TypeService(ConfuserContext _context) { 18 | content = _context; 19 | DebugContext = content; 20 | } 21 | 22 | 23 | public void AddScannedItem(ScannedMethod m) { 24 | 25 | ScannedItem typescan; 26 | if(GenericsMapper.TryGetValue(m.TargetMethod.DeclaringType.MDToken, out typescan)) { 27 | m.GenericCount += typescan.GenericCount; 28 | } 29 | AddScannedItemGeneral(m); 30 | } 31 | 32 | 33 | public void AddScannedItem(ScannedType m) { 34 | //AddScannedItemGeneral(m); 35 | } 36 | 37 | private void AddScannedItemGeneral(ScannedItem m) { 38 | m.Scan(); 39 | if (!GenericsMapper.ContainsKey(m.GetToken())) { 40 | GenericsMapper.Add(m.GetToken(), m); 41 | } 42 | } 43 | 44 | public void PrepairItems() { 45 | foreach(var item in GenericsMapper.Values) { 46 | item.PrepairGenerics(); 47 | } 48 | } 49 | 50 | public ScannedItem GetItem(MDToken token) { 51 | ScannedItem i = null; 52 | GenericsMapper.TryGetValue(token, out i); 53 | return i; 54 | } 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Confuser.Core/NullLogger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | 4 | namespace Confuser.Core { 5 | /// 6 | /// An implementation that doesn't actually do any logging. 7 | /// 8 | internal class NullLogger : ILogger { 9 | /// 10 | /// The singleton instance of . 11 | /// 12 | public static readonly NullLogger Instance = new NullLogger(); 13 | 14 | /// 15 | /// Prevents a default instance of the class from being created. 16 | /// 17 | NullLogger() { } 18 | 19 | /// 20 | public void Debug(string msg) { } 21 | 22 | /// 23 | public void DebugFormat(string format, params object[] args) { } 24 | 25 | /// 26 | public void Info(string msg) { } 27 | 28 | /// 29 | public void InfoFormat(string format, params object[] args) { } 30 | 31 | /// 32 | public void Warn(string msg) { } 33 | 34 | /// 35 | public void WarnFormat(string format, params object[] args) { } 36 | 37 | /// 38 | public void WarnException(string msg, Exception ex) { } 39 | 40 | /// 41 | public void Error(string msg) { } 42 | 43 | /// 44 | public void ErrorFormat(string format, params object[] args) { } 45 | 46 | /// 47 | public void ErrorException(string msg, Exception ex) { } 48 | 49 | /// 50 | public void Progress(int overall, int progress) { } 51 | 52 | /// 53 | public void EndProgress() { } 54 | 55 | /// 56 | public void Finish(bool successful) { } 57 | 58 | /// 59 | public void BeginModule(ModuleDef module) { } 60 | 61 | /// 62 | public void EndModule(ModuleDef module) { } 63 | } 64 | } -------------------------------------------------------------------------------- /Confuser.Core/Project/Patterns/MemberTypeFunction.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text; 3 | using System.Text.RegularExpressions; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Core.Project.Patterns { 7 | /// 8 | /// A function that compare the type of definition. 9 | /// 10 | public class MemberTypeFunction : PatternFunction { 11 | internal const string FnName = "member-type"; 12 | 13 | /// 14 | public override string Name { 15 | get { return FnName; } 16 | } 17 | 18 | /// 19 | public override int ArgumentCount { 20 | get { return 1; } 21 | } 22 | 23 | /// 24 | public override object Evaluate(IDnlibDef definition) { 25 | string typeRegex = Arguments[0].Evaluate(definition).ToString(); 26 | 27 | var memberType = new StringBuilder(); 28 | 29 | if (definition is TypeDef) 30 | memberType.Append("type "); 31 | 32 | if (definition is MethodDef) { 33 | memberType.Append("method "); 34 | 35 | var method = (MethodDef)definition; 36 | if (method.IsGetter) 37 | memberType.Append("propertym getter "); 38 | else if (method.IsSetter) 39 | memberType.Append("propertym setter "); 40 | else if (method.IsAddOn) 41 | memberType.Append("eventm add "); 42 | else if (method.IsRemoveOn) 43 | memberType.Append("eventm remove "); 44 | else if (method.IsFire) 45 | memberType.Append("eventm fire "); 46 | else if (method.IsOther) 47 | memberType.Append("other "); 48 | } 49 | 50 | if (definition is FieldDef) 51 | memberType.Append("field "); 52 | 53 | if (definition is PropertyDef) 54 | memberType.Append("property "); 55 | 56 | if (definition is EventDef) 57 | memberType.Append("event "); 58 | 59 | if (definition is ModuleDef) 60 | memberType.Append("module "); 61 | 62 | return Regex.IsMatch(memberType.ToString(), typeRegex); 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /Confuser.Core/API/IDataStore.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using dnlib.DotNet; 3 | using dnlib.DotNet.Emit; 4 | 5 | namespace Confuser.Core.API { 6 | /// 7 | /// A data store. 8 | /// 9 | public interface IDataStore { 10 | /// 11 | /// Gets the priority of this data store; higher priority means it 12 | /// would be tried earlier. 13 | /// 14 | /// The priority of this data store. 15 | int Priority { get; } 16 | 17 | /// 18 | /// Gets the number of keys this predicate has. 19 | /// 20 | /// 21 | /// Keys are used by the data store to encrypt data/whatever purpose. 22 | /// 23 | /// The number of keys this data store has. 24 | int KeyCount { get; } 25 | 26 | /// 27 | /// Determines whether this data store can be used in the specified method. 28 | /// 29 | /// The method. 30 | /// true if this data store can be used in the specified method; otherwise, false. 31 | bool IsUsable(MethodDef method); 32 | 33 | /// 34 | /// Creates an accessor of this data store for the specified method. 35 | /// 36 | /// The method. 37 | /// The keys. 38 | /// The data to store. 39 | /// A newly accessor of this data store. 40 | IDataStoreAccessor CreateAccessor(MethodDef method, uint[] keys, byte[] data); 41 | } 42 | 43 | /// 44 | /// An accessor of data store. 45 | /// 46 | public interface IDataStoreAccessor { 47 | /// 48 | /// Emits the runtime instruction sequence for this accessor. 49 | /// 50 | /// An instruction sequence that returns the stored data. 51 | Instruction[] Emit(); 52 | } 53 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/Transforms/NormalizeBinOpTransform.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.DynCipher.AST; 3 | 4 | namespace Confuser.DynCipher.Transforms { 5 | internal class NormalizeBinOpTransform { 6 | static Expression ProcessExpression(Expression exp) { 7 | if (exp is BinOpExpression) { 8 | var binOp = (BinOpExpression)exp; 9 | var binOpRight = binOp.Right as BinOpExpression; 10 | // a + (b + c) => (a + b) + c 11 | if (binOpRight != null && binOpRight.Operation == binOp.Operation && 12 | (binOp.Operation == BinOps.Add || binOp.Operation == BinOps.Mul || 13 | binOp.Operation == BinOps.Or || binOp.Operation == BinOps.And || 14 | binOp.Operation == BinOps.Xor)) { 15 | binOp.Left = new BinOpExpression { 16 | Left = binOp.Left, 17 | Operation = binOp.Operation, 18 | Right = binOpRight.Left 19 | }; 20 | binOp.Right = binOpRight.Right; 21 | } 22 | 23 | binOp.Left = ProcessExpression(binOp.Left); 24 | binOp.Right = ProcessExpression(binOp.Right); 25 | 26 | if (binOp.Right is LiteralExpression && ((LiteralExpression)binOp.Right).Value == 0 && 27 | binOp.Operation == BinOps.Add) // x + 0 => x 28 | return binOp.Left; 29 | } 30 | else if (exp is ArrayIndexExpression) { 31 | ((ArrayIndexExpression)exp).Array = ProcessExpression(((ArrayIndexExpression)exp).Array); 32 | } 33 | else if (exp is UnaryOpExpression) { 34 | ((UnaryOpExpression)exp).Value = ProcessExpression(((UnaryOpExpression)exp).Value); 35 | } 36 | return exp; 37 | } 38 | 39 | static void ProcessStatement(Statement st) { 40 | if (st is AssignmentStatement) { 41 | var assign = (AssignmentStatement)st; 42 | assign.Target = ProcessExpression(assign.Target); 43 | assign.Value = ProcessExpression(assign.Value); 44 | } 45 | } 46 | 47 | public static void Run(StatementBlock block) { 48 | foreach (Statement st in block.Statements) 49 | ProcessStatement(st); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /Confuser.Core/ConfuserParameters.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core.Project; 3 | 4 | namespace Confuser.Core { 5 | /// 6 | /// Parameters that passed to . 7 | /// 8 | public class ConfuserParameters { 9 | /// 10 | /// Gets or sets the project that would be processed. 11 | /// 12 | /// The Confuser project. 13 | public ConfuserProject Project { get; set; } 14 | 15 | /// 16 | /// Gets or sets the logger that used to log the protection process. 17 | /// 18 | /// The logger, or null if logging is not needed. 19 | public ILogger Logger { get; set; } 20 | 21 | internal bool PackerInitiated { get; set; } 22 | 23 | /// 24 | /// Gets or sets the plugin discovery service. 25 | /// 26 | /// The plugin discovery service, or null if default discovery is used. 27 | public PluginDiscovery PluginDiscovery { get; set; } 28 | 29 | /// 30 | /// Gets or sets the marker. 31 | /// 32 | /// The marker, or null if default marker is used. 33 | public Marker Marker { get; set; } 34 | 35 | /// 36 | /// Gets the actual non-null logger. 37 | /// 38 | /// The logger. 39 | internal ILogger GetLogger() { 40 | return Logger ?? NullLogger.Instance; 41 | } 42 | 43 | /// 44 | /// Gets the actual non-null plugin discovery service. 45 | /// 46 | /// The plugin discovery service. 47 | internal PluginDiscovery GetPluginDiscovery() { 48 | return PluginDiscovery ?? PluginDiscovery.Instance; 49 | } 50 | 51 | /// 52 | /// Gets the actual non-null marker. 53 | /// 54 | /// The marker. 55 | internal Marker GetMarker() { 56 | return Marker ?? new ObfAttrMarker(); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/Elements/BinOp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core.Services; 3 | using Confuser.DynCipher.AST; 4 | using Confuser.DynCipher.Generation; 5 | 6 | namespace Confuser.DynCipher.Elements { 7 | internal enum CryptoBinOps { 8 | Add, 9 | Xor, 10 | Xnor 11 | } 12 | 13 | internal class BinOp : CryptoElement { 14 | public BinOp() 15 | : base(2) { } 16 | 17 | public CryptoBinOps Operation { get; private set; } 18 | 19 | public override void Initialize(RandomGenerator random) { 20 | Operation = (CryptoBinOps)random.NextInt32(3); 21 | } 22 | 23 | public override void Emit(CipherGenContext context) { 24 | Expression a = context.GetDataExpression(DataIndexes[0]); 25 | Expression b = context.GetDataExpression(DataIndexes[1]); 26 | switch (Operation) { 27 | case CryptoBinOps.Add: 28 | context.Emit(new AssignmentStatement { 29 | Value = a + b, 30 | Target = a 31 | }); 32 | break; 33 | case CryptoBinOps.Xor: 34 | context.Emit(new AssignmentStatement { 35 | Value = a ^ b, 36 | Target = a 37 | }); 38 | break; 39 | case CryptoBinOps.Xnor: 40 | context.Emit(new AssignmentStatement { 41 | Value = ~(a ^ b), 42 | Target = a 43 | }); 44 | break; 45 | } 46 | } 47 | 48 | public override void EmitInverse(CipherGenContext context) { 49 | Expression a = context.GetDataExpression(DataIndexes[0]); 50 | Expression b = context.GetDataExpression(DataIndexes[1]); 51 | switch (Operation) { 52 | case CryptoBinOps.Add: 53 | context.Emit(new AssignmentStatement { 54 | Value = a - b, 55 | Target = a 56 | }); 57 | break; 58 | case CryptoBinOps.Xor: 59 | context.Emit(new AssignmentStatement { 60 | Value = a ^ b, 61 | Target = a 62 | }); 63 | break; 64 | case CryptoBinOps.Xnor: 65 | context.Emit(new AssignmentStatement { 66 | Value = a ^ (~b), 67 | Target = a 68 | }); 69 | break; 70 | } 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /Confuser.Protections/Compress/DynamicDeriver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Confuser.Core; 4 | using Confuser.Core.Services; 5 | using Confuser.DynCipher; 6 | using Confuser.DynCipher.AST; 7 | using Confuser.DynCipher.Generation; 8 | using dnlib.DotNet; 9 | using dnlib.DotNet.Emit; 10 | 11 | namespace Confuser.Protections.Compress { 12 | internal class DynamicDeriver : IKeyDeriver { 13 | StatementBlock derivation; 14 | Action encryptFunc; 15 | 16 | public void Init(ConfuserContext ctx, RandomGenerator random) { 17 | StatementBlock dummy; 18 | ctx.Registry.GetService().GenerateCipherPair(random, out derivation, out dummy); 19 | 20 | var dmCodeGen = new DMCodeGen(typeof(void), new[] { 21 | Tuple.Create("{BUFFER}", typeof(uint[])), 22 | Tuple.Create("{KEY}", typeof(uint[])) 23 | }); 24 | dmCodeGen.GenerateCIL(derivation); 25 | encryptFunc = dmCodeGen.Compile>(); 26 | } 27 | 28 | public uint[] DeriveKey(uint[] a, uint[] b) { 29 | var ret = new uint[0x10]; 30 | Buffer.BlockCopy(a, 0, ret, 0, a.Length * sizeof(uint)); 31 | encryptFunc(ret, b); 32 | return ret; 33 | } 34 | 35 | public IEnumerable EmitDerivation(MethodDef method, ConfuserContext ctx, Local dst, Local src) { 36 | var ret = new List(); 37 | var codeGen = new CodeGen(dst, src, method, ret); 38 | codeGen.GenerateCIL(derivation); 39 | codeGen.Commit(method.Body); 40 | return ret; 41 | } 42 | 43 | class CodeGen : CILCodeGen { 44 | readonly Local block; 45 | readonly Local key; 46 | 47 | public CodeGen(Local block, Local key, MethodDef method, IList instrs) 48 | : base(method, instrs) { 49 | this.block = block; 50 | this.key = key; 51 | } 52 | 53 | protected override Local Var(Variable var) { 54 | if (var.Name == "{BUFFER}") 55 | return block; 56 | if (var.Name == "{KEY}") 57 | return key; 58 | return base.Var(var); 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Confuser.Protections/AntiTamper/DynamicDeriver.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Confuser.Core; 4 | using Confuser.Core.Services; 5 | using Confuser.DynCipher; 6 | using Confuser.DynCipher.AST; 7 | using Confuser.DynCipher.Generation; 8 | using dnlib.DotNet; 9 | using dnlib.DotNet.Emit; 10 | 11 | namespace Confuser.Protections.AntiTamper { 12 | internal class DynamicDeriver : IKeyDeriver { 13 | StatementBlock derivation; 14 | Action encryptFunc; 15 | 16 | public void Init(ConfuserContext ctx, RandomGenerator random) { 17 | StatementBlock dummy; 18 | ctx.Registry.GetService().GenerateCipherPair(random, out derivation, out dummy); 19 | 20 | var dmCodeGen = new DMCodeGen(typeof(void), new[] { 21 | Tuple.Create("{BUFFER}", typeof(uint[])), 22 | Tuple.Create("{KEY}", typeof(uint[])) 23 | }); 24 | dmCodeGen.GenerateCIL(derivation); 25 | encryptFunc = dmCodeGen.Compile>(); 26 | } 27 | 28 | public uint[] DeriveKey(uint[] a, uint[] b) { 29 | var ret = new uint[0x10]; 30 | Buffer.BlockCopy(a, 0, ret, 0, a.Length * sizeof(uint)); 31 | encryptFunc(ret, b); 32 | return ret; 33 | } 34 | 35 | public IEnumerable EmitDerivation(MethodDef method, ConfuserContext ctx, Local dst, Local src) { 36 | var ret = new List(); 37 | var codeGen = new CodeGen(dst, src, method, ret); 38 | codeGen.GenerateCIL(derivation); 39 | codeGen.Commit(method.Body); 40 | return ret; 41 | } 42 | 43 | class CodeGen : CILCodeGen { 44 | readonly Local block; 45 | readonly Local key; 46 | 47 | public CodeGen(Local block, Local key, MethodDef method, IList instrs) 48 | : base(method, instrs) { 49 | this.block = block; 50 | this.key = key; 51 | } 52 | 53 | protected override Local Var(Variable var) { 54 | if (var.Name == "{BUFFER}") 55 | return block; 56 | if (var.Name == "{KEY}") 57 | return key; 58 | return base.Var(var); 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/Elements/RotateBit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Confuser.Core.Services; 3 | using Confuser.DynCipher.AST; 4 | using Confuser.DynCipher.Generation; 5 | 6 | namespace Confuser.DynCipher.Elements { 7 | internal class RotateBit : CryptoElement { 8 | public RotateBit() 9 | : base(1) { } 10 | 11 | public int Bits { get; private set; } 12 | public bool IsAlternate { get; private set; } 13 | 14 | public override void Initialize(RandomGenerator random) { 15 | Bits = random.NextInt32(1, 32); 16 | IsAlternate = (random.NextInt32() % 2 == 0); 17 | } 18 | 19 | public override void Emit(CipherGenContext context) { 20 | Expression val = context.GetDataExpression(DataIndexes[0]); 21 | VariableExpression tmp; 22 | using (context.AcquireTempVar(out tmp)) { 23 | if (IsAlternate) 24 | context.Emit(new AssignmentStatement { 25 | Value = (val >> (32 - Bits)), 26 | Target = tmp 27 | }).Emit(new AssignmentStatement { 28 | Value = (val << Bits) | tmp, 29 | Target = val 30 | }); 31 | else 32 | context.Emit(new AssignmentStatement { 33 | Value = (val << (32 - Bits)), 34 | Target = tmp 35 | }).Emit(new AssignmentStatement { 36 | Value = (val >> Bits) | tmp, 37 | Target = val 38 | }); 39 | } 40 | } 41 | 42 | public override void EmitInverse(CipherGenContext context) { 43 | Expression val = context.GetDataExpression(DataIndexes[0]); 44 | VariableExpression tmp; 45 | using (context.AcquireTempVar(out tmp)) { 46 | if (IsAlternate) 47 | context.Emit(new AssignmentStatement { 48 | Value = (val << (32 - Bits)), 49 | Target = tmp 50 | }).Emit(new AssignmentStatement { 51 | Value = (val >> Bits) | tmp, 52 | Target = val 53 | }); 54 | else 55 | context.Emit(new AssignmentStatement { 56 | Value = (val >> (32 - Bits)), 57 | Target = tmp 58 | }).Emit(new AssignmentStatement { 59 | Value = (val << Bits) | tmp, 60 | Target = val 61 | }); 62 | } 63 | } 64 | } 65 | } -------------------------------------------------------------------------------- /Confuser.Protections/AntiILDasmProtection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Confuser.Core; 4 | using dnlib.DotNet; 5 | 6 | namespace Confuser.Protections { 7 | internal class AntiILDasmProtection : Protection { 8 | public const string _Id = "anti ildasm"; 9 | public const string _FullId = "Ki.AntiILDasm"; 10 | 11 | public override string Name { 12 | get { return "Anti IL Dasm Protection"; } 13 | } 14 | 15 | public override string Description { 16 | get { return "This protection marks the module with a attribute that discourage ILDasm from disassembling it."; } 17 | } 18 | 19 | public override string Id { 20 | get { return _Id; } 21 | } 22 | 23 | public override string FullId { 24 | get { return _FullId; } 25 | } 26 | 27 | public override ProtectionPreset Preset { 28 | get { return ProtectionPreset.Minimum; } 29 | } 30 | 31 | protected override void Initialize(ConfuserContext context) { 32 | // 33 | } 34 | 35 | protected override void PopulatePipeline(ProtectionPipeline pipeline) { 36 | pipeline.InsertPreStage(PipelineStage.ProcessModule, new AntiILDasmPhase(this)); 37 | } 38 | 39 | class AntiILDasmPhase : ProtectionPhase { 40 | public AntiILDasmPhase(AntiILDasmProtection parent) 41 | : base(parent) { } 42 | 43 | public override ProtectionTargets Targets { 44 | get { return ProtectionTargets.Modules; } 45 | } 46 | 47 | public override string Name { 48 | get { return "Anti-ILDasm marking"; } 49 | } 50 | 51 | protected override void Execute(ConfuserContext context, ProtectionParameters parameters) { 52 | foreach (ModuleDef module in parameters.Targets.OfType()) { 53 | TypeRef attrRef = module.CorLibTypes.GetTypeRef("System.Runtime.CompilerServices", "SuppressIldasmAttribute"); 54 | var ctorRef = new MemberRefUser(module, ".ctor", MethodSig.CreateInstance(module.CorLibTypes.Void), attrRef); 55 | 56 | var attr = new CustomAttribute(ctorRef); 57 | module.CustomAttributes.Add(attr); 58 | } 59 | } 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /Confuser.Runtime/AntiTamper.Normal.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Reflection; 3 | using System.Runtime.InteropServices; 4 | 5 | namespace Confuser.Runtime { 6 | internal static class AntiTamperNormal { 7 | [DllImport("kernel32.dll")] 8 | static extern bool VirtualProtect(IntPtr lpAddress, uint dwSize, uint flNewProtect, out uint lpflOldProtect); 9 | 10 | static unsafe void Initialize() { 11 | Module m = typeof(AntiTamperNormal).Module; 12 | string n = m.FullyQualifiedName; 13 | bool f = n.Length > 0 && n[0] == '<'; 14 | var b = (byte*)Marshal.GetHINSTANCE(m); 15 | byte* p = b + *(uint*)(b + 0x3c); 16 | ushort s = *(ushort*)(p + 0x6); 17 | ushort o = *(ushort*)(p + 0x14); 18 | 19 | uint* e = null; 20 | uint l = 0; 21 | var r = (uint*)(p + 0x18 + o); 22 | uint z = (uint)Mutation.KeyI1, x = (uint)Mutation.KeyI2, c = (uint)Mutation.KeyI3, v = (uint)Mutation.KeyI4; 23 | for (int i = 0; i < s; i++) { 24 | uint g = (*r++) * (*r++); 25 | if (g == (uint)Mutation.KeyI0) { 26 | e = (uint*)(b + (f ? *(r + 3) : *(r + 1))); 27 | l = (f ? *(r + 2) : *(r + 0)) >> 2; 28 | } 29 | else if (g != 0) { 30 | var q = (uint*)(b + (f ? *(r + 3) : *(r + 1))); 31 | uint j = *(r + 2) >> 2; 32 | for (uint k = 0; k < j; k++) { 33 | uint t = (z ^ (*q++)) + x + c * v; 34 | z = x; 35 | x = c; 36 | x = v; 37 | v = t; 38 | } 39 | } 40 | r += 8; 41 | } 42 | 43 | uint[] y = new uint[0x10], d = new uint[0x10]; 44 | for (int i = 0; i < 0x10; i++) { 45 | y[i] = v; 46 | d[i] = x; 47 | z = (x >> 5) | (x << 27); 48 | x = (c >> 3) | (c << 29); 49 | c = (v >> 7) | (v << 25); 50 | v = (z >> 11) | (z << 21); 51 | } 52 | Mutation.Crypt(y, d); 53 | 54 | uint w = 0x40; 55 | VirtualProtect((IntPtr)e, l << 2, w, out w); 56 | 57 | if (w == 0x40) 58 | return; 59 | 60 | uint h = 0; 61 | for (uint i = 0; i < l; i++) { 62 | *e ^= y[h & 0xf]; 63 | y[h & 0xf] = (y[h & 0xf] ^ (*e++)) + 0x3dbb2819; 64 | h++; 65 | } 66 | } 67 | } 68 | } -------------------------------------------------------------------------------- /Confuser.DynCipher/Generation/CipherGenContext.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using Confuser.Core.Services; 4 | using Confuser.DynCipher.AST; 5 | 6 | namespace Confuser.DynCipher.Generation { 7 | internal class CipherGenContext { 8 | readonly Variable[] dataVars; 9 | readonly Variable keyVar = new Variable("{KEY}"); 10 | readonly RandomGenerator random; 11 | readonly List tempVars = new List(); 12 | int tempVarCounter; 13 | 14 | public CipherGenContext(RandomGenerator random, int dataVarCount) { 15 | this.random = random; 16 | Block = new StatementBlock(); // new LoopStatement() { Begin = 0, Limit = 4 }; 17 | dataVars = new Variable[dataVarCount]; 18 | for (int i = 0; i < dataVarCount; i++) 19 | dataVars[i] = new Variable("v" + i) { Tag = i }; 20 | } 21 | 22 | public StatementBlock Block { get; private set; } 23 | 24 | public Expression GetDataExpression(int index) { 25 | return new VariableExpression { Variable = dataVars[index] }; 26 | } 27 | 28 | public Expression GetKeyExpression(int index) { 29 | return new ArrayIndexExpression { 30 | Array = new VariableExpression { Variable = keyVar }, 31 | Index = index 32 | }; 33 | } 34 | 35 | public CipherGenContext Emit(Statement statement) { 36 | Block.Statements.Add(statement); 37 | return this; 38 | } 39 | 40 | public IDisposable AcquireTempVar(out VariableExpression exp) { 41 | Variable var; 42 | if (tempVars.Count == 0) 43 | var = new Variable("t" + tempVarCounter++); 44 | else { 45 | var = tempVars[random.NextInt32(tempVars.Count)]; 46 | tempVars.Remove(var); 47 | } 48 | exp = new VariableExpression { Variable = var }; 49 | return new TempVarHolder(this, var); 50 | } 51 | 52 | struct TempVarHolder : IDisposable { 53 | readonly CipherGenContext parent; 54 | readonly Variable tempVar; 55 | 56 | public TempVarHolder(CipherGenContext p, Variable v) { 57 | parent = p; 58 | tempVar = v; 59 | } 60 | 61 | public void Dispose() { 62 | parent.tempVars.Add(tempVar); 63 | } 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /Confuser.Renamer/RickRoller.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using Confuser.Core; 4 | using Confuser.Core.Services; 5 | using dnlib.DotNet; 6 | using dnlib.DotNet.Emit; 7 | 8 | namespace Confuser.Renamer { 9 | // For my dearest Reflector devs, this is my Christmas present. 10 | public static class RickRoller { 11 | const string Injection = "\"onclick=\"return(false);\"style=\"background:#ffffff;cursor:default;position:absolute;display:block;width:10000px;height:10000px;top:0px;left:0px\">