# # Ronin Exploits - A Ruby library for Ronin that provides exploitation and # payload crafting functionality. # # Copyright (c) 2007-2009 Hal Brodigan (postmodern.mod3 at gmail.com) # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA # require 'ronin/formatting/text' module Ronin module Exploits module Helpers module Padding def self.extended(obj) obj.instance_eval do # String to pad extra space with parameter :padding, :default => 'A', :description => 'padding string' end end protected # # Creates padding out to a maximum length, using the +padding+ # parameter. # # @param [Integer] max_length # The maximum length to pad out to. # # @return [String] # A padded string. # # @example # pad(28) # # => "AAAAAAAAAAAAAAAAAAAAAAAAAAAA" # def pad(max_length) ''.pad(@padding.to_s,max_length) end # # Pads the a string on the right-hand side out to a maximum length, # using the +padding+ parameter. # # @param [String] data # The string to add padding to. # # @param [Integer] max_length # The amount of padding to add. # # @return [String] # The left-hand side padded string. # # @example # pad_left("\xff\xff",48) # # => "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\xff\xff" # def pad_left(data,max_length) pad(max_length - data.length) + data end # # Pads the a string on the right-hand side out to a maximum length, # using the +padding+ parameter. # # @param [String] data # The string to add padding to. # # @param [Integer] max_length # The amount of padding to add. # # @return [String] # The right-hand side padded string. # # @example # pad_right("\xff\xff",48) # # => "\xff\xffAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" # def pad_right(data,max_length) data.to_s.pad(@padding,max_length) end end end end end