# # 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 # module Ronin module Controls module FileSystem # # The current working directory, all file-system actions will # be performed relative to. # # @return [String] # The current working directory. # # @since 0.3.0 # def cwd @cwd ||= '' end # # Changes the current working directory. # # @param [String] path # The new current working directory. # # @return [String] # The new current working directory. # # @since 0.3.0 # def chdir(path) @cwd = path end # # Goes up one directory. # # @return [String] # The new current working directory. # # @since 0.3.0 # def updir! chdir(join_paths(cwd,'..')) end protected # # @return [String] # The File name separator to use. # # @since 0.3.0 # def path_separator File::SEPARATOR end # # Joins multiple paths with the path_separator. # # @param [Array] paths # The paths to be joined. # # @return [String] # The joined paths. # # @since 0.3.0 # def join_paths(*paths) paths.join(path_separator) end # # Expands a path into it's absolute form. # # @param [String] path # The path to be expanded. # # @return [String] # The expanded path. # # @since 0.3.0 # def expand_path(path) File.expand_path(path) end # # Converts a sub-path to an absolute path, but only if it is a # realitive path. # # @param [String] sub_path # The sub-path to expand. # # @return [String] # An absolute path. # # @since 0.3.0 # def absolute_path(sub_path) if sub_path[0..0] == path_separator return sub_path else return expand_path(join_paths(cwd,sub_path)) end end # # Specifies that the path could not be found. # # @param [String] path # The path which could not be found. # # @raise [Errno::ENOENT] # The file could not be found. # # @since 0.3.0 # def file_not_found!(path) path = path.to_s raise(Errno::ENOENT,"No such file or directory - #{path.dump}",caller) end end end end