rt
解决方案 »
- winxp中用CFileDialog如何选择上万文档?
- 求一个MFC多线程编程的综合实例!在下谢过了!!
- 请问用CxImage 把BMP转成JPG之后,要怎么看JPG文件大小啊?
- 请教各位高手!!!!!!!!!用网络传送以个数据库里面的表的做法
- 请问如何判断一个文件是已经传递结束的?
- 多文档如何实现彻底全屏?
- 怎么显示音标
- 请问在MFC程序中(一个exe程序)加入ATL支持并实现一个自动化接口后,为何在客户端程序中(也是一个exe程序)无法查找到该接口中的方法?
- 有关vc中的问题
- 怎么用socks5代理一个特定的程序,截获该程序所有报文
- 我是个初学者,没条件买书,所以问一些很基础的问题,请大家帮忙~谢谢~(问题一)
- 请大家集思广益
第一:我没搞清楚:为什么我的串口程序先起动后,portmon还是可以跟踪串口?我发现portmon里没有.sys,.vxd,所以我觉得它就是用的HOOK API。
第二:HOOK CreateFile()的难度太大了,我不知道你想到没有:),在别人的应用程序里,CreateFile()是有返回值的,我一旦hook 了它,那这个返回值就埴不回去了,要埴也要一个一个填(不现实)
第三:我用portmon跟踪了大部分串口软件,我发现在CreateFile,一定是SetCommState()之类的函数,就是对DCB的操作。还有SetTimeOut().我想问问你,这里可不可以找到一个唯一和串口对应的函数,SetCommState()会有别的东西调用吗?(除了COMn).
第4:我拿到了一个hFile句柄后,怎么判断它是对应那个串口?我用SetWindowsHookEx()注射了DLL后,如果,那个串口软件是一个MDI的,也就是一个窗口对一个串口。天,那我存下来的这个hFile不就变来变去?晕,我没想出来,怎么搞。
第5:我认为HOOK API可以动态、不占用串口的监听串口,但不可能动态调试。:)谢谢,你对本问题的关心,我一个星期来,基本上没怎么睡觉,头越来越晕。
HWND WINAPI MYCreateWindowW(
DWORD dwExStyle, // extended window style
LPCTSTR lpClassName, // registered class name
LPCTSTR lpWindowName, // window name
DWORD dwStyle, // window style
int x, // horizontal position of window
int y, // vertical position of window
int nWidth, // window width
int nHeight, // window height
HWND hWndParent, // handle to parent or owner window
HMENU hMenu, // menu handle or child identifier
HINSTANCE hInstance, // handle to application instance
LPVOID lpParam // window-creation data)
{
HWND wnd=CreateWindowExW(
dwExStyle, // extended window style
lpClassName, // registered class name
lpWindowName, // window name
dwStyle, // window style
x, // horizontal position of window
y, // vertical position of window
nWidth, // window width
nHeight, // window height
hWndParent, // handle to parent or owner window
hMenu, // menu handle or child identifier
hInstance, // handle to application instance
lpParam // window-creation data
);
HWND WndParent=wnd;
/* if(hWndParent==NULL)
{
WndParent=wnd;
}
else
{
WndParent=hWndParent;
} */ SetWindowLong(WndParent,GWL_EXSTYLE,
GetWindowLong(WndParent,GWL_EXSTYLE)^0x80000);
HINSTANCE hInst = LoadLibrary("User32.DLL");
if(hInst)
{
typedef BOOL (WINAPI *MYFUNC)(HWND,COLORREF,BYTE,DWORD);
MYFUNC fun = NULL;
//取得SetLayeredWindowAttributes函数指针
fun=(MYFUNC)GetProcAddress(hInst, "SetLayeredWindowAttributes");
if(fun)fun(WndParent,0,200,2);
//SetLayeredWindowAttributes(this->GetSafeHwnd(),0,eff,2);
FreeLibrary(hInst);
//MessageBox(NULL,"CreateWindowW=NULL","CreateWindowW=NULL",MB_OK);
}
//MessageBox(NULL,"CreateWindowW=NULL","CreateWindowW=NULL",MB_OK);
return wnd; }
HANDLE WINAPI Hook_CreateFileW(
LPCTSTR lpFileName, // pointer to name of the file
DWORD dwDesiredAccess, // access (read-write) mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
// pointer to security attributes
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to file with attributes to
)从 LPCTSTR lpFileName,可以判断出是不是含有COMn。
我写了一个函数:
int Str_Contain(char *input)
{
int len = 0;
int i_i = 0;
int j = 0;
char* com = "COM";
len = strlen(input);
for(int i = 0;i<len;i++){
i_i = i;
for(j = 0;j<3;j++){
if(input[i_i] == com[j]){
i_i++;
//j++;
}
else
break;
}
if(j == 3)
break;
}
return (j == 3);
};然后这样用:
HANDLE WINAPI Hook_CreateFileA(
LPCTSTR lpFileName, // pointer to name of the file
DWORD dwDesiredAccess, // access (read-write) mode
DWORD dwShareMode, // share mode
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
// pointer to security attributes
DWORD dwCreationDisposition, // how to create
DWORD dwFlagsAndAttributes, // file attributes
HANDLE hTemplateFile // handle to file with attributes to
)
{
HANDLE hFile = ((PFCreateFileA)(PROC) g_CreateFileA)(
lpFileName , dwDesiredAccess,
dwShareMode, lpSecurityAttributes,
dwCreationDisposition, dwFlagsAndAttributes,
hTemplateFile);
if(Str_Contain((char*)hFile)){///////////////////////////////////出错
MessageBox(NULL,lpFileName,"com",MB_OK);
com = hFile;
}
return hFile;
}我试了几次,发现(char*)hFile,也就是LPCTSTR无法用(char*)转换过来(这两个不是一回事吗???)
不能用CString,我用的是Windows核心编程里那个现成的类,我一#include <afx.h>
就会报错,不可以和windows.h在一起。你觉得我该怎么搞?这个COMn提不出来,就没有用了。
我做了个sdi,响映左击mouse
void CDialogexeView::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call
LastMsgBoxInfo_HookAllApps(TRUE,0,handle);
CView::OnLButtonDown(nFlags, point);
}
LastMsgBoxInfo_HookAllApps本来只有两个参数,我加了第三个,就是那个handle,准备传个句柄之为类的东西过去。在CreateFile成功的时候,在我的sdi里画个圆什么的测试一下。
:(我没搞成