forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject_aliases.rb
83 lines (67 loc) · 1.41 KB
/
object_aliases.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# -*- coding: binary -*-
module Rex
module Post
module Meterpreter
###
#
# Mixin for classes that wish to have object aliases but do not
# really need to inherit from the ObjectAliases class.
#
###
module ObjectAliasesContainer
#
# Initialize the instance's aliases.
#
def initialize_aliases(aliases = {})
self.aliases = aliases
end
#
# Pass-thru aliases.
#
def method_missing(symbol, *args)
self.aliases[symbol.to_s]
end
#
# Recursively dumps all of the aliases registered with a class that
# is kind_of? ObjectAliases.
#
def dump_alias_tree(parent_path, current = nil)
items = []
if (current == nil)
current = self
end
# If the current object may have object aliases...
if (current.kind_of?(Rex::Post::Meterpreter::ObjectAliases))
current.aliases.each_key { |x|
current_path = parent_path + '.' + x
items << current_path
items.concat(dump_alias_tree(current_path,
current.aliases[x]))
}
end
return items
end
#
# The hash of aliases.
#
attr_accessor :aliases
end
###
#
# Generic object aliases from a class instance referenced symbol to an
# associated object of an arbitrary type
#
###
class ObjectAliases
include Rex::Post::Meterpreter::ObjectAliasesContainer
##
#
# Constructor
#
##
# An instance
def initialize(aliases = {})
initialize_aliases(aliases)
end
end
end; end; end