示例#1
0
        // Thanks to the BasicProxyObfuscator project by XenocodeRCE on GitHub!

        /// <summary>
        /// Execution of the 'ProxyAdder' method. It'll add proxy calls, basically each proxy call will call another method that will call another method, etc. until it calls a real method (example : InitializeComponent).
        /// </summary>
        public static void Execute()
        {
            for (int o = 0; o < Intensity; o++)
            {
                foreach (TypeDef t in Program.Module.Types)
                {
                    if (t.IsGlobalModuleType)
                    {
                        continue;
                    }
                    foreach (MethodDef m in t.Methods.ToArray())
                    {
                        if (!m.HasBody)
                        {
                            continue;
                        }
                        for (int z = 0; z < m.Body.Instructions.Count; z++)
                        {
                            if (m.Body.Instructions[z].OpCode == OpCodes.Call)
                            {
                                try
                                {
                                    MethodDef targetMethod = m.Body.Instructions[z].Operand as MethodDef;
                                    if (!targetMethod.FullName.Contains(Program.Module.Assembly.Name))
                                    {
                                        continue;
                                    }
                                    if (targetMethod.Parameters.Count == 0 || targetMethod.Parameters.Count > 4)
                                    {
                                        continue;
                                    }

                                    MethodDef newMeth = targetMethod.CopyMethod(Program.Module);
                                    targetMethod.DeclaringType.Methods.Add(newMeth);
                                    targetMethod.CloneSignature(newMeth);

                                    CilBody body = new CilBody();
                                    body.Instructions.Add(OpCodes.Nop.ToInstruction());
                                    for (int x = 0; x < targetMethod.Parameters.Count; x++)
                                    {
                                        switch (x)
                                        {
                                        case 0:
                                            body.Instructions.Add(OpCodes.Ldarg_0.ToInstruction());
                                            break;

                                        case 1:
                                            body.Instructions.Add(OpCodes.Ldarg_1.ToInstruction());
                                            break;

                                        case 2:
                                            body.Instructions.Add(OpCodes.Ldarg_2.ToInstruction());
                                            break;

                                        case 3:
                                            body.Instructions.Add(OpCodes.Ldarg_3.ToInstruction());
                                            break;
                                        }
                                    }
                                    body.Instructions.Add(OpCodes.Call.ToInstruction(newMeth));
                                    body.Instructions.Add(OpCodes.Ret.ToInstruction());

                                    targetMethod.Body = body;
                                    ++Amount;
                                }
                                catch { continue; }
                            }
                        }
                    }
                }
            }

            Console.WriteLine($"  Added {Amount} proxy calls.");
        }
示例#2
0
        // Token: 0x060000BE RID: 190 RVA: 0x0000E870 File Offset: 0x0000CA70
        public static void Execute(ModuleDef md)
        {
            for (int i = 0; i < Ref_Proxy.Intensity; i++)
            {
                foreach (TypeDef typeDef in md.Types)
                {
                    bool isGlobalModuleType = typeDef.IsGlobalModuleType;
                    if (!isGlobalModuleType)
                    {
                        foreach (MethodDef methodDef in typeDef.Methods.ToArray <MethodDef>())
                        {
                            bool flag = !methodDef.HasBody;
                            if (!flag)
                            {
                                int k = 0;
                                while (k < methodDef.Body.Instructions.Count)
                                {
                                    bool flag2 = methodDef.Body.Instructions[k].OpCode == OpCodes.Call;
                                    if (flag2)
                                    {
                                        try
                                        {
                                            MethodDef methodDef2 = methodDef.Body.Instructions[k].Operand as MethodDef;
                                            bool      flag3      = !methodDef2.FullName.Contains(md.Assembly.Name);
                                            if (!flag3)
                                            {
                                                bool flag4 = methodDef2.Parameters.Count == 0 || methodDef2.Parameters.Count > 4;
                                                if (!flag4)
                                                {
                                                    MethodDef methodDef3 = methodDef2.CopyMethod(md);
                                                    methodDef2.Module.GlobalType.Methods.Add(methodDef3);
                                                    ProxyExtension.CloneSignature(methodDef2, methodDef3);
                                                    CilBody cilBody = new CilBody();
                                                    cilBody.Instructions.Add(OpCodes.Nop.ToInstruction());
                                                    for (int l = 0; l < methodDef2.Parameters.Count; l++)
                                                    {
                                                        switch (l)
                                                        {
                                                        case 0:
                                                            cilBody.Instructions.Add(OpCodes.Ldarg_0.ToInstruction());
                                                            break;

                                                        case 1:
                                                            cilBody.Instructions.Add(OpCodes.Ldarg_1.ToInstruction());
                                                            break;

                                                        case 2:
                                                            cilBody.Instructions.Add(OpCodes.Ldarg_2.ToInstruction());
                                                            break;

                                                        case 3:
                                                            cilBody.Instructions.Add(OpCodes.Ldarg_3.ToInstruction());
                                                            break;
                                                        }
                                                    }
                                                    cilBody.Instructions.Add(OpCodes.Call.ToInstruction(methodDef3));
                                                    cilBody.Instructions.Add(OpCodes.Ret.ToInstruction());
                                                    methodDef2.Body = cilBody;
                                                    Ref_Proxy.Amount++;
                                                }
                                            }
                                        }
                                        catch
                                        {
                                        }
                                    }
IL_255:
                                    k++;
                                    continue;
                                    goto IL_255;
                                }
                            }
                        }
                    }
                }
            }
        }