1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2026-01-08 19:44:06 +00:00

declutter... Will create separate folder for test scripts

This commit is contained in:
Bryan Roe
2019-01-11 22:18:50 -08:00
parent 989a500b6e
commit 60fb611961
31 changed files with 0 additions and 4310 deletions

View File

@@ -1,205 +0,0 @@
var http = require('http');
var digest = require('http-digest').create("admin", "P@ssw0rd");
console.log("Starting AMT Test");
digest.http = require('http');
//console.log("First Test: HTTP/GET on '/'");
//var req = digest.request({ protocol: "http:", method: "GET", host: "172.16.2.249", path: "/", port: 16992 }, OnGet1);
//req.end();
//console.log('First Test: POST /wsman');
//WSManTest();
console.log('First Test: POST /wsman, [immediate]');
WSManTest_Immediate();
function OnGet1(imsg)
{
if(imsg.statusCode == 303)
{
console.log("...SUCCESS!");
console.log("Next Test: Redirect to '" + imsg.header['Location'] + "'");
req = digest.request({ protocol: "http:", method: "GET", host: "172.16.2.249", path: imsg.header['Location'], port: 16992 }, OnGet2);
req.end();
}
else
{
console.log("...FAILED!");
}
}
function OnGet2(imsg)
{
if (imsg.statusCode == 200)
{
console.log("...SUCCESS!");
console.log("...Reading body of message");
imsg.on('end', function ()
{
console.log("...Finished");
console.log("Next Test: '/index.htm'");
req = digest.request({ protocol: "http:", method: "GET", host: "172.16.2.249", path: "/index.htm", port: 16992 }, OnGet3);
req.end();
});
}
else
{
console.log("...FAILED, status code was: " + imsg.statusCode);
}
}
function OnGet3(imsg)
{
if (imsg.statusCode == 200)
{
console.log("...SUCCESS!");
console.log("Next Test: 'POST /wsman'");
WSManTest();
}
}
function WSManTest()
{
req = digest.request({ protocol: "http:", method: "POST", host: "172.16.2.249", path: "/wsman", port: 16992, headers: { Expect: '100-Continue' }, timeout: 2000 });
req.on('continue', WSManTest_Continue);
req.on('timeout', WSManTest_Timeout);
req.on('response', WSManTest_Response);
}
function WSManTest_Immediate()
{
req = digest.request({ protocol: "http:", method: "POST", host: "172.16.2.249", path: "/wsman", port: 16992 });
req.on('response', WSManTest_Response);
var xml = 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48RW52ZWxvcGUgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeG1sbnM6eHNkPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYSIgeG1sbnM6YT0iaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNC8wOC9hZGRyZXNzaW5nIiB4bWxuczp3PSJodHRwOi8vc2NoZW1hcy5kbXRmLm9yZy93YmVtL3dzbWFuLzEvd3NtYW4ueHNkIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMy8wNS9zb2FwLWVudmVsb3BlIiA+PEhlYWRlcj48YTpBY3Rpb24+aHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNC8wOS90cmFuc2Zlci9HZXQ8L2E6QWN0aW9uPjxhOlRvPi93c21hbjwvYTpUbz48dzpSZXNvdXJjZVVSST5odHRwOi8vc2NoZW1hcy5kbXRmLm9yZy93YmVtL3dzY2ltLzEvY2ltLXNjaGVtYS8yL0NJTV9Db21wdXRlclN5c3RlbVBhY2thZ2U8L3c6UmVzb3VyY2VVUkk+PGE6TWVzc2FnZUlEPjQ8L2E6TWVzc2FnZUlEPjxhOlJlcGx5VG8+PGE6QWRkcmVzcz5odHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA0LzA4L2FkZHJlc3Npbmcvcm9sZS9hbm9ueW1vdXM8L2E6QWRkcmVzcz48L2E6UmVwbHlUbz48dzpPcGVyYXRpb25UaW1lb3V0PlBUNjBTPC93Ok9wZXJhdGlvblRpbWVvdXQ+PC9IZWFkZXI+PEJvZHkgLz48L0VudmVsb3BlPg==';
var b = Buffer.from(xml, 'base64');
req.write(b);
req.end();
}
function WSManTest_Continue()
{
console.log("Got Continue!");
}
function WSManTest_Timeout()
{
console.log("Timeout waiting for 100 Continue... Sending body anyways...");
var xml = 'PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz48RW52ZWxvcGUgeG1sbnM6eHNpPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYS1pbnN0YW5jZSIgeG1sbnM6eHNkPSJodHRwOi8vd3d3LnczLm9yZy8yMDAxL1hNTFNjaGVtYSIgeG1sbnM6YT0iaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNC8wOC9hZGRyZXNzaW5nIiB4bWxuczp3PSJodHRwOi8vc2NoZW1hcy5kbXRmLm9yZy93YmVtL3dzbWFuLzEvd3NtYW4ueHNkIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMy8wNS9zb2FwLWVudmVsb3BlIiA+PEhlYWRlcj48YTpBY3Rpb24+aHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNC8wOS90cmFuc2Zlci9HZXQ8L2E6QWN0aW9uPjxhOlRvPi93c21hbjwvYTpUbz48dzpSZXNvdXJjZVVSST5odHRwOi8vc2NoZW1hcy5kbXRmLm9yZy93YmVtL3dzY2ltLzEvY2ltLXNjaGVtYS8yL0NJTV9Db21wdXRlclN5c3RlbVBhY2thZ2U8L3c6UmVzb3VyY2VVUkk+PGE6TWVzc2FnZUlEPjQ8L2E6TWVzc2FnZUlEPjxhOlJlcGx5VG8+PGE6QWRkcmVzcz5odHRwOi8vc2NoZW1hcy54bWxzb2FwLm9yZy93cy8yMDA0LzA4L2FkZHJlc3Npbmcvcm9sZS9hbm9ueW1vdXM8L2E6QWRkcmVzcz48L2E6UmVwbHlUbz48dzpPcGVyYXRpb25UaW1lb3V0PlBUNjBTPC93Ok9wZXJhdGlvblRpbWVvdXQ+PC9IZWFkZXI+PEJvZHkgLz48L0VudmVsb3BlPg==';
var b = Buffer.from(xml, 'base64');
this.write(b);
this.end();
}
function WSManTest_Response(imsg)
{
imsg.on('data', function (chunk) { console.log(chunk); });
}
//var req = digest.request({ protocol: "ws:", method: "GET", host: "127.0.0.1", path: "/", port: 9093 }, function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); });
//var req = http.request({ protocol: "http:", method: "POST", host: "127.0.0.1", path: "/", port: 9093, headers: { Expect: '100-Continue' } }, function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); });
//var req = digest.request({ protocol: "http:", method: "POST", host: "127.0.0.1", path: "/", port: 9093, headers: { Expect: '100-Continue' } }, function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); });
//req.on('upgrade', function (res, sk, h) { console.log("Upgraded to WebSocket!"); });
//req.on('error', function () { console.log("Error occured"); });
//req.on('continue', function () { console.log("Received Continue"); this.write("test"); this.end(); });
//function OnCheckContinue(imsg, resp)
//{
// console.log("Recevied: Expect-100 Continue");
// if (imsg.Digest_IsAuthenticated('www.meshcentral.com') == 1)
// {
// var uname = imsg.Digest_GetUsername();
// console.log("Digest Username was: " + uname);
// if (uname == 'bryan' && imsg.Digest_ValidatePassword('roe') == 1)
// {
// console.log("Validated");
// imsg.on('data', function (chunk) { console.log('Received: ' + chunk.toString()); });
// imsg.on('end', function () { console.log('Received Complete'); });
// resp.writeContinue();
// }
// else
// {
// console.log("Bad Username/Password");
// resp.statusCode = "500";
// resp.statusMessage = "Error";
// resp.end();
// }
// }
// else
// {
// console.log("Sending Unauthorized");
// imsg.Digest_SendUnauthorized('www.meshcentral.com', 'oops');
// }
//}
//function OnCheckContinue_NoDigest(imsg, resp)
//{
// console.log("Recevied: Expect-100 Continue");
// imsg.on('data', function (chunk) { console.log('Received: ' + chunk.toString()); });
// imsg.on('end', function () { console.log('Received Complete'); });
// resp.writeContinue();
//}
//function OnServerUpgrade(imsg, sck, head)
//{
// if(imsg.Digest_IsAuthenticated('www.meshcentral.com')==1)
// {
// var uname = imsg.Digest_GetUsername();
// console.log("Digest Username was: " + uname);
// if(uname == 'bryan' && imsg.Digest_ValidatePassword('roe')==1)
// {
// console.log("Upgrading to WebSocket");
// sck.upgradeWebSocket();
// }
// else
// {
// console.log("Bad Username/Password");
// sck.end();
// }
// }
// else
// {
// console.log("Sending Unauthorized");
// imsg.Digest_SendUnauthorized('www.meshcentral.com', 'oops');
// }
//}
//function onVerifyServer(clientName, certs) {
// console.log("Server Name = " + clientName + "\n");
// for (var i = 0; i < certs.length; ++i) {
// console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
// }
// //throw ("Not Valid");
//}
//function onVerifyClient(clientName, certs)
//{
// console.log("Client Name = " + clientName + "\n");
// for (var i = 0; i < certs.length; ++i) {
// console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
// }
// //throw ("Not Valid");
//}
//function onVerify(serverName, certs)
//{
// console.log("ServerName = " + serverName + "\n");
// for (var i = 0; i < certs.length;++i)
// {
// console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
// }
// //throw ("Not Valid");
//}
//function OnRequest(req, res)
//{
// console.log("Received Request for: " + req.url);
//}

View File

@@ -1,5 +0,0 @@
var parent = require('ScriptContainer');
var Wireless = require('Wireless');
Wireless.on('Scan', function (ap) { parent.send(ap.toString()); });
Wireless.Scan();

View File

@@ -1,27 +0,0 @@
var child = require('child_process');
var childProcess = null;
if (process.platform == 'win32')
{
childProcess = child.execFile(process.env['windir'] + '\\system32\\cmd.exe', ['/c', 'dir'], OnChild);
}
else if (process.platform == 'linux')
{
childProcess = child.execFile('/bin/sh', ['sh', '-c', 'ls'], OnChild);
}
if (childProcess != null)
{
console.log('PID = ' + childProcess.pid);
childProcess.stdout.on('data', function (chunk) { console.log(chunk.toString()); });
childProcess.on('exit', function (code, sig) { console.log("Process Exited with code: " + code.toString()); });
}
//for (var envkey in process.env)
//{
// console.log("Environment Variable: [" + envkey + "] = " + process.env[envkey]);
//}
function OnChild(err, stdErr, stdOut)
{
}

View File

