Created
July 12, 2014 08:49
-
-
Save kmaglione/573db9cc25353b914f8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2 | |
from __future__ import print_function | |
from telnetlib import Telnet | |
import json | |
import sys | |
import os | |
import re | |
HOST = 'localhost' | |
PORT = 17428 | |
conn = Telnet(HOST, PORT) | |
conn.read_until('\nl> ') | |
code = sys.stdin.read() | |
stub = ur''' | |
(function (global, code, url, line, context) { | |
function debugEval(sandbox) { | |
Components.utils.import('resource://gre/modules/jsdebugger.jsm', {}) | |
.addDebuggerToGlobal(sandbox); | |
let d = Debugger(); | |
let res = d.addDebuggee(window) | |
.evalInGlobal(code, { url: url, lineNumber: line }); | |
d.removeDebuggee(window); | |
return res; | |
} | |
if (context) | |
context.split(/\./g).forEach(p => { | |
global = global[p]; | |
}); | |
if ({}.toString.call(global) == '[object Sandbox]') | |
return Components.utils.evalInSandbox(code, global, "1.8", url, line); | |
else { | |
let sandbox = Components.utils.Sandbox(window); | |
sandbox.window = global; | |
sandbox.code = code; | |
sandbox.url = url; | |
sandbox.line = line; | |
return Components.utils.evalInSandbox('(' + debugEval + ')(this)', | |
sandbox, "1.8", | |
'dactyl-eval.py', 20); | |
} | |
})(window, %s, %s, %s, %s); | |
''' | |
stub = stub.replace('\n', '\n\\ ')[1:-1] + '.\n' | |
conn.write( | |
(stub % tuple(map(json.dumps, | |
(code, sys.argv[1], int(sys.argv[2]), | |
sys.argv[3] if len(sys.argv) > 3 else '')))) | |
.encode('utf-8')) | |
end = re.compile('^l> ', re.M) | |
print(conn.expect([end])[2][:-3], | |
end='') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment