Class: Unisec::Hexdump
- Inherits:
-
Object
- Object
- Unisec::Hexdump
- Defined in:
- lib/unisec/hexdump.rb
Overview
Hexdump of all Unicode encodings.
Instance Attribute Summary collapse
-
#utf16be ⇒ String
readonly
UTF-16BE hexdump.
-
#utf16le ⇒ String
readonly
UTF-16LE hexdump.
-
#utf32be ⇒ String
readonly
UTF-32BE hexdump.
-
#utf32le ⇒ String
readonly
UTF-32LE hexdump.
-
#utf8 ⇒ String
readonly
UTF-8 hexdump.
Class Method Summary collapse
-
.utf16be(str) ⇒ String
Encode to UTF-16BE in hexdump format (spaced at every code unit = every 2 bytes).
-
.utf16le(str) ⇒ String
Encode to UTF-16LE in hexdump format (spaced at every code unit = every 2 bytes).
-
.utf32be(str) ⇒ String
Encode to UTF-32BE in hexdump format (spaced at every code unit = every 4 bytes).
-
.utf32le(str) ⇒ String
Encode to UTF-32LE in hexdump format (spaced at every code unit = every 4 bytes).
-
.utf8(str) ⇒ String
Encode to UTF-8 in hexdump format (spaced at every code unit = every byte).
Instance Method Summary collapse
-
#display ⇒ String
Display a CLI-friendly output summurizing the hexdump in all Unicode encodings.
-
#initialize(str) ⇒ Hexdump
constructor
Init the hexdump.
Constructor Details
#initialize(str) ⇒ Hexdump
Init the hexdump.
35 36 37 38 39 40 41 |
# File 'lib/unisec/hexdump.rb', line 35 def initialize(str) @utf8 = Hexdump.utf8(str) @utf16be = Hexdump.utf16be(str) @utf16le = Hexdump.utf16le(str) @utf32be = Hexdump.utf32be(str) @utf32le = Hexdump.utf32le(str) end |
Instance Attribute Details
#utf16be ⇒ String (readonly)
UTF-16BE hexdump
14 15 16 |
# File 'lib/unisec/hexdump.rb', line 14 def utf16be @utf16be end |
#utf16le ⇒ String (readonly)
UTF-16LE hexdump
18 19 20 |
# File 'lib/unisec/hexdump.rb', line 18 def utf16le @utf16le end |
#utf32be ⇒ String (readonly)
UTF-32BE hexdump
22 23 24 |
# File 'lib/unisec/hexdump.rb', line 22 def utf32be @utf32be end |
#utf32le ⇒ String (readonly)
UTF-32LE hexdump
26 27 28 |
# File 'lib/unisec/hexdump.rb', line 26 def utf32le @utf32le end |
#utf8 ⇒ String (readonly)
UTF-8 hexdump
10 11 12 |
# File 'lib/unisec/hexdump.rb', line 10 def utf8 @utf8 end |
Class Method Details
.utf16be(str) ⇒ String
Encode to UTF-16BE in hexdump format (spaced at every code unit = every 2 bytes)
57 58 59 |
# File 'lib/unisec/hexdump.rb', line 57 def self.utf16be(str) str.encode('UTF-16BE').to_hex.scan(/.{4}/).join(' ') end |
.utf16le(str) ⇒ String
Encode to UTF-16LE in hexdump format (spaced at every code unit = every 2 bytes)
66 67 68 |
# File 'lib/unisec/hexdump.rb', line 66 def self.utf16le(str) str.encode('UTF-16LE').to_hex.scan(/.{4}/).join(' ') end |
.utf32be(str) ⇒ String
Encode to UTF-32BE in hexdump format (spaced at every code unit = every 4 bytes)
75 76 77 |
# File 'lib/unisec/hexdump.rb', line 75 def self.utf32be(str) str.encode('UTF-32BE').to_hex.scan(/.{8}/).join(' ') end |
.utf32le(str) ⇒ String
Encode to UTF-32LE in hexdump format (spaced at every code unit = every 4 bytes)
84 85 86 |
# File 'lib/unisec/hexdump.rb', line 84 def self.utf32le(str) str.encode('UTF-32LE').to_hex.scan(/.{8}/).join(' ') end |
.utf8(str) ⇒ String
Encode to UTF-8 in hexdump format (spaced at every code unit = every byte)
48 49 50 |
# File 'lib/unisec/hexdump.rb', line 48 def self.utf8(str) str.encode('UTF-8').to_hex.scan(/.{2}/).join(' ') end |
Instance Method Details
#display ⇒ String
Display a CLI-friendly output summurizing the hexdump in all Unicode encodings
97 98 99 100 101 102 103 |
# File 'lib/unisec/hexdump.rb', line 97 def display "UTF-8: #{@utf8}\n" \ "UTF-16BE: #{@utf16be}\n" \ "UTF-16LE: #{@utf16le}\n" \ "UTF-32BE: #{@utf32be}\n" \ "UTF-32LE: #{@utf32le}" end |