@@ -56,21 +56,22 @@ def initialize(client, parent, consts_mgr)
56
56
end
57
57
58
58
def call ( functions )
59
-
60
59
request = Packet . create_request ( 'stdapi_railgun_api_multi' )
61
60
function_results = [ ]
62
61
layouts = [ ]
63
62
functions . each do |f |
64
- dll_name , funcname , args = f
63
+ dll_name , function , args = f
65
64
dll_host = @parent . get_dll ( dll_name )
66
65
67
66
if not dll_host
68
67
raise "DLL #{ dll_name } has not been loaded"
69
68
end
70
69
71
- function = dll_host . functions [ funcname ]
72
- if not function
73
- raise "DLL #{ dll_name } function #{ funcname } has not been defined"
70
+ unless function . instance_of? DLLFunction
71
+ function = dll_host . functions [ function ]
72
+ if not function
73
+ raise "DLL #{ dll_name } function #{ function } has not been defined"
74
+ end
74
75
end
75
76
76
77
raise "#{ function . params . length } arguments expected. #{ args . length } arguments provided." unless args . length == function . params . length
@@ -96,7 +97,7 @@ def call(functions)
96
97
end
97
98
98
99
# we care only about out-only buffers
99
- if param_desc [ 2 ] == " out"
100
+ if param_desc [ 2 ] == ' out'
100
101
if !args [ param_idx ] . class . kind_of? Integer
101
102
raise "error in param #{ param_desc [ 1 ] } : Out-only buffers must be described by a number indicating their size in bytes "
102
103
end
@@ -122,11 +123,11 @@ def call(functions)
122
123
end
123
124
end
124
125
125
- tmp = assemble_buffer ( "in" , function , args )
126
+ tmp = assemble_buffer ( 'in' , function , args )
126
127
in_only_layout = tmp [ 0 ]
127
128
in_only_buffer = tmp [ 1 ]
128
129
129
- tmp = assemble_buffer ( " inout" , function , args )
130
+ tmp = assemble_buffer ( ' inout' , function , args )
130
131
inout_layout = tmp [ 0 ]
131
132
inout_buffer = tmp [ 1 ]
132
133
@@ -146,41 +147,41 @@ def call(functions)
146
147
#puts " processing (#{param_desc[0]}, #{param_desc[1]}, #{param_desc[2]})"
147
148
buffer = nil
148
149
# is it a pointer to a buffer on our stack
149
- if [ " PDWORD" , " PWCHAR" , " PCHAR" , " PBLOB" ] . include? param_desc [ 0 ]
150
- #puts " pointer"
150
+ if [ ' PDWORD' , ' PWCHAR' , ' PCHAR' , ' PBLOB' ] . include? param_desc [ 0 ]
151
+ #puts ' pointer'
151
152
if args [ param_idx ] == nil # null pointer?
152
153
buffer = [ 0 ] . pack ( @native ) # type: DWORD (so the dll does not rebase it)
153
154
buffer += [ 0 ] . pack ( @native ) # value: 0
154
- elsif param_desc [ 2 ] == "in"
155
+ elsif param_desc [ 2 ] == 'in'
155
156
buffer = [ 1 ] . pack ( @native )
156
157
buffer += [ in_only_layout [ param_desc [ 1 ] ] . addr ] . pack ( @native )
157
- elsif param_desc [ 2 ] == " out"
158
+ elsif param_desc [ 2 ] == ' out'
158
159
buffer = [ 2 ] . pack ( @native )
159
160
buffer += [ out_only_layout [ param_desc [ 1 ] ] . addr ] . pack ( @native )
160
- elsif param_desc [ 2 ] == " inout"
161
+ elsif param_desc [ 2 ] == ' inout'
161
162
buffer = [ 3 ] . pack ( @native )
162
163
buffer += [ inout_layout [ param_desc [ 1 ] ] . addr ] . pack ( @native )
163
164
else
164
- raise " unexpected direction"
165
+ raise ' unexpected direction'
165
166
end
166
167
else
167
- #puts " not a pointer"
168
+ #puts ' not a pointer'
168
169
# it's not a pointer
169
170
buffer = [ 0 ] . pack ( @native )
170
171
case param_desc [ 0 ]
171
- when " LPVOID" , " HANDLE" , " SIZE_T"
172
+ when ' LPVOID' , ' HANDLE' , ' SIZE_T'
172
173
num = param_to_number ( args [ param_idx ] )
173
174
buffer += [ num ] . pack ( @native )
174
- when " DWORD"
175
+ when ' DWORD'
175
176
num = param_to_number ( args [ param_idx ] )
176
177
buffer += [ num % 4294967296 ] . pack ( @native )
177
- when " WORD"
178
+ when ' WORD'
178
179
num = param_to_number ( args [ param_idx ] )
179
180
buffer += [ num % 65536 ] . pack ( @native )
180
- when " BYTE"
181
+ when ' BYTE'
181
182
num = param_to_number ( args [ param_idx ] )
182
183
buffer += [ num % 256 ] . pack ( @native )
183
- when " BOOL"
184
+ when ' BOOL'
184
185
case args [ param_idx ]
185
186
when true
186
187
buffer += [ 1 ] . pack ( 'V' )
@@ -221,9 +222,9 @@ def call(functions)
221
222
end
222
223
223
224
functions . each do |f |
224
- dll_name , funcname , args = f
225
- dll_host = @parent . get_dll ( dll_name )
226
- function = dll_host . functions [ funcname ]
225
+ dll_name , function , args = f
226
+ dll_host = @parent . get_dll ( dll_name )
227
+ function = dll_host . functions [ function ] unless function . instance_of? DLLFunction
227
228
response = call_results . shift
228
229
inout_layout , out_only_layout = layouts . shift
229
230
@@ -239,28 +240,28 @@ def call(functions)
239
240
240
241
# The hash the function returns
241
242
return_hash = {
242
- " GetLastError" => rec_last_error ,
243
- " ErrorMessage" => rec_err_msg
243
+ ' GetLastError' => rec_last_error ,
244
+ ' ErrorMessage' => rec_err_msg
244
245
}
245
246
246
247
#process return value
247
248
case function . return_type
248
- when " LPVOID" , " HANDLE"
249
+ when ' LPVOID' , ' HANDLE'
249
250
if ( @native == 'Q<' )
250
- return_hash [ " return" ] = rec_return_value
251
+ return_hash [ ' return' ] = rec_return_value
251
252
else
252
- return_hash [ " return" ] = rec_return_value % 4294967296
253
+ return_hash [ ' return' ] = rec_return_value % 4294967296
253
254
end
254
- when " DWORD"
255
- return_hash [ " return" ] = rec_return_value % 4294967296
256
- when " WORD"
257
- return_hash [ " return" ] = rec_return_value % 65536
258
- when " BYTE"
259
- return_hash [ " return" ] = rec_return_value % 256
260
- when " BOOL"
261
- return_hash [ " return" ] = ( rec_return_value != 0 )
262
- when " VOID"
263
- return_hash [ " return" ] = nil
255
+ when ' DWORD'
256
+ return_hash [ ' return' ] = rec_return_value % 4294967296
257
+ when ' WORD'
258
+ return_hash [ ' return' ] = rec_return_value % 65536
259
+ when ' BYTE'
260
+ return_hash [ ' return' ] = rec_return_value % 256
261
+ when ' BOOL'
262
+ return_hash [ ' return' ] = ( rec_return_value != 0 )
263
+ when ' VOID'
264
+ return_hash [ ' return' ] = nil
264
265
else
265
266
raise "unexpected return type: #{ function . return_type } "
266
267
end
@@ -275,13 +276,13 @@ def call(functions)
275
276
#puts " #{param_name}"
276
277
buffer = rec_out_only_buffers [ buffer_item . addr , buffer_item . length_in_bytes ]
277
278
case buffer_item . datatype
278
- when " PDWORD"
279
+ when ' PDWORD'
279
280
return_hash [ param_name ] = buffer . unpack ( 'V' ) [ 0 ]
280
- when " PCHAR"
281
+ when ' PCHAR'
281
282
return_hash [ param_name ] = asciiz_to_str ( buffer )
282
- when " PWCHAR"
283
+ when ' PWCHAR'
283
284
return_hash [ param_name ] = uniz_to_str ( buffer )
284
- when " PBLOB"
285
+ when ' PBLOB'
285
286
return_hash [ param_name ] = buffer
286
287
else
287
288
raise "unexpected type in out-only buffer of #{ param_name } : #{ buffer_item . datatype } "
@@ -292,16 +293,16 @@ def call(functions)
292
293
# process in-out buffers
293
294
#puts "processing in-out buffers:"
294
295
inout_layout . each_pair do |param_name , buffer_item |
295
- #puts " #{param_name}"
296
+ #puts ' #{param_name}'
296
297
buffer = rec_inout_buffers [ buffer_item . addr , buffer_item . length_in_bytes ]
297
298
case buffer_item . datatype
298
- when " PDWORD"
299
+ when ' PDWORD'
299
300
return_hash [ param_name ] = buffer . unpack ( 'V' ) [ 0 ]
300
- when " PCHAR"
301
+ when ' PCHAR'
301
302
return_hash [ param_name ] = asciiz_to_str ( buffer )
302
- when " PWCHAR"
303
+ when ' PWCHAR'
303
304
return_hash [ param_name ] = uniz_to_str ( buffer )
304
- when " PBLOB"
305
+ when ' PBLOB'
305
306
return_hash [ param_name ] = buffer
306
307
else
307
308
raise "unexpected type in in-out-buffer of #{ param_name } : #{ buffer_item . datatype } "
0 commit comments