lib/ronin/formatting/extensions/binary/string.rb in ronin-support-0.1.0 vs lib/ronin/formatting/extensions/binary/string.rb in ronin-support-0.2.0.rc1
- old
+ new
@@ -67,10 +67,12 @@
# "A\0\0\0".depack('L')
# # => 65
#
# @see http://ruby-doc.org/core/classes/String.html#M000760
#
+ # @api public
+ #
def depack(arch,address_length=nil)
if arch.kind_of?(String)
return self.unpack(arch)
end
@@ -116,22 +118,28 @@
# "hello".hex_escape
# # => "\\x68\\x65\\x6c\\x6c\\x6f"
#
# @see String#format_bytes
#
+ # @api public
+ #
def hex_escape(options={})
format_bytes(options) { |b| b.hex_escape }
end
#
+ # Unescapes the hex-escaped String.
+ #
# @return [String]
# The unescaped version of the hex escaped String.
#
# @example
# "\\x68\\x65\\x6c\\x6c\\x6f".hex_unescape
# # => "hello"
#
+ # @api public
+ #
def hex_unescape
buffer = ''
hex_index = 0
hex_length = length
@@ -194,10 +202,12 @@
#
# @example
# "hello again".xor([0x55, 0x41, 0xe1])
# # => "=$\x8d9.\xc14&\x80</"
#
+ # @api public
+ #
def xor(key)
key = if key.kind_of?(Integer)
[key]
elsif key.kind_of?(String)
key.bytes
@@ -217,40 +227,48 @@
# Base64 encodes a string.
#
# @return [String]
# The base64 encoded form of the string.
#
+ # @api public
+ #
def base64_encode
Base64.encode64(self)
end
#
# Base64 decodes a string.
#
# @return [String]
# The base64 decoded form of the string.
#
+ # @api public
+ #
def base64_decode
Base64.decode64(self)
end
#
# Zlib inflate a string.
#
# @return [String]
# The Zlib inflated form of the string.
#
+ # @api public
+ #
def zlib_inflate
Zlib::Inflate.inflate(self)
end
#
# Zlib deflate a string.
#
# @return [String]
# The Zlib deflated form of the string.
#
+ # @api public
+ #
def zlib_deflate
Zlib::Deflate.deflate(self)
end
#
@@ -285,9 +303,11 @@
#
# @option options [Integer] :segment (16)
# The length in bytes of each segment in the hexdump.
#
# @return [String] The raw-data from the hexdump.
+ #
+ # @api public
#
def unhexdump(options={})
case (format = options[:format])
when :od
address_base = base = 8