hex_file 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CONTRIBUTORS.txt +3 -0
- data/README.md +11 -2
- data/bin/hex_file_info +5 -8
- data/hex_file.gemspec +1 -1
- data/lib/hex_file.rb +3 -3
- data/lib/hex_file/info.rb +10 -3
- data/lib/hex_file/record.rb +46 -19
- data/lib/hex_file/version.rb +1 -1
- metadata +12 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f77f0154856077426de2b1aa957d8fa12059bb8c
|
4
|
+
data.tar.gz: 7ae2a43b98054b3a4e6ae624dd90eeba2711f971
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3a37457b3590074ebb53fce05f518ae68a22ca2231e2a8b3f8b7b9d5f495f9fc4095b369a78a881c02c3b7d2d8ced387628c9295b2f6377850942f04f3ebe12
|
7
|
+
data.tar.gz: 1dee9a73afb8285e8f7758aa16a79cdf2fe2f5a76a4cabb63ba17f388b9995d8da0012294585816027d05f427be900f060d682bb36d1661bf6de4bb6fb1f3008
|
data/CONTRIBUTORS.txt
ADDED
data/README.md
CHANGED
@@ -37,12 +37,21 @@ Or install it yourself as:
|
|
37
37
|
puts record.type
|
38
38
|
puts record.data
|
39
39
|
puts record.checksum
|
40
|
-
puts record.ok?
|
40
|
+
puts record.ok? # true if checksum correct
|
41
41
|
end
|
42
42
|
|
43
|
+
Also there is a bin script that gives a summary
|
44
|
+
|
45
|
+
$ hex_file_info myfile.hex
|
46
|
+
Format: I32HEX
|
47
|
+
Records: 7133
|
48
|
+
Binary Size (bytes): 113918
|
49
|
+
|
50
|
+
Note if you're an rbenv user, don't forget to `rbenv rehash` after installing the gem to make the `hex_file_info` script available.
|
51
|
+
|
43
52
|
## Contributing
|
44
53
|
|
45
|
-
1. Fork it
|
54
|
+
1. Fork it
|
46
55
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
47
56
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
48
57
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/bin/hex_file_info
CHANGED
@@ -3,18 +3,15 @@
|
|
3
3
|
require 'hex_file'
|
4
4
|
require 'optparse'
|
5
5
|
|
6
|
+
usage = "\nUsage: #{$0} <hexfile.hex>\n\n"
|
7
|
+
|
6
8
|
OptionParser.new do |opts|
|
7
|
-
opts.banner =
|
8
|
-
opts.on_tail("-h", "--help", "Show this message") do
|
9
|
-
puts "Usage: #{$0}"
|
10
|
-
exit
|
11
|
-
end
|
9
|
+
opts.banner = usage
|
12
10
|
end.parse!
|
13
11
|
|
14
12
|
opt = ARGV.pop
|
15
|
-
if
|
16
|
-
puts
|
17
|
-
puts
|
13
|
+
if opt.nil?
|
14
|
+
puts usage
|
18
15
|
exit
|
19
16
|
end
|
20
17
|
|
data/hex_file.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["sean@clanmccarthy.net"]
|
11
11
|
spec.summary = %q{Parses Intel HEX files and gives metadata about the file and records.}
|
12
12
|
spec.description = %q{Parses Intel HEX files and gives metadata about the file and records.}
|
13
|
-
spec.homepage = ""
|
13
|
+
spec.homepage = "https://github.com/seandmccarthy/hex_file_info"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files -z`.split("\x0")
|
data/lib/hex_file.rb
CHANGED
data/lib/hex_file/info.rb
CHANGED
@@ -10,6 +10,15 @@ module HexFile
|
|
10
10
|
@records.each
|
11
11
|
end
|
12
12
|
|
13
|
+
def find_record regex
|
14
|
+
regex = Regexp.new(regex, 'i') unless regex.is_a?(Regexp)
|
15
|
+
records.find { |rec| rec.data =~ regex }
|
16
|
+
end
|
17
|
+
|
18
|
+
def serialize
|
19
|
+
records.map(&:raw).join("\n")
|
20
|
+
end
|
21
|
+
|
13
22
|
def binary_size
|
14
23
|
records.map { |r| r.data_size }.reduce(:+)
|
15
24
|
end
|
@@ -24,15 +33,13 @@ module HexFile
|
|
24
33
|
end
|
25
34
|
end
|
26
35
|
|
27
|
-
private
|
28
|
-
|
29
36
|
def record_types
|
30
37
|
@record_types ||= records.map { |r| r.type }.uniq
|
31
38
|
end
|
32
39
|
|
33
40
|
def linear_record_types?(record_types)
|
34
41
|
record_types.include?(Record::EXTENDED_LINEAR_ADDRESS) ||
|
35
|
-
|
42
|
+
record_types.include?(Record::START_LINEAR_ADDRESS)
|
36
43
|
end
|
37
44
|
|
38
45
|
def start_segment_record_type?(record_types)
|
data/lib/hex_file/record.rb
CHANGED
@@ -1,18 +1,55 @@
|
|
1
1
|
module HexFile
|
2
|
-
class InvalidRecord < StandardError;
|
2
|
+
class InvalidRecord < StandardError;
|
3
|
+
end
|
3
4
|
|
4
5
|
class Record
|
6
|
+
|
7
|
+
class InvalidLength < InvalidRecord
|
8
|
+
end
|
9
|
+
|
5
10
|
DATA = '00'
|
6
11
|
END_OF_FILE = '01'
|
7
12
|
EXTENDED_SEGMENT_ADDRESS = '02'
|
8
13
|
START_SEGMENT_ADDRESS = '03'
|
9
14
|
EXTENDED_LINEAR_ADDRESS = '04'
|
10
15
|
START_LINEAR_ADDRESS = '05'
|
11
|
-
|
16
|
+
|
12
17
|
attr_reader :type, :byte_count, :address, :data, :checksum
|
13
18
|
|
14
19
|
def initialize(record_ascii)
|
15
|
-
|
20
|
+
fail HexFile::InvalidRecord, 'Missing start code' unless record_ascii.start_with?(':')
|
21
|
+
@byte_count = record_ascii[1..2]
|
22
|
+
@address = record_ascii[3..6]
|
23
|
+
@type = record_ascii[7..8]
|
24
|
+
@data = record_ascii[9..-3]
|
25
|
+
@checksum = record_ascii[-2..-1]
|
26
|
+
end
|
27
|
+
|
28
|
+
def raw
|
29
|
+
":#{content}#{@checksum}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def content
|
33
|
+
"#{@byte_count}#{@address}#{@type}#{@data}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_hex_data data
|
37
|
+
raise InvalidLength, "Data should be of length #{data_size}!" unless data.length == @data.length
|
38
|
+
|
39
|
+
@data = data
|
40
|
+
update_checksum
|
41
|
+
self
|
42
|
+
end
|
43
|
+
|
44
|
+
def set_data data
|
45
|
+
data = data.unpack('C*') if data.is_a? String # Assume binary string
|
46
|
+
hexdata = data.map{ |d| "%02X" % d }.join
|
47
|
+
|
48
|
+
set_hex_data hexdata
|
49
|
+
end
|
50
|
+
|
51
|
+
def update_checksum
|
52
|
+
@checksum = "%02X" % calculate_checksum
|
16
53
|
end
|
17
54
|
|
18
55
|
def data_size
|
@@ -23,24 +60,14 @@ module HexFile
|
|
23
60
|
@checksum.to_i(16) == calculate_checksum
|
24
61
|
end
|
25
62
|
|
26
|
-
private
|
27
63
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
@data = record_ascii[9..-3]
|
35
|
-
@checksum = record_ascii[-2..-1]
|
64
|
+
def calculate_checksum record_content = content
|
65
|
+
256 - (record_content
|
66
|
+
.scan(/../)
|
67
|
+
.map { |x| x.to_i(16) }
|
68
|
+
.reduce(:+)
|
69
|
+
) & 0xFF
|
36
70
|
end
|
37
71
|
|
38
|
-
def calculate_checksum
|
39
|
-
256 -
|
40
|
-
(@raw[1...-2]
|
41
|
-
.scan(/../)
|
42
|
-
.map { |x| x.to_i(16) }
|
43
|
-
.inject(:+)) & 0xFF
|
44
|
-
end
|
45
72
|
end
|
46
73
|
end
|
data/lib/hex_file/version.rb
CHANGED
metadata
CHANGED
@@ -1,41 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hex_file
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sean McCarthy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.7'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '10.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
description: Parses Intel HEX files and gives metadata about the file and records.
|
@@ -47,7 +47,8 @@ executables:
|
|
47
47
|
extensions: []
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
|
-
- .gitignore
|
50
|
+
- ".gitignore"
|
51
|
+
- CONTRIBUTORS.txt
|
51
52
|
- Gemfile
|
52
53
|
- LICENSE.txt
|
53
54
|
- README.md
|
@@ -62,7 +63,7 @@ files:
|
|
62
63
|
- lib/hex_file/version.rb
|
63
64
|
- test/test_info.rb
|
64
65
|
- test/test_record.rb
|
65
|
-
homepage:
|
66
|
+
homepage: https://github.com/seandmccarthy/hex_file_info
|
66
67
|
licenses:
|
67
68
|
- MIT
|
68
69
|
metadata: {}
|
@@ -72,17 +73,17 @@ require_paths:
|
|
72
73
|
- lib
|
73
74
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
75
|
requirements:
|
75
|
-
- -
|
76
|
+
- - ">="
|
76
77
|
- !ruby/object:Gem::Version
|
77
78
|
version: '0'
|
78
79
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
80
|
requirements:
|
80
|
-
- -
|
81
|
+
- - ">="
|
81
82
|
- !ruby/object:Gem::Version
|
82
83
|
version: '0'
|
83
84
|
requirements: []
|
84
85
|
rubyforge_project:
|
85
|
-
rubygems_version: 2.
|
86
|
+
rubygems_version: 2.5.2.2
|
86
87
|
signing_key:
|
87
88
|
specification_version: 4
|
88
89
|
summary: Parses Intel HEX files and gives metadata about the file and records.
|