0

我一直在尝试为美好的一天注入一种类型和方法,哈哈。嗯。这是一些代码:我基本上只是想用 Simpy.Simp 替换 System.Convert.FromBase64String 但我似乎无法让它工作......(我使用了来自https://github的 InjectHelper.cs .com/yck1509/ConfuserEx/blob/master/Confuser.Core/Helpers/InjectHelper.cs)和来自https://github.com/yck1509/dnlib/tree/532c767a9a4f6af51cd4eb5d1c0af750c8509c5d的修改后的 dnlib

ModuleDefMD moduleDefMD = ModuleDefMD.Load(typeof(runtime).Module);
        TypeDef type = new TypeDefUser("Simpy");
        type.Attributes = TypeAttributes.AutoLayout | TypeAttributes.Class;
        moduleDef.Types.Add(type);
        TypeDef typeDef = moduleDefMD.ResolveTypeDef(MDToken.ToRID(typeof(Simpy).MetadataToken));
        //InjectHelper.Inject(typeDef, type, moduleDef);
        IEnumerable<IDnlibDef> source = InjectHelper.Inject(typeDef, type, moduleDef);
        init = (MethodDef)source.Single((IDnlibDef method) => method.Name == "Simp");
        foreach (TypeDef typeDef2 in moduleDef.Types)
        {
            foreach (MethodDef methodDef in typeDef2.Methods)
            {
                bool flag = methodDef.Body == null;
                if (!flag)
                {
                    methodDef.Body.SimplifyBranches();
                    for (int i = 0; i < methodDef.Body.Instructions.Count; i++)
                    {
                        bool flag2 = methodDef.Body.Instructions[i].OpCode == OpCodes.Ldstr;
                        if (flag2)
                        {
                            string s = methodDef.Body.Instructions[i].Operand.ToString();
                            string text = Convert.ToBase64String(Encoding.UTF8.GetBytes(s));
                            methodDef.Body.Instructions[i].OpCode = OpCodes.Nop;
                            methodDef.Body.Instructions.Insert(i + 1, new Instruction(OpCodes.Call, moduleDef.Import(typeof(Encoding).GetMethod("get_UTF8", new Type[0]))));
                            methodDef.Body.Instructions.Insert(i + 2, new Instruction(OpCodes.Ldstr, text));
                            methodDef.Body.Instructions.Insert(i + 3, new Instruction(OpCodes.Call, init));
                            methodDef.Body.Instructions.Insert(i + 4, new Instruction(OpCodes.Callvirt, moduleDef.Import(typeof(Encoding).GetMethod("GetString", new Type[]
                            {
                                typeof(byte[])
                            }))));
                            i += 4;
                        }
                    }
                }
            }
        }
4

0 回答 0