-
Notifications
You must be signed in to change notification settings - Fork 0
/
OpcodeFormatterTest.cs
98 lines (86 loc) · 3.55 KB
/
OpcodeFormatterTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// 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 OpcodeFormatterTest
{
private Byte[] code;
[Test]
public void JzImmediate()
{
code = new Byte[] {0xe8, 0xb9, 0xff, 0xff, 0xff};
Assert.AreEqual("call", OpcodeFormatter.GetInstructionName(code));
Assert.AreEqual("0x0804837c", OpcodeFormatter.GetOperands(code, 0x080483be));
Assert.AreEqual("(Jz)", OpcodeFormatter.GetEncodingFor(code));
}
[Test]
public void LeaEdxEaxPlus16()
{
code = new Byte[] {0x8d, 0x50, 0x10};
Assert.AreEqual("lea", OpcodeFormatter.GetInstructionName(code));
Assert.AreEqual("edx, [eax+16]", OpcodeFormatter.GetOperands(code, 0));
}
[Test]
public void MovEaxZero()
{
code = new Byte[] {0xb8, 0x00, 0x00, 0x00, 0x00};
Assert.AreEqual("mov", OpcodeFormatter.GetInstructionName(code));
Assert.AreEqual("eax, 0x0", OpcodeFormatter.GetOperands(code, 0));
Assert.AreEqual("(rAxIv)", OpcodeFormatter.GetEncodingFor(code));
}
[Test]
public void MovEbpEsp()
{
code = new Byte[] {0x89, 0xe5};
Assert.AreEqual("mov", OpcodeFormatter.GetInstructionName(code));
Assert.AreEqual("ebp, esp", OpcodeFormatter.GetOperands(code, 0));
Assert.AreEqual("(EvGv)", OpcodeFormatter.GetEncodingFor(code));
}
[Test]
public void MovPtrEaxPlusSixteenZero()
{
code = new Byte[] {0xc6, 0x40, 0x10, 0x00};
Assert.AreEqual("mov", OpcodeFormatter.GetInstructionName(code));
Assert.AreEqual("[eax+16], 0x0", OpcodeFormatter.GetOperands(code, 0));
Assert.AreEqual("(EbIb)", OpcodeFormatter.GetEncodingFor(code));
}
[Test]
public void MovPtrEsp10()
{
code = new Byte[] {0xc7, 0x04, 0x24, 0x10, 0x00, 0x00, 0x00};
Assert.AreEqual("mov", OpcodeFormatter.GetInstructionName(code));
Assert.AreEqual("[esp], 0x10", OpcodeFormatter.GetOperands(code, 0));
Assert.AreEqual("(EvIz)", OpcodeFormatter.GetEncodingFor(code));
}
[Test]
public void MovZxEaxBytePtr()
{
code = new Byte[] {0x0f, 0xb6, 0x05, 0x00, 0x96, 0x04, 0x08};
// TODO: this should actually be movzx
Assert.AreEqual("mov", OpcodeFormatter.GetInstructionName(code));
Assert.AreEqual("eax, [0x8049600]", OpcodeFormatter.GetOperands(code, 0));
}
[Test]
public void PopEbp()
{
code = new Byte[] {0x5d};
Assert.AreEqual("pop", OpcodeFormatter.GetInstructionName(code));
Assert.AreEqual("ebp", OpcodeFormatter.GetOperands(code, 0));
Assert.AreEqual("(rBP)", OpcodeFormatter.GetEncodingFor(code));
}
[Test]
public void PushEbp()
{
code = new Byte[] {0x55};
Assert.AreEqual("push", OpcodeFormatter.GetInstructionName(code));
Assert.AreEqual("ebp", OpcodeFormatter.GetOperands(code, 0));
Assert.AreEqual("(rBP)", OpcodeFormatter.GetEncodingFor(code));
}
}
}