# #-- # 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.included(base) base.module_eval do # String to pad extra space with parameter :padding, :default => 'A', :description => 'padding string' end end def self.extended(obj) obj.instance_eval do # String to pad extra space with parameter :padding, :default => 'A', :description => 'padding string' end end protected # # Returns padding with the specified _max_length_. # # pad(28) # # => "AAAAAAAAAAAAAAAAAAAAAAAAAAAA" # def pad(max_length) ''.pad(@padding.to_s,max_length) end # # Pads the specified _data_ to the left up to the specified # _max_length_. # # pad_left("\xff\xff",48) # # => "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\xff\xff" # def pad_left(data,max_length) pad(max_length - data.length) + data end # # Pads the specified _data_ to the right up to the specified # _max_length_. # # 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