@@ -1,150 +0,0 @@
var http = require('http');
var server = "";
var req = "";
var gtunnel = "";
var digest = require('http-digest').create("bryan", "roe");
console.log("Starting Digest Test (Agent Connected)");
//server = http.createServer({ "MeshAgent": agent, "requestCert": true, "checkClientIdentity": onVerifyClient }, OnRequest);
server = http.createServer(OnRequest);
server.listen(9093);
server.on('upgrade', OnServerUpgrade);
function OnServerUpgrade(imsg, sck, head)
{
if(imsg.Digest_IsAuthenticated('www.meshcentral.com')==1)
{
var uname = imsg.Digest_GetUsername();
console.log("Digest Username was: " + uname);
if(uname == 'bryan' && imsg.Digest_ValidatePassword('roe')==1)
{
sck.upgradeWebSocket();
}
else
{
console.log("Bad Username/Password");
sck.end();
}
}
else
{
console.log("Sending Unauthorized");
imsg.Digest_SendUnauthorized('www.meshcentral.com', 'oops');
}
}
//gtunnel = require('global-tunnel');
//gtunnel.initialize({ host: "proxy.jf.intel.com", port: 911 });
//req = http.get({ uri: "http://www.google.com/", proxy: { host: "proxy.jf.intel.com", port: 911 } }, OnGoogle);
//req = http.request({ protocol: "wss:", hostname: "alt.meshcentral.com", port: 443, method: "GET", path: "/agent.ashx", MeshAgent: agent /* proxy: { host: "proxy.jf.intel.com", port: 911 }*/}, OnResponse);
//req.upgrade = OnWebSocket;
//req.on('error', function (msg) { console.log(msg); });
//req.end();
//digest.clientRequest = http.get("http://127.0.0.1:9093/");
//digest.on('response', function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!");})
digest.http = require('http');
//digest.get("http://127.0.0.1:9093/", function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); });
//digest.request({ protocol: "http:", method: "GET", host: "127.0.0.1", path: "/", port: 9093 }, function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); }).end();
var req = digest.request({ protocol: "ws:", method: "GET", host: "127.0.0.1", path: "/", port: 9093 }, function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); });
req.on('upgrade', function (res, sk, h) { console.log("Upgraded to WebSocket!"); });
req.on('error', function () { console.log("Error occured"); });
req.end();
function OnAlt(imsg)
{
console.log("OnAlt, StatusCode = " + imsg.statusCode);
}
function OnGoogle(imsg)
{
console.log("Response Code = " + imsg.statusCode);
}
function OnWebSocket(msg, s, head)
{
console.log("WebSocket connected\n");
console.log(JSON.stringify(msg) + "\n");
console.log(JSON.stringify(s) + "\n");
s.end();
}
function OnResponse(msg)
{
if (msg == null)
{
console.log("Receive Error\n");
return;
}
console.log("Status Code = " + msg.statusCode.toString() + "\n");
}
function onVerifyServer(clientName, certs) {
console.log("Server Name = " + clientName + "\n");
for (var i = 0; i < certs.length; ++i) {
console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function onVerifyClient(clientName, certs)
{
console.log("Client Name = " + clientName + "\n");
for (var i = 0; i < certs.length; ++i) {
console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function onVerify(serverName, certs)
{
console.log("ServerName = " + serverName + "\n");
for (var i = 0; i < certs.length;++i)
{
console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function OnRequest(req, res)
{
console.log("Received Request for: " + req.url);
if (req.NativeSession.Digest_IsAuthenticated("meshcentral.com") == 0)
{
req.NativeSession.Digest_SendUnauthorized("meshcentral.com", "<html>Oops</html>");
}
else
{
var username = req.NativeSession.Digest_GetUsername();
console.log("Username = " + username + "\n");
if(username == "bryan" && req.NativeSession.Digest_ValidatePassword("roe")==1)
{
console.log("Validated!\n");
if (req.NativeSession.WebSocket_GetDataType() == 0xFF)
{
req.NativeSession.WebSocket_Upgrade();
}
else
{
res.statusCode = 200;
res.statusMessage = "OK";
res.write("<HTML>SUCCESS!</HTML>");
res.end();
}
}
else
{
console.log("Nope!\n");
res.end();
}
}
}

View File

@@ -1,115 +0,0 @@
var http = require('http');
var https = require('https');
var agent = require('MeshAgent');
var server = "";
var req = "";
var db = require('SimpleDataStore').Shared();
var signer = require('SHA256Stream_Signer');
var keys = db.Keys;
Microstack_print("Enumerating Keys...\n");
for (var i = 0; i < keys.length; ++i)
{
Microstack_print("DB Key=> " + keys[i] + "\n");
}
Microstack_print("Done...\n");
Microstack_print("[TestKey] = " + db.Get("TestKey") + "\n");
//db.Put("TestKey", "TestValue");
agent.Ready = function()
{
signer.Create(agent);
signer.OnSignature = OnSignature;
server = http.createServer({ "MeshAgent": agent, "requestCert": true, "checkClientIdentity": onVerifyClient }, OnRequest);
server.listen(9093);
//req = https.get("https://127.0.0.1:443/", OnResponse);
//req = https.request({ "hostname": "127.0.0.1", "method": "GET", "path": "/", "checkServerIdentity": onVerify }, OnResponse)
//req = https.request({ "hostname": "127.0.0.1", "port": 9093, "method": "GET", "path": "/", "MeshAgent": agent }, OnResponse);
req = https.request(https.addWebSocketHeadersToOptions({ "hostname": "127.0.0.1", "port": 443, "method": "GET", "path": "/", "MeshAgent": agent }, 4096, null), OnResponse);
req.upgrade = OnWebSocket;
//req.end();
}
function OnSignature(sig)
{
//var test = Buffer.from(sig.toString('base64'), 'base64');
var test = Buffer.from(sig.toString('hex'), 'hex');
Microstack_print("sig Length: " + sig.length.toString() + " test.length = " + test.length.toString() + "\n");
Microstack_print("Signature (base64) = " + sig.toString('base64') + "\n");
Microstack_print("Signature (hex) = " + sig.toString('hex') + "\n");
}
function OnWebSocket(msg, s, head)
{
//Microstack_print("WebSocket connected\n");
//Microstack_print(JSON.stringify(msg) + "\n");
//Microstack_print(JSON.stringify(s) + "\n");
s.end();
}
function OnResponse(msg)
{
if (msg == null)
{
Microstack_print("Receive Error\n");
return;
}
Microstack_print("Status Code = " + msg.statusCode.toString() + "\n");
msg.pipe(signer);
}
function onVerifyClient(clientName, certs)
{
Microstack_print("Client Name = " + clientName + "\n");
for (var i = 0; i < certs.length; ++i) {
Microstack_print(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function onVerify(serverName, certs)
{
Microstack_print("ServerName = " + serverName + "\n");
for (var i = 0; i < certs.length;++i)
{
Microstack_print(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function OnRequest(req, res)
{
if (req.NativeSession.Digest_IsAuthenticated("meshcentral.com") == 0)
{
req.NativeSession.Digest_SendUnauthorized("meshcentral.com", "<html>Oops</html>");
}
else
{
var username = req.NativeSession.Digest_GetUsername();
Microstack_print("Username = " + username + "\n");
if(username == "bryan" && req.NativeSession.Digest_ValidatePassword("roe")==1)
{
Microstack_print("Validated!\n");
res.statusCode = 200;
res.statusMessage = "OK";
res.write("<HTML>SUCCESS!</HTML>");
res.end();
}
else
{
Microstack_print("Nope!\n");
res.end();
}
}
}

View File

@@ -1,84 +0,0 @@
//var mesh = require('MeshAgent');
//var tmpBuffer = new Buffer(26);
//mesh.AddCommandHandler_Binary(OnBinaryCommand);
//htons(tmpBuffer, 0, 0x01);
//WriteContextGuid(tmpBuffer, 2, "THISISTHECONTEXT");
//htonl(tmpBuffer, 18, 0x40000000);
//htonl(tmpBuffer, 22, 0x00);
//mesh.InjectCommand(tmpBuffer);
//tmpBuffer = new Buffer(25);
//htons(tmpBuffer, 0, 0x10);
//WriteContextGuid(tmpBuffer, 2, "THISISTHECONTEXT");
//WriteString(tmpBuffer, 18, "bar();")
//mesh.InjectCommand(tmpBuffer);
//function WriteString(buffer, offset, val)
//{
// var i;
// for (i = 0; i < val.length; ++i)
// {
// buffer[offset + i] = val.charCodeAt(i);
// }
// buffer[offset + i] = 0;
//}
//function WriteContextGuid(buffer, offset, contextguid)
//{
// var i;
// for(i=0;i<16;++i)
// {
// if (i >= contextguid.length) {
// buffer[offset + i] = 0;
// }
// else
// {
// buffer[offset + i] = contextguid.charCodeAt(i);
// }
// }
//}
//function OnBinaryCommand(cmd)
//{
// var code = ntohs(cmd, 0);
// if (code == 0x01)
// {
// var context = cmd.slice(2, 16).toString('utf-8');
// var flags = ntohl(cmd, 18);
// var etime = ntohl(cmd, 22);
// if (code != 0xFF)
// {
// Microstack_print("Cmd: " + code.toString() + " Context: " + context + " Flags: " + flags.toString() + " ExecTimeout: " + etime.toString() + "\n");
// }
// }
// return(0);
//}
var mesh = require('MeshAgent');
var container = mesh.CreateScriptContainer(0, ContainerPermissions.DEFAULT);
function OnExit(statusCode)
{
Microstack_print("OnExit: " + statusCode.toString() + "\n");
}
function OnError(msg)
{
Microstack_print("OnError: " + msg + "\n");
}
container.Exit = OnExit;
container.Error = OnError;
//container.ExecuteString("foo();");
container.ExecuteString("var agent = require('MeshAgent').db.Get(\"bryan\");", function (status, msg)
{
Microstack_print("Completed First Execution\n");
container.ExecuteString("foo();");
});
//container.ExecuteString("require('MeshAgent').db.Get(\"bryan\");");
//container.ExecuteString("var x = 2+2;");

View File

@@ -1,15 +0,0 @@
var WiFiScanner = require('WiFiScanner');
var scanner = new WiFiScanner();
scanner.on('accessPoint', function (ap) { console.log("[" + ap.bssid + "] (" + ap.lq + ") " + ap.ssid); });
if (scanner.hasWireless())
{
console.log("This Computer has wireless");
scanner.Scan();
}
else
{
console.log("This Computer DOES NOT have wireless");
}

View File

@@ -1,19 +0,0 @@
var nm = require('NetworkMonitor');
nm.on('change', function () { console.log("Change detected..."); });
nm.on('add', function (addr) { console.log("Address (" + addr + ") added"); });
nm.on('remove', function (addr) { console.log("Address (" + addr + ") removed"); });
console.log("Started Test");
function OnChange()
{
var interfaces = require('os').networkInterfaces();
for(var key in interfaces)
{
for (var i in interfaces[key])
{
console.log("Address ==> " + interfaces[key][i].address);
console.log(" status ==> " + interfaces[key][i].status);
}
}
}

View File

@@ -1,122 +0,0 @@
// JavaScript source code
var fs = require('fs');
//var buffer = fs.readFileSync('test.bin');
//var tls = require('tls');
//var pem = tls.loadpkcs7b(buffer);
//console.log(pem.toString());
var fd = fs.openSync(process.execPath.replace('MeshConsole', 'MC2'), 'rb+');
var bytesRead;
var dosHeader = new Buffer(64);
var ntHeader = new Buffer(24);
var optHeader;
console.log(process.execPath.replace('MeshConsole', 'MC2'));
bytesRead = fs.readSync(fd, dosHeader, 0, 64, 0);
if (dosHeader.readUInt16LE(0).toString(16).toUpperCase() != '5A4D')
{
console.log('unrecognized binary format');
}
bytesRead = fs.readSync(fd, ntHeader, 0, ntHeader.length, dosHeader.readUInt32LE(60));
if (ntHeader.slice(0, 4).toString('hex') != '50450000')
{
console.log('not PE format');
}
switch (ntHeader.readUInt16LE(4).toString(16))
{
case '14c':
console.log('x86 binary');
break;
case '8664':
console.log('x64 binary');
break;
default:
console.log('unknown binary type');
break;
}
console.log('Optional Size = ' + ntHeader.readUInt16LE(20) + 'bytes');
optHeader = new Buffer(ntHeader.readUInt16LE(20));
bytesRead = fs.readSync(fd, optHeader, 0, optHeader.length, dosHeader.readUInt32LE(60) + 24);
var numRVA = undefined;
var CertificateTableAddress = undefined;
var CertificateTableSize = undefined;
switch (optHeader.readUInt16LE(0).toString(16).toUpperCase())
{
case '10B':
console.log('Found IMAGE_NT_OPTIONAL_HDR32_MAGIC');
numRVA = optHeader.readUInt32LE(92);
CertificateTableAddress = optHeader.readUInt32LE(128);
CertificateTableSize = optHeader.readUInt32LE(132);
break;
case '20B':
console.log('Found IMAGE_NT_OPTIONAL_HDR64_MAGIC');
numRVA = optHeader.readUInt32LE(108);
CertificateTableAddress = optHeader.readUInt32LE(144);
CertificateTableSize = optHeader.readUInt32LE(148);
break;
default:
console.log('Unknown Value found for Optional Magic: ' + ntHeader.readUInt16LE(24).toString(16).toUpperCase());
break;
}
console.log('Number of RVA Entries: ' + numRVA.toString());
console.log('Certificate Table Address: ' + CertificateTableAddress.toString(16).toUpperCase());
console.log('Certificate Table Size: ' + CertificateTableSize.toString());
var hdr = new Buffer(8);
fs.readSync(fd, hdr, 0, hdr.length, CertificateTableAddress);
console.log('dwLength = ' + hdr.readUInt32LE(0).toString());
console.log('Updating Table Entries: ');
optHeader.writeUInt32LE(6848, 132);
hdr.writeUInt32LE(6848, 0);
console.log('written', fs.writeSync(fd, optHeader, 0, optHeader.length, dosHeader.readUInt32LE(60) + 24));
console.log('written', fs.writeSync(fd, hdr, 0, hdr.length, CertificateTableAddress));
console.log('Done!');
fs.closeSync(fd);
//switch (hdr.readUInt16LE(6).toString(16).toUpperCase())
//{
// case '1':
// console.log('Cert Type = X509');
// break;
// case '2':
// console.log('Cert Type = PKCS#7')
// break;
// case '3':
// console.log('Cert Type = RESERVED')
// break;
// case '4':
// console.log('Cert Type = TERMINAL_SERVER')
// break;
//}
//var cert = new Buffer(hdr.readUInt32LE(0) - 8);
//fs.readSync(fd, cert, 0, cert.length, CertificateTableAddress + hdr.length);
//console.log('Cert Length: ' + cert.length);
//console.log(cert.toString());
//console.log(1);
//var ws = fs.createWriteStream("test.txt", { flags: "wb" });
//ws.write(cert);
//console.log(2);
//ws.end();
//console.log(3);

View File

@@ -1,50 +0,0 @@
// JavaScript source code
console.log('Running Post Build Step....');
var fs = require('fs');
var hash = require('SHA384Stream').create();
var stream1;
var stream2;
var pending;
hash.on('hashString', function (h)
{
if (process.platform == 'win32') {
pending = 2;
var newFileName = process.execPath.substring(0, process.execPath.length - 4) + "_" + h.substring(0, 16) + ".exe";
var pdbFileName = process.execPath.substring(0, process.execPath.length - 4) + '.pdb';
var newPdbFileName = process.execPath.substring(0, process.execPath.length - 4) + "_" + h.substring(0, 16) + ".pdb";
console.log(process.execPath + ' => ' + newFileName);
console.log(pdbFileName + ' => ' + newPdbFileName);
stream1 = fs.createReadStream(process.execPath, { flags: "rb" });
stream1.output = fs.createWriteStream(newFileName, { flags: "wb+" });
stream1.output.on('finish', OnFinish);
stream1.pipe(stream1.output);
stream2 = fs.createReadStream(pdbFileName, { flags: "rb" });
stream2.output = fs.createWriteStream(newPdbFileName, { flags: "wb+" });
stream2.output.on('finish', OnFinish);
stream2.pipe(stream2.output);
}
else
{
console.log(process.platform + ' is not supported');
process.exit();
}
});
function OnFinish()
{
if (--pending == 0)
{
console.log('Finished!');
process.exit();
}
}
var exeStream = fs.createReadStream(process.execPath, { flags: "rb" });
exeStream.pipe(hash);

View File

@@ -1,125 +0,0 @@
var http = require('http');
var server = "";
var req = "";
var gtunnel = "";
var digest = require('http-digest').create("bryan", "roe");
console.log("Process.execPath = " + process.execPath);
console.log("Starting POST Digest Test");
server = http.createServer(OnRequest);
server.listen(9093);
console.log("Server Address", server._address());
server.on('upgrade', OnServerUpgrade);
server.on('checkContinue', OnCheckContinue);
//server.on('checkContinue', OnCheckContinue_NoDigest);
digest.http = require('http');
//var req = digest.request({ protocol: "ws:", method: "GET", host: "127.0.0.1", path: "/", port: 9093 }, function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); });
//var req = http.request({ protocol: "http:", method: "POST", host: "127.0.0.1", path: "/", port: 9093, headers: { Expect: '100-Continue' } }, function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); });
var req = digest.request({ protocol: "http:", method: "POST", host: "127.0.0.1", path: "/", port: 9093, headers: { Expect: '100-Continue' } }, function (imsg) { console.log(imsg.statusCode == 200 ? "SUCCESS!" : "FAIL!"); });
req.on('upgrade', function (res, sk, h) { console.log("Upgraded to WebSocket!"); });
req.on('error', function () { console.log("Error occured"); });
req.on('continue', function () { console.log("Received Continue"); this.write("test"); this.end(); });
function OnCheckContinue(imsg, resp)
{
console.log("Recevied: Expect-100 Continue");
if (imsg.Digest_IsAuthenticated('www.meshcentral.com') == 1)
{
var uname = imsg.Digest_GetUsername();
console.log("Digest Username was: " + uname);
if (uname == 'bryan' && imsg.Digest_ValidatePassword('roe') == 1)
{
console.log("Validated");
imsg.on('data', function (chunk) { console.log('Received: ' + chunk.toString()); });
imsg.on('end', function () { console.log('Received Complete'); });
resp.writeContinue();
}
else
{
console.log("Bad Username/Password");
resp.statusCode = "500";
resp.statusMessage = "Error";
resp.end();
}
}
else
{
console.log("Sending Unauthorized");
imsg.Digest_SendUnauthorized('www.meshcentral.com', 'oops');
}
}
function OnCheckContinue_NoDigest(imsg, resp)
{
console.log("Recevied: Expect-100 Continue");
imsg.on('data', function (chunk) { console.log('Received: ' + chunk.toString()); });
imsg.on('end', function () { console.log('Received Complete'); });
resp.writeContinue();
}
function OnServerUpgrade(imsg, sck, head)
{
if(imsg.Digest_IsAuthenticated('www.meshcentral.com')==1)
{
var uname = imsg.Digest_GetUsername();
console.log("Digest Username was: " + uname);
if(uname == 'bryan' && imsg.Digest_ValidatePassword('roe')==1)
{
console.log("Upgrading to WebSocket");
sck.upgradeWebSocket();
}
else
{
console.log("Bad Username/Password");
sck.end();
}
}
else
{
console.log("Sending Unauthorized");
imsg.Digest_SendUnauthorized('www.meshcentral.com', 'oops');
}
}
function onVerifyServer(clientName, certs) {
console.log("Server Name = " + clientName + "\n");
for (var i = 0; i < certs.length; ++i) {
console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function onVerifyClient(clientName, certs)
{
console.log("Client Name = " + clientName + "\n");
for (var i = 0; i < certs.length; ++i) {
console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function onVerify(serverName, certs)
{
console.log("ServerName = " + serverName + "\n");
for (var i = 0; i < certs.length;++i)
{
console.log(" Fingerprint = " + certs[i].fingerprint + "\n");
}
//throw ("Not Valid");
}
function OnRequest(req, res)
{
console.log("Received Request for: " + req.url);
}

View File

@@ -1,111 +0,0 @@
<html>
<head>
<title>WebRTC Test Application</title>
</head>
<body onload="start()">
<span id="statustext"></span>
<script type="text/javascript">
var configuration = { "iceServers": [] };
var connection = null;
var datachannel = null;
var currentanswer = null;
var wsocket = null;
var decoder = new TextDecoder('utf-8');
var sdp = null;
function start()
{
debug("Connecting relay, for signaling channel...");
wsocket = new WebSocket("wss://alt.meshcentral.com:443/meshrelay.ashx?id='test123'");
wsocket.binaryType = "arraybuffer";
wsocket.onopen = function (evt) { debug("Web Socket Connection established..."); }
wsocket.onmessage = function (evt)
{
if (evt.data[0] == 'c')
{
debug("Tunnel Established...");
}
else
{
var cmd = JSON.parse(decoder.decode(new Uint8Array(evt.data)));
if(cmd.cmd == 'offer')
{
debug("Received WebRTC Offer...");
startWebRTC();
var ax = null;
if (typeof mozRTCSessionDescription !== 'undefined') { ax = new mozRTCSessionDescription({ type: "offer", sdp: cmd.data }) } else { ax = new RTCSessionDescription({ type: "offer", sdp: cmd.data }) }
connection.setRemoteDescription(ax, onSetRemoteDescriptionDone, onError);
}
}
}
}
function onSetRemoteDescriptionDone()
{
connection.createAnswer(onAnswerDone, onError);
}
function onAnswerDone(answer)
{
//wsocket.send(JSON.stringify({ cmd: 'offer', data: answer.sdp }));
sdp = answer.sdp;
connection.setLocalDescription(answer, onSetLocalDescriptionDone, onError);
}
function startWebRTC()
{
if (connection != null) { debug("Error!"); return; }
if (typeof mozRTCPeerConnection !== 'undefined') { connection = new mozRTCPeerConnection(configuration); }
else if (typeof RTCPeerConnection !== 'undefined') { connection = new RTCPeerConnection(configuration); }
else if (typeof webkitRTCPeerConnection !== 'undefined') { connection = new webkitRTCPeerConnection(configuration); }
else return false;
connection.ondatachannel = onDataChannel
connection.onicecandidate = onIceCandidate;
}
function onDataChannel(event)
{
debug("Data Channel ("+ event.channel.label + ") connected");
datachannel = event.channel;
datachannel.binaryType = "arraybuffer";
datachannel.onmessage = function (msg)
{
try
{
datachannel.send(msg.data.byteLength.toString());
}
catch(e)
{
debug(e.toString());
debug(msg.data.toString());
}
};
}
function onIceCandidate(e)
{
if (e.candidate == null) {
if (sdp == null) { debug('error'); return; }
wsocket.send(JSON.stringify({ cmd: 'offer', data: sdp }));
}
else
{
sdp += ("a=" + e.candidate.candidate + "\r\n");
}
}
function onSetLocalDescriptionDone() { }
function onError(e) { if (e.message) debug(e.message); else debug(e); }
function debug(msg) { document.getElementById("statustext").innerHTML += (msg + "\r\n"); }
</script>
</body>
</html>

View File

@@ -1,183 +0,0 @@
var mesh;
var http = require('http');
var relayId = null;
var req;
var proxy;
var relayHost = null;
var relayPort;
var rtc = require('ILibWebRTC');
var peerConnection;
var signalingChannel;
var dc;
var webServer = null;
var processMgr;
var p;
for (var i = 1; i < process.argv.length; ++i)
{
if(process.argv[i] == 'relayId')
{
relayId = process.argv[i + 1];
++i;
}
else if (process.argv[i] == 'proxy')
{
console.log("Using Proxy: " + process.argv[i + 1] + ":" + parseInt(process.argv[i + 2]));
proxy = require('global-tunnel');
try
{
proxy.initialize({ host: process.argv[i + 1], port: parseInt(process.argv[i + 2]) });
}
catch (e)
{
console.log("Unable to bind proxy: " + e);
}
i += 2;
}
else if(process.argv[i] == 'relay')
{
relayHost = process.argv[i + 1];
relayPort = parseInt(argv[i + 2]);
i += 2;
}
else if(process.argv[i] == 'browser')
{
console.log("Local Web Server started on port 8585...");
webServer = http.createServer(OnLocalWebRequest);
webServer.listen(8585);
}
}
try
{
mesh = require('MeshAgent');
mesh.AddConnectHandler(OnMeshConnected)
}
catch(e)
{
mesh = null;
}
if (mesh == null && webServer == null)
{
console.log("Running as Standalone Mode");
var options = { host: relayHost, port: relayPort, path: "/meshrelay.ashx?id='" + relayId + "'", protocol: "wss:" };
req = http.request(options);
req.upgrade = OnTunnelWebSocket;
}
if (mesh == null && webServer != null)
{
processMgr = require('ILibProcessPipe');
p = processMgr.CreateProcess("c:\\windows\\system32\\cmd.exe", "/c", "start", "http://localhost:8585/start.html");
}
function OnLocalWebRequest(request, response)
{
if(request.method == 'GET' && request.url == '/start.html')
{
var fs = require('fs');
try
{
var stream = fs.createReadStream('WebRTC_Test.html');
response.statusCode = 200;
response.statusMessage = "OK";
stream.pipe(response);
}
catch(e)
{
response.statusCode = 404;
response.statusMessage = "Not Found";
response.end();
}
}
else
{
response.statusCode = 404;
response.statusMessage = "Not Found";
response.end();
}
}
function OnMeshConnected()
{
console.log("Mesh Agent Connected: " + mesh.ConnectedServer);
console.log("Attempting to create WebRTC Control Channel using TunnelID: " + relayId);
var options = http.parseUri(mesh.ConnectedServer);
options.path = "/meshrelay.ashx?id='" + relayId + "'";
req = http.request(options);
req.upgrade = OnTunnelWebSocket;
}
function OnTunnelWebSocket(response, sckt, head)
{
console.log("Websocket Connection to RelayServer established");
signalingChannel = sckt;
sckt.on('data', OnTunnelData);
sckt.on('end', function () { console.log("Relay connection closed"); });
}
function OnWebRTC_Connected()
{
console.log("WebRTC Session Established");
if(mesh != null)
{
// Let create a data channel
this.dc = this.createDataChannel("remoteDesktop", OnKVMChannel)
this.tempTimeout = setTimeout(function (dc) { console.log("sending: 'test'"); dc.write("test"); }, 10000, this.dc);
}
}
function OnKVMChannel()
{
console.log("Successfully established Data Channel to test Data throughput");
dc = this;
dc.kvm = mesh.getRemoteDesktopStream();
dc.on('data', function (buffer) { console.log("Peer Received: " + buffer.toString() + " bytes"); });
dc.on('end', function () { this.kvm.end(); console.log("Closing KVM Session"); });
dc.kvm.pipe(dc);
}
function OnWebRTC_DataChannel(dataChannel)
{
console.log("Data Channel (" + dataChannel.name + ") was created");
dc = dataChannel;
dc.on('data', function (buffer) { console.log("Received: " + buffer.length + " bytes"); dc.write(buffer.length.toString());});
}
function OnTunnelData(buffer)
{
if (buffer == 'c')
{
console.log("Tunnel Established");
peerConnection = rtc.createConnection();
peerConnection.on('connected', OnWebRTC_Connected);
peerConnection.on('dataChannel', OnWebRTC_DataChannel);
if(mesh!=null)
{
console.log("Generating WebRTC Offer...");
this.write({ cmd: "offer", data: peerConnection.generateOffer() });
}
}
else
{
ProcessCommand(JSON.parse(buffer.toString()));
}
}
function ProcessCommand(cmd)
{
console.log("Received Command: " + cmd.cmd);
if(cmd.cmd == 'offer')
{
console.log("setting offer...");
console.log(cmd.data);
var counter = peerConnection.setOffer(cmd.data);
if(mesh == null)
{
signalingChannel.write({ cmd: "offer", data: counter });
}
}
if(cmd.cmd == 'candidate')
{
console.log("Received Candidate: " + cmd.data);
}
}

View File

@@ -1,114 +0,0 @@
<html>
<head>
<title>WebRTC Test Application</title>
</head>
<body onload="start()">
<span id="statustext"></span>
<script type="text/javascript">
var configuration = { "iceServers": [] };
var connection = null;
var datachannel = null;
var currentanswer = null;
var wsocket = null;
var decoder = new TextDecoder('utf-8');
var sdp = null;
function start()
{
debug("Connecting signaling channel...");
wsocket = new WebSocket("ws://192.168.5.128:8585/control");
wsocket.binaryType = "arraybuffer";
wsocket.onopen = function (evt)
{
debug("Web Socket Connection established...");
startWebRTC();
}
wsocket.onmessage = function (evt)
{
//var cmd = JSON.parse(decoder.decode(new Uint8Array(evt.data)));
var cmd = JSON.parse(evt.data);
if (cmd.cmd == 'offer')
{
debug("Received WebRTC Offer...");
var ax = null;
if (typeof mozRTCSessionDescription !== 'undefined') { ax = new mozRTCSessionDescription({ type: "offer", sdp: cmd.data }) } else { ax = new RTCSessionDescription({ type: "offer", sdp: cmd.data }) }
connection.setRemoteDescription(ax, onSetRemoteDescriptionDone, onError);
}
}
}
function onSetRemoteDescriptionDone()
{
connection.createAnswer(onAnswerDone, onError);
}
function onAnswerDone(answer)
{
//wsocket.send(JSON.stringify({ cmd: 'offer', data: answer.sdp }));
sdp = answer.sdp;
connection.setLocalDescription(answer, onSetLocalDescriptionDone, onError);
}
function startWebRTC()
{
debug("Initiating WebRTC...");
if (connection != null) { debug("Error!"); return; }
if (typeof mozRTCPeerConnection !== 'undefined') { connection = new mozRTCPeerConnection(configuration); }
else if (typeof RTCPeerConnection !== 'undefined') { connection = new RTCPeerConnection(configuration); }
else if (typeof webkitRTCPeerConnection !== 'undefined') { connection = new webkitRTCPeerConnection(configuration); }
else return false;
connection.ondatachannel = onDataChannel
connection.onicecandidate = onIceCandidate;
connection.oniceconnectionstatechange = function () { if (connection != null) { if ((connection.iceConnectionState == 'disconnected') || (connection.iceConnectionState == 'failed')) { debug("WTF Happened?"); } } }
}
function onOfferDone(offer)
{
// debug(offer.sdp);
currentoffer = offer;
connection.setLocalDescription(offer, onSetLocalDescriptionDone, onError);
sdp = currentoffer.sdp;
}
function onDataChannel(event)
{
debug("Data Channel ("+ event.channel.label + ") connected");
datachannel = event.channel;
datachannel.binaryType = "arraybuffer";
datachannel.onmessage = function (msg)
{
//try
//{
// datachannel.send(msg.data.byteLength.toString() + 'bytes of ' + msg.data[0].toString());
//}
//catch(e)
//{
// debug(e.toString());
// //debug(msg.data.toString());
//}
};
}
function onIceCandidate(e)
{
if (e.candidate == null) {
if (sdp == null) { debug('error'); return; }
wsocket.send(JSON.stringify({ cmd: 'offer', data: sdp }));
}
else
{
sdp += ("a=" + e.candidate.candidate + "\r\n");
}
}
function onSetLocalDescriptionDone() { }
function onError(e) { if (e.message) debug(e.message); else debug(e); }
function debug(msg) { document.getElementById("statustext").innerHTML += (msg + "\r\n"); }
</script>
</body>
</html>

View File

@@ -1,270 +0,0 @@
console.enableWebLog(9595);
var mesh = null;
var kvmStream = null;
var Readable = require('stream').Readable;
var RS = new Readable({
read: function (options)
{
var min = 62000;
var max = 65535;
var size = Math.floor(Math.random() * (max - min)) + min;
var retVal = Buffer.alloc(size).fill(this.val++);
retVal.writeUInt32BE(size, 0);
if (this.val == 10) { this.val = 0; }
return (retVal);
}
});
RS.val = 0;
var http = require('http');
var rtc = require('ILibWebRTC');
var peerConnection;
var signalingChannel;
var dc;
var webServer = http.createServer(OnLocalWebRequest);
var childprocess = require('child_process');
var p;
webServer.on('upgrade', OnUpgrade);
webServer.listen(8585);
if (process.platform == 'win32') {
p = childprocess.execFile("c:\\windows\\system32\\cmd.exe", ["/c", "start", "http://localhost:8585/start.html"]);
}
else {
console.log('Manually point your browser to http://localhost:8585/start.html');
}
try
{
mesh = require('MeshAgent');
}
catch(e)
{
}
function OnUpgrade(imsg, sck, head)
{
console.log("WebSocket Connected");
signalingChannel = sck.upgradeWebSocket();
signalingChannel.on('data', OnSignalData);
peerConnection = rtc.createConnection();
peerConnection.on('disconnected', function () { console.log('SCTP was disconnected'); });
peerConnection.on('connected', OnWebRTC_Connected);
peerConnection.on('dataChannel', OnWebRTC_DataChannel);
try
{
// peerConnection.on('_hold', function (val) { console.log('Holding Count: ' + val);});
peerConnection.on('_congestionWindowSizeChange', function (val) { console.log('Congestion Window: ' + val); });
// peerConnection.on('_receiverCredits', function (val) { console.log('Receiver Credits: ' + val); });
peerConnection.on('_t3tx', function (val) { console.log('T3TX: ' + val); });
//peerConnection.on('_fastRecovery', function (val) { console.log('Fast Recovery: ' + val);});
//peerConnection.on('_rttCalculated', function (val) { console.log('Calculated RTT Value = ' + val); });
peerConnection.on('_lastSackTime', function (val) { console.log('Last SACK Time = ' + val); });
peerConnection.on('_retransmit', function (val) { console.log('Retransmit: ' + (new Uint32Array([val]))[0]); });
//peerConnection.on('_retransmitPacket', function (val) { DebugPacket(val); console.log('RetransmitPacket: ' + val.toString('hex')); });
//peerConnection.on('_lastSentTime', function (val) { console.log('Last Sent Time = ' + val); });
peerConnection.on('_sackReceived', function (val) { console.log('SACK: ' + (new Uint32Array([val]))[0]); });
}
catch(e)
{
}
console.log("Generating WebRTC Offer...");
signalingChannel.write({ cmd: "offer", data: peerConnection.generateOffer() });
}
function FOURBYTEBOUNDARY(a)
{
return ((a) + ((4 - ((a) % 4)) % 4));
}
function crc32c(crc, bytes)
{
var POLY = 0x82f63b78;
var n;
crc ^= 0xffffffff;
for (n = 0; n < bytes.length; n++) {
crc ^= bytes[n];
crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1;
crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1;
crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1;
crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1;
crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1;
crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1;
crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1;
crc = crc & 1 ? (crc >>> 1) ^ POLY : crc >>> 1;
}
return crc ^ 0xffffffff;
}
function DebugPacket(val)
{
console.log('BufferLen: ' + val.length);
console.log('CRC32C: ' + val.readInt32LE(8))
val.writeUInt32BE(0, 8);
console.log('CRC32C/Calc: ' + crc32c(0, val));
console.log('VTAG: ' + val.readUInt32LE(4));
var ptr = 12;
while (ptr + 4 <= val.length)
{
var hdr = val.slice(ptr);
var chunkType = hdr[0];
var chunkFlags = hdr[1];
var chunkSize = hdr.readUInt16BE(2);
switch (chunkType) {
case 0:
console.log('DATA Chunk');
console.log('...chunkFlags: ' + chunkFlags);
console.log('...chunkLength: ' + chunkSize);
console.log('...TSN: ' + hdr.readUInt32BE(4));
console.log('...StreamID: ' + hdr.readUInt16BE(8));
console.log('...Seq: ' + hdr.readUInt16BE(10));
console.log('...ProtocolID: ' + hdr.readUInt32BE(12));
break;
default:
console.log('UNKNOWN Chunk');
console.log('...chunkFlags: ' + chunkFlags);
console.log('...chunkLength: ' + chunkSize);
break;
}
ptr += FOURBYTEBOUNDARY(chunkSize);
}
}
function OnSignalData(chunk)
{
var j = JSON.parse(chunk);
if (j.cmd == 'offer')
{
console.log("Received Offer");
//signalingChannel.write({ cmd: "offer", data: peerConnection.setOffer(j.data) });
peerConnection.setOffer(j.data);
}
}
function OnLocalWebRequest(request, response)
{
if(request.method == 'GET' && request.url == '/start.html')
{
var fs = require('fs');
try
{
var stream = fs.createReadStream('WebRTC_Test2.html');
response.statusCode = 200;
response.statusMessage = "OK";
stream.pipe(response);
}
catch(e)
{
response.statusCode = 404;
response.statusMessage = "Not Found";
response.end();
}
}
else
{
response.statusCode = 404;
response.statusMessage = "Not Found";
response.end();
}
}
function OnWebRTC_Connected()
{
console.log("WebRTC Session Established");
this.jsdc = this.createDataChannel("testChannel", OnTestChannel);
}
function OnTestChannel()
{
console.log("Successfully established JavaScript Data Channel");
if (mesh == null) {
RS.pipe(this);
}
else {
kvmStream = mesh.getRemoteDesktopStream();
kvmStream.pipe(this);
}
}
function OnKVMChannel()
{
console.log("Successfully established Data Channel to test Data throughput");
dc = this;
dc.kvm = mesh.getRemoteDesktopStream();
dc.on('data', function (buffer)
{
console.log("Peer Received: " + buffer.toString() + " bytes");
});
dc.on('end', function () { this.kvm.end(); console.log("Closing KVM Session"); });
dc.kvm.pipe(dc);
}
function OnWebRTC_DataChannel(dataChannel)
{
console.log("Data Channel (" + dataChannel.name + ") was created");
dc = dataChannel;
dc.on('data', function (buffer)
{
//console.log("Received: " + buffer);
});
dc.on('end', function () { console.log("Data Channel: " + this.name + " was closed"); });
//if (mesh == null)
//{
// RS.pipe(dc);
//}
//else
//{
// kvmStream = mesh.getRemoteDesktopStream();
// kvmStream.pipe(dc);
//}
}
function OnTunnelData(buffer)
{
if (buffer == 'c')
{
console.log("Tunnel Established");
peerConnection = rtc.createConnection();
peerConnection.on('connected', OnWebRTC_Connected);
peerConnection.on('dataChannel', OnWebRTC_DataChannel);
if(mesh!=null)
{
console.log("Generating WebRTC Offer...");
this.write({ cmd: "offer", data: peerConnection.generateOffer() });
}
}
else
{
ProcessCommand(JSON.parse(buffer.toString()));
}
}
function ProcessCommand(cmd)
{
console.log("Received Command: " + cmd.cmd);
if(cmd.cmd == 'offer')
{
console.log("setting offer...");
console.log(cmd.data);
var counter = peerConnection.setOffer(cmd.data);
if(mesh == null)
{
signalingChannel.write({ cmd: "offer", data: counter });
}
}
if(cmd.cmd == 'candidate')
{
console.log("Received Candidate: " + cmd.data);
}
}

View File

@@ -1,266 +0,0 @@
var MemoryStream = require('MemoryStream');
var WindowsWireless = new Buffer([
0x0A, 0x66, 0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x5F, 0x53, 0x63, 0x61, 0x6E, 0x28, 0x29, 0x0A, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x77, 0x6C, 0x61, 0x6E,
0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65,
0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x57, 0x6C, 0x61, 0x6E, 0x45,
0x6E, 0x75, 0x6D, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x77, 0x6C,
0x61, 0x6E, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x63, 0x6F, 0x75, 0x6E, 0x74, 0x20, 0x3D, 0x20,
0x77, 0x6C, 0x61, 0x6E, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x30, 0x2C, 0x20,
0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x20, 0x3D, 0x20, 0x77, 0x6C, 0x61, 0x6E, 0x49, 0x6E, 0x74, 0x65,
0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x38, 0x2C, 0x20, 0x35, 0x33, 0x32, 0x29, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x6E, 0x61, 0x6D, 0x65, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x31, 0x36, 0x2C, 0x20, 0x35, 0x31, 0x32,
0x29, 0x2E, 0x41, 0x6E, 0x73, 0x69, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x3B, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x73, 0x77, 0x69, 0x74, 0x63, 0x68, 0x20, 0x28, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x35, 0x32, 0x38, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61,
0x6C, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20, 0x30, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x4E, 0x4F, 0x54, 0x20, 0x52, 0x45, 0x41, 0x44, 0x59, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20, 0x31, 0x3A, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x43, 0x4F, 0x4E, 0x4E, 0x45, 0x43, 0x54, 0x45, 0x44, 0x22, 0x3B, 0x0A,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20,
0x32, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x41, 0x44, 0x2D, 0x48, 0x4F, 0x43, 0x22,
0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73,
0x65, 0x20, 0x33, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x44, 0x49, 0x53, 0x43, 0x4F,
0x4E, 0x4E, 0x45, 0x43, 0x54, 0x49, 0x4E, 0x47, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20, 0x34, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65,
0x20, 0x3D, 0x20, 0x22, 0x44, 0x49, 0x53, 0x43, 0x4F, 0x4E, 0x4E, 0x45, 0x43, 0x54, 0x45, 0x44, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62,
0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20, 0x35, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x41, 0x53, 0x53, 0x4F, 0x43, 0x49, 0x41, 0x54, 0x49, 0x4E, 0x47, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65, 0x20, 0x36, 0x3A, 0x0A, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x44, 0x49, 0x53, 0x43, 0x4F, 0x56, 0x45, 0x52, 0x49, 0x4E, 0x47, 0x22, 0x3B,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x63, 0x61, 0x73, 0x65,
0x20, 0x37, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x22, 0x41, 0x55, 0x54, 0x48, 0x45, 0x4E,
0x54, 0x49, 0x43, 0x41, 0x54, 0x49, 0x4E, 0x47, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x64, 0x65, 0x66, 0x61, 0x75, 0x6C, 0x74, 0x3A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74,
0x65, 0x20, 0x3D, 0x20, 0x22, 0x55, 0x4E, 0x4B, 0x4E, 0x4F, 0x57, 0x4E, 0x22, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x62, 0x72, 0x65, 0x61, 0x6B,
0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x67, 0x75, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65,
0x72, 0x65, 0x66, 0x28, 0x30, 0x2C, 0x20, 0x31, 0x36, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E,
0x57, 0x6C, 0x61, 0x6E, 0x53, 0x63, 0x61, 0x6E, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x69, 0x67, 0x75, 0x69, 0x64, 0x2C, 0x20, 0x30, 0x2C, 0x20,
0x30, 0x2C, 0x20, 0x30, 0x29, 0x20, 0x3D, 0x3D, 0x20, 0x30, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6E,
0x20, 0x28, 0x74, 0x72, 0x75, 0x65, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6C, 0x73, 0x65, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6E, 0x20, 0x28, 0x66, 0x61, 0x6C, 0x73, 0x65, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x7D, 0x0A, 0x0A, 0x66,
0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x28, 0x5F, 0x73, 0x73, 0x69, 0x64, 0x2C, 0x20, 0x5F, 0x62, 0x73, 0x73, 0x69,
0x64, 0x2C, 0x20, 0x5F, 0x72, 0x73, 0x73, 0x69, 0x2C, 0x20, 0x5F, 0x6C, 0x71, 0x29, 0x0A, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x73, 0x73, 0x69, 0x64, 0x20, 0x3D,
0x20, 0x5F, 0x73, 0x73, 0x69, 0x64, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x62, 0x73, 0x73, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x5F, 0x62, 0x73, 0x73, 0x69, 0x64, 0x3B,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x72, 0x73, 0x73, 0x69, 0x20, 0x3D, 0x20, 0x5F, 0x72, 0x73, 0x73, 0x69, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73,
0x2E, 0x6C, 0x71, 0x20, 0x3D, 0x20, 0x5F, 0x6C, 0x71, 0x3B, 0x0A, 0x7D, 0x0A, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x2E, 0x70, 0x72, 0x6F, 0x74, 0x6F, 0x74, 0x79,
0x70, 0x65, 0x2E, 0x74, 0x6F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x20, 0x3D, 0x20, 0x66, 0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x28, 0x29, 0x0A, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x72,
0x65, 0x74, 0x75, 0x72, 0x6E, 0x20, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x73, 0x73, 0x69, 0x64, 0x20, 0x2B, 0x20, 0x22, 0x20, 0x5B, 0x22, 0x20, 0x2B, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x62,
0x73, 0x73, 0x69, 0x64, 0x20, 0x2B, 0x20, 0x22, 0x5D, 0x3A, 0x20, 0x22, 0x20, 0x2B, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x6C, 0x71, 0x29, 0x3B, 0x0A, 0x7D, 0x0A, 0x0A, 0x66, 0x75, 0x6E, 0x63,
0x74, 0x69, 0x6F, 0x6E, 0x20, 0x4F, 0x6E, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x79, 0x28, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x44, 0x61, 0x74, 0x61, 0x29, 0x0A,
0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x3D, 0x20, 0x4E,
0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x44, 0x61, 0x74, 0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x30, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x43, 0x6F, 0x64, 0x65, 0x20, 0x3D, 0x20, 0x4E, 0x6F, 0x74, 0x69,
0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x44, 0x61, 0x74, 0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x34, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x64, 0x61, 0x74, 0x61, 0x47, 0x75, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x44, 0x61, 0x74,
0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x38, 0x2C, 0x20, 0x31, 0x36, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x28, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69,
0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x26, 0x20, 0x30, 0x58, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x38, 0x29, 0x20, 0x26, 0x26, 0x20, 0x28, 0x4E,
0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x43, 0x6F, 0x64, 0x65, 0x20, 0x3D, 0x3D, 0x20, 0x37, 0x29, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x62, 0x73, 0x73, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x50, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68,
0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20,
0x72, 0x65, 0x73, 0x75, 0x6C, 0x74, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x50, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x47, 0x65, 0x74, 0x42,
0x53, 0x53, 0x4C, 0x69, 0x73, 0x74, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x50, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x64, 0x61, 0x74, 0x61, 0x47,
0x75, 0x69, 0x64, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x33, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x62, 0x73, 0x73, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69,
0x66, 0x20, 0x28, 0x72, 0x65, 0x73, 0x75, 0x6C, 0x74, 0x20, 0x3D, 0x3D, 0x20, 0x30, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x74, 0x6F, 0x74, 0x61, 0x6C, 0x53, 0x69, 0x7A, 0x65, 0x20, 0x3D, 0x20, 0x62, 0x73, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28,
0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x30, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76,
0x61, 0x72, 0x20, 0x6E, 0x75, 0x6D, 0x49, 0x74, 0x65, 0x6D, 0x73, 0x20, 0x3D, 0x20, 0x62, 0x73, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28,
0x34, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x66, 0x6F, 0x72, 0x20, 0x28, 0x69, 0x20, 0x3D, 0x20,
0x30, 0x3B, 0x20, 0x69, 0x20, 0x3C, 0x20, 0x6E, 0x75, 0x6D, 0x49, 0x74, 0x65, 0x6D, 0x73, 0x3B, 0x20, 0x2B, 0x2B, 0x69, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x74, 0x65, 0x6D, 0x20, 0x3D, 0x20, 0x62,
0x73, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x38, 0x20, 0x2B, 0x20, 0x28, 0x33, 0x36, 0x30, 0x20, 0x2A, 0x20, 0x69, 0x29, 0x2C, 0x20,
0x33, 0x36, 0x30, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x73, 0x73, 0x69, 0x64, 0x20, 0x3D,
0x20, 0x69, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x34, 0x2C, 0x20, 0x33, 0x32, 0x29, 0x2E, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x2E, 0x74, 0x72, 0x69, 0x6D, 0x28, 0x29,
0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x62, 0x73, 0x73, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x69, 0x74,
0x65, 0x6D, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x34, 0x30, 0x2C, 0x20, 0x36, 0x29, 0x2E, 0x48, 0x65, 0x78, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x32, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x72, 0x73, 0x73, 0x69, 0x20, 0x3D, 0x20, 0x69, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x65, 0x72, 0x65,
0x66, 0x28, 0x35, 0x36, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61,
0x72, 0x20, 0x6C, 0x71, 0x20, 0x3D, 0x20, 0x69, 0x74, 0x65, 0x6D, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x36, 0x30, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x50, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x2E, 0x65, 0x6D, 0x69, 0x74, 0x28,
0x27, 0x53, 0x63, 0x61, 0x6E, 0x27, 0x2C, 0x20, 0x6E, 0x65, 0x77, 0x20, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x28, 0x73, 0x73, 0x69, 0x64, 0x2C, 0x20, 0x62, 0x73,
0x73, 0x69, 0x64, 0x2C, 0x20, 0x72, 0x73, 0x73, 0x69, 0x2C, 0x20, 0x6C, 0x71, 0x29, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x7D, 0x0A, 0x0A, 0x66, 0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x57, 0x69, 0x72, 0x65,
0x6C, 0x65, 0x73, 0x73, 0x28, 0x29, 0x0A, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x65, 0x6D, 0x69, 0x74, 0x74, 0x65, 0x72, 0x55, 0x74, 0x69, 0x6C, 0x73, 0x20, 0x3D, 0x20,
0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x65, 0x76, 0x65, 0x6E, 0x74, 0x73, 0x27, 0x29, 0x2E, 0x69, 0x6E, 0x68, 0x65, 0x72, 0x69, 0x74, 0x73, 0x28, 0x74, 0x68, 0x69, 0x73, 0x29,
0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x20, 0x3D, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x5F,
0x47, 0x65, 0x6E, 0x65, 0x72, 0x69, 0x63, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x27, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76,
0x65, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x50, 0x72, 0x6F,
0x78, 0x79, 0x28, 0x22, 0x77, 0x6C, 0x61, 0x6E, 0x61, 0x70, 0x69, 0x2E, 0x64, 0x6C, 0x6C, 0x22, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69,
0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28, 0x22, 0x57, 0x6C, 0x61, 0x6E, 0x4F, 0x70, 0x65, 0x6E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x22,
0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28,
0x22, 0x57, 0x6C, 0x61, 0x6E, 0x47, 0x65, 0x74, 0x4E, 0x65, 0x74, 0x77, 0x6F, 0x72, 0x6B, 0x42, 0x73, 0x73, 0x4C, 0x69, 0x73, 0x74, 0x22, 0x2C, 0x20, 0x22, 0x47, 0x65, 0x74, 0x42, 0x53, 0x53,
0x4C, 0x69, 0x73, 0x74, 0x22, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65,
0x74, 0x68, 0x6F, 0x64, 0x28, 0x22, 0x57, 0x6C, 0x61, 0x6E, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x22, 0x29,
0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28, 0x22,
0x57, 0x6C, 0x61, 0x6E, 0x45, 0x6E, 0x75, 0x6D, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x22, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E,
0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28, 0x22, 0x57, 0x6C, 0x61, 0x6E, 0x53, 0x63, 0x61, 0x6E, 0x22, 0x29, 0x3B, 0x0A,
0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28, 0x22, 0x57, 0x6C,
0x61, 0x6E, 0x51, 0x75, 0x65, 0x72, 0x79, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x22, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x6E, 0x65, 0x67,
0x6F, 0x74, 0x69, 0x61, 0x74, 0x65, 0x64, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69,
0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x68, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C,
0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69,
0x76, 0x65, 0x2E, 0x57, 0x6C, 0x61, 0x6E, 0x4F, 0x70, 0x65, 0x6E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x28, 0x32, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x6E, 0x65, 0x67, 0x6F, 0x74, 0x69, 0x61, 0x74,
0x65, 0x64, 0x2C, 0x20, 0x68, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x20, 0x3D, 0x20, 0x68, 0x2E, 0x56, 0x61, 0x6C, 0x3B,
0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x5F, 0x4E, 0x4F, 0x54, 0x49, 0x46, 0x59, 0x5F, 0x50, 0x52, 0x4F, 0x58, 0x59, 0x5F, 0x4F, 0x42, 0x4A, 0x45, 0x43, 0x54, 0x20,
0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x61, 0x6C, 0x6C, 0x62, 0x61, 0x63, 0x6B, 0x50, 0x72, 0x6F,
0x78, 0x79, 0x28, 0x4F, 0x6E, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x79, 0x2C, 0x20, 0x32, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x5F, 0x4E, 0x4F, 0x54, 0x49, 0x46,
0x59, 0x5F, 0x50, 0x52, 0x4F, 0x58, 0x59, 0x5F, 0x4F, 0x42, 0x4A, 0x45, 0x43, 0x54, 0x2E, 0x50, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x50, 0x72, 0x65, 0x76, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E,
0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x72, 0x65, 0x73, 0x75, 0x6C, 0x74, 0x20,
0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x57, 0x6C, 0x61, 0x6E, 0x52, 0x65, 0x67, 0x69, 0x73, 0x74, 0x65, 0x72, 0x4E, 0x6F, 0x74, 0x69, 0x66, 0x69,
0x63, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x30, 0x58, 0x30, 0x30, 0x30, 0x30, 0x46, 0x46, 0x46, 0x46, 0x2C, 0x20,
0x30, 0x2C, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x5F, 0x4E, 0x4F, 0x54, 0x49, 0x46, 0x59, 0x5F, 0x50, 0x52, 0x4F, 0x58, 0x59, 0x5F, 0x4F, 0x42, 0x4A, 0x45, 0x43, 0x54, 0x2E, 0x43, 0x61, 0x6C,
0x6C, 0x62, 0x61, 0x63, 0x6B, 0x2C, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x5F, 0x4E, 0x4F, 0x54, 0x49, 0x46, 0x59, 0x5F, 0x50, 0x52, 0x4F, 0x58, 0x59, 0x5F, 0x4F, 0x42, 0x4A, 0x45, 0x43, 0x54,
0x2E, 0x53, 0x74, 0x61, 0x74, 0x65, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x50, 0x72, 0x65, 0x76, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x65, 0x6D, 0x69,
0x74, 0x74, 0x65, 0x72, 0x55, 0x74, 0x69, 0x6C, 0x73, 0x2E, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x45, 0x76, 0x65, 0x6E, 0x74, 0x28, 0x27, 0x53, 0x63, 0x61, 0x6E, 0x27, 0x29, 0x3B, 0x0A, 0x20,
0x20, 0x20, 0x20, 0x65, 0x6D, 0x69, 0x74, 0x74, 0x65, 0x72, 0x55, 0x74, 0x69, 0x6C, 0x73, 0x2E, 0x61, 0x64, 0x64, 0x4D, 0x65, 0x74, 0x68, 0x6F, 0x64, 0x28, 0x27, 0x53, 0x63, 0x61, 0x6E, 0x27,
0x2C, 0x20, 0x5F, 0x53, 0x63, 0x61, 0x6E, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x47, 0x65, 0x74, 0x43, 0x6F, 0x6E, 0x6E, 0x65, 0x63, 0x74, 0x65, 0x64,
0x4E, 0x65, 0x74, 0x77, 0x6F, 0x72, 0x6B, 0x20, 0x3D, 0x20, 0x66, 0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x28, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61,
0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x69, 0x73,
0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x57, 0x6C, 0x61, 0x6E, 0x45, 0x6E, 0x75, 0x6D, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x28, 0x74, 0x68, 0x69, 0x73, 0x2E,
0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x63, 0x6F, 0x75, 0x6E, 0x74, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x2E,
0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x30, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65, 0x73, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44,
0x65, 0x72, 0x65, 0x66, 0x28, 0x38, 0x2C, 0x20, 0x35, 0x33, 0x32, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x6E, 0x61, 0x6D, 0x65, 0x20,
0x3D, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x31, 0x36, 0x2C, 0x20, 0x35, 0x31, 0x32, 0x29, 0x2E, 0x41, 0x6E, 0x73, 0x69, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67,
0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x73, 0x74, 0x61, 0x74, 0x65, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65,
0x66, 0x28, 0x35, 0x32, 0x38, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x49, 0x6E, 0x74, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x28, 0x69, 0x6E,
0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x35, 0x32, 0x38, 0x2C, 0x20, 0x34, 0x29, 0x2E, 0x49, 0x6E, 0x74, 0x56, 0x61, 0x6C, 0x20, 0x3D, 0x3D, 0x20, 0x31, 0x29, 0x20, 0x2F, 0x2F,
0x20, 0x43, 0x4F, 0x4E, 0x4E, 0x45, 0x43, 0x54, 0x45, 0x44, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x76, 0x61, 0x72, 0x20, 0x64, 0x61, 0x74, 0x61, 0x53, 0x69, 0x7A, 0x65, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65,
0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x70, 0x44,
0x61, 0x74, 0x61, 0x20, 0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72,
0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x54, 0x79, 0x70, 0x65, 0x20, 0x3D, 0x20,
0x74, 0x68, 0x69, 0x73, 0x2E, 0x4D, 0x61, 0x72, 0x73, 0x68, 0x61, 0x6C, 0x2E, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x65, 0x72, 0x28, 0x29, 0x3B, 0x0A, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x69, 0x67, 0x75, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x69, 0x6E, 0x66, 0x6F, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66,
0x28, 0x30, 0x2C, 0x20, 0x31, 0x36, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x72, 0x65, 0x74, 0x56, 0x61, 0x6C, 0x20,
0x3D, 0x20, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x4E, 0x61, 0x74, 0x69, 0x76, 0x65, 0x2E, 0x57, 0x6C, 0x61, 0x6E, 0x51, 0x75, 0x65, 0x72, 0x79, 0x49, 0x6E, 0x74, 0x65, 0x72, 0x66, 0x61, 0x63, 0x65,
0x28, 0x74, 0x68, 0x69, 0x73, 0x2E, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x2C, 0x20, 0x69, 0x67, 0x75, 0x69, 0x64, 0x2C, 0x20, 0x37, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x64, 0x61, 0x74, 0x61, 0x53,
0x69, 0x7A, 0x65, 0x2C, 0x20, 0x70, 0x44, 0x61, 0x74, 0x61, 0x2C, 0x20, 0x76, 0x61, 0x6C, 0x75, 0x65, 0x54, 0x79, 0x70, 0x65, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x69, 0x66, 0x20, 0x28, 0x72, 0x65, 0x74, 0x56, 0x61, 0x6C, 0x20, 0x3D, 0x3D, 0x20, 0x30, 0x29, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x7B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72, 0x20, 0x61, 0x73, 0x73, 0x6F, 0x63, 0x69, 0x61, 0x74, 0x65,
0x64, 0x53, 0x53, 0x49, 0x44, 0x20, 0x3D, 0x20, 0x70, 0x44, 0x61, 0x74, 0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x35, 0x32, 0x34, 0x2C,
0x20, 0x33, 0x32, 0x29, 0x2E, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x76, 0x61, 0x72,
0x20, 0x62, 0x73, 0x73, 0x69, 0x64, 0x20, 0x3D, 0x20, 0x70, 0x44, 0x61, 0x74, 0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x35, 0x36, 0x30,
0x2C, 0x20, 0x36, 0x29, 0x2E, 0x48, 0x65, 0x78, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x76, 0x61, 0x72, 0x20, 0x6C, 0x71, 0x20, 0x3D, 0x20, 0x70, 0x44, 0x61, 0x74, 0x61, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x29, 0x2E, 0x44, 0x65, 0x72, 0x65, 0x66, 0x28, 0x35, 0x37, 0x36,
0x2C, 0x20, 0x34, 0x29, 0x2E, 0x49, 0x6E, 0x74, 0x56, 0x61, 0x6C, 0x3B, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65,
0x74, 0x75, 0x72, 0x6E, 0x20, 0x28, 0x6E, 0x65, 0x77, 0x20, 0x41, 0x63, 0x63, 0x65, 0x73, 0x73, 0x50, 0x6F, 0x69, 0x6E, 0x74, 0x28, 0x61, 0x73, 0x73, 0x6F, 0x63, 0x69, 0x61, 0x74, 0x65, 0x64,
0x53, 0x53, 0x49, 0x44, 0x2C, 0x20, 0x62, 0x73, 0x73, 0x69, 0x64, 0x2C, 0x20, 0x30, 0x2C, 0x20, 0x6C, 0x71, 0x29, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x7D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x7D, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x74, 0x68, 0x72, 0x6F, 0x77, 0x20, 0x28, 0x22, 0x47, 0x65,
0x74, 0x43, 0x6F, 0x6E, 0x6E, 0x65, 0x63, 0x74, 0x65, 0x64, 0x4E, 0x65, 0x74, 0x77, 0x6F, 0x72, 0x6B, 0x73, 0x3A, 0x20, 0x46, 0x41, 0x49, 0x4C, 0x45, 0x44, 0x20, 0x28, 0x6E, 0x6F, 0x74, 0x20,
0x61, 0x73, 0x73, 0x6F, 0x63, 0x69, 0x61, 0x74, 0x65, 0x64, 0x20, 0x74, 0x6F, 0x20, 0x61, 0x20, 0x6E, 0x65, 0x74, 0x77, 0x6F, 0x72, 0x6B, 0x29, 0x22, 0x29, 0x3B, 0x0A, 0x20, 0x20, 0x20, 0x20,
0x7D, 0x3B, 0x0A, 0x0A, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6E, 0x20, 0x28, 0x74, 0x68, 0x69, 0x73, 0x29, 0x3B, 0x0A, 0x7D, 0x0A, 0x0A, 0x6D, 0x6F, 0x64, 0x75, 0x6C,
0x65, 0x2E, 0x65, 0x78, 0x70, 0x6F, 0x72, 0x74, 0x73, 0x20, 0x3D, 0x20, 0x6E, 0x65, 0x77, 0x20, 0x57, 0x69, 0x72, 0x65, 0x6C, 0x65, 0x73, 0x73, 0x28, 0x29, 0x3B, 0x0A]);
var WindowsChildScript = new Buffer([
0x76, 0x61, 0x72, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x20, 0x3D, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x28, 0x27, 0x53, 0x63, 0x72, 0x69, 0x70, 0x74, 0x43, 0x6F, 0x6E, 0x74,
0x61, 0x69, 0x6E, 0x65, 0x72, 0x27, 0x29, 0x3B, 0x0D, 0x0A, 0x76, 0x61, 0x72, 0x20, 0x57, 0x69, 0x72, 0x65, 0x6C, 0x65, 0x73, 0x73, 0x20, 0x3D, 0x20, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65,
0x28, 0x27, 0x57, 0x69, 0x72, 0x65, 0x6C, 0x65, 0x73, 0x73, 0x27, 0x29, 0x3B, 0x0D, 0x0A, 0x0D, 0x0A, 0x57, 0x69, 0x72, 0x65, 0x6C, 0x65, 0x73, 0x73, 0x2E, 0x6F, 0x6E, 0x28, 0x27, 0x53, 0x63,
0x61, 0x6E, 0x27, 0x2C, 0x20, 0x66, 0x75, 0x6E, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x28, 0x61, 0x70, 0x29, 0x20, 0x7B, 0x20, 0x70, 0x61, 0x72, 0x65, 0x6E, 0x74, 0x2E, 0x73, 0x65, 0x6E, 0x64,
0x28, 0x61, 0x70, 0x29, 0x3B, 0x20, 0x7D, 0x29, 0x3B, 0x0D, 0x0A, 0x57, 0x69, 0x72, 0x65, 0x6C, 0x65, 0x73, 0x73, 0x2E, 0x53, 0x63, 0x61, 0x6E, 0x28, 0x29, 0x3B, 0x0D, 0x0A]);
function AccessPoint(_ssid, _bssid, _lq)
{
this.ssid = _ssid;
this.bssid = _bssid;
this.lq = _lq;
}
AccessPoint.prototype.toString = function ()
{
return (this.ssid + " [" + this.bssid + "]: " + this.lq);
}
function WiFiScanner()
{
var emitterUtils = require('events').inherits(this);
emitterUtils.createEvent('accessPoint');
this.hasWireless = function ()
{
var retVal = false;
var interfaces = require('os').networkInterfaces();
for (var name in interfaces)
{
if (interfaces[name][0].type == 'wireless') { retVal = true; break; }
}
return (retVal);
};
this.Scan = function ()
{
if (process.platform == 'win32')
{
this.master = require('ScriptContainer').Create(15, ContainerPermissions.DEFAULT);
this.master.parent = this;
this.master.on('data', function (j) { this.parent.emit('accessPoint', new AccessPoint(j.ssid, j.bssid, j.lq)); });
this.master.addModule('Wireless', WindowsWireless.toString());
this.master.ExecuteString(WindowsChildScript.toString());
}
else if (process.platform == 'linux')
{
// Need to get the wireless interface name
var interfaces = require('os').networkInterfaces();
var wlan = null;
for (var i in interfaces)
{
if (interfaces[i][0].type == 'wireless')
{
wlan = i;
break;
}
}
if (wlan != null)
{
this.child = require('ILibProcessPipe').CreateProcess("/sbin/iwlist", "iwlist", wlan, "scan");
this.child.parent = this;
this.child.ms = new MemoryStream();
this.child.ms.parent = this.child;
this.child.on('data', function (buffer) { this.ms.write(buffer); });
this.child.on('end', function () { this.ms.end(); });
this.child.ms.on('end', function ()
{
var str = this.buffer.toString();
tokens = str.split(' - Address: ');
for (var block in tokens)
{
if (block == 0) continue;
var ln = tokens[block].split('\n');
var _bssid = ln[0];
var _lq;
var _ssid;
for (var lnblock in ln)
{
lnblock = ln[lnblock].trim();
lnblock = lnblock.trim();
if (lnblock.startsWith('ESSID:'))
{
_ssid = lnblock.slice(7, lnblock.length - 1);
if (_ssid == '<hidden>') { _ssid = ''; }
}
if (lnblock.startsWith('Signal level='))
{
_lq = lnblock.slice(13,lnblock.length-4);
}
}
this.parent.parent.emit('accessPoint', new AccessPoint(_ssid, _bssid, _lq));
}
});
}
}
}
}
module.exports = WiFiScanner;

View File

@@ -1,157 +0,0 @@
function _Scan()
{
var wlanInterfaces = this.Marshal.CreatePointer();
this.Native.WlanEnumInterfaces(this.Handle, 0, wlanInterfaces);
var count = wlanInterfaces.Deref().Deref(0, 4).Val;
var info = wlanInterfaces.Deref().Deref(8, 532);
var iname = info.Deref(16, 512).AnsiString;
var istate;
switch (info.Deref(528, 4).Val)
{
case 0:
istate = "NOT READY";
break;
case 1:
istate = "CONNECTED";
break;
case 2:
istate = "AD-HOC";
break;
case 3:
istate = "DISCONNECTING";
break;
case 4:
istate = "DISCONNECTED";
break;
case 5:
istate = "ASSOCIATING";
break;
case 6:
istate = "DISCOVERING";
break;
case 7:
istate = "AUTHENTICATING";
break;
default:
istate = "UNKNOWN";
break;
}
var iguid = info.Deref(0, 16);
if (this.Native.WlanScan(this.Handle, iguid, 0, 0, 0) == 0)
{
return (true);
}
else
{
return (false);
}
}
function AccessPoint(_ssid, _bssid, _rssi, _lq)
{
this.ssid = _ssid;
this.bssid = _bssid;
this.rssi = _rssi;
this.lq = _lq;
}
AccessPoint.prototype.toString = function()
{
return (this.ssid + " [" + this.bssid + "]: " + this.lq);
}
function OnNotify(NotificationData)
{
var NotificationSource = NotificationData.Deref(0, 4).Val;
var NotificationCode = NotificationData.Deref(4, 4).Val;
var dataGuid = NotificationData.Deref(8, 16);
if ((NotificationSource & 0X00000008) && (NotificationCode == 7))
{
var bss = this.Parent.Marshal.CreatePointer();
var result = this.Parent.Native.GetBSSList(this.Parent.Handle, dataGuid, 0, 3, 0, 0, bss);
if (result == 0)
{
var totalSize = bss.Deref().Deref(0, 4).Val;
var numItems = bss.Deref().Deref(4, 4).Val;
for (i = 0; i < numItems; ++i)
{
var item = bss.Deref().Deref(8 + (360 * i), 360);
var ssid = item.Deref(4, 32).String.trim();
var bssid = item.Deref(40, 6).HexString2;
var rssi = item.Deref(56, 4).Val;
var lq = item.Deref(60, 4).Val;
this.Parent.emit('Scan', new AccessPoint(ssid, bssid, rssi, lq));
}
}
}
}
function Wireless()
{
var emitterUtils = require('events').inherits(this);
this.Marshal = require('_GenericMarshal');
this.Native = this.Marshal.CreateNativeProxy("wlanapi.dll");
this.Native.CreateMethod("WlanOpenHandle");
this.Native.CreateMethod("WlanGetNetworkBssList", "GetBSSList");
this.Native.CreateMethod("WlanRegisterNotification");
this.Native.CreateMethod("WlanEnumInterfaces");
this.Native.CreateMethod("WlanScan");
this.Native.CreateMethod("WlanQueryInterface");
var negotiated = this.Marshal.CreatePointer();
var h = this.Marshal.CreatePointer();
this.Native.WlanOpenHandle(2, 0, negotiated, h);
this.Handle = h.Val;
this._NOTIFY_PROXY_OBJECT = this.Marshal.CreateCallbackProxy(OnNotify, 2);
this._NOTIFY_PROXY_OBJECT.Parent = this;
var PrevSource = this.Marshal.CreatePointer();
var result = this.Native.WlanRegisterNotification(this.Handle, 0X0000FFFF, 0, this._NOTIFY_PROXY_OBJECT.Callback, this._NOTIFY_PROXY_OBJECT.State, 0, PrevSource);
emitterUtils.createEvent('Scan');
emitterUtils.addMethod('Scan', _Scan);
this.GetConnectedNetwork = function ()
{
var interfaces = this.Marshal.CreatePointer();
this.Native.WlanEnumInterfaces(this.Handle, 0, interfaces);
var count = interfaces.Deref().Deref(0, 4).Val;
var info = interfaces.Deref().Deref(8, 532);
var iname = info.Deref(16, 512).AnsiString;
var istate = info.Deref(528, 4).IntVal;
if(info.Deref(528, 4).IntVal == 1) // CONNECTED
{
var dataSize = this.Marshal.CreatePointer();
var pData = this.Marshal.CreatePointer();
var valueType = this.Marshal.CreatePointer();
var iguid = info.Deref(0, 16);
var retVal = this.Native.WlanQueryInterface(this.Handle, iguid, 7, 0, dataSize, pData, valueType);
if (retVal == 0)
{
var associatedSSID = pData.Deref().Deref(524, 32).String;
var bssid = pData.Deref().Deref(560, 6).HexString;
var lq = pData.Deref().Deref(576, 4).IntVal;
return (new AccessPoint(associatedSSID, bssid, 0, lq));
}
}
throw ("GetConnectedNetworks: FAILED (not associated to a network)");
};
return (this);
}
module.exports = new Wireless();

View File

@@ -1,281 +0,0 @@
var Q = require('queue');
function amt_heci() {
var emitterUtils = require('events').inherits(this);
emitterUtils.createEvent('error');
emitterUtils.createEvent('connect');
var heci = require('heci');
this._amt = heci.create();
this._amt.BiosVersionLen = 65;
this._amt.UnicodeStringLen = 20;
this._amt.rq = new Q();
this._amt.Parent = this;
this._amt.on('error', function (e) { this.Parent.emit('error', e); });
this._amt.on('connect', function () {
this.Parent.emit('connect');
this.on('data', function (chunk) {
//console.log("Received: " + chunk.length + " bytes");
var header = this.Parent.getCommand(chunk);
//console.log("CMD = " + header.Command + " (Status: " + header.Status + ") Response = " + header.IsResponse);
var user = this.rq.deQueue();
var params = user.optional;
var callback = user.func;
params.unshift(header);
callback.apply(this.Parent, params);
});
});
this._amt.connect(heci.GUIDS.AMT, { noPipeline: 1 });
this.getCommand = function (chunk) {
var command = chunk.length == 0 ? (this._amt.rq.peekQueue().cmd | 0x800000) : chunk.readUInt32LE(4);
var ret = { IsResponse: (command & 0x800000) == 0x800000 ? true : false, Command: (command & 0x7FFFFF), Status: chunk.length != 0 ? chunk.readUInt32LE(12) : -1, Data: chunk.length != 0 ? chunk.slice(16) : null };
return (ret);
};
this.sendCommand = function () {
if (arguments.length < 3 || typeof (arguments[0]) != 'number' || typeof (arguments[1]) != 'object' || typeof (arguments[2]) != 'function') { throw ('invalid parameters'); }
var args = [];
for (var i = 3; i < arguments.length; ++i) { args.push(arguments[i]); }
this._amt.rq.enQueue({ cmd: arguments[0], func: arguments[2], optional: args });
var header = Buffer.from('010100000000000000000000', 'hex');
header.writeUInt32LE(arguments[0] | 0x04000000, 4);
header.writeUInt32LE(arguments[1] == null ? 0 : arguments[1].length, 8);
this._amt.write(arguments[1] == null ? header : Buffer.concat([header, arguments[1]]));
}
this.getVersion = function (callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(26, null, function (header, fn, opt) {
if (header.Status == 0) {
var i, CodeVersion = header.Data, val = { BiosVersion: CodeVersion.slice(0, this._amt.BiosVersionLen), Versions: [] }, v = CodeVersion.slice(this._amt.BiosVersionLen + 4);
for (i = 0; i < CodeVersion.readUInt32LE(this._amt.BiosVersionLen) ; ++i) {
val.Versions[i] = { Description: v.slice(2, v.readUInt16LE(0) + 2).toString(), Version: v.slice(4 + this._amt.UnicodeStringLen, 4 + this._amt.UnicodeStringLen + v.readUInt16LE(2 + this._amt.UnicodeStringLen)).toString() };
v = v.slice(4 + (2 * this._amt.UnicodeStringLen));
}
opt.unshift(val);
} else {
opt.unshift(null);
}
fn.apply(this, opt);
}, callback, optional);
};
this.getProvisioningState = function (callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(17, null, function (header, fn, opt) {
if (header.Status == 0) {
var result = {};
result.state = header.Data.readUInt32LE(0);
if (result.state < 3) { result.stateStr = ["PRE", "IN", "POST"][result.state]; }
opt.unshift(result);
} else {
opt.unshift(null);
}
fn.apply(this, opt);
}, callback, optional);
};
this.getProvisioningMode = function (callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(8, null, function (header, fn, opt) {
if (header.Status == 0) {
var result = {};
result.mode = header.Data.readUInt32LE(0);
if (result.mode < 4) { result.modeStr = ["NONE", "ENTERPRISE", "SMALL_BUSINESS", "REMOTE_ASSISTANCE"][result.mode]; }
result.legacy = header.Data.readUInt32LE(4) == 0 ? false : true;
opt.unshift(result);
} else {
opt.unshift(null);
}
fn.apply(this, opt);
}, callback, optional);
};
this.getEHBCState = function (callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(132, null, function (header, fn, opt) {
if (header.Status == 0) {
opt.unshift({ EHBC: header.Data.readUInt32LE(0) != 0 });
} else {
opt.unshift(null);
}
fn.apply(this, opt);
}, callback, optional);
};
this.getControlMode = function (callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(107, null, function (header, fn, opt) {
if (header.Status == 0) {
var result = {};
result.controlMode = header.Data.readUInt32LE(0);
if (result.controlMode < 3) { result.controlModeStr = ["NONE_RPAT", "CLIENT", "ADMIN", "REMOTE_ASSISTANCE"][result.controlMode]; }
opt.unshift(result);
} else {
opt.unshift(null);
}
fn.apply(this, opt);
}, callback, optional);
};
this.getMACAddresses = function (callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(37, null, function (header, fn, opt) {
if (header.Status == 0) {
opt.unshift({ DedicatedMAC: header.Data.slice(0, 6).toString('hex:'), HostMAC: header.Data.slice(6, 12).toString('hex:') });
} else { opt.unshift({ DedicatedMAC: null, HostMAC: null }); }
fn.apply(this, opt);
}, callback, optional);
};
this.getDnsSuffix = function (callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(54, null, function (header, fn, opt) {
if (header.Status == 0) {
var resultLen = header.Data.readUInt16LE(0);
if (resultLen > 0) { opt.unshift(header.Data.slice(2, 2 + resultLen).toString()); } else { opt.unshift(null); }
} else {
opt.unshift(null);
}
fn.apply(this, opt);
}, callback, optional);
};
this.getHashHandles = function (callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(0x2C, null, function (header, fn, opt) {
var result = [];
if (header.Status == 0) {
var resultLen = header.Data.readUInt32LE(0);
for (var i = 0; i < resultLen; ++i) {
result.push(header.Data.readUInt32LE(4 + (4 * i)));
}
}
opt.unshift(result);
fn.apply(this, opt);
}, callback, optional);
};
this.getCertHashEntry = function (handle, callback) {
var optional = [];
for (var i = 2; i < arguments.length; ++i) { optional.push(arguments[i]); }
var data = new Buffer(4);
data.writeUInt32LE(handle, 0);
this.sendCommand(0x2D, data, function (header, fn, opt) {
if (header.Status == 0) {
var result = {};
result.isDefault = header.Data.readUInt32LE(0);
result.isActive = header.Data.readUInt32LE(4);
result.hashAlgorithm = header.Data.readUInt8(72);
if (result.hashAlgorithm < 4) {
result.hashAlgorithmStr = ["MD5", "SHA1", "SHA256", "SHA512"][result.hashAlgorithm];
result.hashAlgorithmSize = [16, 20, 32, 64][result.hashAlgorithm];
result.certificateHash = header.Data.slice(8, 8 + result.hashAlgorithmSize).toString('hex');
}
result.name = header.Data.slice(73 + 2, 73 + 2 + header.Data.readUInt16LE(73)).toString();
opt.unshift(result);
} else {
opt.unshift(null);
}
fn.apply(this, opt);
}, callback, optional);
};
this.getCertHashEntries = function (callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.getHashHandles(function (handles, fn, opt) {
var entries = [];
this.getCertHashEntry(handles.shift(), this._getHashEntrySink, fn, opt, entries, handles);
}, callback, optional);
};
this._getHashEntrySink = function (result, fn, opt, entries, handles) {
entries.push(result);
if (handles.length > 0) {
this.getCertHashEntry(handles.shift(), this._getHashEntrySink, fn, opt, entries, handles);
} else {
opt.unshift(entries);
fn.apply(this, opt);
}
}
this.getLocalSystemAccount = function (callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(103, Buffer.alloc(40), function (header, fn, opt) {
if (header.Data.length == 68) { opt.unshift({ user: header.Data.slice(0, 34).toString(), pass: header.Data.slice(34, 67).toString(), raw: header.Data }); } else { opt.unshift(null); }
fn.apply(this, opt);
}, callback, optional);
}
this.unprovision = function (mode, callback) {
var optional = [];
for (var i = 2; i < arguments.length; ++i) { optional.push(arguments[i]); }
var data = new Buffer(4);
data.writeUInt32LE(mode, 0);
this.sendCommand(16, data, function (header, fn, opt) {
opt.unshift(header.Status);
fn.apply(this, opt);
}, callback, optional);
}
this.startConfiguration = function () {
var optional = [];
for (var i = 2; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(0x29, data, function (header, fn, opt) { opt.unshift(header.Status); fn.apply(this, opt); }, callback, optional);
}
this.stopConfiguration = function () {
var optional = [];
for (var i = 2; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(0x5E, data, function (header, fn, opt) { opt.unshift(header.Status); fn.apply(this, opt); }, callback, optional);
}
this.openUserInitiatedConnection = function () {
var optional = [];
for (var i = 2; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(0x44, data, function (header, fn, opt) { opt.unshift(header.Status); fn.apply(this, opt); }, callback, optional);
}
this.closeUserInitiatedConnection = function () {
var optional = [];
for (var i = 2; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(0x45, data, function (header, fn, opt) { opt.unshift(header.Status); fn.apply(this, opt); }, callback, optional);
}
this.getRemoteAccessConnectionStatus = function () {
var optional = [];
for (var i = 2; i < arguments.length; ++i) { optional.push(arguments[i]); }
this.sendCommand(0x46, data, function (header, fn, opt) {
if (header.Status == 0) {
var hostname = v.slice(14, header.Data.readUInt16LE(12) + 14).toString()
opt.unshift({ status: header.Status, networkStatus: header.Data.readUInt32LE(0), remoteAccessStatus: header.Data.readUInt32LE(4), remoteAccessTrigger: header.Data.readUInt32LE(8), mpsHostname: hostname, raw: header.Data });
} else {
opt.unshift({ status: header.Status });
}
fn.apply(this, opt);
}, callback, optional);
}
this.getProtocolVersion = function (callback) {
var optional = [];
for (var i = 1; i < arguments.length; ++i) { opt.push(arguments[i]); }
heci.doIoctl(heci.IOCTL.HECI_VERSION, Buffer.alloc(5), Buffer.alloc(5), function (status, buffer, self, fn, opt) {
if (status == 0) {
var result = buffer.readUInt8(0).toString() + '.' + buffer.readUInt8(1).toString() + '.' + buffer.readUInt8(2).toString() + '.' + buffer.readUInt16BE(3).toString();
opt.unshift(result);
fn.apply(self, opt);
}
else {
opt.unshift(null);
fn.apply(self, opt);
}
}, this, callback, optional);
}
}
module.exports = amt_heci;

View File

@@ -1,61 +0,0 @@
var amt_heci = require('amt_heci');
var amt = new amt_heci();
amt.getProtocolVersion(function (result)
{
console.log('protocol version = ' + result);
});
amt.on('error', function (e) { console.log(e);});
amt.on('connect', function()
{
console.log("Connected!");
this.getVersion(OnVersion);
this.getProvisioningState(OnProvisioningState);
this.getProvisioningMode(OnProvisioningMode);
this.getEHBCState(OnEHBC);
this.getControlMode(OnEHBC);
this.getMACAddresses(OnEHBC);
this.getDnsSuffix(OnDns);
this.getCertHashEntries(OnHashEntries);
//this.getHashHandles(OnGetHashHandles);
});
function OnGetHashHandles(handles)
{
console.log(handles.length + " HashHandles");
for (var i = 0; i < handles.length; ++i)
{
amt.getCertHashEntry(handles[i], OnEHBC);
}
}
function OnHashEntries(entries)
{
for(var i=0;i<entries.length;++i)
{
console.log(entries[i]);
}
}
function OnDns(dns)
{
console.log("Dns Suffix = " + dns);
}
function OnVersion(val)
{
console.log("Bios Version = " + val.BiosVersion.toString());
for(var version in val.Versions)
{
console.log(" " + val.Versions[version].Description + " = " + val.Versions[version].Version);
}
}
function OnProvisioningState(state)
{
console.log("ProvisioningState = " + state);
}
function OnProvisioningMode(result)
{
console.log("ProvisioningMode = " + result.mode + " [Legacy = " + result.legacy + "]");
}
function OnEHBC(result)
{
console.log(result);
}

View File

@@ -1,88 +0,0 @@
var dgram = require('dgram');
var os = require('os');
var interfaces = os.networkInterfaces();
var broadcastSockets = {};
var multicastSockets = {};
var httpHeaders = require('http-headers');
for (var adapter in interfaces)
{
if (interfaces.hasOwnProperty(adapter))
{
for (var i = 0 ; i < interfaces[adapter].length; ++i)
{
var addr = interfaces[adapter][i];
multicastSockets[i] = dgram.createSocket({ type: (addr.family == "IPv4" ? "udp4" : "udp6") });
//multicastSockets[i].bind({ address: addr.address, port:1900, exclusive:false});
multicastSockets[i].bind({ address: addr.address, exclusive: false });
if(addr.family == "IPv4")
{
//multicastSockets[i].addMembership("239.255.255.250");
//multicastSockets[i].setMulticastLoopback(true);
multicastSockets[i].once('message', OnMulticastMessage);
multicastSockets[i].send("M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nST: upnp:rootdevice\r\nMAN: \"ssdp:discover\"\r\nMX: 4\r\nContent-Length: 0\r\n\r\n", 1900, "239.255.255.250");
}
}
}
}
function OnMulticastMessage(msg, rinfo)
{
console.log("Received " + rinfo.size + " bytes from " + rinfo.address + ":" + rinfo.port);
var packet = httpHeaders(msg);
if (packet.hasOwnProperty('statusCode'))
{
console.log("Status (" + packet.statusCode + ") " + packet.statusMessage);
}
else
{
console.log(packet.method + " " + packet.url);
}
for (var header in packet.headers) {
console.log(" " + header + ":" + packet.headers[header]);
}
}
function SendWakeOnLan()
{
var magic = new Buffer(102);
for (var x = 0; x < 6; ++x)
{
magic[x] = 0xFF;
}
for (var x = 1; x <= 16; ++x) {
magic[(x * 6)] = 0xB8;
magic[(x * 6) + 1] = 0xAE;
magic[(x * 6) + 2] = 0xED;
magic[(x * 6) + 3] = 0x74;
magic[(x * 6) + 4] = 0xAB;
magic[(x * 6) + 5] = 0xC3;
}
for (var adapter in interfaces) {
if (interfaces.hasOwnProperty(adapter)) {
console.log(adapter + " => ");
for (var i = 0 ; i < interfaces[adapter].length; ++i) {
var addr = interfaces[adapter][i];
console.log(" " + addr.family + " => " + addr.address + " [" + addr.mac + "]");
if (addr.hasOwnProperty('netmask')) { console.log(" Netmask = " + addr.netmask); }
broadcastSockets[i] = dgram.createSocket({ type: (addr.family == "IPv4" ? "udp4" : "udp6") });
broadcastSockets[i].bind({ address: addr.address });
broadcastSockets[i].setBroadcast(true);
if (addr.family == "IPv4") {
broadcastSockets[i].send(magic, 7, "255.255.255.255");
}
}
}
}
}

View File

@@ -1,104 +0,0 @@
var fs = require('fs');
var exe;
var js;
var sz = new Buffer(8);
var exeLen = 0;
var i;
var dependency = [];
var addOn = null;
for (i = 1; i < process.argv.length; ++i)
{
if(process.argv[i].startsWith('-i'))
{
try
{
dependency.push({ name:process.argv[i].slice(2,process.argv[i].indexOf('.js')), base64: fs.readFileSync(process.argv[i].slice(2)).toString('base64') });
process._argv.splice(i, 1);
i = 0;
}
catch(e)
{
console.log(e);
process.exit();
}
}
}
if (dependency.length > 0)
{
console.log("\nIntegrating Dependencies:")
addOn = "";
for(i=0;i<dependency.length;++i)
{
addOn += ("addModule('" + dependency[i].name + "', Buffer.from('" + dependency[i].base64 + "', 'base64'));\n");
console.log(" " + dependency[i].name);
}
console.log("");
}
if (process.argv0.endsWith('.js'))
{
console.log("Non-integrated executable");
if (process.argv.length < 4)
{
console.log("Too few parameters!");
process.exit();
}
console.log("Executable Path: " + process.argv[1]);
console.log("JavaScript Path: " + process.argv[3]);
exe = fs.readFileSync(process.argv[1]);
w = fs.createWriteStream(process.argv[2], { flags: "wb" });
js = fs.readFileSync(process.argv[3]);
}
else
{
console.log("Integrated executable");
if (process.argv.length < 3)
{
console.log("Too few parameters!");
process.exit();
}
console.log("Executable Path: " + process.argv[0]);
console.log("JavaScript Path: " + process.argv[2]);
exe = fs.readFileSync(process.argv[0]);
w = fs.createWriteStream(process.argv[1], { flags: "wb" });
js = fs.readFileSync(process.argv[2]);
}
if (exe.readInt32BE(exe.length - 4) == exe.length)
{
console.log("Integrated JavaScript detected");
exeLen = exe.length - exe.readInt32BE(exe.length - 8) - 8;
console.log("Original Binary Size (Removed Integrated JavaScript): " + exeLen);
}
else
{
console.log("No integrated JavaScript detected");
exeLen = exe.length;
console.log("Original Binary Size: " + exeLen);
}
if (addOn != null) { js = Buffer.concat([Buffer.from(addOn), js]); }
console.log("JavaScript Length: " + js.length);
w.write(exe.slice(0, exeLen), OnWroteExe);
function OnWroteExe()
{
this.write(js, function () {
sz.writeInt32BE(js.length, 0);
sz.writeInt32BE(exeLen + js.length + 8, 4);
this.write(sz, function () {
this.end();
console.log("Finished!");
process.exit();
});
});
}

View File

@@ -1,36 +0,0 @@
var heci = require('heci');
var amt = null;
console.log("Starting HECI test...");
console.log("LME GUID = " + heci.GUIDS.LME.toString('hex'));
console.log("AMT GUID = " + heci.GUIDS.AMT.toString('hex'));
heci.doIoctl(heci.IOCTL.HECI_VERSION, null, new Buffer(16), OnVersion);
function OnVersion(status, buffer, arg)
{
if(status == 0)
{
console.log("HECI Driver Version = " + buffer[0] + "." + buffer[1]);
console.log("Attempting to create AMT/HECI connection");
amt = heci.create();
amt.connect(heci.GUIDS.AMT);
amt.on('connect', OnAMT);
amt.on('error', function (e) { console.log(e); });
}
else {
console.log("Could not determine HECI Driver Version");
}
}
function OnAMT()
{
console.log('AMT Connected');
amt.on('data', OnAMTData);
var header = Buffer.from('010100001A00000400000000', 'hex');
amt.write(header);
}
function OnAMTData(chunk)
{
console.log('Received ' + chunk.length + ' bytes of AMT Data');
}

View File

@@ -1,58 +0,0 @@
var http = require('http');
var https = require('https');
var WS;
console.log("Starting HTTP (Rewrite) Test");
console.displayStreamPipeMessages = 1;
console.displayFinalizerMessages = 1;
var cert = require('tls').generateCertificate('test');
var server = https.createServer({ pfx: cert, passphrase: 'test' });
server.on('request', function (imsg, rsp)
{
console.log('Received inbound request: ' + imsg.method + ' ' + imsg.url);
rsp.writeHead(200, 'OK', {'Content-Length': 0});
});
server.on('upgrade', function (imsg, sck, head)
{
console.log('Server On Upgrade');
WS = sck.upgradeWebSocket();
WS.on('pong', function () { console.log('Server received PONG'); WS.write('this is test'); WS.write(Buffer.from("This is a good day.. Bye!")); WS.end();});
WS.on('data', function (chunk) { console.log('Server received: ' + chunk); });
WS.on('end', function () { console.log('Server WS ended'); WS = null; });
WS.ping();
});
server.listen({ port: 9095 });
//var req = http.get("http://127.0.0.1:9095/test.html");
//var req = http.get("ws://127.0.0.1:9095/test.html");
var req = http.request({ protocol: 'wss:', host: '127.0.0.1', port: 9095, method: 'GET', path: '/test.html', rejectUnauthorized: false})
req.end();
//var req2 = http.request({ protocol: 'https:', host: '127.0.0.1', port: 9095, method: 'GET', path: '/test.html', rejectUnauthorized: false })
//req2.end();
req.on('upgrade', function (imsg, sck, head)
{
console.log('client upgraded to WebSocket');
sck.on('ping', function () { console.log('Client received ping'); this.write('Client says hello');});
sck.on('data', function (chunk) { console.log('client received: ' + chunk, typeof (chunk)); });
sck.on('end', function () { console.log('Client side closed'); console.logReferenceCount(req); req = null; _debugGC(); });
});
req.on('response', function (imsg)
{
console.log('received response', imsg.statusCode, imsg.statusMessage);
imsg.on('end', function () {
console.log('Done reading IncomingMessageStream');
});
})
req.on('error', function (err) { console.log('error received', err); });
//req2.on('response', function (imsg) {
// console.log('received response', imsg.statusCode, imsg.statusMessage);
// imsg.on('end', function () {
// console.log('Done reading IncomingMessageStream');
// });
//})
//req2.on('error', function (err) { console.log('error received', err); });

View File

@@ -1,38 +0,0 @@
var manager = require('ILibProcessPipe');
var child = manager.CreateProcess("/sbin/iwlist", "iwlist", "wlan0", "scan");
var MemoryStream = require('MemoryStream');
var ms = new MemoryStream();
ms.on('end', function ()
{
var str = this.buffer.toString();
tokens = str.split(' - Address: ');
for (var block in tokens)
{
var ln = tokens[block].split('\n');
console.log("MAC Address = " + ln[0]);
for(var lnblock in ln)
{
lnblock = ln[lnblock].trim();
lnblock = lnblock.trim();
if(lnblock.startsWith('ESSID:'))
{
console.log("SSID = " + lnblock.slice(6));
}
if(lnblock.startsWith('Signal level='))
{
console.log("Signal Strength = " + lnblock.slice(13));
}
}
console.log("");
}
});
console.log("starting...");
child.on('data', function (buffer) { ms.write(buffer); });
child.on('end', function () { ms.end(); });
//child.write("iwlist wlan0 scan\n");

View File

@@ -1,355 +0,0 @@
var MemoryStream = require('MemoryStream');
var lme_id = 0;
var APF_DISCONNECT = 1;
var APF_SERVICE_REQUEST = 5;
var APF_SERVICE_ACCEPT = 6;
var APF_USERAUTH_REQUEST = 50;
var APF_USERAUTH_FAILURE = 51;
var APF_USERAUTH_SUCCESS = 52;
var APF_GLOBAL_REQUEST = 80;
var APF_REQUEST_SUCCESS = 81;
var APF_REQUEST_FAILURE = 82;
var APF_CHANNEL_OPEN = 90;
var APF_CHANNEL_OPEN_CONFIRMATION = 91;
var APF_CHANNEL_OPEN_FAILURE = 92;
var APF_CHANNEL_WINDOW_ADJUST = 93;
var APF_CHANNEL_DATA = 94;
var APF_CHANNEL_CLOSE = 97;
var APF_PROTOCOLVERSION = 192;
function lme_object()
{
this.ourId = ++lme_id;
this.amtId = -1;
this.LME_CHANNEL_STATUS = 'LME_CS_FREE';
this.txWindow = 0;
this.rxWindow = 0;
this.localPort = 0;
this.errorCount = 0;
}
function stream_bufferedWrite()
{
var emitterUtils = require('events').inherits(this);
this.buffer = [];
this._readCheckImmediate = undefined;
// Writable Events
emitterUtils.createEvent('close');
emitterUtils.createEvent('drain');
emitterUtils.createEvent('error');
emitterUtils.createEvent('finish');
emitterUtils.createEvent('pipe');
emitterUtils.createEvent('unpipe');
// Readable Events
emitterUtils.createEvent('readable');
this.isEmpty = function ()
{
return (this.buffer.length == 0);
};
this.isWaiting = function ()
{
return (this._readCheckImmediate == undefined);
};
this.write = function (chunk)
{
for (var args in arguments)
{
if (typeof (arguments[args]) == 'function') { this.once('drain', arguments[args]); break; }
}
var tmp = Buffer.alloc(chunk.length);
chunk.copy(tmp);
this.buffer.push({ offset: 0, data: tmp });
this.emit('readable');
return (this.buffer.length == 0 ? true : false);
};
this.read = function ()
{
var size = arguments.length == 0 ? undefined : arguments[0];
var bytesRead = 0;
var list = [];
while((size == undefined || bytesRead < size) && this.buffer.length > 0)
{
var len = this.buffer[0].data.length - this.buffer[0].offset;
var offset = this.buffer[0].offset;
if(len > (size - bytesRead))
{
// Only reading a subset
list.push(this.buffer[0].data.slice(offset, offset + size - bytesRead));
this.buffer[0].offset += (size - bytesRead);
bytesRead += (size - bytesRead);
}
else
{
// Reading the entire thing
list.push(this.buffer[0].data.slice(offset));
bytesRead += len;
this.buffer.shift();
}
}
this._readCheckImmediate = setImmediate(function (buffered)
{
buffered._readCheckImmediate = undefined;
if(buffered.buffer.length == 0)
{
// drained
buffered.emit('drain');
}
else
{
// not drained
buffered.emit('readable');
}
}, this);
return (Buffer.concat(list));
};
}
function lme_heci()
{
var emitterUtils = require('events').inherits(this);
emitterUtils.createEvent('error');
emitterUtils.createEvent('connect');
var heci = require('heci');
this.INITIAL_RXWINDOW_SIZE = 4096;
this._LME = heci.create();
this._LME.LMS = this;
this._LME.on('error', function (e) { this.Parent.emit('error', e); });
this._LME.on('connect', function ()
{
console.log('emitting connect');
this.LMS.emit('connect');
this.on('data', function (chunk)
{
// this = HECI
var cmd = chunk.readUInt8(0);
switch(cmd)
{
default:
//console.log('Received ' + chunk.length + ' bytes of data for LMS');
//console.log('Command = ' + cmd);
break;
case APF_SERVICE_REQUEST:
var nameLen = chunk.readUInt32BE(1);
var name = chunk.slice(5, nameLen + 5);
//console.log("Service Request for: " + name);
if (name == 'pfwd@amt.intel.com' || name == 'auth@amt.intel.com')
{
var outBuffer = Buffer.alloc(5 + nameLen);
outBuffer.writeUInt8(6, 0);
outBuffer.writeUInt32BE(nameLen, 1);
outBuffer.write(name.toString(), 5);
this.write(outBuffer);
//console.log('Answering APF_SERVICE_REQUEST');
}
else
{
//console.log('UNKNOWN APF_SERVICE_REQUEST');
}
break;
case APF_GLOBAL_REQUEST:
var nameLen = chunk.readUInt32BE(1);
var name = chunk.slice(5, nameLen + 5).toString();
switch(name)
{
case 'tcpip-forward':
var len = chunk.readUInt32BE(nameLen + 6);
var port = chunk.readUInt32BE(nameLen + 10 + len);
//console.log("[" + chunk.length + "/" + len + "] APF_GLOBAL_REQUEST for: " + name + " on port " + port);
if (this[name] == undefined)
{
this[name] = {};
}
this[name][port] = require('net').createServer();
this[name][port].HECI = this;
this[name][port].listen({ port: port });
this[name][port].on('connection', function (socket)
{
//console.log('New [' + socket.remoteFamily + '] TCP Connection on: ' + socket.remoteAddress + ' :' + socket.localPort);
this.HECI.LMS.bindDuplexStream(socket, socket.remoteFamily, socket.localPort);
});
var outBuffer = Buffer.alloc(5);
outBuffer.writeUInt8(81, 0);
outBuffer.writeUInt32BE(port, 1);
this.write(outBuffer);
break;
case 'cancel-tcpip-forward':
break;
case 'udp-send-to@amt.intel.com':
break;
default:
//console.log("Unknown APF_GLOBAL_REQUEST for: " + name);
break;
}
break;
case APF_CHANNEL_OPEN_CONFIRMATION:
var rChannel = chunk.readUInt32BE(1);
var sChannel = chunk.readUInt32BE(5);
var wSize = chunk.readUInt32BE(9);
//console.log('rChannel/' + rChannel + ', sChannel/' + sChannel + ', wSize/' + wSize);
if (this.sockets[rChannel] != undefined)
{
this.sockets[rChannel].lme.amtId = sChannel;
this.sockets[rChannel].lme.rxWindow = wSize;
this.sockets[rChannel].lme.txWindow = wSize;
this.sockets[rChannel].lme.LME_CHANNEL_STATUS = 'LME_CS_CONNECTED';
//console.log('LME_CS_CONNECTED');
this.sockets[rChannel].bufferedStream = new stream_bufferedWrite();
this.sockets[rChannel].bufferedStream.socket = this.sockets[rChannel];
this.sockets[rChannel].bufferedStream.on('readable', function ()
{
if(this.socket.lme.txWindow > 0)
{
var buffer = this.read(this.socket.lme.txWindow);
var packet = Buffer.alloc(9 + buffer.length);
packet.writeUInt8(APF_CHANNEL_DATA, 0);
packet.writeUInt32BE(this.socket.lme.amtId, 1);
packet.writeUInt32BE(buffer.length, 5);
buffer.copy(packet, 9);
this.socket.lme.txWindow -= buffer.length;
this.socket.HECI.write(packet);
}
});
this.sockets[rChannel].bufferedStream.on('drain', function ()
{
this.socket.resume();
});
this.sockets[rChannel].on('data', function (chunk)
{
if (!this.bufferedStream.write(chunk)) { this.pause(); }
});
this.sockets[rChannel].on('end', function ()
{
var outBuffer = Buffer.alloc(5);
outBuffer.writeUInt8(APF_CHANNEL_CLOSE, 0);
outBuffer.writeUInt32BE(this.lme.amtId, 1);
this.HECI.write(outBuffer);
});
this.sockets[rChannel].resume();
}
break;
case APF_PROTOCOLVERSION:
var major = chunk.readUInt32BE(1);
var minor = chunk.readUInt32BE(5);
var reason = chunk.readUInt32BE(9);
var outBuffer = Buffer.alloc(93);
outBuffer.writeUInt8(192, 0);
outBuffer.writeUInt32BE(1, 1);
outBuffer.writeUInt32BE(0, 5);
outBuffer.writeUInt32BE(reason, 9);
//console.log('Answering PROTOCOL_VERSION');
this.write(outBuffer);
break;
case APF_CHANNEL_WINDOW_ADJUST:
var rChannelId = chunk.readUInt32BE(1);
var bytesToAdd = chunk.readUInt32BE(5);
if (this.sockets[rChannelId] != undefined)
{
this.sockets[rChannelId].lme.txWindow += bytesToAdd;
if (!this.sockets[rChannelId].bufferedStream.isEmpty() && this.sockets[rChannelId].bufferedStream.isWaiting())
{
this.sockets[rChannelId].bufferedStream.emit('readable');
}
}
else
{
//console.log('Unknown Recipient ID/' + rChannelId + ' for APF_CHANNEL_WINDOW_ADJUST');
}
break;
case APF_CHANNEL_DATA:
var rChannelId = chunk.readUInt32BE(1);
var dataLen = chunk.readUInt32BE(5);
var data = chunk.slice(9, 9 + dataLen);
if (this.sockets[rChannelId] != undefined)
{
this.sockets[rChannelId].pendingBytes.push(data.length);
this.sockets[rChannelId].write(data, function ()
{
var written = this.pendingBytes.shift();
var outBuffer = Buffer.alloc(9);
outBuffer.writeUInt8(APF_CHANNEL_WINDOW_ADJUST, 0);
outBuffer.writeUInt32BE(this.lme.amtId, 1);
outBuffer.writeUInt32BE(written, 5);
this.HECI.write(outBuffer);
});
}
else
{
//console.log('Unknown Recipient ID/' + rChannelId + ' for APF_CHANNEL_DATA');
}
break;
case APF_CHANNEL_CLOSE:
var rChannelId = chunk.readUInt32BE(1);
if (this.sockets[rChannelId] != undefined)
{
this.sockets[rChannelId].end();
var amtId = this.sockets[rChannelId].lme.amtId;
var buffer = Buffer.alloc(5);
delete this.sockets[rChannelId];
buffer.writeUInt8(APF_CHANNEL_CLOSE, 0);
buffer.writeUInt32BE(amtId, 1);
this.write(buffer);
}
else
{
//console.log('Unknown Recipient ID/' + rChannelId + ' for APF_CHANNEL_CLOSE');
}
break;
}
});
});
this.bindDuplexStream = function (duplexStream, remoteFamily, localPort)
{
var socket = duplexStream;
//console.log('New [' + remoteFamily + '] Virtual Connection/' + socket.localPort);
socket.pendingBytes = [];
socket.HECI = this._LME;
socket.LMS = this;
socket.lme = new lme_object();
socket.lme.Socket = socket;
var buffer = new MemoryStream();
buffer.writeUInt8(0x5A);
buffer.writeUInt32BE(15);
buffer.write('forwarded-tcpip');
buffer.writeUInt32BE(socket.lme.ourId);
buffer.writeUInt32BE(this.INITIAL_RXWINDOW_SIZE);
buffer.writeUInt32BE(0xFFFFFFFF);
for (var i = 0; i < 2; ++i)
{
if (remoteFamily == 'IPv6')
{
buffer.writeUInt32BE(3);
buffer.write('::1');
}
else
{
buffer.writeUInt32BE(9);
buffer.write('127.0.0.1');
}
buffer.writeUInt32BE(localPort);
}
this._LME.write(buffer.buffer);
if (this._LME.sockets == undefined) { this._LME.sockets = {}; }
this._LME.sockets[socket.lme.ourId] = socket;
socket.pause();
};
this._LME.connect(heci.GUIDS.LME, { noPipeline: 0 });
}
module.exports = lme_heci;

File diff suppressed because one or more lines are too long

View File

@@ -1,18 +0,0 @@
var http = require('http');
console.log('starting client test');
console.log('Sending Request');
var req = http.request({host: '127.0.0.1', port: 9093, protocol: 'ws:'});
req.on('upgrade', function (res, sk, h)
{
sk.on('ping', function () { console.log('received ping'); });
sk.on('pong', function () { console.log('received pong'); });
this.websocket = sk;
console.log("Upgraded to WebSocket!"); sk.write(JSON.stringify({ a: 'hello' }));
});
//req.end();

View File

@@ -1,205 +0,0 @@
Object.defineProperty(Array.prototype, "peek",
{
value: function ()
{
return (this.length > 0 ? this[this.length - 1] : undefined);
}
});
function _treeBuilder()
{
this.tree = [];
this.push = function (element)
{
this.tree.push(element);
};
this.pop = function ()
{
var element = this.tree.pop();
if(this.tree.length>0)
{
this.tree.peek().childNodes.push(element);
}
return (element);
};
this.peek = function()
{
return (this.tree.peek());
}
this.addNamespace = function(prefix, namespace)
{
this.tree.peek().nsTable[prefix] = namespace;
if(this.tree.peek().attributes.length > 0)
{
for(var i = 0; i<this.tree.peek().attributes; ++i)
{
var a = this.tree.peek().attributes[i];
if(prefix == '*' && a.name == a.localName)
{
a.namespace = namespace;
}
else if(prefix != '*' && a.name != a.localName)
{
var pfx = a.name.split(':')[0];
if(pfx == prefix)
{
a.namespace = namespace;
}
}
}
}
}
this.getNamespace = function(prefix)
{
for(var i=this.tree.length-1;i>=0;--i)
{
if(this.tree[i].nsTable[prefix] != undefined)
{
return (this.tree[i].nsTable[prefix]);
}
}
return ('undefined');
}
}
// This is a drop-in replacement to _turnToXml() that works without xml parser dependency.
function _turnToXml(text)
{
if (text == null) return null;
return ({ childNodes: [_turnToXmlRec(text)], getElementsByTagName: _getElementsByTagName, getChildElementsByTagName: _getChildElementsByTagName, getElementsByTagNameNS: _getElementsByTagNameNS });
}
function _getElementsByTagNameNS(ns, name)
{
var ret = []; _xmlTraverseAllRec(this.childNodes, function (node)
{
if (node.localName == name && (node.namespace == ns || ns == '*')) { ret.push(node); }
}); return ret;
}
function _getElementsByTagName(name)
{
var ret = []; _xmlTraverseAllRec(this.childNodes, function (node)
{
if (node.localName == name) { ret.push(node); }
}); return ret;
}
function _getChildElementsByTagName(name)
{
var ret = [];
if (this.childNodes != undefined)
{
for (var node in this.childNodes) {
if (this.childNodes[node].localName == name) { ret.push(this.childNodes[node]); }
}
}
return (ret);
}
function _getChildElementsByTagNameNS(ns, name)
{
var ret = [];
if (this.childNodes != undefined)
{
for (var node in this.childNodes)
{
if (this.childNodes[node].localName == name && (ns == '*' || this.childNodes[node].namespace == ns)) { ret.push(this.childNodes[node]); }
}
}
return (ret);
}
function _xmlTraverseAllRec(nodes, func) { for (var i in nodes) { func(nodes[i]); if (nodes[i].childNodes) { _xmlTraverseAllRec(nodes[i].childNodes, func); } } }
function _turnToXmlRec(text)
{
var elementStack = new _treeBuilder();
var lastElement = null;
var x1 = text.split('<'), ret = [], element = null, currentElementName = null;
for (var i in x1)
{
var x2 = x1[i].split('>'), x3 = x2[0].split(' '), elementName = x3[0];
if ((elementName.length > 0) && (elementName[0] != '?'))
{
if (elementName[0] != '/')
{
var localName;
var localname2 = elementName.split(' ')[0].split(':'), localName = (localname2.length > 1) ? localname2[1] : localname2[0];
var attributes = [];
Object.defineProperty(attributes, "get",
{
value: function ()
{
if (arguments.length == 1)
{
for (var a in this) { if (this[a].name == arguments[0]) { return (this[a]); } }
}
else if (arguments.length == 2)
{
for (var a in this) { if (this[a].name == arguments[1] && (arguments[0] == '*' || this[a].namespace == arguments[0])) { return (this[a]); } }
}
else
{
throw ('attributes.get(): Invalid number of parameters');
}
}
});
elementStack.push({ name: elementName, localName: localName, getChildElementsByTagName: _getChildElementsByTagName, getElementsByTagNameNS: _getElementsByTagNameNS, getChildElementsByTagNameNS: _getChildElementsByTagNameNS, attributes: attributes, childNodes: [], nsTable: {} });
// Parse Attributes
if (x3.length > 0)
{
var skip = false;
for (var j in x3)
{
if (x3[j] == '/')
{
// This is an empty Element
elementStack.peek().namespace = elementStack.peek().name == elementStack.peek().localName ? elementStack.getNamespace('*') : elementStack.getNamespace(elementStack.peek().name.substring(0, elementStack.peek().name.indexOf(':')));
elementStack.peek().textContent = '';
lastElement = elementStack.pop();
skip = true;
break;
}
var k = x3[j].indexOf('=');
if (k > 0)
{
var attrName = x3[j].substring(0, k);
var attrValue = x3[j].substring(k + 2, x3[j].length - 1);
var attrNS = elementStack.getNamespace('*');
if (attrName == 'xmlns')
{
elementStack.addNamespace('*', attrValue);
attrNS = attrValue;
}
else if (attrName.startsWith('xmlns:'))
{
elementStack.addNamespace(attrName.substring(6), attrValue);
}
else
{
var ax = attrName.split(':');
if (ax.length == 2) { attrName = ax[1]; attrNS = elementStack.getNamespace(ax[0]); }
}
elementStack.peek().attributes.push({ name: attrName, value: attrValue, namespace: attrNS });
}
}
if (skip) { continue; }
}
elementStack.peek().namespace = elementStack.peek().name == elementStack.peek().localName ? elementStack.getNamespace('*') : elementStack.getNamespace(elementStack.peek().name.substring(0, elementStack.peek().name.indexOf(':')));
if (x2[1]) { elementStack.peek().textContent = x2[1]; }
}
else
{
lastElement = elementStack.pop();
}
}
}
return lastElement;
}
module.exports = _turnToXml;

View File

@@ -1,243 +0,0 @@
function parseServiceStatus(token)
{
var j = {};
var serviceType = token.Deref(0, 4).IntVal;
j.isFileSystemDriver = ((serviceType & 0x00000002) == 0x00000002);
j.isKernelDriver = ((serviceType & 0x00000001) == 0x00000001);
j.isSharedProcess = ((serviceType & 0x00000020) == 0x00000020);
j.isOwnProcess = ((serviceType & 0x00000010) == 0x00000010);
j.isInteractive = ((serviceType & 0x00000100) == 0x00000100);
switch (token.Deref((1 * 4), 4).IntVal)
{
case 0x00000005:
j.state = 'CONTINUE_PENDING';
break;
case 0x00000006:
j.state = 'PAUSE_PENDING';
break;
case 0x00000007:
j.state = 'PAUSED';
break;
case 0x00000004:
j.state = 'RUNNING';
break;
case 0x00000002:
j.state = 'START_PENDING';
break;
case 0x00000003:
j.state = 'STOP_PENDING';
break;
case 0x00000001:
j.state = 'STOPPED';
break;
}
var controlsAccepted = token.Deref((2 * 4), 4).IntVal
j.controlsAccepted = [];
if ((controlsAccepted & 0x00000010) == 0x00000010)
{
j.controlsAccepted.push('SERVICE_CONTROL_NETBINDADD');
j.controlsAccepted.push('SERVICE_CONTROL_NETBINDREMOVE');
j.controlsAccepted.push('SERVICE_CONTROL_NETBINDENABLE');
j.controlsAccepted.push('SERVICE_CONTROL_NETBINDDISABLE');
}
if ((controlsAccepted & 0x00000008) == 0x00000008) { j.controlsAccepted.push('SERVICE_CONTROL_PARAMCHANGE'); }
if ((controlsAccepted & 0x00000002) == 0x00000002) { j.controlsAccepted.push('SERVICE_CONTROL_PAUSE'); j.controlsAccepted.push('SERVICE_CONTROL_CONTINUE'); }
if ((controlsAccepted & 0x00000100) == 0x00000100) { j.controlsAccepted.push('SERVICE_CONTROL_PRESHUTDOWN'); }
if ((controlsAccepted & 0x00000004) == 0x00000004) { j.controlsAccepted.push('SERVICE_CONTROL_SHUTDOWN'); }
if ((controlsAccepted & 0x00000001) == 0x00000001) { j.controlsAccepted.push('SERVICE_CONTROL_STOP'); }
if ((controlsAccepted & 0x00000020) == 0x00000020) { j.controlsAccepted.push('SERVICE_CONTROL_HARDWAREPROFILECHANGE'); }
if ((controlsAccepted & 0x00000040) == 0x00000040) { j.controlsAccepted.push('SERVICE_CONTROL_POWEREVENT'); }
if ((controlsAccepted & 0x00000080) == 0x00000080) { j.controlsAccepted.push('SERVICE_CONTROL_SESSIONCHANGE'); }
j.pid = token.Deref((7 * 4), 4).IntVal
return (j);
}
function serviceManager()
{
this.GM = require('_GenericMarshal');
this.proxy = this.GM.CreateNativeProxy('Advapi32.dll');
this.proxy.CreateMethod('OpenSCManagerA');
this.proxy.CreateMethod('EnumServicesStatusExA');
this.proxy.CreateMethod('OpenServiceA');
this.proxy.CreateMethod('QueryServiceStatusEx');
this.proxy.CreateMethod('ControlService');
this.proxy.CreateMethod('StartServiceA');
this.proxy.CreateMethod('CloseServiceHandle');
this.proxy.CreateMethod('CreateServiceA');
this.proxy.CreateMethod('ChangeServiceConfig2A');
this.proxy.CreateMethod('DeleteService');
this.proxy2 = this.GM.CreateNativeProxy('Kernel32.dll');
this.proxy2.CreateMethod('GetLastError');
this.enumerateService = function()
{
var machineName = this.GM.CreatePointer();
var dbName = this.GM.CreatePointer();
var handle = this.proxy.OpenSCManagerA(0x00, 0x00, 0x0001 | 0x0004);
var bytesNeeded = this.GM.CreateVariable(4);
var servicesReturned = this.GM.CreateVariable(4);
var resumeHandle = this.GM.CreateVariable(4);
//var services = this.proxy.CreateVariable(262144);
var success = this.proxy.EnumServicesStatusExA(handle, 0, 0x00000030, 0x00000003, 0x00, 0x00, bytesNeeded, servicesReturned, resumeHandle, 0x00);
if(bytesNeeded.IntVal <= 0)
{
throw ('error enumerating services');
}
var sz = bytesNeeded.IntVal;
var services = this.GM.CreateVariable(sz);
this.proxy.EnumServicesStatusExA(handle, 0, 0x00000030, 0x00000003, services, sz, bytesNeeded, servicesReturned, resumeHandle, 0x00);
console.log("servicesReturned", servicesReturned.IntVal, 'PtrSize = ' + dbName._size);
var ptrSize = dbName._size;
var blockSize = 36 + (2 * ptrSize);
console.log('blockSize', blockSize);
var retVal = [];
for (var i = 0; i < servicesReturned.IntVal; ++i)
{
var token = services.Deref(i * blockSize, blockSize);
var j = {};
j.name = token.Deref(0, ptrSize).Deref().String;
j.displayName = token.Deref(ptrSize, ptrSize).Deref().String;
j.status = parseServiceStatus(token.Deref(2 * ptrSize, 36));
retVal.push(j);
}
this.proxy.CloseServiceHandle(handle);
return (retVal);
}
this.getService = function(name)
{
var serviceName = this.GM.CreateVariable(name);
var ptr = this.GM.CreatePointer();
var bytesNeeded = this.GM.CreateVariable(ptr._size);
var handle = this.proxy.OpenSCManagerA(0x00, 0x00, 0x0001 | 0x0004 | 0x0020 | 0x0010);
if (handle == 0) { throw ('could not open ServiceManager'); }
var h = this.proxy.OpenServiceA(handle, serviceName, 0x0004 | 0x0020 | 0x0010 | 0x00010000);
if (h != 0)
{
var success = this.proxy.QueryServiceStatusEx(h, 0, 0, 0, bytesNeeded);
var status = this.GM.CreateVariable(bytesNeeded.IntVal);
success = this.proxy.QueryServiceStatusEx(h, 0, status, status._size, bytesNeeded);
if (success != 0)
{
retVal = {};
retVal.status = parseServiceStatus(status);
retVal._scm = handle;
retVal._service = h;
retVal._GM = this.GM;
retVal._proxy = this.proxy;
require('events').inherits(retVal);
retVal.on('~', function () { this._proxy.CloseServiceHandle(this); this._proxy.CloseServiceHandle(this._scm); });
retVal.name = name;
retVal.stop = function()
{
if(this.status.state == 'RUNNING')
{
var newstate = this._GM.CreateVariable(36);
var success = this._proxy.ControlService(this._service, 0x00000001, newstate);
if(success == 0)
{
throw (this.name + '.stop() failed');
}
}
else
{
throw ('cannot call ' + this.name + '.stop(), when current state is: ' + this.status.state);
}
}
retVal.start = function()
{
if(this.status.state == 'STOPPED')
{
var success = this._proxy.StartServiceA(this._service, 0, 0);
if(success == 0)
{
throw (this.name + '.start() failed');
}
}
else
{
throw ('cannot call ' + this.name + '.start(), when current state is: ' + this.status.state);
}
}
return (retVal);
}
else
{
}
}
this.proxy.CloseServiceHandle(handle);
throw ('could not find service: ' + name);
}
this.installService = function(options)
{
var handle = this.proxy.OpenSCManagerA(0x00, 0x00, 0x0002);
if (handle == 0) { throw ('error opening SCManager'); }
var serviceName = this.GM.CreateVariable(options.name);
var displayName = this.GM.CreateVariable(options.displayName);
var allAccess = 0x000F01FF;
var serviceType;
var servicePath = this.GM.CreateVariable(options.servicePath);
switch(options.startType)
{
case 'BOOT_START':
serviceType = 0x00;
break;
case 'SYSTEM_START':
serviceType = 0x01;
break;
case 'AUTO_START':
serviceType = 0x02;
break;
case 'DEMAND_START':
serviceType = 0x03;
break;
default:
serviceType = 0x04; // Disabled
break;
}
var h = this.proxy.CreateServiceA(handle, serviceName, displayName, allAccess, 0x10 | 0x100, serviceType, 0, servicePath, 0, 0, 0, 0, 0);
if (h == 0) { this.proxy.CloseServiceHandle(handle); throw ('Error Creating Service'); }
if(options.description)
{
console.log(options.description);
var dscPtr = this.GM.CreatePointer();
dscPtr.Val = this.GM.CreateVariable(options.description);
if(this.proxy.ChangeServiceConfig2A(h, 1, dscPtr)==0)
{
this.proxy.CloseServiceHandle(h);
this.proxy.CloseServiceHandle(handle);
throw ('Unable to set description');
}
}
this.proxy.CloseServiceHandle(h);
this.proxy.CloseServiceHandle(handle);
return (this.getService(options.name));
}
this.uninstallService = function(name)
{
var service = this.getService(name);
if(service.status.state == 'STOPPED')
{
if (this.proxy.DeleteService(service._service) == 0) { throw ('Uninstall Service for: ' + name + ', failed with error: ' + this.proxy2.GetLastError()); }
}
else
{
throw ('Cannot uninstall service: ' + name + ', because it is: ' + service.status.state);
}
}
}
module.exports = serviceManager;

View File

@@ -1,113 +0,0 @@
var proxy;
var i;
var http = require('http');
var net = require('net');
var host = null;
var port = 443;
var id = null;
var req;
var local = 0;
var remoteHost = "";
var remotePort = 0;
process.on("uncaughtException", function (e) { console.log("UncaughtException: " + e); });
process.on("exit", function (code) { console.log("Process Exiting with code: " + code); });
function onWebSocket(response, s, head)
{
console.log("WebSocket connected");
s.data = onWebSocketData;
}
function OnNewConnection(connection)
{
console.log("New Local Connection");
this.parent.pipe(connection);
connection.pipe(this.parent);
}
function OnClientConnection()
{
console.log("New Client Connection Established");
this.parent.pipe(this);
this.pipe(this.parent);
}
function onWebSocketData(buffer)
{
if(buffer == 'c')
{
console.log("tunnel established");
this.pause();
if (local != 0)
{
this.server = net.createServer();
this.server.parent = this;
this.server.on('connection', OnNewConnection);
this.server.listen({ port: local });
}
if(remotePort != 0)
{
this.client = net.createConnection({ port: remotePort, host: remoteHost }, OnClientConnection);
this.client.parent = this;
}
}
}
for (i = 1; i < process.argv.length; ++i)
{
if(process.argv[i] == 'local')
{
console.log("binding local port " + (local = parseInt(process.argv[i + 1])));
++i;
}
else if(process.argv[i] == 'remote')
{
remoteHost = process.argv[i + 1];
remotePort = parseInt(process.argv[i + 2])
console.log("binding remote " + remoteHost + ":" + remotePort);
i += 2;
}
else if(process.argv[i] == 'proxy')
{
console.log("Using Proxy: " + process.argv[i + 1] + ":" + parseInt(process.argv[i + 2]));
proxy = require('global-tunnel');
try
{
proxy.initialize({ host: process.argv[i + 1], port: parseInt(process.argv[i + 2]) });
}
catch(e)
{
console.log("Unable to bind proxy: " + e);
}
i += 2;
}
else if(process.argv[i] == 'relayHost')
{
host = process.argv[i + 1];
++i;
}
else if(process.argv[i] == 'relayId')
{
id = process.argv[i + 1];
++i;
}
else if(process.argv[i] == 'relayPort')
{
port = parseInt(argv[i + 1]);
++i;
}
}
if (host != null && id != null)
{
console.log("using relay: [" + host + ":" + port + "] using id: " + id);
req = http.request({ protocol: "wss:", host: host, port: port, path: "/meshrelay.ashx?id='" + id + "'" });
req.upgrade = onWebSocket;
}

View File

@@ -1,655 +0,0 @@
var parseXml = require('parseXml');
var http = require('http');
var dgram = require('dgram');
var os = require('os');
var MemoryStream = require('MemoryStream');
var net = require('net');
//var networkMonitor = require('NetworkMonitor');
function upnpdevice(descriptionUrl, usn, cp)
{
var d = descriptionUrl.split('/');
this.BaseURL = d[0] + '//' + d[2];
var emitterUtils = require('events').inherits(this);
emitterUtils.createEvent('bye');
emitterUtils.createEvent('error');
emitterUtils.createEvent('alive');
emitterUtils.createEvent('serviceLoaded');
this.pendingServices = 0;
this.usn = usn;
this.cp = cp;
this.req = http.get(descriptionUrl);
this.req.device = this;
this.req.on('error', function ()
{
this.device.emit('error', 'Error fetching Description Document from ' + this.device.BaseURL);
});
this.req.on('response', function (msg)
{
if (msg.statusCode == 200)
{
msg.device = this.device;
this.device.dd = new MemoryStream();
this.device.dd.device = this.device;
msg.pipe(this.device.dd);
this.device.dd.on('end', function ()
{
upnpdevice_parseXml.apply(this.device, [this.buffer.toString()]);
});
}
else
{
this.device.emit('error', 'Error (' + msg.statusCode + ') Fetching Description Document from: ' + this.device.BaseURL);
}
});
this.loadAllServices = function () { this.rootDevice.loadAllServices(); };
this.makeUrl = function (url)
{
if(url.startsWith('/'))
{
if (this.BaseURL.endsWith('/'))
{
return (this.BaseURL + url.substring(1));
}
else
{
return (this.BaseURL + url);
}
}
else
{
if (this.BaseURL.endsWith('/'))
{
return (this.BaseURL + url);
}
else
{
return (this.BaseURL + '/' + url);
}
}
};
this.on('~', upnpdevice_Cleanup);
this.on('serviceLoaded', function (svc)
{
if(--this.pendingServices == 0)
{
// All Services have been loaded
this.cp.emit('device', this);
}
});
this.getDevice = function (udn)
{
return (this.rootDevice.getDevice(udn));
};
}
function upnpdevice_Cleanup()
{
console.log('Finalizing: ' + this.rootDevice.friendlyName);
}
function upnpservice(parentDevice, xmlDoc)
{
var emitterUtils = require('events').inherits(this);
this.device = parentDevice;
this.serviceType = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'serviceType')[0].textContent;
this.serviceId = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'serviceId')[0].textContent;
this.controlURL = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'controlURL')[0].textContent;
this.eventSubURL = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'eventSubURL')[0].textContent;
this.SCPDURL = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'SCPDURL')[0].textContent;
if (!this.controlURL.startsWith('http:') && !this.controlURL.startsWith('https:')) { this.controlURL = this.device.rootDevice.makeUrl(this.controlURL); }
if (!this.eventSubURL.startsWith('http:') && !this.eventSubURL.startsWith('https:')) { this.eventSubURL = this.device.rootDevice.makeUrl(this.eventSubURL); }
if (!this.SCPDURL.startsWith('http:') && !this.SCPDURL.startsWith('https:')) { this.SCPDURL = this.device.rootDevice.makeUrl(this.SCPDURL); }
this.load = function ()
{
++this.device.rootDevice.pendingServices;
this.req = http.get(this.SCPDURL);
this.req.service = this;
this.req.on('error', function () { this.service.device.rootDevice.emit('error', 'Error fetching SCPD from: ' + this.service.SCPDURL); });
this.req.on('response', function (msg)
{
if (msg.statusCode == 200)
{
msg.service = this.service;
this.service.scpdxml = new MemoryStream();
this.service.scpdxml.service = this.service;
msg.pipe(this.service.scpdxml);
this.service.scpdxml.on('end', function ()
{
try
{
upnpservice_parseScpd.apply(this.service, [this.buffer.toString()]);
}
catch(e)
{
this.service.device.rootDevice.emit('error', 'error parsing SCPD: ' + e);
}
});
}
else
{
this.service.device.rootDevice.emit('error', 'Error loading SCPD from: ' + this.service.SCPDURL);
}
});
}
this.getAction = function(name)
{
for(var a in this.actions)
{
if (this.actions[a].name == name) { return (this.actions[a]); }
}
return (undefined);
}
}
function upnpargument(action, xmlDoc)
{
this.action = action;
this.name = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'name')[0].textContent;
this.direction = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'direction')[0].textContent;
this.relatedStateVariable = action.service.stateVariables.get(xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'relatedStateVariable')[0].textContent);
}
function post_response(msg)
{
if (msg.statusCode != 200)
{
var userArgs = this.args;
if (userArgs.length > 0 && typeof (userArgs[0] == 'function'))
{
var fn = userArgs.shift();
userArgs.unshift(msg.StatusCode ? msg.StatusCode : msg.url);
fn.apply(this.action, userArgs);
}
return;
}
var buff = new MemoryStream();
buff.req = this;
msg.pipe(buff);
buff.on('end', function ()
{
var body = {};
var xml = parseXml(this.buffer.toString());
var action = this.req.action;
var userArgs = this.req.args;
var actionResponse = xml.getElementsByTagNameNS(action.service.serviceType, action.name + 'Response')[0];
if(actionResponse)
{
for(var child in actionResponse.childNodes)
{
if(action.arguments.get(actionResponse.childNodes[child].name))
{
body[actionResponse.childNodes[child].name] = actionResponse.childNodes[child].textContent;
}
}
if(userArgs.length > 0 && typeof(userArgs[0]) == 'function')
{
var fn = userArgs.shift();
userArgs.unshift(body);
fn.apply(action, userArgs);
}
}
});
}
function upnpaction(service, xmlDoc)
{
this.pendingPosts = [];
this.arguments = []; Object.defineProperty(this.arguments, "get", { value: function (name) { for (var i in this) { if (this[i].name == name) { return (this[i]); } } return (undefined); } });
this.service = service;
this.name = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'name')[0].textContent;
var argumentList = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'argumentList')[0];
if (argumentList)
{
var arguments = argumentList.getChildElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'argument');
for (var i in arguments)
{
this.arguments.push(new upnpargument(this, arguments[i]));
}
}
else
{
//console.log(this.service.scpdxml.buffer.toString());
}
this.invoke = function (args)
{
var parameters = '';
for (var i in this.arguments)
{
if(this.arguments[i].direction == 'in' && args[this.arguments[i].name])
{
parameters += ('<u:' + this.arguments[i].name + '>' + args[this.arguments[i].name] + '</u:' + this.arguments[i].name + '>');
}
else if(this.arguments.direction == 'in')
{
throw ('missing parameter: [' + this.arguments[i].name + '] when invoking Action: ' + this.name);
}
}
var controlUri = http.parseUri(this.service.controlURL);
console.log(controlUri);
var headers = { HOST: (controlUri.host + ':' + controlUri.port), SOAPACTION: '"' + this.service.serviceType + '#' + this.name + '"', 'Content-Type': 'text/xml; charset="utf-8"' };
this.pendingPosts.push(http.request({ protocol: 'http', host: controlUri.host, port: controlUri.port, method: 'POST', path: controlUri.path, headers: headers }));
this.pendingPosts.peek().action = this;
this.pendingPosts.peek().args = [];
for (var i = 1; i < arguments.length; ++i)
{
this.pendingPosts.peek().args.push(arguments[i]);
}
this.pendingPosts.peek().on('response', post_response);
var txt = '<?xml version="1.0" encoding="utf-8"?>\r\n<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body>';
this.pendingPosts.peek().write(txt);
console.log(txt);
txt = '<u:' + this.name + ' xmlns:u="' + this.service.serviceType + '">';
this.pendingPosts.peek().write(txt);
console.log(txt);
if (parameters != '')
{
this.pendingPosts.peek().write(parameters);
console.log(parameters);
}
this.pendingPosts.peek().write('</u:' + this.name + '>');
this.pendingPosts.peek().write('</s:Body></s:Envelope>');
console.log('</u:' + this.name + '>' + '</s:Body></s:Envelope>');
this.pendingPosts.peek().end();
};
this.invokeLegacy = function (args)
{
var controlUri = http.parseUri(this.service.controlURL);
var parameters = '';
for (var i in this.arguments) {
if (this.arguments[i].direction == 'in' && args[this.arguments[i].name]) {
parameters += ('<u:' + this.arguments[i].name + '>' + args[this.arguments[i].name] + '</u:' + this.arguments[i].name + '>');
}
else if (this.arguments.direction == 'in') {
throw ('missing parameter: [' + this.arguments[i].name + '] when invoking Action: ' + this.name);
}
}
this.pendingPosts.push(net.connect({ host: controlUri.host, port: controlUri.port }));
this.pendingPosts.peek().path = controlUri.path;
this.pendingPosts.peek().args = args;
this.pendingPosts.peek().parameters = parameters;
this.pendingPosts.peek().action = this;
this.pendingPosts.peek().headers = { HOST: (controlUri.host + ':' + controlUri.port), SOAPACTION: '"' + this.service.serviceType + '#' + this.name + '"', 'Content-Type': 'text/xml; charset="utf-8"' };
this.pendingPosts.peek().on('connect', function ()
{
console.log('legacy connected');
this.write('POST ' + this.path + ' HTTP/1.1\r\n');
var headers = this.headers;
this.write('HOST: ' + headers.HOST + '\r\n');
this.write('SOAPACTION: ' + headers.SOAPACTION + '\r\n');
this.write('Content-Type: ' + headers['Content-Type'] + '\r\n');
var txt = '<?xml version="1.0" encoding="utf-8"?>\r\n<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body>';
txt += '<u:' + this.action.name + ' xmlns:u="' + this.action.service.serviceType + '">';
txt += this.parameters;
txt += ('</u:' + this.name + '>' + '</s:Body></s:Envelope>');
var b = Buffer.from(txt);
this.write('Content-Length: ' + b.length + '\r\n\r\n');
this.write(b);
});
this.pendingPosts.peek().http = http.createStream();
this.pendingPosts.peek().pipe(this.pendingPosts.peek().http);
this.pendingPosts.peek().http.on('response', post_response);
};
}
function upnpvariable(service, xmlDoc)
{
this.service = service;
this.name = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'name')[0].textContent;
this.dataType = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'dataType')[0].textContent;
this.evented = xmlDoc.attributes.get('sendEvents').value;
if (this.evented == 'yes')
{
this.currentValue = null;
}
}
function upnpservice_parseScpd(scpd)
{
this.stateVariables = []; Object.defineProperty(this.stateVariables, "get", { value: function (name) { for (var i in this) { if (this[i].name == name) { return (this[i]); } } return (undefined); } });
this.actions = []; Object.defineProperty(this.actions, "get", { value: function (name) { for (var i in this) { if (this[i].name == name) { return (this[i]); } } return (undefined); } });
var doc = parseXml(scpd);
var stateTable = doc.getElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'serviceStateTable')[0];
var variables = stateTable.getChildElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'stateVariable');
for (var i in variables)
{
this.stateVariables.push(new upnpvariable(this, variables[i]));
}
var actionList = doc.getElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'actionList')[0];
var actions = actionList.getChildElementsByTagNameNS('urn:schemas-upnp-org:service-1-0', 'action');
for (var i in actions)
{
try
{
this.actions.push(new upnpaction(this, actions[i]));
}
catch(e)
{
this.device.rootDevice.emit('error', 'error parsing SCPD/Action: ' + e);
return;
}
}
this.subscribe = function ()
{
};
this.device.rootDevice.emit('serviceLoaded', this);
}
function upnpdevice_child(rootDevice, xmlDoc)
{
this.rootDevice = rootDevice;
this.services = []; Object.defineProperty(this.services, "get", { value: function (id) { for (var i in this) { if (this[i].serviceType == id || this[i].serviceId == id) { return (this[i]); } } return (undefined); } });
this.embeddedDevices = []; Object.defineProperty(this.embeddedDevices, "get", { value: function (id) { for (var i in this) { if (this[i].UDN == id || this[i].deviceType == id) { return (this[i]); } } return (undefined); } });
var emitterUtils = require('events').inherits(this);
emitterUtils.createEvent('bye');
emitterUtils.createEvent('error');
this.friendlyName = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'friendlyName')[0].textContent;
this.deviceType = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'deviceType')[0].textContent;
this.UDN = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'UDN')[0].textContent;
this.manufacturer = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'manufacturer')[0].textContent;
var serviceList = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'serviceList')[0]
for (var i in serviceList.childNodes)
{
if(serviceList.childNodes[i].namespace == 'urn:schemas-upnp-org:device-1-0')
{
this.services.push(new upnpservice(this, serviceList.childNodes[i]));
}
}
var deviceList = xmlDoc.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'deviceList')[0]
if (deviceList != null)
{
var devices = deviceList.getChildElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'device')
for (var device in devices)
{
this.embeddedDevices.push(new upnpdevice_child(rootDevice, devices[device]));
}
//console.log(devices);
}
this.loadAllServices = function () { for (var i in this.services) { this.services[i].load();} for (var i in this.embeddedDevices) { this.embeddedDevices[i].loadAllServices(); } };
this.getDevice = function (udn)
{
if (this.UDN == udn) { return (this); }
for(var ed in this.embeddedDevices)
{
var ret = this.embeddedDevices[ed].getDevice(udn);
if (ret) { return (ret); }
}
return (undefined);
};
this.getService = function(id)
{
for (var s in this.services)
{
if (this.services[s].serviceId == id) { return (this.services[s]); }
}
return (undefined);
}
}
function upnpdevice_parseXml(xml)
{
this.dd = null;
var doc = parseXml(xml);
//var URLBase = doc.getElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'URLBase')[0];
//if (URLBase != null) { console.log("old base: " + this.BaseURL); this.BaseURL = URLBase.textContent; }
var root = doc.getElementsByTagNameNS('urn:schemas-upnp-org:device-1-0', 'device')[0];
if (root != null)
{
this.rootDevice = new upnpdevice_child(this, root);
if (!this.cp.searchString.startsWith('ssdp:') && !this.cp.searchString.startsWith('upnp:') && !this.cp.searchString.startsWith('urn:') && !this.cp.searchString.startsWith('uuid:'))
{
// Friendly Name Search
if(this.rootDevice.friendlyName == this.cp.searchString)
{
//console.log(xml);
this.rootDevice.loadAllServices();
}
}
else
{
console.log(this.cp.searchString.split(':')[0]);
switch(this.cp.searchString.split(':')[0])
{
case 'ssdp':
break;
case 'upnp':
this.rootDevice.loadAllServices();
break;
case 'uuid':
break;
case 'urn':
break;
}
}
//console.log(this.rootDevice.friendlyName);
}
}
function upnpcp_onSearch(msg, rinfo)
{
var header = require('http-headers')(msg);
if (header.statusCode != 200) { return; }
var usn = header.headers.usn.split('::')[0];
if(this.cp.deviceTable[usn] == null)
{
this.cp.deviceTable[usn] = new upnpdevice(header.headers.location, usn, this.cp);
this.cp.deviceTable[usn].on('error', function (e) { console.log('Removing Device/' + this.usn + ' due to error: ' + e); this.cp.deviceTable[this.usn] = null; });
this.cp.deviceTable[usn].on('alive', function () { this.cp.emit('device', this); });
}
}
function upnpcp(search)
{
this.searchString = search;
if (!search.startsWith('ssdp:') && !search.startsWith('upnp:') && !search.startsWith('uuid:') && !search.startsWith('urn:'))
{
// Search by Friendly Name
search = 'upnp:rootdevice';
}
var MSEARCH = 'M-SEARCH * HTTP/1.1\r\nHOST: 239.255.255.250:1900\r\nST: ' + search + '\r\nMAN: "ssdp:discover"\r\nMX: 5\r\nContent-Length: 0\r\n\r\n';
var emitterUtils = require('events').inherits(this);
emitterUtils.createEvent('device');
this.searchSocket = dgram.createSocket({ type: 'udp4' });
this.searchSocket.cp = this;
this.searchSocket.bind({ port: 0, address:'0.0.0.0' });
this.deviceTable = {};
this.searchSocket.on('message', upnpcp_onSearch);
var interfaces = os.networkInterfaces();
for(var name in interfaces)
{
for (var i in interfaces[name])
{
if (interfaces[name][i].family == 'IPv4' && interfaces[name][i].status == 'up')
{
console.log('Sending Multicast on: ' + interfaces[name][i].address + ' to: 239.255.255.250:1900');
this.searchSocket.setMulticastTTL(1);
this.searchSocket.setMulticastLoopback(true);
this.searchSocket.setMulticastInterface(interfaces[name][i].address);
this.searchSocket.send(MSEARCH, 1900, '239.255.255.250');
}
}
}
}
//var testCP = new upnpcp("Samsung CLX-3300 Series (10.128.125.118)");
function display_device(dv)
{
if (!dv) { console.log('No match'); return; }
console.log('FriendlyName/ ' + dv.friendlyName);
console.log(' DeviceType/ ' + dv.deviceType);
console.log(' DeviceUDN/ ' + dv.UDN);
for (var svc in dv.services)
{
console.log(' ServiceID/ ' + dv.services[svc].serviceId);
}
for (var ed in dv.embeddedDevices)
{
console.log(' Embedded Device: ' + dv.embeddedDevices[ed].friendlyName + ' [' + dv.embeddedDevices[ed].UDN + ']');
}
}
function display_action(action)
{
var argString = null;
for (var arg in action.arguments)
{
if (action.arguments[arg].direction == 'in')
{
if (argString)
{
argString += (', ' + action.arguments[arg].name);
}
else
{
argString = action.arguments[arg].name;
}
}
}
console.log(' ' + action.name + '(' + (argString?argString:'') + ')');
}
function display_actionDetail(action)
{
if (!action) { console.log('no match'); return; }
console.log('Action: ' + action.name);
console.log(' Input Parameters:');
console.log(' {');
for (var arg in action.arguments)
{
if (action.arguments[arg].direction == 'in')
{
console.log(' [' + action.arguments[arg].relatedStateVariable.dataType + '] ' + action.arguments[arg].name);
}
}
console.log(' }');
console.log(' Output Parameters:');
console.log(' {');
for (var arg in action.arguments)
{
if (action.arguments[arg].direction == 'out')
{
console.log(' [' + action.arguments[arg].relatedStateVariable.dataType + '] ' + action.arguments[arg].name);
}
}
console.log(' }');
}
function display_service(svc)
{
if (!svc) { console.log('No match'); return; }
console.log('ServiceID/ ' + svc.serviceId);
console.log('ServiceType/ ' + svc.serviceType);
console.log('Actions:');
for(var action in svc.actions)
{
display_action(svc.actions[action]);
}
}
var testCP;
if (process.argv.length > 1)
{
if(process.argv[1].startsWith('discover='))
{
testCP = new upnpcp(process.argv[1].split('=')[1]);
}
}
if (!testCP) { process.exit(); }
testCP.on('device', function (dv)
{
var selectedDevice = null;
var selectedService = null;
var selectedAction = null;
console.log('');
console.log('Device Added: ');
display_device(dv.rootDevice);
console.log('');
for (var arg in process.argv)
{
if(process.argv[arg].startsWith('dv='))
{
var i = parseInt(process.argv[arg].split('=')[1]);
console.log('Selected Embedded Device: ' + i);
display_device(dv.rootDevice.embeddedDevices[i]);
selectedDevice = dv.rootDevice.embeddedDevices[i];
}
if(process.argv[arg].startsWith('udn='))
{
console.log('Selected Device: ' + process.argv[arg].split('=')[1]);
selectedDevice = dv.getDevice(process.argv[arg].split('=')[1]);
display_device(selectedDevice);
}
if(selectedDevice && process.argv[arg].startsWith('serviceId='))
{
selectedService = selectedDevice.getService(process.argv[arg].split('=')[1]);
display_service(selectedService);
}
if(selectedService && process.argv[arg].startsWith('action='))
{
selectedAction = selectedService.getAction(process.argv[arg].split('=')[1]);
display_actionDetail(selectedAction);
}
if(selectedAction && process.argv[arg].startsWith('invoke='))
{
var txt = process.argv[arg].split('=')[1];
console.log('Invoking with: ' + txt);
selectedAction.invoke(JSON.parse(process.argv[arg].split('=')[1]), function ()
{
console.log('Response: ', arguments[0]);
process.exit();
});
}
if (selectedAction && process.argv[arg].startsWith('invokeLegacy=')) {
var txt = process.argv[arg].split('=')[1];
console.log('Invoking with: ' + txt);
selectedAction.invokeLegacy(JSON.parse(process.argv[arg].split('=')[1]), function () {
console.log('Response: ', arguments[0]);
process.exit();
});
}
}
});