求助,各位请帮我看这个汇编内联问题,谢谢!

lshlsh2009 2014-08-27 08:50:36
是这样的:
有 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,
0x50,
0x72,
0x6F,
0x74,
0x65,
0x63,
0x74,
0x20,
0x65,
0x6E,
0x64,
0x00
};

IntPtr handle2 = IntPtr.Zero;
handle2 = VirtualAlloc(IntPtr.Zero, codeBytes2.Length,
MEM_COMMIT | MEM_RESERVE,
PAGE_EXECUTE_READWRITE);
Marshal.Copy(codeBytes2, 0, handle2, codeBytes2.Length);

AddProc2 add2 = Marshal.GetDelegateForFunctionPointer(handle2, typeof(AddProc2)) as AddProc2;
add2();
}
//Windows API
[DllImport("Kernel32.dll", EntryPoint = "VirtualAlloc")]
public static extern IntPtr VirtualAlloc(IntPtr address, int size, uint allocType, uint protect);
[DllImport("Kernel32.dll", EntryPoint = "VirtualFree")]
public static extern bool VirtualFree(IntPtr address, int size, uint freeType);
//flags
const uint MEM_COMMIT = 0x1000;
const uint MEM_RESERVE = 0x2000;
const uint PAGE_EXECUTE_READWRITE = 0x40;
const uint MEM_RELEASE = 0x8000;
}
}



执行 add( ); 就出现错误了
我想
byte[] codeBytes =
{
0xEB,
0x10,
0x56,
0x4D,
0x50,
0x72,
0x6F,
0x74,
0x65,
0x63,
0x74,
0x20,
0x62,
0x65,
0x67,
0x69,
0x6E,
0x00
};
这段代码我写错了,但是知道怎么写?
请各位大哥帮我看看是哪里错了
应该怎么改
谢谢!

...全文
225 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
fhqdx0012 2014-08-27
  • 打赏
  • 举报
回复
汇编代码部分没错误! jmp @F "VMProtect begin",0 @@:
fhqdx0012 2014-08-27
  • 打赏
  • 举报
回复
很明显EB 10有问题 跳到字符中间了
fhqdx0012 2014-08-27
  • 打赏
  • 举报
回复

jmp @F    ;0xEB  0x10
byte  "VMProtect begin",0  ;56 4D 50 72 6F 74 65 63 74 20 62 65 67 69 6E 00
@@:




21,499

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