@@ -14,6 +14,12 @@ module Util
14
14
15
15
class PayloadCachedSize
16
16
17
+ # Insert a new CachedSize value into the text of a payload module
18
+ #
19
+ # @param data [String] The source code of a payload module
20
+ # @param cached_size [String] The new value for cached_size, which
21
+ # which should be either numeric or the string :dynamic
22
+ # @return [String]
17
23
def self . update_cache_constant ( data , cached_size )
18
24
data .
19
25
gsub ( /^\s *CachedSize\s *=\s *(\d +|:dynamic).*/ , '' ) .
@@ -22,6 +28,12 @@ def self.update_cache_constant(data, cached_size)
22
28
end
23
29
end
24
30
31
+ # Insert a new CachedSize value into a payload module file
32
+ #
33
+ # @param mod [Msf::Payload] The class of the payload module to update
34
+ # @param cached_size [String] The new value for cached_size, which
35
+ # which should be either numeric or the string :dynamic
36
+ # @return [void]
25
37
def self . update_cached_size ( mod , cached_size )
26
38
mod_data = ""
27
39
@@ -34,19 +46,37 @@ def self.update_cached_size(mod, cached_size)
34
46
end
35
47
end
36
48
49
+ # Updates the payload module specified with the current CachedSize
50
+ #
51
+ # @param mod [Msf::Payload] The class of the payload module to update
52
+ # @return [void]
37
53
def self . update_module_cached_size ( mod )
38
54
update_cached_size ( mod , compute_cached_size ( mod ) )
39
55
end
40
56
57
+ # Calculates the CachedSize value for a payload module
58
+ #
59
+ # @param mod [Msf::Payload] The class of the payload module to update
60
+ # @return [Fixnum]
41
61
def self . compute_cached_size ( mod )
42
62
return :dynamic if is_dynamic? ( mod )
43
63
return mod . new . size
44
64
end
45
65
66
+ # Determines whether a payload generates a static sized output
67
+ #
68
+ # @param mod [Msf::Payload] The class of the payload module to update
69
+ # @param generation_count [Fixnum] The number of iterations to use to
70
+ # verify that the size is static.
71
+ # @return [Fixnum]
46
72
def self . is_dynamic? ( mod , generation_count = 5 )
47
73
[ *( 1 ..generation_count ) ] . map { |x | mod . new . size } . uniq . length != 1
48
74
end
49
75
76
+ # Determines whether a payload's CachedSize is up to date
77
+ #
78
+ # @param mod [Msf::Payload] The class of the payload module to update
79
+ # @return [Boolean]
50
80
def self . is_cached_size_accurate? ( mod )
51
81
return true if mod . dynamic_size?
52
82
return false if mod . cached_size . nil?
0 commit comments