ruby-yasm 0.2.1 → 0.3.1

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: e5eb2ab4aa16aaba13a740d3da526612f16aba6a9a637a22ea483a227ad59d81
4
+ data.tar.gz: 84b004cb1fe8e0faf9a43d6458af3a5c3ebf86d44635ac9ce27139e09cafea4e
5
+ SHA512:
6
+ metadata.gz: 467baec65f43042bbab6e755e10b729db056816375fb2ec099afe9978e28424cea634518d7579178b4354eef743ab6b4930da7e58b281c6a0774654fd20ccf78
7
+ data.tar.gz: 71346029b9ccbc3152b01cc8c3471aece56f6de4d473a8178a7adfaec0d35f78558191a231d091137ae235d99b56a83b3b87cd4de0da04549c9355b7065decf0
@@ -0,0 +1,31 @@
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
+ - '3.0'
13
+ - '3.1'
14
+ - '3.2'
15
+ - '3.3'
16
+ - jruby
17
+ name: Ruby ${{ matrix.ruby }}
18
+ steps:
19
+ - uses: actions/checkout@v2
20
+ - name: Set up Ruby
21
+ uses: ruby/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ - name: Install yasm
25
+ run: |
26
+ sudo apt update -y && \
27
+ sudo apt install -y --no-install-recommends --no-install-suggests yasm
28
+ - name: Install dependencies
29
+ run: bundle install --jobs 4 --retry 3
30
+ - name: Run tests
31
+ run: bundle exec rake test
data/.gitignore CHANGED
@@ -1,6 +1,8 @@
1
- doc
2
- pkg
3
- .yardoc
1
+ /Gemfile.lock
2
+ /coverage
3
+ /doc
4
+ /pkg
5
+ /.yardoc
4
6
  .DS_Store
5
7
  *.log
6
8
  *.swp
data/ChangeLog.md CHANGED
@@ -1,6 +1,17 @@
1
+ ### 0.3.1 / 2024-01-25
2
+
3
+ * Switched to using `require_relative` to improve load-times.
4
+ * Added `# frozen_string_literal: true` to all files.
5
+
6
+ ### 0.3.0 / 2022-01-07
7
+
8
+ * Replace rprogram with [command_mapper].
9
+ * Added {YASM::Command}.
10
+ * Deprecated {YASM::Program} in favor of {YASM::Command}.
11
+
1
12
  ### 0.2.1 / 2012-05-27
2
13
 
