@@ -76,7 +76,7 @@ let formatterOptions = FormatterOptions(
76
76
77
77
78
78
// disassemble a single method
79
- let disassembleConcreteMethod ( runtime : ClrRuntime ) ( mthinfo : MethodBase ) platform ( writer : TextWriter ) =
79
+ let disassembleConcreteMethod ( runtime : ClrRuntime ) ( mthinfo : MethodBase ) platform showOpcodes ( writer : TextWriter ) =
80
80
81
81
runtime.FlushCachedData()
82
82
let h = mthinfo.MethodHandle
@@ -139,7 +139,13 @@ let disassembleConcreteMethod (runtime: ClrRuntime) (mthinfo: MethodBase) platfo
139
139
// render instructions
140
140
for inst in decoder do
141
141
formatter.Format(& inst, out)
142
- writer.WriteLine $" L%04x {inst.IP - address}: %s {out.ToStringAndReset()}"
142
+ let inst_relative_ip = int <| inst.IP - address
143
+ if showOpcodes then
144
+ let inst_opcode_hex = bytes[ inst_ relative_ ip.. inst_ relative_ ip + inst.Length - 1 ]
145
+ |> Array.fold ( fun hex b -> sprintf " %s %02x " hex b) " "
146
+ writer.WriteLine $" L%04x {inst_relative_ip}: %45s {inst_opcode_hex} %s {out.ToStringAndReset()}"
147
+ else
148
+ writer.WriteLine $" L%04x {inst_relative_ip}: %s {out.ToStringAndReset()}"
143
149
writer.Flush()
144
150
145
151
@@ -153,9 +159,9 @@ let outputGenericMethod (runtime: ClrRuntime) (mthinfo: MethodBase) (writer: Tex
153
159
writer.WriteLine $" ; generic method cannot be jitted. provide explicit types"
154
160
writer.Flush()
155
161
156
- let disassembleMethod runtime ( mthinfo : MethodBase ) platform writer =
162
+ let disassembleMethod runtime ( mthinfo : MethodBase ) platform showOpcodes writer =
157
163
if not mthinfo.IsGenericMethodDefinition && not mthinfo.DeclaringType.IsGenericTypeDefinition then
158
- disassembleConcreteMethod runtime mthinfo platform writer
164
+ disassembleConcreteMethod runtime mthinfo platform showOpcodes writer
159
165
else
160
166
outputGenericMethod runtime mthinfo writer
161
167
@@ -167,7 +173,7 @@ let withRuntime f =
167
173
168
174
169
175
// disassemble assembly as jitted x86/x64 to text writer
170
- let disassemble asmPath ( writer : TextWriter ) platform =
176
+ let disassemble asmPath ( writer : TextWriter ) platform showOpcodes =
171
177
172
178
// attach to self
173
179
withRuntime ( fun runtime ->
@@ -188,13 +194,13 @@ let disassemble asmPath (writer: TextWriter) platform =
188
194
189
195
for mth in getAllMethods ty do
190
196
if mth.DeclaringType <> typeof< obj> then
191
- disassembleMethod runtime mth platform writer
197
+ disassembleMethod runtime mth platform showOpcodes writer
192
198
193
199
194
200
for sty in ty.GetNestedTypes() do
195
201
for mth in getAllMethods sty do
196
202
if mth.DeclaringType <> typeof< obj> then
197
- disassembleMethod runtime mth platform writer
203
+ disassembleMethod runtime mth platform showOpcodes writer
198
204
)
199
205
200
206
/// disassemble assembly as IL to text writer
@@ -205,19 +211,19 @@ let ildasm asmPath writer =
205
211
disass.WriteModuleContents( pe)
206
212
207
213
/// disassemble assembly to writer
208
- let decompile asmPath writer language platform =
214
+ let decompile asmPath writer language platform showOpcodes =
209
215
match language with
210
- | Asm -> disassemble asmPath writer platform
216
+ | Asm -> disassemble asmPath writer platform showOpcodes
211
217
| IL -> ildasm asmPath writer
212
218
213
219
/// disassemble assembly to file
214
- let decompileToFile asmPath outPath language platform =
220
+ let decompileToFile asmPath outPath language platform showOpcodes =
215
221
use w = File.CreateText( outPath)
216
- decompile asmPath w language platform
222
+ decompile asmPath w language platform showOpcodes
217
223
218
224
219
225
/// disassemble assembly to console
220
- let decompileToConsole asmPath language platform =
226
+ let decompileToConsole asmPath language platform showOpcodes =
221
227
use s = Console.OpenStandardOutput()
222
228
use w = new IO.StreamWriter( s)
223
- decompile asmPath w language platform
229
+ decompile asmPath w language platform showOpcodes
0 commit comments