Skip to content

Commit ee0aa20

Browse files
committed
Land rapid7#3013, Metasm update
2 parents 3c2eb29 + 7c5ba3e commit ee0aa20

File tree

209 files changed

+17972
-8408
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

209 files changed

+17972
-8408
lines changed

lib/metasm.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
# Load a slightly tweaked METASM stub
22
require 'metasm/metasm'
3-
4-
# Manually load the classes we need from METASM
5-
require 'metasm/ia32'
6-
require 'metasm/mips'
7-
require 'metasm/exe_format/shellcode'

lib/metasm/.hg_archival.txt

Lines changed: 0 additions & 2 deletions
This file was deleted.

lib/metasm/README

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ Ready-to-use scripts can be found in the samples/ subdirectory, check the
2121
comments in the scripts headers. You can also try the --help argument if
2222
you're feeling lucky.
2323

24+
For more information, check the doc/ subdirectory. The text files can be
25+
compiled to html using the misc/txt2html.rb script.
26+
27+
2428

2529
Here is a short overview of the Metasm internals.
2630

@@ -167,8 +171,8 @@ You can encode/decode an ExeFormat (ie decode sections, imports, headers etc)
167171
Constructor: ExeFormat.decode_file(str), ExeFormat.decode_file_header(str)
168172
Methods: ExeFormat#encode_file(filename), ExeFormat#encode_string
169173

170-
PE and ELF files have a LoadedPE/LoadedELF counterpart, that is able to work
171-
with memory-mmaped versions of those formats (e.g. to debugging running
174+
PE and ELF files have a LoadedPE/LoadedELF counterpart, that are able to work
175+
with memory-mmaped versions of those formats (e.g. to debug running
172176
processes)
173177

174178

@@ -198,27 +202,31 @@ disassembly/patching easily (using LoadedPE/LoadedELF as ExeFormat)
198202

199203
Debugging:
200204

201-
Metasm includes a few interfaces to allow live debugging.
205+
Metasm includes a few interfaces to handle debugging.
202206
The WinOS and LinOS classes offer access to the underlying OS processes (e.g.
203207
OS.current.find_process('foobar') will retrieve a running process with foobar
204208
in its filename ; then process.mem can be used to access its memory.)
205209

206-
The Windows and Linux debugging APIs (x86 only) have a basic ruby interface
207-
(PTrace32, extended in samples/rubstop.rb ; and WinDBG, a simple mapping of the
208-
windows debugging API) ; those will be more worked on/integrated in the future.
210+
The Windows and Linux low-level debugging APIs have a basic ruby interface
211+
(PTrace and WinAPI) ; which are used by the unified high-end Debugger class.
212+
Remote debugging is supported through the GDB server wire protocol.
209213

210-
A linux console debugging interface is available in samples/lindebug.rb ; it
211-
uses a SoftICE-like look and feel.
212-
This interface can talk to a gdb-server through samples/gdbclient.rb ; use
213-
[udp:]<host:port> as target.
214+
High-level debuggers can be created with the following ruby line:
215+
Metasm::OS.current.create_debugger('foo')
214216

215-
The disassembler scripts allow live process interaction by using as target
216-
'live:<pid or part of filename>'.
217+
Only one kind of host debugger class can exist at a time ; to debug multiple
218+
processes, attach to other processes using the existing class. This is due
219+
to the way the OS debugging API works on Windows and Linux.
217220

218-
A generic debugging interface is available, it is defined in metasm/os/main.rb
219-
It may be accessed using the Metasm::OS.current.create_debugger('foo')
221+
The low-level backends are defined in the os/ subdirectory, the front-end is
222+
defined in debug.rb.
220223

221-
It can be viewed in action using the GUI and 'open live' target.
224+
A linux console debugging interface is available in samples/lindebug.rb ; it
225+
uses a (simplified) SoftICE-like look and feel.
226+
It can talk to a gdb-server socket ; use a [udp:]<host:port> target.
227+
228+
The disassembler-gui sample allow live process interaction when using as
229+
target 'live:<pid or part of program name>'.
222230

223231

224232
C Parser:
@@ -236,7 +244,11 @@ It handles all the constructs i am aware of, except hex floats:
236244
- __int8 etc native types
237245
- Label addresses (&&label)
238246
Also note that all those things are parsed, but most of them will fail to
239-
compile on the Ia32 backend (the only one implemented so far.)
247+
compile on the Ia32/X64 backend (the only one implemented so far.)
248+
249+
Parsing C files should be done using an existing ExeFormat, with the
250+
parse_c_file method. This ensures that format-specific macros/ABI are correctly
251+
defined (ex: size of the 'long' type, ABI to pass parameters to functions, etc)
240252

241253
When you parse a C String using C::Parser.parse(text), you receive a Parser
242254
object. It holds a #toplevel field, which is a C::Block, which holds #structs,
@@ -249,15 +261,11 @@ CExpressions...)
249261

