`

C++ USN日志 相关的代码

    博客分类:
  • C++
 
阅读更多

例子一:

TestApp.cpp

#include <set>
#include "USNMethod.h"

using namespace std;

int main()
{
	// 获得所有变化记录
	deque<MY_USN_RECORD> con;
	EnumUsnRecord( "F", con );

	// 搜寻文件名为"testXML.xml"的文件号(可能有多个)
	set<DWORDLONG> con2;
	for( deque<MY_USN_RECORD>::const_iterator itor=con.begin(); itor!=con.end(); ++itor )
	{
		const MY_USN_RECORD& mur = *itor;
		if( _wcsicmp(mur.FileName,L"testXML.xml") == 0 )
		{
			con2.insert( mur.FileReferenceNumber );
		}
	}

	// 遍历其历史操作
	setlocale( LC_CTYPE, "chs" );
	for( set<DWORDLONG>::const_iterator itor2=con2.begin(); itor2!=con2.end(); ++itor2 )
	{
		for( deque<MY_USN_RECORD>::const_iterator itor=con.begin(); itor!=con.end(); ++itor )
		{
			const MY_USN_RECORD& mur = *itor;
			if( *itor2 == mur.FileReferenceNumber )
			{
				FILETIME timestamp;
				FileTimeToLocalFileTime( &(FILETIME&)mur.TimeStamp, &timestamp );
				SYSTEMTIME st;
				FileTimeToSystemTime( &timestamp, &st );
				printf( "%04d-%02d-%02d %02d:%02d:%02d " , st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond );

				if( mur.Reason&USN_REASON_DATA_OVERWRITE )
				{
					printf( "%s|", "DATA_OVERWRITE" );
				}
				if( mur.Reason&USN_REASON_DATA_EXTEND )
				{
					printf( "%s|", "DATA_EXTEND" );
				}
				if( mur.Reason&USN_REASON_DATA_TRUNCATION )
				{
					printf( "%s|", "DATA_TRUNCATION" );
				}
				if( mur.Reason&USN_REASON_NAMED_DATA_OVERWRITE )
				{
					printf( "%s|", "NAMED_DATA_OVERWRITE" );
				}
				if( mur.Reason&USN_REASON_NAMED_DATA_EXTEND )
				{
					printf( "%s|", "NAMED_DATA_EXTEND" );
				}
				if( mur.Reason&USN_REASON_NAMED_DATA_TRUNCATION )
				{
					printf( "%s|", "NAMED_DATA_TRUNCATION" );
				}
				if( mur.Reason&USN_REASON_FILE_CREATE )
				{
					printf( "%s|", "FILE_CREATE" );
				}
				if( mur.Reason&USN_REASON_FILE_DELETE )
				{
					printf( "%s|", "FILE_DELETE" );
				}
				if( mur.Reason&USN_REASON_EA_CHANGE )
				{
					printf( "%s|", "EA_CHANGE" );
				}
				if( mur.Reason&USN_REASON_SECURITY_CHANGE )
				{
					printf( "%s|", "SECURITY_CHANGE" );
				}
				if( mur.Reason&USN_REASON_RENAME_OLD_NAME )
				{
					printf( "%s|", "RENAME_OLD_NAME" );
				}
				if( mur.Reason&USN_REASON_RENAME_NEW_NAME )
				{
					printf( "%s|", "RENAME_NEW_NAME" );
				}
				if( mur.Reason&USN_REASON_INDEXABLE_CHANGE )
				{
					printf( "%s|", "INDEXABLE_CHANGE" );
				}
				if( mur.Reason&USN_REASON_BASIC_INFO_CHANGE )
				{
					printf( "%s|", "BASIC_INFO_CHANGE" );
				}
				if( mur.Reason&USN_REASON_HARD_LINK_CHANGE )
				{
					printf( "%s|", "HARD_LINK_CHANGE" );
				}
				if( mur.Reason&USN_REASON_COMPRESSION_CHANGE )
				{
					printf( "%s|", "COMPRESSION_CHANGE" );
				}
				if( mur.Reason&USN_REASON_ENCRYPTION_CHANGE )
				{
					printf( "%s|", "ENCRYPTION_CHANGE" );
				}
				if( mur.Reason&USN_REASON_OBJECT_ID_CHANGE )
				{
					printf( "%s|", "OBJECT_ID_CHANGE" );
				}
				if( mur.Reason&USN_REASON_REPARSE_POINT_CHANGE )
				{
					printf( "%s|REPARSE_POINT_CHANGE", "" );
				}
				if( mur.Reason&USN_REASON_STREAM_CHANGE )
				{
					printf( "%s|", "STREAM_CHANGE" );
				}
				if( mur.Reason&USN_REASON_TRANSACTED_CHANGE )
				{
					printf( "%s|", "TRANSACTED_CHANGE" );
				}
				if( mur.Reason&USN_REASON_CLOSE )
				{
					printf( "%s|", "CLOSE" );
				}

				printf( "\n  " );
				bool PrintFullPath( const MY_USN_RECORD& mur, const deque<MY_USN_RECORD>& con );
				PrintFullPath(mur,con);
				printf( "\n" );
			}
		}
		printf( "\n" );
	}

	if( hVol != INVALID_HANDLE_VALUE )
	{
		CloseHandle( hVol );
	}

	return 0;
}

bool PrintFullPath( const MY_USN_RECORD& mur, const deque<MY_USN_RECORD>& con )
{
	if( (mur.FileReferenceNumber&0x0000FFFFFFFFFFFF) == 5 )
		return true;

	deque<MY_USN_RECORD>::const_iterator recent = con.end();
	for( deque<MY_USN_RECORD>::const_iterator itor=con.begin(); itor!=con.end() && itor->TimeStamp.QuadPart<=mur.TimeStamp.QuadPart; ++itor )
	{
		if( itor->FileReferenceNumber == mur.ParentFileReferenceNumber )
			recent = itor;
	}
	// 它的父目录可能也已被删除,所以要先在记录集中找找
	if( recent != con.end() ) 
	{
		bool r= PrintFullPath(*recent,con);
		printf( "\\%S", mur.FileName );
		return r;
	}

	bool GetFullPathByFileReferenceNumber( HANDLE hVol, DWORDLONG FileReferenceNumber );
	// 如果记录中没有,再去看看这个文件实际存在否
	bool r = GetFullPathByFileReferenceNumber(hVol,mur.ParentFileReferenceNumber); 
	if( r )	{
		printf( "\\%S", mur.FileName );
	} else {
		printf( "???\\%S", mur.FileName );
	}
	return r;
}

bool GetFullPathByFileReferenceNumber( HANDLE hVol, DWORDLONG FileReferenceNumber )
{
	if( (FileReferenceNumber&0x0000FFFFFFFFFFFF) == 5 ){
		return true;
	}

	bool ret = false;
	DWORD BytesReturned;
	NTFS_VOLUME_DATA_BUFFER nvdb;
	// 仅是事例,没有作优化 1.作为递归调用,这一步应当提取出来 2.如果多次调用,DirectoryFileReferenceNumber没必要被重复获取
	if( DeviceIoControl( hVol, FSCTL_GET_NTFS_VOLUME_DATA, NULL, 0
		, &nvdb, sizeof(nvdb), &BytesReturned, NULL ) ) 
	{
		NTFS_FILE_RECORD_INPUT_BUFFER nfrib;
		nfrib.FileReferenceNumber.QuadPart = FileReferenceNumber;
		size_t len = sizeof(NTFS_FILE_RECORD_OUTPUT_BUFFER)+nvdb.BytesPerFileRecordSegment-1;
		NTFS_FILE_RECORD_OUTPUT_BUFFER* nfrob = (PNTFS_FILE_RECORD_OUTPUT_BUFFER)operator new(len);
		if( DeviceIoControl( hVol, FSCTL_GET_NTFS_FILE_RECORD, &nfrib, sizeof(nfrib)
			, nfrob, len, &BytesReturned, NULL ) )
		{
			// a 48-bit index and a 16-bit sequence number
			if( (nfrib.FileReferenceNumber.QuadPart&0x0000FFFFFFFFFFFF) == nfrob->FileReferenceNumber.QuadPart )
			{
				PFILE_RECORD_HEADER frh = (PFILE_RECORD_HEADER)nfrob->FileRecordBuffer;
				for( PATTRIBUTE attr=(PATTRIBUTE)((LPBYTE)frh+frh->AttributesOffset); attr->AttributeType!=-1; attr=(PATTRIBUTE)((LPBYTE)attr+attr->Length) )
				{
					if( attr->AttributeType == AttributeFileName )
					{
						PFILENAME_ATTRIBUTE name = (PFILENAME_ATTRIBUTE)( (LPBYTE)attr + PRESIDENT_ATTRIBUTE(attr)->ValueOffset );
						// long name
						if( (name->NameType&1) == 1 )
						{
							if( GetFullPathByFileReferenceNumber( hVol, name->DirectoryFileReferenceNumber ) )
							{
								printf( "\\%.*S", name->NameLength, name->Name );
								ret = true;
							}
						}
					}
				}
			}
		}
		operator delete( nfrob );
	}
	return ret;
}

 

USNMethod.h

#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <string>
#include <deque>

using namespace std;

struct MY_USN_RECORD
{
	DWORDLONG FileReferenceNumber;
	DWORDLONG ParentFileReferenceNumber;
	LARGE_INTEGER TimeStamp;
	DWORD Reason;
	WCHAR FileName[MAX_PATH];
};


typedef struct {
	ULONG Type;
	USHORT UsaOffset;
	USHORT UsaCount;
	USN Usn;
} NTFS_RECORD_HEADER, *PNTFS_RECORD_HEADER;

typedef struct {
	NTFS_RECORD_HEADER Ntfs;
	USHORT SequenceNumber;
	USHORT LinkCount;
	USHORT AttributesOffset;
	USHORT Flags;               // 0x0001 = InUse, 0x0002 = Directory
	ULONG BytesInUse;
	ULONG BytesAllocated;
	ULONGLONG BaseFileRecord;
	USHORT NextAttributeNumber;
} FILE_RECORD_HEADER, *PFILE_RECORD_HEADER;

typedef enum {
	AttributeStandardInformation = 0x10,
	AttributeAttributeList = 0x20,
	AttributeFileName = 0x30,
	AttributeObjectId = 0x40,
	AttributeSecurityDescriptor = 0x50,
	AttributeVolumeName = 0x60,
	AttributeVolumeInformation = 0x70,
	AttributeData = 0x80,
	AttributeIndexRoot = 0x90,
	AttributeIndexAllocation = 0xA0,
	AttributeBitmap = 0xB0,
	AttributeReparsePoint = 0xC0,
	AttributeEAInformation = 0xD0,
	AttributeEA = 0xE0,
	AttributePropertySet = 0xF0,
	AttributeLoggedUtilityStream = 0x100
} ATTRIBUTE_TYPE, *PATTRIBUTE_TYPE;

typedef struct {
	ATTRIBUTE_TYPE AttributeType;
	ULONG Length;
	BOOLEAN Nonresident;
	UCHAR NameLength;
	USHORT NameOffset;
	USHORT Flags;               // 0x0001 = Compressed
	USHORT AttributeNumber;
} ATTRIBUTE, *PATTRIBUTE;

typedef struct {
	ATTRIBUTE Attribute;
	ULONGLONG LowVcn;
	ULONGLONG HighVcn;
	USHORT RunArrayOffset;
	UCHAR CompressionUnit;
	UCHAR AlignmentOrReserved[5];
	ULONGLONG AllocatedSize;
	ULONGLONG DataSize;
	ULONGLONG InitializedSize;
	ULONGLONG CompressedSize;    // Only when compressed
} NONRESIDENT_ATTRIBUTE, *PNONRESIDENT_ATTRIBUTE;

typedef struct {
	ATTRIBUTE Attribute;
	ULONG ValueLength;
	USHORT ValueOffset;
	USHORT Flags;               // 0x0001 = Indexed
} RESIDENT_ATTRIBUTE, *PRESIDENT_ATTRIBUTE;

typedef struct {
	ULONGLONG CreationTime;
	ULONGLONG ChangeTime;
	ULONGLONG LastWriteTime;
	ULONGLONG LastAccessTime;
	ULONG FileAttributes;
	ULONG AlignmentOrReservedOrUnknown[3];
	ULONG QuotaId;                        // NTFS 3.0 only
	ULONG SecurityId;                     // NTFS 3.0 only
	ULONGLONG QuotaCharge;                // NTFS 3.0 only
	USN Usn;                              // NTFS 3.0 only
} STANDARD_INFORMATION, *PSTANDARD_INFORMATION;

typedef struct {
	ULONGLONG DirectoryFileReferenceNumber;
	ULONGLONG CreationTime;   // Saved when filename last changed
	ULONGLONG ChangeTime;     // ditto
	ULONGLONG LastWriteTime;  // ditto
	ULONGLONG LastAccessTime; // ditto
	ULONGLONG AllocatedSize;  // ditto
	ULONGLONG DataSize;       // ditto
	ULONG FileAttributes;     // ditto
	ULONG AlignmentOrReserved;
	UCHAR NameLength;
	UCHAR NameType;           // 0x01 = Long, 0x02 = Short
	WCHAR Name[1];
} FILENAME_ATTRIBUTE, *PFILENAME_ATTRIBUTE;

HANDLE hVol = INVALID_HANDLE_VALUE;

bool EnumUsnRecord( const char* drvname, deque<MY_USN_RECORD>& con )
{
	bool ret = false;

	char FileSystemName[MAX_PATH+1];
	DWORD MaximumComponentLength;
	// 判断是否为 NTFS 格式
	if( GetVolumeInformationA( (string(drvname)+":\\").c_str(),0,0,0,&MaximumComponentLength,0,FileSystemName,MAX_PATH+1)
		&& 0==strcmp(FileSystemName,"NTFS") )
	{
		// 需要管理员权限,无奈
		hVol = CreateFileA( (string("\\\\.\\")+drvname+":").c_str() 
			, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
		if( hVol != INVALID_HANDLE_VALUE )
		{
			DWORD br;
			USN_JOURNAL_DATA qujd;
			if( DeviceIoControl( hVol, FSCTL_QUERY_USN_JOURNAL, NULL, 0, &qujd, sizeof(qujd), &br, NULL ) )
			{
				char buffer[0x1000];
				DWORD BytesReturned;
				{
					READ_USN_JOURNAL_DATA rujd = { 0, -1, 0, 0, 0, qujd.UsnJournalID };
					for( ; DeviceIoControl(hVol,FSCTL_READ_USN_JOURNAL,&rujd,sizeof(rujd),buffer,_countof(buffer),&BytesReturned,NULL); rujd.StartUsn=*(USN*)&buffer )
					{
						DWORD dwRetBytes = BytesReturned - sizeof(USN);
						PUSN_RECORD UsnRecord = (PUSN_RECORD)((PCHAR)buffer+sizeof(USN));
						if( dwRetBytes==0 )
						{
							ret = true;
							break;
						}

						while( dwRetBytes > 0 )
						{
							MY_USN_RECORD myur = { UsnRecord->FileReferenceNumber, UsnRecord->ParentFileReferenceNumber, UsnRecord->TimeStamp, UsnRecord->Reason };
							memcpy( myur.FileName, UsnRecord->FileName, UsnRecord->FileNameLength );
							myur.FileName[UsnRecord->FileNameLength/2] = L'\0';

							con.push_back( myur );

							dwRetBytes -= UsnRecord->RecordLength;
							UsnRecord = (PUSN_RECORD)( (PCHAR)UsnRecord + UsnRecord->RecordLength );
						}
					}
				}
			}
			//CloseHandle( hVol );
		}
	}
	return ret;
}
 

 

例子二:

USNEyesApp.cpp

/**
* 对Ntfs下USN操作的示例程序
*/
#include <iostream>
#include <Windows.h>
#include <fstream>

using namespace std;

char* volName = "F:\\"; // 驱动盘名称

HANDLE hVol; // 用于储存驱动盘句柄

USN_JOURNAL_DATA UsnInfo; // 用于储存USN日志的基本信息

#define BUF_LEN 4096

ofstream fout("c:\\log.txt"); // 用来将数据记录到文本,方便查看

long counter = 0;

int main()
{
	BOOL status;
	BOOL isNTFS = false;
	BOOL getHandleSuccess = false;
	BOOL initUsnJournalSuccess = false;

	/**
	* step 01. 判断驱动盘是否NTFS格式
	* msdn:http://msdn.microsoft.com/en-us/library/aa364993%28VS.85%29.aspx
	*/
	cout<< "step 01. 判断驱动盘是否NTFS格式\n";
	char sysNameBuf[MAX_PATH] = {0};
	status = GetVolumeInformationA(volName,
		NULL, // 驱动盘名缓冲,这里我们不需要
		0,
		NULL,
		NULL,
		NULL,
		sysNameBuf, // 驱动盘的系统名(FAT/NTFS)
		MAX_PATH);

	if(0!=status){
		cout<< "文件系统名:" << sysNameBuf << "\n";
		// 比较字符串
		if(0==strcmp(sysNameBuf, "NTFS")){
			cout<< "此驱动盘是NTFS格式!转向step-02.\n";
			isNTFS = true;
		}else{
			cout<< "该驱动盘非NTFS格式\n";
		}

	}

	// 只有NTFS才有USN,才能进行操作
	if(isNTFS){
		/**
		* step 02. 获取驱动盘句柄
		* msdn:http://msdn.microsoft.com/en-us/library/aa363858%28VS.85%29.aspx
		*/
		cout<<"step 02. 获取驱动盘句柄\n";
		char fileName[MAX_PATH];
		fileName[0] = '\0';

		// 传入的文件名必须为\\.\C:的形式
		strcpy_s(fileName, "\\\\.\\");
		strcat_s(fileName, volName);
		// 为了方便操作,这里转为string进行去尾
		string fileNameStr = (string)fileName;
		fileNameStr.erase(fileNameStr.find_last_of(":")+1);

		cout<< "驱动盘地址:" << fileNameStr.data() << "\n";

		// 调用该函数需要管理员权限
		hVol = CreateFileA(fileNameStr.data(),
			GENERIC_READ | GENERIC_WRITE, // 可以为0
			FILE_SHARE_READ | FILE_SHARE_WRITE, // 必须包含有FILE_SHARE_WRITE
			NULL, // 这里不需要
			OPEN_EXISTING, // 必须包含OPEN_EXISTING, CREATE_ALWAYS可能会导致错误
			FILE_ATTRIBUTE_READONLY, // FILE_ATTRIBUTE_NORMAL可能会导致错误
			NULL); // 这里不需要

		if(INVALID_HANDLE_VALUE!=hVol){
			cout<< "获取驱动盘句柄成功!转向step-03.\n";
			getHandleSuccess = true;
		}else{
			cout<< "获取驱动盘句柄失败 —— handle:" << hVol << " error:" << GetLastError() << "\n";
		}
	}

	if(getHandleSuccess){
		/**
		* step 03. 初始化USN日志文件
		* msdn:http://msdn.microsoft.com/en-us/library/aa364558%28v=VS.85%29.aspx
		*/
		cout<< "step 03. 初始化USN日志文件\n";
		DWORD br;
		CREATE_USN_JOURNAL_DATA cujd;
		cujd.MaximumSize = 0; // 0表示使用默认值
		cujd.AllocationDelta = 0; // 0表示使用默认值
		status = DeviceIoControl(hVol,
			FSCTL_CREATE_USN_JOURNAL,
			&cujd,
			sizeof(cujd),
			NULL,
			0,
			&br,
			NULL);

		if(0!=status){
			cout<< "初始化USN日志文件成功!转向step-04.\n";
			initUsnJournalSuccess = true;
		}else{
			cout<< "初始化USN日志文件失败 —— status:" << status << " error:" << GetLastError() << "\n";
		}
	}

	if(initUsnJournalSuccess){

		BOOL getBasicInfoSuccess = false;

		/**
		* step 04. 获取USN日志基本信息(用于后续操作)
		* msdn:http://msdn.microsoft.com/en-us/library/aa364583%28v=VS.85%29.aspx
		*/
		cout<< "step 04. 获取USN日志基本信息(用于后续操作)\n";
		DWORD br;
		status = DeviceIoControl(hVol,
			FSCTL_QUERY_USN_JOURNAL,
			NULL,
			0,
			&UsnInfo,
			sizeof(USN_JOURNAL_DATA),
			&br,
			NULL);

		if(0!=status){
			cout<< "获取USN日志基本信息成功!转向step-05.\n";
			getBasicInfoSuccess = true;
		}else{
			cout<< "获取USN日志基本信息失败 —— status:" << status << " error:" << GetLastError() << "\n";
		}

		if(getBasicInfoSuccess){
			cout<< "UsnJournalID: " << UsnInfo.UsnJournalID << "\n";
			cout<< "lowUsn: " << UsnInfo.FirstUsn << "\n";
			cout<< "highUsn: " << UsnInfo.NextUsn << "\n";

			/**
			* step 05. 枚举USN日志文件中的所有记录
			* msdn:http://msdn.microsoft.com/en-us/library/aa364563%28v=VS.85%29.aspx
			*/
			cout<< "step 05. 枚举USN日志文件中的所有记录\n";
			MFT_ENUM_DATA med;
			med.StartFileReferenceNumber = 0;
			med.LowUsn = 0;//UsnInfo.FirstUsn; 这里经测试发现,如果用FirstUsn有时候不正确,导致获取到不完整的数据,还是直接写0好.
			med.HighUsn = UsnInfo.NextUsn;

			CHAR buffer[BUF_LEN]; // 用于储存记录的缓冲,尽量足够地大
			DWORD usnDataSize;
			PUSN_RECORD UsnRecord;

			while(0!=DeviceIoControl(hVol,
				FSCTL_ENUM_USN_DATA,
				&med,
				sizeof(med),
				buffer,
				BUF_LEN,
				&usnDataSize,
				NULL))
			{
				DWORD dwRetBytes = usnDataSize - sizeof(USN);

				// 找到第一个USN记录
				// from MSDN(http://msdn.microsoft.com/en-us/library/aa365736%28v=VS.85%29.aspx):
				// return a USN followed by zero or more change journal records, each in a USN_RECORD structure. 
				UsnRecord = (PUSN_RECORD)(((PCHAR)buffer)+sizeof(USN));
				cout<< " ********************************** \n";
				while(dwRetBytes>0){
					// 打印获取到的信息
					const int strLen = UsnRecord->FileNameLength;
					char fileName[MAX_PATH] = {0};
					//char filePath[MAX_PATH] = {0};
					WideCharToMultiByte(CP_OEMCP,NULL,UsnRecord->FileName,strLen/2,fileName,strLen,NULL,FALSE);

					cout<< "FileName: " << fileName << "\n";
					// 下面两个file reference number可以用来获取文件的路径信息
					cout<< "FileReferenceNumber: " << UsnRecord->FileReferenceNumber << "\n";
					cout<< "ParentFileReferenceNumber: " << UsnRecord->ParentFileReferenceNumber << "\n";
					//cout<< "FilePath: " << filePath << "\n\n";

					fout << "FileName:" << fileName << endl;
					fout << "FileReferenceNumber:" << UsnRecord->FileReferenceNumber << endl;
					fout << "ParentFileReferenceNumber:" << UsnRecord->ParentFileReferenceNumber << endl;
					//fout << "FilePath:" << filePath << endl;
					fout << endl;
					counter++;

					// 获取下一个记录
					DWORD recordLen = UsnRecord->RecordLength;
					dwRetBytes -= recordLen;
					UsnRecord = (PUSN_RECORD)(((PCHAR)UsnRecord)+recordLen);
				}

				//获取下一页数据,MTF大概是分多页来储存的吧?
				// from MSDN(http://msdn.microsoft.com/en-us/library/aa365736%28v=VS.85%29.aspx):
				// The USN returned as the first item in the output buffer is the USN of the next record number to be retrieved. 
				// Use this value to continue reading records from the end boundary forward.
				med.StartFileReferenceNumber = *(USN *)&buffer;

			}
			cout<< "共" << counter << "个文件\n";

			fout << "共" << counter << "个文件" << endl;
			fout << flush;
			fout.close();
		}

		/**
		* step 06. 删除USN日志文件(当然也可以不删除)
		* msdn:http://msdn.microsoft.com/en-us/library/aa364561%28v=VS.85%29.aspx
		*/
		cout<< "step 06. 删除USN日志文件(当然也可以不删除)\n";
		DELETE_USN_JOURNAL_DATA dujd;
		dujd.UsnJournalID = UsnInfo.UsnJournalID;
		dujd.DeleteFlags = USN_DELETE_FLAG_DELETE;

		status = DeviceIoControl(hVol,
			FSCTL_DELETE_USN_JOURNAL,
			&dujd,
			sizeof(dujd),
			NULL,
			0,
			&br,
			NULL);

		if(0 != status){
			cout<< "成功删除USN日志文件!\n";
		}else{
			cout<< "删除USN日志文件失败 —— status:" << status << " error:" << GetLastError() << "\n";
		}
	}

	// 最后释放一些资源
	if(getHandleSuccess){
		CloseHandle(hVol);
	}

	// 避免后台程序一闪而过
	MessageBox(0, L"按确定退出", L"结束", MB_OK);

	return 0;
}
 

 

 

 

 

分享到:
评论

相关推荐

    获取USN日志基本信息

    关于获取USN基本日志信息的C++ code block 上运行,因为是自己参照网上VC版本改编的可能会有些许疏漏。

    读取USN,建立索引优化后的全盘快速搜索工具

    原理是读取USN文件日志,然后内建索引加快文件搜索速度。 1、列表文件支持批量处理(删除、复制、复制文件名路径、打开、重命名),或者引用系统菜单。 2、支持拼音首字母缩写搜索,指定文件夹内搜索,多关键词搜索...

    人工智能-项目实践-信息检索-用C++实现的基于NTFS下MFT和USN-Journal检索与类正则表达式-NFA-DFA字符串

    这个项目的核心是用C++编程语言实现了一套在NTFS文件系统中进行高效检索的系统,它利用了NTFS的元文件表(MFT)和更新序列号日志(USN Journal),同时结合了类正则表达式和状态自动机(NFA和DFA)的字符串匹配算法...

    C#制作的windows系统文件快速搜索工具,读取USN,易用性与速度都已优化的很好。程序为免安装的exe文件。

    原理是读取ntfs的USN文件日志,然后内建索引加速文件搜索过程。 1、列表文件支持批量处理(删除、复制、复制文件名路径、打开、重命名),或者引用系统菜单。 2、支持拼音首字母缩写搜索,指定文件夹内搜索,多...

    Usn__Use.rar_USN

    标题中的"Usn__Use.rar_USN"暗示了这个压缩包可能包含与USN日志(Update Sequence Number Journal)相关的程序或代码示例。USN日志是Windows操作系统中一个重要的系统组件,它记录了文件系统中所有更改的序列号,...

    filesearch_everything.rar

    1. **USN日志读取**:程序会包含如何打开并解析USN日志的代码,这涉及对`DeviceIoControl`函数的调用,传递`FSCTL_READ_FILE_USN_DATA`控制代码来获取特定文件的USN记录。 2. **变更通知注册**:为了实时跟踪文件...

    最好的日志分析工具(永久免费)

    一款非常好用的日志分析工具(永久免费),这三个数据:“访问次数”、“总停留时间”和“总抓取量”,都是数字越高对网站越有利,所以需要想很多办法提高他们。大多数时候看他们绝对值没什么用处,而要看现在的和...

    everything源码模拟

    在实现过程中,`NtfsDesktopSearch`可能包含了实现这个功能的相关代码,比如读取USN日志的函数、解析MFT和USN Journal的逻辑、构建及更新索引的算法,以及搜索接口等。这部分代码需要仔细阅读和理解,以确保正确地...

    华为USN9810V900R011产品概述.pdf

    华为USN9810是华为公司推出的一款高端核心路由器,主要应用于移动通信网络的核心层,特别在中国移动4G网络工程中扮演着重要角色。V900R011是该产品的某一版本,它在2019年7月进行了更新,体现了华为在技术研发上的...

    C#快速NTFS硬盘文件索引

    NTFS是Windows操作系统的主要文件系统,它提供了高级功能,如权限管理、事务支持以及USN(Update Sequence Number)日志。 USN日志是NTFS中的一个重要特性,用于记录文件系统中所有更改。每当文件或目录发生改变,...

    USN9810硬件数据配置

    华为MME USN9810硬件配置,最新架构的osta2.0介绍,基本的配置原则和步骤。

    Everything山寨版源码

    这个"Everything山寨版源码"显然是一款基于"Everything"的仿制品或修改版,其核心也是通过读取NTFS文件系统的USN(Update Sequence Number)日志来实现即时的文件索引和搜索功能。 NTFS USN日志是Windows操作系统为...

    用C++实现的基于NTFS下MFT和USN-Journal检索与类正则表达式-NFA-DFA字符串匹配的本地文件查找系统.zip

    C++是一种面向对象的计算机程序设计语言,由美国AT&T贝尔实验室的本贾尼·斯特劳斯特卢普博士在20世纪80年代初期发明并实现(最初这种语言被称作“C with Classes”带类的C)。它是一种静态数据类型检查的、支持多重...

    pyntfsjournal-开源

    《深入理解NTFS USN日志与Python解析库pyntfsjournal》 在Windows操作系统中,NTFS(New Technology File System)是默认的文件系统,它具有诸多高级特性,其中USN(Update Sequence Number)日志就是一项重要的...

    java版everything+纯java不用任何包读取office中word文件

    在Java编程领域,读取和操作Office文档,特别是Word文件,通常需要依赖第三方库,如Apache POI或OpenOffice ...如果你对这个项目感兴趣,可以从提供的`vskeverything`压缩包中获取源代码,进一步学习和研究其工作原理。

    USN物料资源编码2222

    USN物料资源编码2222

    USN Seminar Papers

    《无线网络传感器路由算法基础论文合集》是一个针对无线传感器网络(Wireless Sensor Networks, WSN)初学者的重要资源包,包含了一系列关于该领域路由算法的基础研究论文。无线传感器网络是由大量微型传感器节点...

    page_usn.json

    page_usn.json

    USNVC-Selector

    1. **USN日志**:这是Windows NTFS文件系统的一个特性,它是一个持久化的日志,记录了文件系统中所有对象(文件、目录)的变化。每次变化都会分配一个唯一的USN,使得跟踪和回溯文件系统的状态成为可能。 2. **文件...

Global site tag (gtag.js) - Google Analytics