Contextify - Loading objects from Ruby files
Hey, ever wanted to load Objects from Ruby files without having to use YAML or define a custom class named like the file? Now you can, with Contextify.
Hey, ever wanted to load Objects from Ruby files without having to use YAML or define a custom class named like the file? Now you can, with Contextify.
Comments
Why not just use Modules and include them into the object you want?
Also, I’m not sure I see how this replaces the need for YAML…
Perhaps you can provide a real world example?
I originally wrote Contextify for another project of mine, Ronin. Using Contextify I was able to define exploits and even load them from arbitrary files.
# test_exploit.rb require 'ronin/sessions/tcp'
ronin_exploit do
extend Sessions::TCP
self.name = ‘test’ self.version = ‘0.2’ self.license = License.cc_by_nc
author(:name => ‘postmodern’)
def builder @buffer = ‘some data’ end
def deployer tcp_connect_and_send(@buffer) end
end </code>
test = Ronin::Exploits::Exploit.load_context('my_exploit.rb') test.host = '0.0.0.0' test.port = 1337 test.exploit
The above example would not be possible using YAML (since YAML cannot encode methods, lambdas or Procs). Also, Contextify removes the need to define any additional Modules or Classes.
I eventually split Contextify out of Ronin in the hope that it might be useful to others.
Post a comment