-
Notifications
You must be signed in to change notification settings - Fork 231
/
disasm.c
137 lines (94 loc) · 3.01 KB
/
disasm.c
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*++
Copyright (c) 2012 Minoca Corp.
This file is licensed under the terms of the GNU General Public License
version 3. Alternative licensing terms are available. Contact
info@minocacorp.com for details. See the LICENSE file at the root of this
project for complete licensing information.
Module Name:
disasm.c
Abstract:
This module contains routines for disassembling x86 binary code.
Author:
Evan Green 21-Jun-2012
Environment:
Debugging client
--*/
//
// ------------------------------------------------------------------- Includes
//
#include <minoca/lib/types.h>
#include "disasm.h"
#include <stdio.h>
#include <string.h>
#include <assert.h>
//
// ---------------------------------------------------------------- Definitions
//
//
// ----------------------------------------------- Internal Function Prototypes
//
//
// ------------------------------------------------------ Data Type Definitions
//
//
// ------------------------------------------------------------------ Functions
//
BOOL
DbgDisassemble (
ULONGLONG InstructionPointer,
PBYTE InstructionStream,
PSTR Buffer,
ULONG BufferLength,
PDISASSEMBLED_INSTRUCTION Disassembly,
MACHINE_LANGUAGE Language
)
/*++
Routine Description:
This routine decodes one instruction from a binary instruction stream into
a human readable form.
Arguments:
InstructionPointer - Supplies the instruction pointer for the start of the
instruction stream.
InstructionStream - Supplies a pointer to the binary instruction stream.
Buffer - Supplies a pointer to the buffer where the human
readable strings will be printed. This buffer must be allocated by the
caller.
BufferLength - Supplies the length of the supplied buffer.
Disassembly - Supplies a pointer to the structure that will receive
information about the instruction.
Language - Supplies the machine language to interpret this stream as.
Return Value:
TRUE on success.
FALSE if the instruction was unknown.
--*/
{
BOOL Result;
switch (Language) {
case MachineLanguageX86:
case MachineLanguageX64:
Result = DbgpX86Disassemble(InstructionPointer,
InstructionStream,
Buffer,
BufferLength,
Disassembly,
Language);
break;
case MachineLanguageArm:
case MachineLanguageThumb2:
Result = DbgpArmDisassemble(InstructionPointer,
InstructionStream,
Buffer,
BufferLength,
Disassembly,
Language);
break;
default:
Result = FALSE;
goto DisassembleEnd;
}
DisassembleEnd:
return Result;
}
//
// --------------------------------------------------------- Internal Functions
//