,
, . , Ruby , " ", eval.
script . . /usr/bin, .
$ myruby <source>
. md5 md5()
require 'digest/md5';
def executeCode(file)
handle = File.open(file,'r');
for line in handle.readlines()
line = line.strip();
begin
eval(line);
rescue Exception => e
print "Problem with script '" + file + "'\n";
print e + "\n";
end
end
end
def checkFile(file)
if !File.exists?(file)
print "No such source file '" + file + "'\n";
exit(1);
elsif !File.readable?(file)
print "Cannot read from source file '" + file + "'\n";
exit(1);
else
executeCode(file);
end
end
def md5(key=nil)
if key.nil?
raise "md5 requires 1 parameter, 0 given!\n";
else
return Digest::MD5.hexdigest(key)
end
end
if ARGV[0].nil?
print "No input file specified!\n"
exit(1);
else
checkFile(ARGV[0]);
end
myruby myruby.rb (755). ruby
puts "I will now generate a md5 digest for mypass using the md5() function"
puts md5('mypass')
Save this and run it like a regular ruby script, but with our new interpreter. You will notice that I do not need to include any libraries or write a function in the source code, because all this is defined in our interpreter.
This is probably not the most ideal method, but it is the only one I can think of.
Greetings
source
share