16,472
社区成员
发帖
与我相关
我的任务
分享
/*
first call: "\\.\COM1 CreateFileW"
then call: "\\.\COM1 CreateFileA"
*/
HANDLE WINAPI myCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{// unhook first
g_HookApi.UnhookOneApi(&myapi_info[CREATEFILEA]);
HANDLE handle=CreateFileA(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
// hook again
g_HookApi.HookOneApi(&myapi_info[CREATEFILEA]);
//
if(handle != INVALID_HANDLE_VALUE)
{// handle
if(g_CommFile != handle)// not comes
{// because first call: "\\.\COM1 CreateFileW"
char *CommPort=0;
CommPort=strrchr(lpFileName,'\\');
if(CommPort) CommPort++;
else CommPort=(char*)lpFileName;
if(strnicmp(CommPort,"COM",3)==0)
{//save handle and port name
g_CommFile=handle;
strcpy(g_CommStruc.CommName,CommPort);
#ifdef _DEBUG
SendData2Dialog(WM_CFA_MSG,(BYTE*)(g_CommStruc.CommName),strlen(g_CommStruc.CommName)+1);
#endif
}
}
}
return handle;
}
//
HANDLE WINAPI myCreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{// unhook first
g_HookApi.UnhookOneApi(&myapi_info[CREATEFILEW]);
HANDLE handle=CreateFileW(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes,
dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
// hook again
g_HookApi.HookOneApi(&myapi_info[CREATEFILEW]);
//
if(handle != INVALID_HANDLE_VALUE)
{
if(g_CommFile != handle)
{
char fname[MAX_PATH]={0};//'\\.\COM1'
WideCharToMultiByte(CP_ACP, 0, lpFileName, -1, fname, MAX_PATH/2 ,NULL,NULL);
char *CommPort=0;
CommPort=strrchr(fname,'\\');
if(CommPort) CommPort++;
else CommPort=fname;
if(strnicmp(CommPort,"COM",3)==0)
{//save handle and port name
g_CommFile = handle;
strcpy(g_CommStruc.CommName,CommPort);
#ifdef _DEBUG
SendData2Dialog(WM_CFW_MSG,(BYTE*)(g_CommStruc.CommName),strlen(g_CommStruc.CommName)+1);
#endif
}
}
}
return handle;
}