Class: Pwnlib::Shellcraft::Shellcraft

Inherits:
Object
  • Object
show all
Includes:
Context, Logger, Singleton
Defined in:
lib/pwnlib/shellcraft/shellcraft.rb

Overview

Singleton class.

Instance Method Summary collapse

Constructor Details

#initializeShellcraft

All files under generators/ will be required.



22
23
24
25
26
# File 'lib/pwnlib/shellcraft/shellcraft.rb', line 22

def initialize
  Dir[File.join(__dir__, 'generators', '**', '*.rb')].sort.each do |f|
    require f
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, **kwargs, &block) ⇒ Object

Will search modules/methods under Generators according to current arch and os. i.e. Shellcraft::Generators::${arch}::<Common|${os}>.${method}.

With this method, context.local(arch: ‘amd64’) { shellcraft.sh } will invoke Generators::Amd64::Linux#sh.



33
34
35
36
37
38
# File 'lib/pwnlib/shellcraft/shellcraft.rb', line 33

def method_missing(method, *args, **kwargs, &block)
  mod = find_module_for(method)
  return super if mod.nil?

  mod.public_send(method, *args, **kwargs, &block)
end

Instance Method Details

#respond_to_missing?(method, include_private = false) ⇒ Boolean

For respond_to?.

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/pwnlib/shellcraft/shellcraft.rb', line 41

def respond_to_missing?(method, include_private = false)
  return true if find_module_for(method)

  super
end