-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathExamplePlugin.Disassembler.cs
59 lines (50 loc) · 1.93 KB
/
ExamplePlugin.Disassembler.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
using System;
using Dotx64Dbg;
public partial class ExamplePlugin : IPlugin, IHotload
{
[Command("DisassembleIP", DebugOnly = true)]
public void DisassembleAtIP(string[] args)
{
var decoder = Decoder.Create();
var ip = Thread.Main.Nip;
var decodedInstr = decoder.Decode(ip);
var instrText = $"Instruction {{\n"
+ $" Text = {decodedInstr},\n"
+ $" Info = {{\n"
+ $" Flags Read = {decodedInstr.FlagsRead}\n"
+ $" Flags Write = {decodedInstr.FlagsWrite}\n"
+ $" }},\n"
+ $" Operands = {{\n";
for(int i = 0; i < 4 ;i++)
{
var op = decodedInstr.GetOperand(i);
if (op.Type == OperandType.None)
break;
var visibility = decodedInstr.GetOperandVisibility(i);
instrText += $" Operand[{i}] = ";
switch (op.Type)
{
case OperandType.Immediate:
var imm = op as Operand.Immediate;
instrText += $"{{ {visibility}, Imm({imm.Value:X}) }},\n";
break;
case OperandType.Register:
var reg = op as Operand.Register;
instrText += $"{{ {visibility}, Reg({reg}) }},\n";
break;
case OperandType.Memory:
var mem = op as Operand.Memory;
instrText += $"{{ {visibility}, Memory {{\n";
instrText += $" Base = {mem.Base},\n";
instrText += $" Index = {mem.Index},\n";
instrText += $" Scale = {mem.Scale}\n";
instrText += $" Disp = {mem.Displacement},\n";
instrText += $" }} }},\n";
break;
}
}
instrText += $" }}\n";
instrText += $"}}";
Console.WriteLine(instrText);
}
}