ruby-yasm 0.1.0 → 0.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3a2caa603f754d40e6ba2d6f10ff5e4e63829a28ee3e89a5c0eb76aee4e9b38c
4
+ data.tar.gz: df4c5fab51e3a804d7b4f16f515f05eef1e2295742a7e1f36743fddfe4b857e6
5
+ SHA512:
6
+ metadata.gz: 79baa6465f54ff67bb4697aff6338d6566a1b59611b58af8e69f90f680819828747a2657699d579f1a8c50b1e67cdb00179e9872159b78fa59b7a2fd75ca7d38
7
+ data.tar.gz: 7df6abee2fe8b61463e2dff4c361c72c2566996658f99830e0bd2699e9229cec6dcf1556e109cddae3eb72dbbb175c2c1cb96bef0fa4f757b3847639ba5167b7
data/.document ADDED
@@ -0,0 +1,3 @@
1
+ -
2
+ ChangeLog.md
3
+ LICENSE.txt
data/.gemtest ADDED
File without changes
@@ -0,0 +1,30 @@
1
+ name: CI
2
+
3
+ on: [ push, pull_request ]
4
+
5
+ jobs:
6
+ tests:
7
+ runs-on: ubuntu-latest
8
+ strategy:
9
+ fail-fast: false
10
+ matrix:
11
+ ruby:
12
+ - 2.6
13
+ - 2.7
14
+ - 3.0
15
+ - jruby
16
+ name: Ruby ${{ matrix.ruby }}
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby }}
23
+ - name: Install yasm
24
+ run: |
25
+ sudo apt update -y && \
26
+ sudo apt install -y --no-install-recommends --no-install-suggests yasm
27
+ - name: Install dependencies
28
+ run: bundle install --jobs 4 --retry 3
29
+ - name: Run tests
30
+ run: bundle exec rake test
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /Gemfile.lock
2
+ /coverage
3
+ /doc
4
+ /pkg
5
+ /.yardoc
6
+ .DS_Store
7
+ *.log
8
+ *.swp
9
+ *~
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/.specopts ADDED
@@ -0,0 +1 @@
1
+ --colour --format specdoc
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown --title 'Ruby YASM Documentation' --protected
data/ChangeLog.md ADDED
@@ -0,0 +1,31 @@
1
+ ### 0.3.0 / 2022-01-07
2
+
3
+ * Replace rprogram with [command_mapper].
4
+ * Added {YASM::Command}.
5
+ * Deprecated {YASM::Program} in favor of {YASM::Command}.
6
+
7
+ ### 0.2.1 / 2012-05-27
8
+
9
+ * `YASM::Task#target!` now raises an `ArgumentError` when given an unknown
10
+ target.
11
+ * Replaced ore-tasks with
12
+ [rubygems-tasks](https://github.com/postmodern/rubygems-tasks#readme).
13
+
14
+ ### 0.2.0 / 2011-04-11
15
+
16
+ * Require rprogram ~> 0.3.
17
+ * Allow passing in additional exec-options in {YASM::Program.assemble}
18
+ and {YASM::Program#assemble}.
19
+ * Opt into [test.rubygems.org](http://test.rubygems.org/)
20
+
21
+ ### 0.1.1 / 2010-04-15
22
+
23
+ * Migrated to [Jeweler](http://github.com/technicalpickles/jeweler)
24
+ for packaging rubygems.
25
+ * Fixed a few critical typos.
26
+
27
+ ### 0.1.0 / 2009-12-24
28
+
29
+ * Initial release.
30
+
31
+ [command_mapper]: https://github.com/postmodern/command_mapper.rb#readme
data/Gemfile ADDED
@@ -0,0 +1,16 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ # gem 'command_mapper', '~> 0.1', github: 'postmodern/command_mapper.rb'
6
+
7
+ group :development do
8
+ gem 'rake'
9
+ gem 'rubygems-tasks', '~> 0.2'
10
+ gem 'rspec', '~> 3.0'
11
+ gem 'simplecov', '~> 0.7'
12
+
13
+ gem 'kramdown'
14
+ gem 'yard', '~> 0.9'
15
+ gem 'yard-spellcheck'
16
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2022 Hal Brodigan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,83 @@
1
+ # ruby-yasm
2
+
3
+ * [Source](https://github.com/sophsec/ruby-yasm/)
4
+ * [Issues](https://github.com/sophsec/ruby-yasm/issues)
5
+ * [Documentation](https://rubydoc.info/gems/ruby-yasm)
6
+
7
+ ## Description
8
+
9
+ A Ruby interface to [YASM][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
+ ```ruby
26
+ YASM::Command.run(syntax: :gas, file: 'hello_world.S', output: 'hello_world.o')
27
+ ```
28
+
29
+ Assemble amd64 assembly, in GAS syntax, into an ELF64 file with
30
+ debugging information:
31
+
32
+ ```ruby
33
+ YASM::Command.run do |yasm|
34
+ yasm.target = :amd64
35
+
36
+ yasm.syntax = :gas
37
+ yasm.file = 'hello_world.S'
38
+
39
+ yasm.output = 'hello_world.o'
40
+ yasm.output_format = :elf64
41
+ yasm.debug_format = :stabs
42
+ end
43
+ ```
44
+
45
+ ## Requirements
46
+
47
+ * [yasm] >= 0.8.0
48
+ * [command_mapper] ~> 0.1
49
+
50
+ ## Install
51
+
52
+ ```shell
53
+ $ gem install ruby-yasm
54
+ ```
55
+
56
+ ### yasm
57
+
58
+ * Debian / Ubuntu:
59
+
60
+ ```shell
61
+ $ sudo apt install yasm
62
+ ```
63
+
64
+ * RedHat / Fedora:
65
+
66
+ ```shell
67
+ $ sudo dnf install yasm
68
+ ```
69
+
70
+ * Homebrew:
71
+
72
+ ```shell
73
+ $ brew install yasm
74
+ ```
75
+
76
+ ## License
77
+
78
+ Copyright (c) 2009-2022 Hal Brodigan
79
+
80
+ See {file:LICENSE.txt} for license information.
81
+
82
+ [yasm]: https://www.tortall.net/projects/yasm/
83
+ [command_mapper]: https://github.com/postmodern/command_mapper.rb#readme
data/Rakefile CHANGED
@@ -1,27 +1,10 @@
1
- # -*- ruby -*-
1
+ require 'rubygems/tasks'
2
+ Gem::Tasks.new
2
3
 
3
- require 'rubygems'
4
- require 'hoe'
5
- require 'hoe/signing'
6
- require './tasks/spec.rb'
7
- require './tasks/yard.rb'
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
6
+ task :test => :spec
7
+ task :default => :spec
8
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
9
+ require 'yard'
10
+ YARD::Rake::YardocTask.new
data/gemspec.yml ADDED
@@ -0,0 +1,18 @@
1
+ name: ruby-yasm
2
+ summary: A Ruby interface to YASM.
3
+ description:
4
+ ruby-yasm provides a Ruby interface to YASM assembler.
5
+
6
+ license: MIT
7
+ authors: Postmodern
8
+ email: postmodern.mod3@gmail.com
9
+ homepage: https://github.com/postmodern/ruby-yasm#readme
10
+ has_yard: true
11
+
12
+ requirements: yasm >= 0.6.0
13
+
14
+ dependencies:
15
+ command_mapper: ~> 0.1
16
+
17
+ development_dependencies:
18
+ bundler: ~> 2.0
@@ -0,0 +1,272 @@
1
+ require 'command_mapper/command'
2
+
3
+ module YASM
4
+ #
5
+ # Provides an interface for invoking the `yasm` utility.
6
+ #
7
+ # ## Examples
8
+ #
9
+ # Assemble a binary file:
10
+ #
11
+ # YASM::Command.run(syntax: :gas, file: 'hello_world.S', output: 'hello_world.o')
12
+ #
13
+ # Assemble amd64 assembly, in GAS syntax, into an ELF64 file with
14
+ # debugging information:
15
+ #
16
+ # YASM::Command.run do |yasm|
17
+ # yasm.target = :amd64
18
+ #
19
+ # yasm.syntax = :gas
20
+ # yasm.file = 'hello_world.S'
21
+ #
22
+ # yasm.output = 'hello_world.o'
23
+ # yasm.output_format = :elf64
24
+ # yasm.debug_format = :stabs
25
+ # end
26
+ #
27
+ # ## `yasm` options:
28
+ #
29
+ # * `--version` - `yasm.version`
30
+ # * `--license` - `yasm.license`
31
+ # * `--help` - `yasm.help`
32
+ # * `--arch` - `yasm.arch`
33
+ # * `x86` - x86 (IA-32 and derivatives), AMD64
34
+ # * `lc3b` - LC-3b
35
+ # * `--parser` - `yasm.parser`
36
+ # * `gas` - GNU AS (GAS)-compatible parser
37
+ # * `gnu` - GNU AS (GAS)-compatible parser
38
+ # * `nasm` - NASM-compatible parser
39
+ # * `tasm` - TASM-compatible parser
40
+ # * `--preproc` - `yasm.preprocessor`
41
+ # * `nasm` - Real NASM Preprocessor
42
+ # * `tasm` - Real TASM Preprocessor
43
+ # * `raw` - Disable preprocessing
44
+ # * `cpp` - Run input through external C preprocessor
45
+ # * `gas` - GNU AS (GAS)-compatible preprocessor
46
+ # * `--oformat` - `yasm.output_format`
47
+ # * `dbg` - Trace of all info passed to object format module
48
+ # * `bin` - Flat format binary
49
+ # * `dosexe` - DOS .EXE format binary
50
+ # * `elf` - ELF
51
+ # * `elf32` - ELF (32-bit)
52
+ # * `elf64` - ELF (64-bit)
53
+ # * `elfx32` - ELF (x32)
54
+ # * `coff` - COFF (DJGPP)
55
+ # * `macho` - Mac OS X ABI Mach-O File Format
56
+ # * `macho32` - Mac OS X ABI Mach-O File Format (32-bit)
57
+ # * `macho64` - Mac OS X ABI Mach-O File Format (64-bit)
58
+ # * `rdf` - Relocatable Dynamic Object File Format (RDOFF) v2.0
59
+ # * `win32` - Win32
60
+ # * `win64` - Win64
61
+ # * `x64` - Win64
62
+ # * `xdf` - Extended Dynamic Object
63
+ # * `--dformat` - `yasm.debug_format`
64
+ # * `cv8` - CodeView debugging format for VC8
65
+ # * `dwarf2` - DWARF2 debugging format
66
+ # * `null` - No debugging info
67
+ # * `stabs` - Stabs debugging format
68
+ # * `--lformat` - `yasm.list_format`
69
+ # * `nasm` -NASM-style list format
70
+ # * `--list` - `yasm.list_file`
71
+ # * `--objfile` - `yasm.output`
72
+ # * `--mapfile` - `yasm.map_file`
73
+ # * `--machine` - `yasm.machine`
74
+ # * `x86` - IA-32 and derivatives
75
+ # * `amd64` - AMD64
76
+ # * `x32` - X32
77
+ # * `--force-strict` - `yasm.force_strict`
78
+ # * `-w` - `yasm.inhibit_warnings`
79
+ # * `-W` - `yasm.toggle_warnings`
80
+ # * `-M` - `yasm.gen_makefile_deps`
81
+ # * `-E` - `yasm.redirect_errors_to`
82
+ # * `-e` - `yasm.redirect_errors`
83
+ # * `--preproc-only` - `yasm.preprocessor_only`
84
+ # * `-I` - `yasm.include`
85
+ # * `-P` - `yasm.pre_include`
86
+ # * `-D` - `yasm.define`
87
+ # * `-U` - `yasm.undefine`
88
+ # * `-X` - `yasm.message_style`
89
+ # * `gnu`
90
+ # * `vc`
91
+ # * `--prefix` - `yasm.prefix`
92
+ # * `--suffix` - `yasm.suffix`
93
+ # * `file` - `yasm.file`
94
+ #
95
+ # @since 0.3.0
96
+ #
97
+ # @api public
98
+ #
99
+ class Command < CommandMapper::Command
100
+
101
+ command 'yasm' do
102
+ option '--version'
103
+ option '--license'
104
+ option '--help'
105
+
106
+ option '--arch', equals: true,
107
+ value: {
108
+ type: Enum[
109
+ :x86, # x86 (IA-32 and derivatives), AMD64
110
+ :lc3b # LC-3b
111
+ ]
112
+ }
113
+
114
+ option '--parser', equals: true,
115
+ value: {
116
+ type: Enum[
117
+ :gas, # GNU AS (GAS)-compatible parser
118
+ :gnu, # GNU AS (GAS)-compatible parser
119
+ :nasm, # NASM-compatible parser
120
+ :tasm # TASM-compatible parser
121
+ ]
122
+ }
123
+
124
+ option '--preproc', equals: true,
125
+ value: {
126
+ type: Enum[
127
+ :nasm, # Real NASM Preprocessor
128
+ :tasm, # Real TASM Preprocessor
129
+ :raw, # Disable preprocessing
130
+ :cpp, # Run input through external C preprocessor
131
+ :gas # GNU AS (GAS)-compatible preprocessor
132
+ ]
133
+ },
134
+ name: :preprocessor
135
+ option '--oformat', equals: true,
136
+ value: {
137
+ type: Enum[
138
+ :dbg, # Trace of all info passed to object format module
139
+ :bin, # Flat format binary
140
+ :dosexe, # DOS .EXE format binary
141
+ :elf, # ELF
142
+ :elf32, # ELF (32-bit)
143
+ :elf64, # ELF (64-bit)
144
+ :elfx32, # ELF (x32)
145
+ :coff, # COFF (DJGPP)
146
+ :macho, # Mac OS X ABI Mach-O File Format
147
+ :macho32, # Mac OS X ABI Mach-O File Format (32-bit)
148
+ :macho64, # Mac OS X ABI Mach-O File Format (64-bit)
149
+ :rdf, # Relocatable Dynamic Object File Format (RDOFF) v2.0
150
+ :win32, # Win32
151
+ :win64, # Win64
152
+ :x64, # Win64
153
+ :xdf # Extended Dynamic Object
154
+ ]
155
+ },
156
+ name: :output_format
157
+ option '--dformat', equals: true,
158
+ value: {
159
+ type: Enum[
160
+ :cv8, # CodeView debugging format for VC8
161
+ :dwarf2, # DWARF2 debugging format
162
+ :null, # No debugging info
163
+ :stabs # Stabs debugging format
164
+ ]
165
+ },
166
+ name: :debug_format
167
+ option '--lformat', equals: true,
168
+ value: {
169
+ type: Enum[
170
+ :nasm # NASM-style list format
171
+ ]
172
+ },
173
+ name: :list_format
174
+
175
+ option '--list', equals: true,
176
+ value: true,
177
+ name: :list_file
178
+
179
+ option '--objfile', equals: true,
180
+ value: true,
181
+ name: :output
182
+
183
+ option '--mapfile', equals: true,
184
+ value: true,
185
+ name: :map_file
186
+
187
+ option '--machine', equals: true,
188
+ value: {
189
+ type: Enum[
190
+ :x86, # IA-32 and derivatives
191
+ :amd64, # AMD64
192
+ :x32 # X32
193
+ ]
194
+ }
195
+
196
+ option '--force-strict'
197
+ option '-w', name: :inhibit_warnings
198
+ option '-W', name: :toggle_warnings
199
+ option '-M', name: :gen_makefile_deps
200
+ option '-E', value: true, name: :redirect_errors_to
201
+ option '-s', name: :redirect_errors
202
+ option '--preproc-only', name: :preprocessor_only
203
+
204
+ option '-I', value: {type: InputDir.new},
205
+ repeats: true,
206
+ name: :include
207
+
208
+ option '-P', value: {type: InputFile.new},
209
+ repeats: true,
210
+ name: :pre_include
211
+
212
+ option '-D', name: :define, repeats: true
213
+
214
+ option '-U', value: true,
215
+ repeats: true,
216
+ name: :undefine
217
+
218
+ option '-X', value: {type: Enum[:gnu, :vc]},
219
+ name: :message_style
220
+
221
+ option '--prefix'
222
+ option '--suffix'
223
+
224
+ argument :file, type: InputFile.new
225
+ end
226
+
227
+ # The known YASM targets
228
+ TARGETS = {
229
+ x86: {arch: :x86, machine: :x86},
230
+ amd64: {arch: :x86, machine: :amd64},
231
+ lc3b: {arch: :lc3b, machine: :lc3b}
232
+ }
233
+
234
+ #
235
+ # Determines which target was set.
236
+ #
237
+ # @return [:x86, :amd64, :lc3b, nil]
238
+ # The target name or `nil` if no target has been set.
239
+ #
240
+ def target
241
+ if arch && machine
242
+ TARGETS.key(arch: arch.to_sym, machine: machine.to_sym)
243
+ end
244
+ end
245
+
246
+ #
247
+ # Sets that target.
248
+ #
249
+ # @param [:x86, :amd64, :lc3b] name
250
+ # The target name.
251
+ #
252
+ # @return [Symbol]
253
+ # The set target.
254
+ #
255
+ # @raise [ArgumentError]
256
+ # An unknown target name was given.
257
+ #
258
+ def target=(name)
259
+ target = TARGETS.fetch(name.to_sym) do
260
+ raise(ArgumentError,"unknown YASM target: #{name.inspect}")
261
+ end
262
+
263
+ self.arch = target[:arch]
264
+ self.machine = target[:machine]
265
+ return name
266
+ end
267
+
268
+ alias syntax parser
269
+ alias syntax= parser=
270
+
271
+ end
272
+ end