|
From: <mat...@us...> - 2009-09-11 22:28:59
|
Revision: 170
http://bugreport.svn.sourceforge.net/bugreport/?rev=170&view=rev
Author: matt_hargett
Date: 2009-09-11 22:28:12 +0000 (Fri, 11 Sep 2009)
Log Message:
-----------
Run ReSharper 5.x alpha code cleanup, which: converted simple properties to auto properties, fixed naming conventions, used objects/array initializers when possible, made use of the var keyword where possible, converted some delegates to lambdas, and other C# 3.0/style cleanups.
Modified Paths:
--------------
AbstractBuffer.cs
AbstractBufferTest.cs
AbstractValue.cs
AbstractValueTest.cs
Analyzer.cs
AnalyzerTest.cs
AssemblyInfo.cs
BitMath.cs
DebuggerCommand.cs
DebuggerView.cs
DumpFileParser.cs
DumpFileParserTest.cs
ElfFileParser.cs
MachineState.cs
MachineStateTest.cs
Main.cs
MainTest.cs
ModRM.cs
ModRMTest.cs
Opcode.cs
OpcodeFormatter.cs
OpcodeFormatterTest.cs
Options.cs
OptionsTest.cs
SIB.cs
X86Emulator.cs
X86EmulatorTest.cs
X86Opcode.cs
X86OpcodeTest.cs
Modified: AbstractBuffer.cs
===================================================================
--- AbstractBuffer.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ AbstractBuffer.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -10,33 +10,25 @@
{
public sealed class AbstractBuffer
{
- private readonly Int32 allocatedLength;
- private UInt32 baseIndex;
private AbstractValue[] storage;
- public AbstractBuffer(AbstractValue[] _buffer)
+ public AbstractBuffer(AbstractValue[] values)
{
- storage = _buffer;
- allocatedLength = storage.Length;
+ storage = values;
+ Length = storage.Length;
}
- public AbstractBuffer(AbstractBuffer _copyMe)
+ public AbstractBuffer(AbstractBuffer other)
{
- baseIndex = _copyMe.BaseIndex;
- allocatedLength = _copyMe.allocatedLength;
- storage = new AbstractValue[_copyMe.storage.Length];
- Array.Copy(_copyMe.storage, storage, _copyMe.storage.Length);
+ BaseIndex = other.BaseIndex;
+ Length = other.Length;
+ storage = new AbstractValue[other.storage.Length];
+ Array.Copy(other.storage, storage, other.storage.Length);
}
- private UInt32 BaseIndex
- {
- get { return baseIndex; }
- }
+ private UInt32 BaseIndex { get; set; }
- public Int32 Length
- {
- get { return allocatedLength; }
- }
+ public int Length { get; private set; }
public AbstractValue this[Int32 index]
{
@@ -45,38 +37,38 @@
// We check this.storage.Length as well so that we aren't calling Extend() when we dont need to.
if (IsIndexPastBounds(index))
{
- extend(baseIndex + (UInt32) index);
- return storage[baseIndex + index];
+ Extend(BaseIndex + (UInt32) index);
+ return storage[BaseIndex + index];
}
- return storage[baseIndex + index];
+ return storage[BaseIndex + index];
}
set
{
- if ((baseIndex + index) >= allocatedLength)
+ if ((BaseIndex + index) >= Length)
{
- value.IsOOB = true;
+ value.IsOutOfBounds = true;
}
if (IsIndexPastBounds(index))
{
- extend(baseIndex + (UInt32) index);
- storage[baseIndex + index] = value;
+ Extend(BaseIndex + (UInt32) index);
+ storage[BaseIndex + index] = value;
}
else
{
- storage[baseIndex + index] = value;
+ storage[BaseIndex + index] = value;
}
}
}
- public AbstractBuffer DoOperation(OperatorEffect _operatorEffect, AbstractValue _rhs)
+ public AbstractBuffer DoOperation(OperatorEffect operatorEffect, AbstractValue rhs)
{
var lhs = this;
- // TODO: should have a guard for if _rhs isn't a pointer
- switch (_operatorEffect)
+ // TODO: should have a guard for if rhs isn't a pointer
+ switch (operatorEffect)
{
case OperatorEffect.Assignment:
{
@@ -88,7 +80,7 @@
case OperatorEffect.Add:
{
var result = new AbstractBuffer(lhs);
- result.baseIndex += _rhs.Value;
+ result.BaseIndex += rhs.Value;
return result;
}
@@ -97,18 +89,19 @@
{
var result = new AbstractBuffer(lhs);
- if (result.baseIndex < _rhs.Value)
+ 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
)
);
}
- result.baseIndex -= _rhs.Value;
+ result.BaseIndex -= rhs.Value;
return result;
}
@@ -116,41 +109,44 @@
{
var result = new AbstractBuffer(lhs);
- result.baseIndex &= _rhs.Value;
+ 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);
+ return ((BaseIndex + index) >= Length) && ((BaseIndex + index) >= storage.Length);
}
- private void extend(UInt32 _newLength)
+ private void Extend(UInt32 newLength)
{
// Account for element [0] of the array
- _newLength = _newLength + 1;
- if (_newLength >= Length)
+ newLength = newLength + 1;
+ if (newLength >= Length)
{
- var _copyTo = new AbstractValue[_newLength];
+ var extendedCopy = new AbstractValue[newLength];
Int32 i;
for (i = 0; i < storage.Length; i++)
{
- _copyTo[i] = storage[i];
+ extendedCopy[i] = storage[i];
}
- for (; i < _newLength; i++)
+ for (; i < newLength; i++)
{
- _copyTo[i] = new AbstractValue(AbstractValue.UNKNOWN) {IsOOB = true};
+ extendedCopy[i] = new AbstractValue(AbstractValue.UNKNOWN)
+ {
+ IsOutOfBounds = true
+ };
}
- storage = _copyTo;
+ storage = extendedCopy;
}
return;
Modified: AbstractBufferTest.cs
===================================================================
--- AbstractBufferTest.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ AbstractBufferTest.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -123,7 +123,7 @@
var pointer = new AbstractBuffer(buffer);
var value = pointer[16];
- Assert.IsTrue(value.IsOOB);
+ Assert.IsTrue(value.IsOutOfBounds);
Assert.IsFalse(value.IsInitialized);
Assert.AreEqual(AbstractValue.UNKNOWN, value.Value);
}
@@ -141,13 +141,13 @@
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.IsTrue(pointer[2].IsOutOfBounds, " 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.IsFalse(pointer[0].IsOutOfBounds);
+ Assert.IsFalse(pointer[1].IsOutOfBounds);
Assert.AreEqual(0x41, pointer[0].Value);
Assert.AreEqual(0x42, pointer[1].Value);
@@ -160,19 +160,19 @@
var pointer = new AbstractBuffer(buffer);
// Access beyond buffer bounds forcing buffer to expand
- Assert.IsTrue(pointer[17].IsOOB);
+ Assert.IsTrue(pointer[17].IsOutOfBounds);
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.IsTrue(pointer[64].IsOutOfBounds);
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.IsTrue(pointer[17].IsOutOfBounds);
Assert.AreEqual(0x41414141, pointer[17].Value);
}
Modified: AbstractValue.cs
===================================================================
--- AbstractValue.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ AbstractValue.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -22,48 +22,48 @@
storage = UNKNOWN;
}
- public AbstractValue(AbstractValue[] _willPointTo)
+ public AbstractValue(AbstractValue[] willPointTo)
{
- if (_willPointTo.Length == 0)
+ if (willPointTo.Length == 0)
{
- throw new ArgumentException("Empty buffer is not allowed", "_willPointTo");
+ throw new ArgumentException("Empty buffer is not allowed", "willPointTo");
}
storage = 0xdeadbeef;
- pointsTo = new AbstractBuffer(_willPointTo);
+ pointsTo = new AbstractBuffer(willPointTo);
}
- public AbstractValue(AbstractBuffer _willPointTo)
+ public AbstractValue(AbstractBuffer willPointTo)
{
- if (_willPointTo.Length == 0)
+ if (willPointTo.Length == 0)
{
- throw new ArgumentException("Empty buffer is not allowed", "_willPointTo");
+ throw new ArgumentException("Empty buffer is not allowed", "willPointTo");
}
storage = 0xdeadbeef;
- pointsTo = new AbstractBuffer(_willPointTo);
+ pointsTo = new AbstractBuffer(willPointTo);
}
- public AbstractValue(AbstractValue _copyMe)
+ public AbstractValue(AbstractValue other)
{
- if (_copyMe == null)
+ if (other == null)
{
- throw new ArgumentNullException("_copyMe");
+ throw new ArgumentNullException("other");
}
- storage = _copyMe.Value;
- tainted = _copyMe.IsTainted;
- IsOOB = _copyMe.IsOOB;
+ storage = other.Value;
+ tainted = other.IsTainted;
+ IsOutOfBounds = other.IsOutOfBounds;
- if (_copyMe.PointsTo != null)
+ if (other.PointsTo != null)
{
- pointsTo = new AbstractBuffer(_copyMe.PointsTo);
+ pointsTo = new AbstractBuffer(other.PointsTo);
}
}
- public AbstractValue(UInt32 _value)
+ public AbstractValue(UInt32 value)
{
- storage = _value;
+ storage = value;
}
public AbstractBuffer PointsTo
@@ -78,7 +78,7 @@
private set { tainted = value; }
}
- public Boolean IsOOB { get; set; }
+ public Boolean IsOutOfBounds { get; set; }
public Boolean IsInitialized
{
@@ -122,14 +122,14 @@
}
return Value == other.Value &&
- IsOOB == other.IsOOB &&
+ IsOutOfBounds == other.IsOutOfBounds &&
IsTainted == other.IsTainted &&
PointsTo == other.PointsTo;
}
public override Int32 GetHashCode()
{
- var hashCode = Value.GetHashCode() ^ IsOOB.GetHashCode() ^
+ var hashCode = Value.GetHashCode() ^ IsOutOfBounds.GetHashCode() ^
IsTainted.GetHashCode();
if (PointsTo != null)
@@ -156,7 +156,10 @@
throw new InvalidOperationException("Cannot AddTaint to a pointer");
}
- var taintedValue = new AbstractValue(this) {IsTainted = true};
+ var taintedValue = new AbstractValue(this)
+ {
+ IsTainted = true
+ };
return taintedValue;
}
@@ -189,7 +192,8 @@
const Byte MAXIMUM_DISPLAYED_POINTER_DEPTH = 100;
Int32 count = MAXIMUM_DISPLAYED_POINTER_DEPTH;
- while ((pointer != null) && (count-- > 0))
+ while ((pointer != null) &&
+ (count-- > 0))
{
newResult.Append("*");
Modified: AbstractValueTest.cs
===================================================================
--- AbstractValueTest.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ AbstractValueTest.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -115,12 +115,15 @@
}
[Test]
- public void OOBSurvivesCopy()
+ public void OutOfBoundsPropertySurvivesCopy()
{
- var src = new AbstractValue(0x31337) {IsOOB = true};
+ var src = new AbstractValue(0x31337)
+ {
+ IsOutOfBounds = true
+ };
var dest = new AbstractValue(src);
- Assert.IsTrue(dest.IsOOB);
+ Assert.IsTrue(dest.IsOutOfBounds);
}
[Test]
@@ -164,12 +167,15 @@
}
[Test]
- public void PreserveIsOOBAfterCopy()
+ public void IsOutOfBoundsPropertySurviviesCopy()
{
- var src = new AbstractValue(0x31337) {IsOOB = true};
+ var src = new AbstractValue(0x31337)
+ {
+ IsOutOfBounds = true
+ };
var dest = new AbstractValue(src);
- Assert.IsTrue(dest.IsOOB);
+ Assert.IsTrue(dest.IsOutOfBounds);
}
[Test]
Modified: Analyzer.cs
===================================================================
--- Analyzer.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ Analyzer.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -103,17 +103,19 @@
public void Run()
{
- var machineState = new MachineState(getRegistersForLinuxStart());
- machineState.InstructionPointer = parser.EntryPointAddress;
+ var machineState = new MachineState(GetRegistersForLinuxStart())
+ {
+ InstructionPointer = parser.EntryPointAddress
+ };
var instructions = parser.GetBytes();
var index = machineState.InstructionPointer - parser.BaseAddress;
while (index < instructions.Length)
{
var savedState = machineState;
- var instruction = extractInstruction(instructions, index);
+ var instruction = GetInstructionFor(instructions, index);
- machineState = runCode(machineState, instruction);
+ machineState = RunCode(machineState, instruction);
if (null != OnEmulationComplete)
{
OnEmulationComplete(
@@ -129,12 +131,12 @@
}
}
- protected virtual MachineState runCode(MachineState _machineState, Byte[] code)
+ protected virtual MachineState RunCode(MachineState _machineState, Byte[] code)
{
return X86Emulator.Run(reportItems, _machineState, code);
}
- private static RegisterCollection getRegistersForLinuxStart()
+ private static RegisterCollection GetRegistersForLinuxStart()
{
var linuxMainDefaultValues = new RegisterCollection();
@@ -161,9 +163,9 @@
return linuxMainDefaultValues;
}
- private Byte[] extractInstruction(Byte[] instructions, UInt32 index)
+ private Byte[] GetInstructionFor(Byte[] instructions, UInt32 index)
{
- var instructionLength = opcode.GetInstructionLength(instructions, index);
+ var instructionLength = opcode.GetInstructionLengthFor(instructions, index);
var instruction = new Byte[instructionLength];
for (var count = index; count < index + instructionLength; count++)
{
Modified: AnalyzerTest.cs
===================================================================
--- AnalyzerTest.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ AnalyzerTest.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -27,7 +27,7 @@
}
}
- private IParsable createMockParser(UInt32 expectedReportItemCount)
+ private IParsable CreateMockParser(UInt32 expectedReportItemCount)
{
var control = new DynamicMock(typeof (IParsable));
control.ExpectAndReturn("GetBytes", code, null);
@@ -44,7 +44,7 @@
return control.MockInstance as IParsable;
}
- private class FakeAnalyzer : Analyzer
+ private sealed class FakeAnalyzer : Analyzer
{
private readonly UInt32 actualReportItemCount;
@@ -54,23 +54,23 @@
this.actualReportItemCount = actualReportItemCount;
}
- protected override MachineState runCode(MachineState _machineState, Byte[] _instructionBytes)
+ 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;
+ machineState.InstructionPointer += (UInt32) instructionBytes.Length;
- return _machineState;
+ return machineState;
}
}
[Test]
public void NoReportItems()
{
- analyzer = new Analyzer(createMockParser(0));
+ analyzer = new Analyzer(CreateMockParser(0));
Assert.AreEqual(0, analyzer.ActualReportItems.Count);
analyzer.Run();
Assert.AreEqual(0, analyzer.ExpectedReportItems.Count);
@@ -87,11 +87,11 @@
[Test]
public void VerifyExpectedAndActualReports()
{
- analyzer = new FakeAnalyzer(createMockParser(2), 2);
+ analyzer = new FakeAnalyzer(CreateMockParser(2), 2);
analyzer.Run();
Assert.AreEqual(analyzer.ActualReportItems.Count, analyzer.ExpectedReportItems.Count);
- analyzer = new FakeAnalyzer(createMockParser(2), 3);
+ analyzer = new FakeAnalyzer(CreateMockParser(2), 3);
analyzer.Run();
Assert.AreNotEqual(analyzer.ActualReportItems.Count, analyzer.ExpectedReportItems.Count);
}
@@ -101,7 +101,7 @@
{
var reportItems = new List<ReportItem>();
- analyzer = new FakeAnalyzer(createMockParser(2), 2);
+ analyzer = new FakeAnalyzer(CreateMockParser(2), 2);
analyzer.OnEmulationComplete +=
delegate(object sender, EmulationEventArgs e)
{
@@ -110,7 +110,7 @@
};
analyzer.OnReport +=
- delegate(object sender, ReportEventArgs e) { reportItems.Add(e.ReportItem); };
+ (sender, e) => reportItems.Add(e.ReportItem);
analyzer.Run();
Assert.AreEqual(2, analyzer.ActualReportItems.Count);
Modified: AssemblyInfo.cs
===================================================================
--- AssemblyInfo.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ AssemblyInfo.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -8,7 +8,7 @@
using System.Reflection;
using System.Runtime.InteropServices;
-[assembly : ComVisible(false)]
+[assembly: ComVisible(false)]
// The assembly version has following format :
//
@@ -16,5 +16,5 @@
//
// You can specify all values by your own or you can build default build and revision
-[assembly : AssemblyVersion("0.1.*")]
-[assembly : CLSCompliant(true)]
+[assembly: AssemblyVersion("0.1.*")]
+[assembly: CLSCompliant(true)]
\ No newline at end of file
Modified: BitMath.cs
===================================================================
--- BitMath.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ BitMath.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -13,14 +13,17 @@
public static UInt32 BytesToDword(Byte[] data, Byte index)
{
UInt32 result = 0;
+ const int DWORD_SIZE = 4;
- if (data.Length < index + 4)
+ if (data.Length < index + DWORD_SIZE)
{
throw new ArgumentException(
- String.Format("Not enough bytes for DWORD: need {0}, got {1}", index + 4, data.Length), "data");
+ String.Format("Not enough bytes for DWORD: need {0}, got {1}", index + DWORD_SIZE, data.Length),
+ "data"
+ );
}
- for (Byte i = 0; i < 4; ++i)
+ for (var i = 0; i < DWORD_SIZE; ++i)
{
result |= (UInt32) data[i + index] << (8 * i);
}
Modified: DebuggerCommand.cs
===================================================================
--- DebuggerCommand.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ DebuggerCommand.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -4,8 +4,6 @@
// Licensed under the GNU General Public License, Version 3 (GPLv3).
// See LICENSE.txt for details.
-using System;
-
namespace bugreport
{
public class DebuggerCommand
Modified: DebuggerView.cs
===================================================================
--- DebuggerView.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ DebuggerView.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -18,22 +18,22 @@
this.interactive = interactive;
}
- public void printInfo(object sender, EmulationEventArgs e)
+ public void PrintInfo(object sender, EmulationEventArgs emulationEvent)
{
- var address = getEffectiveAddressFor(e);
+ var address = GetEffectiveAddressFor(emulationEvent);
Console.Write(address + ":");
Console.Write("\t");
- var code = getCodeFor(e);
- printOpcodeInfo(code);
+ var code = GetCodeFor(emulationEvent);
+ PrintOpcodeInfoFor(code);
Console.WriteLine(state.Registers);
Console.WriteLine();
- handleInputIfNecessary();
+ HandleInputIfNecessary();
}
- private void handleInputIfNecessary()
+ private void HandleInputIfNecessary()
{
if (!interactive) return;
@@ -42,7 +42,7 @@
while (!enterPressed)
{
- var input = getInput();
+ var input = GetInput();
var command = new DebuggerCommand(input);
if (command.IsEnter)
{
@@ -52,15 +52,15 @@
if (command.IsStackPrint)
{
- printStackFor(state);
+ PrintStackFor(state);
continue;
}
if (command.IsDisassemble)
{
var hex = input.Substring("disasm".Length + 1);
- var code = DumpFileParser.getByteArrayFromHexString(hex);
- printOpcodeInfo(code);
+ var code = DumpFileParser.GetByteArrayFor(hex);
+ PrintOpcodeInfoFor(code);
continue;
}
@@ -73,7 +73,7 @@
}
}
- private void printOpcodeInfo(byte[] code)
+ private void PrintOpcodeInfoFor(byte[] code)
{
foreach (var codeByte in code)
{
@@ -97,32 +97,32 @@
Console.Write("\t");
}
- var encoding = OpcodeFormatter.GetEncoding(code);
+ var encoding = OpcodeFormatter.GetEncodingFor(code);
Console.Write("\t");
Console.WriteLine(encoding);
}
- private static Byte[] getCodeFor(EmulationEventArgs e)
+ private static Byte[] GetCodeFor(EmulationEventArgs e)
{
var code = new Byte[e.Code.Count];
e.Code.CopyTo(code, 0);
return code;
}
- private string getEffectiveAddressFor(EmulationEventArgs e)
+ private string GetEffectiveAddressFor(EmulationEventArgs e)
{
state = e.MachineState;
var address = String.Format("{0:x8}", state.InstructionPointer);
return address;
}
- private string getInput()
+ private string GetInput()
{
Console.Write("0x{0:x8} > ", state.InstructionPointer);
return Console.ReadLine();
}
- private static void printStackFor(MachineState state)
+ private static void PrintStackFor(MachineState state)
{
var esp = state.Registers[RegisterName.ESP];
Modified: DumpFileParser.cs
===================================================================
--- DumpFileParser.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ DumpFileParser.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -23,15 +23,14 @@
Byte[] GetBytes();
}
- public sealed class DumpFileParser : IParsable, IDisposable
+ public sealed class DumpFileParser : IParsable,
+ IDisposable
{
private readonly List<ReportItem> expectedReportItems;
private readonly String functionNameToParse = "main";
private readonly List<Byte[]> opcodeList;
private readonly StreamReader reader;
private readonly Stream stream;
- private UInt32 baseAddress;
- private UInt32 entryPointAddress;
private Boolean inTextSection;
public DumpFileParser(Stream stream, String functionNameToParse)
@@ -41,7 +40,7 @@
this.stream.Position = 0;
reader = new StreamReader(this.stream);
expectedReportItems = new List<ReportItem>();
- opcodeList = parse();
+ opcodeList = Parse();
}
#region IDisposable Members
@@ -63,15 +62,9 @@
get { return expectedReportItems.AsReadOnly(); }
}
- public UInt32 BaseAddress
- {
- get { return baseAddress; }
- }
+ public UInt32 BaseAddress { get; private set; }
- public UInt32 EntryPointAddress
- {
- get { return entryPointAddress; }
- }
+ public UInt32 EntryPointAddress { get; private set; }
public Byte[] GetBytes()
{
@@ -103,7 +96,7 @@
#endregion
- public static Byte[] getByteArrayFromHexString(String hex)
+ public static Byte[] GetByteArrayFor(String hex)
{
var hexStrings = hex.Split(new[] {' '});
@@ -117,13 +110,13 @@
return hexBytes;
}
- private static UInt32 getAddressForLine(String line)
+ private static UInt32 GetAddressFrom(String line)
{
var address = line.Substring(0, 8);
return UInt32.Parse(address, NumberStyles.HexNumber);
}
- private static String getHexWithSpaces(String line)
+ private static String GetHexWithSpacesFrom(String line)
{
var colonIndex = line.IndexOf(':');
@@ -142,7 +135,8 @@
var spaceTabIndex = afterColonToEnd.IndexOf(" \t", StringComparison.Ordinal);
Int32 endOfHexIndex;
- if (doubleSpaceIndex >= 0 && spaceTabIndex >= 0)
+ if (doubleSpaceIndex >= 0 &&
+ spaceTabIndex >= 0)
{
endOfHexIndex = doubleSpaceIndex < spaceTabIndex ? doubleSpaceIndex : spaceTabIndex;
}
@@ -161,31 +155,31 @@
return hexString;
}
- private static Byte[] getHexFromString(String line)
+ private static Byte[] GetHexFrom(String line)
{
if (line.Trim().Length == 0)
{
return null;
}
- var hex = getHexWithSpaces(line);
+ var hex = GetHexWithSpacesFrom(line);
if (null == hex)
{
return null;
}
- var hexBytes = getByteArrayFromHexString(hex);
+ var hexBytes = GetByteArrayFor(hex);
return hexBytes;
}
- private static Boolean hasAnnotation(String line)
+ private static Boolean HasAnnotation(String line)
{
return line.Contains("//<OutOfBoundsMemoryAccess ");
}
- private static ReportItem getAnnotation(String line)
+ private static ReportItem GetAnnotationFrom(String line)
{
var locationIndex = line.IndexOf("=", StringComparison.Ordinal) + 1;
var location = UInt32.Parse(line.Substring(locationIndex + "/>".Length, 8), NumberStyles.HexNumber);
@@ -195,43 +189,47 @@
return new ReportItem(location, exploitable);
}
- private void updateMainInfo(String line)
+ private void UpdateMainInfoFrom(String line)
{
- if (String.IsNullOrEmpty(line) || line[0] < '0' || line[0] > '7') return;
+ if (String.IsNullOrEmpty(line) || line[0] < '0' ||
+ line[0] > '7')
+ {
+ return;
+ }
if (line.Contains("<_start>:"))
{
- baseAddress = getAddressForLine(line);
+ BaseAddress = GetAddressFrom(line);
inTextSection = true;
}
if (line.Contains("<" + functionNameToParse + ">:"))
{
- entryPointAddress = getAddressForLine(line);
+ EntryPointAddress = GetAddressFrom(line);
}
}
- private List<Byte[]> parse()
+ private List<Byte[]> Parse()
{
var opcodes = new List<Byte[]>();
while (!reader.EndOfStream)
{
var currentLine = reader.ReadLine();
- if (hasAnnotation(currentLine))
+ if (HasAnnotation(currentLine))
{
- var item = getAnnotation(currentLine);
+ var item = GetAnnotationFrom(currentLine);
expectedReportItems.Add(item);
}
- updateMainInfo(currentLine);
+ UpdateMainInfoFrom(currentLine);
if (inTextSection)
{
- var opcode = getHexFromString(currentLine);
+ var opcode = GetHexFrom(currentLine);
if (opcode != null)
{
- opcodes.Add(getHexFromString(currentLine));
+ opcodes.Add(GetHexFrom(currentLine));
}
}
}
Modified: DumpFileParserTest.cs
===================================================================
--- DumpFileParserTest.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ DumpFileParserTest.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -27,7 +27,10 @@
[TearDown]
public void TearDown()
{
- if (parser == null) return;
+ if (parser == null)
+ {
+ return;
+ }
parser.Dispose();
parser = null;
@@ -37,16 +40,12 @@
[TestFixture]
public class WithNothingElseTest : DumpFileParserFixture
{
- #region Setup/Teardown
-
[SetUp]
public override void SetUp()
{
base.SetUp();
}
- #endregion
-
[Test]
public void EmptyLine()
{
Modified: ElfFileParser.cs
===================================================================
--- ElfFileParser.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ ElfFileParser.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -11,7 +11,8 @@
namespace bugreport
{
- public sealed class ElfFileParser : IParsable, IDisposable
+ public sealed class ElfFileParser : IParsable,
+ IDisposable
{
private readonly Stream stream;
private readonly Byte[] textData;
@@ -22,8 +23,6 @@
textData = new Byte[stream.Length];
}
- #region IDisposable Members
-
public void Dispose()
{
if (null != stream)
@@ -32,10 +31,6 @@
}
}
- #endregion
-
- #region IParsable Members
-
public UInt32 BaseAddress
{
get { return 0x080482e0; }
@@ -57,7 +52,5 @@
stream.Read(textData, 0, (Int32) (stream.Length - stream.Position));
return textData;
}
-
- #endregion
}
}
\ No newline at end of file
Modified: MachineState.cs
===================================================================
--- MachineState.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ MachineState.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -169,21 +169,21 @@
return newState;
}
- public MachineState DoOperation(OperatorEffect _operatorEffect, AbstractValue _offset)
+ public MachineState DoOperation(OperatorEffect operatorEffect, AbstractValue offset)
{
- if (_offset.IsPointer)
+ if (offset.IsPointer)
{
throw new ArgumentException("_offset pointer not supported.");
}
var newState = new MachineState(this);
- switch (_operatorEffect)
+ switch (operatorEffect)
{
case OperatorEffect.Jnz:
{
if (!newState.zeroFlag)
{
- newState.instructionPointer += _offset.Value;
+ newState.instructionPointer += offset.Value;
}
break;
@@ -192,23 +192,23 @@
default:
{
throw new ArgumentException(
- String.Format("Unsupported OperatorEffect: {0}", _operatorEffect), "_operatorEffect");
+ String.Format("Unsupported OperatorEffect: {0}", operatorEffect), "operatorEffect");
}
}
return newState;
}
- public MachineState DoOperation(UInt32 offset, OperatorEffect _operatorEffect, AbstractValue rhs)
+ public MachineState DoOperation(UInt32 offset, OperatorEffect operatorEffect, AbstractValue rhs)
{
var newState = new MachineState(this);
- switch (_operatorEffect)
+ switch (operatorEffect)
{
case OperatorEffect.Assignment:
{
newState.dataSegment[offset] =
- DoOperation(newState.dataSegment[offset], _operatorEffect, rhs).Value;
+ DoOperation(newState.dataSegment[offset], operatorEffect, rhs).Value;
break;
}
}
@@ -216,16 +216,16 @@
return newState;
}
- public MachineState DoOperation(RegisterName lhs, Int32 index, OperatorEffect _operatorEffect, AbstractValue rhs)
+ public MachineState DoOperation(RegisterName lhs, Int32 index, OperatorEffect operatorEffect, AbstractValue rhs)
{
var newState = new MachineState(this);
- switch (_operatorEffect)
+ switch (operatorEffect)
{
case OperatorEffect.Assignment:
case OperatorEffect.Cmp:
{
- var result = 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;
@@ -235,18 +235,19 @@
return newState;
}
- public MachineState DoOperation(RegisterName lhs, OperatorEffect _operatorEffect, AbstractValue rhs)
+ public MachineState DoOperation(RegisterName lhs, OperatorEffect operatorEffect, AbstractValue rhs)
{
var newState = new MachineState(this);
- if (Registers[lhs].IsPointer && _operatorEffect != OperatorEffect.Assignment)
+ if (Registers[lhs].IsPointer &&
+ operatorEffect != OperatorEffect.Assignment)
{
- var newBuffer = Registers[lhs].PointsTo.DoOperation(_operatorEffect, rhs);
+ var newBuffer = Registers[lhs].PointsTo.DoOperation(operatorEffect, rhs);
newState.Registers[lhs] = new AbstractValue(newBuffer);
}
else
{
- var result = DoOperation(Registers[lhs], _operatorEffect, rhs);
+ var result = DoOperation(Registers[lhs], operatorEffect, rhs);
newState.Registers[lhs] = result.Value;
newState.ZeroFlag = result.ZeroFlag;
}
@@ -254,18 +255,19 @@
return newState;
}
- public MachineState DoOperation(RegisterName lhs, OperatorEffect _operatorEffect, RegisterName rhs)
+ public MachineState DoOperation(RegisterName lhs, OperatorEffect operatorEffect, RegisterName rhs)
{
var newState = new MachineState(this);
- var result = 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;
}
- private static OperationResult DoOperation(AbstractValue lhs, OperatorEffect _operatorEffect, AbstractValue rhs)
+ private static OperationResult DoOperation(AbstractValue lhs, OperatorEffect operatorEffect, AbstractValue rhs)
{
- if (rhs.IsPointer && _operatorEffect != OperatorEffect.Assignment)
+ if (rhs.IsPointer &&
+ operatorEffect != OperatorEffect.Assignment)
{
throw new ArgumentException("rhs pointer only supported for OperatorEffect.Assignment.");
}
@@ -273,12 +275,13 @@
var result = new OperationResult();
AbstractValue totalValue;
- if (_operatorEffect == OperatorEffect.Assignment)
+ if (operatorEffect == OperatorEffect.Assignment)
{
var newValue = new AbstractValue(rhs);
- if (rhs.IsInitialized && rhs.IsOOB)
+ if (rhs.IsInitialized &&
+ rhs.IsOutOfBounds)
{
- newValue.IsOOB = true;
+ newValue.IsOutOfBounds = true;
}
result.Value = newValue;
@@ -286,7 +289,7 @@
return result;
}
- if (_operatorEffect == OperatorEffect.Cmp)
+ if (operatorEffect == OperatorEffect.Cmp)
{
result.ZeroFlag = (lhs.Value - rhs.Value) == 0;
@@ -297,15 +300,16 @@
if (lhs.IsPointer)
{
- var newBuffer = lhs.PointsTo.DoOperation(_operatorEffect, rhs);
+ var newBuffer = lhs.PointsTo.DoOperation(operatorEffect, rhs);
result.Value = new AbstractValue(newBuffer);
return result;
}
- var total = getCalculatedValue(lhs.Value, _operatorEffect, rhs.Value);
+ var total = CalculateValueFor(lhs.Value, operatorEffect, rhs.Value);
totalValue = new AbstractValue(total);
- if (lhs.IsTainted || rhs.IsTainted)
+ if (lhs.IsTainted ||
+ rhs.IsTainted)
{
totalValue = totalValue.AddTaint();
}
@@ -314,7 +318,7 @@
return result;
}
- private static UInt32 getCalculatedValue(UInt32 lhs, OperatorEffect operatorEffect, UInt32 rhs)
+ private static UInt32 CalculateValueFor(UInt32 lhs, OperatorEffect operatorEffect, UInt32 rhs)
{
switch (operatorEffect)
{
Modified: MachineStateTest.cs
===================================================================
--- MachineStateTest.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ MachineStateTest.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -75,10 +75,13 @@
[Test]
public void AssignmentRetainsOOB()
{
- var oob = new AbstractValue(1) {IsOOB = true};
+ var oob = new AbstractValue(1)
+ {
+ IsOutOfBounds = true
+ };
state = state.DoOperation(RegisterName.EAX, OperatorEffect.Assignment, oob);
- Assert.IsTrue(eax.IsOOB);
+ Assert.IsTrue(eax.IsOutOfBounds);
}
[Test]
@@ -258,6 +261,18 @@
}
[Test]
+ public void PushTwiceThenManuallyAdjustStackThenAssignToEbp()
+ {
+ AbstractValue[] buffer = AbstractValue.GetNewBuffer(0x20);
+ esp = new AbstractValue(buffer);
+ state = state.PushOntoStack(one);
+ state = state.PushOntoStack(two);
+
+ state = state.DoOperation(RegisterName.ESP, OperatorEffect.Sub, new AbstractValue(0x4));
+ Assert.AreEqual(one, state.TopOfStack);
+ }
+
+ [Test]
public void Shr()
{
eax = new AbstractValue(0x8).AddTaint();
Modified: Main.cs
===================================================================
--- Main.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ Main.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -21,18 +21,18 @@
if (arguments.Length < 1)
{
- printUsage();
+ PrintUsage();
return;
}
try
{
- Options.ParseArguments(arguments);
+ Options.ParseArgumentsFrom(arguments);
}
catch (ArgumentException e)
{
Console.WriteLine(e.Message);
- printUsage();
+ PrintUsage();
Environment.Exit(1);
}
@@ -42,7 +42,7 @@
Environment.Exit(1);
}
- analyzeFiles(Options.Filenames, Options.IsTracing, Options.IsDebugging);
+ AnalyzeFiles(Options.Filenames, Options.IsTracing, Options.IsDebugging);
if (analyzer.ExpectedReportItems.Count == 0 ||
(analyzer.ExpectedReportItems.Count == analyzer.ActualReportItems.Count))
@@ -56,9 +56,9 @@
Environment.Exit(2);
}
- private static void analyzeFiles(IEnumerable<string> _fileNames, Boolean _isTracing, Boolean _isDebugging)
+ private static void AnalyzeFiles(IEnumerable<string> fileNames, Boolean withTracing, Boolean withDebugging)
{
- foreach (var fileName in _fileNames)
+ foreach (var fileName in fileNames)
{
Console.WriteLine();
Console.WriteLine("Interpreting file: " + fileName);
@@ -80,18 +80,18 @@
IParsable parser = new ElfFileParser(fileStream);
analyzer = new Analyzer(parser);
- analyzer.OnReport += printReportItem;
+ analyzer.OnReport += PrintReportItem;
- if (_isTracing)
+ if (withTracing)
{
- analyzer.OnEmulationComplete += new DebuggerView(_isDebugging).printInfo;
+ analyzer.OnEmulationComplete += new DebuggerView(withDebugging).PrintInfo;
}
analyzer.Run();
}
}
- private static void printReportItem(object sender, ReportEventArgs e)
+ private static void PrintReportItem(object sender, ReportEventArgs e)
{
var item = e.ReportItem;
@@ -106,7 +106,7 @@
Console.WriteLine();
}
- private static void printUsage()
+ private static void PrintUsage()
{
Console.WriteLine("Usage: bugreport.exe [--trace] file.test");
}
Modified: MainTest.cs
===================================================================
--- MainTest.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ MainTest.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -22,7 +22,7 @@
private readonly String testRoot = Directory.GetCurrentDirectory() + @"/../../tests/simple/heap/";
private readonly String testDataFile = Directory.GetCurrentDirectory() + @"/../../systemTestsList.txt";
- private static void waitForAnalysisToFinish(Process analysisProcess)
+ private static void WaitForAnalysisToFinish(Process analysisProcess)
{
var maximumTimeAllowed = TimeSpan.FromSeconds(10);
while (!analysisProcess.HasExited && (DateTime.Now - analysisProcess.StartTime < maximumTimeAllowed))
@@ -31,7 +31,7 @@
}
}
- private static List<String> getOutputFromAnalysis(Process analysisProcess)
+ private static List<String> GetOutputFrom(Process analysisProcess)
{
var messages = new List<String>();
@@ -46,26 +46,31 @@
return messages;
}
- private static Process getAnalysisProcessForFileName(String fileName)
+ private static Process GetAnalysisProcessFor(String fileName)
{
- var analysisProcess = new Process();
- analysisProcess.StartInfo.FileName = "bugreport.exe";
- analysisProcess.StartInfo.Arguments = "\"" + fileName + "\"";
- analysisProcess.StartInfo.RedirectStandardOutput = true;
- analysisProcess.StartInfo.UseShellExecute = false;
- analysisProcess.StartInfo.CreateNoWindow = false;
+ var analysisProcess = new Process
+ {
+ StartInfo =
+ {
+ FileName = "bugreport.exe",
+ Arguments = "\"" + fileName + "\"",
+ RedirectStandardOutput = true,
+ UseShellExecute = false,
+ CreateNoWindow = false
+ }
+ };
return analysisProcess;
}
- private static List<String> getOutputForFilename(String fileName)
+ private static List<String> GetOutputFor(String fileName)
{
- var analysisProcess = getAnalysisProcessForFileName(fileName);
+ var analysisProcess = GetAnalysisProcessFor(fileName);
analysisProcess.Start();
- waitForAnalysisToFinish(analysisProcess);
+ WaitForAnalysisToFinish(analysisProcess);
- return getOutputFromAnalysis(analysisProcess);
+ return GetOutputFrom(analysisProcess);
}
[Test]
@@ -88,7 +93,7 @@
Assert.IsTrue(File.Exists(fileName), fileName + " does not exist. Fix paths in test data?");
- var messages = getOutputForFilename(fileName);
+ var messages = GetOutputFor(fileName);
try
{
Modified: ModRM.cs
===================================================================
--- ModRM.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ ModRM.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -12,60 +12,60 @@
{
private static readonly Opcode opcode = new X86Opcode();
- private static Byte GetRM(Byte modrm)
+ private static Byte GetRMFor(Byte modrm)
{
return (Byte) (modrm & 7);
}
- public static RegisterName GetEv(Byte[] code)
+ public static RegisterName GetEvFor(Byte[] code)
{
if (HasSIB(code))
{
throw new InvalidOperationException("For ModRM that specifies SIB byte, usage of GetEv is invalid.");
}
- var modRM = getModRM(code);
+ var modRM = GetModRMFor(code);
return (RegisterName) (modRM & 7);
}
- internal static RegisterName GetGv(Byte[] code)
+ internal static RegisterName GetGvFor(Byte[] code)
{
- var modRM = getModRM(code);
+ var modRM = GetModRMFor(code);
return (RegisterName) ((modRM >> 3) & 7);
}
- internal static Byte GetOpcodeGroupIndex(Byte[] _code)
+ internal static Byte GetOpcodeGroupIndexFor(Byte[] code)
{
- var modRM = getModRM(_code);
+ var modRM = GetModRMFor(code);
return (Byte) ((modRM >> 3) & 7);
}
- public static Boolean HasIndex(Byte[] _code)
+ public static Boolean HasIndex(Byte[] code)
{
- var modRM = getModRM(_code);
- var mod = getMod(modRM);
+ var modRM = GetModRMFor(code);
+ var mod = GetModFor(modRM);
return mod == 1 || mod == 2;
}
- public static Byte GetIndex(Byte[] _code)
+ public static Byte GetIndexFor(Byte[] code)
{
- if (!HasIndex(_code))
+ if (!HasIndex(code))
{
throw new InvalidOperationException(
- "For ModRM that does not specify an index, usage of GetIndex is invalid."
+ "For ModRM that does not specify an index, usage of GetIndexFor is invalid."
);
}
- UInt32 modRMIndex = opcode.GetOpcodeLength(_code);
- var modRM = getModRM(_code);
- var mod = getMod(modRM);
+ UInt32 modRMIndex = opcode.GetOpcodeLengthFor(code);
+ var modRM = GetModRMFor(code);
+ var mod = GetModFor(modRM);
switch (mod)
{
case 1:
{
- return _code[modRMIndex + 1];
+ return code[modRMIndex + 1];
}
default:
@@ -75,43 +75,44 @@
}
}
- public static Boolean IsEffectiveAddressDereferenced(Byte[] _code)
+ public static Boolean IsEffectiveAddressDereferenced(Byte[] code)
{
- var modRM = getModRM(_code);
+ var modRM = GetModRMFor(code);
- return !(getMod(modRM) == 3);
+ return !(GetModFor(modRM) == 3);
}
- public static Boolean HasOffset(Byte[] _code)
+ public static Boolean HasOffset(Byte[] code)
{
- if (HasSIB(_code))
+ if (HasSIB(code))
{
return false;
}
- var modRM = getModRM(_code);
- return GetRM(modRM) == 5 && getMod(modRM) == 0;
+ var modRM = GetModRMFor(code);
+ return GetRMFor(modRM) == 5 && GetModFor(modRM) == 0;
}
- public static UInt32 GetOffset(Byte[] code)
+ public static UInt32 GetOffsetFor(Byte[] code)
{
- var offsetBeginsAt = opcode.GetOpcodeLength(code);
+ var offsetBeginsAt = opcode.GetOpcodeLengthFor(code);
offsetBeginsAt++; // for modRM byte
return BitMath.BytesToDword(code, offsetBeginsAt);
}
- public static Boolean HasSIB(Byte[] _code)
+ public static Boolean HasSIB(Byte[] code)
{
- var modRM = getModRM(_code);
+ var modRM = GetModRMFor(code);
- return GetRM(modRM) == 4 && IsEffectiveAddressDereferenced(_code);
+ return GetRMFor(modRM) == 4 && IsEffectiveAddressDereferenced(code);
}
public static Boolean IsEvDword(Byte[] code)
{
- var modRM = getModRM(code);
- if ((getMod(modRM) == 0) && (GetRM(modRM) == 5))
+ var modRM = GetModRMFor(code);
+ if ((GetModFor(modRM) == 0) &&
+ (GetRMFor(modRM) == 5))
{
return true;
}
@@ -119,19 +120,19 @@
return false;
}
- private static Byte getModRM(Byte[] _code)
+ private static Byte GetModRMFor(Byte[] code)
{
- Int32 modRMIndex = opcode.GetOpcodeLength(_code);
+ Int32 modRMIndex = opcode.GetOpcodeLengthFor(code);
- if (modRMIndex > _code.Length - 1)
+ if (modRMIndex > code.Length - 1)
{
- throw new InvalidOperationException("No ModRM present: " + _code[0]);
+ throw new InvalidOperationException("No ModRM present: " + code[0]);
}
- return _code[modRMIndex];
+ return code[modRMIndex];
}
- private static Byte getMod(Byte modrm)
+ private static Byte GetModFor(Byte modrm)
{
return (Byte) ((modrm >> 6) & 3);
}
Modified: ModRMTest.cs
===================================================================
--- ModRMTest.cs 2009-02-12 04:43:29 UTC (rev 169)
+++ ModRMTest.cs 2009-09-11 22:28:12 UTC (rev 170)
@@ -19,8 +19,8 @@
{
// mov eax,DWORD PTR [eax]
code = new Byte[] {0x8b, 0x00};
- Assert.AreEqual(RegisterName.EAX, ModRM.GetEv(code));
- Assert.AreEqual(RegisterName.EAX, ModRM.GetGv(code));
+ Assert.AreEqual(RegisterName.EAX, ModRM.GetEvFor(code));
+ Assert.AreEqual(RegisterName.EAX, ModRM.GetGvFor(code));
Assert.IsFalse(ModRM.HasIndex(code));
Assert.IsTrue(ModRM.IsEffectiveAddressDereferenced(code));
}
@@ -29,21 +29,21 @@
[ExpectedException(typeof (NotImplementedException))]
public void EaxEbpPlusDword12()
{
- var index = 0x0c;
- code = new Byte[] {0x8b, 0x85, (Byte) index, 0x00, 0x00, 0x00};
+ const int INDEX = 0x0c;
+ code = new Byte[] {0x8b, 0x85, INDEX, 0x00, 0x00, 0x00};
Assert.IsTrue(ModRM.HasIndex(code));
- Assert.AreEqual(index, ModRM.GetIndex(code));
+ Assert.AreEqual(INDEX, ModRM.GetIndexFor(code));
}
[Test]
public void EaxEbpPlusSByte12()
{
// mov eax,DWORD PTR [ebp+index]
- var index = 0x0c;
- code = new Byte[] {0x8b, 0x45, (Byte) index};
- Assert.AreEqual(RegisterName.EBP, ModRM.GetEv(code));
- Assert.AreEqual(RegisterName.EAX, ModRM.GetGv(code));
- Assert.AreEqual(index, ModRM.GetIndex(code));
+ const int INDEX = 0x0c;
+ code = new Byte[] {0x8b, 0x45, INDEX};
+ Assert.AreEqual(RegisterName.EBP, ModRM.GetEvFor(code));
+ Assert.AreEqual(RegisterName.EAX, ModRM.GetGvFor(code));
+ Assert.AreEqual(INDEX, ModRM.GetIndexFor(code));
}
[Test]
@@ -51,9 +51,9 @@
{
// mov eax,DWORD PTR [ebx-4]
code = new Byte[] {0x8b, 0x43, 0xfc};
- Assert.AreEqual(RegisterName.EBX, ModRM.GetEv(code));
- Assert.AreEqual(RegisterName.EAX, ModRM.GetGv(code));
- Assert.AreEqual(0xfc, ModRM.GetIndex(code));
+ Assert.AreEqual(RegisterName.EBX, ModRM.GetEvFor(code));
+ Assert.AreEqual(RegisterName.EAX, ModRM.GetGvFor(code));
+ Assert.AreEqual(0xfc, ModRM.GetIndexFor(code));
}
[Test]
@@ -61,10 +61,10 @@
{
// mov ebx,DWORD PTR [ebp-12]
code = new Byte[] {0x8b, 0x5d, 0xf4};
- Assert.AreEqual(RegisterName.EBP, ModRM.GetEv(code));
- Assert.AreEqual(RegisterName.EBX, ModRM.GetGv(code));
+ Assert.AreEqual(RegisterName.EBP, ModRM.GetEvFor(code));
+ Assert.AreEqual(RegisterName.EBX, ModRM.GetGvFor(code));
Assert.IsFalse(ModRM.HasSIB(code));
- Assert.AreEqual(0xf4, ModRM.GetIndex(code));
+ Assert.AreEqual(0xf4, ModRM.GetIndexFor(code));
}
[Test]
@@ -72,9 +72,9 @@
{
// mov ebx,DWORD PTR [esp]
code = new Byte[] {0x8b, 0x1c, 0x24};
- //// Assert.AreEqual(RegisterName.ESP, ModRM.GetEv(code));
+ //// Assert.AreEqual(RegisterName.ESP, ModRM.GetEvFor(code));
Assert.IsTrue(ModRM.HasSIB(code));
- Assert.AreEqual(RegisterName.EBX, ModRM.GetGv(code));
+ Assert.AreEqual(RegisterName.EBX, ModRM.GetGvFor(code));
Assert.IsFalse(ModRM.HasIndex(code));
}
@@ -83,9 +83,9 @@
{
// mov edi,DWORD PTR [ebp-4]
code = new Byte[] {0x8b, 0x7d, 0xfc};
- Assert.AreEqual(RegisterName.EBP, ModRM.GetEv(code));
- Assert.AreEqual(RegisterName.EDI, ModRM.GetGv(code));
- Assert.AreEqual(0xfc, ModRM.GetIndex(code));
+ Assert.AreEqual(RegisterName.EBP, ModRM.GetEvFor(code));
+ Assert.AreEqual(RegisterName.EDI, ModRM.GetGvFor(code));
+ Assert.AreEqual(0xfc, ModRM.GetIndexFor(code));
}
[Test]
@@ -93,9 +93,9 @@
{
// mov esi,DWORD PTR [ebp-8]
code = new Byte[] {0x8b, 0x75, 0xf8};
- Assert.AreEqual(RegisterName.EBP, ModRM.GetEv(code));
- Assert.AreEqual(RegisterName.ESI, ModRM.GetGv(code));
- Assert.AreEqual(0xf8, ModRM.GetIndex(code));
+ Assert.AreEqual(RegisterName.EBP, ModRM.GetEvFor(code));
+ Assert.AreEqual(RegisterName.ESI, ModRM.GetGvFor(code));
+ Assert.AreEqual(0xf8, ModRM.GetIndexFor(code));
}
[Test]
@@ -104,7 +104,7 @@
{
code = new Byte[] {0xc7, 0x04, 0x24, 0x10, 0x00, 0x00, 0x00};
Assert.IsTrue(ModRM.HasSIB(code));
- ModRM.GetEv(code);
+ ModRM.GetEvFor(code);
}
[Test]
@@ -113,7 +113,7 @@
{
code = new Byte[] {0x89, 0xe5};
Assert.IsFalse(ModRM.HasIndex(code));
- ModRM.GetIndex(code);
+ ModRM.GetIndexFor(code);
}
[Test]
@@ -121,7 +1...
[truncated message content] |