|
From: <mat...@us...> - 2009-01-29 22:41:13
|
Revision: 165
http://bugreport.svn.sourceforge.net/bugreport/?rev=165&view=rev
Author: matt_hargett
Date: 2009-01-29 21:45:15 +0000 (Thu, 29 Jan 2009)
Log Message:
-----------
Matt - fix all the StyleCop warnings that are easy/relevant.
Modified Paths:
--------------
AbstractBuffer.cs
AbstractBufferTest.cs
AbstractValue.cs
AbstractValueTest.cs
AnalysisEngine.csproj
Analyzer.cs
AnalyzerTest.cs
AssemblyInfo.cs
BitMath.cs
BitMathTest.cs
Contract.cs
DebuggerCommand.cs
DebuggerCommandTest.cs
DebuggerView.cs
DumpFileParser.cs
DumpFileParserTest.cs
ElfFileParser.cs
ElfFileParserTest.cs
GLibcStartMainContract.cs
GLibcStartMainContractTest.cs
MachineState.cs
MachineStateTest.cs
Main.cs
MainTest.cs
MallocContract.cs
ModRM.cs
ModRMTest.cs
Opcode.cs
OpcodeFormatter.cs
OpcodeFormatterTest.cs
Options.cs
OptionsTest.cs
RegisterCollection.cs
RegisterCollectionTest.cs
ReportItem.cs
SIB.cs
SIBTests.cs
X86Emulator.cs
X86EmulatorTest.cs
X86Opcode.cs
X86OpcodeTest.cs
bugreport.sln
Added Paths:
-----------
InvalidOpcodeException.cs
Modified: AbstractBuffer.cs
===================================================================
--- AbstractBuffer.cs 2009-01-29 05:41:37 UTC (rev 164)
+++ AbstractBuffer.cs 2009-01-29 21:45:15 UTC (rev 165)
@@ -1,33 +1,43 @@
-// This file is part of bugreport.
-// Copyright (c) 2006-2009 The bugreport Developers.
-// See AUTHORS.txt for details.
-// Licensed under the GNU General Public License, Version 3 (GPLv3).
-// See LICENSE.txt for details.
-
+// This file is part of bugreport.
+// Copyright (c) 2006-2009 The bugreport Developers.
+// See AUTHORS.txt for details.
+// Licensed under the GNU General Public License, Version 3 (GPLv3).
+// See LICENSE.txt for details.
+
using System;
-namespace bugreport
-{
- public class AbstractBuffer
+namespace bugreport
+{
+ public class AbstractBuffer
{
- private readonly Int32 allocatedLength;
+ private readonly Int32 allocatedLength;
private UInt32 baseIndex;
- private AbstractValue[] storage;
-
- public AbstractBuffer(AbstractValue[] _buffer)
- {
- storage = _buffer;
- allocatedLength = storage.Length;
- }
-
- public AbstractBuffer(AbstractBuffer _copyMe)
- {
- baseIndex = _copyMe.BaseIndex;
- allocatedLength = _copyMe.allocatedLength;
- storage = new AbstractValue[_copyMe.storage.Length];
- Array.Copy(_copyMe.storage, storage, _copyMe.storage.Length);
+ private AbstractValue[] storage;
+
+ public AbstractBuffer(AbstractValue[] _buffer)
+ {
+ storage = _buffer;
+ allocatedLength = storage.Length;
}
+ public AbstractBuffer(AbstractBuffer _copyMe)
+ {
+ baseIndex = _copyMe.BaseIndex;
+ allocatedLength = _copyMe.allocatedLength;
+ storage = new AbstractValue[_copyMe.storage.Length];
+ Array.Copy(_copyMe.storage, storage, _copyMe.storage.Length);
+ }
+
+ public UInt32 BaseIndex
+ {
+ get { return baseIndex; }
+ }
+
+ public Int32 Length
+ {
+ get { return allocatedLength; }
+ }
+
public AbstractValue this[Int32 index]
{
get
@@ -61,72 +71,64 @@
}
}
- public UInt32 BaseIndex
+ public AbstractBuffer DoOperation(OperatorEffect _operatorEffect, AbstractValue _rhs)
{
- get { return baseIndex; }
- }
+ AbstractBuffer lhs = this;
- public Int32 Length
- {
- get { return allocatedLength; }
- }
-
- public AbstractBuffer DoOperation(OperatorEffect _operatorEffect, AbstractValue _rhs)
- {
- AbstractBuffer lhs = this;
-
- // TODO: should have a guard for if _rhs isnt a pointer
-
- switch (_operatorEffect)
- {
- case OperatorEffect.Assignment:
- {
- var result = new AbstractBuffer(lhs);
-
- return result;
- }
-
- case OperatorEffect.Add:
- {
- var result = new AbstractBuffer(lhs);
- result.baseIndex += _rhs.Value;
-
- return result;
- }
-
- case OperatorEffect.Sub:
- {
- var result = new AbstractBuffer(lhs);
-
- if (result.baseIndex < _rhs.Value)
- {
+ // TODO: should have a guard for if _rhs isn't a pointer
+ switch (_operatorEffect)
+ {
+ case OperatorEffect.Assignment:
+ {
+ var result = new AbstractBuffer(lhs);
+
+ return result;
+ }
+
+ case OperatorEffect.Add:
+ {
+ var result = new AbstractBuffer(lhs);
+ result.baseIndex += _rhs.Value;
+
+ return result;
+ }
+
+ case OperatorEffect.Sub:
+ {
+ var result = new AbstractBuffer(lhs);
+
+ if (result.baseIndex < _rhs.Value)
+ {
throw new ArgumentOutOfRangeException(
String.Format(
"Attempting to set a negative baseindex, baseindex: {0:x4}, _subValue {1:x4}",
- result.baseIndex, _rhs.Value));
- }
-
- result.baseIndex -= _rhs.Value;
- return result;
- }
-
- case OperatorEffect.And:
- {
- var result = new AbstractBuffer(lhs);
-
- result.baseIndex &= _rhs.Value;
- return result;
- }
-
- default:
+ result.baseIndex,
+ _rhs.Value
+ )
+ );
+ }
+
+ result.baseIndex -= _rhs.Value;
+ return result;
+ }
+
+ case OperatorEffect.And:
+ {
+ var result = new AbstractBuffer(lhs);
+
+ result.baseIndex &= _rhs.Value;
+ return result;
+ }
+
+ default:
throw new ArgumentException(
- String.Format("Unsupported OperatorEffect: {0}", _operatorEffect), "_operatorEffect");
- }
+ String.Format("Unsupported OperatorEffect: {0}", _operatorEffect), "_operatorEffect");
+ }
}
- private Boolean IsIndexPastBounds(Int32 index)
- {
- return (((baseIndex + index) >= allocatedLength) && ((baseIndex + index) >= storage.Length));
+ private Boolean IsIndexPastBounds(Int32 index)
+ {
+ return ((baseIndex + index) >= allocatedLength) && ((baseIndex + index) >= storage.Length);
}
private void extend(UInt32 _newLength)
@@ -153,6 +155,6 @@
}
return;
- }
- }
+ }
+ }
}
\ No newline at end of file
Modified: AbstractBufferTest.cs
===================================================================
--- AbstractBufferTest.cs 2009-01-29 05:41:37 UTC (rev 164)
+++ AbstractBufferTest.cs 2009-01-29 21:45:15 UTC (rev 165)
@@ -1,216 +1,216 @@
-// This file is part of bugreport.
-// Copyright (c) 2006-2009 The bugreport Developers.
-// See AUTHORS.txt for details.
-// Licensed under the GNU General Public License, Version 3 (GPLv3).
-// See LICENSE.txt for details.
-
+// This file is part of bugreport.
+// Copyright (c) 2006-2009 The bugreport Developers.
+// See AUTHORS.txt for details.
+// Licensed under the GNU General Public License, Version 3 (GPLv3).
+// See LICENSE.txt for details.
+
using System;
using NUnit.Framework;
-namespace bugreport
-{
- [TestFixture]
- public class AbstractBufferTest
+namespace bugreport
+{
+ [TestFixture]
+ public class AbstractBufferTest
{
- [Test]
- public void Copy()
- {
- AbstractValue[] values = AbstractValue.GetNewBuffer(4);
- var buffer = new AbstractBuffer(values);
- var newBuffer = new AbstractBuffer(buffer);
- Assert.AreNotSame(newBuffer, buffer);
-
- for (Int32 index = 0; index < newBuffer.Length; index++)
- {
- Assert.AreSame(newBuffer[index], buffer[index]);
- }
+ [Test]
+ public void Copy()
+ {
+ AbstractValue[] values = AbstractValue.GetNewBuffer(4);
+ var buffer = new AbstractBuffer(values);
+ var newBuffer = new AbstractBuffer(buffer);
+ Assert.AreNotSame(newBuffer, buffer);
+
+ for (Int32 index = 0; index < newBuffer.Length; index++)
+ {
+ Assert.AreSame(newBuffer[index], buffer[index]);
+ }
}
- [Test]
- [ExpectedException(typeof (ArgumentOutOfRangeException))]
- public void InvalidPointerAnd()
- {
- var one = new AbstractValue(0x1);
- var buffer = new AbstractBuffer(new[] {one});
- AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Sub, new AbstractValue(3));
- modifiedBuffer.DoOperation(OperatorEffect.And, new AbstractValue(0xf));
+ [Test]
+ [ExpectedException(typeof(ArgumentOutOfRangeException))]
+ public void InvalidPointerAnd()
+ {
+ var one = new AbstractValue(0x1);
+ var buffer = new AbstractBuffer(new[] {one});
+ AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Sub, new AbstractValue(3));
+ modifiedBuffer.DoOperation(OperatorEffect.And, new AbstractValue(0xf));
}
- [Test]
- public void OverflowDoesntLoseIncrement()
- {
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
- var pointer = new AbstractBuffer(buffer);
- var value = new AbstractValue(0x41);
- value = value.AddTaint();
-
- pointer[0] = value;
-
- pointer = pointer.DoOperation(OperatorEffect.Add, new AbstractValue(1));
-
- pointer[16] = value;
-
- pointer = pointer.DoOperation(OperatorEffect.Sub, new AbstractValue(1));
-
- Assert.AreEqual(0x41, pointer[0].Value);
- Assert.IsTrue(value.IsTainted);
- Assert.AreEqual(0x41, pointer[17].Value);
- Assert.IsTrue(pointer[17].IsTainted);
- }
-
- [Test]
- public void OverflowZeroSizeBuffer()
- {
- var f = new AbstractBuffer(new AbstractValue[] {});
- Assert.IsFalse(f[0].IsInitialized);
- }
-
- [Test]
- public void PointerAdd()
- {
- var one = new AbstractValue(0x1);
- var two = new AbstractValue(0x2);
- var three = new AbstractValue(0x3);
- var four = new AbstractValue(0x4);
- AbstractValue[] values = AbstractValue.GetNewBuffer(4);
-
- values[0] = one;
- values[1] = two;
- values[2] = three;
- values[3] = four;
-
- var buffer = new AbstractBuffer(values);
- Assert.AreEqual(one, buffer[0]);
- AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(2));
- Assert.AreEqual(three, modifiedBuffer[0]);
- }
-
- [Test]
- public void PointerAnd()
- {
- var one = new AbstractValue(0x1);
- var two = new AbstractValue(0x2);
- var three = new AbstractValue(0x3);
- var four = new AbstractValue(0x4);
- AbstractValue[] avBuffer = AbstractValue.GetNewBuffer(4);
-
- avBuffer[0] = one;
- avBuffer[1] = two;
- avBuffer[2] = three;
- avBuffer[3] = four;
-
- var buffer = new AbstractBuffer(avBuffer);
- Assert.AreEqual(one, buffer[0]);
- AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(3));
- Assert.AreEqual(four, modifiedBuffer[0]);
- AbstractBuffer andedBuffer = modifiedBuffer.DoOperation(OperatorEffect.And, new AbstractValue(0xfffffff0));
- Assert.AreEqual(one, andedBuffer[0]);
+ [Test]
+ public void OverflowDoesntLoseIncrement()
+ {
+ AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
+ var pointer = new AbstractBuffer(buffer);
+ var value = new AbstractValue(0x41);
+ value = value.AddTaint();
+
+ pointer[0] = value;
+
+ pointer = pointer.DoOperation(OperatorEffect.Add, new AbstractValue(1));
+
+ pointer[16] = value;
+
+ pointer = pointer.DoOperation(OperatorEffect.Sub, new AbstractValue(1));
+
+ Assert.AreEqual(0x41, pointer[0].Value);
+ Assert.IsTrue(value.IsTainted);
+ Assert.AreEqual(0x41, pointer[17].Value);
+ Assert.IsTrue(pointer[17].IsTainted);
}
- [Test]
- public void PointerAssignment()
- {
- AbstractValue[] values = AbstractValue.GetNewBuffer(4);
- var buffer = new AbstractBuffer(values);
- AbstractBuffer assignedBuffer = buffer.DoOperation(OperatorEffect.Assignment, null);
- Assert.AreNotSame(buffer, assignedBuffer);
- }
-
- [Test]
- public void PointerOverflowByOne()
- {
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
- var pointer = new AbstractBuffer(buffer);
-
- AbstractValue value = pointer[16];
- Assert.IsTrue(value.IsOOB);
- Assert.IsFalse(value.IsInitialized);
- Assert.AreEqual(AbstractValue.UNKNOWN, value.Value);
- }
-
- [Test]
- public void PointerOverflowStillRetainsOldValues()
- {
- var test1 = new AbstractValue(0x41);
- var test2 = new AbstractValue(0x42);
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(2);
-
- buffer[0] = test1;
- buffer[1] = test2;
-
- var pointer = new AbstractBuffer(buffer);
-
- // Accessing pointer[2] will cause the AbstractBuffer to extend..
- Assert.IsTrue(pointer[2].IsOOB, " value is not out of bounds");
- Assert.IsFalse(pointer[2].IsInitialized);
- Assert.AreEqual(AbstractValue.UNKNOWN, pointer[2].Value);
-
- // And then we make sure the in bounds values stay the same
- Assert.IsFalse(pointer[0].IsOOB);
- Assert.IsFalse(pointer[1].IsOOB);
-
- Assert.AreEqual(0x41, pointer[0].Value);
- Assert.AreEqual(0x42, pointer[1].Value);
- }
-
- [Test]
- public void PointerOverflowTwiceStillRetainsOriginalValues()
- {
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
- var pointer = new AbstractBuffer(buffer);
-
- //Access beyond buffer bounds forcing buffer to expand
- Assert.IsTrue(pointer[17].IsOOB);
- Assert.IsFalse(pointer[17].IsInitialized);
- Assert.AreEqual(AbstractValue.UNKNOWN, pointer[17].Value);
-
- pointer[17] = new AbstractValue(0x41414141);
-
- // Access beyond previously expanded bounds to force 2nd expand
- Assert.IsTrue(pointer[64].IsOOB);
- Assert.IsFalse(pointer[64].IsInitialized);
- Assert.AreEqual(AbstractValue.UNKNOWN, pointer[64].Value);
-
- // check that value set outside of bounds is still the same as well
- Assert.IsTrue(pointer[17].IsOOB);
- Assert.AreEqual(0x41414141, pointer[17].Value);
+ [Test]
+ public void OverflowZeroSizeBuffer()
+ {
+ var f = new AbstractBuffer(new AbstractValue[] {});
+ Assert.IsFalse(f[0].IsInitialized);
}
- [Test]
- public void PointerSub()
- {
- var one = new AbstractValue(0x1);
- var two = new AbstractValue(0x2);
- var three = new AbstractValue(0x3);
- var four = new AbstractValue(0x4);
- AbstractValue[] values = AbstractValue.GetNewBuffer(4);
-
- values[0] = one;
- values[1] = two;
- values[2] = three;
- values[3] = four;
-
- var buffer = new AbstractBuffer(values);
- Assert.AreEqual(one, buffer[0]);
- AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(2));
- Assert.AreEqual(three, modifiedBuffer[0]);
-
- AbstractBuffer subbedBuffer = modifiedBuffer.DoOperation(OperatorEffect.Sub, new AbstractValue(2));
- Assert.AreEqual(one, subbedBuffer[0]);
- }
-
- [Test]
- [ExpectedException(typeof (ArgumentOutOfRangeException))]
- public void PointerSubUnderflow()
- {
- new AbstractBuffer(new AbstractValue[] {}).DoOperation(OperatorEffect.Sub, new AbstractValue(1));
+ [Test]
+ public void PointerAdd()
+ {
+ var one = new AbstractValue(0x1);
+ var two = new AbstractValue(0x2);
+ var three = new AbstractValue(0x3);
+ var four = new AbstractValue(0x4);
+ AbstractValue[] values = AbstractValue.GetNewBuffer(4);
+
+ values[0] = one;
+ values[1] = two;
+ values[2] = three;
+ values[3] = four;
+
+ var buffer = new AbstractBuffer(values);
+ Assert.AreEqual(one, buffer[0]);
+ AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(2));
+ Assert.AreEqual(three, modifiedBuffer[0]);
}
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void PointerUnknownOperation()
- {
- new AbstractBuffer(new AbstractValue[] {}).DoOperation(OperatorEffect.Unknown, null);
+ [Test]
+ public void PointerAnd()
+ {
+ var one = new AbstractValue(0x1);
+ var two = new AbstractValue(0x2);
+ var three = new AbstractValue(0x3);
+ var four = new AbstractValue(0x4);
+ AbstractValue[] values = AbstractValue.GetNewBuffer(4);
+
+ values[0] = one;
+ values[1] = two;
+ values[2] = three;
+ values[3] = four;
+
+ var buffer = new AbstractBuffer(values);
+ Assert.AreEqual(one, buffer[0]);
+ AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(3));
+ Assert.AreEqual(four, modifiedBuffer[0]);
+ AbstractBuffer andedBuffer = modifiedBuffer.DoOperation(OperatorEffect.And, new AbstractValue(0xfffffff0));
+ Assert.AreEqual(one, andedBuffer[0]);
}
- }
+
+ [Test]
+ public void PointerAssignment()
+ {
+ AbstractValue[] values = AbstractValue.GetNewBuffer(4);
+ var buffer = new AbstractBuffer(values);
+ AbstractBuffer assignedBuffer = buffer.DoOperation(OperatorEffect.Assignment, null);
+ Assert.AreNotSame(buffer, assignedBuffer);
+ }
+
+ [Test]
+ public void PointerOverflowByOne()
+ {
+ AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
+ var pointer = new AbstractBuffer(buffer);
+
+ AbstractValue value = pointer[16];
+ Assert.IsTrue(value.IsOOB);
+ Assert.IsFalse(value.IsInitialized);
+ Assert.AreEqual(AbstractValue.UNKNOWN, value.Value);
+ }
+
+ [Test]
+ public void PointerOverflowStillRetainsOldValues()
+ {
+ var test1 = new AbstractValue(0x41);
+ var test2 = new AbstractValue(0x42);
+ AbstractValue[] buffer = AbstractValue.GetNewBuffer(2);
+
+ buffer[0] = test1;
+ buffer[1] = test2;
+
+ var pointer = new AbstractBuffer(buffer);
+
+ // Accessing pointer[2] will cause the AbstractBuffer to extend..
+ Assert.IsTrue(pointer[2].IsOOB, " value is not out of bounds");
+ Assert.IsFalse(pointer[2].IsInitialized);
+ Assert.AreEqual(AbstractValue.UNKNOWN, pointer[2].Value);
+
+ // And then we make sure the in bounds values stay the same
+ Assert.IsFalse(pointer[0].IsOOB);
+ Assert.IsFalse(pointer[1].IsOOB);
+
+ Assert.AreEqual(0x41, pointer[0].Value);
+ Assert.AreEqual(0x42, pointer[1].Value);
+ }
+
+ [Test]
+ public void PointerOverflowTwiceStillRetainsOriginalValues()
+ {
+ AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
+ var pointer = new AbstractBuffer(buffer);
+
+ // Access beyond buffer bounds forcing buffer to expand
+ Assert.IsTrue(pointer[17].IsOOB);
+ Assert.IsFalse(pointer[17].IsInitialized);
+ Assert.AreEqual(AbstractValue.UNKNOWN, pointer[17].Value);
+
+ pointer[17] = new AbstractValue(0x41414141);
+
+ // Access beyond previously expanded bounds to force 2nd expand
+ Assert.IsTrue(pointer[64].IsOOB);
+ Assert.IsFalse(pointer[64].IsInitialized);
+ Assert.AreEqual(AbstractValue.UNKNOWN, pointer[64].Value);
+
+ // check that value set outside of bounds is still the same as well
+ Assert.IsTrue(pointer[17].IsOOB);
+ Assert.AreEqual(0x41414141, pointer[17].Value);
+ }
+
+ [Test]
+ public void PointerSub()
+ {
+ var one = new AbstractValue(0x1);
+ var two = new AbstractValue(0x2);
+ var three = new AbstractValue(0x3);
+ var four = new AbstractValue(0x4);
+ AbstractValue[] values = AbstractValue.GetNewBuffer(4);
+
+ values[0] = one;
+ values[1] = two;
+ values[2] = three;
+ values[3] = four;
+
+ var buffer = new AbstractBuffer(values);
+ Assert.AreEqual(one, buffer[0]);
+ AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(2));
+ Assert.AreEqual(three, modifiedBuffer[0]);
+
+ AbstractBuffer subbedBuffer = modifiedBuffer.DoOperation(OperatorEffect.Sub, new AbstractValue(2));
+ Assert.AreEqual(one, subbedBuffer[0]);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentOutOfRangeException))]
+ public void PointerSubUnderflow()
+ {
+ new AbstractBuffer(new AbstractValue[] {}).DoOperation(OperatorEffect.Sub, new AbstractValue(1));
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentException))]
+ public void PointerUnknownOperation()
+ {
+ new AbstractBuffer(new AbstractValue[] {}).DoOperation(OperatorEffect.Unknown, null);
+ }
+ }
}
\ No newline at end of file
Modified: AbstractValue.cs
===================================================================
--- AbstractValue.cs 2009-01-29 05:41:37 UTC (rev 164)
+++ AbstractValue.cs 2009-01-29 21:45:15 UTC (rev 165)
@@ -1,220 +1,223 @@
-// This file is part of bugreport.
-// Copyright (c) 2006-2009 The bugreport Developers.
-// See AUTHORS.txt for details.
-// Licensed under the GNU General Public License, Version 3 (GPLv3).
-// See LICENSE.txt for details.
-
+// This file is part of bugreport.
+// Copyright (c) 2006-2009 The bugreport Developers.
+// See AUTHORS.txt for details.
+// Licensed under the GNU General Public License, Version 3 (GPLv3).
+// See LICENSE.txt for details.
+
using System;
using System.Text;
-namespace bugreport
-{
- public class AbstractValue
- {
+namespace bugreport
+{
+ public class AbstractValue
+ {
public const UInt32 MAX_BUFFER_SIZE = 25600000;
public const UInt32 UNKNOWN = 0xb4dc0d3d;
- private readonly AbstractBuffer pointsTo;
- private readonly UInt32 storage;
- private Boolean tainted;
-
- public AbstractValue()
- {
- storage = UNKNOWN;
- }
-
- public AbstractValue(AbstractValue[] _willPointTo)
- {
- if (_willPointTo.Length == 0)
- {
- throw new ArgumentException("Empty buffer is not allowed", "_willPointTo");
- }
-
- storage = 0xdeadbeef;
- pointsTo = new AbstractBuffer(_willPointTo);
- }
-
- public AbstractValue(AbstractBuffer _willPointTo)
- {
- if (_willPointTo.Length == 0)
- {
- throw new ArgumentException("Empty buffer is not allowed", "_willPointTo");
- }
-
- storage = 0xdeadbeef;
- pointsTo = new AbstractBuffer(_willPointTo);
- }
-
- public AbstractValue(AbstractValue _copyMe)
- {
- if (_copyMe == null)
- {
- throw new ArgumentNullException("_copyMe");
- }
-
- storage = _copyMe.Value;
- tainted = _copyMe.IsTainted;
- IsOOB = _copyMe.IsOOB;
-
- if (_copyMe.PointsTo != null)
- {
- pointsTo = new AbstractBuffer(_copyMe.PointsTo);
- }
- }
-
- public AbstractValue(UInt32 _value)
- {
- storage = _value;
- }
-
- public AbstractBuffer PointsTo
- {
- get { return pointsTo; }
- }
-
- public Boolean IsTainted
- {
- get { return tainted; }
-
- private set { tainted = value; }
- }
-
- public Boolean IsOOB { get; set; }
-
- public Boolean IsInitialized
- {
- get { return storage != UNKNOWN; }
- }
-
- public UInt32 Value
- {
- get { return storage; }
- }
-
- public Boolean IsPointer
- {
- get { return pointsTo != null; }
+ private readonly AbstractBuffer pointsTo;
+ private readonly UInt32 storage;
+ private Boolean tainted;
+
+ public AbstractValue()
+ {
+ storage = UNKNOWN;
}
- public override Boolean Equals(object obj)
- {
- var other = obj as AbstractValue;
-
- if (null == other)
- {
- return false;
- }
-
- return Value == other.Value &&
- IsOOB == other.IsOOB &&
- IsTainted == other.IsTainted &&
- PointsTo == other.PointsTo;
- }
-
- public override Int32 GetHashCode()
- {
- Int32 hashCode = Value.GetHashCode() ^ IsOOB.GetHashCode() ^
- IsTainted.GetHashCode();
-
- if (PointsTo != null)
- {
- hashCode ^= PointsTo.GetHashCode();
- }
-
- return hashCode;
- }
-
- public static AbstractValue[] GetNewBuffer(UInt32 size)
- {
- if (size > MAX_BUFFER_SIZE)
- {
+ public AbstractValue(AbstractValue[] _willPointTo)
+ {
+ if (_willPointTo.Length == 0)
+ {
+ throw new ArgumentException("Empty buffer is not allowed", "_willPointTo");
+ }
+
+ storage = 0xdeadbeef;
+ pointsTo = new AbstractBuffer(_willPointTo);
+ }
+
+ public AbstractValue(AbstractBuffer _willPointTo)
+ {
+ if (_willPointTo.Length == 0)
+ {
+ throw new ArgumentException("Empty buffer is not allowed", "_willPointTo");
+ }
+
+ storage = 0xdeadbeef;
+ pointsTo = new AbstractBuffer(_willPointTo);
+ }
+
+ public AbstractValue(AbstractValue _copyMe)
+ {
+ if (_copyMe == null)
+ {
+ throw new ArgumentNullException("_copyMe");
+ }
+
+ storage = _copyMe.Value;
+ tainted = _copyMe.IsTainted;
+ IsOOB = _copyMe.IsOOB;
+
+ if (_copyMe.PointsTo != null)
+ {
+ pointsTo = new AbstractBuffer(_copyMe.PointsTo);
+ }
+ }
+
+ public AbstractValue(UInt32 _value)
+ {
+ storage = _value;
+ }
+
+ public AbstractBuffer PointsTo
+ {
+ get { return pointsTo; }
+ }
+
+ public Boolean IsTainted
+ {
+ get { return tainted; }
+
+ private set { tainted = value; }
+ }
+
+ public Boolean IsOOB { get; set; }
+
+ public Boolean IsInitialized
+ {
+ get { return storage != UNKNOWN; }
+ }
+
+ public UInt32 Value
+ {
+ get { return storage; }
+ }
+
+ public Boolean IsPointer
+ {
+ get { return pointsTo != null; }
+ }
+
+ public static AbstractValue[] GetNewBuffer(UInt32 size)
+ {
+ if (size > MAX_BUFFER_SIZE)
+ {
throw new ArgumentOutOfRangeException(
- "size", "Size specified larger than maximum allowed: " + MAX_BUFFER_SIZE);
- }
-
- var buffer = new AbstractValue[size];
- for (UInt32 i = 0; i < size; i++)
- {
- buffer[i] = new AbstractValue();
- }
-
- return buffer;
- }
-
- public AbstractValue TruncateValueToByte()
- {
- UInt32 byteValue = Value & 0xff;
- var truncatedValue = new AbstractValue(byteValue);
- truncatedValue.IsTainted = IsTainted;
-
- return truncatedValue;
- }
-
- public AbstractValue AddTaint()
- {
- if (PointsTo != null)
- {
- throw new InvalidOperationException("Cannot AddTaint to a pointer");
- }
-
- var taintedValue = new AbstractValue(this);
- taintedValue.IsTainted = true;
- return taintedValue;
- }
-
- public AbstractValue AddTaintIf(Boolean condition)
- {
- if (condition)
- {
- return AddTaint();
- }
-
- return this;
- }
-
- public override String ToString()
- {
- String result = String.Empty;
-
- if (tainted)
- result += "t";
-
- UInt32 valueToPrint = Value;
-
- if (pointsTo != null)
- {
- AbstractValue pointer = pointsTo[0];
-
- var newResult = new StringBuilder(result);
-
- const Byte maximumPointerDepth = 100;
- Int32 count = maximumPointerDepth;
- while ((pointer != null) && (count-- > 0))
- {
- newResult.Append("*");
-
- if (pointer.PointsTo != null)
- {
- pointer = pointer.PointsTo[0];
- }
- else
- {
- valueToPrint = pointer.Value;
- pointer = null;
- }
- }
- result = newResult.ToString();
- }
-
- if (valueToPrint != UNKNOWN)
- {
- result += String.Format("0x{0:x8}", valueToPrint);
- }
- else
- {
- result += "?";
- }
-
- return result;
- }
- }
+ "size", "Size specified larger than maximum allowed: " + MAX_BUFFER_SIZE);
+ }
+
+ var buffer = new AbstractValue[size];
+ for (UInt32 i = 0; i < size; i++)
+ {
+ buffer[i] = new AbstractValue();
+ }
+
+ return buffer;
+ }
+
+ public override Boolean Equals(object obj)
+ {
+ var other = obj as AbstractValue;
+
+ if (null == other)
+ {
+ return false;
+ }
+
+ return Value == other.Value &&
+ IsOOB == other.IsOOB &&
+ IsTainted == other.IsTainted &&
+ PointsTo == other.PointsTo;
+ }
+
+ public override Int32 GetHashCode()
+ {
+ Int32 hashCode = Value.GetHashCode() ^ IsOOB.GetHashCode() ^
+ IsTainted.GetHashCode();
+
+ if (PointsTo != null)
+ {
+ hashCode ^= PointsTo.GetHashCode();
+ }
+
+ return hashCode;
+ }
+
+ public AbstractValue TruncateValueToByte()
+ {
+ UInt32 byteValue = Value & 0xff;
+ var truncatedValue = new AbstractValue(byteValue);
+ truncatedValue.IsTainted = IsTainted;
+
+ return truncatedValue;
+ }
+
+ public AbstractValue AddTaint()
+ {
+ if (PointsTo != null)
+ {
+ throw new InvalidOperationException("Cannot AddTaint to a pointer");
+ }
+
+ var taintedValue = new AbstractValue(this);
+ taintedValue.IsTainted = true;
+ return taintedValue;
+ }
+
+ public AbstractValue AddTaintIf(Boolean condition)
+ {
+ if (condition)
+ {
+ return AddTaint();
+ }
+
+ return this;
+ }
+
+ public override String ToString()
+ {
+ String result = String.Empty;
+
+ if (tainted)
+ {
+ result += "t";
+ }
+
+ UInt32 valueToPrint = Value;
+
+ if (pointsTo != null)
+ {
+ AbstractValue pointer = pointsTo[0];
+
+ var newResult = new StringBuilder(result);
+
+ const Byte MAXIMUM_DISPLAYED_POINTER_DEPTH = 100;
+ Int32 count = MAXIMUM_DISPLAYED_POINTER_DEPTH;
+ while ((pointer != null) && (count-- > 0))
+ {
+ newResult.Append("*");
+
+ if (pointer.PointsTo != null)
+ {
+ pointer = pointer.PointsTo[0];
+ }
+ else
+ {
+ valueToPrint = pointer.Value;
+ pointer = null;
+ }
+ }
+
+ result = newResult.ToString();
+ }
+
+ if (valueToPrint != UNKNOWN)
+ {
+ result += String.Format("0x{0:x8}", valueToPrint);
+ }
+ else
+ {
+ result += "?";
+ }
+
+ return result;
+ }
+ }
}
\ No newline at end of file
Modified: AbstractValueTest.cs
===================================================================
--- AbstractValueTest.cs 2009-01-29 05:41:37 UTC (rev 164)
+++ AbstractValueTest.cs 2009-01-29 21:45:15 UTC (rev 165)
@@ -1,202 +1,202 @@
-// This file is part of bugreport.
-// Copyright (c) 2006-2009 The bugreport Developers.
-// See AUTHORS.txt for details.
-// Licensed under the GNU General Public License, Version 3 (GPLv3).
-// See LICENSE.txt for details.
-
+// This file is part of bugreport.
+// Copyright (c) 2006-2009 The bugreport Developers.
+// See AUTHORS.txt for details.
+// Licensed under the GNU General Public License, Version 3 (GPLv3).
+// See LICENSE.txt for details.
+
using System;
using NUnit.Framework;
-namespace bugreport
-{
- [TestFixture]
- public class AbstractValueTest
- {
- private AbstractValue pointer;
- private AbstractBuffer buffer;
-
- [Test]
- public void AddTaint()
- {
- var clean = new AbstractValue(0x31337);
- Assert.IsFalse(clean.IsTainted);
- AbstractValue tainted = clean.AddTaint();
- Assert.IsTrue(tainted.IsTainted);
- Assert.AreNotSame(clean, tainted);
+namespace bugreport
+{
+ [TestFixture]
+ public class AbstractValueTest
+ {
+ private AbstractValue pointer;
+ private AbstractBuffer buffer;
+
+ [Test]
+ public void AddTaint()
+ {
+ var clean = new AbstractValue(0x31337);
+ Assert.IsFalse(clean.IsTainted);
+ AbstractValue tainted = clean.AddTaint();
+ Assert.IsTrue(tainted.IsTainted);
+ Assert.AreNotSame(clean, tainted);
}
- [Test]
- public void AddTaintIf()
- {
- var clean = new AbstractValue(0x31337);
- Assert.IsFalse(clean.IsTainted);
- AbstractValue notTainted = clean.AddTaintIf(0 == 1);
- Assert.IsFalse(notTainted.IsTainted);
- Assert.AreSame(clean, notTainted);
-
- AbstractValue tainted = clean.AddTaintIf(1 == 1);
- Assert.IsTrue(tainted.IsTainted);
- Assert.AreNotSame(clean, tainted);
- }
-
- [Test]
- [ExpectedException(typeof (InvalidOperationException))]
- public void AddTaintOnPointer()
- {
- var buffer = new AbstractBuffer(AbstractValue.GetNewBuffer(1));
- var clean = new AbstractValue(buffer);
- clean.AddTaint();
+ [Test]
+ public void AddTaintIf()
+ {
+ var clean = new AbstractValue(0x31337);
+ Assert.IsFalse(clean.IsTainted);
+ AbstractValue notTainted = clean.AddTaintIf(0 == 1);
+ Assert.IsFalse(notTainted.IsTainted);
+ Assert.AreSame(clean, notTainted);
+
+ AbstractValue tainted = clean.AddTaintIf(1 == 1);
+ Assert.IsTrue(tainted.IsTainted);
+ Assert.AreNotSame(clean, tainted);
}
- [Test]
- public void AssignmentAtByteZero()
- {
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
- pointer = new AbstractValue(buffer);
- pointer.PointsTo[0] = new AbstractValue(0x31337);
- Assert.AreEqual(0x31337, pointer.PointsTo[0].Value);
- Assert.AreEqual("*0x00031337", pointer.ToString());
- }
-
- [Test]
- public void AssignmentAtEnd()
- {
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
- pointer = new AbstractValue(buffer);
- pointer.PointsTo[15] = new AbstractValue(0x31337);
- Assert.AreEqual(0x31337, pointer.PointsTo[15].Value);
+ [Test]
+ [ExpectedException(typeof(InvalidOperationException))]
+ public void AddTaintOnPointer()
+ {
+ var buffer = new AbstractBuffer(AbstractValue.GetNewBuffer(1));
+ var clean = new AbstractValue(buffer);
+ clean.AddTaint();
}
- [Test]
- public void CheckOOBAfterCopy()
- {
- var src = new AbstractValue(0x31337);
- src.IsOOB = false;
- var dest = new AbstractValue(0x1);
- dest.IsOOB = true;
- dest = new AbstractValue(src);
-
- Assert.IsFalse(dest.IsOOB);
- }
-
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void EmptyBuffer()
- {
- pointer = new AbstractValue(new AbstractBuffer(new AbstractValue[] {}));
+ [Test]
+ public void AssignmentAtByteZero()
+ {
+ AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
+ pointer = new AbstractValue(buffer);
+ pointer.PointsTo[0] = new AbstractValue(0x31337);
+ Assert.AreEqual(0x31337, pointer.PointsTo[0].Value);
+ Assert.AreEqual("*0x00031337", pointer.ToString());
}
- [Test]
- public void Equals()
- {
- Assert.IsFalse(new AbstractValue().Equals(null));
+ [Test]
+ public void AssignmentAtEnd()
+ {
+ AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
+ pointer = new AbstractValue(buffer);
+ pointer.PointsTo[15] = new AbstractValue(0x31337);
+ Assert.AreEqual(0x31337, pointer.PointsTo[15].Value);
}
- [Test]
- public void Initialized()
- {
- var uninit = new AbstractValue(0xabcdef);
- Assert.IsTrue(uninit.IsInitialized);
- Assert.AreEqual(0xabcdef, uninit.Value);
- }
-
- [Test]
- public void NoPointer()
- {
- AbstractValue value = new AbstractValue(2).AddTaint();
-
- Assert.IsNull(value.PointsTo);
- StringAssert.Contains("0x00000002", value.ToString());
+ [Test]
+ public void CheckOOBAfterCopy()
+ {
+ var src = new AbstractValue(0x31337);
+ src.IsOOB = false;
+ var dest = new AbstractValue(0x1);
+ dest.IsOOB = true;
+ dest = new AbstractValue(src);
+
+ Assert.IsFalse(dest.IsOOB);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentException))]
+ public void EmptyBuffer()
+ {
+ pointer = new AbstractValue(new AbstractBuffer(new AbstractValue[] {}));
+ }
+
+ [Test]
+ public void Equals()
+ {
+ Assert.IsFalse(new AbstractValue().Equals(null));
+ }
+
+ [Test]
+ public void Initialized()
+ {
+ var uninit = new AbstractValue(0xabcdef);
+ Assert.IsTrue(uninit.IsInitialized);
+ Assert.AreEqual(0xabcdef, uninit.Value);
+ }
+
+ [Test]
+ public void NoPointer()
+ {
+ AbstractValue value = new AbstractValue(2).AddTaint();
+
+ Assert.IsNull(value.PointsTo);
+ StringAssert.Contains("0x00000002", value.ToString());
StringAssert.Contains("t", value.ToString());
}
- [Test]
- public void NotInitialized()
- {
- var uninitializedValue = new AbstractValue();
- Assert.IsFalse(uninitializedValue.IsInitialized);
- Assert.AreEqual(AbstractValue.UNKNOWN, uninitializedValue.Value);
- Assert.AreEqual("?", uninitializedValue.ToString());
+ [Test]
+ public void NotInitialized()
+ {
+ var uninitializedValue = new AbstractValue();
+ Assert.IsFalse(uninitializedValue.IsInitialized);
+ Assert.AreEqual(AbstractValue.UNKNOWN, uninitializedValue.Value);
+ Assert.AreEqual("?", uninitializedValue.ToString());
}
- [Test]
- [ExpectedException(typeof (ArgumentNullException))]
- public void NullCopyCtor()
- {
- pointer = new AbstractValue((AbstractValue) null);
- }
-
- [Test]
- public void Pointer()
- {
- buffer = new AbstractBuffer(new[] {new AbstractValue(2)});
- pointer = new AbstractValue(buffer);
- Assert.AreEqual(2, pointer.PointsTo[0].Value);
- StringAssert.StartsWith("*0x00000002", pointer.ToString());
+ [Test]
+ [ExpectedException(typeof(ArgumentNullException))]
+ public void NullCopyCtor()
+ {
+ pointer = new AbstractValue((AbstractValue) null);
}
- [Test]
- public void PointerHashcodes()
- {
- pointer = new AbstractValue(new[] {new AbstractValue(1)});
- var pointer2 = new AbstractValue(new[] {new AbstractValue(2)});
-
- Assert.AreNotEqual(pointer.GetHashCode(), pointer2.GetHashCode());
- }
-
- [Test]
- public void PointerPointer()
- {
- buffer = new AbstractBuffer(new[] {new AbstractValue(2)});
- pointer = new AbstractValue(buffer);
- var pointerPointer = new AbstractValue(new[] {pointer});
- Assert.AreEqual(2, pointerPointer.PointsTo[0].PointsTo[0].Value);
- StringAssert.StartsWith("**0x00000002", pointerPointer.ToString());
- }
-
- [Test]
- public void PointerPointerPointer()
- {
- buffer = new AbstractBuffer(new[] {new AbstractValue(2)});
- pointer = new AbstractValue(buffer);
- var pointerPointer = new AbstractValue(new[] {pointer});
- var pointerPointerPointer = new AbstractValue(new[] {pointerPointer});
- Assert.AreEqual(2, pointerPointerPointer.PointsTo[0].PointsTo[0].PointsTo[0].Value);
-
- StringAssert.StartsWith("***0x00000002", pointerPointerPointer.ToString());
- }
-
- [Test]
- public void PreserveIsOOBAfterCopy()
- {
- var src = new AbstractValue(0x31337);
- var dest = new AbstractValue(0x1);
- src.IsOOB = true;
- dest = new AbstractValue(src);
-
- Assert.IsTrue(dest.IsOOB);
- }
-
- [Test]
- [ExpectedException(typeof (ArgumentOutOfRangeException))]
- public void RequestedBufferTooLarge()
- {
- AbstractValue.GetNewBuffer(AbstractValue.MAX_BUFFER_SIZE + 1);
+ [Test]
+ public void Pointer()
+ {
+ buffer = new AbstractBuffer(new[] {new AbstractValue(2)});
+ pointer = new AbstractValue(buffer);
+ Assert.AreEqual(2, pointer.PointsTo[0].Value);
+ StringAssert.StartsWith("*0x00000002", pointer.ToString());
}
- [Test]
- public void TruncateValue()
- {
- var dwordValue = new AbstractValue(0xdeadbeef);
- AbstractValue byteValue = dwordValue.TruncateValueToByte();
- Assert.AreEqual(0xef, byteValue.Value);
+ [Test]
+ public void PointerHashcodes()
+ {
+ pointer = new AbstractValue(new[] {new AbstractValue(1)});
+ var pointer2 = new AbstractValue(new[] {new AbstractValue(2)});
+
+ Assert.AreNotEqual(pointer.GetHashCode(), pointer2.GetHashCode());
}
- [Test]
- [ExpectedException(typeof (ArgumentException))]
- public void ZeroSizeBuffer()
- {
- pointer = new AbstractValue(new AbstractValue[] {});
- }
- }
+ [Test]
+ public void PointerPointer()
+ {
+ buffer = new AbstractBuffer(new[] {new AbstractValue(2)});
+ pointer = new AbstractValue(buffer);
+ var pointerPointer = new AbstractValue(new[] {pointer});
+ Assert.AreEqual(2, pointerPointer.PointsTo[0].PointsTo[0].Value);
+ StringAssert.StartsWith("**0x00000002", pointerPointer.ToString());
+ }
+
+ [Test]
+ public void PointerPointerPointer()
+ {
+ buffer = new AbstractBuffer(new[] {new AbstractValue(2)});
+ pointer = new AbstractValue(buffer);
+ var pointerPointer = new AbstractValue(new[] {pointer});
+ var pointerPointerPointer = new AbstractValue(new[] {pointerPointer});
+ Assert.AreEqual(2, pointerPointerPointer.PointsTo[0].PointsTo[0].PointsTo[0].Value);
+
+ StringAssert.StartsWith("***0x00000002", pointerPointerPointer.ToString());
+ }
+
+ [Test]
+ public void PreserveIsOOBAfterCopy()
+ {
+ var src = new AbstractValue(0x31337);
+ var dest = new AbstractValue(0x1);
+ src.IsOOB = true;
+ dest = new AbstractValue(src);
+
+ Assert.IsTrue(dest.IsOOB);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentOutOfRangeException))]
+ public void RequestedBufferTooLarge()
+ {
+ AbstractValue.GetNewBuffer(AbstractValue.MAX_BUFFER_SIZE + 1);
+ }
+
+ [Test]
+ public void TruncateValue()
+ {
+ var dwordValue = new AbstractValue(0xdeadbeef);
+ AbstractValue byteValue = dwordValue.TruncateValueToByte();
+ Assert.AreEqual(0xef, byteValue.Value);
+ }
+
+ [Test]
+ [ExpectedException(typeof(ArgumentException))]
+ public void ZeroSizeBuffer()
+ {
+ pointer = new AbstractValue(new AbstractValue[] {});
+ }
+ }
}
\ No newline at end of file
Modified: AnalysisEngine.csproj
===================================================================
--- AnalysisEngine.csproj 2009-01-29 05:41:37 UTC (rev 164)
+++ AnalysisEngine.csproj 2009-01-29 21:45:15 UTC (rev 165)
@@ -60,8 +60,6 @@
<Compile Include="AbstractValueTest.cs" />
<Compile Include="Analyzer.cs" />
<Compile Include="AnalyzerTest.cs" />
- <Compile Include="ArmEmulator.cs" />
- <Compile Include="ArmEmulatorTest.cs" />
<Compile Include="BitMathTest.cs" />
<Compile Include="Contract.cs" />
<Compile Include="CoverageExcludeAttribute.cs" />
@@ -70,6 +68,7 @@
<Compile Include="ElfFileParserTest.cs" />
<Compile Include="GLibcStartMainContract.cs" />
<Compile Include="GLibcStartMainContractTest.cs" />
+ <Compile Include="InvalidOpcodeException.cs" />
<Compile Include="MachineStateTest.cs" />
<Compile Include="MallocContract.cs" />
<Compile Include="ModRMTest.cs" />
Modified: Analyzer.cs
===================================================================
--- Analyzer.cs 2009-01-29 05:41:37 UTC (rev 164)
+++ Analyzer.cs 2009-01-29 21:45:15 UTC (rev 165)
@@ -1,174 +1,176 @@
-// This file is part of bugreport.
-// Copyright (c) 2006-2009 The bugreport Developers.
-// See AUTHORS.txt for details.
-// Licensed under the GNU General Public License, Version 3 (GPLv3).
-// See LICENSE.txt for details.
-
+// This file is part of bugreport.
+// Copyright (c) 2006-2009 The bugreport Developers.
+// See AUTHORS.txt for details.
+// Licensed under the GNU General Public License, Version 3 (GPLv3).
+// See LICENSE.txt for details.
+
using System;
using System.Collections.ObjectModel;
-namespace bugreport
-{
- public class EmulationEventArgs : EventArgs
- {
+namespace bugreport
+{
+ public class EmulationEventArgs : EventArgs
+ {
private readonly ReadOnlyCollection<Byte> code;
- private readonly MachineState state;
-
- public EmulationEventArgs(MachineState state, ReadOnlyCollection<Byte> code)
- {
- this.state = state;
- this.code = code;
- }
-
- public MachineState MachineState
- {
- get { return state; }
- }
-
- public ReadOnlyCollection<Byte> Code
- {
- get { return code; }
- }
- }
-
- public class ReportEventArgs : EventArgs
- {
- private readonly ReportItem reportItem;
-
- public ReportEventArgs(ReportItem reportItem)
- {
- this.reportItem = reportItem;
- }
-
- public ReportItem ReportItem
- {
- get { return reportItem; }
- }
- }
-
- public class ReportCollection : Collection<ReportItem>
- {
- public EventHandler<ReportEventArgs> OnReport;
-
- protected override void InsertItem(int index, ReportItem item)
- {
- base.InsertItem(index, item);
-
- if (null != OnReport)
- {
- OnReport(this, new ReportEventArgs(item));
- }
- }
- }
-
- public class Analyzer
- {
+ private readonly MachineState state;
+
+ public EmulationEventArgs(MachineState state, ReadOnlyCollection<Byte> code)
+ {
+ this.state = state;
+ this.code = code;
+ }
+
+ public MachineState MachineState
+ {
+ get { return state; }
+ }
+
+ public ReadOnlyCollection<Byte> Code
+ {
+ get { return code; }
+ }
+ }
+
+ public class ReportEventArgs : EventArgs
+ {
+ private readonly ReportItem reportItem;
+
+ public ReportEventArgs(ReportItem reportItem)
+ {
+ this.reportItem = reportItem;
+ }
+
+ public ReportItem ReportItem
+ {
+ get { return reportItem; }
+ }
+ }
+
+ public class ReportCollection : Collection<ReportItem>
+ {
+ public EventHandler<ReportEventArgs> OnReport;
+
+ protected override void InsertItem(int index, ReportItem item)
+ {
+ base.InsertItem(index, item);
+
+ if (null != OnReport)
+ {
+ OnReport(this, new ReportEventArgs(item));
+ }
+ }
+ }
+
+ public class Analyzer
+ {
+ public EventHandler<EmulationEventArgs> OnEmulationComplete;
private readonly Opcode opcode = new X86Opcode();
private readonly IParsable parser;
- public EventHandler<EmulationEventArgs> OnEmulationComplete;
-
- protected ReportCollection reportItems;
-
- public Analyzer(IParsable parser)
- {
- if (null == parser)
- {
- throw new ArgumentNullException("parser");
- }
-
- this.parser = parser;
-
- reportItems = new ReportCollection();
- }
-
- public ReadOnlyCollection<ReportItem> ActualReportItems
- {
- get { return new ReadOnlyCollection<ReportItem>(reportItems); }
- }
-
- public ReadOnlyCollection<ReportItem> ExpectedReportItems
- {
- get { return parser.ExpectedReportItems; }
- }
-
- public EventHandler<ReportEventArgs> OnReport
- {
- get { return reportItems.OnReport; }
- set { reportItems.OnReport = value; }
- }
-
-
- private static RegisterCollection getRegistersForLinuxStart()
- {
- var linuxMainDefaultValues = new RegisterCollection();
-
- AbstractValue arg0 = new AbstractValue(1).AddTaint();
-
- var argvBuffer = new[] {arg0};
- var argvPointer = new AbstractValue(argvBuffer);
- var argvPointerBuffer = new[] {argvPointer};
- var argvPointerPointer = new AbstractValue(argvPointerBuffer);
- AbstractValue[] stackBuffer = AbstractValue.GetNewBuffer(0x200);
-
- var buffer = new AbstractBuffer(stackBuffer);
- AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(0x100));
-
- // linux ABI dictates
- modifiedBuffer[5] = argvPointerPointer;
-
- // gcc generates code that accesses this at some optimization levels
- modifiedBuffer[0xfc] = new AbstractValue(1);
-
- var stackPointer = new AbstractValue(modifiedBuffer);
- linuxMainDefaultValues[RegisterName.ESP] = stackPointer;
-
- return linuxMainDefaultValues;
- }
-
-
- protected virtual MachineState runCode(MachineState _machineState, Byte[] code)
- {
- return X86Emulator.Run(reportItems, _machineState, code);
- }
-
- public void Run()
- {
- var machineState = new MachineState(getRegistersForLinuxStart());
- machineState.InstructionPointer = parser.EntryPointAddress;
- Byte[] instructions = parser.GetBytes();
- UInt32 index = machineState.InstructionPointer - parser.BaseAddress;
-
- while (index < instructions.Length)
- {
- MachineState savedState = machineState;
- Byte[] instruction = extractInstruction(instructions, index);
-
- machineState = runCode(machineState, instruction);
- if (null != OnEmulationComplete)
- {
+ private ReportCollection reportItems;
+
+ public Analyzer(IParsable parser)
+ {
+ if (null == parser)
+ {
+ throw new ArgumentNullException("parser");
+ }
+
+ this.parser = parser;
+
+ reportItems = new ReportCollection();
+ }
+
+ public ReadOnlyCollection<ReportItem> ActualReportItems
+ {
+ get { return new ReadOnlyCollection<ReportItem>(reportItems); }
+ }
+
+ public ReadOnlyCollection<ReportItem> ExpectedReportItems
+ {
+ get { return parser.ExpectedReportItems; }
+ }
+
+ public EventHandler<ReportEventArgs> OnReport
+ {
+ get { return reportItems.OnReport; }
+ set { reportItems.OnReport = value; }
+ }
+
+ protected ReportCollection ReportItems
+ {
+ get { return reportItems; }
+ }
+
+ public void Run()
+ {
+ var machineState = new MachineState(getRegistersForLinuxStart());
+ machineState.InstructionPointer = parser.EntryPointAddress;
+ Byte[] instructions = parser.GetBytes();
+ UInt32 index = machineState.InstructionPointer - parser.BaseAddress;
+
+ while (index < instructions.Length)
+ {
+ MachineState savedState = machineState;
+ Byte[] instruction = extractInstruction(instructions, index);
+
+ machineState = runCode(machineState, instruction);
+ if (null != OnEmulationComplete)
+ {
OnEmulationComplete(
- this, new EmulationEventArgs(savedState, new ReadOnlyCollection<Byte>(instruction)));
- }
-
- index = machineState.InstructionPointer - parser.BaseAddress;
-
- if (opcode.TerminatesFunction(instruction))
- {
- break;
- }
- }
- }
-
- private Byte[] extractInstruction(Byte[] instructions, UInt32 index)
- {
- Byte instructionLength = opcode.GetInstructionLength(instructions, index);
- var instruction = new Byte[instructionLength];
- for (UInt32 count = index; count < index + instructionLength; count++)
- {
- instruction[count - index] = instructions[count];
- }
-
- return instruction;
- }
- }
+ this, new EmulationEventArgs(savedState, new ReadOnlyCollection<Byte>(instruction)));
+ }
+
+ index = machineState.InstructionPointer - parser.BaseAddress;
+
+ if (opcode.TerminatesFunction(instruction))
+ {
+ break;
+ }
+ }
+ }
+
+ protected virtual MachineState runCode(MachineState _machineState, Byte[] code)
+ {
+ return X86Emulator.Run(reportItems, _machineState, code);
+ }
+
+ private static RegisterCollection getRegistersForLinuxStart()
+ {
+ var linuxMainDefaultValues = new RegisterCollection();
+
+ AbstractValue arg0 = new AbstractValue(1).AddTaint();
+
+ var argvBuffer = new[] {arg0};
+ var argvPointer = new AbstractValue(argvBuffer);
+ var argvPointerBuffer = new[] {argvPointer};
+ var argvPointerPointer = new AbstractValue(argvPointerBuffer);
+ AbstractValue[] stackBuffer = AbstractValue.GetNewBuffer(0x200);
+
+ var buffer = new AbstractBuffer(stackBuffer);
+ AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(0x100));
+
+ // linux ABI dictates
+ modifiedBuffer[5] = argvPointerPointer;
+
+ // gcc generates code that accesses this at some optimization levels
+ modifiedBuffer[0xfc] = new AbstractValue(1);
+
+ var stackPointer = new AbstractValue(modifiedBuffer);
+ linuxMainDefaultValues[RegisterName.ESP] = stackPointer;
+
+ return linuxMainDefaultValues;
+ }
+
+ private Byte[] extractInstruction(Byte[] instructions, UInt32 index)
+ {
+ Byte instructionLength = opcode.GetInstructionLength(instructions, index);
+ var instruction = new Byte[instructionLengt...
[truncated message content] |