Skip to content

Instantly share code, notes, and snippets.

@pmauduit
Last active June 4, 2016 11:35
Show Gist options
  • Save pmauduit/7a2e6fe607213ab58f49dc98b12e318c to your computer and use it in GitHub Desktop.
Save pmauduit/7a2e6fe607213ab58f49dc98b12e318c to your computer and use it in GitHub Desktop.
java polyglot
@Grab(group='com.sun.script.jruby', module='jruby-engine', version='1.1.7')
import javax.script.ScriptEngineManager;
import javax.script.ScriptEngineFactory;
// See http://stackoverflow.com/questions/11838369/where-can-i-find-a-list-of-available-jsr-223-scripting-languages
// for other options :)
// I Would like to find a "ShellCode ScriptEngine" which could receive hex-encoded strings, like (helloworld):
// "\xeb\x0d\x48\x65\x6c\x6c\x6f\x20\x57\x6f\x72\x6c\x64\x0a\x00\xe8\x00\x00\x00\x00\x59\x48\x81\xe9\x6e\x05"
// "\x40\x00\x48\xc7\xc2\x0c\x00\x00\x00\x48\x81\xc1\x5c\x05\x40\x00\x48\xc7\xc3\x01\x00\x00\x00\x48\xc7\xc0"
// "\x04\x00\x00\x00\xcd\x80\xc3"
// http://www.javaworld.com/article/2071821/core-java/build-your-own-scripting-language-for-java.html
ScriptEngineManager sem = new ScriptEngineManager()
for (ScriptEngineFactory f : sem.getEngineFactories()) {
println f.getEngineName()
if (f.getEngineName().equals("Oracle Nashorn")) {
// JS
f.getScriptEngine().eval("var Helloworld = function() { print('Helloworld'); }; Helloworld();")
}
else if (f.getEngineName().equals("Groovy Scripting Engine")) {
// groovy
f.getScriptEngine().eval("println 'Helloworld'")
}
else if (f.getEngineName().equals("JRuby Engine")) {
// ruby
f.getScriptEngine().eval("puts 'Helloworld'")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment