Opdis 1.3.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/ChangeLog +2 -0
- data/LICENSE +674 -0
- data/LICENSE.README +8 -0
- data/README +101 -0
- data/examples/array_linear.rb +23 -0
- data/examples/bfd_entry.rb +24 -0
- data/examples/bfd_section.rb +24 -0
- data/examples/bfd_symbol.rb +27 -0
- data/examples/buf_linear.rb +25 -0
- data/examples/decoder.rb +45 -0
- data/examples/file_linear.rb +31 -0
- data/examples/libopcodes_options.rb +11 -0
- data/examples/resolver.rb +191 -0
- data/examples/supported_architectures.rb +11 -0
- data/examples/visited_handler.rb +61 -0
- data/examples/x86_decoder.rb +46 -0
- data/lib/Opdis.rb +123 -0
- data/module/Arch.c +364 -0
- data/module/Arch.h +37 -0
- data/module/Callbacks.c +266 -0
- data/module/Callbacks.h +43 -0
- data/module/Model.c +1275 -0
- data/module/Model.h +230 -0
- data/module/Opdis.c +850 -0
- data/module/Opdis.h +89 -0
- data/module/extconf.rb +126 -0
- data/module/rdoc_input/Callbacks.rb +143 -0
- data/module/rdoc_input/Model.rb +636 -0
- data/module/rdoc_input/Opdis.rb +253 -0
- data/module/ruby_compat.c +72 -0
- data/module/ruby_compat.h +25 -0
- data/tests/ut_opdis.rb +30 -0
- data/tests/ut_opdis_bfd.rb +556 -0
- metadata +109 -0
@@ -0,0 +1,61 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Opdis Example: Visited Address Tracker
|
3
|
+
# Custom Visited Address Tracker used in control-flow disassembly of
|
4
|
+
# BFD entry point
|
5
|
+
# Copyright 2010 Thoughtgang <http://www.thoughtgang.org>
|
6
|
+
|
7
|
+
require 'BFD'
|
8
|
+
require 'Opdis'
|
9
|
+
|
10
|
+
# ----------------------------------------------------------------------
|
11
|
+
class CustomTracker < Opdis::VisitedAddressTracker
|
12
|
+
|
13
|
+
attr_reader :visited_addresses
|
14
|
+
|
15
|
+
def initialize()
|
16
|
+
@visited_addresses = {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def visited?( insn )
|
20
|
+
return @visited_addresses.fetch(insn.vma, false)
|
21
|
+
end
|
22
|
+
|
23
|
+
def visit( insn )
|
24
|
+
@visited_addresses[insn.vma] = true
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
# ----------------------------------------------------------------------
|
30
|
+
# print an instruction in the standard disasm listing format:
|
31
|
+
# VMA 8_hex_bytes instruction
|
32
|
+
def print_insn(insn)
|
33
|
+
hex_str = insn.bytes.bytes.collect { |b| "%02X" % b }.join(' ')
|
34
|
+
puts "%08X %-23.23s %s" % [ insn.vma, hex_str, insn.ascii ]
|
35
|
+
end
|
36
|
+
|
37
|
+
# ----------------------------------------------------------------------
|
38
|
+
def disasm_entry( tgt )
|
39
|
+
# custom resolver to use in disassembler
|
40
|
+
tracker = CustomTracker.new
|
41
|
+
|
42
|
+
Opdis::Disassembler.new( :addr_tracker => tracker ) do |dis|
|
43
|
+
|
44
|
+
dis.disasm_entry( tgt ) do |insn|
|
45
|
+
# Store instruction as having been visited
|
46
|
+
tracker.visit(insn)
|
47
|
+
|
48
|
+
# Print instructions in order of VMA
|
49
|
+
end.values.sort_by{ |i| i.vma }.each { |i| print_insn(i) }
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# ----------------------------------------------------------------------
|
54
|
+
if __FILE__ == $0
|
55
|
+
raise "Usage: #{$0} FILE [FILE...]" if ARGV.length == 0
|
56
|
+
|
57
|
+
ARGV.each do |filename|
|
58
|
+
Bfd::Target.new(filename) { |f| disasm_entry( f ) }
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Opdis Example: X86Decoder
|
3
|
+
# Custom X86 Decoder used in linear disassembly of array of bytes
|
4
|
+
# Copyright 2010 Thoughtgang <http://www.thoughtgang.org>
|
5
|
+
|
6
|
+
require 'BFD'
|
7
|
+
require 'Opdis'
|
8
|
+
|
9
|
+
# ----------------------------------------------------------------------
|
10
|
+
# Decoder that wraps X86AttDecoder.
|
11
|
+
class CustomX86Decoder < Opdis::X86Decoder
|
12
|
+
|
13
|
+
def decode(insn, hash)
|
14
|
+
# Invoke built-in X86 AT&T instruction decoder
|
15
|
+
super(insn, hash)
|
16
|
+
# TODO: something interesting
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
# ----------------------------------------------------------------------
|
22
|
+
# print an instruction in the standard disasm listing format:
|
23
|
+
# VMA 8_hex_bytes instruction
|
24
|
+
def print_insn(insn)
|
25
|
+
hex_str = insn.bytes.bytes.collect { |b| "%02X" % b }.join(' ')
|
26
|
+
puts "%08X %-23.23s %s" % [ insn.vma, hex_str, insn.ascii ]
|
27
|
+
end
|
28
|
+
|
29
|
+
# ----------------------------------------------------------------------
|
30
|
+
def disasm_bytes( bytes )
|
31
|
+
# custom decoder to use in disassembler
|
32
|
+
decoder = CustomX86Decoder.new
|
33
|
+
|
34
|
+
Opdis::Disassembler.new( :arch => 'x86', :insn_decoder => decoder ) do |dis|
|
35
|
+
|
36
|
+
dis.disassemble( bytes ) { |i| print_insn(i) }
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
# ----------------------------------------------------------------------
|
42
|
+
if __FILE__ == $0
|
43
|
+
raise "Usage: #{$0} BYTE [BYTE...]" if ARGV.length < 2
|
44
|
+
|
45
|
+
disasm_bytes( ARGV.collect { |b| b.hex } )
|
46
|
+
end
|
data/lib/Opdis.rb
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
#!/usr/bin/env/ruby1.0
|
2
|
+
# Copyright 2010 Thoughtgang <http://www.thoughtgang.org>
|
3
|
+
# Ruby additions to the Opdis module
|
4
|
+
|
5
|
+
require 'OpdisExt'
|
6
|
+
require 'tempfile' # for Disassembler#options
|
7
|
+
|
8
|
+
module Opdis
|
9
|
+
|
10
|
+
class Disassembler
|
11
|
+
|
12
|
+
=begin rdoc
|
13
|
+
|
14
|
+
The args parameter is a Hash which can contain any of the following members:
|
15
|
+
|
16
|
+
resolver:: AddressResolver object to use instead of the builtin
|
17
|
+
address resolver.
|
18
|
+
|
19
|
+
addr_tracker:: VisitedAddressTracker object to use instead of the built-in
|
20
|
+
address tracker.
|
21
|
+
|
22
|
+
insn_decoder:: InstructionDecoder object to use instead of the built-in
|
23
|
+
instruction decoder.
|
24
|
+
|
25
|
+
syntax:: Assembly language syntax to use; either SYNTAX_ATT (default) or
|
26
|
+
SYNTAX_INTEL.
|
27
|
+
|
28
|
+
debug:: Enable or disable libopdis debug mode.
|
29
|
+
|
30
|
+
options:: Options command-line string for libopcodes. See disassembler_usage()
|
31
|
+
in dis-asm.h for details.
|
32
|
+
|
33
|
+
arch:: The architecture to disassemble for. Use <i>arhcitectures</i> to
|
34
|
+
determine supported architectures.
|
35
|
+
=end
|
36
|
+
|
37
|
+
def self.new(args={})
|
38
|
+
dis = ext_new(args)
|
39
|
+
yield dis if (dis and block_given?)
|
40
|
+
return dis
|
41
|
+
end
|
42
|
+
|
43
|
+
=begin rdoc
|
44
|
+
Disassemble all bytes in a buffer. This is simply a wrapper for ext_disasm
|
45
|
+
that provides a default value for <i>args</i>.
|
46
|
+
See ext_disasm.
|
47
|
+
=end
|
48
|
+
def disassemble( target, args={}, &block ) # :yields: instruction
|
49
|
+
# Wrapper provides a default option
|
50
|
+
ext_disassemble(target, args, &block)
|
51
|
+
end
|
52
|
+
|
53
|
+
=begin rdoc
|
54
|
+
Convenience method for invoking disassemble() with STRATEGY_SINGLE.
|
55
|
+
=end
|
56
|
+
def disasm_single( target, args={}, &block )
|
57
|
+
args[:strategy] = STRATEGY_SINGLE
|
58
|
+
disassemble(target, args, &block)
|
59
|
+
end
|
60
|
+
|
61
|
+
=begin rdoc
|
62
|
+
Convenience method for invoking disassemble() with STRATEGY_LINEAR.
|
63
|
+
=end
|
64
|
+
def disasm_linear( target, args={}, &block )
|
65
|
+
args[:strategy] = STRATEGY_LINEAR
|
66
|
+
disassemble(target, args, &block)
|
67
|
+
end
|
68
|
+
|
69
|
+
=begin rdoc
|
70
|
+
Convenience method for invoking disassemble() with STRATEGY_CFLOW.
|
71
|
+
=end
|
72
|
+
def disasm_cflow( target, args={}, &block )
|
73
|
+
args[:strategy] = STRATEGY_CFLOW
|
74
|
+
disassemble(target, args, &block)
|
75
|
+
end
|
76
|
+
|
77
|
+
=begin rdoc
|
78
|
+
Convenience method for invoking disassemble() with STRATEGY_SECTION.
|
79
|
+
=end
|
80
|
+
def disasm_section( target, args={}, &block )
|
81
|
+
args[:strategy] = STRATEGY_SECTION
|
82
|
+
disassemble(target, args, &block)
|
83
|
+
end
|
84
|
+
|
85
|
+
=begin rdoc
|
86
|
+
Convenience method for invoking disassemble() with STRATEGY_SYMBOL.
|
87
|
+
=end
|
88
|
+
def disasm_symbol( target, args={}, &block )
|
89
|
+
args[:strategy] = STRATEGY_SYMBOL
|
90
|
+
disassemble(target, args, &block)
|
91
|
+
end
|
92
|
+
|
93
|
+
=begin rdoc
|
94
|
+
Convenience method for invoking disassemble() with STRATEGY_ENTRY.
|
95
|
+
=end
|
96
|
+
def disasm_entry( target, args={}, &block )
|
97
|
+
args[:strategy] = STRATEGY_ENTRY
|
98
|
+
disassemble(target, args, &block)
|
99
|
+
end
|
100
|
+
|
101
|
+
=begin rdoc
|
102
|
+
Convenience alias for disassemble().
|
103
|
+
=end
|
104
|
+
alias :disasm :disassemble
|
105
|
+
|
106
|
+
=begin rdoc
|
107
|
+
Return array of available disassembler options, as printed by libopcodes.
|
108
|
+
=end
|
109
|
+
def self.options()
|
110
|
+
opts = []
|
111
|
+
Tempfile.open("opcodes-options") do |tmp|
|
112
|
+
tmp.close
|
113
|
+
ext_usage(tmp)
|
114
|
+
tmp.open
|
115
|
+
opts.concat tmp.readlines
|
116
|
+
end
|
117
|
+
|
118
|
+
opts
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
data/module/Arch.c
ADDED
@@ -0,0 +1,364 @@
|
|
1
|
+
/* Arch.c
|
2
|
+
* Disassembler definitions for architectures supported by libopcodes
|
3
|
+
* Copyright 2010 Thoughtgang <http://www.thoughtgang.org>
|
4
|
+
* Written by TG Community Developers <community@thoughtgang.org>
|
5
|
+
* Released under the GNU Public License, version 3.
|
6
|
+
* See http://www.gnu.org/licenses/gpl.txt for details.
|
7
|
+
*/
|
8
|
+
#include <string.h>
|
9
|
+
|
10
|
+
#include "Arch.h"
|
11
|
+
|
12
|
+
static int generic_print_address_wrapper(bfd_vma vma, disassemble_info *info ) {
|
13
|
+
generic_print_address(vma, info);
|
14
|
+
return 1;
|
15
|
+
}
|
16
|
+
|
17
|
+
static const Opdis_disasm_def disasm_definitions[] = {
|
18
|
+
/* Goddamn GNU. They make it near-impossible to get a list of supported
|
19
|
+
* architectures at build OR run time. */
|
20
|
+
#ifdef ARCH_ALPHA
|
21
|
+
{"alpha", bfd_arch_alpha, bfd_mach_alpha_ev4, print_insn_alpha},
|
22
|
+
{"alphaev4", bfd_arch_alpha, bfd_mach_alpha_ev4,
|
23
|
+
print_insn_alpha},
|
24
|
+
{"alphaev5", bfd_arch_alpha, bfd_mach_alpha_ev5,
|
25
|
+
print_insn_alpha},
|
26
|
+
{"alphaev6", bfd_arch_alpha, bfd_mach_alpha_ev6,
|
27
|
+
print_insn_alpha},
|
28
|
+
#endif
|
29
|
+
#ifdef ARCH_ARM
|
30
|
+
{"big_arm", bfd_arch_arm, bfd_mach_arm_umknown,
|
31
|
+
print_insn_big_arm},
|
32
|
+
{"little_arm", bfd_arch_arm, bfd_mach_arm_unknown,
|
33
|
+
print_insn_little_arm},
|
34
|
+
// TODO: the other ARMs have to be big & little?
|
35
|
+
#endif
|
36
|
+
#ifdef ARCH_AVR
|
37
|
+
{"avr", bfd_arch_avr, bfd_mach_avr1, print_insn_avr},
|
38
|
+
{"avr1", bfd_arch_avr, bfd_mach_avr1, print_insn_avr},
|
39
|
+
{"avr2", bfd_arch_avr, bfd_mach_avr2, print_insn_avr},
|
40
|
+
{"avr25", bfd_arch_avr, bfd_mach_avr25, print_insn_avr},
|
41
|
+
{"avr3", bfd_arch_avr, bfd_mach_avr3, print_insn_avr},
|
42
|
+
{"avr31", bfd_arch_avr, bfd_mach_avr31, print_insn_avr},
|
43
|
+
{"avr35", bfd_arch_avr, bfd_mach_avr35, print_insn_avr},
|
44
|
+
{"avr4", bfd_arch_avr, bfd_mach_avr4, print_insn_avr},
|
45
|
+
{"avr5", bfd_arch_avr, bfd_mach_avr5, print_insn_avr},
|
46
|
+
{"avr51", bfd_arch_avr, bfd_mach_avr51, print_insn_avr},
|
47
|
+
{"avr6", bfd_arch_avr, bfd_mach_avr6, print_insn_avr},
|
48
|
+
#endif
|
49
|
+
#ifdef ARCH_BFIN
|
50
|
+
{"bfin", bfd_arch_bfin, bfd_mach_bfin, print_insn_bfin},
|
51
|
+
#endif
|
52
|
+
|
53
|
+
#ifdef ARCH_CR16
|
54
|
+
{"cr16", bfd_arch_cr16, bfd_mach_cr16, print_insn_cr16},
|
55
|
+
{"cr16c", bfd_arch_cr16c, bfd_mach_cr16c, print_insn_cr16},
|
56
|
+
#endif
|
57
|
+
#ifdef ARCH_CRX
|
58
|
+
{"crx", bfd_arch_crx, bfd_mach_crx, print_insn_crx},
|
59
|
+
#endif
|
60
|
+
#ifdef ARCH_D10V
|
61
|
+
{"d10v", bfd_arch_d10v, bfd_mach_d10v, print_insn_d10v},
|
62
|
+
{"d10v2", bfd_arch_d10v, bfd_mach_d10v_ts2, print_insn_d10v},
|
63
|
+
{"d10v3", bfd_arch_d10v, bfd_mach_d10v_ts3, print_insn_d10v},
|
64
|
+
#endif
|
65
|
+
#ifdef ARCH_D30V
|
66
|
+
{"d30v", bfd_arch_d30v, 0, print_insn_d30v},
|
67
|
+
#endif
|
68
|
+
#ifdef ARCH_DLX
|
69
|
+
{"dlx", bfd_arch_dlx, 0, print_insn_dlx},
|
70
|
+
#endif
|
71
|
+
#ifdef ARCH_FR30
|
72
|
+
{"fr30", bfd_arch_fr30, bfd_mach_fr30, print_insn_fr30},
|
73
|
+
#endif
|
74
|
+
#ifdef ARCH_FRV
|
75
|
+
{"frv", bfd_arch_frv, bfd_mach_frv, print_insn_frv},
|
76
|
+
{"frvsimple", bfd_arch_frv, bfd_mach_frvsimple, print_insn_frv},
|
77
|
+
{"fr300", bfd_arch_frv, bfd_mach_fr300, print_insn_frv},
|
78
|
+
{"fr400", bfd_arch_frv, bfd_mach_fr400, print_insn_frv},
|
79
|
+
{"fr450", bfd_arch_frv, bfd_mach_fr450, print_insn_frv},
|
80
|
+
{"frvtomcat", bfd_arch_frv, bfd_mach_frvtomcat, print_insn_frv},
|
81
|
+
{"fr500", bfd_arch_frv, bfd_mach_fr500, print_insn_frv},
|
82
|
+
{"fr550", bfd_arch_frv, bfd_mach_fr550, print_insn_frv},
|
83
|
+
#endif
|
84
|
+
#ifdef ARCH_H8300
|
85
|
+
{"h8300", bfd_arch_8300, bfd_mach_h8300, print_insn_h8300},
|
86
|
+
{"h8300h", bfd_arch_8300, bfd_mach_h8300h, print_insn_h8300h},
|
87
|
+
{"h8300hn", bfd_arch_8300, bfd_mach_h8300hn, print_insn_h8300h},
|
88
|
+
{"h8300s", bfd_arch_8300, bfd_mach_h8300s, print_insn_h8300s},
|
89
|
+
{"h8300sn", bfd_arch_8300, bfd_mach_h8300sn, print_insn_h8300s},
|
90
|
+
{"h8300sx", bfd_arch_8300, bfd_mach_h8300sx, print_insn_h8300s},
|
91
|
+
{"h8300sxn", bfd_arch_8300, bfd_mach_h8300sxn,
|
92
|
+
print_insn_h8300s},
|
93
|
+
#endif
|
94
|
+
#ifdef ARCH_H8500
|
95
|
+
{"h8500", bfd_arch_h8500, 0, print_insn_h8500},
|
96
|
+
#endif
|
97
|
+
#ifdef ARCH_HPPA
|
98
|
+
{"hppa", bfd_arch_hppa, bfd_mach_hppa10, print_insn_hppa},
|
99
|
+
{"hppa11", bfd_arch_hppa, bfd_mach_hppa11, print_insn_hppa},
|
100
|
+
{"hppa20", bfd_arch_hppa, bfd_mach_hppa20, print_insn_hppa},
|
101
|
+
{"hppa20w", bfd_arch_hppa, bfd_mach_hppa20w, print_insn_hppa},
|
102
|
+
#endif
|
103
|
+
#ifdef ARCH_I370
|
104
|
+
{"i370", bfd_arch_i370, 0, print_insn_i370},
|
105
|
+
#endif
|
106
|
+
#ifdef ARCH_I386
|
107
|
+
{"8086", bfd_arch_i386, bfd_mach_i386_i8086, print_insn_i386},
|
108
|
+
{"x86", bfd_arch_i386, bfd_mach_i386_i386, print_insn_i386},
|
109
|
+
{"x86_att", bfd_arch_i386, bfd_mach_i386_i386,
|
110
|
+
print_insn_i386_att},
|
111
|
+
{"x86_intel", bfd_arch_i386, bfd_mach_i386_i386_intel_syntax,
|
112
|
+
print_insn_i386_intel},
|
113
|
+
{"x86_64", bfd_arch_i386, bfd_mach_x86_64, print_insn_i386},
|
114
|
+
{"x86_64_att", bfd_arch_i386, bfd_mach_x86_64, print_insn_i386},
|
115
|
+
{"x86_64_intel", bfd_arch_i386, bfd_mach_x86_64_intel_syntax,
|
116
|
+
print_insn_i386},
|
117
|
+
#endif
|
118
|
+
#ifdef ARCH_i860
|
119
|
+
{"i860", bfd_arch_i860, 0, print_insn_i860},
|
120
|
+
#endif
|
121
|
+
#ifdef ARCH_i960
|
122
|
+
{"i960", bfd_arch_i960, bfd_mach_i960_core, print_insn_i960},
|
123
|
+
{"i960_hx", bfd_arch_i960, bfd_mach_i960_hx, print_insn_i960},
|
124
|
+
#endif
|
125
|
+
#ifdef ARCH_ia64
|
126
|
+
{"ia64", bfd_arch_ia64, bfd_mach_ia64_elf64, print_insn_ia64},
|
127
|
+
{"ia64_32", bfd_arch_ia64, bfd_mach_ia64_elf32,
|
128
|
+
print_insn_ia64},
|
129
|
+
#endif
|
130
|
+
#ifdef ARCH_IP2K
|
131
|
+
{"ip2k", bfd_arch_ip2k, bfd_mach_ip2022, print_insn_ip2k},
|
132
|
+
{"ip2kext", bfd_arch_ip2k, bfd_mach_ip2022ext, print_insn_ip2k},
|
133
|
+
#endif
|
134
|
+
#ifdef ARCH_IQ2000
|
135
|
+
{"iq2000", bfd_arch_iq2000, bfd_mach_iq2000, print_insn_iq2000},
|
136
|
+
{"iq10", bfd_arch_iq2000, bfd_mach_iq10, print_insn_iq2000},
|
137
|
+
#endif
|
138
|
+
#ifdef ARCH_LM32
|
139
|
+
{"lm32", bfd_arch_lm32, bfd_mach_lm32, print_insn_lm32},
|
140
|
+
#endif
|
141
|
+
#ifdef ARCH_M32C
|
142
|
+
{"m32c", bfd_arch_m32c, bfd_mach_m32c, print_insn_m32c},
|
143
|
+
{"m16c", bfd_arch_m32c, bfd_mach_m16c, print_insn_m32c},
|
144
|
+
#endif
|
145
|
+
#ifdef ARCH_M32R
|
146
|
+
{"m32r", bfd_arch_m32r, bfd_mach_m32r, print_insn_m32r},
|
147
|
+
{"m32rx", bfd_arch_m32r, bfd_mach_m32rx, print_insn_m32r},
|
148
|
+
{"m32r2", bfd_arch_m32r, bfd_mach_m32r2, print_insn_m32r},
|
149
|
+
#endif
|
150
|
+
#ifdef ARCH_M68HC11
|
151
|
+
{"m68hc11", bfd_arch_m68hc11, 0, print_insn_m68hc11},
|
152
|
+
#endif
|
153
|
+
#ifdef ARCH_M68HC12
|
154
|
+
{"m68hc12", bfd_arch_m68hc12, bfd_mach_m6812_default,
|
155
|
+
print_insn_m68hc12},
|
156
|
+
{"m68hc12s", bfd_arch_m68hc12, bfd_mach_m6812s,
|
157
|
+
print_insn_m68hc12},
|
158
|
+
#endif
|
159
|
+
#ifdef ARCH_M68K
|
160
|
+
{"m68k", bfd_arch_m68k, bfd_mach_m68000, print_insn_m68k},
|
161
|
+
{"m68008", bfd_arch_m68k, bfd_mach_m68008, print_insn_m68k},
|
162
|
+
{"m68010", bfd_arch_m68k, bfd_mach_m68010, print_insn_m68k},
|
163
|
+
{"m68020", bfd_arch_m68k, bfd_mach_m68020, print_insn_m68k},
|
164
|
+
{"m68030", bfd_arch_m68k, bfd_mach_m68030, print_insn_m68k},
|
165
|
+
{"m68040", bfd_arch_m68k, bfd_mach_m68040, print_insn_m68k},
|
166
|
+
{"m68060", bfd_arch_m68k, bfd_mach_m68060, print_insn_m68k},
|
167
|
+
{"m68060", bfd_arch_m68k, bfd_mach_m68060, print_insn_m68k},
|
168
|
+
{"m68k_cpu32", bfd_arch_m68k, bfd_mach_cpu32, print_insn_m68k},
|
169
|
+
{"m68k_fido", bfd_arch_m68k, bfd_mach_fido, print_insn_m68k},
|
170
|
+
#endif
|
171
|
+
#ifdef ARCH_M88K
|
172
|
+
{"m88k", bfd_arch_m88k, 0, print_insn_m88k},
|
173
|
+
#endif
|
174
|
+
#ifdef ARCH_MAXQ
|
175
|
+
{"maxq_big", bfd_arch_maxq, 0, print_insn_maxq_big},
|
176
|
+
{"maxq_little", bfd_arch_maxq, 0, print_insn_maxq_little},
|
177
|
+
{"maxq10_big", bfd_arch_maxq, bfd_mach_maxq10,
|
178
|
+
print_insn_maxq_big},
|
179
|
+
{"maxq10_little", bfd_arch_maxq, bfd_mach_maxq10,
|
180
|
+
print_insn_maxq_little},
|
181
|
+
{"maxq20_big", bfd_arch_maxq, bfd_mach_maxq20,
|
182
|
+
print_insn_maxq_big},
|
183
|
+
{"maxq20_little", bfd_arch_maxq, bfd_mach_maxq20,
|
184
|
+
print_insn_maxq_little},
|
185
|
+
#endif
|
186
|
+
#ifdef ARCH_MCORE
|
187
|
+
{"mcore", bfd_arch_mcore, 0, print_insn_mcore},
|
188
|
+
#endif
|
189
|
+
#ifdef ARCH_MEP
|
190
|
+
{"mep", bfd_arch_mep, 0, print_insn_mep},
|
191
|
+
#endif
|
192
|
+
#ifdef ARCH_MICROBLAZE
|
193
|
+
{"microblaze", bfd_arch_microblaze, print_insn_microblaze},
|
194
|
+
#endif
|
195
|
+
#ifdef ARCH_MIPS
|
196
|
+
{"big_mips", bfd_arch_mips, 0, print_insn_big_mips},
|
197
|
+
{"little_mips", bfd_arch_mips, 0, print_insn_little_mips},
|
198
|
+
#endif
|
199
|
+
#ifdef ARCH_MMIX
|
200
|
+
{"mmix", bfd_arch_mmix, 0, print_insn_mmix},
|
201
|
+
#endif
|
202
|
+
#ifdef ARCH_MN10200
|
203
|
+
{"mn10200", bfd_arch_mn10200, 0, print_insn_mn10200},
|
204
|
+
#endif
|
205
|
+
#ifdef ARCH_MN10300
|
206
|
+
{"mn10300", bfd_arch_mn10300, bfd_mach_mn10300,
|
207
|
+
print_insn_mn10300},
|
208
|
+
#endif
|
209
|
+
#ifdef ARCH_MOXIE
|
210
|
+
{"moxie", bfd_arch_moxie, bfd_mach_moxie, print_insn_moxie},
|
211
|
+
#endif
|
212
|
+
#ifdef ARCH_MSP430
|
213
|
+
{"msp430", bfd_arch_msp430, 0, print_insn_msp430},
|
214
|
+
#endif
|
215
|
+
#ifdef ARCH_MT
|
216
|
+
{"mt", bfd_arch_mt, 0, print_insn_mt},
|
217
|
+
#endif
|
218
|
+
#ifdef ARCH_NS32K
|
219
|
+
{"ns32k", bfd_arch_ns32k, 0, print_insn_ns32k},
|
220
|
+
#endif
|
221
|
+
#ifdef ARCH_OPENRISC
|
222
|
+
{"openrisc", bfd_arch_openrisc, 0, print_insn_openrisc},
|
223
|
+
#endif
|
224
|
+
#ifdef ARCH_OR32
|
225
|
+
{"big_or32", bfd_arch_or32, 0, print_insn_big_or32},
|
226
|
+
{"little_or32", bfd_arch_or32, 0, print_insn_little_or32},
|
227
|
+
#endif
|
228
|
+
#ifdef ARCH_PDP11
|
229
|
+
{"pdp11", bfd_arch_pdp11, 0, print_insn_pdp11},
|
230
|
+
#endif
|
231
|
+
#ifdef ARCH_PJ
|
232
|
+
{"pj", bfd_arch_pj, 0, print_insn_pj},
|
233
|
+
#endif
|
234
|
+
#ifdef ARCH_POWERPC
|
235
|
+
{"big_powerpc", bfd_arch_powerpc, 0, print_insn_big_powerpc},
|
236
|
+
{"little_powerpc", bfd_arch_powerpc, 0,
|
237
|
+
print_insn_little_powerpc},
|
238
|
+
{"big_powerpc32", bfd_arch_powerpc, bfd_mach_ppc,
|
239
|
+
print_insn_big_powerpc},
|
240
|
+
{"little_powerpc32", bfd_arch_powerpc, bfd_mach_ppc,
|
241
|
+
print_insn_little_powerpc},
|
242
|
+
{"big_powerpc64", bfd_arch_powerpc, bfd_mach_ppc64,
|
243
|
+
print_insn_big_powerpc},
|
244
|
+
{"little_powerpc64", bfd_arch_powerpc, bfd_mach_ppc64,
|
245
|
+
print_insn_little_powerpc},
|
246
|
+
#endif
|
247
|
+
#ifdef ARCH_RS6000
|
248
|
+
{"rs6000", bfd_arch_rs6000, bfd_mach_rs6k, print_insn_rs6000},
|
249
|
+
#endif
|
250
|
+
#ifdef ARCH_S390
|
251
|
+
{"s390", bfd_arch_s390, 0, print_insn_s390},
|
252
|
+
#endif
|
253
|
+
#ifdef ARCH_SCORE
|
254
|
+
{"big_score", bfd_arch_score, 0, print_insn_big_score},
|
255
|
+
{"little_score", bfd_arch_score, 0, print_insn_little_score},
|
256
|
+
#endif
|
257
|
+
#ifdef ARCH_SH
|
258
|
+
{"sh", bfd_arch_sh, bfd_mach_sh, print_insn_sh},
|
259
|
+
{"sh2", bfd_arch_sh, bfd_mach_sh2, print_insn_sh},
|
260
|
+
{"sh3", bfd_arch_sh, bfd_mach_sh3, print_insn_sh},
|
261
|
+
{"sh4", bfd_arch_sh, bfd_mach_sh4, print_insn_sh},
|
262
|
+
{"sh5", bfd_arch_sh, bfd_mach_sh5, print_insn_sh},
|
263
|
+
{"sh_dsp", bfd_arch_sh, bfd_mach_sh_dsp, print_insn_sh},
|
264
|
+
{"sh64", bfd_arch_sh, bfd_mach_sh, print_insn_sh64},
|
265
|
+
{"sh64x_media", bfd_mach_sh, bfd_mach_sh,
|
266
|
+
print_insn_sh64x_media},
|
267
|
+
#endif
|
268
|
+
#ifdef ARCH_SPARC
|
269
|
+
{"sparc", bfd_arch_sparc, bfd_mach_sparc, print_insn_sparc},
|
270
|
+
{"sparclite", bfd_arch_sparc, bfd_mach_sparc_sparclite,
|
271
|
+
print_insn_sparc},
|
272
|
+
{"sparclitev9", bfd_arch_sparc, bfd_mach_sparc_v9,
|
273
|
+
print_insn_sparc},
|
274
|
+
#endif
|
275
|
+
#ifdef ARCH_SPU
|
276
|
+
{"spu", bfd_arch_spu, bfd_mach_spu, print_insn_spu},
|
277
|
+
#endif
|
278
|
+
#ifdef ARCH_TIC30
|
279
|
+
{"tic30", bfd_arch_tic30, 0, print_insn_tic30},
|
280
|
+
#endif
|
281
|
+
#ifdef ARCH_TIC4X
|
282
|
+
{"tic3x", bfd_arch_tic4x, bfd_mach_tic3x, print_insn_tic4x},
|
283
|
+
{"tic4x", bfd_arch_tic4x, bfd_mach_tic4x, print_insn_tic4x},
|
284
|
+
#endif
|
285
|
+
#ifdef ARCH_TIC54X
|
286
|
+
{"tic54x", bfd_arch_tic54x, 0, print_insn_tic54x},
|
287
|
+
#endif
|
288
|
+
#ifdef ARCH_TIC80
|
289
|
+
{"tic80", bfd_arch_tic80, 0, print_insn_tic80},
|
290
|
+
#endif
|
291
|
+
#ifdef ARCH_V850
|
292
|
+
{"v850", bfd_arch_v850, bfd_mach_v850, print_insn_v850},
|
293
|
+
#endif
|
294
|
+
#ifdef ARCH_VAX
|
295
|
+
{"vax", bfd_arch_vax, 0, print_insn_vax},
|
296
|
+
#endif
|
297
|
+
#ifdef ARCH_W65
|
298
|
+
{"w65", bfd_arch_w65, 0, print_insn_w65},
|
299
|
+
#endif
|
300
|
+
#ifdef ARCH_XC16X
|
301
|
+
{"xc16x", bfd_arch_xc16x, bfd_mach_xc16x, print_insn_xc16x},
|
302
|
+
#endif
|
303
|
+
#ifdef ARCH_XSTORMY16
|
304
|
+
{"xstormy16", bfd_arch_xstormy16, bfd_mach_xstormy16,
|
305
|
+
print_insn_xstormy16},
|
306
|
+
#endif
|
307
|
+
#ifdef ARCH_XTENSA
|
308
|
+
{"xtensa", bfd_arch_xtensa, bfd_mach_xtensa, print_insn_xtensa},
|
309
|
+
#endif
|
310
|
+
#ifdef ARCH_Z80
|
311
|
+
{"z80", bfd_arch_z80, bfd_mach_z80full, print_insn_z80},
|
312
|
+
{"z80strict", bfd_arch_z80, bfd_mach_z80strict, print_insn_z80},
|
313
|
+
{"r800", bfd_arch_z80, bfd_mach_r800, print_insn_z80},
|
314
|
+
#endif
|
315
|
+
#ifdef ARCH_Z8K
|
316
|
+
{"z8001", bfd_arch_z8k, bfd_mach_z8001, print_insn_z8001},
|
317
|
+
{"z8002", bfd_arch_z8k, bfd_mach_z8002, print_insn_z8002},
|
318
|
+
#endif
|
319
|
+
/* NULL entry to ensure table ends up ok */
|
320
|
+
{"INVALID", bfd_arch_unknown, 0, generic_print_address_wrapper}
|
321
|
+
};
|
322
|
+
|
323
|
+
void Opdis_disasm_iter( OPDIS_DISASM_ITER_FN fn, void * arg ) {
|
324
|
+
int i;
|
325
|
+
int num_defs = sizeof(disasm_definitions) / sizeof(Opdis_disasm_def);
|
326
|
+
|
327
|
+
if (! fn ) {
|
328
|
+
return;
|
329
|
+
}
|
330
|
+
|
331
|
+
for ( i = 0; i < num_defs; i++ ) {
|
332
|
+
const Opdis_disasm_def *def = &disasm_definitions[i];
|
333
|
+
if (! fn( def, arg ) ) {
|
334
|
+
break;
|
335
|
+
}
|
336
|
+
}
|
337
|
+
}
|
338
|
+
|
339
|
+
struct disasm_find_name_arg {
|
340
|
+
const char * name;
|
341
|
+
const Opdis_disasm_def * def;
|
342
|
+
};
|
343
|
+
|
344
|
+
static int is_named_def( const Opdis_disasm_def * def, void * arg ) {
|
345
|
+
struct disasm_find_name_arg * out = (struct disasm_find_name_arg *) arg;
|
346
|
+
if (! strcmp( out->name, def->name ) ) {
|
347
|
+
out->def = def;
|
348
|
+
return 0;
|
349
|
+
}
|
350
|
+
|
351
|
+
return 1;
|
352
|
+
}
|
353
|
+
|
354
|
+
const Opdis_disasm_def * Opdis_disasm_for_name( const char * name ) {
|
355
|
+
struct disasm_find_name_arg arg = { name, Opdis_disasm_invalid() };
|
356
|
+
Opdis_disasm_iter( is_named_def, &arg );
|
357
|
+
return arg.def;
|
358
|
+
}
|
359
|
+
|
360
|
+
const Opdis_disasm_def * Opdis_disasm_invalid( void ) {
|
361
|
+
int num_defs = sizeof(disasm_definitions) / sizeof(Opdis_disasm_def);
|
362
|
+
return &disasm_definitions[num_defs-1];
|
363
|
+
}
|
364
|
+
|