|
This post originated from an RSS feed registered with Ruby Buzz
by Red Handed.
|
Original Post: Ruby for Windows in Under 1K
Feed Title: RedHanded
Feed URL: http://redhanded.hobix.com/index.xml
Feed Description: sneaking Ruby through the system
|
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Red Handed
Latest Posts From RedHanded
|
|
If you enjoyed Rubyless Ruby, here’s a remix for Windows. I’m using the Windows Scripting Host for this one, which means an appearance from good ol’ XmlHttpRequest. It’s the first new wave of 2006: Ajax for Batch Files, peoepl!
Here’s the code, I’ll show ya how to run it after the jump.
tryurl = "http://tryruby.hobix.com/irb?cmd="
// strap on xhr, nice, nice
function wget( url, hdrs ) {
var http = WScript.CreateObject( "Microsoft.XMLHTTP" );
http.open( "GET", url, false );
for ( var k in hdrs ) {
http.setRequestHeader( k, hdrs[k] );
}
http.send( "" );
return http.responseText;
}
// the prompt!
sess = wget( tryurl + escape( "!INIT!IRB!" ), {} )
WScript.Echo( "Interactive Ruby ready." )
WScript.StdOut.Write( ">> " )
WScript.StdIn.Read(0)
while ( true ) {
cmd = WScript.StdIn.ReadLine()
resp = ""; ps = ">>";
if ( cmd ) {
resp = wget( tryurl + escape( cmd ).replace( '+', '%2B' ),
{'Cookie': '_session_id=' + sess});
ps = "..";
if ( resp ) {
WScript.StdOut.Write( resp );
ps = ">>";
}
}
WScript.StdOut.Write( ps + " " );
}
You can download the script try.js by doing a right-click Save as... in IE. To run the thing from the prompt:
cscript /Nologo try.js
While the Windows Scripting Host has probably been the number one source of viruses for the platform (ILOVEYOU comes to mind), it’s actually a very natural way to shell script. Many years ago there was a brilliant desktop shell called Graphite which had WSH hooks. It’s too bad that lots of stuff is buried in obscure objects.
For the above script, I found the ss64 reference to be the most practical reference. And JS/XHR docs are wide and far, of course.
Read: Ruby for Windows in Under 1K