-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUIAConsole.js
31 lines (30 loc) · 1.5 KB
/
UIAConsole.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
var UIAConsole = {
breakpoint: function () {
UIALogger.logMessage("[UIAConsole] Hit breakpoint, opening browser...");
this._openBrowser();
for (var command = this._readCommand(); command != "continue"; command = this._readCommand()) {
if (command !== null) {
eval(command);
}
}
UIALogger.logMessage("[UIAConsole] ...continuing execution");
},
_openBrowser: function () {
var envCommand = UIATarget.localTarget().host().performTaskWithPathArgumentsTimeout("/usr/bin/env", [], 10);
var pwd = envCommand.stdout.match(/^PWD=(.*)$/m)[1];
var findCommand = UIATarget.localTarget().host().performTaskWithPathArgumentsTimeout("/usr/bin/find", [ pwd, "-name", "uia-console.html" ], 10);
UIATarget.localTarget().host().performTaskWithPathArgumentsTimeout('/bin/sh', [ '-c', "open file://" + findCommand.stdout + " &" ], 10);
},
_readCommand: function () {
var okResponse = '"HTTP/1.1 200 OK\\nContent-Length: 2\\nConnection: close\\n\\nOK"';
var ncShellCommand = this._shellCommand('echo ' + okResponse + ' | nc -l 4567', 10);
if (ncShellCommand.stdout === "") {
return null;
}
var command = ncShellCommand.stdout.match(/\r\n\r\n([^$]*)$/m)[1];
return command;
},
_shellCommand: function (command, timeout) {
return UIATarget.localTarget().host().performTaskWithPathArgumentsTimeout('/bin/sh', [ '-c', command ], timeout);
}
};