Module: Undll32

Defined in:
lib/undll32.rb,
lib/undll32/version.rb

Overview

Undll32 replacement of Windows’ rundll32.exe

Defined Under Namespace

Classes: Buffer, Win32API

Constant Summary collapse

VERSION =
"0.3.3"

Class Method Summary collapse

Class Method Details

.exe(argv = ARGV) ⇒ Object



267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/undll32.rb', line 267

def self.exe(argv=ARGV)
  return help if ARGV.include? '-h' or ARGV.include? '--help'
  dllfunc, *args = argv
  return help if dllfunc.nil?
  dll, func = dllfunc.split(',')
  return help if func.nil?
  dll += '.dll' unless dll.end_with? '.dll'
  realpath = File.expand_path dll
  dll = realpath if File.exist? realpath
  args.map! do |e|
    e = e.dup
    if e.start_with?('+')
      e.slice!(0)
      next e if e.start_with?('+')
      Buffer.from(e)
    else
      n = Integer(e) rescue nil
      next n if n
      e
    end
  end
  ret = run(dll, func, *args)
  args.each { |e| pp e.unpack if Buffer === e }
  ret
end

.helpObject



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
# File 'lib/undll32.rb', line 293

def self.help
  puts <<-USAGE

  undll32 dll,func [...args]

  EXAMPLE
    undll32 user32,MessageBox 0 hello world 0
    undll32 user32,GetCursorPos +[LL]
    undll32 user32,GetCursorPos +x,y
    undll32 user32,GetCursorPos +:8 # will be converted to string

  ARGUMENTS
    0   => (Integer) 0
    str => 'str'
    +0  => '0'
    ++0 => '+0'
    +[CSLQ]    => Buffer.new([:C, :S, :L, :Q])
    +{x:L,y:L} => Buffer.new({:x => :L, :y => :L})
    +:256      => Buffer.new(256)

  VERSION
    #{VERSION}

  USAGE
end

.run(dll, func, *args) ⇒ Object

Undll32.run ‘user32’, ‘MessageBox’, 0, ‘hello’, ‘world’, 0 Undll32.run ‘user32’, ‘GetCursorPos’, Buffer.new(=> :L, :y => :L) Undll32.run ‘user32’, ‘GetCursorPos’, Buffer.from(‘x,y’)



261
262
263
264
265
# File 'lib/undll32.rb', line 261

def self.run(dll, func, *args)
  types = args.map { |e| Integer === e ? 'L' : 'p' }
  input = args.map { |e| Buffer === e ? e.buffer : e }
  Win32API.new(dll, func, types, 'i').call(*input)
end