25.12.2014 Views

Analysis and Evaluation of the Windows Event Log - Bill Buchanan

Analysis and Evaluation of the Windows Event Log - Bill Buchanan

Analysis and Evaluation of the Windows Event Log - Bill Buchanan

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Barrie Codona, BSc (Hons) Network Computing, 2007<br />

5.2.2 FileSystemWatcher<br />

The ‘FileSystemWatcher’ class is part <strong>of</strong> <strong>the</strong> ‘System.IO’ namespace provided by<br />

.NET versions 1.1 though to <strong>the</strong> current 3.5. According to MSDN it listens to <strong>the</strong> file<br />

system change notifications <strong>and</strong> raises events when a directory, or file in a directory,<br />

changes. In Figure 21 The FileSystemWatcher is set to watch all files that are<br />

contained in <strong>the</strong> ‘C:\Test\’ directory. Multiple instances <strong>of</strong> FileSystemWatcher can<br />

also be run to monitor o<strong>the</strong>r directories, that way multiple directories can monitored<br />

using a single application.<br />

// Create a new FileSystemWatcher <strong>and</strong> set its properties.<br />

FileSystemWatcher watcher = new FileSystemWatcher();<br />

//<br />

Specify <strong>the</strong> path to watch.<br />

watcher.Path = "c:\\Test\\";<br />

watcher.NotifyFilter = NotifyFilters.LastAccess<br />

|<br />

NotifyFilters.LastWrite<br />

| NotifyFilters.FileName | NotifyFilters.DirectoryName;<br />

//<br />

Specify <strong>the</strong> file <strong>and</strong>/or extension to watch.<br />

watcher.Filter = "*.*";<br />

ries = true;<br />

watcher.IncludeSubdirecto<br />

// Add event h<strong>and</strong>lers.<br />

watcher.Changed += new FileSystem<strong>Event</strong>H<strong>and</strong>ler(OnChanged);<br />

watcher.Created += new FileSystem<strong>Event</strong>H<strong>and</strong>ler(OnChanged);<br />

watcher.Deleted += new FileSystem<strong>Event</strong>H<strong>and</strong>ler(OnChanged);<br />

watcher.Renamed += new Renamed<strong>Event</strong>H<strong>and</strong>ler(OnRenamed);<br />

// Specify <strong>the</strong> buffer size, default is 8192 (8K).<br />

watcher.InternalBufferSize = 102400;<br />

// Begin Watching.<br />

watcher.EnableRaising<strong>Event</strong>s = true;<br />

Figure 21: The FileSystemWatcher class<br />

5.2.3 Capturing <strong>Event</strong>s<br />

When a ‘Renamed’ event occurs it is passed to <strong>the</strong> above ‘OnRenamed’ class, this<br />

<strong>the</strong>n wraps <strong>the</strong> various elements <strong>of</strong> <strong>the</strong> event in XML tags, this creates an ‘<strong>Event</strong><br />

Message’ <strong>and</strong> includes such things as <strong>the</strong> clients time <strong>and</strong> date, <strong>the</strong> user <strong>and</strong> details<br />

about <strong>the</strong> event <strong>and</strong> <strong>the</strong> file that was renamed. This is a similar process when a file is<br />

changed. After this stage <strong>the</strong> <strong>Event</strong> Message is passed though to <strong>the</strong> HMAC section,<br />

where a hash signature value will be generated for it. Figure 22 shows this.<br />

42

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!