ronin 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING.txt +339 -0
- data/History.txt +34 -0
- data/Manifest.txt +157 -0
- data/README.txt +131 -0
- data/Rakefile +23 -0
- data/TODO.txt +6 -0
- data/bin/ronin +12 -0
- data/lib/ronin.rb +35 -0
- data/lib/ronin/arch.rb +86 -0
- data/lib/ronin/author.rb +88 -0
- data/lib/ronin/cache.rb +27 -0
- data/lib/ronin/cache/config.rb +34 -0
- data/lib/ronin/cache/exceptions.rb +25 -0
- data/lib/ronin/cache/exceptions/extension_not_found.rb +29 -0
- data/lib/ronin/cache/exceptions/overlay_cached.rb +29 -0
- data/lib/ronin/cache/exceptions/overlay_not_found.rb +29 -0
- data/lib/ronin/cache/extension.rb +706 -0
- data/lib/ronin/cache/extension_cache.rb +108 -0
- data/lib/ronin/cache/overlay.rb +418 -0
- data/lib/ronin/cache/overlay_cache.rb +228 -0
- data/lib/ronin/cache/ronin.rb +50 -0
- data/lib/ronin/chars.rb +25 -0
- data/lib/ronin/chars/char_set.rb +121 -0
- data/lib/ronin/chars/chars.rb +180 -0
- data/lib/ronin/config.rb +31 -0
- data/lib/ronin/console.rb +127 -0
- data/lib/ronin/context.rb +233 -0
- data/lib/ronin/database.rb +122 -0
- data/lib/ronin/environment.rb +39 -0
- data/lib/ronin/exceptions/context_not_found.rb +27 -0
- data/lib/ronin/exceptions/invalid_database_config.rb +27 -0
- data/lib/ronin/exceptions/object_context_not_found.rb +27 -0
- data/lib/ronin/exceptions/unknown_context.rb +27 -0
- data/lib/ronin/exceptions/unknown_object_context.rb +27 -0
- data/lib/ronin/extensions.rb +28 -0
- data/lib/ronin/extensions/hash.rb +62 -0
- data/lib/ronin/extensions/kernel.rb +34 -0
- data/lib/ronin/extensions/meta.rb +24 -0
- data/lib/ronin/extensions/meta/object.rb +24 -0
- data/lib/ronin/extensions/string.rb +37 -0
- data/lib/ronin/extensions/uri.rb +24 -0
- data/lib/ronin/extensions/uri/http.rb +78 -0
- data/lib/ronin/extensions/uri/query_params.rb +97 -0
- data/lib/ronin/formatting.rb +29 -0
- data/lib/ronin/formatting/binary.rb +24 -0
- data/lib/ronin/formatting/digest.rb +24 -0
- data/lib/ronin/formatting/extensions.rb +26 -0
- data/lib/ronin/formatting/extensions/binary.rb +25 -0
- data/lib/ronin/formatting/extensions/binary/integer.rb +59 -0
- data/lib/ronin/formatting/extensions/binary/string.rb +73 -0
- data/lib/ronin/formatting/extensions/digest.rb +24 -0
- data/lib/ronin/formatting/extensions/digest/string.rb +65 -0
- data/lib/ronin/formatting/extensions/html.rb +24 -0
- data/lib/ronin/formatting/extensions/html/string.rb +75 -0
- data/lib/ronin/formatting/extensions/http.rb +24 -0
- data/lib/ronin/formatting/extensions/http/string.rb +69 -0
- data/lib/ronin/formatting/extensions/text.rb +24 -0
- data/lib/ronin/formatting/extensions/text/string.rb +96 -0
- data/lib/ronin/formatting/html.rb +24 -0
- data/lib/ronin/formatting/http.rb +24 -0
- data/lib/ronin/formatting/text.rb +24 -0
- data/lib/ronin/license.rb +87 -0
- data/lib/ronin/model.rb +44 -0
- data/lib/ronin/models.rb +34 -0
- data/lib/ronin/network.rb +31 -0
- data/lib/ronin/network/esmtp.rb +24 -0
- data/lib/ronin/network/extensions.rb +31 -0
- data/lib/ronin/network/extensions/esmtp.rb +24 -0
- data/lib/ronin/network/extensions/esmtp/net.rb +68 -0
- data/lib/ronin/network/extensions/http.rb +24 -0
- data/lib/ronin/network/extensions/http/net.rb +303 -0
- data/lib/ronin/network/extensions/imap.rb +24 -0
- data/lib/ronin/network/extensions/imap/net.rb +92 -0
- data/lib/ronin/network/extensions/pop3.rb +24 -0
- data/lib/ronin/network/extensions/pop3/net.rb +65 -0
- data/lib/ronin/network/extensions/smtp.rb +24 -0
- data/lib/ronin/network/extensions/smtp/net.rb +80 -0
- data/lib/ronin/network/extensions/tcp.rb +24 -0
- data/lib/ronin/network/extensions/tcp/net.rb +94 -0
- data/lib/ronin/network/extensions/telnet.rb +24 -0
- data/lib/ronin/network/extensions/telnet/net.rb +132 -0
- data/lib/ronin/network/extensions/udp.rb +24 -0
- data/lib/ronin/network/extensions/udp/net.rb +99 -0
- data/lib/ronin/network/http.rb +128 -0
- data/lib/ronin/network/http/exceptions.rb +24 -0
- data/lib/ronin/network/http/exceptions/unknown_request.rb +31 -0
- data/lib/ronin/network/imap.rb +47 -0
- data/lib/ronin/network/pop3.rb +47 -0
- data/lib/ronin/network/smtp.rb +26 -0
- data/lib/ronin/network/smtp/email.rb +126 -0
- data/lib/ronin/network/smtp/smtp.rb +55 -0
- data/lib/ronin/network/tcp.rb +24 -0
- data/lib/ronin/network/telnet.rb +95 -0
- data/lib/ronin/network/udp.rb +24 -0
- data/lib/ronin/object_context.rb +257 -0
- data/lib/ronin/objects.rb +29 -0
- data/lib/ronin/parameters.rb +27 -0
- data/lib/ronin/parameters/class_param.rb +45 -0
- data/lib/ronin/parameters/exceptions.rb +25 -0
- data/lib/ronin/parameters/exceptions/missing_param.rb +29 -0
- data/lib/ronin/parameters/exceptions/param_not_found.rb +29 -0
- data/lib/ronin/parameters/instance_param.rb +57 -0
- data/lib/ronin/parameters/param.rb +45 -0
- data/lib/ronin/parameters/parameters.rb +275 -0
- data/lib/ronin/path.rb +70 -0
- data/lib/ronin/pending_context.rb +42 -0
- data/lib/ronin/persistence.rb +32 -0
- data/lib/ronin/platform.rb +95 -0
- data/lib/ronin/product.rb +56 -0
- data/lib/ronin/ronin.rb +49 -0
- data/lib/ronin/rpc.rb +27 -0
- data/lib/ronin/rpc/call.rb +75 -0
- data/lib/ronin/rpc/client.rb +91 -0
- data/lib/ronin/rpc/console.rb +79 -0
- data/lib/ronin/rpc/exceptions.rb +25 -0
- data/lib/ronin/rpc/exceptions/not_implemented.rb +29 -0
- data/lib/ronin/rpc/exceptions/response_missing.rb +29 -0
- data/lib/ronin/rpc/interactive.rb +55 -0
- data/lib/ronin/rpc/interactive_console.rb +58 -0
- data/lib/ronin/rpc/interactive_shell.rb +59 -0
- data/lib/ronin/rpc/response.rb +57 -0
- data/lib/ronin/rpc/service.rb +69 -0
- data/lib/ronin/rpc/shell.rb +66 -0
- data/lib/ronin/runner.rb +24 -0
- data/lib/ronin/runner/program.rb +26 -0
- data/lib/ronin/runner/program/command.rb +204 -0
- data/lib/ronin/runner/program/commands.rb +33 -0
- data/lib/ronin/runner/program/commands/add.rb +73 -0
- data/lib/ronin/runner/program/commands/help.rb +52 -0
- data/lib/ronin/runner/program/commands/install.rb +65 -0
- data/lib/ronin/runner/program/commands/list.rb +81 -0
- data/lib/ronin/runner/program/commands/remove.rb +57 -0
- data/lib/ronin/runner/program/commands/uninstall.rb +57 -0
- data/lib/ronin/runner/program/commands/update.rb +55 -0
- data/lib/ronin/runner/program/exceptions.rb +24 -0
- data/lib/ronin/runner/program/exceptions/unknown_command.rb +31 -0
- data/lib/ronin/runner/program/options.rb +205 -0
- data/lib/ronin/runner/program/program.rb +173 -0
- data/lib/ronin/runner/program/runner.rb +35 -0
- data/lib/ronin/sessions.rb +32 -0
- data/lib/ronin/sessions/esmtp.rb +76 -0
- data/lib/ronin/sessions/imap.rb +73 -0
- data/lib/ronin/sessions/pop3.rb +70 -0
- data/lib/ronin/sessions/session.rb +52 -0
- data/lib/ronin/sessions/smtp.rb +76 -0
- data/lib/ronin/sessions/tcp.rb +111 -0
- data/lib/ronin/sessions/telnet.rb +76 -0
- data/lib/ronin/sessions/udp.rb +99 -0
- data/lib/ronin/sessions/web.rb +83 -0
- data/lib/ronin/shell.rb +81 -0
- data/lib/ronin/target.rb +40 -0
- data/lib/ronin/version.rb +27 -0
- data/lib/ronin/web.rb +24 -0
- data/lib/ronin/web/web.rb +265 -0
- data/spec/spec_helper.rb +9 -0
- data/tasks/spec.rb +7 -0
- metadata +324 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
4
|
+
# exploration tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#++
|
22
|
+
#
|
23
|
+
|
24
|
+
require 'ronin/extensions/kernel'
|
25
|
+
require 'ronin/object_context'
|
26
|
+
|
27
|
+
module Ronin
|
28
|
+
ronin_require 'ronin/objects'
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
4
|
+
# exploration tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#++
|
22
|
+
#
|
23
|
+
|
24
|
+
require 'ronin/parameters/param'
|
25
|
+
require 'ronin/parameters/class_param'
|
26
|
+
require 'ronin/parameters/instance_param'
|
27
|
+
require 'ronin/parameters/parameters'
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
4
|
+
# exploration tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#++
|
22
|
+
#
|
23
|
+
|
24
|
+
require 'ronin/parameters/param'
|
25
|
+
|
26
|
+
module Ronin
|
27
|
+
module Parameters
|
28
|
+
class ClassParam < Param
|
29
|
+
|
30
|
+
# Default value of the class parameter
|
31
|
+
attr_accessor :value
|
32
|
+
|
33
|
+
#
|
34
|
+
# Creates a new ClassParam object with the specified _name_,
|
35
|
+
# given _description_ and _value_.
|
36
|
+
#
|
37
|
+
def initialize(name,description='',value=nil)
|
38
|
+
super(name,description)
|
39
|
+
|
40
|
+
@value = value
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
4
|
+
# exploration tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#++
|
22
|
+
#
|
23
|
+
|
24
|
+
require 'ronin/parameters/exceptions/param_not_found'
|
25
|
+
require 'ronin/parameters/exceptions/missing_param'
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
4
|
+
# exploration tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#++
|
22
|
+
#
|
23
|
+
|
24
|
+
module Ronin
|
25
|
+
module Parameters
|
26
|
+
class MissingParam < RuntimeError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
4
|
+
# exploration tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#++
|
22
|
+
#
|
23
|
+
|
24
|
+
module Ronin
|
25
|
+
module Parameters
|
26
|
+
class ParamNotFound < RuntimeError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
4
|
+
# exploration tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#++
|
22
|
+
#
|
23
|
+
|
24
|
+
module Ronin
|
25
|
+
module Parameters
|
26
|
+
class InstanceParam < Param
|
27
|
+
|
28
|
+
# Owning object
|
29
|
+
attr_reader :object
|
30
|
+
|
31
|
+
#
|
32
|
+
# Creates a new InstanceParam object with the specified _object_ and
|
33
|
+
# _name_, and the given _description_.
|
34
|
+
#
|
35
|
+
def initialize(object,name,description='')
|
36
|
+
super(name,description)
|
37
|
+
|
38
|
+
@object = object
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# Returns the value of the instance param.
|
43
|
+
#
|
44
|
+
def value
|
45
|
+
@object.instance_variable_get("@#{@name}")
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# Sets the value of the instance param.
|
50
|
+
#
|
51
|
+
def value=(value)
|
52
|
+
@object.instance_variable_set("@#{@name}",value)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
4
|
+
# exploration tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#++
|
22
|
+
#
|
23
|
+
|
24
|
+
module Ronin
|
25
|
+
module Parameters
|
26
|
+
class Param
|
27
|
+
|
28
|
+
# Name of parameter
|
29
|
+
attr_reader :name
|
30
|
+
|
31
|
+
# Description of parameter
|
32
|
+
attr_reader :description
|
33
|
+
|
34
|
+
#
|
35
|
+
# Creates a new Param object with the specified _name_ and the given
|
36
|
+
# _description_.
|
37
|
+
#
|
38
|
+
def initialize(name,description='')
|
39
|
+
@name = name.to_sym
|
40
|
+
@description = description
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,275 @@
|
|
1
|
+
#
|
2
|
+
#--
|
3
|
+
# Ronin - A Ruby platform designed for information security and data
|
4
|
+
# exploration tasks.
|
5
|
+
#
|
6
|
+
# Copyright (c) 2006-2008 Hal Brodigan (postmodern.mod3 at gmail.com)
|
7
|
+
#
|
8
|
+
# This program is free software; you can redistribute it and/or modify
|
9
|
+
# it under the terms of the GNU General Public License as published by
|
10
|
+
# the Free Software Foundation; either version 2 of the License, or
|
11
|
+
# (at your option) any later version.
|
12
|
+
#
|
13
|
+
# This program is distributed in the hope that it will be useful,
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16
|
+
# GNU General Public License for more details.
|
17
|
+
#
|
18
|
+
# You should have received a copy of the GNU General Public License
|
19
|
+
# along with this program; if not, write to the Free Software
|
20
|
+
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
21
|
+
#++
|
22
|
+
#
|
23
|
+
|
24
|
+
require 'ronin/parameters/class_param'
|
25
|
+
require 'ronin/parameters/instance_param'
|
26
|
+
require 'ronin/parameters/exceptions'
|
27
|
+
require 'ronin/extensions/meta'
|
28
|
+
|
29
|
+
module Ronin
|
30
|
+
module Parameters
|
31
|
+
def self.included(base) # :nodoc:
|
32
|
+
base.metaclass_eval do
|
33
|
+
#
|
34
|
+
# Returns the +Hash+ of parameters for the class.
|
35
|
+
#
|
36
|
+
def params
|
37
|
+
@params ||= {}
|
38
|
+
end
|
39
|
+
|
40
|
+
#
|
41
|
+
# Adds a new parameters with the specified _name_ and the given
|
42
|
+
# _options_ to the Class.
|
43
|
+
#
|
44
|
+
# parameter 'var'
|
45
|
+
#
|
46
|
+
# parameter 'var', :value => 3, :description => 'my variable'
|
47
|
+
#
|
48
|
+
def parameter(name,options={})
|
49
|
+
name = name.to_sym
|
50
|
+
|
51
|
+
# add the parameter to the class params list
|
52
|
+
params[name] = ClassParam.new(name,options[:description],options[:value])
|
53
|
+
|
54
|
+
# define the reader class method for the parameter
|
55
|
+
meta_def(name) do
|
56
|
+
params[name].value
|
57
|
+
end
|
58
|
+
|
59
|
+
# define the writer class method for the parameter
|
60
|
+
meta_def("#{name}=") do |value|
|
61
|
+
params[name].value = value
|
62
|
+
end
|
63
|
+
|
64
|
+
# define the getter/setter instance methods for the parameter
|
65
|
+
attr_accessor(name)
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# Returns the class parameter with the specified _name_. If no
|
70
|
+
# such class parameter exists, a ParamNotFound exception will be
|
71
|
+
# raised.
|
72
|
+
#
|
73
|
+
def get_param(name)
|
74
|
+
name = name.to_sym
|
75
|
+
|
76
|
+
ancestors.each do |superclass|
|
77
|
+
if superclass.include?(Parameters)
|
78
|
+
if superclass.params.has_key?(name)
|
79
|
+
return superclass.params[name]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
raise(ParamNotFound,"parameter #{name.to_s.dump} was not found in class #{self.name.dump}",caller)
|
85
|
+
end
|
86
|
+
|
87
|
+
#
|
88
|
+
# Returns +true+ if a class parameters with the specified _name_
|
89
|
+
# exists, returns +false+ otherwise.
|
90
|
+
#
|
91
|
+
def has_param?(name)
|
92
|
+
name = name.to_sym
|
93
|
+
|
94
|
+
ancestors.each do |superclass|
|
95
|
+
if superclass.include?(Parameters)
|
96
|
+
return true if superclass.params.has_key?(name)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
return false
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# Iterates over all class parameters, passing each one to the
|
105
|
+
# specified _block_.
|
106
|
+
#
|
107
|
+
def each_param(&block)
|
108
|
+
ancestors.each do |superclass|
|
109
|
+
if superclass.include?(Parameters)
|
110
|
+
superclass.params.each_value(&block)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
return self
|
115
|
+
end
|
116
|
+
|
117
|
+
#
|
118
|
+
# Returns the description of the class parameters with the
|
119
|
+
# specified _name_. If no such class parameter exists, a
|
120
|
+
# ParamNotFound exception will be raised.
|
121
|
+
#
|
122
|
+
def describe_param(name)
|
123
|
+
get_param(name).description
|
124
|
+
end
|
125
|
+
|
126
|
+
#
|
127
|
+
# Returns the value of the class parameters with the specified
|
128
|
+
# _name_. If no such class parameter exists, a ParamNotFound
|
129
|
+
# exception will be raised.
|
130
|
+
#
|
131
|
+
def param_value(name)
|
132
|
+
get_param(name).value
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
#
|
138
|
+
# Calls initialize_parameters and then proceeds to call the
|
139
|
+
# super-classes initialize.
|
140
|
+
#
|
141
|
+
def initialize(*args,&block)
|
142
|
+
initialize_parameters()
|
143
|
+
|
144
|
+
super(*args,&block)
|
145
|
+
end
|
146
|
+
|
147
|
+
#
|
148
|
+
# Initializes all instance parameters based off the class parameter's
|
149
|
+
# descriptions and default values.
|
150
|
+
#
|
151
|
+
def initialize_parameters
|
152
|
+
# import the class parameters
|
153
|
+
self.class.each_param { |param| initialize_param(param) }
|
154
|
+
end
|
155
|
+
|
156
|
+
#
|
157
|
+
# Adds a new parameters with the specified _name_ and the given
|
158
|
+
# _options_ to the object.
|
159
|
+
#
|
160
|
+
# obj.parameter('var')
|
161
|
+
#
|
162
|
+
# obj.parameter('var',:value => 3, :description => 'my variable')
|
163
|
+
#
|
164
|
+
def parameter(name,options={})
|
165
|
+
name = name.to_sym
|
166
|
+
|
167
|
+
# set the instance variable
|
168
|
+
instance_variable_set("@#{name}",options[:value])
|
169
|
+
|
170
|
+
# add the new parameter
|
171
|
+
params[name] = InstanceParam.new(self,name,options[:description])
|
172
|
+
|
173
|
+
# define the reader method for the parameter
|
174
|
+
instance_eval %{
|
175
|
+
def #{name}
|
176
|
+
instance_variable_get("@#{name}")
|
177
|
+
end
|
178
|
+
}
|
179
|
+
|
180
|
+
# define the writer method for the parameter
|
181
|
+
instance_eval %{
|
182
|
+
def #{name}=(value)
|
183
|
+
instance_variable_set("@#{name}",value)
|
184
|
+
end
|
185
|
+
}
|
186
|
+
|
187
|
+
return params[name]
|
188
|
+
end
|
189
|
+
|
190
|
+
#
|
191
|
+
# Returns a Hash of the classes params.
|
192
|
+
#
|
193
|
+
def class_params
|
194
|
+
self.class.params
|
195
|
+
end
|
196
|
+
|
197
|
+
#
|
198
|
+
# Returns a +Hash+ of the instance parameters.
|
199
|
+
#
|
200
|
+
def params
|
201
|
+
@params ||= {}
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# Returns +true+ if the a parameter with the specified _name_ exists,
|
206
|
+
# returns +false+ otherwise.
|
207
|
+
#
|
208
|
+
# obj.has_param?('rhost') # => true
|
209
|
+
#
|
210
|
+
def has_param?(name)
|
211
|
+
params.has_key?(name.to_sym)
|
212
|
+
end
|
213
|
+
|
214
|
+
#
|
215
|
+
# Returns the parameter with the specified _name_. If no such parameter
|
216
|
+
# exists, a ParamNotFound exception will be raised.
|
217
|
+
#
|
218
|
+
# obj.get_param('var') # => InstanceParam
|
219
|
+
#
|
220
|
+
def get_param(name)
|
221
|
+
name = name.to_sym
|
222
|
+
|
223
|
+
unless has_param?(name)
|
224
|
+
raise(ParamNotFound,"parameter #{name.to_s.dump} was not found within #{self.to_s.dump}",caller)
|
225
|
+
end
|
226
|
+
|
227
|
+
return params[name]
|
228
|
+
end
|
229
|
+
|
230
|
+
#
|
231
|
+
# Returns the description of the parameter with the specified _name_.
|
232
|
+
# If no such parameter exists, a ParamNotFound exception will be raised.
|
233
|
+
#
|
234
|
+
# obj.describe_param('rhost') # => "remote host"
|
235
|
+
#
|
236
|
+
def describe_param(name)
|
237
|
+
get_param(name).description
|
238
|
+
end
|
239
|
+
|
240
|
+
#
|
241
|
+
# Returns the value of the parameter with the specified _name_. If no
|
242
|
+
# such parameter exists, a ParamNotFound exception will be raised.
|
243
|
+
#
|
244
|
+
# obj.value_param('rhost') # => 80
|
245
|
+
#
|
246
|
+
def param_value(name)
|
247
|
+
get_param(name).value
|
248
|
+
end
|
249
|
+
|
250
|
+
protected
|
251
|
+
|
252
|
+
|
253
|
+
#
|
254
|
+
# Initializes the specified class _param_.
|
255
|
+
#
|
256
|
+
def initialize_param(param)
|
257
|
+
# set the instance variable if the param has a value
|
258
|
+
if param.value
|
259
|
+
# do not override existing instance value if present
|
260
|
+
unless instance_variable_get("@#{param.name}")
|
261
|
+
begin
|
262
|
+
value = param.value.clone
|
263
|
+
rescue TypeError
|
264
|
+
value = param.value
|
265
|
+
end
|
266
|
+
|
267
|
+
instance_variable_set("@#{param.name}",value)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
params[param.name] = InstanceParam.new(self,param.name,param.description)
|
272
|
+
return params[param.name]
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|