3
- * {YASM::Task#target!} now raises an `ArgumentError` when given an unknown
14
+ * `YASM::Task#target!` now raises an `ArgumentError` when given an unknown
4
15
  target.
5
16
  * Replaced ore-tasks with
6
17
  [rubygems-tasks](https://github.com/postmodern/rubygems-tasks#readme).
@@ -22,3 +33,4 @@
22
33
 
23
34
  * Initial release.
24
35
 
36
+ [command_mapper]: https://github.com/postmodern/command_mapper.rb#readme
data/Gemfile ADDED
@@ -0,0 +1,17 @@
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 'redcarpet', platform: :mri
15
+ gem 'yard', '~> 0.9'
16
+ gem 'yard-spellcheck'
17
+ end
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-2012 Postmodern
1
+ Copyright (c) 2009-2024 Hal Brodigan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,19 +2,17 @@
2
2
 
3
3
  * [Source](https://github.com/sophsec/ruby-yasm/)
4
4
  * [Issues](https://github.com/sophsec/ruby-yasm/issues)
5
- * [Email](mailto:postmodern.mod3 at gmail.com)
6
- * [www.tortall.net/projects/yasm](http://www.tortall.net/projects/yasm/)
7
- * [www.sophsec.com](http://www.sophsec.com/)
5
+ * [Documentation](https://rubydoc.info/gems/ruby-yasm)
8
6
 
9
7
  ## Description
10
8
 
11
- A Ruby interface to YASM.
9
+ A Ruby interface to [YASM][yasm].
12
10
 
13
- YASM is a complete rewrite of the NASM assembler, YASM currently supports
14
- the x86 and AMD64 instruction sets, accepts NASM and GAS assembler syntaxes,
15
- outputs binary, ELF32, ELF64, 32 and 64-bit Mach-O, RDOFF2, COFF, Win32,
16
- and Win64 object formats, and generates source debugging information in
17
- STABS, DWARF 2, and CodeView 8 formats.
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.
18
16
 
19
17
  ## Features
20
18
 
@@ -24,37 +22,60 @@ STABS, DWARF 2, and CodeView 8 formats.
24
22
 
25
23
  Assemble a binary file:
26
24
 
27
- YASM::Program.assemble do |yasm|
28
- yasm.syntax = :gas
29
- yasm.file = 'hello_world.S'
30
- yasm.output = 'hello_world.o'
31
- end
25
+ ```ruby
26
+ YASM::Command.run(syntax: :gas, file: 'hello_world.S', output: 'hello_world.o')
27
+ ```
32
28
 
33
29
  Assemble amd64 assembly, in GAS syntax, into an ELF64 file with
34
30
  debugging information:
35
31
 
36
- YASM::Program.assemble do |yasm|
37
- yasm.target! :amd64
32
+ ```ruby
33
+ YASM::Command.run do |yasm|
34
+ yasm.target = :amd64
38
35
 
39
- yasm.syntax = :gas
40
- yasm.file = 'hello_world.S'
36
+ yasm.syntax = :gas
37
+ yasm.file = 'hello_world.S'
41
38
 
42
- yasm.output = 'hello_world.o'
43
- yasm.output_format = :elf64
44
- yasm.debug_format = :stabs
45
- end
39
+ yasm.output = 'hello_world.o'
40
+ yasm.output_format = :elf64
41
+ yasm.debug_format = :stabs
42
+ end
43
+ ```
46
44
 
47
45
  ## Requirements
48
46
 
49
- * [yasm](http://www.tortall.net/projects/yasm/) >= 0.8.0
50
- * [rprogram](http://rprogram.rubyforge.org/) ~> 0.3
47
+ * [yasm] >= 0.8.0
48
+ * [command_mapper] ~> 0.1
51
49
 
52
50
  ## Install
53
51
 
54
- $ sudo gem install ruby-yasm
52
+ ```shell
53
+ $ gem install ruby-yasm
54
+ ```
55
55
 
56
- ## License
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
+ ```
57
69
 
58
- Copyright (c) 2009-2017 Postmodern
70
+ * Homebrew:
71
+
72
+ ```shell
73
+ $ brew install yasm
74
+ ```
75
+
76
+ ## License
59
77
 
60
78
  See {file:LICENSE.txt} for license information.
79
+
80
+ [yasm]: https://www.tortall.net/projects/yasm/
81
+ [command_mapper]: https://github.com/postmodern/command_mapper.rb#readme
data/Rakefile CHANGED
@@ -1,36 +1,10 @@
1
- require 'rubygems'
2
- require 'rake'
1
+ require 'rubygems/tasks'
2
+ Gem::Tasks.new
3
3
 
4
- begin
5
- gem 'rubygems-tasks', '~> 0.1'
6
- require 'rubygems/tasks'
7
-
8
- Gem::Tasks.new
9
- rescue LoadError => e
10
- warn e.message
11
- warn "Run `gem install rubygems-tasks` to install 'rubygems/tasks'."
12
- end
13
-
14
- begin
15
- gem 'rspec', '~> 2.4'
16
- require 'rspec/core/rake_task'
17
-
18
- RSpec::Core::RakeTask.new
19
- rescue LoadError => e
20
- task :spec do
21
- abort "Please run `gem install rspec` to install RSpec."
22
- end
23
- end
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new
24
6
  task :test => :spec
25
7
  task :default => :spec
26
8
 
27
- begin
28
- gem 'yard', '~> 0.7'
29
- require 'yard'
30
-
31
- YARD::Rake::YardocTask.new
32
- rescue LoadError => e
33
- task :yard do
34
- abort "Please run `gem install yard` to install YARD."
35
- end
36
- end
9
+ require 'yard'
10
+ YARD::Rake::YardocTask.new
data/gemspec.yml CHANGED
@@ -6,15 +6,13 @@ description:
6
6
  license: MIT
7
7
  authors: Postmodern
8
8
  email: postmodern.mod3@gmail.com
9
- homepage: https://github.com/sophsec/ruby-yasm#readme
9
+ homepage: https://github.com/postmodern/ruby-yasm#readme
10
10
  has_yard: true
11
11
 
12
12
  requirements: yasm >= 0.6.0
13
13
 
14
14
  dependencies:
15
- rprogram: ~> 0.3
15
+ command_mapper: ~> 0.1
16
16
 
17
17
  development_dependencies:
18
- rubygems-tasks: ~> 0.1
19
- rspec: ~> 2.4
20
- yard: ~> 0.7
18
+ bundler: ~> 2.0
@@ -0,0 +1,274 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'command_mapper/command'
4
+
5
+ module YASM
6
+ #
7
+ # Provides an interface for invoking the `yasm` utility.
8
+ #
9
+ # ## Examples
10
+ #
11
+ # Assemble a binary file:
12
+ #
13
+ # YASM::Command.run(syntax: :gas, file: 'hello_world.S', output: 'hello_world.o')
14
+ #
15
+ # Assemble amd64 assembly, in GAS syntax, into an ELF64 file with
16
+ # debugging information:
17
+ #
18
+ # YASM::Command.run do |yasm|
19
+ # yasm.target = :amd64
20
+ #
21
+ # yasm.syntax = :gas
22
+ # yasm.file = 'hello_world.S'
23
+ #
24
+ # yasm.output = 'hello_world.o'
25
+ # yasm.output_format = :elf64
26
+ # yasm.debug_format = :stabs
27
+ # end
28
+ #
29
+ # ## `yasm` options:
30
+ #
31
+ # * `--version` - `yasm.version`
32
+ # * `--license` - `yasm.license`
33
+ # * `--help` - `yasm.help`
34
+ # * `--arch` - `yasm.arch`
35
+ # * `x86` - x86 (IA-32 and derivatives), AMD64
36
+ # * `lc3b` - LC-3b
37
+ # * `--parser` - `yasm.parser`
38
+ # * `gas` - GNU AS (GAS)-compatible parser
39
+ # * `gnu` - GNU AS (GAS)-compatible parser
40
+ # * `nasm` - NASM-compatible parser
41
+ # * `tasm` - TASM-compatible parser
42
+ # * `--preproc` - `yasm.preprocessor`
43
+ # * `nasm` - Real NASM Preprocessor
44
+ # * `tasm` - Real TASM Preprocessor
45
+ # * `raw` - Disable preprocessing
46
+ # * `cpp` - Run input through external C preprocessor
47
+ # * `gas` - GNU AS (GAS)-compatible preprocessor
48
+ # * `--oformat` - `yasm.output_format`
49
+ # * `dbg` - Trace of all info passed to object format module
50
+ # * `bin` - Flat format binary
51
+ # * `dosexe` - DOS .EXE format binary
52
+ # * `elf` - ELF
53
+ # * `elf32` - ELF (32-bit)
54
+ # * `elf64` - ELF (64-bit)
55
+ # * `elfx32` - ELF (x32)
56
+ # * `coff` - COFF (DJGPP)
57
+ # * `macho` - Mac OS X ABI Mach-O File Format
58
+ # * `macho32` - Mac OS X ABI Mach-O File Format (32-bit)
59
+ # * `macho64` - Mac OS X ABI Mach-O File Format (64-bit)
60
+ # * `rdf` - Relocatable Dynamic Object File Format (RDOFF) v2.0
61
+ # * `win32` - Win32
62
+ # * `win64` - Win64
63
+ # * `x64` - Win64
64
+ # * `xdf` - Extended Dynamic Object
65
+ # * `--dformat` - `yasm.debug_format`
66
+ # * `cv8` - CodeView debugging format for VC8
67
+ # * `dwarf2` - DWARF2 debugging format
68
+ # * `null` - No debugging info
69
+ # * `stabs` - Stabs debugging format
70
+ # * `--lformat` - `yasm.list_format`
71
+ # * `nasm` -NASM-style list format
72
+ # * `--list` - `yasm.list_file`
73
+ # * `--objfile` - `yasm.output`
74
+ # * `--mapfile` - `yasm.map_file`
75
+ # * `--machine` - `yasm.machine`
76
+ # * `x86` - IA-32 and derivatives
77
+ # * `amd64` - AMD64
78
+ # * `x32` - X32
79
+ # * `--force-strict` - `yasm.force_strict`
80
+ # * `-w` - `yasm.inhibit_warnings`
81
+ # * `-W` - `yasm.toggle_warnings`
82
+ # * `-M` - `yasm.gen_makefile_deps`
83
+ # * `-E` - `yasm.redirect_errors_to`
84
+ # * `-e` - `yasm.redirect_errors`
85
+ # * `--preproc-only` - `yasm.preprocessor_only`
86
+ # * `-I` - `yasm.include`
87
+ # * `-P` - `yasm.pre_include`
88
+ # * `-D` - `yasm.define`
89
+ # * `-U` - `yasm.undefine`
90
+ # * `-X` - `yasm.message_style`
91
+ # * `gnu`
92
+ # * `vc`
93
+ # * `--prefix` - `yasm.prefix`
94
+ # * `--suffix` - `yasm.suffix`
95
+ # * `file` - `yasm.file`
96
+ #
97
+ # @since 0.3.0
98
+ #
99
+ # @api public
100
+ #
101
+ class Command < CommandMapper::Command
102
+
103
+ command 'yasm' do
104
+ option '--version'
105
+ option '--license'
106
+ option '--help'
107
+
108
+ option '--arch', equals: true,
109
+ value: {
110
+ type: Enum[
111
+ :x86, # x86 (IA-32 and derivatives), AMD64
112
+ :lc3b # LC-3b
113
+ ]
114
+ }
115
+
116
+ option '--parser', equals: true,
117
+ value: {
118
+ type: Enum[
119
+ :gas, # GNU AS (GAS)-compatible parser
120
+ :gnu, # GNU AS (GAS)-compatible parser
121
+ :nasm, # NASM-compatible parser
122
+ :tasm # TASM-compatible parser
123
+ ]
124
+ }
125
+
126
+ option '--preproc', equals: true,
127
+ value: {
128
+ type: Enum[
129
+ :nasm, # Real NASM Preprocessor
130
+ :tasm, # Real TASM Preprocessor
131
+ :raw, # Disable preprocessing
132
+ :cpp, # Run input through external C preprocessor
133
+ :gas # GNU AS (GAS)-compatible preprocessor
134
+ ]
135
+ },
136
+ name: :preprocessor
137
+ option '--oformat', equals: true,
138
+ value: {
139
+ type: Enum[
140
+ :dbg, # Trace of all info passed to object format module
141
+ :bin, # Flat format binary
142
+ :dosexe, # DOS .EXE format binary
143
+ :elf, # ELF
144
+ :elf32, # ELF (32-bit)
145
+ :elf64, # ELF (64-bit)
146
+ :elfx32, # ELF (x32)
147
+ :coff, # COFF (DJGPP)
148
+ :macho, # Mac OS X ABI Mach-O File Format
149
+ :macho32, # Mac OS X ABI Mach-O File Format (32-bit)
150
+ :macho64, # Mac OS X ABI Mach-O File Format (64-bit)
151
+ :rdf, # Relocatable Dynamic Object File Format (RDOFF) v2.0
152
+ :win32, # Win32
153
+ :win64, # Win64
154
+ :x64, # Win64
155
+ :xdf # Extended Dynamic Object
156
+ ]
157
+ },
158
+ name: :output_format
159
+ option '--dformat', equals: true,
160
+ value: {
161
+ type: Enum[
162
+ :cv8, # CodeView debugging format for VC8
163
+ :dwarf2, # DWARF2 debugging format
164
+ :null, # No debugging info
165
+ :stabs # Stabs debugging format
166
+ ]
167
+ },
168
+ name: :debug_format
169
+ option '--lformat', equals: true,
170
+ value: {
171
+ type: Enum[
172
+ :nasm # NASM-style list format
173
+ ]
174
+ },
175
+ name: :list_format
176
+
177
+ option '--list', equals: true,
178
+ value: true,
179
+ name: :list_file
180
+
181
+ option '--objfile', equals: true,
182
+ value: true,
183
+ name: :output
184
+
185
+ option '--mapfile', equals: true,
186
+ value: true,
187
+ name: :map_file
188
+
189
+ option '--machine', equals: true,
190
+ value: {
191
+ type: Enum[
192
+ :x86, # IA-32 and derivatives
193
+ :amd64, # AMD64
194
+ :x32 # X32
195
+ ]
196
+ }
197
+
198
+ option '--force-strict'
199
+ option '-w', name: :inhibit_warnings
200
+ option '-W', name: :toggle_warnings
201
+ option '-M', name: :gen_makefile_deps
202
+ option '-E', value: true, name: :redirect_errors_to
203
+ option '-s', name: :redirect_errors
204
+ option '--preproc-only', name: :preprocessor_only
205
+
206
+ option '-I', value: {type: InputDir.new},
207
+ repeats: true,
208
+ name: :include
209
+
210
+ option '-P', value: {type: InputFile.new},
211
+ repeats: true,
212
+ name: :pre_include
213
+
214
+ option '-D', name: :define, repeats: true
215
+
216
+ option '-U', value: true,
217
+ repeats: true,
218
+ name: :undefine
219
+
220
+ option '-X', value: {type: Enum[:gnu, :vc]},
221
+ name: :message_style
222
+
223
+ option '--prefix'
224
+ option '--suffix'
225
+
226
+ argument :file, type: InputFile.new
227
+ end
228
+
229
+ # The known YASM targets
230
+ TARGETS = {
231
+ x86: {arch: :x86, machine: :x86},
232
+ amd64: {arch: :x86, machine: :amd64},
233
+ lc3b: {arch: :lc3b, machine: :lc3b}
234
+ }
235
+
236
+ #
237
+ # Determines which target was set.
238
+ #
239
+ # @return [:x86, :amd64, :lc3b, nil]
240
+ # The target name or `nil` if no target has been set.
241
+ #
242
+ def target
243
+ if arch && machine
244
+ TARGETS.key(arch: arch.to_sym, machine: machine.to_sym)
245
+ end
246
+ end
247
+
248
+ #
249
+ # Sets that target.
250
+ #
251
+ # @param [:x86, :amd64, :lc3b] name
252
+ # The target name.
253
+ #
254
+ # @return [Symbol]
255
+ # The set target.
256
+ #
257
+ # @raise [ArgumentError]
258
+ # An unknown target name was given.
259
+ #
260
+ def target=(name)
261
+ target = TARGETS.fetch(name.to_sym) do
262
+ raise(ArgumentError,"unknown YASM target: #{name.inspect}")
263
+ end
264
+
265
+ self.arch = target[:arch]
266
+ self.machine = target[:machine]
267
+ return name
268
+ end
269
+
270
+ alias syntax parser
271
+ alias syntax= parser=
272
+
273
+ end
274
+ end
data/lib/yasm/program.rb CHANGED
@@ -1,11 +1,12 @@
1
- require 'yasm/task'
1
+ # frozen_string_literal: true
2
2
 
3
- require 'rprogram'
3
+ require_relative 'command'
4
4
 
5
5
  module YASM
6
- class Program < RProgram::Program
7
-
8
- name_program 'yasm'
6
+ #
7
+ # @deprecated Please use {Command} instead.
8
+ #
9
+ class Program < Command
9
10
 
10
11
  #
11
12
  # Finds the `yasm` program and assembles a file.
@@ -13,15 +14,12 @@ module YASM
13
14
  # @param [Hash{Symbol => Object}] options
14
15
  # Additional options for yasm.
15
16
  #
16
- # @param [Hash{Symbol => Object}] exec_options
17
- # Additional exec-options.
18
- #
19
- # @yield [task]
20
- # If a block is given, it will be passed a task object used to
17
+ # @yield [program]
18
+ # If a block is given, it will be passed a program object used to
21
19
  # specify options for yasm.
22
20
  #
23
- # @yieldparam [Task] task
24
- # The yasm task object.
21
+ # @yieldparam [Program] program
22
+ # The yasm program object.
25
23
  #
26
24
  # @return [Boolean]
27
25
  # Specifies whether the command exited normally.
@@ -44,8 +42,8 @@ module YASM
44
42
  #
45
43
  # @see #assemble
46
44
  #
47
- def self.assemble(options={},exec_options={},&block)
48
- find.assemble(options,exec_options,&block)
45
+ def self.assemble(options={},&block)
46
+ new(options,&block).assemble()
49
47
  end
50
48
 
51
49
  #
@@ -54,15 +52,12 @@ module YASM
54
52
  # @param [Hash{Symbol => Object}] options
55
53
  # Additional options for yasm.
56
54
  #
57
- # @param [Hash{Symbol => Object}] exec_options
58
- # Additional exec-options.
59
- #
60
- # @yield [task]
61
- # If a block is given, it will be passed a task object used to
55
+ # @yield [program]
56
+ # If a block is given, it will be passed a program object used to
62
57
  # specify options for yasm.
63
58
  #
64
- # @yieldparam [Task] task
65
- # The yasm task object.
59
+ # @yieldparam [Program] program
60
+ # The yasm program object.
66
61
  #
67
62
  # @return [Boolean]
68
63
  # Specifies whether the command exited normally.
@@ -83,11 +78,22 @@ module YASM
83
78
  # yasm.output = 'code.o'
84
79
  # end
85
80
  #
86
- # @see http://rubydoc.info/gems/rprogram/0.3.0/RProgram/Program#run-instance_method
87
- # For additional exec-options.
81
+ def assemble(options={})
82
+ options.each do |name,value|
83
+ self[name] = value
84
+ end
85
+
86
+ yield self if block_given?
87
+
88
+ run_command()
89
+ end
90
+
91
+ #
92
+ # @deprecated Please use {#target=} instead.
88
93
  #
89
- def assemble(options={},exec_options={},&block)
90
- run_task(Task.new(options,&block),exec_options)
94
+ def target!(name)
95
+ self.target = name
96
+ return true
91
97
  end
92
98
 
93
99
  end
data/lib/yasm/version.rb CHANGED
@@ -1,4 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module YASM
2
4
  # ruby-yasm VERSION
3
- VERSION = '0.2.1'
5
+ VERSION = '0.3.1'
4
6
  end
data/lib/yasm.rb CHANGED
@@ -1,2 +1,3 @@
1
- require 'yasm/program'
2
- require 'yasm/version'
1
+ require_relative 'yasm/command'
2
+ require_relative 'yasm/program'
3
+ require_relative 'yasm/version'