Sha256: 9a40d8e146df48df3de02467b7874638a9477b57bf71360776589752626f3e62

Contents?: true

Size: 670 Bytes

Versions: 2

Compression:

Stored size: 670 Bytes

Contents

class Libnet
  attr_reader :injection_type

  # :call-seq:
  #   Libnet.hexdump(bytes) # -> string
  #
  # Returns a string containing a hexdump of the given byte string.
  #
  # Example:
  #   Libnet.hexump("foobar")
  #
  # produces the following string:
  #
  #   0x00000000: 666f6f62 6172
  def self.hexdump(bytes)
    offset = 0
    i      = 0
    dump   = "0x00000000: "

    bytes.each_byte do |b|
      if i != 0
        if i % 16 == 0
          offset += 16
          dump += sprintf("\n0x%08x: ", offset)
        elsif i % 4 == 0
          dump += " "
        end
      end

      dump += sprintf("%02x", b)

      i += 1
    end

    dump += "\n"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
libnet4r-0.1 lib/libnet4r/libnet.rb
libnet4r-0.2 lib/libnet4r/libnet.rb