Skip to content

Commit 1ae320c

Browse files
authored
Hotfix api.rb (#2173)
* testing api * formatting
1 parent 43e3fa5 commit 1ae320c

1 file changed

Lines changed: 38 additions & 41 deletions

File tree

core/api.rb

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,28 @@ def initialize
2424
# Register timed API calls to an owner
2525
#
2626
# @param [Class] owner the owner of the API hook
27-
# @param [Class] cla the API class the owner would like to hook into
27+
# @param [Class] c the API class the owner would like to hook into
2828
# @param [String] method the method of the class the owner would like to execute
2929
# @param [Array] params an array of parameters that need to be matched before the owner will be called
3030
#
31-
def register(owner, cla, method, params = [])
32-
unless verify_api_path(cla, method)
33-
print_error "API Registrar: Attempted to register non-existant API method #{cla} :#{method}"
31+
def register(owner, c, method, params = [])
32+
unless verify_api_path(c, method)
33+
print_error "API Registrar: Attempted to register non-existant API method #{c} :#{method}"
3434
return
3535
end
3636

37-
if registered?(owner, cla, method, params)
38-
print_debug "API Registrar: Attempting to re-register API call #{cla} :#{method}"
37+
if registered?(owner, c, method, params)
38+
print_debug "API Registrar: Attempting to re-register API call #{c} :#{method}"
3939
return
4040
end
4141

4242
id = @count
4343
@registry << {
44-
'id': id,
45-
'owner': owner,
46-
'class': cla,
47-
'method': method,
48-
'params': params
44+
'id' => id,
45+
'owner' => owner,
46+
'class' => c,
47+
'method' => method,
48+
'params' => params
4949
}
5050
@count += 1
5151

@@ -56,19 +56,18 @@ def register(owner, cla, method, params = [])
5656
# Tests whether the owner is registered for an API hook
5757
#
5858
# @param [Class] owner the owner of the API hook
59-
# @param [Class] cla the API class
59+
# @param [Class] c the API class
6060
# @param [String] method the method of the class
6161
# @param [Array] params an array of parameters that need to be matched
6262
#
6363
# @return [Boolean] whether or not the owner is registered
6464
#
65-
def registered?(owner, cla, method, params = [])
65+
def registered?(owner, c, method, params = [])
6666
@registry.each do |r|
6767
next unless r['owner'] == owner
68-
next unless r['class'] == cla
68+
next unless r['class'] == c
6969
next unless r['method'] == method
7070
next unless is_matched_params? r, params
71-
7271
return true
7372
end
7473
false
@@ -77,18 +76,17 @@ def registered?(owner, cla, method, params = [])
7776
#
7877
# Match a timed API call to determine if an API.fire() is required
7978
#
80-
# @param [Class] cla the target API class
79+
# @param [Class] c the target API class
8180
# @param [String] method the method of the target API class
8281
# @param [Array] params an array of parameters that need to be matched
8382
#
8483
# @return [Boolean] whether or not the arguments match an entry in the API registry
8584
#
86-
def matched?(cla, method, params = [])
85+
def matched?(c, method, params = [])
8786
@registry.each do |r|
88-
next unless r['class'] == cla
87+
next unless r['class'] == c
8988
next unless r['method'] == method
9089
next unless is_matched_params? r, params
91-
9290
return true
9391
end
9492
false
@@ -105,20 +103,19 @@ def unregister(id)
105103

106104
#
107105
# Retrieves all the owners and ID's of an API hook
108-
# @param [Class] cla the target API class
106+
# @param [Class] c the target API class
109107
# @param [String] method the method of the target API class
110108
# @param [Array] params an array of parameters that need to be matched
111109
#
112110
# @return [Array] an array of hashes consisting of two keys :owner and :id
113111
#
114-
def get_owners(cla, method, params = [])
112+
def get_owners(c, method, params = [])
115113
owners = []
116114
@registry.each do |r|
117-
next unless r['class'] == cla
115+
next unless r['class'] == c
118116
next unless r['method'] == method
119117
next unless is_matched_params? r, params
120-
121-
owners << { owner: r['owner'], id: r['id'] }
118+
owners << { :owner => r['owner'], :id => r['id'] }
122119
end
123120
owners
124121
end
@@ -129,23 +126,23 @@ def get_owners(cla, method, params = [])
129126
#
130127
# @note This is a security precaution
131128
#
132-
# @param [Class] cla the target API class to verify
133-
# @param [String] met the target method to verify
129+
# @param [Class] c the target API class to verify
130+
# @param [String] m the target method to verify
134131
#
135-
def verify_api_path(cla, met)
136-
(cla.const_defined?('API_PATHS') && cla.const_get('API_PATHS').key?(met))
132+
def verify_api_path(c, m)
133+
(c.const_defined?('API_PATHS') && c.const_get('API_PATHS').key?(m))
137134
end
138135

139136
#
140137
# Retrieves the registered symbol reference for an API hook
141138
#
142-
# @param [Class] cla the target API class to verify
143-
# @param [String] met the target method to verify
139+
# @param [Class] c the target API class to verify
140+
# @param [String] m the target method to verify
144141
#
145142
# @return [Symbol] the API path
146143
#
147-
def get_api_path(cla, met)
148-
verify_api_path(cla, met) ? cla.const_get('API_PATHS')[met] : nil
144+
def get_api_path(c, m)
145+
verify_api_path(c, m) ? c.const_get('API_PATHS')[m] : nil
149146
end
150147

151148
#
@@ -174,32 +171,32 @@ def is_matched_params?(reg, params)
174171
#
175172
# Fires all owners registered to this API hook
176173
#
177-
# @param [Class] cla the target API class
178-
# @param [String] met the target API method
174+
# @param [Class] c the target API class
175+
# @param [String] m the target API method
179176
# @param [Array] *args parameters passed for the API call
180177
#
181178
# @return [Hash, NilClass] returns either a Hash of :api_id and :data
182179
# if the owners return data, otherwise NilClass
183180
#
184-
def fire(cla, met, *args)
185-
mods = get_owners(cla, met, args)
181+
def fire(c, m, *args)
182+
mods = get_owners(c, m, args)
186183
return nil unless mods.length.positive?
187184

188-
unless verify_api_path(cla, met) && cla.ancestors[0].to_s > 'BeEF::API'
189-
print_error "API Path not defined for Class: #{cla} method:#{method}"
185+
unless verify_api_path(c, m) && c.ancestors[0].to_s > 'BeEF::API'
186+
print_error "API Path not defined for Class: #{c} method:#{method}"
190187
return []
191188
end
192189

193190
data = []
194-
method = get_api_path(cla, met)
191+
method = get_api_path(c, m)
195192
mods.each do |mod|
196193
begin
197194
# Only used for API Development (very verbose)
198195
# print_info "API: #{mod} fired #{method}"
199196

200197
result = mod[:owner].method(method).call(*args)
201198
unless result.nil?
202-
data << { api_id: mod[:id], data: result }
199+
data << { :api_id => mod[:id], :data => result }
203200
end
204201
rescue => e
205202
print_error "API Fire Error: #{e.message} in #{mod}.#{method}()"
@@ -217,7 +214,7 @@ def fire(cla, met, *args)
217214
require 'core/api/extension'
218215
require 'core/api/extensions'
219216
require 'core/api/main/migration'
220-
require 'core/api/main/network_stack/assethandler'
217+
require 'core/api/main/network_stack/assethandler.rb'
221218
require 'core/api/main/server'
222219
require 'core/api/main/server/hook'
223220
require 'core/api/main/configuration'

0 commit comments

Comments
 (0)