1

我正在创建自己的程序来通过 dnlib 更改 .exe 代码。
然后我想通过 IL 和 Dnlib 代码创建一个字典。
但是两者的教程都不多,所以很难。
它编写了错误的字典代码并使 DnSpy 崩溃。
我的代码:

            MethodDef cctor = Module.GlobalType.FindOrCreateStaticConstructor();
        IList<Instruction> inst = cctor.Body.Instructions;
        var objectCtor = new MemberRefUser(Module, ".ctor",
                    MethodSig.CreateInstance(Module.CorLibTypes.Void),
                    Module.CorLibTypes.Object.TypeDefOrRef);
        var Global_Array = new FieldDefUser(
"field_obfuscator_array",
new FieldSig(Module.CorLibTypes.GetCorLibTypeSig(,
FieldAttributes.Public | FieldAttributes.Static);
        Module.GlobalType.Fields.Add(Global_Array);
        if (inst.Count < 1)
            inst.Add(new Instruction(OpCodes.Ret));
        inst.Insert(0, new Instruction(OpCodes.Ldc_I4, 100000));
        inst.Insert(1, new Instruction(OpCodes.Newobj, "[mscorlib]System.Collections.Generic.Dictionary`2"));
        inst.Insert(2, new Instruction(OpCodes.Stsfld, Global_Array));

任何帮助都非常感谢,谢谢!

4

0 回答 0