我究竟做错了什么?我正在尝试创建 LoadLibraryA 的导出函数并将其注入程序集中。
TypeReference stringType = asm.MainModule.Import(typeof(String));
TypeReference nativeIntType = asm.MainModule.Import(typeof(IntPtr));
ModuleReference kernel32Ref = new ModuleReference("kernel32");
asm.MainModule.ModuleReferences.Add(kernel32Ref);
MethodDefinition loadLibraryA = new MethodDefinition("LoadLibraryA", Mono.Cecil.MethodAttributes.Public |
Mono.Cecil.MethodAttributes.HideBySig | Mono.Cecil.MethodAttributes.Static |
Mono.Cecil.MethodAttributes.PInvokeImpl, nativeIntType);
loadLibraryA.PInvokeInfo = new PInvokeInfo(PInvokeAttributes.NoMangle | PInvokeAttributes.CharSetAnsi
| PInvokeAttributes.SupportsLastError | PInvokeAttributes.CallConvWinapi, "LoadLibraryA", kernel32Ref);
loadLibraryA.Parameters.Add(new ParameterDefinition("name", Mono.Cecil.ParameterAttributes.None, stringType));