-
Notifications
You must be signed in to change notification settings - Fork 0
/
NativeInstructionExtension.cs
77 lines (69 loc) · 3.15 KB
/
NativeInstructionExtension.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
using Gee.External.Capstone.Arm;
using Gee.External.Capstone.Arm64;
using Gee.External.Capstone.X86;
namespace Gee.External.Capstone {
/// <summary>
/// Native Instruction Extension.
/// </summary>
public static class NativeInstructionExtension {
/// <summary>
/// Convert a Native Instruction to a Dissembled Instruction.
/// </summary>
/// <param name="this">
/// A native instruction.
/// </param>
/// <returns>
/// A dissembled instruction.
/// </returns>
public static Instruction<TArchitectureInstruction, TArchitectureRegister, TArchitectureGroup, TArchitectureDetail> AsInstruction<TArchitectureInstruction, TArchitectureRegister, TArchitectureGroup, TArchitectureDetail>(this NativeInstruction @this) {
var @object = new Instruction<TArchitectureInstruction, TArchitectureRegister, TArchitectureGroup, TArchitectureDetail>();
@object.Address = (long) @this.Address;
@object.Bytes = @this.ManagedBytes;
@object.Mnemonic = @this.ManagedMnemonic;
@object.Operand = @this.ManagedOperand;
return @object;
}
/// <summary>
/// Create an ARM Dissembled Instruction.
/// </summary>
/// <param name="this">
/// A native instruction.
/// </param>
/// <returns>
/// A dissembled instruction.
/// </returns>
public static Instruction<ArmInstruction, ArmRegister, ArmInstructionGroup, ArmInstructionDetail> AsArmInstruction(this NativeInstruction @this) {
var @object = @this.AsInstruction<ArmInstruction, ArmRegister, ArmInstructionGroup, ArmInstructionDetail>();
@object.Id = (ArmInstruction) @this.Id;
return @object;
}
/// <summary>
/// Convert a Native Instruction to a ARM64 Dissembled Instruction.
/// </summary>
/// <param name="this">
/// A native instruction.
/// </param>
/// <returns>
/// A dissembled instruction.
/// </returns>
public static Instruction<Arm64Instruction, Arm64Register, Arm64InstructionGroup, Arm64InstructionDetail> AsArm64Instruction(this NativeInstruction @this) {
var @object = @this.AsInstruction<Arm64Instruction, Arm64Register, Arm64InstructionGroup, Arm64InstructionDetail>();
@object.Id = (Arm64Instruction) @this.Id;
return @object;
}
/// <summary>
/// Convert a Native Instruction to an X86 Dissembled Instruction.
/// </summary>
/// <param name="this">
/// A native instruction.
/// </param>
/// <returns>
/// A dissembled instruction.
/// </returns>
public static Instruction<X86Instruction, X86Register, X86InstructionGroup, X86InstructionDetail> AsX86Instruction(this NativeInstruction @this) {
var @object = @this.AsInstruction<X86Instruction, X86Register, X86InstructionGroup, X86InstructionDetail>();
@object.Id = (X86Instruction) @this.Id;
return @object;
}
}
}