250262
A C::Parser may be #precompiled to transform it into a simplified version that
251263
is easier to compile: typedefs are removed, control sequences are transformed
252-
in if () goto ; etc.
264+
into 'if (XX) goto YY;' etc.
253265

254266
To compile a C program, use PE/ELF.compile_c, that will create a C::Parser with
255267
exe-specific macros defined (eg __PE__ or __ELF__).
256268

257-
The prefered way to create a C::Parser is to initialize it with a CPU and the
258-
desired ExeFormat, so that it is
259-
correctly initialized (eg type sizes: is long 4 or 8 bytes? etc) ; and
260-
may define preprocessor macros needed to correctly parse standard headers.
261269
Vendor-specific headers may need to use either #pragma prepare_visualstudio
262270
(to parse the Microsoft Visual Studio headers) or prepare_gcc (for gcc), the
263271
latter may be auto-detected (or may not).

lib/metasm/TODO

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@ List of TODO items, by section, in random order
22

33
Ia32
44
emu fpu
5-
add all sse2 instrs
5+
AVX support
66
realmode
77

88
X86_64
99
decompiler
1010

1111
CPU
12+
Arm
1213
Sparc
1314
Cell
1415

@@ -26,14 +27,14 @@ Assembler
2627
Disasm
2728
DecodedData
2829
Exe decoding generate decodeddata ?
29-
Function-local namespace (esp+12 -> esp+var_42)
30+
Function variable names using stack analysis + ExpressionString
3031
Fix thunk detection (thunk: mov ecx, 42 jmp [iat_thiscall] is not a thunk)
3132
Test with ET_REL style exe
3233
Store stuff out of mem (to handle big binaries)
3334
Better :default usage
3435
good on call eax, but not on <600k instrs> ret
3536
use binary personality ? (uses call vs uses pushret..)
36-
Improve backtrace -> patch di.instr.args exprs
37+
Improve 'backtrace => patch di.instr.args'
3738
path-specific backtracking ( foo: call a ; a: jmp retloc ; bar: call b ; b: jmp retloc ; retloc: ret ; call foo ; ret : last ret trackback should only reach a:)
3839
Decode pseudo/macro-instrs (mips 'li')
3940
Deoptimizer (instr reordering for readability)
@@ -69,6 +70,7 @@ Decompiler
6970
Handle/hide compiler-generated stuff (getip, stack cookie setup/check..)
7071
Handle call 1f ; 1: pop eax
7172
More user control (force/forbid register arg, return type, etc)
73+
Preserve C decompiled line association to range of asm decoded addrs
7274

7375
Debugger
7476
OSX
@@ -81,7 +83,6 @@ Debugger
8183
Remote debugging (small standalone C client)
8284
Support dbghelp.dll (ms symbol server info)
8385
Support debugee function call (gdb 'call')
84-
Manipulate memory through C struct casts
8586

8687
ExeFormat
8788
Handle minor editing without decode/reencode (eg patch ELF entrypoint)
@@ -105,10 +106,9 @@ GUI
105106
show breakpoints
106107
show jump direction from current flag values
107108
have a console frontend
108-
better graph positionning fallback
109109
zoom font when zooming graph
110-
copy/paste, selection
110+
text selection
111111
map (part of) the binary & debug it (map a PE on a linux host & run it)
112112

113113
Ruby
114-
compile ruby AST to native optimized code
114+
write a fast ruby-like interpreter

lib/metasm/doc/code_organisation.txt

Lines changed: 0 additions & 146 deletions
This file was deleted.

lib/metasm/doc/const_missing.txt

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)