public void Execute(ModuleDefMD md)
 {
     foreach (var type in md.Types)
     {
         foreach (var method in type.Methods.Where(x => !x.IsConstructor && !x.IsVirtual))
         {
             Renamer.Rename(method, Renamer.RenameMode.Invalid, 69);
         }
     }
 }
示例#2
0
        public void Execute(ModuleDefMD md)
        {
            var      consttype = RuntimeHelper.GetRuntimeType("AsStrongAsFuck.Runtime.Constants");
            FieldDef field     = consttype.FindField("array");

            Renamer.Rename(field, Renamer.RenameMode.Base64, 2);
            field.DeclaringType = null;
            foreach (TypeDef type in md.Types)
            {
                foreach (MethodDef method in type.Methods)
                {
                    if (method.HasBody && method.Body.HasInstructions)
                    {
                        ExtractStrings(method);
                    }
                }
            }
            md.GlobalType.Fields.Add(field);
            MethodDef todef = consttype.FindMethod("Get");

            todef.DeclaringType = null;
            todef.Body.Instructions[59].Operand = field;
            Renamer.Rename(todef, Renamer.RenameMode.Logical);
            md.GlobalType.Methods.Add(todef);
            MethodDef init = consttype.FindMethod("Initialize");
            MethodDef add  = consttype.FindMethod("Set");

            init.DeclaringType = null;
            init.Body.Instructions[3].Operand = field;
            List <Instruction> insts = new List <Instruction>(add.Body.Instructions);

            insts[1].Operand = field;
            insts[insts.Count - 1].OpCode = OpCodes.Nop;
            insts.RemoveAt(0);
            insts[1].OpCode = OpCodes.Ldc_I4;
            insts[2].OpCode = OpCodes.Ldc_I4;

            var compressed = Compress(array.ToArray());


            for (int i = 0; i < compressed.Length; i++)
            {
                insts[1].Operand = i;
                insts[2].Operand = Convert.ToInt32(compressed[i]);
                for (int x = insts.Count - 1; x >= 0; x--)
                {
                    init.Body.Instructions.Insert(4, new Instruction(insts[x].OpCode, insts[x].Operand));
                }
            }
            init.Body.Instructions[init.Body.Instructions.Count - 1 - 1].Operand  = field;
            init.Body.Instructions[init.Body.Instructions.Count - 1 - 99].Operand = field;
            Renamer.Rename(init, Renamer.RenameMode.Base64, 2);
            md.GlobalType.Methods.Add(init);
            Decryptor = todef;
            MethodDef cctor = md.GlobalType.FindOrCreateStaticConstructor();

            cctor.Body = new CilBody();
            cctor.Body.Instructions.Add(new Instruction(OpCodes.Ldc_I4, compressed.Length));
            cctor.Body.Instructions.Add(new Instruction(OpCodes.Call, init));
            cctor.Body.Instructions.Add(new Instruction(OpCodes.Ret));
            foreach (TypeDef type2 in md.Types)
            {
                foreach (MethodDef method2 in type2.Methods)
                {
                    if (method2.HasBody && method2.Body.HasInstructions)
                    {
                        ReferenceReplace(method2);
                    }
                }
            }
        }
示例#3
0
        public void ExecuteMethod(MethodDef method)
        {
            for (int i = 0; i < method.Body.Instructions.Count; i++)
            {
                var instr = method.Body.Instructions[i];
                if (instr.OpCode == OpCodes.Call)
                {
                    var target = (IMethod)instr.Operand;
                    if (!target.ResolveMethodDefThrow().IsPublic || !target.ResolveMethodDefThrow().IsStatic || !target.DeclaringType.ResolveTypeDef().IsPublic || target.DeclaringType.ResolveTypeDef().IsSealed)
                    {
                        continue;
                    }

                    var       key = target.FullName;
                    MethodDef value;
                    if (!Proxies.TryGetValue(key, out value))
                    {
                        var consttype = RuntimeHelper.GetRuntimeType("AsStrongAsFuck.Runtime.RefProxy");

                        var proxysig = ReferenceProxyHelper.CreateProxySignature(target, method.Module);

                        var deleg = ReferenceProxyHelper.CreateDelegateType(proxysig, method.Module, target.ResolveMethodDef());

                        FieldDefUser field = new FieldDefUser("ZYXDNGuarder", new FieldSig(deleg.ToTypeSig()));

                        Renamer.Rename(field, Renamer.RenameMode.Base64);
                        method.DeclaringType.Fields.Add(field);
                        field.IsStatic = true;

                        var typedef = target.ResolveMethodDefThrow().DeclaringType;

                        var mdtoken = target.ResolveMethodDef().MDToken;
                        var asshole = consttype.Methods.First(x => x.Name == "Load");
                        asshole.Body.Instructions[1].Operand  = deleg;
                        asshole.Body.Instructions[3].Operand  = method.Module.Import(typedef);
                        asshole.Body.Instructions[6].OpCode   = OpCodes.Ldc_I4;
                        asshole.Body.Instructions[6].Operand  = (int)mdtoken.Raw;
                        asshole.Body.Instructions[10].Operand = deleg;
                        asshole.Body.Instructions[11].Operand = field;
                        asshole.Body.Instructions.RemoveAt(12);

                        var cctor = method.DeclaringType.FindOrCreateStaticConstructor();
                        foreach (var item in asshole.Body.Instructions)
                        {
                            cctor.Body.Instructions.Add(item);
                        }

                        if (cctor.Body.Instructions[0].OpCode == OpCodes.Ret)
                        {
                            cctor.Body.Instructions.RemoveAt(0);
                        }


                        var proxy = new MethodDefUser(Renamer.GetRandomName(), proxysig);

                        proxy.Attributes     = MethodAttributes.PrivateScope | MethodAttributes.Static;
                        proxy.ImplAttributes = MethodImplAttributes.Managed | MethodImplAttributes.IL;

                        method.DeclaringType.Methods.Add(proxy);

                        proxy.Body = new CilBody();
                        proxy.Body.Instructions.Add(Instruction.Create(OpCodes.Ldsfld, field));
                        for (int x = 0; x < target.ResolveMethodDefThrow().Parameters.Count; x++)
                        {
                            proxy.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg, proxy.Parameters[x]));
                        }
                        proxy.Body.Instructions.Add(Instruction.Create(OpCodes.Callvirt, deleg.FindMethod("Invoke")));
                        proxy.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));

                        value = proxy;
                        Proxies.Add(key, value);
                    }
                    Console.WriteLine($"{key} - {value}");
                    instr.Operand = value;
                }
            }
        }