请教这段代码在C#中如何写 void hkSendCommand( const char * szCommand ){ _asm { PUSH szCommand; MOV EAX, 0x4214C0; CALL EAX; ADD ESP, 0x4; }} 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 汇编的要写成Dll,然后c#来调用,指针可以用unsafe编程参考--C#和asm联用 错误 1 error C3644: “set::Class1::SendCommandToConsole”: 不能编译生成托管代码的函数 c:\users\zhp0083\documents\visual studio 2008\projects\set\set\set.h 14 set错误 2 error C3821: “void set::Class1::SendCommandToConsole(char *)”: 托管类型或托管函数不能用于非托管函数 c:\users\zhp0083\documents\visual studio 2008\projects\set\set\set.h 23 set错误 3 error C3645: “set::Class1::SendCommandToConsole”: __clrcall 不能用在编译为本机代码的函数上 c:\users\zhp0083\documents\visual studio 2008\projects\set\set\set.h 12 set 要改写过啊直接用当然不行了即使生成dll,你C#调用之前也要对dll进行C#处理 下一个这样的类专门写外挂专用的!AsmAPIClass.cspublic class AsmClass { [System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "CloseHandle")] public static extern int CloseHandle( int hObject ); [System.Runtime.InteropServices.DllImport("kernel32.dll")] public static extern Int32 WriteProcessMemory(IntPtr hProcess, IntPtr lpBaseAddress, [System .Runtime .InteropServices .In ,System .Runtime .InteropServices .Out ] byte[] buffer, int size, out IntPtr lpNumberOfBytesWritten); [System.Runtime.InteropServices.DllImport("kernel32.dll")] public static extern Int32 WriteProcessMemory(int hProcess, int lpBaseAddress, byte[] buffer, int size, int lpNumberOfBytesWritten); [System.Runtime.InteropServices.DllImport("kernel32", EntryPoint = "CreateRemoteThread")] public static extern int CreateRemoteThread( int hProcess, int lpThreadAttributes, int dwStackSize, int lpStartAddress, int lpParameter, int dwCreationFlags, ref int lpThreadId ); [System.Runtime.InteropServices.DllImport("Kernel32.dll")] public static extern System.Int32 VirtualAllocEx( System.IntPtr hProcess, System.Int32 lpAddress, System.Int32 dwSize, System.Int16 flAllocationType, System.Int16 flProtect ); [System.Runtime.InteropServices.DllImport("Kernel32.dll")] public static extern System.Int32 VirtualAllocEx( int hProcess, int lpAddress, int dwSize, int flAllocationType, int flProtect ); [System.Runtime.InteropServices.DllImport("Kernel32.dll")] public static extern System.Int32 VirtualFreeEx( int hProcess, int lpAddress, int dwSize, int flAllocationType ); [System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "OpenProcess")] public static extern int OpenProcess( int dwDesiredAccess, int bInheritHandle, int dwProcessId ); private const int PAGE_EXECUTE_READWRITE = 0x4; private const int MEM_COMMIT = 4096; private const int MEM_RELEASE = 0x8000; private const int MEM_DECOMMIT = 0x4000; private const int PROCESS_ALL_ACCESS = 0x1F0FFF; private const int PROCESS_CREATE_THREAD = 0x2; private const int PROCESS_VM_OPERATION = 0x8; private const int PROCESS_VM_WRITE = 0x20; public string Asmcode = "";#region Call public void Call_EAX() { this.Asmcode = this.Asmcode + "FFD0"; } public void Call_EBX() { this.Asmcode = this.Asmcode + "FFD3"; } public void Call_ECX() { this.Asmcode = this.Asmcode + "FFD1"; } public void Call_EDX() { this.Asmcode = this.Asmcode + "FFD2"; } public void Call_ESI() { this.Asmcode = this.Asmcode + "FFD2"; } public void Call_ESP() { this.Asmcode = this.Asmcode + "FFD4"; } public void Call_EBP() { this.Asmcode = this.Asmcode + "FFD5"; } public void Call_EDI() { this.Asmcode = this.Asmcode + "FFD7"; } public void Call_DWORD_Ptr(int addre) { this.Asmcode = this.Asmcode + "FF15" + intTohex(addre, 8); } public void Call_DWORD_Ptr_EAX() { this.Asmcode = this.Asmcode + "FF10"; } public void Call_DWORD_Ptr_EBX() { this.Asmcode = this.Asmcode + "FF13"; } #endregion /以下是用代码注入器成功调用CALL的代码 //mov edi,[537F5C] //push 0567EDBC //push 00000009 //mov ecx,edi //call 004579A0 //下面是用.NET C#代码写的喊话CALL代码,现在一运行游戏就退出,谁帮我看一下哪里写错了 private void spealCall(string str)//str喊话内容 { byte[] byteArray = System.Text.Encoding.Default.GetBytes(str); int hwnd, ThreadAdd; hwnd = AsmAPI.API32Class.OpenProcess(PROCESS_ALL_ACCESS | PROCESS_CREATE_THREAD | PROCESS_VM_WRITE, 0, exerciseProcessId); ThreadAdd = (int)AsmAPI.API32Class.VirtualAllocEx(hwnd, 0, byteArray.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);//申请内存 AsmAPI.API32Class.WriteProcessMemory(hwnd, ThreadAdd, byteArray, byteArray.Length, 0); //写入函数地址 AsmAPI.AsmClass asm = new AsmAPI.AsmClass(); asm.Pushad(); asm.Mov_ECX(00000009);//喊话频道 asm.Push_ECX(); asm.Mov_EAX(ThreadAdd);//喊话内容内存地址 asm.Push_EAX(); asm.Mov_ECX_DWORD_Ptr(0x537F5C); asm.Mov_EBX(0x4579A0);//喊话call地址 asm.Call_EBX(); asm.Popad(); asm.Ret(); asm.RunAsm(exerciseProcessId); }内容来自 http://bbs.bpsend.com/read.php?tid=7507&page=e [UnmanagedFunctionPointer(CallingConvention.Cdecl.Stdcall)] public delegate void FunctionInvoker(string command);Marshal.GetDelegateForFunctionPointer(new IntPtr(0x4214C0),typeof(FunctionInvoker)).DynamicInvoke("cmd1"); 哦 第一行 写错了[UnmanagedFunctionPointer(CallingConvention.Stdcall)] public delegate void FunctionInvoker(string command);Marshal.GetDelegateForFunctionPointer(new IntPtr(0x4214C0),typeof(FunctionInvoker)).DynamicInvoke("cmd1");没有测试 应该可以 C# excel表格导入问题 vs2010 项目生成后如何自动把生成的EXE,DLL复制到指定文件夹中 用C# Winform 制作公司局域网内部聊天工具(求思路) 树形菜单的问题!!!怎么控制左边的树???? C#如何解决以下网络通信的问题100分 求delphi转c#,一段小代码而已 socket通信问题 statustrip的问题 提取html代码中的标签属性 如何将一个XML字符串,写入到DataSet里去? 问如何读取缓存文件 伪三层结构,帮忙指出这样写可能会出现的问题
参考--C#和asm联用
错误 2 error C3821: “void set::Class1::SendCommandToConsole(char *)”: 托管类型或托管函数不能用于非托管函数 c:\users\zhp0083\documents\visual studio 2008\projects\set\set\set.h 23 set
错误 3 error C3645: “set::Class1::SendCommandToConsole”: __clrcall 不能用在编译为本机代码的函数上 c:\users\zhp0083\documents\visual studio 2008\projects\set\set\set.h 12 set
直接用当然不行了即使生成dll,你C#调用之前也要对dll进行C#处理
{
[System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "CloseHandle")]
public static extern int CloseHandle(
int hObject
); [System.Runtime.InteropServices.DllImport("kernel32.dll")]
public static extern Int32 WriteProcessMemory(IntPtr hProcess,
IntPtr lpBaseAddress,
[System .Runtime .InteropServices .In ,System .Runtime .InteropServices .Out ] byte[] buffer,
int size,
out IntPtr lpNumberOfBytesWritten); [System.Runtime.InteropServices.DllImport("kernel32.dll")]
public static extern Int32 WriteProcessMemory(int hProcess,
int lpBaseAddress,
byte[] buffer,
int size,
int lpNumberOfBytesWritten); [System.Runtime.InteropServices.DllImport("kernel32", EntryPoint = "CreateRemoteThread")]
public static extern int CreateRemoteThread(
int hProcess,
int lpThreadAttributes,
int dwStackSize,
int lpStartAddress,
int lpParameter,
int dwCreationFlags,
ref int lpThreadId
); [System.Runtime.InteropServices.DllImport("Kernel32.dll")]
public static extern System.Int32 VirtualAllocEx(
System.IntPtr hProcess,
System.Int32 lpAddress,
System.Int32 dwSize,
System.Int16 flAllocationType,
System.Int16 flProtect
); [System.Runtime.InteropServices.DllImport("Kernel32.dll")]
public static extern System.Int32 VirtualAllocEx(
int hProcess,
int lpAddress,
int dwSize,
int flAllocationType,
int flProtect
); [System.Runtime.InteropServices.DllImport("Kernel32.dll")]
public static extern System.Int32 VirtualFreeEx(
int hProcess,
int lpAddress,
int dwSize,
int flAllocationType
); [System.Runtime.InteropServices.DllImport("kernel32.dll", EntryPoint = "OpenProcess")]
public static extern int OpenProcess(
int dwDesiredAccess,
int bInheritHandle,
int dwProcessId
); private const int PAGE_EXECUTE_READWRITE = 0x4;
private const int MEM_COMMIT = 4096;
private const int MEM_RELEASE = 0x8000;
private const int MEM_DECOMMIT = 0x4000;
private const int PROCESS_ALL_ACCESS = 0x1F0FFF;
private const int PROCESS_CREATE_THREAD = 0x2;
private const int PROCESS_VM_OPERATION = 0x8;
private const int PROCESS_VM_WRITE = 0x20;
public string Asmcode = "";
#region Call
public void Call_EAX()
{
this.Asmcode = this.Asmcode + "FFD0";
} public void Call_EBX()
{
this.Asmcode = this.Asmcode + "FFD3";
} public void Call_ECX()
{
this.Asmcode = this.Asmcode + "FFD1";
} public void Call_EDX()
{
this.Asmcode = this.Asmcode + "FFD2";
} public void Call_ESI()
{
this.Asmcode = this.Asmcode + "FFD2";
} public void Call_ESP()
{
this.Asmcode = this.Asmcode + "FFD4";
} public void Call_EBP()
{
this.Asmcode = this.Asmcode + "FFD5";
} public void Call_EDI()
{
this.Asmcode = this.Asmcode + "FFD7";
} public void Call_DWORD_Ptr(int addre)
{
this.Asmcode = this.Asmcode + "FF15" + intTohex(addre, 8);
} public void Call_DWORD_Ptr_EAX()
{
this.Asmcode = this.Asmcode + "FF10";
} public void Call_DWORD_Ptr_EBX()
{
this.Asmcode = this.Asmcode + "FF13";
}
#endregion
//mov edi,[537F5C]
//push 0567EDBC
//push 00000009
//mov ecx,edi
//call 004579A0
//下面是用.NET C#代码写的喊话CALL代码,现在一运行游戏就退出,谁帮我看一下哪里写错了
private void spealCall(string str)//str喊话内容
{
byte[] byteArray = System.Text.Encoding.Default.GetBytes(str);
int hwnd, ThreadAdd;
hwnd = AsmAPI.API32Class.OpenProcess(PROCESS_ALL_ACCESS | PROCESS_CREATE_THREAD | PROCESS_VM_WRITE, 0, exerciseProcessId);
ThreadAdd = (int)AsmAPI.API32Class.VirtualAllocEx(hwnd, 0, byteArray.Length, MEM_COMMIT, PAGE_EXECUTE_READWRITE);//申请内存 AsmAPI.API32Class.WriteProcessMemory(hwnd, ThreadAdd, byteArray, byteArray.Length, 0); //写入函数地址
AsmAPI.AsmClass asm = new AsmAPI.AsmClass();
asm.Pushad();
asm.Mov_ECX(00000009);//喊话频道
asm.Push_ECX();
asm.Mov_EAX(ThreadAdd);//喊话内容内存地址
asm.Push_EAX();
asm.Mov_ECX_DWORD_Ptr(0x537F5C);
asm.Mov_EBX(0x4579A0);//喊话call地址
asm.Call_EBX();
asm.Popad();
asm.Ret();
asm.RunAsm(exerciseProcessId);
}
内容来自 http://bbs.bpsend.com/read.php?tid=7507&page=e
[UnmanagedFunctionPointer(CallingConvention.Cdecl.Stdcall)] public delegate void FunctionInvoker(string command);Marshal.GetDelegateForFunctionPointer(new IntPtr(0x4214C0),typeof(FunctionInvoker)).DynamicInvoke("cmd1");
没有测试 应该可以