首页
社区
课程
招聘
[讨论]FindFirstChangeNotification 函数不起作用(已解决)
发表于: 2007-6-30 16:29 13183

[讨论]FindFirstChangeNotification 函数不起作用(已解决)

2007-6-30 16:29
13183
俺最近想写个监视系统文件,防止被病毒删除和更改的程序,有很多这方面的知识都还学习.
于是先在自己力所能及的前提下写了个测试程序:

运行过程中,程序执行到

DWORD nObjectWait = ::WaitForSingleObject (m_hEvent, INFINITE);

处进行等待操作,然后我修改C盘根目录下autorun.inf 文件夹的名称,发现程序没有响应!


调试了下,发现 FindFirstChangeNotification 函数没有起作用:

// 监视目录名称的改变
m_hEvent = ::FindFirstChangeNotification (strPath,
TRUE, FILE_NOTIFY_CHANGE_DIR_NAME);


之前我搜索了很多,有一帖子也是这样的:http://forum.eviloctal.com/read-htm-tid-28250-keyword-%BC%E0%CA%D3%CE%C4%BC%FE.html

弄了半天不思其解,还请知道的达人帮忙看下,先谢谢了~

代码很少,如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream.h>
#include <string.h>
#include <afxwin.h>
 
 
BOOL g_bCheck = TRUE;
DWORD __stdcall ScoutThread (LPVOID lpParam);
 
int main ()
{
    HANDLE hThread;
    DWORD dwThreadId;
     
    hThread = ::CreateThread (NULL, NULL, ScoutThread, NULL, 0, &dwThreadId);
    cout << "该线程ID号:" << dwThreadId<<endl;
    Sleep (6*1000*1000);
    g_bCheck = FALSE;
     
    ::WaitForSingleObject (hThread, INFINITE);
    ::CloseHandle (hThread);
     
    return 0;
}
 
////////////////////////////////////////////////////////////////////////////////
/// 监视线程
 
DWORD __stdcall ScoutThread (LPVOID lpParam)
{
    cout << "a thread that still watch c:\\autorun.inf..." << endl;
     
    CString strPath = "c:\\autorun.inf";
    HANDLE m_hEvent;
     
    // 监视目录名称的改变
    m_hEvent = ::FindFirstChangeNotification (strPath,
        TRUE, FILE_NOTIFY_CHANGE_DIR_NAME);
     
    cout<<"1111..."<<endl;
    if (m_hEvent == INVALID_HANDLE_VALUE)
    {
        ExitProcess(GetLastError());
    }
     
    // 进入循环判断
    while (g_bCheck)
    {
        cout<<"2222..."<<endl;
        DWORD nObjectWait = ::WaitForSingleObject (m_hEvent, INFINITE);
        cout<<"3333..."<<endl;
         
        if (nObjectWait)
        {
            ::MessageBox (NULL, "autorun.inf被病毒改名了...", "!", MB_OK);
            system ("rd /s/q c:\\autorun.inf");
            system ("md c:\\autorun.inf");
            system ("md c:\\autorun.inf\\1..\\");
            system ("attrib +s +h +r c:\\autorun.inf");
        }
         
        // 继续监视
        cout<<"4444..."<<endl;
        ::FindNextChangeNotification (m_hEvent);
 
        if ( FindNextChangeNotification(m_hEvent) == FALSE )
            ExitProcess(GetLastError());
    }
     
    return 0;
}


由于对文件方便操作还在学习中,所以暂时没用很多API, 就大致用system() 搪塞过去了先...

[注意]看雪招聘,专注安全领域的专业人才平台!

收藏
免费
支持
分享
最新回复 (11)
雪    币: 2134
活跃值: (14)
能力值: (RANK:170 )
在线值:
发帖
回帖
粉丝
2
你添加 /MT选项看看
ScoutThread中,
    CString strPath = "c:\\autorun.inf";
2007-6-30 17:38
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
3

2007-6-30 18:18
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
4
问题太简单了吧?

知道的大致说下咯,55555
2007-7-1 12:06
0
雪    币: 39
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
5
cout<<"a thread that still watch c:\autorun.inf..."<<endl;
应该是 :
cout<<"a thread that still watch c:\\autorun.inf..."<<endl;
不过这个手误不应该引起这个问题
2007-7-1 13:28
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
6


.
2007-7-1 15:48
0
雪    币: 201
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
7
帮你 关 注
2007-7-1 16:57
0
雪    币: 200
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
8
我也正在研究 遍历目录 我写好了程序  我想写个遍历 然后追加asp jsp php aspx 等网页文件 嘿嘿 别骂我 我给你代码

Code:
void CFFileDlg::OnFindFile()
{
// TODO: Add your control notific ation handler code here

CString xiaohao;
xiaohao="c:\\Test\\";
BrowseDir(xiaohao);

}

void CFFileDlg::BrowseDir(CString strDir)
{
CFileFind ff;
CString szDir = strDir;

if(szDir.Right(1)!="\\")
szDir+="\\";
szDir+="*.*";


BOOL res = ff.FindFile(szDir);
while(res)
{
res = ff.FindNextFile();
if(ff.IsDirectory()&&!ff.IsDots())
{
BrowseDir(ff.GetFilePath());
}
else if(!ff.IsDirectory() && !ff.IsDots())
{
CString str;
str.Format("当前访问的文件:%s",ff.GetFilePath());
GanRan(str); //感染函数自己写的 你不用就去掉既可
MessageBox("感染完了一个咯");
}
}
ff.Close();
}
2007-7-1 17:22
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
9
程序已经可以运行了,可是监视不成功...

这是什么原因啊?
2007-7-2 13:20
0
雪    币: 46
活跃值: (10)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
10
你仔细看看FindFirstChangeNotification的参数。
你的参数错了。
那个BOOL值是确定是要监视某一指定目录,还是一个目录树。
你的那个传给第三个参数的值也不正确。你的那个DIR_NAME是监视目录名是否改变。而你是要监视文件名,SO。。FILE_NOTIFY_CHANGE_FILE_NAME
2007-7-4 12:35
0
雪    币: 709
活跃值: (2420)
能力值: ( LV12,RANK:1010 )
在线值:
发帖
回帖
粉丝
11
谢谢大家指点,问题已经解决了~
2007-7-5 20:20
0
雪    币: 3164
活跃值: (5912)
能力值: ( LV3,RANK:20 )
在线值:
发帖
回帖
粉丝
12
晕,我在也试用这个API(FindFirstChangeNotification), 现在,只能知要监视目录已改变的事件, 不知“要监视目录已改变的”的名字。。。。
2007-9-19 23:20
0
游客
登录 | 注册 方可回帖
返回

账号登录
验证码登录

忘记密码?
没有账号?立即免费注册