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 />

because <strong>the</strong> server writes a line to <strong>the</strong> file when a connection is established <strong>and</strong><br />

ano<strong>the</strong>r line when <strong>the</strong> connection is terminated; at this point in time this project is<br />

only interested in <strong>the</strong> data that is being sent from <strong>the</strong> client.<br />

// Declare new instance <strong>of</strong> StreamReader <strong>and</strong> tell it <strong>the</strong> filename.<br />

StreamReader sr = new StreamReader("c:\\Evt<strong>Log</strong>2.log");<br />

// Decalare local variable.<br />

string line;<br />

// Repeat <strong>the</strong> following until all lines are read from file.<br />

while ((line = sr.ReadLine()) != null)<br />

{<br />

// Only copy <strong>the</strong> lines that contain .<br />

if(line.Contains(""))<br />

{<br />

// Add <strong>the</strong> lines to <strong>the</strong> array called ‘lines’.<br />

lines.Add(line);<br />

}<br />

}<br />

// Close <strong>the</strong> file.<br />

sr.Close();<br />

Figure 31: Reading a file<br />

5.4.2 Decoding XML<br />

To convert <strong>the</strong> flat XML strings that are contained within <strong>the</strong> <strong>Log</strong> file a simple piece<br />

<strong>of</strong> code was written that could extract <strong>the</strong> data. Figure 32 shows this for extracting <strong>the</strong><br />

data from <strong>the</strong> tags. First it calculates <strong>the</strong> starting point <strong>of</strong> <strong>the</strong> required<br />

data by working out <strong>the</strong> size <strong>of</strong> <strong>the</strong> opening tag. Then it calculates <strong>the</strong> end point <strong>of</strong> <strong>the</strong><br />

data based upon <strong>the</strong> length <strong>of</strong> <strong>the</strong> closing tag. It <strong>the</strong>n displays <strong>the</strong> data on <strong>the</strong> screen.<br />

// Copy <strong>the</strong> currently selected array item to string1.<br />

string string1 = Convert.ToString(lines[arrayItem]);<br />

// Define <strong>the</strong> start tag.<br />

string myString1 = "";<br />

// Define <strong>the</strong> end tag.<br />

string myString2 = "";<br />

// Calculate <strong>the</strong> starting <strong>and</strong> ending points <strong>of</strong> <strong>the</strong> data contined<br />

// within <strong>the</strong> start <strong>and</strong> end tags.<br />

serverTimeLbl.Text = string1.Substring((string1.IndexOf(myString1) +<br />

myString1.Length), (string1.IndexOf(myString2) -<br />

(string1.IndexOf(myString1) + myString1.Length)));<br />

// Repeat this process for all <strong>the</strong> tags.<br />

Figure 32: Dividing up an XML string<br />

48

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

Saved successfully!

Ooh no, something went wrong!