hexhelper 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 09ced30dd9c164580fc5ae58cdb57017754b6163
4
+ data.tar.gz: 684781351e0bd8bcf0b3f5b8e316226600b431d6
5
+ SHA512:
6
+ metadata.gz: 9dc22a33d841058aceb7affed3d243da28c0b2d9d0185c17c0a51147e83a7077c374adf526ac1478d9e87b62d26eb51602ad31c19493ab725877e6ce3eb33743
7
+ data.tar.gz: d4b4882c9a1a78c0cdaf6731ab11c3bf8334663a07205bd95ea353a72f3f4cb05bdf86dccc83c32a379afc40f0c3f51a8a5ea29aff0584e5fb4c1ac59b4ed55c
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hexhelper.gemspec
4
+ gemspec
data/LICENSE.md ADDED
@@ -0,0 +1,10 @@
1
+ Copyright (c) 2013-2017, Ron Bowes
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ - Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+ - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
8
+ - Neither the name of the organization nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
9
+
10
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Hexhelper
2
+
3
+ This gem simply makes it easy to dump a binary string as nicely formatted hex.
4
+
5
+ I found myself copying and pasting this code/project to a million different
6
+ projects, so I thought it'd make sense to create a gem out of it.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'hexhelper'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install hexhelper
23
+
24
+ ## Usage
25
+
26
+ Using it is simple!
27
+
28
+ ```ruby
29
+ require 'hexhelper'
30
+
31
+ str = "This is a test string\x00\x01\x02"
32
+ puts Hexhelper::to_s(str)
33
+ ```
34
+
35
+ ## Contributing
36
+
37
+ Bug reports and pull requests are welcome on GitHub at
38
+ https://github.com/iagox86/hexhelper
39
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "hexhelper"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/hexhelper.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'hexhelper/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "hexhelper"
8
+ spec.version = Hexhelper::VERSION
9
+ spec.authors = ["iagox86"]
10
+ spec.email = ["ron-git@skullsecurity.org"]
11
+
12
+ spec.summary = "A simple gem for printing nicely-formatted hex strings"
13
+ spec.homepage = "https://github.com/iagox86/hexhelper"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_development_dependency "bundler"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency "simplecov"
21
+ end
@@ -0,0 +1,3 @@
1
+ module Hexhelper
2
+ VERSION = "0.0.1"
3
+ end
data/lib/hexhelper.rb ADDED
@@ -0,0 +1,79 @@
1
+ # Encoding: ASCII-8BIT
2
+ ##
3
+ # hexhelper.rb
4
+ # Created November, 2012
5
+ # By Ron Bowes
6
+ #
7
+ # See: LICENSE.md
8
+ #
9
+ # This is a simple utility class that converts an arbitrary binary string into
10
+ # a user-readable string.
11
+ ##
12
+
13
+ class HexHelper
14
+ BYTE_NUMBER_LENGTH = 8
15
+ SPACES_BEFORE_HEX = 2
16
+ SPACES_BEFORE_ASCII = 2
17
+ LINE_LENGTH = 16
18
+
19
+ # Convert the arbitrary binary data, 'data', into a user-readable string.
20
+ def self.to_s(data, indent: 0, offset: nil)
21
+ length = data.length
22
+ out = (' ' * indent)
23
+
24
+ 0.upto(length - 1) do |i|
25
+ # This section encodes all the hex lines, including the final partial line
26
+ if((i % LINE_LENGTH) == 0)
27
+ if(i != 0)
28
+ # Subtract one from the indent because we print a space surrounding
29
+ # the actual hex number
30
+ out = out + "\n" + (' ' * indent)
31
+ end
32
+ # Minus 1, so we can potentially replace the last one with a current-
33
+ # place marker
34
+ out = out + ("%0#{BYTE_NUMBER_LENGTH}x" % i) + " " * (SPACES_BEFORE_HEX - 1)
35
+ if(offset && (i == offset))
36
+ out = out + '<'
37
+ else
38
+ out = out + ' '
39
+ end
40
+ end
41
+
42
+ out = out + ("%02x" % data[i].ord)
43
+ # Always put a '>' immediately after the highlighted offset
44
+ if(i == offset)
45
+ out = out + '>'
46
+ # Put a '>' after the value before the chosen offset, unless we're at
47
+ # the end of a line or the absolute end
48
+ elsif((i + 1 == offset) && (((i + 1) % LINE_LENGTH) != 0) && ((i + 1) % length) != 0)
49
+ out = out + '<'
50
+ else
51
+ out = out + ' '
52
+ end
53
+
54
+ if(((i + 1) % LINE_LENGTH) == 0)
55
+ out = out + (" " * SPACES_BEFORE_ASCII)
56
+ LINE_LENGTH.step(1, -1) do |j|
57
+ out = out + ("%c" % ((data[i + 1 - j].ord > 0x20 && data[i + 1 - j].ord < 0x80) ? data[i + 1 - j].ord : ?.))
58
+ end
59
+ end
60
+
61
+ end
62
+
63
+ # This encodes the partial line of ascii, plus the spaces before
64
+ if((length % LINE_LENGTH) != 0)
65
+ # Add extra spaces between the hex and the ascii
66
+ (length % LINE_LENGTH).upto(LINE_LENGTH - 1) do |i|
67
+ out = out + (' ') # The width of a hex character and a space
68
+ end
69
+ out = out + (' ' * SPACES_BEFORE_ASCII)
70
+
71
+ # Add the final line of characters
72
+ (length - (length % LINE_LENGTH)).upto(length - 1) do |i|
73
+ out = out + ("%c" % ((data[i].ord > 0x20 && data[i].ord < 0x80) ? data[i].ord : ?.))
74
+ end
75
+ end
76
+
77
+ return out
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hexhelper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - iagox86
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-06-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: simplecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - ron-git@skullsecurity.org
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - ".travis.yml"
64
+ - Gemfile
65
+ - LICENSE.md
66
+ - README.md
67
+ - Rakefile
68
+ - bin/console
69
+ - bin/setup
70
+ - hexhelper.gemspec
71
+ - lib/hexhelper.rb
72
+ - lib/hexhelper/version.rb
73
+ homepage: https://github.com/iagox86/hexhelper
74
+ licenses: []
75
+ metadata: {}
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubyforge_project:
92
+ rubygems_version: 2.5.1
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: A simple gem for printing nicely-formatted hex strings
96
+ test_files: []