ruby-yasm 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/History.rdoc +4 -0
- data/Manifest.txt +17 -0
- data/README.rdoc +85 -0
- data/Rakefile +27 -0
- data/lib/yasm.rb +2 -0
- data/lib/yasm/program.rb +98 -0
- data/lib/yasm/task.rb +161 -0
- data/lib/yasm/version.rb +4 -0
- data/lib/yasm/yasm.rb +142 -0
- data/spec/helpers/files.rb +9 -0
- data/spec/helpers/files/gas.S +2 -0
- data/spec/program_spec.rb +38 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/task_spec.rb +182 -0
- data/spec/yasm_spec.rb +9 -0
- data/tasks/spec.rb +10 -0
- data/tasks/yard.rb +13 -0
- metadata +140 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
Binary file
|
data/History.rdoc
ADDED
data/Manifest.txt
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
History.rdoc
|
2
|
+
Manifest.txt
|
3
|
+
README.rdoc
|
4
|
+
Rakefile
|
5
|
+
lib/yasm.rb
|
6
|
+
lib/yasm/task.rb
|
7
|
+
lib/yasm/program.rb
|
8
|
+
lib/yasm/yasm.rb
|
9
|
+
lib/yasm/version.rb
|
10
|
+
tasks/spec.rb
|
11
|
+
tasks/yard.rb
|
12
|
+
spec/spec_helper.rb
|
13
|
+
spec/helpers/files.rb
|
14
|
+
spec/helpers/files/gas.S
|
15
|
+
spec/task_spec.rb
|
16
|
+
spec/program_spec.rb
|
17
|
+
spec/yasm_spec.rb
|
data/README.rdoc
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
= ruby-yasm
|
2
|
+
|
3
|
+
* http://www.tortall.net/projects/yasm/
|
4
|
+
* http://www.sophsec.com/
|
5
|
+
* Postmodern (postmodern.mod3 at gmail.com)
|
6
|
+
|
7
|
+
== DESCRIPTION:
|
8
|
+
|
9
|
+
A Ruby interface to YASM.
|
10
|
+
|
11
|
+
YASM is a complete rewrite of the NASM assembler, YASM currently supports
|
12
|
+
the x86 and AMD64 instruction sets, accepts NASM and GAS assembler syntaxes,
|
13
|
+
outputs binary, ELF32, ELF64, 32 and 64-bit Mach-O, RDOFF2, COFF, Win32,
|
14
|
+
and Win64 object formats, and generates source debugging information in
|
15
|
+
STABS, DWARF 2, and CodeView 8 formats.
|
16
|
+
|
17
|
+
== FEATURES:
|
18
|
+
|
19
|
+
* Supports all of the +yasm+ command-line options.
|
20
|
+
|
21
|
+
== EXAMPLES:
|
22
|
+
|
23
|
+
* Assemble a binary file:
|
24
|
+
|
25
|
+
YASM::Program.assemble do |yasm|
|
26
|
+
yasm.syntax = :gas
|
27
|
+
yasm.file = 'hello_world.S'
|
28
|
+
yasm.output = 'hello_world.o'
|
29
|
+
end
|
30
|
+
|
31
|
+
* Assemble a binary file, and write the output to a temporary file:
|
32
|
+
|
33
|
+
YASM::Program.assemble_temp do |yasm|
|
34
|
+
yasm.syntax = :gas
|
35
|
+
yasm.file = 'hello_world.S'
|
36
|
+
end
|
37
|
+
# => "/tmp/yasm.3386.0"
|
38
|
+
|
39
|
+
* Assemble amd64 assembly, in GAS syntax, into an ELF64 file with
|
40
|
+
debugging information:
|
41
|
+
|
42
|
+
YASM::Program.assemble do |yasm|
|
43
|
+
yasm.target! :amd64
|
44
|
+
|
45
|
+
yasm.syntax = :gas
|
46
|
+
yasm.file = 'hello_world.S'
|
47
|
+
|
48
|
+
yasm.output = 'hello_world.o'
|
49
|
+
yasm.output_format = :elf64
|
50
|
+
yasm.debug_format = :stabs
|
51
|
+
end
|
52
|
+
|
53
|
+
== REQUIREMENTS:
|
54
|
+
|
55
|
+
* {yasm}[http://www.tortall.net/projects/yasm/] >= 0.8.0.
|
56
|
+
* {rprogram}[http://rprogram.rubyforge.org/] >= 0.1.8.
|
57
|
+
|
58
|
+
== INSTALL:
|
59
|
+
|
60
|
+
$ sudo gem install ruby-yasm
|
61
|
+
|
62
|
+
== LICENSE:
|
63
|
+
|
64
|
+
(The MIT License)
|
65
|
+
|
66
|
+
Copyright (c) 2009 Hal Brodigan
|
67
|
+
|
68
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
69
|
+
a copy of this software and associated documentation files (the
|
70
|
+
'Software'), to deal in the Software without restriction, including
|
71
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
72
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
73
|
+
permit persons to whom the Software is furnished to do so, subject to
|
74
|
+
the following conditions:
|
75
|
+
|
76
|
+
The above copyright notice and this permission notice shall be
|
77
|
+
included in all copies or substantial portions of the Software.
|
78
|
+
|
79
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
80
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
81
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
82
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
83
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
84
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
85
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require 'hoe/signing'
|
6
|
+
require './tasks/spec.rb'
|
7
|
+
require './tasks/yard.rb'
|
8
|
+
|
9
|
+
Hoe.spec('ruby-yasm') do
|
10
|
+
self.developer('Postmodern', 'postmodern.mod3@gmail.com')
|
11
|
+
self.remote_rdoc_dir = '/'
|
12
|
+
self.readme_file = 'README.rdoc'
|
13
|
+
self.history_file = 'History.rdoc'
|
14
|
+
|
15
|
+
self.extra_deps = [
|
16
|
+
['rprogram', '>=0.1.8']
|
17
|
+
]
|
18
|
+
|
19
|
+
self.extra_dev_deps = [
|
20
|
+
['rspec', '>=1.2.9'],
|
21
|
+
['yard', '>=0.5.2']
|
22
|
+
]
|
23
|
+
|
24
|
+
self.spec_extras = {:has_rdoc => 'yard'}
|
25
|
+
end
|
26
|
+
|
27
|
+
# vim: syntax=ruby
|
data/lib/yasm.rb
ADDED
data/lib/yasm/program.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'yasm/task'
|
2
|
+
|
3
|
+
require 'rprogram'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
module YASM
|
7
|
+
class Program < RProgram::Program
|
8
|
+
|
9
|
+
name_program 'yasm'
|
10
|
+
|
11
|
+
#
|
12
|
+
# Finds the +yasm+ program and assembles a file.
|
13
|
+
#
|
14
|
+
# @param [Hash{Symbol => Object}] options
|
15
|
+
# Additional options for yasm.
|
16
|
+
#
|
17
|
+
# @yield [task]
|
18
|
+
# If a block is given, it will be passed a task object used to
|
19
|
+
# specify options for yasm.
|
20
|
+
#
|
21
|
+
# @yieldparam [Task] task
|
22
|
+
# The yasm task object.
|
23
|
+
#
|
24
|
+
# @return [Boolean]
|
25
|
+
# Specifies whether the command exited normally.
|
26
|
+
#
|
27
|
+
def self.assmeble(options={},&block)
|
28
|
+
self.find().assemble(options,&block)
|
29
|
+
end
|
30
|
+
|
31
|
+
#
|
32
|
+
# Finds the +yasm+ program, then assembles an assembly file and writes
|
33
|
+
# the output to a temporary file.
|
34
|
+
#
|
35
|
+
# @param [Hash{Symbol => Object}] options
|
36
|
+
# Additional options for yasm.
|
37
|
+
#
|
38
|
+
# @yield [task]
|
39
|
+
# If a block is given, it will be passed a task object used to
|
40
|
+
# specify options for yasm.
|
41
|
+
#
|
42
|
+
# @yieldparam [Task] task
|
43
|
+
# The yasm task object.
|
44
|
+
#
|
45
|
+
# @return [TempFile]
|
46
|
+
# The temporary file containing the assembled object code.
|
47
|
+
#
|
48
|
+
def self.assemble_temp(options={},&block)
|
49
|
+
self.find().assemble(options,&block)
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Assembles an assembly file.
|
54
|
+
#
|
55
|
+
# @param [Hash{Symbol => Object}] options
|
56
|
+
# Additional options for yasm.
|
57
|
+
#
|
58
|
+
# @yield [task]
|
59
|
+
# If a block is given, it will be passed a task object used to
|
60
|
+
# specify options for yasm.
|
61
|
+
#
|
62
|
+
# @yieldparam [Task] task
|
63
|
+
# The yasm task object.
|
64
|
+
#
|
65
|
+
# @return [Boolean]
|
66
|
+
# Specifies whether the command exited normally.
|
67
|
+
#
|
68
|
+
def assemble(options={},&block)
|
69
|
+
run_task(Task.new(options,&block))
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Assembles an assembly file and writes the output to a temporary file.
|
74
|
+
#
|
75
|
+
# @param [Hash{Symbol => Object}] options
|
76
|
+
# Additional options for yasm.
|
77
|
+
#
|
78
|
+
# @yield [task]
|
79
|
+
# If a block is given, it will be passed a task object used to
|
80
|
+
# specify options for yasm.
|
81
|
+
#
|
82
|
+
# @yieldparam [Task] task
|
83
|
+
# The yasm task object.
|
84
|
+
#
|
85
|
+
# @return [TempFile]
|
86
|
+
# The temporary file containing the assembled object code.
|
87
|
+
#
|
88
|
+
def assemble_temp(options={},&block)
|
89
|
+
task = Task.new(options,&block)
|
90
|
+
task.output = Tempfile.new('yasm').path
|
91
|
+
|
92
|
+
if run_task(task)
|
93
|
+
return task.output
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
data/lib/yasm/task.rb
ADDED
@@ -0,0 +1,161 @@
|
|
1
|
+
require 'yasm/yasm'
|
2
|
+
|
3
|
+
require 'rprogram/task'
|
4
|
+
|
5
|
+
module YASM
|
6
|
+
#
|
7
|
+
# == YASM options:
|
8
|
+
#
|
9
|
+
# <tt>--version</tt>:: <tt>yasm.version</tt>
|
10
|
+
# <tt>--license</tt>:: <tt>yasm.license</tt>
|
11
|
+
# <tt>--help</tt>:: <tt>yasm.help</tt>
|
12
|
+
#
|
13
|
+
# <tt>--arch</tt>:: <tt>yasm.arch</tt>
|
14
|
+
# <tt>--parser</tt>:: <tt>yasm.parser</tt>
|
15
|
+
# <tt>--preproc</tt>:: <tt>yasm.preprocessor</tt>
|
16
|
+
# <tt>--oformat</tt>:: <tt>yasm.output_format</tt>
|
17
|
+
# <tt>--dformat</tt>:: <tt>yasm.debug_format</tt>
|
18
|
+
# <tt>--lformat</tt>:: <tt>yasm.list_format</tt>
|
19
|
+
#
|
20
|
+
# <tt>--list</tt>:: <tt>yasm.list_file</tt>
|
21
|
+
# <tt>--objfile</tt>:: <tt>yasm.output</tt>
|
22
|
+
# <tt>--mapfile</tt>:: <tt>yasm.map_file</tt>
|
23
|
+
#
|
24
|
+
# <tt>--machine</tt>:: <tt>yasm.machine</tt>
|
25
|
+
# <tt>--force-strict</tt>:: <tt>yasm.force_strict</tt>
|
26
|
+
# <tt>-w</tt>:: <tt>yasm.inhibit_warnings</tt>
|
27
|
+
# <tt>-W</tt>:: <tt>yasm.toggle_warnings</tt>
|
28
|
+
# <tt>-M</tt>:: <tt>yasm.gen_makefile_deps</tt>
|
29
|
+
# <tt>-E</tt>:: <tt>yasm.redirect_errors_to</tt>
|
30
|
+
# <tt>-e</tt>:: <tt>yasm.redirect_errors</tt>
|
31
|
+
# <tt>--preproc-only</tt>:: <tt>yasm.preprocessor_only</tt>
|
32
|
+
# <tt>-I</tt>:: <tt>yasm.include</tt>
|
33
|
+
# <tt>-P</tt>:: <tt>yasm.pre_include</tt>
|
34
|
+
# <tt>-D</tt>:: <tt>yasm.define</tt>
|
35
|
+
# <tt>-U</tt>:: <tt>yasm.undefine</tt>
|
36
|
+
# <tt>-X</tt>:: <tt>yasm.message_style</tt>
|
37
|
+
# <tt>--prefix</tt>:: <tt>yasm.prefix</tt>
|
38
|
+
# <tt>--suffix</tt>:: <tt>yasm.suffix</tt>
|
39
|
+
#
|
40
|
+
# <tt>file</tt>:: <tt>yasm.file</tt>
|
41
|
+
#
|
42
|
+
class Task < RProgram::Task
|
43
|
+
|
44
|
+
# The known YASM targets
|
45
|
+
TARGETS = {
|
46
|
+
:x86 => {:arch => :x86, :machine => :x86},
|
47
|
+
:amd64 => {:arch => :x86, :machine => :amd64},
|
48
|
+
:lc3b => {:arch => :lc3b, :machine => :lc3b}
|
49
|
+
}
|
50
|
+
|
51
|
+
long_option :flag => '--version'
|
52
|
+
long_option :flag => '--license'
|
53
|
+
long_option :flag => '--help'
|
54
|
+
|
55
|
+
long_option :flag => '--arch', :equals => true
|
56
|
+
long_option :flag => '--parser', :equals => true
|
57
|
+
long_option :flag => '--preproc',
|
58
|
+
:equals => true,
|
59
|
+
:name => :preprocessor
|
60
|
+
long_option :flag => '--oformat',
|
61
|
+
:equals => true,
|
62
|
+
:name => :output_format
|
63
|
+
long_option :flag => '--dformat',
|
64
|
+
:equals => true,
|
65
|
+
:name => :debug_format
|
66
|
+
long_option :flag => '--lformat',
|
67
|
+
:equals => true,
|
68
|
+
:name => :list_format
|
69
|
+
|
70
|
+
long_option :flag => '--list',
|
71
|
+
:equals => true,
|
72
|
+
:name => :list_file
|
73
|
+
long_option :flag => '--objfile',
|
74
|
+
:equals => true,
|
75
|
+
:name => :output
|
76
|
+
long_option :flag => '--mapfile',
|
77
|
+
:equals => true,
|
78
|
+
:name => :map_file
|
79
|
+
|
80
|
+
long_option :flag => '--machine', :equals => true
|
81
|
+
long_option :flag => '--force-strict'
|
82
|
+
short_option :flag => '-w', :name => :inhibit_warnings
|
83
|
+
short_option :flag => '-W', :name => :toggle_warnings
|
84
|
+
short_option :flag => '-M', :name => :gen_makefile_deps
|
85
|
+
short_option :flag => '-E', :name => :redirect_errors_to
|
86
|
+
short_option :flag => '-s', :name => :redirect_errors
|
87
|
+
long_option :flag => '--preproc-only', :name => :preprocessor_only
|
88
|
+
short_option :flag => '-I', :name => :include, :multiple => true
|
89
|
+
short_option :flag => '-P', :name => :pre_include, :multiple => true
|
90
|
+
short_option :flag => '-D', :name => :define, :multiple => true
|
91
|
+
short_option :flag => '-U', :name => :undefine, :multiple => true
|
92
|
+
short_option :flag => '-X', :name => :message_style
|
93
|
+
long_option :flag => '--prefix'
|
94
|
+
long_option :flag => '--suffix'
|
95
|
+
|
96
|
+
non_option :tailing => true, :name => :file
|
97
|
+
|
98
|
+
#
|
99
|
+
# Creates a new Task object.
|
100
|
+
#
|
101
|
+
# @param [Hash{Symbol => Object}] options
|
102
|
+
# Additional options for the task.
|
103
|
+
#
|
104
|
+
# @option options [String, Symbol] :target
|
105
|
+
# The arch/machine to target.
|
106
|
+
#
|
107
|
+
# @yield [task]
|
108
|
+
# If a block is given, it will be passed the newly created task
|
109
|
+
# object.
|
110
|
+
#
|
111
|
+
# @yieldparam [Task] task
|
112
|
+
# The new task object.
|
113
|
+
#
|
114
|
+
# @see Task#target!
|
115
|
+
#
|
116
|
+
def initialize(options={},&block)
|
117
|
+
target = options.delete(:target)
|
118
|
+
|
119
|
+
super(options,&block)
|
120
|
+
|
121
|
+
self.target!(target) if target
|
122
|
+
|
123
|
+
self.parser ||= YASM.parser
|
124
|
+
self.arch ||= YASM.arch
|
125
|
+
self.machine ||= YASM.machine
|
126
|
+
self.debug_format ||= YASM.debug_format
|
127
|
+
self.output_format ||= YASM.output_format
|
128
|
+
end
|
129
|
+
|
130
|
+
#
|
131
|
+
# Sets the YASM +arch+ and +machine+.
|
132
|
+
#
|
133
|
+
# @param [String, Symbol] name
|
134
|
+
# The target name.
|
135
|
+
#
|
136
|
+
# @raise [RuntimeError]
|
137
|
+
# The specified target is unknown.
|
138
|
+
#
|
139
|
+
# @return [true]
|
140
|
+
# The YASM +arch+ and +machine+ options were set successfully.
|
141
|
+
#
|
142
|
+
# @example
|
143
|
+
# yasm.target! :amd64
|
144
|
+
#
|
145
|
+
def target!(name)
|
146
|
+
target = TARGETS[name.to_sym]
|
147
|
+
|
148
|
+
unless target
|
149
|
+
raise(RuntimeError,"unknown YASM target #{name.inspect}",caller)
|
150
|
+
end
|
151
|
+
|
152
|
+
self.arch = target[:arch]
|
153
|
+
self.machine = target[:machine]
|
154
|
+
return true
|
155
|
+
end
|
156
|
+
|
157
|
+
alias syntax parser
|
158
|
+
alias syntax= parser=
|
159
|
+
|
160
|
+
end
|
161
|
+
end
|
data/lib/yasm/version.rb
ADDED
data/lib/yasm/yasm.rb
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
module YASM
|
2
|
+
@@yasm_parser = nil
|
3
|
+
@@yasm_arch = nil
|
4
|
+
@@yasm_machine = nil
|
5
|
+
@@yasm_debug_format = nil
|
6
|
+
@@yasm_output_format = nil
|
7
|
+
|
8
|
+
#
|
9
|
+
# The default YASM parser to use.
|
10
|
+
#
|
11
|
+
# @return [Symbol]
|
12
|
+
# The YASM parser.
|
13
|
+
#
|
14
|
+
def YASM.parser
|
15
|
+
@@yasm_parser
|
16
|
+
end
|
17
|
+
|
18
|
+
#
|
19
|
+
# Sets the default YASM parser to use.
|
20
|
+
#
|
21
|
+
# @param [Symbol, String] new_parser
|
22
|
+
# The new YASM parser to use.
|
23
|
+
#
|
24
|
+
# @return [Symbol]
|
25
|
+
# The new YASM parser to use.
|
26
|
+
#
|
27
|
+
def YASM.parser=(new_parser)
|
28
|
+
@@yasm_parser = if new_parser.nil?
|
29
|
+
nil
|
30
|
+
else
|
31
|
+
new_parser.to_sym
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# The default YASM architecture to assemble for.
|
37
|
+
#
|
38
|
+
# @return [Symbol]
|
39
|
+
# The YASM architecture.
|
40
|
+
#
|
41
|
+
def YASM.arch
|
42
|
+
@@yasm_arch
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# Sets the default YASM architecture to assemble for.
|
47
|
+
#
|
48
|
+
# @param [Symbol, String] new_arch
|
49
|
+
# The new YASM architecture to assemble for.
|
50
|
+
#
|
51
|
+
# @return [Symbol]
|
52
|
+
# The new YASM architecture to assemble for.
|
53
|
+
#
|
54
|
+
def YASM.arch=(new_arch)
|
55
|
+
if new_arch.nil?
|
56
|
+
@@yasm_arch = nil
|
57
|
+
else
|
58
|
+
@@yasm_arch = new_arch.to_sym
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
#
|
63
|
+
# The default YASM machine to assemble for.
|
64
|
+
#
|
65
|
+
# @return [Symbol]
|
66
|
+
# The YASM machine.
|
67
|
+
#
|
68
|
+
def YASM.machine
|
69
|
+
@@yasm_machine ||= nil
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# Sets the default YASM machine to assemble for.
|
74
|
+
#
|
75
|
+
# @param [Symbol, String] new_machine
|
76
|
+
# The new YASM machine to assemble for.
|
77
|
+
#
|
78
|
+
# @return [Symbol]
|
79
|
+
# The new YASM machine to assemble for.
|
80
|
+
#
|
81
|
+
def YASM.machine=(new_machine)
|
82
|
+
@@yasm_machine = if new_machine.nil?
|
83
|
+
nil
|
84
|
+
else
|
85
|
+
new_machine.to_sym
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# The default YASM debugging format to use.
|
91
|
+
#
|
92
|
+
# @return [Symbol]
|
93
|
+
# The YASM debugging format.
|
94
|
+
#
|
95
|
+
def YASM.debug_format
|
96
|
+
@@yasm_debug_format
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# Sets the default YASM debugging format to use.
|
101
|
+
#
|
102
|
+
# @param [Symbol, String] new_format
|
103
|
+
# The new YASM debugging format to use.
|
104
|
+
#
|
105
|
+
# @return [Symbol]
|
106
|
+
# The new YASM debugging format to use.
|
107
|
+
#
|
108
|
+
def YASM.debug_format=(new_format)
|
109
|
+
@@yasm_debug_format = if new_format.nil?
|
110
|
+
nil
|
111
|
+
else
|
112
|
+
new_format.to_sym
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
#
|
117
|
+
# The default YASM output format to use.
|
118
|
+
#
|
119
|
+
# @return [Symbol]
|
120
|
+
# The YASM output format.
|
121
|
+
#
|
122
|
+
def YASM.output_format
|
123
|
+
@@yasm_output_format
|
124
|
+
end
|
125
|
+
|
126
|
+
#
|
127
|
+
# Sets the default YASM output format to use.
|
128
|
+
#
|
129
|
+
# @param [Symbol, String] new_format
|
130
|
+
# The new YASM output format to use.
|
131
|
+
#
|
132
|
+
# @return [Symbol]
|
133
|
+
# The new YASM output format to use.
|
134
|
+
#
|
135
|
+
def YASM.output_format=(new_format)
|
136
|
+
@@yasm_output_format = if new_format.nil?
|
137
|
+
nil
|
138
|
+
else
|
139
|
+
new_format.to_sym
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'yasm/program'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'helpers/files'
|
5
|
+
|
6
|
+
describe Program do
|
7
|
+
include Helpers::Files
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@yasm = Program.find
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should be able to assemble a file" do
|
14
|
+
file = Tempfile.new('yasm').path
|
15
|
+
|
16
|
+
@yasm.assemble do |yasm|
|
17
|
+
yasm.target! :x86
|
18
|
+
|
19
|
+
yasm.syntax = :gas
|
20
|
+
yasm.file = assembly_file('gas')
|
21
|
+
yasm.output = file
|
22
|
+
end
|
23
|
+
|
24
|
+
File.size(file).should > 0
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should assemble a file, and write the output to a temporary file" do
|
28
|
+
file = @yasm.assemble_temp do |yasm|
|
29
|
+
yasm.target! :x86
|
30
|
+
|
31
|
+
yasm.syntax = :gas
|
32
|
+
yasm.file = assembly_file('gas')
|
33
|
+
end
|
34
|
+
|
35
|
+
file.should_not be_nil
|
36
|
+
File.size(file).should > 0
|
37
|
+
end
|
38
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/spec/task_spec.rb
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'yasm/task'
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Task do
|
6
|
+
it "should support a :target option" do
|
7
|
+
task = Task.new(:target => :amd64)
|
8
|
+
|
9
|
+
task.arch.should == :x86
|
10
|
+
task.machine.should == :amd64
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "default" do
|
14
|
+
describe "parser" do
|
15
|
+
before(:all) do
|
16
|
+
@old_parser = YASM.parser
|
17
|
+
|
18
|
+
YASM.parser = :tasm
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should have a default parser value" do
|
22
|
+
task = Task.new
|
23
|
+
task.parser.should == :tasm
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should allow overriding the default parser" do
|
27
|
+
task = Task.new(:parser => :gas)
|
28
|
+
task.parser.should == :gas
|
29
|
+
end
|
30
|
+
|
31
|
+
after(:all) do
|
32
|
+
YASM.parser = @old_parser
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe "arch" do
|
37
|
+
before(:all) do
|
38
|
+
@old_arch = YASM.arch
|
39
|
+
|
40
|
+
YASM.arch = :lc3b
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have a default arch value" do
|
44
|
+
task = Task.new
|
45
|
+
task.arch.should == :lc3b
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should allow overriding the default arch" do
|
49
|
+
task = Task.new(:arch => :x86)
|
50
|
+
task.arch.should == :x86
|
51
|
+
end
|
52
|
+
|
53
|
+
after(:all) do
|
54
|
+
YASM.arch = @old_arch
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe "machine" do
|
59
|
+
before(:all) do
|
60
|
+
@old_machine = YASM.machine
|
61
|
+
|
62
|
+
YASM.machine = :amd64
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should have a default machine value" do
|
66
|
+
task = Task.new
|
67
|
+
task.machine.should == :amd64
|
68
|
+
end
|
69
|
+
|
70
|
+
it "should allow overriding the default machine" do
|
71
|
+
task = Task.new(:machine => :x86)
|
72
|
+
task.machine.should == :x86
|
73
|
+
end
|
74
|
+
|
75
|
+
after(:all) do
|
76
|
+
YASM.machine = @old_machine
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "debug_format" do
|
81
|
+
before(:all) do
|
82
|
+
@old_debug_format = YASM.debug_format
|
83
|
+
|
84
|
+
YASM.debug_format = :stabs
|
85
|
+
end
|
86
|
+
|
87
|
+
it "should have a default debug_format value" do
|
88
|
+
task = Task.new
|
89
|
+
task.debug_format.should == :stabs
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should allow overriding the default debug_format" do
|
93
|
+
task = Task.new(:debug_format => :null)
|
94
|
+
task.debug_format.should == :null
|
95
|
+
end
|
96
|
+
|
97
|
+
after(:all) do
|
98
|
+
YASM.debug_format = @old_debug_format
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "output_format" do
|
103
|
+
before(:all) do
|
104
|
+
@old_output_format = YASM.output_format
|
105
|
+
|
106
|
+
YASM.output_format = :elf64
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should have a default output_format value" do
|
110
|
+
task = Task.new
|
111
|
+
task.output_format.should == :elf64
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should allow overriding the default output_format" do
|
115
|
+
task = Task.new(:output_format => :bin)
|
116
|
+
task.output_format.should == :bin
|
117
|
+
end
|
118
|
+
|
119
|
+
after(:all) do
|
120
|
+
YASM.output_format = @old_output_format
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe "target!" do
|
126
|
+
it "should return true for valid targets" do
|
127
|
+
task = Task.new
|
128
|
+
|
129
|
+
task.target!(:amd64).should == true
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should raise RuntimeError when passed unknown targets" do
|
133
|
+
task = Task.new
|
134
|
+
|
135
|
+
lambda {
|
136
|
+
task.target! :lol
|
137
|
+
}.should raise_error(RuntimeError)
|
138
|
+
end
|
139
|
+
|
140
|
+
describe "x86" do
|
141
|
+
before(:all) do
|
142
|
+
@task = Task.new { |task| task.target! :x86 }
|
143
|
+
end
|
144
|
+
|
145
|
+
it "should set the arch value" do
|
146
|
+
@task.arch.should == :x86
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should set the machine value" do
|
150
|
+
@task.machine.should == :x86
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe "amd64" do
|
155
|
+
before(:all) do
|
156
|
+
@task = Task.new { |task| task.target! :amd64 }
|
157
|
+
end
|
158
|
+
|
159
|
+
it "should set the arch value" do
|
160
|
+
@task.arch.should == :x86
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should set the machine value" do
|
164
|
+
@task.machine.should == :amd64
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "lc3b" do
|
169
|
+
before(:all) do
|
170
|
+
@task = Task.new { |task| task.target! :lc3b }
|
171
|
+
end
|
172
|
+
|
173
|
+
it "should set the arch value" do
|
174
|
+
@task.arch.should == :lc3b
|
175
|
+
end
|
176
|
+
|
177
|
+
it "should set the machine value" do
|
178
|
+
@task.machine.should == :lc3b
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
data/spec/yasm_spec.rb
ADDED
data/tasks/spec.rb
ADDED
data/tasks/yard.rb
ADDED
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruby-yasm
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Postmodern
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDQDCCAiigAwIBAgIBADANBgkqhkiG9w0BAQUFADBGMRgwFgYDVQQDDA9wb3N0
|
14
|
+
bW9kZXJuLm1vZDMxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixk
|
15
|
+
ARkWA2NvbTAeFw0wOTA2MDMwNDU5MDNaFw0xMDA2MDMwNDU5MDNaMEYxGDAWBgNV
|
16
|
+
BAMMD3Bvc3Rtb2Rlcm4ubW9kMzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYK
|
17
|
+
CZImiZPyLGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA
|
18
|
+
1wvANkTDHFgVih5XLjuTwTZjgBq1lBGybXJiH6Id1lY2JOMqM5FB1DDHVvvij94i
|
19
|
+
mJabN0zkzu6VKWC70y0IwOxY7CPokr0eFdK/D0y7mCq1P8QITv76i2YqAl0eYqIt
|
20
|
+
W+IhIkANQ7E6uMZIZcdnfadC6lPAtlKkqtd9crvRbFgr6e3kyflmohbRnTEJHoRd
|
21
|
+
7SHHsybE6DSn7oTDs6XBTNrNIn5VfZA0z01eeos/+zBm1zKJOK2+/7xtLLDuDU9G
|
22
|
+
+Rd+ltUBbvxUrMNZmDG29pnmN2xTRH+Q8HxD2AxlvM5SRpK6OeZaHV7PaCCAVZ4L
|
23
|
+
T9BFl1sfMvRlABeGEkSyuQIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIE
|
24
|
+
sDAdBgNVHQ4EFgQUKwsd+PqEYmBvyaTyoL+uRuk+PhEwDQYJKoZIhvcNAQEFBQAD
|
25
|
+
ggEBAB4TvHsrlbcXcKg6gX5BIb9tI+zGkpzo0Z7jnxMEcNO7NGGwmzafDBI/xZYv
|
26
|
+
xkRH3/HXbGGYDOi6Q6gWt5GujSx0bOImDtYTJTH8jnzN92HzEK5WdScm1QpZKF1e
|
27
|
+
cezArMbxbSPaosxTCtG6LQTkE28lFQsmFZ5xzouugS4h5+LVJiVMmiP+l3EfkjFa
|
28
|
+
GOURU+rNEMPWo8MCWivGW7jes6BMzWHcW7DQ0scNVmIcCIgdyMmpscuAEOSeghy9
|
29
|
+
/fFs57Ey2OXBL55nDOyvN/ZQ2Vab05UH4t+GCxjAPeirzL/29FBtePT6VD44c38j
|
30
|
+
pDj+ws7QjtH/Qcrr1l9jfN0ehDs=
|
31
|
+
-----END CERTIFICATE-----
|
32
|
+
|
33
|
+
date: 2009-12-27 00:00:00 -08:00
|
34
|
+
default_executable:
|
35
|
+
dependencies:
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rprogram
|
38
|
+
type: :runtime
|
39
|
+
version_requirement:
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: 0.1.8
|
45
|
+
version:
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
type: :development
|
49
|
+
version_requirement:
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.2.9
|
55
|
+
version:
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: yard
|
58
|
+
type: :development
|
59
|
+
version_requirement:
|
60
|
+
version_requirements: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 0.5.2
|
65
|
+
version:
|
66
|
+
- !ruby/object:Gem::Dependency
|
67
|
+
name: hoe
|
68
|
+
type: :development
|
69
|
+
version_requirement:
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 2.4.0
|
75
|
+
version:
|
76
|
+
description: |-
|
77
|
+
A Ruby interface to YASM.
|
78
|
+
|
79
|
+
YASM is a complete rewrite of the NASM assembler, YASM currently supports
|
80
|
+
the x86 and AMD64 instruction sets, accepts NASM and GAS assembler syntaxes,
|
81
|
+
outputs binary, ELF32, ELF64, 32 and 64-bit Mach-O, RDOFF2, COFF, Win32,
|
82
|
+
and Win64 object formats, and generates source debugging information in
|
83
|
+
STABS, DWARF 2, and CodeView 8 formats.
|
84
|
+
email:
|
85
|
+
- postmodern.mod3@gmail.com
|
86
|
+
executables: []
|
87
|
+
|
88
|
+
extensions: []
|
89
|
+
|
90
|
+
extra_rdoc_files:
|
91
|
+
- Manifest.txt
|
92
|
+
files:
|
93
|
+
- History.rdoc
|
94
|
+
- Manifest.txt
|
95
|
+
- README.rdoc
|
96
|
+
- Rakefile
|
97
|
+
- lib/yasm.rb
|
98
|
+
- lib/yasm/task.rb
|
99
|
+
- lib/yasm/program.rb
|
100
|
+
- lib/yasm/yasm.rb
|
101
|
+
- lib/yasm/version.rb
|
102
|
+
- tasks/spec.rb
|
103
|
+
- tasks/yard.rb
|
104
|
+
- spec/spec_helper.rb
|
105
|
+
- spec/helpers/files.rb
|
106
|
+
- spec/helpers/files/gas.S
|
107
|
+
- spec/task_spec.rb
|
108
|
+
- spec/program_spec.rb
|
109
|
+
- spec/yasm_spec.rb
|
110
|
+
has_rdoc: yard
|
111
|
+
homepage: http://www.tortall.net/projects/yasm/
|
112
|
+
licenses: []
|
113
|
+
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options:
|
116
|
+
- --main
|
117
|
+
- README.rdoc
|
118
|
+
require_paths:
|
119
|
+
- lib
|
120
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: "0"
|
125
|
+
version:
|
126
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: "0"
|
131
|
+
version:
|
132
|
+
requirements: []
|
133
|
+
|
134
|
+
rubyforge_project: ruby-yasm
|
135
|
+
rubygems_version: 1.3.5
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: A Ruby interface to YASM
|
139
|
+
test_files: []
|
140
|
+
|
metadata.gz.sig
ADDED
Binary file
|