请问管道调用卡巴杀毒获取输出的问题

xiaomatian 2010-02-22 03:08:26
最近自己想做个小程序,就是在文件同步前先调用杀毒软件进行杀毒然后再进行拷贝,但是我发现无法获取卡巴的输出,我用KIS7,用avp.exe scan d:\1.txt是可以获得,而当我用一个rar文件或者一个安装包的时候就无法获得输出了,KIS2010则直接返回就过去了,压缩文件或安装包的时候KIS7只扫描到50%就一直不动了,程序就无法继续了。代码帖出来,还往各位指教指教啊!

UINT CFileScanDlg::DoVarsScan(LPVOID pvParam)
{
Para *ThreadPara= (Para *)pvParam;
string sdir=ThreadPara->sourceDir;
string spath=ThreadPara->softPath;
string sparam=ThreadPara->softparams;
string key1=ThreadPara->key1;
string key2=ThreadPara->key2;
CFileScanDlg *dlg=ThreadPara->dlg;
int softID=ThreadPara->softID;
OutputDebugString("扫描线程参数输出开始");
OutputDebugString(spath.c_str());
OutputDebugString(sparam.c_str());
OutputDebugString(sdir.c_str());
OutputDebugString(key1.c_str());
OutputDebugString(key2.c_str());
OutputDebugString("扫描线程参数输出结束");
//
BOOL working=FALSE;
while(1)
{
if (::WaitForSingleObject(ThreadPara->_stopEvent->m_hObject,0)== WAIT_OBJECT_0)
{
OutputDebugString("接收到退出扫描线程事件!自动结束该线程!");
break;
}
map<string,string> temp;
map<string,string>::iterator i;
if (!working)
{
OutputDebugString("ScanThread begin to do job...");
working=TRUE;
cs.Lock();
temp=m_ScanMap;
m_ScanMap.clear();
CListBox *list=(CListBox *)dlg->GetDlgItem(IDC_LIST_WAITSCAN);
CListBox *list_Copy=(CListBox *)dlg->GetDlgItem(IDC_LIST_COPY);
cs.Unlock();

for (i=temp.begin();i!=temp.end();i++)
{
OutputDebugString("待扫描列表不为空,输出结果!");
int SelIndex=0;
cs.Lock();
if ((SelIndex=list->FindString(0,i->second.c_str()))!=LB_ERR)
{
list->SetCurSel(SelIndex);
}
cs.Unlock();
CString filePath;
filePath.Format("%s%s",sdir.c_str(),i->second.c_str());
OutputDebugString(filePath);
CString strCmd;
strCmd.Format("cmd.exe /c \"%s\" %s %s",spath.c_str(),sparam.c_str(),filePath);
OutputDebugString(strCmd);
SECURITY_ATTRIBUTES sa;
HANDLE hRead,hWrite;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = TRUE;
if (!CreatePipe(&hRead,&hWrite,&sa,0)) {
OutputDebugString("创建管道失败!");
return 0;
}
OutputDebugString("CreatePipe成功!");
STARTUPINFO si;
PROCESS_INFORMATION pi;
si.cb = sizeof(STARTUPINFO);
GetStartupInfo(&si);
si.hStdError = hWrite;
si.hStdOutput = hWrite;
si.wShowWindow = SW_HIDE;
si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES;//
if (!CreateProcess(NULL,strCmd.GetBuffer(strCmd.GetLength())
,NULL,NULL,TRUE,NULL,NULL,NULL,&si,&pi)) {
OutputDebugString("CreateProcess error");
return 0;
}
OutputDebugString("after createprocess");
DWORD ret=WaitForSingleObject(pi.hProcess, INFINITE);
/*
if(WaitForSingleObject(pi.hProcess, INFINITE)==WAIT_FAILED)
{
OutputDebugString("Scan waitforsingleobject error");
return 0;
}*/
if (ret==WAIT_FAILED)
{
OutputDebugString("WAIT_FAILED");
}
if (ret==WAIT_OBJECT_0)
{
OutputDebugString("WAIT_OBJECT_0");
}
if (ret==WAIT_TIMEOUT)
{
OutputDebugString("WAIT_TIMEOUT");
}
m_dbgStr.Format("ret:%d",ret);
OutputDebugString(m_dbgStr);
OutputDebugString("after waitfor singleobject");
CloseHandle(hWrite);
OutputDebugString("after close handle");
char buffer[4096] ={0} ;
DWORD bytesRead;
CString strResult="";
while(1)
{
if(ReadFile(hRead,buffer,4096,&bytesRead,NULL) != NULL)
{
strResult += buffer;
}
else
{
break;
}
}
strResult.Replace(" ","");
OutputDebugString(strResult);
cs.Lock();
dlg->GetDlgItem(IDC_EDIT_SCANINFO)->SetWindowText(strResult);
dlg->GetDlgItem(IDC_EDIT_SCANINFO)->PostMessage(WM_VSCROLL, SB_BOTTOM, 0);
dlg->UpdateData(FALSE);
cs.Unlock();
if (strResult.GetLength()>0)
{
if(DoScanAnalysis(softID,strResult,key1,key2))//扫描分析文件未被感染,添加到拷贝线程中
{
OutputDebugString("文件未被感染,加入自动拷贝列表!");
cs.Lock();
m_CopyMap.insert(m_ScanPair(i->first,i->second));
list_Copy->AddString(i->second.c_str());
OutputDebugString("加入到待拷贝列表成功!");
cs.Unlock();
}else
{
OutputDebugString("文件检测到威胁,检测是否已经被删除!");
}

cs.Lock();
if ((SelIndex=list->FindString(0,i->second.c_str()))!=LB_ERR)
{
list->DeleteString(SelIndex);
OutputDebugString("从待扫描列表中删除已经完成扫描的文件!");
}
temp.erase(i);
cs.Unlock();
}
}
working=FALSE;
OutputDebugString("ScanThread end to do job...");
}
Sleep(1000);
}
::CloseHandle(_listenThread);
_listenThread = NULL;
return 0;
}

...全文
169 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaomatian 2010-02-23
  • 打赏
  • 举报
回复
还有一个问题啊,我发现卡巴死机在dos下对中文不支持啊,只要有字母和中文名的扫描就不对了。
xiaomatian 2010-02-22
  • 打赏
  • 举报
回复
而且我要是扫描一个记事本或者一个视频文件的话我是可以得到卡巴扫描的输出的。这种压缩包什么的就卡巴只到50%就不走了,而且会一直在50%,这样我这个线程就被赌在这走不了了。
songsu 2010-02-22
  • 打赏
  • 举报
回复
没研究过,友情UP.
xiaomatian 2010-02-22
  • 打赏
  • 举报
回复
对啊,在控制台中执行是有输出的,但是用管道创建就没有结果了,但是单个文件的话我又可以获取到输出的。
jingzhongrong 2010-02-22
  • 打赏
  • 举报
回复
一下命令行测试,KIS2009可以返回结果:
F:\>"E:\Kaspersky Lab\Kaspersky Internet Security 2009\avp" scan test.rar >1.txt

1.txt中的进度都是Progress 50%

15,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 进程/线程/DLL
社区管理员
  • 进程/线程/DLL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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