metasm 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/BUGS +11 -0
- data/CREDITS +17 -0
- data/README +270 -0
- data/TODO +114 -0
- data/doc/code_organisation.txt +146 -0
- data/doc/const_missing.txt +16 -0
- data/doc/core_classes.txt +75 -0
- data/doc/feature_list.txt +53 -0
- data/doc/index.txt +59 -0
- data/doc/install_notes.txt +170 -0
- data/doc/style.css +3 -0
- data/doc/use_cases.txt +18 -0
- data/lib/metasm.rb +80 -0
- data/lib/metasm/arm.rb +12 -0
- data/lib/metasm/arm/debug.rb +39 -0
- data/lib/metasm/arm/decode.rb +167 -0
- data/lib/metasm/arm/encode.rb +77 -0
- data/lib/metasm/arm/main.rb +75 -0
- data/lib/metasm/arm/opcodes.rb +177 -0
- data/lib/metasm/arm/parse.rb +130 -0
- data/lib/metasm/arm/render.rb +55 -0
- data/lib/metasm/compile_c.rb +1457 -0
- data/lib/metasm/dalvik.rb +8 -0
- data/lib/metasm/dalvik/decode.rb +196 -0
- data/lib/metasm/dalvik/main.rb +60 -0
- data/lib/metasm/dalvik/opcodes.rb +366 -0
- data/lib/metasm/decode.rb +213 -0
- data/lib/metasm/decompile.rb +2659 -0
- data/lib/metasm/disassemble.rb +2068 -0
- data/lib/metasm/disassemble_api.rb +1280 -0
- data/lib/metasm/dynldr.rb +1329 -0
- data/lib/metasm/encode.rb +333 -0
- data/lib/metasm/exe_format/a_out.rb +194 -0
- data/lib/metasm/exe_format/autoexe.rb +82 -0
- data/lib/metasm/exe_format/bflt.rb +189 -0
- data/lib/metasm/exe_format/coff.rb +455 -0
- data/lib/metasm/exe_format/coff_decode.rb +901 -0
- data/lib/metasm/exe_format/coff_encode.rb +1078 -0
- data/lib/metasm/exe_format/dex.rb +457 -0
- data/lib/metasm/exe_format/dol.rb +145 -0
- data/lib/metasm/exe_format/elf.rb +923 -0
- data/lib/metasm/exe_format/elf_decode.rb +979 -0
- data/lib/metasm/exe_format/elf_encode.rb +1375 -0
- data/lib/metasm/exe_format/macho.rb +827 -0
- data/lib/metasm/exe_format/main.rb +228 -0
- data/lib/metasm/exe_format/mz.rb +164 -0
- data/lib/metasm/exe_format/nds.rb +172 -0
- data/lib/metasm/exe_format/pe.rb +437 -0
- data/lib/metasm/exe_format/serialstruct.rb +246 -0
- data/lib/metasm/exe_format/shellcode.rb +114 -0
- data/lib/metasm/exe_format/xcoff.rb +167 -0
- data/lib/metasm/gui.rb +23 -0
- data/lib/metasm/gui/cstruct.rb +373 -0
- data/lib/metasm/gui/dasm_coverage.rb +199 -0
- data/lib/metasm/gui/dasm_decomp.rb +369 -0
- data/lib/metasm/gui/dasm_funcgraph.rb +103 -0
- data/lib/metasm/gui/dasm_graph.rb +1354 -0
- data/lib/metasm/gui/dasm_hex.rb +543 -0
- data/lib/metasm/gui/dasm_listing.rb +599 -0
- data/lib/metasm/gui/dasm_main.rb +906 -0
- data/lib/metasm/gui/dasm_opcodes.rb +291 -0
- data/lib/metasm/gui/debug.rb +1228 -0
- data/lib/metasm/gui/gtk.rb +884 -0
- data/lib/metasm/gui/qt.rb +495 -0
- data/lib/metasm/gui/win32.rb +3004 -0
- data/lib/metasm/gui/x11.rb +621 -0
- data/lib/metasm/ia32.rb +14 -0
- data/lib/metasm/ia32/compile_c.rb +1523 -0
- data/lib/metasm/ia32/debug.rb +193 -0
- data/lib/metasm/ia32/decode.rb +1167 -0
- data/lib/metasm/ia32/decompile.rb +564 -0
- data/lib/metasm/ia32/encode.rb +314 -0
- data/lib/metasm/ia32/main.rb +233 -0
- data/lib/metasm/ia32/opcodes.rb +872 -0
- data/lib/metasm/ia32/parse.rb +327 -0
- data/lib/metasm/ia32/render.rb +91 -0
- data/lib/metasm/main.rb +1193 -0
- data/lib/metasm/mips.rb +11 -0
- data/lib/metasm/mips/compile_c.rb +7 -0
- data/lib/metasm/mips/decode.rb +253 -0
- data/lib/metasm/mips/encode.rb +51 -0
- data/lib/metasm/mips/main.rb +72 -0
- data/lib/metasm/mips/opcodes.rb +443 -0
- data/lib/metasm/mips/parse.rb +51 -0
- data/lib/metasm/mips/render.rb +43 -0
- data/lib/metasm/os/gnu_exports.rb +270 -0
- data/lib/metasm/os/linux.rb +1112 -0
- data/lib/metasm/os/main.rb +1686 -0
- data/lib/metasm/os/remote.rb +527 -0
- data/lib/metasm/os/windows.rb +2027 -0
- data/lib/metasm/os/windows_exports.rb +745 -0
- data/lib/metasm/parse.rb +876 -0
- data/lib/metasm/parse_c.rb +3938 -0
- data/lib/metasm/pic16c/decode.rb +42 -0
- data/lib/metasm/pic16c/main.rb +17 -0
- data/lib/metasm/pic16c/opcodes.rb +68 -0
- data/lib/metasm/ppc.rb +11 -0
- data/lib/metasm/ppc/decode.rb +264 -0
- data/lib/metasm/ppc/decompile.rb +251 -0
- data/lib/metasm/ppc/encode.rb +51 -0
- data/lib/metasm/ppc/main.rb +129 -0
- data/lib/metasm/ppc/opcodes.rb +410 -0
- data/lib/metasm/ppc/parse.rb +52 -0
- data/lib/metasm/preprocessor.rb +1277 -0
- data/lib/metasm/render.rb +130 -0
- data/lib/metasm/sh4.rb +8 -0
- data/lib/metasm/sh4/decode.rb +336 -0
- data/lib/metasm/sh4/main.rb +292 -0
- data/lib/metasm/sh4/opcodes.rb +381 -0
- data/lib/metasm/x86_64.rb +12 -0
- data/lib/metasm/x86_64/compile_c.rb +1025 -0
- data/lib/metasm/x86_64/debug.rb +59 -0
- data/lib/metasm/x86_64/decode.rb +268 -0
- data/lib/metasm/x86_64/encode.rb +264 -0
- data/lib/metasm/x86_64/main.rb +135 -0
- data/lib/metasm/x86_64/opcodes.rb +118 -0
- data/lib/metasm/x86_64/parse.rb +68 -0
- data/misc/bottleneck.rb +61 -0
- data/misc/cheader-findpppath.rb +58 -0
- data/misc/hexdiff.rb +74 -0
- data/misc/hexdump.rb +55 -0
- data/misc/metasm-all.rb +13 -0
- data/misc/objdiff.rb +47 -0
- data/misc/objscan.rb +40 -0
- data/misc/pdfparse.rb +661 -0
- data/misc/ppc_pdf2oplist.rb +192 -0
- data/misc/tcp_proxy_hex.rb +84 -0
- data/misc/txt2html.rb +440 -0
- data/samples/a.out.rb +31 -0
- data/samples/asmsyntax.rb +77 -0
- data/samples/bindiff.rb +555 -0
- data/samples/compilation-steps.rb +49 -0
- data/samples/cparser_makestackoffset.rb +55 -0
- data/samples/dasm-backtrack.rb +38 -0
- data/samples/dasmnavig.rb +318 -0
- data/samples/dbg-apihook.rb +228 -0
- data/samples/dbghelp.rb +143 -0
- data/samples/disassemble-gui.rb +102 -0
- data/samples/disassemble.rb +133 -0
- data/samples/dump_upx.rb +95 -0
- data/samples/dynamic_ruby.rb +1929 -0
- data/samples/elf_list_needed.rb +46 -0
- data/samples/elf_listexports.rb +33 -0
- data/samples/elfencode.rb +25 -0
- data/samples/exeencode.rb +128 -0
- data/samples/factorize-headers-elfimports.rb +77 -0
- data/samples/factorize-headers-peimports.rb +109 -0
- data/samples/factorize-headers.rb +43 -0
- data/samples/gdbclient.rb +583 -0
- data/samples/generate_libsigs.rb +102 -0
- data/samples/hotfix_gtk_dbg.rb +59 -0
- data/samples/install_win_env.rb +78 -0
- data/samples/lindebug.rb +924 -0
- data/samples/linux_injectsyscall.rb +95 -0
- data/samples/machoencode.rb +31 -0
- data/samples/metasm-shell.rb +91 -0
- data/samples/pe-hook.rb +69 -0
- data/samples/pe-ia32-cpuid.rb +203 -0
- data/samples/pe-mips.rb +35 -0
- data/samples/pe-shutdown.rb +78 -0
- data/samples/pe-testrelocs.rb +51 -0
- data/samples/pe-testrsrc.rb +24 -0
- data/samples/pe_listexports.rb +31 -0
- data/samples/peencode.rb +19 -0
- data/samples/peldr.rb +494 -0
- data/samples/preprocess-flatten.rb +19 -0
- data/samples/r0trace.rb +308 -0
- data/samples/rubstop.rb +399 -0
- data/samples/scan_pt_gnu_stack.rb +54 -0
- data/samples/scanpeexports.rb +62 -0
- data/samples/shellcode-c.rb +40 -0
- data/samples/shellcode-dynlink.rb +146 -0
- data/samples/source.asm +34 -0
- data/samples/struct_offset.rb +47 -0
- data/samples/testpe.rb +32 -0
- data/samples/testraw.rb +45 -0
- data/samples/win32genloader.rb +132 -0
- data/samples/win32hooker-advanced.rb +169 -0
- data/samples/win32hooker.rb +96 -0
- data/samples/win32livedasm.rb +33 -0
- data/samples/win32remotescan.rb +133 -0
- data/samples/wintrace.rb +92 -0
- data/tests/all.rb +8 -0
- data/tests/dasm.rb +39 -0
- data/tests/dynldr.rb +35 -0
- data/tests/encodeddata.rb +132 -0
- data/tests/ia32.rb +82 -0
- data/tests/mips.rb +116 -0
- data/tests/parse_c.rb +239 -0
- data/tests/preprocessor.rb +269 -0
- data/tests/x86_64.rb +62 -0
- metadata +255 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
The const_missing trick
|
|
2
|
+
=======================
|
|
3
|
+
|
|
4
|
+
Metasm uses a ruby trick to load most of the framework on demand, so that
|
|
5
|
+
*e.g.* the `MIPS`-related classes are never loaded in the ruby interpreter
|
|
6
|
+
unless you use them.
|
|
7
|
+
|
|
8
|
+
It is setup by the top-level `metasm.rb` file, by using the ruby mechanism of
|
|
9
|
+
`Module.autoload`. This mechanism will automatically load the specified metasm
|
|
10
|
+
components whenever a reference is made to one of the constants listed here.
|
|
11
|
+
|
|
12
|
+
Metasm provides a replacement top-level file, `misc/metasm-all.rb`,
|
|
13
|
+
which will unconditionally load all metasm files.
|
|
14
|
+
This will not however load mutually exclusive files, like the Gui subsystems ;
|
|
15
|
+
in this case it will load only the autodetected gui module (win32 or gtk).
|
|
16
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
Core classes
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
Core
|
|
5
|
+
----
|
|
6
|
+
|
|
7
|
+
* <core/Expression.txt>
|
|
8
|
+
* <core/EncodedData.txt>
|
|
9
|
+
* <core/VirtualString.txt>
|
|
10
|
+
* <core/Opcode.txt>
|
|
11
|
+
* <core/Instruction.txt>
|
|
12
|
+
|
|
13
|
+
CPUs
|
|
14
|
+
----
|
|
15
|
+
|
|
16
|
+
* <core/CPU.txt>
|
|
17
|
+
* <core/Ia32.txt>
|
|
18
|
+
* <core/X86_64.txt>
|
|
19
|
+
* <core/MIPS.txt>
|
|
20
|
+
* <core/PowerPC.txt>
|
|
21
|
+
* <core/Sh4.txt>
|
|
22
|
+
|
|
23
|
+
ExeFormats
|
|
24
|
+
----------
|
|
25
|
+
|
|
26
|
+
* <core/ExeFormat.txt>
|
|
27
|
+
* <core/SerialStruct.txt>
|
|
28
|
+
* <core/AutoExe.txt>
|
|
29
|
+
|
|
30
|
+
* <core/Shellcode.txt>
|
|
31
|
+
* <core/PE.txt>
|
|
32
|
+
* <core/COFF.txt>
|
|
33
|
+
* <core/ELF.txt>
|
|
34
|
+
|
|
35
|
+
C
|
|
36
|
+
----
|
|
37
|
+
|
|
38
|
+
* <core/Preprocessor.txt>
|
|
39
|
+
* <core/CParser.txt>
|
|
40
|
+
* <core/CCompiler.txt>
|
|
41
|
+
|
|
42
|
+
Debugger
|
|
43
|
+
--------
|
|
44
|
+
|
|
45
|
+
* <core/OS.txt>
|
|
46
|
+
* <core/Debugger.txt>
|
|
47
|
+
* <core/LinDebugger.txt>
|
|
48
|
+
* <core/WinDebugger.txt>
|
|
49
|
+
* <core/PTrace.txt>
|
|
50
|
+
* <core/GdbClient.txt>
|
|
51
|
+
* <core/WinDbgAPI.txt>
|
|
52
|
+
|
|
53
|
+
Disassembler
|
|
54
|
+
------------
|
|
55
|
+
|
|
56
|
+
* <core/Disassembler.txt>
|
|
57
|
+
* <core/DecodedFunction.txt>
|
|
58
|
+
* <core/DecodedInstruction.txt>
|
|
59
|
+
* <core/InstructionBlock.txt>
|
|
60
|
+
* <core/Decompiler.txt>
|
|
61
|
+
|
|
62
|
+
GUI
|
|
63
|
+
----
|
|
64
|
+
|
|
65
|
+
* <core/Gui.txt>
|
|
66
|
+
* <core/Gui_Drawable.txt>
|
|
67
|
+
* <core/Gui_Window.txt>
|
|
68
|
+
|
|
69
|
+
* <core/Gui_DasmWidget.txt>
|
|
70
|
+
* <core/Gui_DebugWidget.txt>
|
|
71
|
+
|
|
72
|
+
Others
|
|
73
|
+
------
|
|
74
|
+
|
|
75
|
+
* <core/DynLdr.txt>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
Metasm feature list
|
|
2
|
+
===================
|
|
3
|
+
|
|
4
|
+
Metasm is a cross-architecture assembler, disassembler, compiler, linker and debugger.
|
|
5
|
+
|
|
6
|
+
See <use_cases.txt>
|
|
7
|
+
|
|
8
|
+
Architectures
|
|
9
|
+
-------------
|
|
10
|
+
|
|
11
|
+
It is written in such a way that it is easy to add support for new architectures.
|
|
12
|
+
For now, the following architectures are in:
|
|
13
|
+
|
|
14
|
+
* Intel <core/Ia32.txt> (16 and 32bits)
|
|
15
|
+
* Intel <core/X86_64.txt> (*aka* Ia32 64bits, X64, AMD64)
|
|
16
|
+
* MIPS
|
|
17
|
+
* PowerPC
|
|
18
|
+
* Sh4
|
|
19
|
+
|
|
20
|
+
The developpement is generally more focused on Ia32 and X86_64.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
File formats
|
|
24
|
+
------------
|
|
25
|
+
|
|
26
|
+
The following executable file formats are supported:
|
|
27
|
+
|
|
28
|
+
* <core/Shellcode.txt> (raw binary)
|
|
29
|
+
* <core/PE.txt>/<core/COFF.txt> (32/64bits)
|
|
30
|
+
* <core/ELF.txt> (32/64bits)
|
|
31
|
+
|
|
32
|
+
Those are supported in a more limited way:
|
|
33
|
+
|
|
34
|
+
* Mach-O, UniversalBinary
|
|
35
|
+
* MZ
|
|
36
|
+
* A.out
|
|
37
|
+
* XCoff
|
|
38
|
+
* NDS
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
Features
|
|
42
|
+
--------
|
|
43
|
+
|
|
44
|
+
The framework includes
|
|
45
|
+
|
|
46
|
+
* a graphical <usage/disassembler.txt>
|
|
47
|
+
* a graphical <usage/debugger.txt>
|
|
48
|
+
* low and high-level debugging support (Ia32 only for now) under Windows, Linux and remote (via a GdbServer)
|
|
49
|
+
* an advanced disassembler engine, with limited emulation support
|
|
50
|
+
* a full <usage/C_parser.txt> (with preprocessor)
|
|
51
|
+
* an experimental <usage/C_compiler.txt> (Ia32 only)
|
|
52
|
+
* an experimental <usage/decompiler.txt> (Ia32 only)
|
|
53
|
+
|
data/doc/index.txt
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
The Metasm framework documentation
|
|
2
|
+
==================================
|
|
3
|
+
|
|
4
|
+
Metasm
|
|
5
|
+
------
|
|
6
|
+
|
|
7
|
+
The Metasm framework is an opensource software designed to interact with
|
|
8
|
+
the various forms of binary code. It is written in pure Ruby
|
|
9
|
+
(<http://ruby-lang.org/>).
|
|
10
|
+
|
|
11
|
+
More detailed informations can be found in the <feature_list.txt>.
|
|
12
|
+
|
|
13
|
+
It is distributed freely under the terms of the LGPL.
|
|
14
|
+
|
|
15
|
+
Documentation organisation
|
|
16
|
+
--------------------------
|
|
17
|
+
|
|
18
|
+
This documentation is split in different parts :
|
|
19
|
+
|
|
20
|
+
* the <core_classes.txt>
|
|
21
|
+
* the major <use_cases.txt>
|
|
22
|
+
* <code_organisation.txt>
|
|
23
|
+
|
|
24
|
+
The first part describes the internal structure of the framework, the
|
|
25
|
+
second part is a higher level overview of the software and shows how
|
|
26
|
+
the various parts are used and can interract. The last part explains
|
|
27
|
+
the role of the source files and directories.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
Documentation progress
|
|
31
|
+
----------------------
|
|
32
|
+
|
|
33
|
+
The documentation is written here and there in my free time, and is **very**
|
|
34
|
+
**incomplete** as of now. Specifically, all internal links you'll find
|
|
35
|
+
ending in `.txt` are link to pages that have not been written yet.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
Install notes
|
|
39
|
+
-------------
|
|
40
|
+
|
|
41
|
+
See the <install_notes.txt>
|
|
42
|
+
|
|
43
|
+
Authors
|
|
44
|
+
-------
|
|
45
|
+
|
|
46
|
+
Metasm is mostly written by Yoann Guillot.
|
|
47
|
+
|
|
48
|
+
Some parts were added by various contributors, including :
|
|
49
|
+
* Julien Tinnès
|
|
50
|
+
* Raphaël Rigo
|
|
51
|
+
* Arnaud Cornet
|
|
52
|
+
* Alexandre Gazet
|
|
53
|
+
|
|
54
|
+
Contact
|
|
55
|
+
-------
|
|
56
|
+
|
|
57
|
+
The latest version of this documentation can be found on the Metasm site: <http://metasm.cr0.org/doc>
|
|
58
|
+
|
|
59
|
+
Patches, bug reports, feature requests should be sent to metasm@cr0.org
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
Metasm installation notes
|
|
2
|
+
=========================
|
|
3
|
+
|
|
4
|
+
Metasm is a pure ruby lib, and the core (`metasm/` subdir) does not depend on any
|
|
5
|
+
ruby library (except the `metasm/gui`, which may use `gtk2`).
|
|
6
|
+
|
|
7
|
+
So the install is quite simple.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Download
|
|
11
|
+
--------
|
|
12
|
+
|
|
13
|
+
Metasm is distributed using the `mercurial` source control system.
|
|
14
|
+
|
|
15
|
+
The recommanded way to install is to use that tool, so you can always be
|
|
16
|
+
up-to-date with the latest developpements.
|
|
17
|
+
|
|
18
|
+
You will also need the Ruby interpreter (version 1.8 and 1.9 are supported).
|
|
19
|
+
|
|
20
|
+
Linux
|
|
21
|
+
#####
|
|
22
|
+
|
|
23
|
+
Issue the following commands to install the `mercurial` and `ruby` software
|
|
24
|
+
|
|
25
|
+
sudo apt-get install ruby
|
|
26
|
+
sudo apt-get install mercurial
|
|
27
|
+
|
|
28
|
+
Then download metasm with
|
|
29
|
+
|
|
30
|
+
hg clone http://metasm.cr0.org/hg/metasm/
|
|
31
|
+
|
|
32
|
+
This will create a new directory `metasm/` with the latest version of the
|
|
33
|
+
framework.
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
Windows
|
|
37
|
+
#######
|
|
38
|
+
|
|
39
|
+
The ruby website offers many ruby packages. The *RubyInstaller* should
|
|
40
|
+
work fine. Go to <http://www.ruby-lang.org/en/downloads/>, under the
|
|
41
|
+
`Ruby on Windows` section.
|
|
42
|
+
|
|
43
|
+
The `mercurial` website has links to various installers:
|
|
44
|
+
<http://mercurial.selenic.com/wiki/BinaryPackages>
|
|
45
|
+
Choose one, then use the `clone repository` command with the following
|
|
46
|
+
url:
|
|
47
|
+
|
|
48
|
+
http://metasm.cr0.org/hg/metasm/
|
|
49
|
+
|
|
50
|
+
This will create a new subdirectory `metasm/` with the latest version of
|
|
51
|
+
the framework.
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
Upgrading
|
|
55
|
+
---------
|
|
56
|
+
|
|
57
|
+
To upgrade to the latest and greatest version, launch a shell prompt and
|
|
58
|
+
navigate to the metasm directory, then issue:
|
|
59
|
+
|
|
60
|
+
hg pull -u
|
|
61
|
+
|
|
62
|
+
which will upgrade your installation to the latest available version.
|
|
63
|
+
|
|
64
|
+
With `TortoiseHG`, simply issue the `upgrade` command on the `metasm`
|
|
65
|
+
directory.
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
Local installation
|
|
69
|
+
------------------
|
|
70
|
+
|
|
71
|
+
If you simply want to install metasm for your personnal usage (VS a
|
|
72
|
+
system-wide installation), follow these steps.
|
|
73
|
+
|
|
74
|
+
Download the metasm source files under any directory, then update the
|
|
75
|
+
environment variable `RUBYLIB` to include this path. The path you add
|
|
76
|
+
should be the directory containing the `metasm.rb` script and the `metasm/`,
|
|
77
|
+
`samples/`, `doc/` subdirectories.
|
|
78
|
+
|
|
79
|
+
If `RUBYLIB` is empty or non-existant, simply set its value to the directory,
|
|
80
|
+
otherwise you can append the path to an existing list by separating the values
|
|
81
|
+
with a `:` such as:
|
|
82
|
+
|
|
83
|
+
RUBYLIB='/foo/bar:/home/jj/metasm'
|
|
84
|
+
|
|
85
|
+
Linux
|
|
86
|
+
#####
|
|
87
|
+
|
|
88
|
+
Under linux or cygwin, this is done by modifying your shell profile, e.g.
|
|
89
|
+
`~/.bash_profile`, by adding a line such as:
|
|
90
|
+
|
|
91
|
+
export RUBYLIB='/home/jj/metasm'
|
|
92
|
+
|
|
93
|
+
You may need to restart your session or start a new shell for the changes
|
|
94
|
+
to take effect.
|
|
95
|
+
|
|
96
|
+
Windows
|
|
97
|
+
#######
|
|
98
|
+
|
|
99
|
+
The environment variables can be set through :
|
|
100
|
+
|
|
101
|
+
* rightclick on `my computer`
|
|
102
|
+
* select tab `advanced`
|
|
103
|
+
* click `environment variables`
|
|
104
|
+
|
|
105
|
+
If a line RUBYLIB exists, add `;C:\path\to\metasm` at the end, otherwise
|
|
106
|
+
create a new variable `RUBYLIB` with the path as value.
|
|
107
|
+
|
|
108
|
+
You may need to restart your session for the changes to take effect.
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
Systemwide installation
|
|
112
|
+
-----------------------
|
|
113
|
+
|
|
114
|
+
For a systemwide installation, you should create a `metasm.rb` file in the `site_ruby`
|
|
115
|
+
directory (that would be `/usr/lib/ruby/1.8/` under linux, or `C:\apps\ruby\lib\ruby\1.8\`
|
|
116
|
+
for windows users) with the content
|
|
117
|
+
|
|
118
|
+
# if metasm.rb can be found in /home/jj/metasm/metasm.rb
|
|
119
|
+
require '/home/jj/metasm/metasm'
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
Testing
|
|
123
|
+
-------
|
|
124
|
+
|
|
125
|
+
Open a new shell session and type
|
|
126
|
+
|
|
127
|
+
ruby -r metasm -e "p Metasm::VERSION"
|
|
128
|
+
|
|
129
|
+
It should print a single line with a (meaningless) number in it.
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
Gui
|
|
133
|
+
----
|
|
134
|
+
|
|
135
|
+
If you intend to use the graphical user-interface (debugger/disassembler),
|
|
136
|
+
if you are under Windows with a 32bit x86 ruby, this should work out of the
|
|
137
|
+
box. In any other case, you'll need the `ruby-gtk2` library.
|
|
138
|
+
|
|
139
|
+
Linux
|
|
140
|
+
#####
|
|
141
|
+
|
|
142
|
+
Under linux, use your package manager to install `ruby-gtk2`, e.g. for
|
|
143
|
+
Debian/Ubuntu, type:
|
|
144
|
+
|
|
145
|
+
sudo apt-get install libgtk2-ruby
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
Windows
|
|
149
|
+
#######
|
|
150
|
+
|
|
151
|
+
If you run a 32bit Ia32 ruby interpreter (check that `ruby -v` returns
|
|
152
|
+
something like `[i386-mswin32]`), the Gui should work right away without
|
|
153
|
+
`gtk2`, so go directly to the `Testing` part.
|
|
154
|
+
|
|
155
|
+
Otherwise, you'll need to install the `gtk2` libs and the ruby bindings
|
|
156
|
+
manually. Please follow the instructions at
|
|
157
|
+
<http://ruby-gnome2.sourceforge.jp/hiki.cgi?Install+Guide+for+Windows>
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
Testing
|
|
161
|
+
#######
|
|
162
|
+
|
|
163
|
+
To test the correct working of the Gui, simply launch the
|
|
164
|
+
`samples/disassemble-gui.rb` script found in the metasm directory
|
|
165
|
+
(double-click on the script, or type `ruby samples/disassemble-gui.rb` at
|
|
166
|
+
a command prompt). It should display a window with a menu, and should
|
|
167
|
+
answer to a `ctrl-o` keystroke with an `open binary file` dialog.
|
|
168
|
+
|
|
169
|
+
See the <usage/disassembler_gui.txt> for more information.
|
|
170
|
+
|
data/doc/style.css
ADDED
data/doc/use_cases.txt
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Metasm use cases
|
|
2
|
+
================
|
|
3
|
+
|
|
4
|
+
Metasm is intended to be a binary manipulation toolbox.
|
|
5
|
+
There are quite a lot of possible usages that can be derived from the
|
|
6
|
+
<feature_list.txt>.
|
|
7
|
+
|
|
8
|
+
The major would be related to:
|
|
9
|
+
|
|
10
|
+
* the scriptable <usage/debugger.txt>
|
|
11
|
+
* the <usage/disassembler.txt> (with the optionnal <usage/disassembler_gui.txt>)
|
|
12
|
+
* the <usage/assembler.txt>
|
|
13
|
+
* the <usage/C_parser.txt>
|
|
14
|
+
* the <usage/C_compiler.txt>
|
|
15
|
+
* the <usage/exe_manipulation.txt> facilities
|
|
16
|
+
|
|
17
|
+
and various interaction between those.
|
|
18
|
+
|
data/lib/metasm.rb
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# This file is part of Metasm, the Ruby assembly manipulation suite
|
|
2
|
+
# Copyright (C) 2006-2009 Yoann GUILLOT
|
|
3
|
+
#
|
|
4
|
+
# Licence is LGPL, see LICENCE in the top-level directory
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
module Metasm
|
|
8
|
+
# root directory for metasm files
|
|
9
|
+
# used by some scripts, eg to find samples/dasm-plugin directory
|
|
10
|
+
Metasmdir = File.dirname(__FILE__)
|
|
11
|
+
# add it to the ruby library path
|
|
12
|
+
$: << Metasmdir
|
|
13
|
+
|
|
14
|
+
# constants defined in the same file as another
|
|
15
|
+
Const_autorequire_equiv = {
|
|
16
|
+
'X86' => 'Ia32', 'PPC' => 'PowerPC',
|
|
17
|
+
'X64' => 'X86_64', 'AMD64' => 'X86_64',
|
|
18
|
+
'UniversalBinary' => 'MachO', 'COFFArchive' => 'COFF',
|
|
19
|
+
'DEY' => 'DEX',
|
|
20
|
+
'PTrace' => 'LinOS', 'FatELF' => 'ELF',
|
|
21
|
+
'LoadedELF' => 'ELF', 'LoadedPE' => 'PE',
|
|
22
|
+
'LoadedAutoExe' => 'AutoExe',
|
|
23
|
+
'LinuxRemoteString' => 'LinOS',
|
|
24
|
+
'LinDebugger' => 'LinOS',
|
|
25
|
+
'WinAPI' => 'WinOS',
|
|
26
|
+
'WindowsRemoteString' => 'WinOS', 'WinDbgAPI' => 'WinOS',
|
|
27
|
+
'WinDebugger' => 'WinOS',
|
|
28
|
+
'GdbRemoteString' => 'GdbClient', 'GdbRemoteDebugger' => 'GdbClient',
|
|
29
|
+
'DecodedInstruction' => 'Disassembler', 'DecodedFunction' => 'Disassembler',
|
|
30
|
+
'InstructionBlock' => 'Disassembler',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
# files to require to get the definition of those constants
|
|
34
|
+
Const_autorequire = {
|
|
35
|
+
'Ia32' => 'ia32', 'MIPS' => 'mips', 'PowerPC' => 'ppc', 'ARM' => 'arm',
|
|
36
|
+
'X86_64' => 'x86_64', 'Sh4' => 'sh4', 'Dalvik' => 'dalvik',
|
|
37
|
+
'C' => 'compile_c',
|
|
38
|
+
'MZ' => 'exe_format/mz', 'PE' => 'exe_format/pe',
|
|
39
|
+
'ELF' => 'exe_format/elf', 'COFF' => 'exe_format/coff',
|
|
40
|
+
'Shellcode' => 'exe_format/shellcode', 'AutoExe' => 'exe_format/autoexe',
|
|
41
|
+
'AOut' => 'exe_format/a_out', 'MachO' => 'exe_format/macho',
|
|
42
|
+
'DEX' => 'exe_format/dex',
|
|
43
|
+
'NDS' => 'exe_format/nds', 'XCoff' => 'exe_format/xcoff',
|
|
44
|
+
'Bflt' => 'exe_format/bflt', 'Dol' => 'exe_format/dol',
|
|
45
|
+
'Gui' => 'gui',
|
|
46
|
+
'WindowsExports' => 'os/windows_exports',
|
|
47
|
+
'GNUExports' => 'os/gnu_exports',
|
|
48
|
+
'LinOS' => 'os/linux', 'WinOS' => 'os/windows',
|
|
49
|
+
'GdbClient' => 'os/remote',
|
|
50
|
+
'Disassembler' => 'disassemble',
|
|
51
|
+
'Decompiler' => 'decompile',
|
|
52
|
+
'DynLdr' => 'dynldr',
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
# use the Module.autoload ruby functionnality to load framework components on demand
|
|
56
|
+
Const_autorequire.each { |cst, file|
|
|
57
|
+
autoload cst, File.join('metasm', file)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
Const_autorequire_equiv.each { |cst, eqv|
|
|
61
|
+
file = Const_autorequire[eqv]
|
|
62
|
+
autoload cst, File.join('metasm', file)
|
|
63
|
+
}
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# load Metasm core files
|
|
67
|
+
%w[main encode decode render exe_format/main os/main].each { |f|
|
|
68
|
+
require File.join('metasm', f)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
# remove an 1.9 warning, couldn't find a compatible way...
|
|
73
|
+
if Hash.new.respond_to?(:key)
|
|
74
|
+
puts "using ruby1.9 workaround for Hash#index warning" if $DEBUG
|
|
75
|
+
class Hash
|
|
76
|
+
alias index_premetasm index rescue nil
|
|
77
|
+
undef index rescue nil
|
|
78
|
+
alias index key
|
|
79
|
+
end
|
|
80
|
+
end
|