高难度问题,高手请进,exe文件的通讯。

helysan 2005-05-25 10:42:57
我们单位有一个程序,只有exe文件,是用pb6.5编写的。当某个按钮按下时,我想在其事件中的加入用c#或c++写的一个form,这个技术路线走的得通吗?如果不能,有没有其他变通的方法?我们没有源代码!!!
...全文
105 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
柯本 2005-05-25
  • 打赏
  • 举报
回复
可以考虑用
CreateRemoteThread试试
但具体实现就复杂了
以下是一个例子,在一个已存在的进程中显示一个MessageBox

typedef struct _RemotePara{//参数结构
char pMessageBox[12];
DWORD dwMessageBox;
}RemotePara;
//远程线程
DWORD __stdcall ThreadProc (RemotePara *lpPara){
typedef int (__stdcall *MMessageBoxA)(HWND,LPCTSTR,LPCTSTR,DWORD);//定义MessageBox函数


MMessageBoxA myMessageBoxA;
myMessageBoxA =(MMessageBoxA) lpPara->dwMessageBox ;//得到函数入口地址
myMessageBoxA(NULL,lpPara->pMessageBox ,lpPara->pMessageBox,0);//call
return 0;
}

void EnableDebugPriv( void )
{
HANDLE hToken;
LUID sedebugnameValue;
TOKEN_PRIVILEGES tkp;

if ( ! OpenProcessToken( GetCurrentProcess(),
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken ) )
return;
if ( ! LookupPrivilegeValue( NULL, SE_DEBUG_NAME, &sedebugnameValue ) ){
CloseHandle( hToken );
return;
}
tkp.PrivilegeCount = 1;
tkp.Privileges[0].Luid = sedebugnameValue;
tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if ( ! AdjustTokenPrivileges( hToken, FALSE, &tkp, sizeof tkp, NULL, NULL ) )
CloseHandle( hToken );
}
int test(DWORD pid)
{
const DWORD THREADSIZE=1024*4;
DWORD byte_write;
EnableDebugPriv();//提升权限
HANDLE hWnd = ::OpenProcess (PROCESS_ALL_ACCESS,FALSE,pid);
if(!hWnd)return 0;
void *pRemoteThread =::VirtualAllocEx(hWnd,0,THREADSIZE,MEM_COMMIT| MEM_RESERVE,PAGE_EXECUTE_READWRITE);
if(!pRemoteThread)return 0;
if(!::WriteProcessMemory(hWnd,pRemoteThread,&ThreadProc,THREADSIZE,0))
return 0;

//再付值
RemotePara myRemotePara;
::ZeroMemory(&myRemotePara,sizeof(RemotePara));
HINSTANCE hUser32 = ::LoadLibrary ("user32.dll");
myRemotePara.dwMessageBox =(DWORD) ::GetProcAddress (hUser32 , "MessageBoxA");
strcat(myRemotePara.pMessageBox,"hello\0");
//写进目标进程
RemotePara *pRemotePara =(RemotePara *) ::VirtualAllocEx (hWnd ,0,sizeof(RemotePara),MEM_COMMIT,PAGE_READWRITE);//注意申请空间时的页面属性
if(!pRemotePara)return 0;
if(!::WriteProcessMemory (hWnd ,pRemotePara,&myRemotePara,sizeof myRemotePara,0))return 0;

//启动线程
HANDLE hThread = ::CreateRemoteThread (hWnd ,0,0,(DWORD (__stdcall *)(void *))pRemoteThread ,pRemotePara,0,&byte_write);
if(!hThread){
return 0;
}
return 0;
}

--------------------调用---------------------------
HWND hd=FindWindow(NULL,"STEST"); // 找到运行程序的handle
String s;
if(hd==NULL)
{
MessageBox("Error");
return ;
}
DWORD pid;
GetWindowThreadProcessId(hd,&pid);
test(pid);
吹泡泡的小猫 2005-05-25
  • 打赏
  • 举报
回复
在软家加密技术内幕中提到了一种修改exe可执行文件,注入自己的代码的方法,可以参考
dongfa 2005-05-25
  • 打赏
  • 举报
回复
钩子或许可以.
SetWindowsHookEx
sinall 2005-05-25
  • 打赏
  • 举报
回复
例子在这里:
http://www.vckbase.com/document/viewdoc/?id=277
sinall 2005-05-25
  • 打赏
  • 举报
回复
楼上的CreateRemoteThread方法我研究过,对于楼主的应用,不太可行。

dongfa(一桶江湖)的方法应该可行。

我想的方法是,
1、隐藏它的按钮,创建自己的按钮。
2、使用自己的按钮处理函数。
3、发送原程序的按钮点击事件。

3,245

社区成员

发帖
与我相关
我的任务
社区描述
ATL,Active Template Library活动(动态)模板库,是一种微软程序库,支持利用C++语言编写ASP代码以及其它ActiveX程序。
社区管理员
  • ATL/ActiveX/COM社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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