bin2hex 0.0.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.
- data/bin/bin2hex +50 -0
- data/lib/bin2hex.rb +21 -0
- metadata +66 -0
data/bin/bin2hex
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "optparse"
|
|
4
|
+
require "ostruct"
|
|
5
|
+
require "bin2hex"
|
|
6
|
+
|
|
7
|
+
DEFAULT_BYTE_FORMAT = '0x%02x, '
|
|
8
|
+
DEFAULT_OUTPUT_FILE_NAME = '%s.hex'
|
|
9
|
+
|
|
10
|
+
def parse_args(args)
|
|
11
|
+
options = OpenStruct.new
|
|
12
|
+
options.format = DEFAULT_BYTE_FORMAT
|
|
13
|
+
options.output_file = DEFAULT_OUTPUT_FILE_NAME
|
|
14
|
+
|
|
15
|
+
option_parser = OptionParser.new do |opts|
|
|
16
|
+
opts.banner = "Usage: bin2hex [options] file"
|
|
17
|
+
|
|
18
|
+
opts.on("-h", "--help", "Shows this help") do
|
|
19
|
+
puts opts
|
|
20
|
+
exit
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
opts.on( "--format=[FORMAT]", String, "Specify a format string (default: '#{DEFAULT_BYTE_FORMAT}')") do |f|
|
|
24
|
+
options.format = f
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
opts.on( "--out=[FILENAME]", String, "Name of the output file") do |f|
|
|
28
|
+
options.output_file = f
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
begin
|
|
33
|
+
option_parser.parse!(args)
|
|
34
|
+
rescue OptionParser::InvalidOption
|
|
35
|
+
puts option_parser # help and quit
|
|
36
|
+
exit
|
|
37
|
+
end
|
|
38
|
+
if args.length == 0 then
|
|
39
|
+
puts option_parser # no filename inputted, show help and quit
|
|
40
|
+
exit
|
|
41
|
+
end
|
|
42
|
+
options.input_file = args.join(' ') # input file from remaining args not consumed by optparse
|
|
43
|
+
return options
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
options = parse_args(ARGV)
|
|
47
|
+
b2h = BinaryToHexFileConverter.new({ :format => options.format })
|
|
48
|
+
b2h.process_file(options.input_file, options.output_file)
|
|
49
|
+
|
|
50
|
+
|
data/lib/bin2hex.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
class BinaryToHexFileConverter
|
|
4
|
+
|
|
5
|
+
def initialize(options)
|
|
6
|
+
@options = options
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def process_file(input, output)
|
|
10
|
+
begin
|
|
11
|
+
File.open(sprintf(output, input), "w") do |out_file|
|
|
12
|
+
File.open(input, "rb").each_byte do |b|
|
|
13
|
+
out_file.write(sprintf(@options[:format], b))
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
rescue Errno::ENOENT => e
|
|
17
|
+
puts "Error: #{e.message}"
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: bin2hex
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
hash: 29
|
|
5
|
+
prerelease:
|
|
6
|
+
segments:
|
|
7
|
+
- 0
|
|
8
|
+
- 0
|
|
9
|
+
- 1
|
|
10
|
+
version: 0.0.1
|
|
11
|
+
platform: ruby
|
|
12
|
+
authors:
|
|
13
|
+
- Dextrey
|
|
14
|
+
autorequire:
|
|
15
|
+
bindir: bin
|
|
16
|
+
cert_chain: []
|
|
17
|
+
|
|
18
|
+
date: 2012-08-01 00:00:00 Z
|
|
19
|
+
dependencies: []
|
|
20
|
+
|
|
21
|
+
description: Converts any binary file into a hex format text file
|
|
22
|
+
email: dextrey010@gmail.com
|
|
23
|
+
executables:
|
|
24
|
+
- bin2hex
|
|
25
|
+
extensions: []
|
|
26
|
+
|
|
27
|
+
extra_rdoc_files: []
|
|
28
|
+
|
|
29
|
+
files:
|
|
30
|
+
- lib/bin2hex.rb
|
|
31
|
+
- bin/bin2hex
|
|
32
|
+
homepage:
|
|
33
|
+
licenses: []
|
|
34
|
+
|
|
35
|
+
post_install_message:
|
|
36
|
+
rdoc_options: []
|
|
37
|
+
|
|
38
|
+
require_paths:
|
|
39
|
+
- lib
|
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
hash: 3
|
|
46
|
+
segments:
|
|
47
|
+
- 0
|
|
48
|
+
version: "0"
|
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ">="
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
hash: 3
|
|
55
|
+
segments:
|
|
56
|
+
- 0
|
|
57
|
+
version: "0"
|
|
58
|
+
requirements: []
|
|
59
|
+
|
|
60
|
+
rubyforge_project:
|
|
61
|
+
rubygems_version: 1.8.15
|
|
62
|
+
signing_key:
|
|
63
|
+
specification_version: 3
|
|
64
|
+
summary: Binary to hex file converter
|
|
65
|
+
test_files: []
|
|
66
|
+
|