CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

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