public void RunAsm(int pid)//在目的空间(游戏空间)分配运行汇编码所需的内存空间,并启动远程线程函数调用代码
{
int hwnd, addre, threadhwnd;
byte[] Asm = this.AsmChangebytes(this.Asmcode);
if (pid != 0)
{
hwnd = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
if (hwnd != 0)
{
addre = VirtualAllocEx(hwnd, 0, 1024, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(hwnd, addre, Asm, 1024, 0);
threadhwnd = CreateRemoteThread(hwnd, 0, 0, addre, 0, 0, ref pid);
VirtualFreeEx(hwnd, addre, 1024, MEM_RELEASE);
CloseHandle(threadhwnd);
CloseHandle(hwnd);
}
}
this.Asmcode = "";
}
private byte[] AsmChangebytes(string asmPram)//将16进制样式的字符串转换成以字节数组表现的汇编码
{
byte[] reAsmCode = new byte[asmPram.Length / 2];
for (int i = 0; i < reAsmCode.Length; i++)//29
{
reAsmCode[i] = Convert.ToByte(Int32.Parse(asmPram.Substring(i * 2, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
}
return reAsmCode;
}
{
int hwnd, addre, threadhwnd;
byte[] Asm = this.AsmChangebytes(this.Asmcode);
if (pid != 0)
{
hwnd = OpenProcess(PROCESS_ALL_ACCESS, 0, pid);
if (hwnd != 0)
{
addre = VirtualAllocEx(hwnd, 0, 1024, MEM_COMMIT, PAGE_EXECUTE_READWRITE);
WriteProcessMemory(hwnd, addre, Asm, 1024, 0);
threadhwnd = CreateRemoteThread(hwnd, 0, 0, addre, 0, 0, ref pid);
VirtualFreeEx(hwnd, addre, 1024, MEM_RELEASE);
CloseHandle(threadhwnd);
CloseHandle(hwnd);
}
}
this.Asmcode = "";
}
private byte[] AsmChangebytes(string asmPram)//将16进制样式的字符串转换成以字节数组表现的汇编码
{
byte[] reAsmCode = new byte[asmPram.Length / 2];
for (int i = 0; i < reAsmCode.Length; i++)//29
{
reAsmCode[i] = Convert.ToByte(Int32.Parse(asmPram.Substring(i * 2, 2), System.Globalization.NumberStyles.AllowHexSpecifier));
}
return reAsmCode;
}