metasm 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.hgtags +3 -0
- data/Gemfile +1 -0
- data/INSTALL +61 -0
- data/LICENCE +458 -0
- data/README +29 -21
- data/Rakefile +10 -0
- data/TODO +10 -12
- data/doc/code_organisation.txt +2 -0
- data/doc/core/DynLdr.txt +247 -0
- data/doc/core/ExeFormat.txt +43 -0
- data/doc/core/Expression.txt +220 -0
- data/doc/core/GNUExports.txt +27 -0
- data/doc/core/Ia32.txt +236 -0
- data/doc/core/SerialStruct.txt +108 -0
- data/doc/core/VirtualString.txt +145 -0
- data/doc/core/WindowsExports.txt +61 -0
- data/doc/core/index.txt +1 -0
- data/doc/style.css +6 -3
- data/doc/usage/debugger.txt +327 -0
- data/doc/usage/index.txt +1 -0
- data/doc/use_cases.txt +2 -2
- data/metasm.gemspec +22 -0
- data/{lib/metasm.rb → metasm.rb} +11 -3
- data/{lib/metasm → metasm}/compile_c.rb +13 -7
- data/metasm/cpu/arc.rb +8 -0
- data/metasm/cpu/arc/decode.rb +425 -0
- data/metasm/cpu/arc/main.rb +191 -0
- data/metasm/cpu/arc/opcodes.rb +588 -0
- data/{lib/metasm → metasm/cpu}/arm.rb +7 -5
- data/{lib/metasm → metasm/cpu}/arm/debug.rb +2 -2
- data/{lib/metasm → metasm/cpu}/arm/decode.rb +13 -12
- data/{lib/metasm → metasm/cpu}/arm/encode.rb +23 -8
- data/{lib/metasm → metasm/cpu}/arm/main.rb +0 -3
- data/metasm/cpu/arm/opcodes.rb +324 -0
- data/{lib/metasm → metasm/cpu}/arm/parse.rb +25 -13
- data/{lib/metasm → metasm/cpu}/arm/render.rb +2 -2
- data/metasm/cpu/arm64.rb +15 -0
- data/metasm/cpu/arm64/debug.rb +38 -0
- data/metasm/cpu/arm64/decode.rb +289 -0
- data/metasm/cpu/arm64/encode.rb +41 -0
- data/metasm/cpu/arm64/main.rb +105 -0
- data/metasm/cpu/arm64/opcodes.rb +232 -0
- data/metasm/cpu/arm64/parse.rb +20 -0
- data/metasm/cpu/arm64/render.rb +95 -0
- data/{lib/metasm/ppc.rb → metasm/cpu/bpf.rb} +2 -4
- data/metasm/cpu/bpf/decode.rb +142 -0
- data/metasm/cpu/bpf/main.rb +60 -0
- data/metasm/cpu/bpf/opcodes.rb +81 -0
- data/metasm/cpu/bpf/render.rb +41 -0
- data/metasm/cpu/cy16.rb +9 -0
- data/metasm/cpu/cy16/decode.rb +253 -0
- data/metasm/cpu/cy16/main.rb +63 -0
- data/metasm/cpu/cy16/opcodes.rb +78 -0
- data/metasm/cpu/cy16/render.rb +41 -0
- data/metasm/cpu/dalvik.rb +11 -0
- data/{lib/metasm → metasm/cpu}/dalvik/decode.rb +35 -13
- data/{lib/metasm → metasm/cpu}/dalvik/main.rb +51 -2
- data/{lib/metasm → metasm/cpu}/dalvik/opcodes.rb +19 -11
- data/metasm/cpu/ia32.rb +17 -0
- data/{lib/metasm → metasm/cpu}/ia32/compile_c.rb +5 -7
- data/{lib/metasm → metasm/cpu}/ia32/debug.rb +5 -5
- data/{lib/metasm → metasm/cpu}/ia32/decode.rb +246 -59
- data/{lib/metasm → metasm/cpu}/ia32/decompile.rb +7 -7
- data/{lib/metasm → metasm/cpu}/ia32/encode.rb +19 -13
- data/{lib/metasm → metasm/cpu}/ia32/main.rb +51 -8
- data/metasm/cpu/ia32/opcodes.rb +1424 -0
- data/{lib/metasm → metasm/cpu}/ia32/parse.rb +47 -16
- data/{lib/metasm → metasm/cpu}/ia32/render.rb +31 -4
- data/metasm/cpu/mips.rb +14 -0
- data/{lib/metasm → metasm/cpu}/mips/compile_c.rb +1 -1
- data/metasm/cpu/mips/debug.rb +42 -0
- data/{lib/metasm → metasm/cpu}/mips/decode.rb +46 -16
- data/{lib/metasm → metasm/cpu}/mips/encode.rb +4 -3
- data/{lib/metasm → metasm/cpu}/mips/main.rb +11 -4
- data/{lib/metasm → metasm/cpu}/mips/opcodes.rb +86 -17
- data/{lib/metasm → metasm/cpu}/mips/parse.rb +1 -1
- data/{lib/metasm → metasm/cpu}/mips/render.rb +1 -1
- data/{lib/metasm/dalvik.rb → metasm/cpu/msp430.rb} +1 -1
- data/metasm/cpu/msp430/decode.rb +247 -0
- data/metasm/cpu/msp430/main.rb +62 -0
- data/metasm/cpu/msp430/opcodes.rb +101 -0
- data/{lib/metasm → metasm/cpu}/pic16c/decode.rb +6 -7
- data/{lib/metasm → metasm/cpu}/pic16c/main.rb +0 -0
- data/{lib/metasm → metasm/cpu}/pic16c/opcodes.rb +1 -1
- data/{lib/metasm/mips.rb → metasm/cpu/ppc.rb} +4 -4
- data/{lib/metasm → metasm/cpu}/ppc/decode.rb +18 -12
- data/{lib/metasm → metasm/cpu}/ppc/decompile.rb +3 -3
- data/{lib/metasm → metasm/cpu}/ppc/encode.rb +2 -2
- data/{lib/metasm → metasm/cpu}/ppc/main.rb +17 -12
- data/{lib/metasm → metasm/cpu}/ppc/opcodes.rb +11 -5
- data/metasm/cpu/ppc/parse.rb +55 -0
- data/metasm/cpu/python.rb +8 -0
- data/metasm/cpu/python/decode.rb +136 -0
- data/metasm/cpu/python/main.rb +36 -0
- data/metasm/cpu/python/opcodes.rb +180 -0
- data/{lib/metasm → metasm/cpu}/sh4.rb +1 -1
- data/{lib/metasm → metasm/cpu}/sh4/decode.rb +48 -17
- data/{lib/metasm → metasm/cpu}/sh4/main.rb +13 -4
- data/{lib/metasm → metasm/cpu}/sh4/opcodes.rb +7 -8
- data/metasm/cpu/x86_64.rb +15 -0
- data/{lib/metasm → metasm/cpu}/x86_64/compile_c.rb +28 -17
- data/{lib/metasm → metasm/cpu}/x86_64/debug.rb +4 -4
- data/{lib/metasm → metasm/cpu}/x86_64/decode.rb +57 -15
- data/{lib/metasm → metasm/cpu}/x86_64/encode.rb +55 -26
- data/{lib/metasm → metasm/cpu}/x86_64/main.rb +14 -6
- data/metasm/cpu/x86_64/opcodes.rb +136 -0
- data/{lib/metasm → metasm/cpu}/x86_64/parse.rb +10 -2
- data/metasm/cpu/x86_64/render.rb +35 -0
- data/metasm/cpu/z80.rb +9 -0
- data/metasm/cpu/z80/decode.rb +313 -0
- data/metasm/cpu/z80/main.rb +67 -0
- data/metasm/cpu/z80/opcodes.rb +224 -0
- data/metasm/cpu/z80/render.rb +59 -0
- data/{lib/metasm/os/main.rb → metasm/debug.rb} +160 -401
- data/{lib/metasm → metasm}/decode.rb +35 -4
- data/{lib/metasm → metasm}/decompile.rb +15 -16
- data/{lib/metasm → metasm}/disassemble.rb +201 -45
- data/{lib/metasm → metasm}/disassemble_api.rb +651 -87
- data/{lib/metasm → metasm}/dynldr.rb +220 -133
- data/{lib/metasm → metasm}/encode.rb +10 -1
- data/{lib/metasm → metasm}/exe_format/a_out.rb +9 -6
- data/{lib/metasm → metasm}/exe_format/autoexe.rb +1 -0
- data/{lib/metasm → metasm}/exe_format/bflt.rb +57 -27
- data/{lib/metasm → metasm}/exe_format/coff.rb +11 -3
- data/{lib/metasm → metasm}/exe_format/coff_decode.rb +53 -20
- data/{lib/metasm → metasm}/exe_format/coff_encode.rb +11 -13
- data/{lib/metasm → metasm}/exe_format/dex.rb +13 -5
- data/{lib/metasm → metasm}/exe_format/dol.rb +1 -0
- data/{lib/metasm → metasm}/exe_format/elf.rb +93 -57
- data/{lib/metasm → metasm}/exe_format/elf_decode.rb +143 -34
- data/{lib/metasm → metasm}/exe_format/elf_encode.rb +122 -31
- data/metasm/exe_format/gb.rb +65 -0
- data/metasm/exe_format/javaclass.rb +424 -0
- data/{lib/metasm → metasm}/exe_format/macho.rb +204 -16
- data/{lib/metasm → metasm}/exe_format/main.rb +26 -3
- data/{lib/metasm → metasm}/exe_format/mz.rb +1 -0
- data/{lib/metasm → metasm}/exe_format/nds.rb +7 -4
- data/{lib/metasm → metasm}/exe_format/pe.rb +71 -8
- data/metasm/exe_format/pyc.rb +167 -0
- data/{lib/metasm → metasm}/exe_format/serialstruct.rb +67 -14
- data/{lib/metasm → metasm}/exe_format/shellcode.rb +7 -3
- data/metasm/exe_format/shellcode_rwx.rb +114 -0
- data/metasm/exe_format/swf.rb +205 -0
- data/{lib/metasm → metasm}/exe_format/xcoff.rb +7 -7
- data/metasm/exe_format/zip.rb +335 -0
- data/metasm/gui.rb +13 -0
- data/{lib/metasm → metasm}/gui/cstruct.rb +35 -41
- data/{lib/metasm → metasm}/gui/dasm_coverage.rb +11 -11
- data/{lib/metasm → metasm}/gui/dasm_decomp.rb +7 -20
- data/{lib/metasm → metasm}/gui/dasm_funcgraph.rb +0 -0
- data/metasm/gui/dasm_graph.rb +1695 -0
- data/{lib/metasm → metasm}/gui/dasm_hex.rb +12 -8
- data/{lib/metasm → metasm}/gui/dasm_listing.rb +43 -28
- data/{lib/metasm → metasm}/gui/dasm_main.rb +310 -53
- data/{lib/metasm → metasm}/gui/dasm_opcodes.rb +5 -19
- data/{lib/metasm → metasm}/gui/debug.rb +93 -27
- data/{lib/metasm → metasm}/gui/gtk.rb +162 -40
- data/{lib/metasm → metasm}/gui/qt.rb +12 -2
- data/{lib/metasm → metasm}/gui/win32.rb +179 -42
- data/{lib/metasm → metasm}/gui/x11.rb +59 -59
- data/{lib/metasm → metasm}/main.rb +389 -264
- data/{lib/metasm/os/remote.rb → metasm/os/gdbremote.rb} +146 -54
- data/{lib/metasm → metasm}/os/gnu_exports.rb +1 -1
- data/{lib/metasm → metasm}/os/linux.rb +628 -151
- data/metasm/os/main.rb +330 -0
- data/{lib/metasm → metasm}/os/windows.rb +132 -42
- data/{lib/metasm → metasm}/os/windows_exports.rb +141 -0
- data/{lib/metasm → metasm}/parse.rb +26 -24
- data/{lib/metasm → metasm}/parse_c.rb +221 -116
- data/{lib/metasm → metasm}/preprocessor.rb +55 -40
- data/{lib/metasm → metasm}/render.rb +14 -38
- data/misc/hexdump.rb +2 -1
- data/misc/lint.rb +58 -0
- data/misc/txt2html.rb +9 -7
- data/samples/bindiff.rb +3 -4
- data/samples/dasm-plugins/bindiff.rb +15 -0
- data/samples/dasm-plugins/bookmark.rb +133 -0
- data/samples/dasm-plugins/c_constants.rb +57 -0
- data/samples/dasm-plugins/colortheme_solarized.rb +125 -0
- data/samples/dasm-plugins/cppobj_funcall.rb +60 -0
- data/samples/dasm-plugins/dasm_all.rb +70 -0
- data/samples/dasm-plugins/demangle_cpp.rb +31 -0
- data/samples/dasm-plugins/deobfuscate.rb +251 -0
- data/samples/dasm-plugins/dump_text.rb +35 -0
- data/samples/dasm-plugins/export_graph_svg.rb +86 -0
- data/samples/dasm-plugins/findgadget.rb +75 -0
- data/samples/dasm-plugins/hl_opcode.rb +32 -0
- data/samples/dasm-plugins/hotfix_gtk_dbg.rb +19 -0
- data/samples/dasm-plugins/imm2off.rb +34 -0
- data/samples/dasm-plugins/match_libsigs.rb +93 -0
- data/samples/dasm-plugins/patch_file.rb +95 -0
- data/samples/dasm-plugins/scanfuncstart.rb +36 -0
- data/samples/dasm-plugins/scanxrefs.rb +26 -0
- data/samples/dasm-plugins/selfmodify.rb +197 -0
- data/samples/dasm-plugins/stringsxrefs.rb +28 -0
- data/samples/dasmnavig.rb +1 -1
- data/samples/dbg-apihook.rb +24 -9
- data/samples/dbg-plugins/heapscan.rb +283 -0
- data/samples/dbg-plugins/heapscan/compiled_heapscan_lin.c +155 -0
- data/samples/dbg-plugins/heapscan/compiled_heapscan_win.c +128 -0
- data/samples/dbg-plugins/heapscan/graphheap.rb +616 -0
- data/samples/dbg-plugins/heapscan/heapscan.rb +709 -0
- data/samples/dbg-plugins/heapscan/winheap.h +174 -0
- data/samples/dbg-plugins/heapscan/winheap7.h +307 -0
- data/samples/dbg-plugins/trace_func.rb +214 -0
- data/samples/disassemble-gui.rb +35 -5
- data/samples/disassemble.rb +31 -6
- data/samples/dump_upx.rb +24 -12
- data/samples/dynamic_ruby.rb +12 -3
- data/samples/exeencode.rb +6 -5
- data/samples/factorize-headers-peimports.rb +1 -1
- data/samples/lindebug.rb +175 -381
- data/samples/metasm-shell.rb +1 -2
- data/samples/peldr.rb +2 -2
- data/tests/all.rb +1 -1
- data/tests/arc.rb +26 -0
- data/tests/dynldr.rb +22 -4
- data/tests/expression.rb +55 -0
- data/tests/graph_layout.rb +285 -0
- data/tests/ia32.rb +79 -26
- data/tests/mips.rb +9 -2
- data/tests/x86_64.rb +66 -18
- metadata +330 -218
- data/lib/metasm/arm/opcodes.rb +0 -177
- data/lib/metasm/gui.rb +0 -23
- data/lib/metasm/gui/dasm_graph.rb +0 -1354
- data/lib/metasm/ia32.rb +0 -14
- data/lib/metasm/ia32/opcodes.rb +0 -873
- data/lib/metasm/ppc/parse.rb +0 -52
- data/lib/metasm/x86_64.rb +0 -12
- data/lib/metasm/x86_64/opcodes.rb +0 -118
- data/samples/gdbclient.rb +0 -583
- data/samples/rubstop.rb +0 -399
@@ -0,0 +1,36 @@
|
|
1
|
+
# This file is part of Metasm, the Ruby assembly manipulation suite
|
2
|
+
# Copyright (C) 2006-2010 Yoann GUILLOT
|
3
|
+
#
|
4
|
+
# Licence is LGPL, see LICENCE in the top-level directory
|
5
|
+
|
6
|
+
require 'metasm/main'
|
7
|
+
|
8
|
+
module Metasm
|
9
|
+
class Python < CPU
|
10
|
+
def initialize(prog = nil)
|
11
|
+
super()
|
12
|
+
@program = prog
|
13
|
+
@endianness = (prog.respond_to?(:endianness) ? prog.endianness : :little)
|
14
|
+
@size = (prog.respond_to?(:size) ? prog.size : 32)
|
15
|
+
end
|
16
|
+
|
17
|
+
class Var
|
18
|
+
include Renderable
|
19
|
+
|
20
|
+
attr_accessor :i
|
21
|
+
|
22
|
+
def initialize(i); @i = i end
|
23
|
+
|
24
|
+
def ==(o)
|
25
|
+
o.class == self.class and o.i == i
|
26
|
+
end
|
27
|
+
|
28
|
+
def symbolic; "var_#{@i}".to_sym end
|
29
|
+
|
30
|
+
def render
|
31
|
+
["var_#@i"]
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
# This file is part of Metasm, the Ruby assembly manipulation suite
|
2
|
+
# Copyright (C) 2006-2010 Yoann GUILLOT
|
3
|
+
#
|
4
|
+
# Licence is LGPL, see LICENCE in the top-level directory
|
5
|
+
|
6
|
+
require 'metasm/cpu/python/main'
|
7
|
+
|
8
|
+
module Metasm
|
9
|
+
class Python
|
10
|
+
CMP_OP = %w[< <= == != > >= in not_in is is_not exch]
|
11
|
+
|
12
|
+
def addop(name, bin, *args)
|
13
|
+
o = Opcode.new(name)
|
14
|
+
o.bin = bin
|
15
|
+
|
16
|
+
args.each { |a|
|
17
|
+
o.args << a if @valid_args[a]
|
18
|
+
o.props[a] = true if @valid_props[a]
|
19
|
+
}
|
20
|
+
o.args << :i16 if o.bin >= 90 and o.props.empty? # HAVE_ARGUMENT
|
21
|
+
|
22
|
+
@opcode_list << o
|
23
|
+
end
|
24
|
+
|
25
|
+
def init_opcode_list
|
26
|
+
@opcode_list = []
|
27
|
+
|
28
|
+
@valid_args[:u8] = true
|
29
|
+
@valid_args[:i16] = true
|
30
|
+
@valid_args[:cmp] = true
|
31
|
+
|
32
|
+
addop 'STOP_CODE', 0, :stopexec
|
33
|
+
addop 'POP_TOP', 1
|
34
|
+
addop 'ROT_TWO', 2
|
35
|
+
addop 'ROT_THREE', 3
|
36
|
+
addop 'DUP_TOP', 4
|
37
|
+
addop 'ROT_FOUR', 5
|
38
|
+
addop 'NOP', 9
|
39
|
+
|
40
|
+
addop 'UNARY_POSITIVE', 10
|
41
|
+
addop 'UNARY_NEGATIVE', 11
|
42
|
+
addop 'UNARY_NOT', 12
|
43
|
+
addop 'UNARY_CONVERT', 13
|
44
|
+
|
45
|
+
addop 'UNARY_INVERT', 15
|
46
|
+
|
47
|
+
addop 'BINARY_POWER', 19
|
48
|
+
|
49
|
+
addop 'BINARY_MULTIPLY', 20
|
50
|
+
addop 'BINARY_DIVIDE', 21
|
51
|
+
addop 'BINARY_MODULO', 22
|
52
|
+
addop 'BINARY_ADD', 23
|
53
|
+
addop 'BINARY_SUBTRACT', 24
|
54
|
+
addop 'BINARY_SUBSCR', 25
|
55
|
+
addop 'BINARY_FLOOR_DIVIDE', 26
|
56
|
+
addop 'BINARY_TRUE_DIVIDE', 27
|
57
|
+
addop 'INPLACE_FLOOR_DIVIDE', 28
|
58
|
+
addop 'INPLACE_TRUE_DIVIDE', 29
|
59
|
+
|
60
|
+
addop 'SLICE', 30
|
61
|
+
addop 'SLICE_1', 31
|
62
|
+
addop 'SLICE_2', 32
|
63
|
+
addop 'SLICE_3', 33
|
64
|
+
|
65
|
+
addop 'STORE_SLICE', 40
|
66
|
+
addop 'STORE_SLICE_1', 41
|
67
|
+
addop 'STORE_SLICE_2', 42
|
68
|
+
addop 'STORE_SLICE_3', 43
|
69
|
+
|
70
|
+
addop 'DELETE_SLICE', 50
|
71
|
+
addop 'DELETE_SLICE_1', 51
|
72
|
+
addop 'DELETE_SLICE_2', 52
|
73
|
+
addop 'DELETE_SLICE_3', 53
|
74
|
+
|
75
|
+
addop 'STORE_MAP', 54
|
76
|
+
addop 'INPLACE_ADD', 55
|
77
|
+
addop 'INPLACE_SUBTRACT', 56
|
78
|
+
addop 'INPLACE_MULTIPLY', 57
|
79
|
+
addop 'INPLACE_DIVIDE', 58
|
80
|
+
addop 'INPLACE_MODULO', 59
|
81
|
+
addop 'STORE_SUBSCR', 60
|
82
|
+
addop 'DELETE_SUBSCR', 61
|
83
|
+
|
84
|
+
addop 'BINARY_LSHIFT', 62
|
85
|
+
addop 'BINARY_RSHIFT', 63
|
86
|
+
addop 'BINARY_AND', 64
|
87
|
+
addop 'BINARY_XOR', 65
|
88
|
+
addop 'BINARY_OR', 66
|
89
|
+
addop 'INPLACE_POWER', 67
|
90
|
+
addop 'GET_ITER', 68
|
91
|
+
|
92
|
+
addop 'PRINT_EXPR', 70
|
93
|
+
addop 'PRINT_ITEM', 71
|
94
|
+
addop 'PRINT_NEWLINE', 72
|
95
|
+
addop 'PRINT_ITEM_TO', 73
|
96
|
+
addop 'PRINT_NEWLINE_TO', 74
|
97
|
+
addop 'INPLACE_LSHIFT', 75
|
98
|
+
addop 'INPLACE_RSHIFT', 76
|
99
|
+
addop 'INPLACE_AND', 77
|
100
|
+
addop 'INPLACE_XOR', 78
|
101
|
+
addop 'INPLACE_OR', 79
|
102
|
+
addop 'BREAK_LOOP', 80
|
103
|
+
addop 'WITH_CLEANUP', 81
|
104
|
+
addop 'LOAD_LOCALS', 82
|
105
|
+
addop 'RETURN_VALUE', 83
|
106
|
+
addop 'IMPORT_STAR', 84
|
107
|
+
addop 'EXEC_STMT', 85
|
108
|
+
addop 'YIELD_VALUE', 86
|
109
|
+
addop 'POP_BLOCK', 87
|
110
|
+
addop 'END_FINALLY', 88
|
111
|
+
addop 'BUILD_CLASS', 89
|
112
|
+
|
113
|
+
#addop 'HAVE_ARGUMENT', 90 #/* Opcodes from here have an argument: */
|
114
|
+
|
115
|
+
addop 'STORE_NAME', 90 #/* Index in name list */
|
116
|
+
addop 'DELETE_NAME', 91 #/* "" */
|
117
|
+
addop 'UNPACK_SEQUENCE', 92 #/* Number of sequence items */
|
118
|
+
addop 'FOR_ITER', 93, :setip
|
119
|
+
addop 'LIST_APPEND', 94
|
120
|
+
|
121
|
+
addop 'STORE_ATTR', 95 #/* Index in name list */
|
122
|
+
addop 'DELETE_ATTR', 96 #/* "" */
|
123
|
+
addop 'STORE_GLOBAL', 97 #/* "" */
|
124
|
+
addop 'DELETE_GLOBAL', 98 #/* "" */
|
125
|
+
addop 'DUP_TOPX', 99 #/* number of items to duplicate */
|
126
|
+
addop 'LOAD_CONST', 100 #/* Index in const list */
|
127
|
+
addop 'LOAD_NAME', 101 #/* Index in name list */
|
128
|
+
addop 'BUILD_TUPLE', 102 #/* Number of tuple items */
|
129
|
+
addop 'BUILD_LIST', 103 #/* Number of list items */
|
130
|
+
addop 'BUILD_SET', 104 #/* Number of set items */
|
131
|
+
addop 'BUILD_MAP', 105 #/* Always zero for now */
|
132
|
+
addop 'LOAD_ATTR', 106 #/* Index in name list */
|
133
|
+
addop 'COMPARE_OP', 107, :cmp #/* Comparison operator */
|
134
|
+
addop 'IMPORT_NAME', 108 #/* Index in name list */
|
135
|
+
addop 'IMPORT_FROM', 109 #/* Index in name list */
|
136
|
+
addop 'JUMP_FORWARD', 110, :setip, :stopexec #/* Number of bytes to skip */
|
137
|
+
|
138
|
+
addop 'JUMP_IF_FALSE_OR_POP', 111, :setip #/* Target byte offset from beginning of code */
|
139
|
+
addop 'JUMP_IF_TRUE_OR_POP', 112, :setip #/* "" */
|
140
|
+
addop 'JUMP_ABSOLUTE', 113, :setip, :stopexec #/* "" */
|
141
|
+
addop 'POP_JUMP_IF_FALSE', 114, :setip #/* "" */
|
142
|
+
addop 'POP_JUMP_IF_TRUE', 115, :setip #/* "" */
|
143
|
+
|
144
|
+
addop 'LOAD_GLOBAL', 116 #/* Index in name list */
|
145
|
+
|
146
|
+
addop 'CONTINUE_LOOP', 119 #/* Start of loop (absolute) */
|
147
|
+
addop 'SETUP_LOOP', 120 #/* Target address (relative) */
|
148
|
+
addop 'SETUP_EXCEPT', 121 #/* "" */
|
149
|
+
addop 'SETUP_FINALLY', 122 #/* "" */
|
150
|
+
|
151
|
+
addop 'LOAD_FAST', 124 #/* Local variable number */
|
152
|
+
addop 'STORE_FAST', 125 #/* Local variable number */
|
153
|
+
addop 'DELETE_FAST', 126 #/* Local variable number */
|
154
|
+
|
155
|
+
addop 'RAISE_VARARGS', 130 #/* Number of raise arguments (1, 2 or 3) */
|
156
|
+
#/* CALL_FUNCTION_XXX opcodes defined below depend on this definition */
|
157
|
+
addop 'CALL_FUNCTION', 131, :u8, :u8, :setip #/* #args + (#kwargs<<8) */
|
158
|
+
addop 'MAKE_FUNCTION', 132 #/* #defaults */
|
159
|
+
addop 'BUILD_SLICE', 133 #/* Number of items */
|
160
|
+
|
161
|
+
addop 'MAKE_CLOSURE', 134 #/* #free vars */
|
162
|
+
addop 'LOAD_CLOSURE', 135 #/* Load free variable from closure */
|
163
|
+
addop 'LOAD_DEREF', 136 #/* Load and dereference from closure cell */
|
164
|
+
addop 'STORE_DEREF', 137 #/* Store into cell */
|
165
|
+
|
166
|
+
#/* The next 3 opcodes must be contiguous and satisfy (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */
|
167
|
+
addop 'CALL_FUNCTION_VAR', 140, :u8, :u8, :setip #/* #args + (#kwargs<<8) */
|
168
|
+
addop 'CALL_FUNCTION_KW', 141, :u8, :u8, :setip #/* #args + (#kwargs<<8) */
|
169
|
+
addop 'CALL_FUNCTION_VAR_KW', 142, :u8, :u8, :setip #/* #args + (#kwargs<<8) */
|
170
|
+
|
171
|
+
addop 'SETUP_WITH', 143
|
172
|
+
|
173
|
+
#/* Support for opargs more than 16 bits long */
|
174
|
+
addop 'EXTENDED_ARG', 145
|
175
|
+
|
176
|
+
addop 'SET_ADD', 146
|
177
|
+
addop 'MAP_ADD', 147
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -3,7 +3,7 @@
|
|
3
3
|
#
|
4
4
|
# Licence is LGPL, see LICENCE in the top-level directory
|
5
5
|
|
6
|
-
require 'metasm/sh4/opcodes'
|
6
|
+
require 'metasm/cpu/sh4/opcodes'
|
7
7
|
require 'metasm/decode'
|
8
8
|
|
9
9
|
module Metasm
|
@@ -39,7 +39,7 @@ class Sh4
|
|
39
39
|
end
|
40
40
|
|
41
41
|
def decode_findopcode(edata)
|
42
|
-
return if edata.ptr >= edata.
|
42
|
+
return if edata.ptr >= edata.length
|
43
43
|
|
44
44
|
di = DecodedInstruction.new(self)
|
45
45
|
val = edata.decode_imm(:u16, @endianness)
|
@@ -110,7 +110,6 @@ class Sh4
|
|
110
110
|
when :pr; PR.new
|
111
111
|
when :fpul; FPUL.new
|
112
112
|
when :fpscr; FPSCR.new
|
113
|
-
when :dbr; DBR.new
|
114
113
|
when :pc; PC.new
|
115
114
|
|
116
115
|
when :@rm, :@rn, :@disppc
|
@@ -137,25 +136,49 @@ class Sh4
|
|
137
136
|
}
|
138
137
|
|
139
138
|
di.bin_length += edata.ptr - before_ptr
|
139
|
+
|
140
|
+
return if edata.ptr > edata.length
|
141
|
+
|
140
142
|
di
|
141
143
|
end
|
142
144
|
|
143
145
|
def disassembler_default_func
|
144
146
|
df = DecodedFunction.new
|
145
147
|
df.backtrace_binding = {}
|
146
|
-
|
148
|
+
(0..7 ).each { |i| r = "r#{i}".to_sym ; df.backtrace_binding[r] = Expression::Unknown }
|
149
|
+
(8..15).each { |i| r = "r#{i}".to_sym ; df.backtrace_binding[r] = Expression[r] }
|
147
150
|
df.backtracked_for = [BacktraceTrace.new(Expression[:pr], :default, Expression[:pr], :x)]
|
148
151
|
df.btfor_callback = lambda { |dasm, btfor, funcaddr, calladdr|
|
149
152
|
if funcaddr != :default
|
150
153
|
btfor
|
151
154
|
elsif di = dasm.decoded[calladdr] and di.opcode.props[:saveip]
|
152
155
|
btfor
|
153
|
-
else
|
156
|
+
else
|
157
|
+
[]
|
154
158
|
end
|
155
159
|
}
|
156
160
|
df
|
157
161
|
end
|
158
162
|
|
163
|
+
def backtrace_update_function_binding(dasm, faddr, f, retaddrlist, *wantregs)
|
164
|
+
retaddrlist.map! { |retaddr| dasm.decoded[retaddr] ? dasm.decoded[retaddr].block.list.last.address : retaddr } if retaddrlist
|
165
|
+
b = f.backtrace_binding
|
166
|
+
|
167
|
+
bt_val = lambda { |r|
|
168
|
+
next if not retaddrlist
|
169
|
+
bt = []
|
170
|
+
b[r] = Expression::Unknown # break recursive dep
|
171
|
+
retaddrlist.each { |retaddr|
|
172
|
+
bt |= dasm.backtrace(Expression[r], retaddr,
|
173
|
+
:include_start => true, :snapshot_addr => faddr, :origin => retaddr)
|
174
|
+
}
|
175
|
+
b[r] = ((bt.length == 1) ? bt.first : Expression::Unknown)
|
176
|
+
}
|
177
|
+
wantregs = GPR::Sym if wantregs.empty?
|
178
|
+
wantregs.map { |r| r.to_sym }.each(&bt_val)
|
179
|
+
end
|
180
|
+
|
181
|
+
|
159
182
|
# interprets a condition code (in an opcode name) as an expression
|
160
183
|
def decode_cmp_expr(di, a0, a1)
|
161
184
|
case di.opcode.name
|
@@ -197,6 +220,7 @@ class Sh4
|
|
197
220
|
when 'stc.w', 'stc.b', 'mov.w', 'mov.b'
|
198
221
|
lambda { |di, a0, a1| { a1 => Expression[a0, :&, mask[di]] }}
|
199
222
|
when 'movt'; lambda { |di, a0| { a0 => :t_bit }}
|
223
|
+
when 'mova'; lambda { |di, a0, a1| { a1 => Expression[a0] }}
|
200
224
|
when 'exts.b', 'exts.w', 'extu.w'
|
201
225
|
lambda { |di, a0, a1| { a1 => Expression[a0, :&, mask[di]] }}
|
202
226
|
when 'cmp/eq', 'cmp/ge', 'cmp/ge', 'cmp/gt', 'cmp/hi', 'cmp/hs'
|
@@ -212,12 +236,12 @@ class Sh4
|
|
212
236
|
when 'clrt'; lambda { |di| { :t_bit => 0 }}
|
213
237
|
when 'clrmac'; lambda { |di| { :macl => 0, :mach => 0 }}
|
214
238
|
when 'jmp'; lambda { |di, a0| { :pc => a0 }}
|
215
|
-
when 'jsr'; lambda { |di, a0| { :pc => Expression[a0], :pr => Expression[di.address
|
239
|
+
when 'jsr', 'bsr', 'bsrf'; lambda { |di, a0| { :pc => Expression[a0], :pr => Expression[di.address, :+, 2*2] }}
|
216
240
|
when 'dt'; lambda { |di, a0|
|
217
241
|
res = Expression[a0, :-, 1]
|
218
242
|
{ :a0 => res, :t_bit => Expression[res, :==, 0] }
|
219
243
|
}
|
220
|
-
when 'add' ; lambda { |di, a0, a1| { a1 => Expression[a0, :+, a1] }}
|
244
|
+
when 'add' ; lambda { |di, a0, a1| { a1 => Expression[[a0, :+, a1], :&, 0xffff_ffff] }}
|
221
245
|
when 'addc' ; lambda { |di, a0, a1|
|
222
246
|
res = Expression[[a0, :&, mask[di]], :+, [[a1, :&, mask[di]], :+, :t_bit]]
|
223
247
|
{ a1 => Expression[a0, :+, [a1, :+, :t_bit]], :t_bit => Expression[res, :>, mask[di]] }
|
@@ -252,17 +276,16 @@ class Sh4
|
|
252
276
|
shift_bit = Expression[a0, :&, 1]
|
253
277
|
{ a0 => Expression[a0, :>>, 1], :t_bit => shift_bit }
|
254
278
|
}
|
255
|
-
when 'sub'; lambda { |di, a0, a1| { a1 => Expression[
|
256
|
-
when 'subc'; lambda { |di, a0, a1| { a1 => Expression[
|
279
|
+
when 'sub'; lambda { |di, a0, a1| { a1 => Expression[[a1, :-, a0], :&, 0xffff_ffff] }}
|
280
|
+
when 'subc'; lambda { |di, a0, a1| { a1 => Expression[a1, :-, [a0, :-, :t_bit]] }}
|
257
281
|
when 'and', 'and.b'; lambda { |di, a0, a1| { a1 => Expression[[a0, :&, mask[di]], :|, [[a1, :&, mask[di]]]] }}
|
258
282
|
when 'or', 'or.b'; lambda { |di, a0, a1| { a1 => Expression[[a0, :|, mask[di]], :|, [[a1, :&, mask[di]]]] }}
|
259
283
|
when 'xor', 'xor.b'; lambda { |di, a0, a1| { a1 => Expression[[a0, :|, mask[di]], :^, [[a1, :&, mask[di]]]] }}
|
260
|
-
when 'add', 'addc', 'addv'; lambda { |di, a0, a1| { a1 => Expression[a0, :+, a1] }}
|
261
284
|
when 'neg' ; lambda { |di, a0, a1| { a1 => Expression[mask[di], :-, a0] }}
|
262
285
|
when 'negc' ; lambda { |di, a0, a1| { a1 => Expression[[[mask[di], :-, a0], :-, :t_bit], :&, mask[di]] }}
|
263
286
|
when 'not'; lambda { |di, a0, a1| { a1 => Expression[a0, :^, mask[di]] }}
|
264
|
-
when 'nop'; lambda { {} }
|
265
|
-
when /^b/; lambda { {} } # branches
|
287
|
+
when 'nop'; lambda { |*a| {} }
|
288
|
+
when /^b/; lambda { |*a| {} } # branches
|
266
289
|
end
|
267
290
|
}
|
268
291
|
|
@@ -283,12 +306,15 @@ class Sh4
|
|
283
306
|
if binding = backtrace_binding[di.opcode.basename]
|
284
307
|
bd = binding[di, *a] || {}
|
285
308
|
di.instruction.args.grep(Memref).each { |m|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
309
|
+
next unless r = m.base and r.kind_of?(GPR)
|
310
|
+
r = r.symbolic
|
311
|
+
case m.action
|
312
|
+
when :post
|
313
|
+
bd[r] ||= Expression[r, :+, di.opcode.props[:memsz]/8]
|
314
|
+
when :pre
|
315
|
+
bd[r] ||= Expression[r, :-, di.opcode.props[:memsz]/8]
|
290
316
|
end
|
291
|
-
}
|
317
|
+
}
|
292
318
|
bd
|
293
319
|
else
|
294
320
|
puts "unhandled instruction to backtrace: #{di}" if $VERBOSE
|
@@ -310,6 +336,11 @@ class Sh4
|
|
310
336
|
else val
|
311
337
|
end
|
312
338
|
|
339
|
+
val = case di.instruction.opname
|
340
|
+
when 'braf', 'bsrf'; Expression[[di.address, :+, 4], :+, val]
|
341
|
+
else val
|
342
|
+
end
|
343
|
+
|
313
344
|
[Expression[val]]
|
314
345
|
end
|
315
346
|
|
@@ -257,6 +257,8 @@ class Sh4 < CPU
|
|
257
257
|
b = @base
|
258
258
|
b = b.symbolic if b.kind_of? Reg
|
259
259
|
|
260
|
+
b = Expression[b, :-, sz/8] if @action == :pre
|
261
|
+
|
260
262
|
if disp
|
261
263
|
o = @disp
|
262
264
|
o = o.symbolic if o.kind_of? Reg
|
@@ -272,12 +274,16 @@ class Sh4 < CPU
|
|
272
274
|
|
273
275
|
def render
|
274
276
|
if @disp
|
275
|
-
['@(', @base, ',', @disp, ')']
|
277
|
+
#['@(', @base, ',', @disp, ')']
|
278
|
+
['[', @base, '+', @disp, ']']
|
276
279
|
else
|
277
280
|
case @action
|
278
|
-
when :pre then ['
|
279
|
-
when :post then ['
|
280
|
-
else ['
|
281
|
+
when :pre then ['[--', @base, ']']
|
282
|
+
when :post then ['[', @base, '++]']
|
283
|
+
else ['[', @base, ']']
|
284
|
+
#when :pre then ['@-', @base]
|
285
|
+
#when :post then ['@', @base, '+']
|
286
|
+
#else ['@', @base]
|
281
287
|
end
|
282
288
|
end
|
283
289
|
end
|
@@ -288,5 +294,8 @@ class Sh4 < CPU
|
|
288
294
|
init
|
289
295
|
end
|
290
296
|
|
297
|
+
def dbg_register_list
|
298
|
+
@dbg_register_list ||= GPR::Sym
|
299
|
+
end
|
291
300
|
end
|
292
301
|
end
|
@@ -3,18 +3,17 @@
|
|
3
3
|
#
|
4
4
|
# Licence is LGPL, see LICENCE in the top-level directory
|
5
5
|
|
6
|
-
require 'metasm/sh4/main'
|
6
|
+
require 'metasm/cpu/sh4/main'
|
7
7
|
|
8
8
|
module Metasm
|
9
9
|
class Sh4
|
10
10
|
def addop(name, bin, *args)
|
11
11
|
o = Opcode.new name, bin
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
o.fields[f] = [@fields_mask[f], @fields_shift[f]]
|
13
|
+
args.each { |a|
|
14
|
+
o.args << a if @fields_mask[a]
|
15
|
+
o.props[a] = true if @valid_props[a]
|
16
|
+
o.fields[a] = [@fields_mask[a], @fields_shift[a]] if @fields_mask[a]
|
18
17
|
}
|
19
18
|
|
20
19
|
@opcode_list << o
|
@@ -74,7 +73,7 @@ class Sh4
|
|
74
73
|
# implicit operands
|
75
74
|
[:vbr, :gbr, :sr, :ssr, :spc, :sgr, :dbr, :mach, :macl, :pr, :fpul, :fpscr, :dbr, :pc, :r0].each { |a| @fields_mask[a] = @fields_shift[a] = 0 }
|
76
75
|
|
77
|
-
@valid_props
|
76
|
+
@valid_props[:delay_slot] = true
|
78
77
|
|
79
78
|
addop 'add', 0b0011 << 12 | 0b1100, :rm, :rn
|
80
79
|
addop 'add', 0b0111 << 12, :s8, :rn
|
@@ -275,7 +274,7 @@ class Sh4
|
|
275
274
|
addop 'mov.w', 0b10000101 << 8, :@disprm, :r0
|
276
275
|
|
277
276
|
addop 'mova', 0b11000111 << 8, :disppc, :r0 # calculates an effective address using PC-relative with displacement addressing
|
278
|
-
addop 'movca.l', 0b0000 << 12 | 11000011, :r0, :@rn # stores the long-word in R0 to memory at the effective address specified in Rn.
|
277
|
+
addop 'movca.l', 0b0000 << 12 | 11000011, :r0, :@rn # stores the long-word in R0 to memory at the effective address specified in Rn.
|
279
278
|
|
280
279
|
addop 'movt', 0b0000 << 12 | 0b00101001, :rn # copies the T-bit to Rn
|
281
280
|
|