|
From: <mat...@us...> - 2009-02-12 03:52:10
|
Revision: 167
http://bugreport.svn.sourceforge.net/bugreport/?rev=167&view=rev
Author: matt_hargett
Date: 2009-02-12 03:51:26 +0000 (Thu, 12 Feb 2009)
Log Message:
-----------
Massive cleanup toward C# 3.0 features with the help of ReSharper nightly builds. Added X86EmulatorTest.BugComplicatedMuthafuqqa() that should demonstrate the current issue with interfunction-immediate-parameter test. Still not sure what exactly the problem is, though. Need to step through the new unit test and look for suspicious activity.
Modified Paths:
--------------
AbstractBuffer.cs
AbstractBufferTest.cs
AbstractValue.cs
AbstractValueTest.cs
Analyzer.cs
AnalyzerTest.cs
AssemblyInfo.cs
BitMath.cs
BitMathTest.cs
Contract.cs
DebuggerView.cs
DumpFileParser.cs
DumpFileParserTest.cs
ElfFileParser.cs
ElfFileParserTest.cs
GLibcStartMainContract.cs
GLibcStartMainContractTest.cs
InvalidOpcodeException.cs
MachineState.cs
MachineStateTest.cs
Main.cs
MainTest.cs
MallocContract.cs
ModRM.cs
ModRMTest.cs
Opcode.cs
OpcodeFormatter.cs
Options.cs
OptionsTest.cs
RegisterCollection.cs
ReportItem.cs
SIB.cs
SIBTests.cs
X86Emulator.cs
X86EmulatorTest.cs
X86Opcode.cs
X86OpcodeTest.cs
Modified: AbstractBuffer.cs
===================================================================
--- AbstractBuffer.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ AbstractBuffer.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -8,7 +8,7 @@
namespace bugreport
{
- public class AbstractBuffer
+ public sealed class AbstractBuffer
{
private readonly Int32 allocatedLength;
private UInt32 baseIndex;
@@ -28,7 +28,7 @@
Array.Copy(_copyMe.storage, storage, _copyMe.storage.Length);
}
- public UInt32 BaseIndex
+ private UInt32 BaseIndex
{
get { return baseIndex; }
}
@@ -73,7 +73,7 @@
public AbstractBuffer DoOperation(OperatorEffect _operatorEffect, AbstractValue _rhs)
{
- AbstractBuffer lhs = this;
+ var lhs = this;
// TODO: should have a guard for if _rhs isn't a pointer
switch (_operatorEffect)
@@ -102,10 +102,10 @@
throw new ArgumentOutOfRangeException(
String.Format(
"Attempting to set a negative baseindex, baseindex: {0:x4}, _subValue {1:x4}",
- result.baseIndex,
+ result.baseIndex,
_rhs.Value
- )
- );
+ )
+ );
}
result.baseIndex -= _rhs.Value;
@@ -147,8 +147,7 @@
for (; i < _newLength; i++)
{
- _copyTo[i] = new AbstractValue(AbstractValue.UNKNOWN);
- _copyTo[i].IsOOB = true;
+ _copyTo[i] = new AbstractValue(AbstractValue.UNKNOWN) {IsOOB = true};
}
storage = _copyTo;
Modified: AbstractBufferTest.cs
===================================================================
--- AbstractBufferTest.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ AbstractBufferTest.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -15,31 +15,31 @@
[Test]
public void Copy()
{
- AbstractValue[] values = AbstractValue.GetNewBuffer(4);
+ var 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++)
+ for (var index = 0; index < newBuffer.Length; index++)
{
Assert.AreSame(newBuffer[index], buffer[index]);
}
}
[Test]
- [ExpectedException(typeof(ArgumentOutOfRangeException))]
+ [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));
+ var 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 buffer = AbstractValue.GetNewBuffer(16);
var pointer = new AbstractBuffer(buffer);
var value = new AbstractValue(0x41);
value = value.AddTaint();
@@ -72,7 +72,7 @@
var two = new AbstractValue(0x2);
var three = new AbstractValue(0x3);
var four = new AbstractValue(0x4);
- AbstractValue[] values = AbstractValue.GetNewBuffer(4);
+ var values = AbstractValue.GetNewBuffer(4);
values[0] = one;
values[1] = two;
@@ -81,7 +81,7 @@
var buffer = new AbstractBuffer(values);
Assert.AreEqual(one, buffer[0]);
- AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(2));
+ var modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(2));
Assert.AreEqual(three, modifiedBuffer[0]);
}
@@ -92,7 +92,7 @@
var two = new AbstractValue(0x2);
var three = new AbstractValue(0x3);
var four = new AbstractValue(0x4);
- AbstractValue[] values = AbstractValue.GetNewBuffer(4);
+ var values = AbstractValue.GetNewBuffer(4);
values[0] = one;
values[1] = two;
@@ -101,28 +101,28 @@
var buffer = new AbstractBuffer(values);
Assert.AreEqual(one, buffer[0]);
- AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(3));
+ var modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(3));
Assert.AreEqual(four, modifiedBuffer[0]);
- AbstractBuffer andedBuffer = modifiedBuffer.DoOperation(OperatorEffect.And, new AbstractValue(0xfffffff0));
+ var andedBuffer = modifiedBuffer.DoOperation(OperatorEffect.And, new AbstractValue(0xfffffff0));
Assert.AreEqual(one, andedBuffer[0]);
}
[Test]
public void PointerAssignment()
{
- AbstractValue[] values = AbstractValue.GetNewBuffer(4);
+ var values = AbstractValue.GetNewBuffer(4);
var buffer = new AbstractBuffer(values);
- AbstractBuffer assignedBuffer = buffer.DoOperation(OperatorEffect.Assignment, null);
+ var assignedBuffer = buffer.DoOperation(OperatorEffect.Assignment, null);
Assert.AreNotSame(buffer, assignedBuffer);
}
[Test]
public void PointerOverflowByOne()
{
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
+ var buffer = AbstractValue.GetNewBuffer(16);
var pointer = new AbstractBuffer(buffer);
- AbstractValue value = pointer[16];
+ var value = pointer[16];
Assert.IsTrue(value.IsOOB);
Assert.IsFalse(value.IsInitialized);
Assert.AreEqual(AbstractValue.UNKNOWN, value.Value);
@@ -133,7 +133,7 @@
{
var test1 = new AbstractValue(0x41);
var test2 = new AbstractValue(0x42);
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(2);
+ var buffer = AbstractValue.GetNewBuffer(2);
buffer[0] = test1;
buffer[1] = test2;
@@ -156,7 +156,7 @@
[Test]
public void PointerOverflowTwiceStillRetainsOriginalValues()
{
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
+ var buffer = AbstractValue.GetNewBuffer(16);
var pointer = new AbstractBuffer(buffer);
// Access beyond buffer bounds forcing buffer to expand
@@ -183,7 +183,7 @@
var two = new AbstractValue(0x2);
var three = new AbstractValue(0x3);
var four = new AbstractValue(0x4);
- AbstractValue[] values = AbstractValue.GetNewBuffer(4);
+ var values = AbstractValue.GetNewBuffer(4);
values[0] = one;
values[1] = two;
@@ -192,22 +192,22 @@
var buffer = new AbstractBuffer(values);
Assert.AreEqual(one, buffer[0]);
- AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(2));
+ var modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(2));
Assert.AreEqual(three, modifiedBuffer[0]);
- AbstractBuffer subbedBuffer = modifiedBuffer.DoOperation(OperatorEffect.Sub, new AbstractValue(2));
+ var subbedBuffer = modifiedBuffer.DoOperation(OperatorEffect.Sub, new AbstractValue(2));
Assert.AreEqual(one, subbedBuffer[0]);
}
[Test]
- [ExpectedException(typeof(ArgumentOutOfRangeException))]
+ [ExpectedException(typeof (ArgumentOutOfRangeException))]
public void PointerSubUnderflow()
{
new AbstractBuffer(new AbstractValue[] {}).DoOperation(OperatorEffect.Sub, new AbstractValue(1));
}
[Test]
- [ExpectedException(typeof(ArgumentException))]
+ [ExpectedException(typeof (ArgumentException))]
public void PointerUnknownOperation()
{
new AbstractBuffer(new AbstractValue[] {}).DoOperation(OperatorEffect.Unknown, null);
Modified: AbstractValue.cs
===================================================================
--- AbstractValue.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ AbstractValue.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -9,7 +9,7 @@
namespace bugreport
{
- public class AbstractValue
+ public sealed class AbstractValue
{
public const UInt32 MAX_BUFFER_SIZE = 25600000;
public const UInt32 UNKNOWN = 0xb4dc0d3d;
@@ -94,7 +94,7 @@
{
get { return pointsTo != null; }
}
-
+
public static AbstractValue[] GetNewBuffer(UInt32 size)
{
if (size > MAX_BUFFER_SIZE)
@@ -129,8 +129,8 @@
public override Int32 GetHashCode()
{
- Int32 hashCode = Value.GetHashCode() ^ IsOOB.GetHashCode() ^
- IsTainted.GetHashCode();
+ var hashCode = Value.GetHashCode() ^ IsOOB.GetHashCode() ^
+ IsTainted.GetHashCode();
if (PointsTo != null)
{
@@ -142,7 +142,7 @@
public AbstractValue TruncateValueToByte()
{
- UInt32 byteValue = Value & 0xff;
+ var byteValue = Value & 0xff;
var truncatedValue = new AbstractValue(byteValue);
truncatedValue.IsTainted = IsTainted;
@@ -156,8 +156,7 @@
throw new InvalidOperationException("Cannot AddTaint to a pointer");
}
- var taintedValue = new AbstractValue(this);
- taintedValue.IsTainted = true;
+ var taintedValue = new AbstractValue(this) {IsTainted = true};
return taintedValue;
}
@@ -173,18 +172,18 @@
public override String ToString()
{
- String result = String.Empty;
+ var result = String.Empty;
if (tainted)
{
result += "t";
}
- UInt32 valueToPrint = Value;
+ var valueToPrint = Value;
if (pointsTo != null)
{
- AbstractValue pointer = pointsTo[0];
+ var pointer = pointsTo[0];
var newResult = new StringBuilder(result);
@@ -204,7 +203,7 @@
pointer = null;
}
}
-
+
result = newResult.ToString();
}
Modified: AbstractValueTest.cs
===================================================================
--- AbstractValueTest.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ AbstractValueTest.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -20,7 +20,7 @@
{
var clean = new AbstractValue(0x31337);
Assert.IsFalse(clean.IsTainted);
- AbstractValue tainted = clean.AddTaint();
+ var tainted = clean.AddTaint();
Assert.IsTrue(tainted.IsTainted);
Assert.AreNotSame(clean, tainted);
}
@@ -30,20 +30,20 @@
{
var clean = new AbstractValue(0x31337);
Assert.IsFalse(clean.IsTainted);
- AbstractValue notTainted = clean.AddTaintIf(0 == 1);
+ var notTainted = clean.AddTaintIf(0 == 1);
Assert.IsFalse(notTainted.IsTainted);
Assert.AreSame(clean, notTainted);
- AbstractValue tainted = clean.AddTaintIf(1 == 1);
+ var tainted = clean.AddTaintIf(1 == 1);
Assert.IsTrue(tainted.IsTainted);
Assert.AreNotSame(clean, tainted);
}
[Test]
- [ExpectedException(typeof(InvalidOperationException))]
+ [ExpectedException(typeof (InvalidOperationException))]
public void AddTaintOnPointer()
{
- var buffer = new AbstractBuffer(AbstractValue.GetNewBuffer(1));
+ buffer = new AbstractBuffer(AbstractValue.GetNewBuffer(1));
var clean = new AbstractValue(buffer);
clean.AddTaint();
}
@@ -51,8 +51,8 @@
[Test]
public void AssignmentAtByteZero()
{
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
- pointer = new AbstractValue(buffer);
+ var values = AbstractValue.GetNewBuffer(16);
+ pointer = new AbstractValue(values);
pointer.PointsTo[0] = new AbstractValue(0x31337);
Assert.AreEqual(0x31337, pointer.PointsTo[0].Value);
Assert.AreEqual("*0x00031337", pointer.ToString());
@@ -61,26 +61,14 @@
[Test]
public void AssignmentAtEnd()
{
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(16);
- pointer = new AbstractValue(buffer);
+ var values = AbstractValue.GetNewBuffer(16);
+ pointer = new AbstractValue(values);
pointer.PointsTo[15] = new AbstractValue(0x31337);
Assert.AreEqual(0x31337, pointer.PointsTo[15].Value);
}
[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))]
+ [ExpectedException(typeof (ArgumentException))]
public void EmptyBuffer()
{
pointer = new AbstractValue(new AbstractBuffer(new AbstractValue[] {}));
@@ -103,7 +91,7 @@
[Test]
public void NoPointer()
{
- AbstractValue value = new AbstractValue(2).AddTaint();
+ var value = new AbstractValue(2).AddTaint();
Assert.IsNull(value.PointsTo);
StringAssert.Contains("0x00000002", value.ToString());
@@ -120,13 +108,22 @@
}
[Test]
- [ExpectedException(typeof(ArgumentNullException))]
+ [ExpectedException(typeof (ArgumentNullException))]
public void NullCopyCtor()
{
pointer = new AbstractValue((AbstractValue) null);
}
[Test]
+ public void OOBSurvivesCopy()
+ {
+ var src = new AbstractValue(0x31337) {IsOOB = true};
+ var dest = new AbstractValue(src);
+
+ Assert.IsTrue(dest.IsOOB);
+ }
+
+ [Test]
public void Pointer()
{
buffer = new AbstractBuffer(new[] {new AbstractValue(2)});
@@ -169,16 +166,14 @@
[Test]
public void PreserveIsOOBAfterCopy()
{
- var src = new AbstractValue(0x31337);
- var dest = new AbstractValue(0x1);
- src.IsOOB = true;
- dest = new AbstractValue(src);
+ var src = new AbstractValue(0x31337) {IsOOB = true};
+ var dest = new AbstractValue(src);
Assert.IsTrue(dest.IsOOB);
}
[Test]
- [ExpectedException(typeof(ArgumentOutOfRangeException))]
+ [ExpectedException(typeof (ArgumentOutOfRangeException))]
public void RequestedBufferTooLarge()
{
AbstractValue.GetNewBuffer(AbstractValue.MAX_BUFFER_SIZE + 1);
@@ -188,12 +183,12 @@
public void TruncateValue()
{
var dwordValue = new AbstractValue(0xdeadbeef);
- AbstractValue byteValue = dwordValue.TruncateValueToByte();
+ var byteValue = dwordValue.TruncateValueToByte();
Assert.AreEqual(0xef, byteValue.Value);
}
[Test]
- [ExpectedException(typeof(ArgumentException))]
+ [ExpectedException(typeof (ArgumentException))]
public void ZeroSizeBuffer()
{
pointer = new AbstractValue(new AbstractValue[] {});
Modified: Analyzer.cs
===================================================================
--- Analyzer.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ Analyzer.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -9,12 +9,12 @@
namespace bugreport
{
- public class EmulationEventArgs : EventArgs
+ public sealed class EmulationEventArgs : EventArgs
{
private readonly ReadOnlyCollection<Byte> code;
private readonly MachineState state;
- public EmulationEventArgs(MachineState state, ReadOnlyCollection<Byte> code)
+ internal EmulationEventArgs(MachineState state, ReadOnlyCollection<Byte> code)
{
this.state = state;
this.code = code;
@@ -31,7 +31,7 @@
}
}
- public class ReportEventArgs : EventArgs
+ public sealed class ReportEventArgs : EventArgs
{
private readonly ReportItem reportItem;
@@ -46,7 +46,7 @@
}
}
- public class ReportCollection : Collection<ReportItem>
+ public sealed class ReportCollection : Collection<ReportItem>
{
public EventHandler<ReportEventArgs> OnReport;
@@ -63,10 +63,10 @@
public class Analyzer
{
- public EventHandler<EmulationEventArgs> OnEmulationComplete;
private readonly Opcode opcode = new X86Opcode();
private readonly IParsable parser;
- private ReportCollection reportItems;
+ private readonly ReportCollection reportItems;
+ public EventHandler<EmulationEventArgs> OnEmulationComplete;
public Analyzer(IParsable parser)
{
@@ -79,7 +79,7 @@
reportItems = new ReportCollection();
}
-
+
public ReadOnlyCollection<ReportItem> ActualReportItems
{
get { return new ReadOnlyCollection<ReportItem>(reportItems); }
@@ -105,13 +105,13 @@
{
var machineState = new MachineState(getRegistersForLinuxStart());
machineState.InstructionPointer = parser.EntryPointAddress;
- Byte[] instructions = parser.GetBytes();
- UInt32 index = machineState.InstructionPointer - parser.BaseAddress;
+ var instructions = parser.GetBytes();
+ var index = machineState.InstructionPointer - parser.BaseAddress;
while (index < instructions.Length)
{
- MachineState savedState = machineState;
- Byte[] instruction = extractInstruction(instructions, index);
+ var savedState = machineState;
+ var instruction = extractInstruction(instructions, index);
machineState = runCode(machineState, instruction);
if (null != OnEmulationComplete)
@@ -138,16 +138,16 @@
{
var linuxMainDefaultValues = new RegisterCollection();
- AbstractValue arg0 = new AbstractValue(1).AddTaint();
+ var 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 stackBuffer = AbstractValue.GetNewBuffer(0x200);
var buffer = new AbstractBuffer(stackBuffer);
- AbstractBuffer modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(0x100));
+ var modifiedBuffer = buffer.DoOperation(OperatorEffect.Add, new AbstractValue(0x100));
// linux ABI dictates
modifiedBuffer[5] = argvPointerPointer;
@@ -163,9 +163,9 @@
private Byte[] extractInstruction(Byte[] instructions, UInt32 index)
{
- Byte instructionLength = opcode.GetInstructionLength(instructions, index);
+ var instructionLength = opcode.GetInstructionLength(instructions, index);
var instruction = new Byte[instructionLength];
- for (UInt32 count = index; count < index + instructionLength; count++)
+ for (var count = index; count < index + instructionLength; count++)
{
instruction[count - index] = instructions[count];
}
Modified: AnalyzerTest.cs
===================================================================
--- AnalyzerTest.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ AnalyzerTest.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -27,6 +27,46 @@
}
}
+ private IParsable createMockParser(UInt32 expectedReportItemCount)
+ {
+ var control = new DynamicMock(typeof (IParsable));
+ control.ExpectAndReturn("GetBytes", code, null);
+
+ var reportItemList = new List<ReportItem>();
+
+ for (UInt32 i = 0; i < expectedReportItemCount; i++)
+ {
+ reportItemList.Add(new ReportItem(i, false));
+ }
+
+ control.ExpectAndReturn("get_ExpectedReportItems", reportItemList.AsReadOnly(), null);
+ control.ExpectAndReturn("get_ExpectedReportItems", reportItemList.AsReadOnly(), null);
+ return control.MockInstance as IParsable;
+ }
+
+ private class FakeAnalyzer : Analyzer
+ {
+ private readonly UInt32 actualReportItemCount;
+
+ public FakeAnalyzer(IParsable parser, UInt32 actualReportItemCount)
+ : base(parser)
+ {
+ this.actualReportItemCount = actualReportItemCount;
+ }
+
+ protected override MachineState runCode(MachineState _machineState, Byte[] _instructionBytes)
+ {
+ for (UInt32 i = 0; i < actualReportItemCount; i++)
+ {
+ ReportItems.Add(new ReportItem(i, false));
+ }
+
+ _machineState.InstructionPointer += (UInt32) _instructionBytes.Length;
+
+ return _machineState;
+ }
+ }
+
[Test]
public void NoReportItems()
{
@@ -37,7 +77,7 @@
}
[Test]
- [ExpectedException(typeof(ArgumentNullException))]
+ [ExpectedException(typeof (ArgumentNullException))]
public void NullStream()
{
analyzer = new Analyzer(null);
@@ -79,45 +119,5 @@
Assert.AreEqual(0, reportItems[0].InstructionPointer);
Assert.AreEqual(1, reportItems[1].InstructionPointer);
}
-
- private IParsable createMockParser(UInt32 expectedReportItemCount)
- {
- var control = new DynamicMock(typeof(IParsable));
- control.ExpectAndReturn("GetBytes", code, null);
-
- var reportItemList = new List<ReportItem>();
-
- for (UInt32 i = 0; i < expectedReportItemCount; i++)
- {
- reportItemList.Add(new ReportItem(i, false));
- }
-
- control.ExpectAndReturn("get_ExpectedReportItems", reportItemList.AsReadOnly(), null);
- control.ExpectAndReturn("get_ExpectedReportItems", reportItemList.AsReadOnly(), null);
- return control.MockInstance as IParsable;
- }
-
- private class FakeAnalyzer : Analyzer
- {
- private readonly UInt32 actualReportItemCount;
-
- public FakeAnalyzer(IParsable parser, UInt32 actualReportItemCount)
- : base(parser)
- {
- this.actualReportItemCount = actualReportItemCount;
- }
-
- protected override MachineState runCode(MachineState _machineState, Byte[] _instructionBytes)
- {
- for (UInt32 i = 0; i < actualReportItemCount; i++)
- {
- ReportItems.Add(new ReportItem(i, false));
- }
-
- _machineState.InstructionPointer += (UInt32) _instructionBytes.Length;
-
- return _machineState;
- }
- }
- }
+ }
}
\ No newline at end of file
Modified: AssemblyInfo.cs
===================================================================
--- AssemblyInfo.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ AssemblyInfo.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -7,11 +7,12 @@
using System.Reflection;
using System.Runtime.InteropServices;
-[assembly: ComVisible(false)]
+[assembly : ComVisible(false)]
// The assembly version has following format :
//
// Major.Minor.Build.Revision
//
// You can specify all values by your own or you can build default build and revision
-[assembly: AssemblyVersion("0.1.*")]
\ No newline at end of file
+
+[assembly : AssemblyVersion("0.1.*")]
\ No newline at end of file
Modified: BitMath.cs
===================================================================
--- BitMath.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ BitMath.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -22,7 +22,7 @@
for (Byte i = 0; i < 4; ++i)
{
- result |= (UInt32)data[i + index] << (8 * i);
+ result |= (UInt32) data[i + index] << (8 * i);
}
return result;
Modified: BitMathTest.cs
===================================================================
--- BitMathTest.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ BitMathTest.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -15,26 +15,26 @@
[Test]
public void AllZeroes()
{
- UInt32 result = BitMath.BytesToDword(new Byte[] {0, 0, 0, 0}, 0);
+ var result = BitMath.BytesToDword(new Byte[] {0, 0, 0, 0}, 0);
Assert.AreEqual(0, result);
}
[Test]
- [ExpectedException(typeof(ArgumentException))]
+ [ExpectedException(typeof (ArgumentException))]
public void EmptyBytes()
{
BitMath.BytesToDword(new Byte[] {}, 0);
}
[Test]
- [ExpectedException(typeof(ArgumentException))]
+ [ExpectedException(typeof (ArgumentException))]
public void NotEnoughBytesToDwordAtNonZeroIndex()
{
BitMath.BytesToDword(new Byte[] {0, 1, 2, 3}, 1);
}
[Test]
- [ExpectedException(typeof(ArgumentException))]
+ [ExpectedException(typeof (ArgumentException))]
public void NotEnoughBytesToDwordAtZeroIndex()
{
BitMath.BytesToDword(new Byte[] {0}, 0);
@@ -43,7 +43,7 @@
[Test]
public void OneTwoThreeFour()
{
- UInt32 result = BitMath.BytesToDword(new Byte[] {1, 2, 3, 4}, 0);
+ var result = BitMath.BytesToDword(new Byte[] {1, 2, 3, 4}, 0);
Assert.AreEqual(0x04030201, result);
}
}
Modified: Contract.cs
===================================================================
--- Contract.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ Contract.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -10,15 +10,15 @@
{
public abstract class Contract
{
- private Opcode opcode = new X86Opcode();
-
- protected Opcode Opcode
- {
- get { return opcode; }
+ private readonly Opcode opcode = new X86Opcode();
+
+ protected Opcode Opcode
+ {
+ get { return opcode; }
}
public abstract Boolean IsSatisfiedBy(MachineState state, Byte[] code);
-
+
public abstract MachineState Execute(MachineState state);
}
}
\ No newline at end of file
Modified: DebuggerView.cs
===================================================================
--- DebuggerView.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ DebuggerView.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -8,7 +8,7 @@
namespace bugreport
{
- internal class DebuggerView
+ internal sealed class DebuggerView
{
private readonly Boolean interactive;
private MachineState state;
@@ -20,11 +20,11 @@
public void printInfo(object sender, EmulationEventArgs e)
{
- String address = getEffectiveAddressFor(e);
+ var address = getEffectiveAddressFor(e);
Console.Write(address + ":");
Console.Write("\t");
- Byte[] code = getCodeFor(e);
+ var code = getCodeFor(e);
printOpcodeInfo(code);
Console.WriteLine(state.Registers);
@@ -33,56 +33,56 @@
handleInputIfNecessary();
}
- protected void handleInputIfNecessary()
+ private void handleInputIfNecessary()
{
+ if (!interactive) return;
+
// TODO: cover this with a system-level test
- Boolean enterPressed = false;
- if (interactive)
+ var enterPressed = false;
+
+ while (!enterPressed)
{
- while (!enterPressed)
+ var input = getInput();
+ var command = new DebuggerCommand(input);
+ if (command.IsEnter)
{
- string input = getInput();
- var command = new DebuggerCommand(input);
- if (command.IsEnter)
- {
- enterPressed = true;
- continue;
- }
-
- if (command.IsStackPrint)
- {
- printStackFor(state);
- continue;
- }
-
- if (command.IsDisassemble)
- {
- string hex = input.Substring("disasm".Length + 1);
- byte[] code = DumpFileParser.getByteArrayFromHexString(hex);
- printOpcodeInfo(code);
- continue;
- }
-
- if (command.IsQuit)
- {
- Environment.Exit(0);
- }
+ enterPressed = true;
+ continue;
+ }
- Console.WriteLine("invalid command");
+ if (command.IsStackPrint)
+ {
+ printStackFor(state);
+ continue;
}
+
+ if (command.IsDisassemble)
+ {
+ var hex = input.Substring("disasm".Length + 1);
+ var code = DumpFileParser.getByteArrayFromHexString(hex);
+ printOpcodeInfo(code);
+ continue;
+ }
+
+ if (command.IsQuit)
+ {
+ Environment.Exit(0);
+ }
+
+ Console.WriteLine("invalid command");
}
}
private void printOpcodeInfo(byte[] code)
{
- foreach (Byte codeByte in code)
+ foreach (var codeByte in code)
{
Console.Write(String.Format("{0:x2}", codeByte) + " ");
}
// magic numbers that happen to look good :)
- Int32 numberOfTabs = 3 - (code.Length / 3);
- for (Int32 i = 0; i < numberOfTabs; i++)
+ var numberOfTabs = 3 - (code.Length / 3);
+ for (var i = 0; i < numberOfTabs; i++)
{
Console.Write("\t");
}
@@ -90,19 +90,19 @@
Console.Write(OpcodeFormatter.GetInstructionName(code));
Console.Write("\t");
- String operands = OpcodeFormatter.GetOperands(code, state.InstructionPointer);
+ var operands = OpcodeFormatter.GetOperands(code, state.InstructionPointer);
Console.Write(operands);
if (operands.Length < 8)
{
Console.Write("\t");
}
- String encoding = OpcodeFormatter.GetEncoding(code);
+ var encoding = OpcodeFormatter.GetEncoding(code);
Console.Write("\t");
Console.WriteLine(encoding);
}
- private Byte[] getCodeFor(EmulationEventArgs e)
+ private static Byte[] getCodeFor(EmulationEventArgs e)
{
var code = new Byte[e.Code.Count];
e.Code.CopyTo(code, 0);
@@ -112,7 +112,7 @@
private string getEffectiveAddressFor(EmulationEventArgs e)
{
state = e.MachineState;
- String address = String.Format("{0:x8}", state.InstructionPointer);
+ var address = String.Format("{0:x8}", state.InstructionPointer);
return address;
}
@@ -122,9 +122,9 @@
return Console.ReadLine();
}
- private void printStackFor(MachineState state)
+ private static void printStackFor(MachineState state)
{
- AbstractValue esp = state.Registers[RegisterName.ESP];
+ var esp = state.Registers[RegisterName.ESP];
Console.WriteLine("Stack dump");
Console.WriteLine("esp-8\t\t esp-4\t\t esp");
Modified: DumpFileParser.cs
===================================================================
--- DumpFileParser.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ DumpFileParser.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -17,7 +17,7 @@
ReadOnlyCollection<ReportItem> ExpectedReportItems { get; }
UInt32 BaseAddress { get; }
-
+
UInt32 EntryPointAddress { get; }
Byte[] GetBytes();
@@ -44,6 +44,20 @@
opcodeList = parse();
}
+ #region IDisposable Members
+
+ public void Dispose()
+ {
+ if (null != reader)
+ {
+ reader.Dispose();
+ }
+ }
+
+ #endregion
+
+ #region IParsable Members
+
public ReadOnlyCollection<ReportItem> ExpectedReportItems
{
get { return expectedReportItems.AsReadOnly(); }
@@ -59,28 +73,6 @@
get { return entryPointAddress; }
}
- public static Byte[] getByteArrayFromHexString(String hex)
- {
- String[] hexStrings = hex.Split(new[] {' '});
-
- var hexBytes = new Byte[hexStrings.Length];
-
- for (Int32 i = 0; i < hexStrings.Length; ++i)
- {
- hexBytes[i] = Byte.Parse(hexStrings[i], NumberStyles.HexNumber);
- }
-
- return hexBytes;
- }
-
- public void Dispose()
- {
- if (null != reader)
- {
- reader.Dispose();
- }
- }
-
public Byte[] GetBytes()
{
if (opcodeList.Count == 0)
@@ -88,49 +80,66 @@
return null;
}
- Int32 total = 0;
+ var total = 0;
foreach (var bytes in opcodeList)
{
total += bytes.Length;
}
- int allByteCount = 0;
+ var allByteCount = 0;
var allBytes = new Byte[total];
foreach (var bytes in opcodeList)
{
- for (int i = 0; i < bytes.Length; i++)
+ for (var i = 0; i < bytes.Length; i++)
{
allBytes[i + allByteCount] = bytes[i];
}
-
+
allByteCount += bytes.Length;
}
return allBytes;
}
+ #endregion
+
+ public static Byte[] getByteArrayFromHexString(String hex)
+ {
+ var hexStrings = hex.Split(new[] {' '});
+
+ var hexBytes = new Byte[hexStrings.Length];
+
+ for (var i = 0; i < hexStrings.Length; ++i)
+ {
+ hexBytes[i] = Byte.Parse(hexStrings[i], NumberStyles.HexNumber);
+ }
+
+ return hexBytes;
+ }
+
private static UInt32 getAddressForLine(String line)
{
- String address = line.Substring(0, 8);
+ var address = line.Substring(0, 8);
return UInt32.Parse(address, NumberStyles.HexNumber);
}
private static String getHexWithSpaces(String line)
{
- Int32 colonIndex = line.IndexOf(':');
+ var colonIndex = line.IndexOf(':');
if (colonIndex == -1)
{
return null;
}
- else if (colonIndex != 8)
+
+ if (colonIndex != 8)
{
return null;
}
- String afterColonToEnd = line.Substring(colonIndex + 1).Trim();
- Int32 doubleSpaceIndex = afterColonToEnd.IndexOf(" ", StringComparison.Ordinal);
- Int32 spaceTabIndex = afterColonToEnd.IndexOf(" \t", StringComparison.Ordinal);
+ var afterColonToEnd = line.Substring(colonIndex + 1).Trim();
+ var doubleSpaceIndex = afterColonToEnd.IndexOf(" ", StringComparison.Ordinal);
+ var spaceTabIndex = afterColonToEnd.IndexOf(" \t", StringComparison.Ordinal);
Int32 endOfHexIndex;
if (doubleSpaceIndex >= 0 && spaceTabIndex >= 0)
@@ -147,7 +156,7 @@
return null;
}
- String hexString = afterColonToEnd.Substring(0, endOfHexIndex).Trim();
+ var hexString = afterColonToEnd.Substring(0, endOfHexIndex).Trim();
return hexString;
}
@@ -159,14 +168,14 @@
return null;
}
- String hex = getHexWithSpaces(line);
+ var hex = getHexWithSpaces(line);
if (null == hex)
{
return null;
}
- Byte[] hexBytes = getByteArrayFromHexString(hex);
+ var hexBytes = getByteArrayFromHexString(hex);
return hexBytes;
}
@@ -178,28 +187,27 @@
private static ReportItem getAnnotation(String line)
{
- Int32 locationIndex = line.IndexOf("=", StringComparison.Ordinal) + 1;
- UInt32 location = UInt32.Parse(line.Substring(locationIndex + "/>".Length, 8), NumberStyles.HexNumber);
- Int32 exploitableIndex = line.IndexOf("=", locationIndex + 1, StringComparison.Ordinal) + 1;
- Boolean exploitable =
+ var locationIndex = line.IndexOf("=", StringComparison.Ordinal) + 1;
+ var location = UInt32.Parse(line.Substring(locationIndex + "/>".Length, 8), NumberStyles.HexNumber);
+ var exploitableIndex = line.IndexOf("=", locationIndex + 1, StringComparison.Ordinal) + 1;
+ var exploitable =
Boolean.Parse(line.Substring(exploitableIndex, (line.Length - exploitableIndex) - "/>".Length));
return new ReportItem(location, exploitable);
}
private void updateMainInfo(String line)
{
- if (line.Length > 0 && line[0] >= '0' && line[0] <= '7')
+ if (String.IsNullOrEmpty(line) || line[0] < '0' || line[0] > '7') return;
+
+ if (line.Contains("<_start>:"))
{
- if (line.Contains("<_start>:"))
- {
- baseAddress = getAddressForLine(line);
- inTextSection = true;
- }
+ baseAddress = getAddressForLine(line);
+ inTextSection = true;
+ }
- if (line.Contains("<" + functionNameToParse + ">:"))
- {
- entryPointAddress = getAddressForLine(line);
- }
+ if (line.Contains("<" + functionNameToParse + ">:"))
+ {
+ entryPointAddress = getAddressForLine(line);
}
}
@@ -209,10 +217,10 @@
while (!reader.EndOfStream)
{
- String currentLine = reader.ReadLine();
+ var currentLine = reader.ReadLine();
if (hasAnnotation(currentLine))
{
- ReportItem item = getAnnotation(currentLine);
+ var item = getAnnotation(currentLine);
expectedReportItems.Add(item);
}
@@ -220,14 +228,14 @@
if (inTextSection)
{
- Byte[] opcode = getHexFromString(currentLine);
+ var opcode = getHexFromString(currentLine);
if (opcode != null)
{
opcodes.Add(getHexFromString(currentLine));
}
}
}
-
+
return opcodes;
}
}
Modified: DumpFileParserTest.cs
===================================================================
--- DumpFileParserTest.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ DumpFileParserTest.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -27,11 +27,10 @@
[TearDown]
public void TearDown()
{
- if (parser != null)
- {
- parser.Dispose();
- parser = null;
- }
+ if (parser == null) return;
+
+ parser.Dispose();
+ parser = null;
}
}
@@ -91,7 +90,7 @@
writer.Flush();
parser = new DumpFileParser(stream, "main");
- Byte[] code = parser.GetBytes();
+ var code = parser.GetBytes();
CollectionAssert.AreEqual(new Byte[] {0xc9, 0xc3, 0x90}, code);
}
@@ -114,7 +113,7 @@
}
[Test]
- [ExpectedException(typeof(FormatException))]
+ [ExpectedException(typeof (FormatException))]
public void LineWithBadHex()
{
writer.WriteLine(" 8048385: 83 ej 10 sub esp,0x10");
@@ -176,7 +175,7 @@
Assert.AreEqual(0x0804837c, parser.BaseAddress);
Assert.AreEqual(0x0804837d, parser.EntryPointAddress);
- Byte[] code = parser.GetBytes();
+ var code = parser.GetBytes();
CollectionAssert.AreEqual(new Byte[] {0xc9, 0xc3}, code);
Assert.AreEqual(2, code.Length);
Assert.AreEqual(0, parser.ExpectedReportItems.Count);
@@ -195,7 +194,7 @@
Assert.AreEqual(0x0804837c, parser.BaseAddress);
Assert.AreEqual(0x0804837d, parser.EntryPointAddress);
- Byte[] code = parser.GetBytes();
+ var code = parser.GetBytes();
CollectionAssert.AreEqual(new Byte[] {0xc9, 0xc3, 0x90}, code);
Assert.AreEqual(3, code.Length);
Assert.AreEqual(0, parser.ExpectedReportItems.Count);
@@ -224,7 +223,7 @@
Assert.AreEqual(0x0804837c, parser.BaseAddress);
Assert.AreEqual(0x0804837c, parser.EntryPointAddress);
- Byte[] code = parser.GetBytes();
+ var code = parser.GetBytes();
Assert.AreEqual(0xc9, code[0]);
}
Modified: ElfFileParser.cs
===================================================================
--- ElfFileParser.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ ElfFileParser.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -22,6 +22,20 @@
textData = new Byte[stream.Length];
}
+ #region IDisposable Members
+
+ public void Dispose()
+ {
+ if (null != stream)
+ {
+ stream.Dispose();
+ }
+ }
+
+ #endregion
+
+ #region IParsable Members
+
public UInt32 BaseAddress
{
get { return 0x080482e0; }
@@ -40,16 +54,10 @@
public Byte[] GetBytes()
{
stream.Seek(0x2e0, SeekOrigin.Begin);
- stream.Read(textData, 0, (Int32)(stream.Length - stream.Position));
+ stream.Read(textData, 0, (Int32) (stream.Length - stream.Position));
return textData;
}
- public void Dispose()
- {
- if (null != stream)
- {
- stream.Dispose();
- }
- }
+ #endregion
}
}
\ No newline at end of file
Modified: ElfFileParserTest.cs
===================================================================
--- ElfFileParserTest.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ ElfFileParserTest.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -38,7 +38,7 @@
[TestFixture]
public class WellFormatted : ElfFileParserFixture
{
- private Byte[] textData;
+ #region Setup/Teardown
[SetUp]
public override void SetUp()
@@ -52,6 +52,10 @@
parser = new ElfFileParser(stream);
}
+ #endregion
+
+ private Byte[] textData;
+
[Test]
public void GetBytes()
{
Modified: GLibcStartMainContract.cs
===================================================================
--- GLibcStartMainContract.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ GLibcStartMainContract.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -8,21 +8,15 @@
namespace bugreport
{
- public class GLibcStartMainContract : Contract
+ internal sealed class GLibcStartMainContract : Contract
{
public override Boolean IsSatisfiedBy(MachineState state, Byte[] code)
{
- UInt32 effectiveAddress = Opcode.GetEffectiveAddress(code, state.InstructionPointer);
+ var effectiveAddress = Opcode.GetEffectiveAddress(code, state.InstructionPointer);
const UInt32 GLIBC_START_MAIN_IMPORT_FUNCTION_ADDR = 0x80482b8;
- if (effectiveAddress == GLIBC_START_MAIN_IMPORT_FUNCTION_ADDR)
- {
- return true;
- }
- else
- {
- return false;
- }
+
+ return effectiveAddress == GLIBC_START_MAIN_IMPORT_FUNCTION_ADDR;
}
public override MachineState Execute(MachineState state)
Modified: GLibcStartMainContractTest.cs
===================================================================
--- GLibcStartMainContractTest.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ GLibcStartMainContractTest.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -12,8 +12,7 @@
[TestFixture]
public class GLibcStartMainContractTest
{
- private GLibcStartMainContract contract;
- private MachineState state;
+ #region Setup/Teardown
[SetUp]
public void SetUp()
@@ -24,6 +23,11 @@
contract = new GLibcStartMainContract();
}
+ #endregion
+
+ private GLibcStartMainContract contract;
+ private MachineState state;
+
[Test]
public void Execute()
{
Modified: InvalidOpcodeException.cs
===================================================================
--- InvalidOpcodeException.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ InvalidOpcodeException.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -3,18 +3,18 @@
namespace bugreport
{
- public class InvalidOpcodeException : Exception
+ public sealed class InvalidOpcodeException : Exception
{
public InvalidOpcodeException(params Byte[] code)
: base(FormatOpcodes(code))
{
}
- public static String FormatOpcodes(params Byte[] code)
+ private static String FormatOpcodes(params Byte[] code)
{
var message = new StringBuilder("Invalid opcode: ");
- foreach (Byte opcode in code)
+ foreach (var opcode in code)
{
message.Append(String.Format(" 0x{0:x2}", opcode));
}
Modified: MachineState.cs
===================================================================
--- MachineState.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ MachineState.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -33,7 +33,7 @@
public override Boolean Equals(object obj)
{
- var operationResult = (OperationResult)obj;
+ var operationResult = (OperationResult) obj;
return Value.Equals(operationResult.Value) && ZeroFlag == operationResult.ZeroFlag;
}
@@ -97,7 +97,7 @@
return registers[RegisterName.ESP].PointsTo[0];
}
- set
+ private set
{
Debug.Assert(registers[RegisterName.ESP] != null);
Debug.Assert(registers[RegisterName.ESP].PointsTo != null);
@@ -132,7 +132,7 @@
return false;
}
- foreach (UInt32 key in dataSegment.Keys)
+ foreach (var key in dataSegment.Keys)
{
if (!other.dataSegment.ContainsKey(key))
{
@@ -150,11 +150,11 @@
public override Int32 GetHashCode()
{
- Int32 hashCode = instructionPointer.GetHashCode() ^
- registers.GetHashCode() ^
- zeroFlag.GetHashCode();
+ var hashCode = instructionPointer.GetHashCode() ^
+ registers.GetHashCode() ^
+ zeroFlag.GetHashCode();
- foreach (UInt32 key in dataSegment.Keys)
+ foreach (var key in dataSegment.Keys)
{
hashCode ^= dataSegment[key].GetHashCode();
}
@@ -164,7 +164,7 @@
public MachineState PushOntoStack(AbstractValue value)
{
- MachineState newState = DoOperation(RegisterName.ESP, OperatorEffect.Add, new AbstractValue(0x4));
+ var newState = DoOperation(RegisterName.ESP, OperatorEffect.Add, new AbstractValue(0x4));
newState.TopOfStack = new AbstractValue(value);
return newState;
}
@@ -195,7 +195,7 @@
String.Format("Unsupported OperatorEffect: {0}", _operatorEffect), "_operatorEffect");
}
}
-
+
return newState;
}
@@ -208,11 +208,11 @@
case OperatorEffect.Assignment:
{
newState.dataSegment[offset] =
- newState.DoOperation(newState.dataSegment[offset], _operatorEffect, rhs).Value;
+ DoOperation(newState.dataSegment[offset], _operatorEffect, rhs).Value;
break;
}
}
-
+
return newState;
}
@@ -225,7 +225,7 @@
case OperatorEffect.Assignment:
case OperatorEffect.Cmp:
{
- OperationResult result = newState.DoOperation(Registers[lhs].PointsTo[index], _operatorEffect, rhs);
+ var result = DoOperation(Registers[lhs].PointsTo[index], _operatorEffect, rhs);
newState.Registers[lhs].PointsTo[index] = result.Value;
newState.ZeroFlag = result.ZeroFlag;
break;
@@ -241,12 +241,12 @@
if (Registers[lhs].IsPointer && _operatorEffect != OperatorEffect.Assignment)
{
- AbstractBuffer newBuffer = Registers[lhs].PointsTo.DoOperation(_operatorEffect, rhs);
+ var newBuffer = Registers[lhs].PointsTo.DoOperation(_operatorEffect, rhs);
newState.Registers[lhs] = new AbstractValue(newBuffer);
}
else
{
- OperationResult result = newState.DoOperation(Registers[lhs], _operatorEffect, rhs);
+ var result = DoOperation(Registers[lhs], _operatorEffect, rhs);
newState.Registers[lhs] = result.Value;
newState.ZeroFlag = result.ZeroFlag;
}
@@ -257,13 +257,13 @@
public MachineState DoOperation(RegisterName lhs, OperatorEffect _operatorEffect, RegisterName rhs)
{
var newState = new MachineState(this);
- OperationResult result = newState.DoOperation(Registers[lhs], _operatorEffect, Registers[rhs]);
+ var result = DoOperation(Registers[lhs], _operatorEffect, Registers[rhs]);
newState.Registers[lhs] = result.Value;
newState.ZeroFlag = result.ZeroFlag;
return newState;
}
- public OperationResult DoOperation(AbstractValue lhs, OperatorEffect _operatorEffect, AbstractValue rhs)
+ private static OperationResult DoOperation(AbstractValue lhs, OperatorEffect _operatorEffect, AbstractValue rhs)
{
if (rhs.IsPointer && _operatorEffect != OperatorEffect.Assignment)
{
@@ -272,7 +272,6 @@
var result = new OperationResult();
AbstractValue totalValue;
- UInt32 total;
if (_operatorEffect == OperatorEffect.Assignment)
{
@@ -289,14 +288,7 @@
if (_operatorEffect == OperatorEffect.Cmp)
{
- if ((lhs.Value - rhs.Value) == 0)
- {
- result.ZeroFlag = true;
- }
- else
- {
- result.ZeroFlag = false;
- }
+ result.ZeroFlag = (lhs.Value - rhs.Value) == 0;
totalValue = lhs;
result.Value = totalValue;
@@ -305,12 +297,12 @@
if (lhs.IsPointer)
{
- AbstractBuffer newBuffer = lhs.PointsTo.DoOperation(_operatorEffect, rhs);
+ var newBuffer = lhs.PointsTo.DoOperation(_operatorEffect, rhs);
result.Value = new AbstractValue(newBuffer);
return result;
}
- total = getCalculatedValue(lhs.Value, _operatorEffect, rhs.Value);
+ var total = getCalculatedValue(lhs.Value, _operatorEffect, rhs.Value);
totalValue = new AbstractValue(total);
if (lhs.IsTainted || rhs.IsTainted)
Modified: MachineStateTest.cs
===================================================================
--- MachineStateTest.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ MachineStateTest.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -12,6 +12,12 @@
[TestFixture]
public class MachineStateTest
{
+ [SetUp]
+ public void SetUp()
+ {
+ state = new MachineState(new RegisterCollection());
+ }
+
private readonly AbstractValue one = new AbstractValue(1);
private readonly AbstractValue two = new AbstractValue(2).AddTaint();
private MachineState state;
@@ -33,12 +39,6 @@
set { state.Registers[RegisterName.ESP] = value; }
}
- [SetUp]
- public void SetUp()
- {
- state = new MachineState(new RegisterCollection());
- }
-
[Test]
public void Add()
{
@@ -75,8 +75,7 @@
[Test]
public void AssignmentRetainsOOB()
{
- var oob = new AbstractValue(1);
- oob.IsOOB = true;
+ var oob = new AbstractValue(1) {IsOOB = true};
state = state.DoOperation(RegisterName.EAX, OperatorEffect.Assignment, oob);
Assert.IsTrue(eax.IsOOB);
@@ -143,7 +142,7 @@
[Test]
public void Jnz()
{
- Byte offset = 6;
+ const byte offset = 6;
eax = two;
ebx = one;
state = state.DoOperation(RegisterName.EAX, OperatorEffect.Cmp, RegisterName.EAX);
@@ -156,7 +155,7 @@
}
[Test]
- [ExpectedException(typeof(ArgumentException))]
+ [ExpectedException(typeof (ArgumentException))]
public void JnzPointerOffset()
{
var pointer = new AbstractValue(AbstractValue.GetNewBuffer(1));
@@ -164,7 +163,7 @@
}
[Test]
- [ExpectedException(typeof(ArgumentException))]
+ [ExpectedException(typeof (ArgumentException))]
public void NonAssignmentOfPointer()
{
eax = one;
@@ -192,7 +191,7 @@
[Test]
public void PointerAdd()
{
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(0x10);
+ var buffer = AbstractValue.GetNewBuffer(0x10);
buffer[4] = one;
eax = new AbstractValue(buffer);
@@ -203,7 +202,7 @@
[Test]
public void PointerAnd()
{
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(0x10);
+ var buffer = AbstractValue.GetNewBuffer(0x10);
buffer[4] = one;
eax = new AbstractValue(buffer);
@@ -212,7 +211,7 @@
Assert.AreEqual(one, eax.PointsTo[0]);
var andValue = new AbstractValue(0xfffffff0);
- MachineState newState = state.DoOperation(RegisterName.EAX, OperatorEffect.And, andValue);
+ var newState = state.DoOperation(RegisterName.EAX, OperatorEffect.And, andValue);
Assert.AreNotSame(newState, state);
Assert.AreNotEqual(newState, state);
@@ -223,7 +222,7 @@
[Test]
public void PointerSub()
{
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(0x10);
+ var buffer = AbstractValue.GetNewBuffer(0x10);
buffer[0] = one;
eax = new AbstractValue(buffer);
ebx = new AbstractValue(0x4);
@@ -236,7 +235,7 @@
[Test]
public void PushPopThenAssignToTop()
{
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(0x20);
+ var buffer = AbstractValue.GetNewBuffer(0x20);
esp = new AbstractValue(buffer);
state = state.PushOntoStack(one);
@@ -249,7 +248,7 @@
[Test]
public void PushTwiceThenManuallyAdjustStack()
{
- AbstractValue[] buffer = AbstractValue.GetNewBuffer(0x20);
+ var buffer = AbstractValue.GetNewBuffer(0x20);
esp = new AbstractValue(buffer);
state = state.PushOntoStack(one);
state = state.PushOntoStack(two);
@@ -281,7 +280,7 @@
}
[Test]
- [ExpectedException(typeof(ArgumentException))]
+ [ExpectedException(typeof (ArgumentException))]
public void Unknown()
{
state.DoOperation(RegisterName.EAX, OperatorEffect.Unknown, RegisterName.EBX);
Modified: Main.cs
===================================================================
--- Main.cs 2009-02-02 22:36:43 UTC (rev 166)
+++ Main.cs 2009-02-12 03:51:26 UTC (rev 167)
@@ -44,19 +44,21 @@
analyzeFiles(Options.Filenames, Options.IsTracing, Options.IsDebugging);
- if (analyzer.ExpectedReportItems.Count != 0 &&
- (analyzer.ExpectedReportItems.Count != analyzer.ActualReportItems.Count))
+ if (analyzer.ExpectedReportItems.Count == 0 ||
+ (analyzer.ExpectedRep...
[truncated message content] |