Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#加载原始字节_C#_.net Assembly - Fatal编程技术网

C#加载原始字节

C#加载原始字节,c#,.net-assembly,C#,.net Assembly,我已经开发了一个小型的解密和执行应用程序,我被困在执行部分。 我使用以下方法成功执行.NET程序集: Assembly asm = Assembly.Load(decryptedBytes); if (asm.EntryPoint == null) throw new ApplicationException("No entry point found!"); MethodInfo ePoint = asm.EntryPoint; object ins = asm.Cr

我已经开发了一个小型的解密和执行应用程序,我被困在执行部分。 我使用以下方法成功执行.NET程序集:

 Assembly asm = Assembly.Load(decryptedBytes);   
 if (asm.EntryPoint == null)
     throw new ApplicationException("No entry point found!");

 MethodInfo ePoint = asm.EntryPoint;
 object ins = asm.CreateInstance(ePoint.Name);
 ePoint.Invoke(ins, null);
但是,当我尝试使用此方法分配可执行区域时,应用程序崩溃

我得到的唯一有用的信息是:

Fault Module Name:  StackHash_0a9e
这是我的密码:

  const uint PAGE_EXECUTE_READWRITE = 0x40;
  const uint MEM_COMMIT = 0x1000;

  [DllImport("kernel32.dll", SetLastError = true)]
  static extern IntPtr VirtualAlloc(IntPtr lpAddress, uint dwSize, uint flAllocationType, uint flProtect);

  private delegate int IntReturner();

IntPtr buf = VirtualAlloc(IntPtr.Zero, (uint)decryptedBytes.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
Marshal.Copy(decryptedBytes, 0, buf, decryptedBytes.Length);

IntReturner ptr = (IntReturner)Marshal.GetDelegateForFunctionPointer(buf, typeof(IntReturner));
Console.WriteLine(ptr());

VirtualAlloc返回什么?可能为空。是否确实需要Assembly.Load和VirtualAlloc?您链接的问题涉及本机代码执行…我需要执行所有.exe应用程序。我根本不喜欢这个领域,也不知道该怎么做。有什么建议吗?这可能会有所帮助:在这个项目中,程序集是在服务器上编译的,它的原始字节被传输到Silverlight客户端,在那里它被加载到AssemblyPart中。