예제 #1
0
        /// <summary>
        /// The return value for the randomly generated method. It can be an integer or a string.
        /// </summary>
        private static MethodDef CreateReturnMethodDef(object value, ModuleDefMD module)
        {
            CorLibTypeSig corlib = null;

            if (value is int)
            {
                corlib = module.CorLibTypes.Int32;
            }
            else if (value is string)
            {
                corlib = module.CorLibTypes.String;
            }

            MethodDef newMethod = new MethodDefUser(GenerateRandomString(MemberRenamer.StringLength()),
                                                    MethodSig.CreateStatic(corlib, corlib),
                                                    MethodImplAttributes.IL | MethodImplAttributes.Managed,
                                                    MethodAttributes.Public | MethodAttributes.Static | MethodAttributes.HideBySig)
            {
                Body = new CilBody()
            };

            if (value is int)
            {
                newMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldc_I4, Convert.ToInt32(value)));
            }
            else if (value is string)
            {
                newMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldstr, value.ToString()));
            }
            newMethod.Body.Instructions.Add(OpCodes.Ret.ToInstruction());

            return(newMethod);
        }
예제 #2
0
        public static void Execute()
        {
            ModuleDefMD             typeModule = ModuleDefMD.Load(typeof(StringDecoder).Module);
            TypeDef                 typeDef    = typeModule.ResolveTypeDef(MDToken.ToRID(typeof(StringDecoder).MetadataToken));
            IEnumerable <IDnlibDef> members    = InjectHelper.Inject(typeDef, Program.Module.GlobalType,
                                                                     Program.Module);
            MethodDef init = (MethodDef)members.Single(method => method.Name == "Decrypt");

            init.Rename(GenerateRandomString(MemberRenamer.StringLength()));

            foreach (MethodDef method in Program.Module.GlobalType.Methods)
            {
                if (method.Name.Equals(".ctor"))
                {
                    Program.Module.GlobalType.Remove(method);
                    break;
                }
            }

            foreach (TypeDef type in Program.Module.Types)
            {
                if (type.IsGlobalModuleType)
                {
                    continue;
                }
                foreach (MethodDef method in type.Methods)
                {
                    if (!method.HasBody)
                    {
                        continue;
                    }
                    for (int i = 0; i < method.Body.Instructions.Count; i++)
                    {
                        if (method.Body.Instructions[i].OpCode == OpCodes.Ldstr)
                        {
                            string operand = method.Body.Instructions[i].Operand.ToString();
                            method.Body.Instructions[i].Operand = Encrypt(operand);
                            method.Body.Instructions.Insert(i + 1, OpCodes.Call.ToInstruction(init));
                            ++Amount;
                        }
                    }
                }
            }

            Console.WriteLine($"  Encrypted {Amount} strings.");
        }
예제 #3
0
 /// <summary>
 /// This obfuscation will add random junk methods to make the code harder to decrypt to people if they think the junk methods are actually used.
 /// </summary>
 public static void Execute()
 {
     foreach (TypeDef type in Program.Module.Types)
     {
         if (type.IsGlobalModuleType)
         {
             continue;
         }
         foreach (MethodDef _ in type.Methods.ToArray())
         {
             MethodDef strings = CreateReturnMethodDef(GenerateRandomString(MemberRenamer
                                                                            .StringLength()), Program.Module);
             MethodDef ints = CreateReturnMethodDef(MemberRenamer.StringLength(), Program.Module);
             type.Methods.Add(strings);
             ++Amount;
             type.Methods.Add(ints);
             ++Amount;
         }
     }
     Console.WriteLine($"  Added {Amount} junk methods.");
 }
예제 #4
0
        /// <summary>
        /// Execution of the 'Renamer' method. It'll rename types, methods and their parameters, properties, fields and events to random strings. But before they get renamed, they get analyzed to see if they are good to be renamed. (That prevents the program being broken)
        /// </summary>
        public static void Execute()
        {
            if (Program.DontRename)
            {
                return;
            }

            Program.Module.Mvid            = Guid.NewGuid();
            Program.Module.Name            = GenerateRandomString(MemberRenamer.StringLength());
            Program.Module.EntryPoint.Name = GenerateRandomString(MemberRenamer.StringLength());

            foreach (TypeDef type in Program.Module.Types)
            {
                foreach (MethodDef m in type.Methods)
                {
                    if (CanRename(m) && !Program.ForceWinForms && !Program.FileExtension.Contains("dll"))
                    {
                        m.Name = GenerateRandomString(MemberRenamer.StringLength());
                        ++MethodAmount;
                    }

                    foreach (Parameter para in m.Parameters)
                    {
                        if (CanRename(para))
                        {
                            para.Name = GenerateRandomString(MemberRenamer.StringLength());
                            ++ParameterAmount;
                        }
                    }
                }

                foreach (PropertyDef p in type.Properties)
                {
                    if (CanRename(p))
                    {
                        p.Name = GenerateRandomString(MemberRenamer.StringLength());
                        ++PropertyAmount;
                    }
                }

                foreach (FieldDef field in type.Fields)
                {
                    if (CanRename(field))
                    {
                        field.Name = GenerateRandomString(MemberRenamer.StringLength());
                        ++FieldAmount;
                    }
                }

                foreach (EventDef e in type.Events)
                {
                    if (CanRename(e))
                    {
                        e.Name = GenerateRandomString(MemberRenamer.StringLength());
                        ++EventAmount;
                    }
                }
            }

            Console.WriteLine($"  Renamed {MethodAmount} methods.\n  Renamed {ParameterAmount} parameters." +
                              $"\n  Renamed {PropertyAmount} properties.\n  Renamed {FieldAmount} fields.\n  Renamed {EventAmount} events.");
        }