当前位置: 代码迷 >> 汇编语言 >> ,各位请帮小弟我看这个汇编内联有关问题,多谢
  详细解决方案

,各位请帮小弟我看这个汇编内联有关问题,多谢

热度:173   发布时间:2016-05-02 04:31:16.0
求助,各位请帮我看这个汇编内联问题,谢谢!
是这样的:
有 1段 在 C++ 里的代码
__asm 
{  
  _emit 0xEB
  _emit 0x0E   
  _emit 0x56   
  _emit 0x4D   
  _emit 0x50 
  _emit 0x72 
  _emit 0x6F 
  _emit 0x74 
  _emit 0x65 
  _emit 0x63 
  _emit 0x74 
  _emit 0x20 
  _emit 0x65 
  _emit 0x6E 
  _emit 0x64 
  _emit 0x00


int i = 0;

 __asm  
{  
  _emit 0xEB
  _emit 0x0E  
  _emit 0x56   
  _emit 0x4D   
  _emit 0x50 
  _emit 0x72 
  _emit 0x6F 
  _emit 0x74 
  _emit 0x65 
  _emit 0x63 
  _emit 0x74 
  _emit 0x20 
  _emit 0x65 
  _emit 0x6E 
  _emit 0x64 
  _emit 0x00

 
在 c++ 里是可以编译执行的
我想把它改为 C# 代码
 
namespace HuiBianTest2
{
    delegate void AddProc();
    delegate void AddProc2(); 
    class Program
    {
        static void Main(string[] args)
        {
            byte[] codeBytes = 
            {
                0xEB,
                0x10,  
                0x56,
                0x4D,  
                0x50, 
                0x72, 
                0x6F, 
                0x74, 
                0x65, 
                0x63, 
                0x74, 
                0x20, 
                0x62, 
                0x65, 
                0x67, 
                0x69,
                0x6E, 
                0x00
            };
            
            int i = 0;
            IntPtr handle = IntPtr.Zero;
            handle = VirtualAlloc(IntPtr.Zero, codeBytes.Length,
                MEM_COMMIT | MEM_RESERVE,
                PAGE_EXECUTE_READWRITE);

            Marshal.Copy(codeBytes, 0, handle, codeBytes.Length);
            AddProc add = Marshal.GetDelegateForFunctionPointer(handle, typeof(AddProc)) as AddProc;
            add( );

            byte[] codeBytes2 = 
            {
                0xEB,
                0x0E,
                0x56,
                0x4D,   
  相关解决方案