From 6f10e62b52979c080d010819f360b37f9832b11a Mon Sep 17 00:00:00 2001 From: heyfryman Date: Wed, 19 Apr 2017 10:08:19 -0400 Subject: [PATCH 1/9] Add files via upload --- advertise.js | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/advertise.js b/advertise.js index fa10ed0..a5b1d8f 100644 --- a/advertise.js +++ b/advertise.js @@ -16,9 +16,9 @@ var options = new getopt([ ['S' , 'static' , 'static - do not connect to ws-slave/target device'], ['f' , 'funmode' , 'have fun!'], ['' , 'jk' , 'see http://xkcd.com/1692'], - ['h' , 'help' , 'display this help'], + ['h' , 'help' , 'display this help'], ]); -options.setHelp("Usage: node advertise -a [ -s ] [-S] \n[[OPTIONS]]" ) +options.setHelp("\nUsage:".underline + " node".bold + " advertise.js".cyan.bold + " -a ".yellow.bold + "[ -s ]".magenta.bold + " [-S]".bold + " \n[[OPTIONS]]\n" ) opt=options.parseSystem(); @@ -68,7 +68,7 @@ if (opt.options.static) { baseAdvFile=path.basename(opt.options.advertisement); var peripheralId = baseAdvFile.substring(0, baseAdvFile.indexOf("_")); -console.log("peripheralid: " + peripheralId) +console.log('[+]'.green.bold + "Peripheral ID (MAC):".yellow.bold + " " + peripheralId) if (opt.options.advertisement.indexOf('.adv.json') > -1 ) { @@ -77,14 +77,14 @@ if (opt.options.advertisement.indexOf('.adv.json') > -1 ) { advertisementFile=opt.options.advertisement + '.adv.json'; } -console.log('advertisement file: ' + advertisementFile) +console.log('[+]'.green.bold + 'Advertisement File:'.yellow.bold + " " + advertisementFile) var advertisement = JSON.parse(fs.readFileSync(advertisementFile, 'utf8')); var eir = new Buffer(advertisement.eir,'hex'); var scanResponse = advertisement.scanResponse ? new Buffer(advertisement.scanResponse, 'hex') : ''; -console.log("EIR: " + eir.toString('hex')); -console.log("scanResponse: " + scanResponse.toString('hex')); +console.log('[+]'.green.bold + "EIR:".yellow.bold + " " + eir.toString('hex')); +console.log('[+]'.green.bold + "Scan Response:".yellow.bold + " " + scanResponse.toString('hex')); if (opt.options.services) { if (opt.options.services.indexOf('.srv.json') > -1 ) { @@ -109,10 +109,10 @@ if (!staticRun) { wsclient.on('ws_open', function(){ wsclient.getMac(function(address){ myAddress = address; - console.log('Noble MAC address : ' + myAddress); + console.log('[+]'.green.bold + 'Noble MAC address: '.blue.bold + myAddress); }) wsclient.initialize(peripheralId, services, true, function(){ - console.log('initialized !'); + console.log('[+]Initialized!'.green.bold); startAdvertising(); }) }); @@ -122,17 +122,17 @@ if (!staticRun) { function startAdvertising(){ if (bleno.state != 'poweredOn') { - console.log('waiting for interface to initialize...'); + console.log('Waiting for interface to initialize...'.yellow); bleno.once('stateChange', function(state){ if (state === 'poweredOn') { bleno.startAdvertisingWithEIRData(eir,scanResponse); } else { - console.log('Interface down! Exiting...'); + console.log('[-]'.red.bold + 'Interface down! Exiting...'.red.bold); process.exit(1); } }) } else { - console.log('Static - start advertising'); + console.log('[+]'.green.bold + 'Static - Start Advertising...'.green.bold); bleno.startAdvertisingWithEIRData(eir,scanResponse); } } @@ -206,33 +206,33 @@ function dumpLog(type, peripheralId, serviceUuid, uuid, data ){ bleno.on('stateChange', function(state) { - console.log('BLENO - on -> stateChange: ' + state); + console.log('[+]'.green.bold + 'BLENO - on -> stateChange: '.green.bold + state); if (state === 'poweredOn') { // console.log('poweredOn'); } else { - console.log('Interface down! Reset/power it up again...') + console.log('[-]'.red.bold + 'Interface down! Reset/Power it up again...'.red.bold) bleno.stopAdvertising(); } }); bleno.on('advertisingStart', function(error) { - console.log('on -> advertisingStart: ' + (error ? 'error ' + error : 'success')); + console.log('On -> advertisingStart: '.yellow.bold + (error ? 'Error '.red.bold + error : 'Success'.green.bold)); if (error) { - console.log("Adv error ".red,error); + console.log('[-]'.red.bold + "Advertising Error ".red.bold,error); } else { bleno.setServices( mitmservices, function(error){ - console.log('setServices: ' + (error ? 'error ' + error : 'success')); - console.log(' <<<<<<<<<<<<<<<< INITIALIZED >>>>>>>>>>>>>>>>>>>> '.magenta.inverse) + console.log('setServices: '.yellow.bold + (error ? 'Error '.red.bold + error : 'Success'.green.bold)); + console.log('\n <<<<<<<<<<<<<<<< INITIALIZED >>>>>>>>>>>>>>>>>>>> \n'.magenta.inverse) }); } }); bleno.on('accept', function(clientAddress) { - console.log('Client connected: ' + clientAddress); + console.log('Client Connected: '.green.bold + clientAddress); if (clientAddress === myAddress) { - console.log('SELF CONNECT!'); + console.log('SELF CONNECT!'.green); bleno.disconnect(); } else { if (!staticRun) { @@ -247,7 +247,7 @@ bleno.on('accept', function(clientAddress) { //update the ws-slave on client disconnect bleno.on('disconnect', function(clientAddress){ - console.log('Client disconnected: ' + clientAddress); + console.log('Client Disconnected: '.red.bold + clientAddress); if (!staticRun) { wsclient.clientConnection(clientAddress,false); } @@ -256,11 +256,11 @@ bleno.on('disconnect', function(clientAddress){ wsclient.on('disconnect', function(peripheralId){ - console.log(' target device disconnected'); + console.log(' -----Target device disconnected!'.red.bold); }) wsclient.on('connect', function(peripheralId){ - console.log(' target device connected'); + console.log(' -----Target device connected!'.green.bold); }) //change the advertisement @@ -268,7 +268,7 @@ wsclient.on('advchange', function(newEir, newScanResponse){ bleno.stopAdvertising(function(){ //wait 2 seconds after stopAdvertising, otherwise the HCI will often fail with "Command Disallowed" setTimeout(function() { - console.log('Advertisement change: waited 2s for device, should work now...'); + console.log('Advertisement change: waited 2s for device, should work now...'.yellow); console.log(' old ' + eir.toString('hex') + ' ('+ utils.hex2a(eir) +') '+ ' : ' + scanResponse.toString('hex') + ' ('+ utils.hex2a(scanResponse) +')'); console.log(' new ' + newEir.toString('hex') + ' ('+ utils.hex2a(newEir) +') '+ ' : ' + newScanResponse.toString('hex') + ' ('+ utils.hex2a(newScanResponse) +') '); bleno.startAdvertisingWithEIRData(newEir,newScanResponse); @@ -343,7 +343,7 @@ function setServices(services, callback){ for (sindex = 0; sindex < services.length; ++sindex) { serviceToCopy = services[sindex]; servicesLookup[serviceToCopy.uuid]= { characteristics: [] }; - debug("Setting up service: " + serviceToCopy.uuid); + debug("Setting up service: ".yellow + serviceToCopy.uuid); mitmcharacteristics=[]; for (cindex = 0; cindex ' + this.uuid + ' offset: ' + offset) + debug('<< Read req : '.green + this.serviceUuid +' -> ' + this.uuid + ' offset: '.green + offset) //we assume the original device read success //todo? - forward possible error to client @@ -480,7 +480,7 @@ function setServices(services, callback){ callback(0x00); }); } else { - console.log(' hook function did not return modified data'); + console.log(' hook function did not return modified data'.yellow); callback(0x00); } }) From 23c0ee838660650d13cc892dfe37172a48da0f6a Mon Sep 17 00:00:00 2001 From: heyfryman Date: Wed, 19 Apr 2017 10:09:35 -0400 Subject: [PATCH 2/9] Add files via upload --- lib/ws-client.js | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/ws-client.js b/lib/ws-client.js index 6aaf990..5130508 100644 --- a/lib/ws-client.js +++ b/lib/ws-client.js @@ -16,7 +16,7 @@ var myAddress=''; var wsClient = function(){ - console.log('Ws-slave address: ' + slaveAddress); + console.log('\n[+]'.green.bold + 'WS-Slave IP Address:'.yellow.bold +" " + slaveAddress); this.on('read', this.onRead); events.EventEmitter.call(this); @@ -31,7 +31,7 @@ var wsClient = function(){ var _this = this; ws.on('open', function() { // ws.send('something'); - console.log('on open'); + console.log('[+]'.green.bold + 'WS is On & Open'.yellow.bold); _this.emit('ws_open'); }); @@ -43,16 +43,16 @@ wsClient.prototype.checkReadyState = function(callback){ switch (ws.readyState) { case WebSocket.CONNECTING: - console.log('connecting'); + console.log('Connecting'.green.bold); break; case WebSocket.OPEN: - console.log('connecting'); + console.log('Connecting/Open'.green.bold); break; case WebSocket.CLOSING: - console.log('closing'); + console.log('Closing'.red.bold); break; case WebSocket.CLOSED: - console.log('closed'); + console.log('Closed'.red.bold); break; default: break; @@ -98,7 +98,7 @@ wsClient.prototype.onMessage = function(rawmessage) { var handle = message.handle; if (type === 'stateChange') { - console.log(state); + console.log('[+]'.green.bold + 'Current State: '.yellow.bold + state); this.emit('stateChange', state); } else if (type === 'discover') { @@ -237,7 +237,7 @@ wsClient.prototype.read = function(peripheralId, serviceUuid, characteristicUuid if (callback) { //todo - what if there was another read in the meantime ;) this.once('read', function(peripheralId, service, characteristic, data, isNotification) { - debug("READ: " + service + "("+serviceUuid+") : " + characteristic + "("+characteristicUuid+") : " + data + " : " + isNotification); + debug("READ: ".yellow.bold + service + "("+serviceUuid+") : " + characteristic + "("+characteristicUuid+") : " + data + " : " + isNotification); callback(data); }); } @@ -254,7 +254,7 @@ wsClient.prototype.write = function(peripheralId, serviceUuid, characteristicUui //todo err this.once('write', function(peripheral, service, characteristic) { if ((peripheral === peripheralId) && (service === serviceUuid) && (characteristic === characteristicUuid)) { - debug("WRITE: " + service + "("+serviceUuid+") : " + characteristic + "("+characteristicUuid+")"); + debug("WRITE: ".yellow.bold + service + "("+serviceUuid+") : " + characteristic + "("+characteristicUuid+")"); callback(null); } }); @@ -275,7 +275,7 @@ wsClient.prototype.notify = function(peripheralId, serviceUuid, characteristicUu if (callback) { //todo err this.once('notify', function(peripheralId, service, characteristic, state) { - debug("NOTIFY SUBSCRIBE: " + service + " : " + characteristic + ' : ' + state); + debug("NOTIFY SUBSCRIBE: ".yellow.bold + service + " : " + characteristic + ' : ' + state); //todo handle err callback(null, peripheralId, service, characteristic, state); }); From d41afac4ab0c682164c9723734225467f0f39c0d Mon Sep 17 00:00:00 2001 From: heyfryman Date: Wed, 19 Apr 2017 14:52:26 -0400 Subject: [PATCH 3/9] Add files via upload --- ws-slave.js | 50 +++++++++++++++++++++++++++++++++++++------------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/ws-slave.js b/ws-slave.js index d31c8b5..e51ddd0 100644 --- a/ws-slave.js +++ b/ws-slave.js @@ -28,14 +28,14 @@ var isClientConnected=false; var eventEmitter = new events.EventEmitter(); -console.log('GATTacker ws-slave'); +console.log('\nGATTacker ws-slave\n'.white.bold); wss = new WebSocket.Server({ port: port, perMessageDeflate: false }); wss.on('connection', function(ws_) { - console.log('ws -> connection'); + console.log('[+]'.green.bold + 'ws -> connection'.yellow.bold); ws = ws_; @@ -47,7 +47,7 @@ wss.on('connection', function(ws_) { ws.on('message', onMessage); ws.on('close', function() { - console.log('ws -> close'); + console.log('[-]'.red.bold + 'ws -> close'.yellow.bold); //stop keeping connection to target device if (targetPeripheralId) { deinitialize(targetPeripheralId, function(peripheralId){ @@ -67,7 +67,21 @@ noble._bindings.on('handleNotify', onRawNotify); function sendEvent(event) { var message = JSON.stringify(event); - console.log('ws -> send: '.blue + message); + //console.log('ws -> send: '.blue.bold + message); //Orginal + console.log('\nws -> send:'.bgBlue.bold); //Modified + + //New stuff added + var command = JSON.parse(message); + JSON.parse(message, (key,value) => { + if (key == '' || value == ''){} else { + if (key == 'uuid'){ + console.log('') // This creates a new line break + console.log('-----------------------------------------------') + } + console.log(key.blue.bold + ': '.blue.bold + value); + } + }) + //End of new stuff for test var clients = wss.clients; @@ -98,12 +112,21 @@ noble._bindings._hci.on('addressChange', function(address){ var onMessage = function(message) { - console.log('ws -> message: '.green + message); + //console.log('\nws -> message: '.green.bold + message); //Orginal + console.log('\nws -> message:'.bgGreen.bold); //Modified var command = JSON.parse(message); + JSON.parse(message, (key,value) => { + if (key == '' || value == ''){} else { + if (key == 'uuid'){ + console.log('') // This creates a new line break + console.log('-----------------------------------------------') + } + console.log(key.green.bold + ': '.green.bold + value); + } + }) var action = command.action; - var peripheralId = command.peripheralId; var serviceUuids = command.serviceUuids; var serviceUuid = command.serviceUuid; @@ -124,7 +147,7 @@ var onMessage = function(message) { if (peripheral && serviceUuid) { var service = servicesCache[peripheralId].services[serviceUuid]; if (!service) { - debug('service not found!'.red); + debug('Service not found!'.red.bold); } else { var characteristic = servicesCache[peripheralId].services[serviceUuid].characteristics[characteristicUuid]; if (!characteristic) { @@ -182,6 +205,7 @@ var onMessage = function(message) { } else if (action === 'writeHandle') { peripheral.writeHandle(handle, data, withoutResponse); } + }; @@ -190,7 +214,7 @@ function initializeWithoutServices(peripheralId) { //was previously initialized for other device if (targetPeripheralId && targetPeripheralId != peripheralId) { deinitialize(targetPeripheralId, function(){ - console.log('re-initialize for other device '); + console.log('Re-initialize for other device '); }) } @@ -240,7 +264,7 @@ function initialize(peripheralId, servicesJson, keepConnected) { //was previously initialized for other device if (targetPeripheralId && targetPeripheralId != peripheralId) { deinitialize(targetPeripheralId, function(){ - console.log('re-initialize for other device '); + console.log('Re-initialize for other device '); }) } @@ -358,9 +382,9 @@ function readRaw(peripheralId, serviceUuid, uuid, callback){ checkConnected(peripheral, function(){ peripheral.readHandle(handle, function(error, data){ if (error) { - debug('readHandle error : '.red + error) + debug('readHandle error: '.red + error) } - debug('read handle data :' + data.toString('hex')); + debug('read handle data:' + data.toString('hex')); sendEvent({ type: 'read', @@ -386,7 +410,7 @@ function writeRaw(peripheralId, serviceUuid, uuid, data, withoutResponse, callba checkConnected(peripheral, function(){ peripheral.writeHandle(handle, new Buffer(data,'hex'), withoutResponse, function(error){ if (error) { - debug('Write handle error! '. red + error); + debug('Write handle error! '.red + error); } debug('write handle sent ' + peripheralId + ' : ' + serviceUuid + ' : ' + uuid ) sendEvent({ @@ -518,7 +542,7 @@ function checkConnected(peripheral, callback){ peripheral.connect( function(error) { if (error) { - debug('checkconnected -> reconnect error !'.red + error) + debug('checkconnected -> reconnect error!'.red.bold + error) } else { debug('checkconnected -> reconnect'); } From 66da5723575cf8703d1475256af704770e28d25d Mon Sep 17 00:00:00 2001 From: heyfryman Date: Wed, 19 Apr 2017 16:09:31 -0400 Subject: [PATCH 4/9] Update advertise.js --- advertise.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advertise.js b/advertise.js index a5b1d8f..49527d4 100644 --- a/advertise.js +++ b/advertise.js @@ -343,7 +343,7 @@ function setServices(services, callback){ for (sindex = 0; sindex < services.length; ++sindex) { serviceToCopy = services[sindex]; servicesLookup[serviceToCopy.uuid]= { characteristics: [] }; - debug("Setting up service: ".yellow + serviceToCopy.uuid); + debug("Setting up service: " + serviceToCopy.uuid); mitmcharacteristics=[]; for (cindex = 0; cindex ' + this.uuid + ' offset: '.green + offset) + debug('<< Read req : ' + this.serviceUuid +' -> ' + this.uuid + ' offset: ' + offset) //we assume the original device read success //todo? - forward possible error to client From 2343ea50ce9810c7633091f868f0bc3eaa6dddd1 Mon Sep 17 00:00:00 2001 From: heyfryman Date: Wed, 19 Apr 2017 16:12:46 -0400 Subject: [PATCH 5/9] Update ws-client.js --- lib/ws-client.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/ws-client.js b/lib/ws-client.js index 5130508..ef51c00 100644 --- a/lib/ws-client.js +++ b/lib/ws-client.js @@ -237,7 +237,7 @@ wsClient.prototype.read = function(peripheralId, serviceUuid, characteristicUuid if (callback) { //todo - what if there was another read in the meantime ;) this.once('read', function(peripheralId, service, characteristic, data, isNotification) { - debug("READ: ".yellow.bold + service + "("+serviceUuid+") : " + characteristic + "("+characteristicUuid+") : " + data + " : " + isNotification); + debug("READ: " + service + "("+serviceUuid+") : " + characteristic + "("+characteristicUuid+") : " + data + " : " + isNotification); callback(data); }); } @@ -254,7 +254,7 @@ wsClient.prototype.write = function(peripheralId, serviceUuid, characteristicUui //todo err this.once('write', function(peripheral, service, characteristic) { if ((peripheral === peripheralId) && (service === serviceUuid) && (characteristic === characteristicUuid)) { - debug("WRITE: ".yellow.bold + service + "("+serviceUuid+") : " + characteristic + "("+characteristicUuid+")"); + debug("WRITE: " + service + "("+serviceUuid+") : " + characteristic + "("+characteristicUuid+")"); callback(null); } }); @@ -275,7 +275,7 @@ wsClient.prototype.notify = function(peripheralId, serviceUuid, characteristicUu if (callback) { //todo err this.once('notify', function(peripheralId, service, characteristic, state) { - debug("NOTIFY SUBSCRIBE: ".yellow.bold + service + " : " + characteristic + ' : ' + state); + debug("NOTIFY SUBSCRIBE: " + service + " : " + characteristic + ' : ' + state); //todo handle err callback(null, peripheralId, service, characteristic, state); }); @@ -317,4 +317,4 @@ wsClient.prototype.getMac = function(callback) { } } -module.exports = new wsClient(); \ No newline at end of file +module.exports = new wsClient(); From f8cacad667fb212e45a586b03e2f2326ded8c456 Mon Sep 17 00:00:00 2001 From: heyfryman Date: Wed, 19 Apr 2017 16:19:01 -0400 Subject: [PATCH 6/9] Update advertise.js --- advertise.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/advertise.js b/advertise.js index 49527d4..4b52b7c 100644 --- a/advertise.js +++ b/advertise.js @@ -396,7 +396,7 @@ function setServices(services, callback){ var info = getServiceNames(serviceUuid, uuid); - debug('<< Read req : ' + this.serviceUuid +' -> ' + this.uuid + ' offset: ' + offset) + debug('<< Read req: '.green + this.serviceUuid +' -> ' + this.uuid + ' offset: ' + offset) //we assume the original device read success //todo? - forward possible error to client From 80928af71cf92b92745e236a86df8542b2bff14c Mon Sep 17 00:00:00 2001 From: heyfryman Date: Thu, 4 May 2017 13:24:16 -0400 Subject: [PATCH 7/9] Add files via upload --- ws-slave.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ws-slave.js b/ws-slave.js index e51ddd0..d298130 100644 --- a/ws-slave.js +++ b/ws-slave.js @@ -511,7 +511,7 @@ function clientConnection(clientAddress, state) { if (state != true) { dis='dis'; } - console.log('client ' + dis + 'connected : ' + clientAddress); + console.log('client '.yellow.bold + dis.red.bold + 'connected: '.yellow.bold + clientAddress.yellow.bold); isClientConnected = state; // send confirmation event for reconnect eventEmitter.emit('clientConnection', clientAddress, state); From 95b52863bb88c7ebf1ad5026d25c901759ae57ce Mon Sep 17 00:00:00 2001 From: heyfryman Date: Thu, 4 May 2017 13:25:44 -0400 Subject: [PATCH 8/9] Add files via upload --- advertise.js | 9 +++++---- replay.js | 40 +++++++++++++++++++++++++++++++++------- scan.js | 16 ++++++++-------- 3 files changed, 46 insertions(+), 19 deletions(-) diff --git a/advertise.js b/advertise.js index 4b52b7c..2d56a9f 100644 --- a/advertise.js +++ b/advertise.js @@ -85,6 +85,7 @@ var scanResponse = advertisement.scanResponse ? new Buffer(advertisement.scanRes console.log('[+]'.green.bold + "EIR:".yellow.bold + " " + eir.toString('hex')); console.log('[+]'.green.bold + "Scan Response:".yellow.bold + " " + scanResponse.toString('hex')); +console.log(getDateTime().bgCyan.bold); if (opt.options.services) { if (opt.options.services.indexOf('.srv.json') > -1 ) { @@ -229,7 +230,7 @@ bleno.on('advertisingStart', function(error) { }); bleno.on('accept', function(clientAddress) { - console.log('Client Connected: '.green.bold + clientAddress); + console.log('Client Connected: \t'.green.bold + clientAddress + ' \t' + getDateTime().bgCyan.bold); if (clientAddress === myAddress) { console.log('SELF CONNECT!'.green); @@ -247,7 +248,7 @@ bleno.on('accept', function(clientAddress) { //update the ws-slave on client disconnect bleno.on('disconnect', function(clientAddress){ - console.log('Client Disconnected: '.red.bold + clientAddress); + console.log('Client Disconnected: \t'.red.bold + clientAddress + ' \t' + getDateTime().bgCyan.bold); if (!staticRun) { wsclient.clientConnection(clientAddress,false); } @@ -256,11 +257,11 @@ bleno.on('disconnect', function(clientAddress){ wsclient.on('disconnect', function(peripheralId){ - console.log(' -----Target device disconnected!'.red.bold); + console.log(' -----Target device disconnected!'.red.bold + ' ' + getDateTime().bgCyan.bold); }) wsclient.on('connect', function(peripheralId){ - console.log(' -----Target device connected!'.green.bold); + console.log(' -----Target device connected!'.green.bold + ' ' + getDateTime().bgCyan.bold); }) //change the advertisement diff --git a/replay.js b/replay.js index 18aaff8..7e8883a 100644 --- a/replay.js +++ b/replay.js @@ -72,7 +72,8 @@ function parse(line) { if(waiting) {//we want it to match console.log('LINE: ' + line); - setTimeout(parse(line), 500);//wait 50 millisecnds then recheck + //setTimeout(parse(line), 500;//wait 50 millisecnds then recheck + setTimeout(parse(line), 20;//wait 20 millisecnds then recheck - Modified return; } @@ -82,25 +83,50 @@ function parse(line) { var uuid = arr[3].trim().split(' ')[0]; var data = arr[4].trim().split(' ')[0]; + +/* switch(operator) { - case '< W' : console.log('WRITE REQ: '.blue + data ); + case '< W' : console.log('WRITE REQ: '.blue.bold + data ); wsclient.write(peripheralId, serviceUuid, uuid, new Buffer(data,'hex'), true , function(error) { if (error){ - console.log('------ Write error: '.red); + console.log('------ Write error: '.red.bold); throw(error); } }); break; case '< C' : console.log('WRITE CMD: '.blue + data ); wsclient.write(peripheralId, serviceUuid, uuid, new Buffer(data,'hex'), false , function(error) { if (error){ - console.log('------ Write error: '.red); + console.log('------ Write error: '.red.bold); + throw(error); + } + }); break; +*/ + + switch(operator) { + case '< W' : console.log('WRITE REQ: '.blue.bold + data.yellow + ' ('.yellow.bold + new Buffer(data, 'hex') + ')'.yellow.bold); + wsclient.write(peripheralId, serviceUuid, uuid, new Buffer(data,'hex'), true , function(error) { + if (error){ + console.log('------ Write error: '.red.bold); throw(error); } }); break; + case '< C' : console.log('WRITE CMD: '.green.bold + data.yellow + ' ('.yellow.bold + new Buffer(data, 'hex') + ')'.yellow.bold ); + wsclient.write(peripheralId, serviceUuid, uuid, new Buffer(data,'hex'), false , function(error) { + if (error){ + console.log('------ Write error: '.red.bold); + throw(error); + } + }); break; + + + + + + - case '> R' : console.log('READ: '.grey + data + ' --- skip'); + case '> R' : console.log('READ: '.grey + data + ' --- skipped'); break - case '> N' : console.log('NOTIFICATION: '.grey + data + ' --- skip'); + case '> N' : console.log('NOTIFICATION: '.grey + data + ' --- skipped'); break } @@ -110,7 +136,7 @@ function parse(line) { wsclient.on('ws_open', function(){ wsclient.getMac(function(address){ myAddress = address; - console.log('Noble MAC address : ' + myAddress); + console.log('Noble MAC address: ' + myAddress); }) wsclient.initialize(peripheralId, services, true, function(){ console.log('initialized !'); diff --git a/scan.js b/scan.js index 2ed9213..8c94e00 100644 --- a/scan.js +++ b/scan.js @@ -45,17 +45,17 @@ var readValues=true; var overWriteServices=false; if (opt.options["no-advertisements"]) { - console.log('Not saving advertisement discovery.'); + console.log('Not saving advertisement discovery because the -a flag was set.'.red.bold); saveAdvertisements=false; } if (opt.options["no-read"]) { - console.log('Not reading characteristic values.') + console.log('Not reading characteristic values.'.red.bold) readValues=false; } if (opt.options.overwrite) { - console.log('Overwrite services file if exists.'); + console.log('Overwrite services file if exists.'.red.bold); overWriteServices=true; } @@ -64,10 +64,10 @@ function exploreSpecified(peripheralId) { checkFile(peripheralId, function(exists){ if (!exists) { - console.log('Start to explore ' + peripheralId) + console.log('[+]'.green.bold + 'No advertisement file exists, starting to explore '.yellow.bold + peripheralId.cyan.bold) wsclient.explore(peripheralId, readValues); } else { - console.log('Services file for ' + peripheralId + ' already saved, skipping. Use -o option to overwrite.'); + console.log('Services file for '.yellow.bold + peripheralId.cyan.bold + ' already saved, skipping. Use -o option to overwrite.'.yellow.bold); } }) @@ -93,7 +93,7 @@ function checkFile(peripheralId, callback) { wsclient.on('stateChange', function(state) { if (state === 'poweredOn') { if (specifiedPeripheral) { - console.log('Start exploring ' + specifiedPeripheral); + console.log('[+]'.green.bold + 'Start exploring '.yellow.bold + specifiedPeripheral.cyan.bold); exploreSpecified(specifiedPeripheral) } else { console.log('Start scanning.'); @@ -122,7 +122,7 @@ wsclient.on('discover', function(peripheralId, address, addressType, connectable wsclient.on('explore', function(peripheralId, state, servicesJson){ - console.log('explore state: ' + peripheralId + ' : ' + state); + console.log('[+]'.green.bold +'Explore state: '.yellow.bold + peripheralId.cyan.bold + ' - ' + state.magenta.bold); if(state === 'finished') { var filename = devicesPath+'/'+peripheralId+'.srv.json'; @@ -131,7 +131,7 @@ wsclient.on('explore', function(peripheralId, state, servicesJson){ if(err) { return console.log(err); } - console.log("Services file "+ filename +" saved!"); + console.log('[+]'.green.bold +"Services file ".yellow.bold+ filename.white.bold +" saved!".yellow.bold); if (peripheralId === specifiedPeripheral) { process.exit(0); } From 49a345a4d7e353935d950f75680ab0aa90384828 Mon Sep 17 00:00:00 2001 From: heyfryman Date: Thu, 4 May 2017 13:26:05 -0400 Subject: [PATCH 9/9] Add files via upload --- lib/utils.js | 65 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 54 insertions(+), 11 deletions(-) diff --git a/lib/utils.js b/lib/utils.js index 600b0d8..604d29c 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -23,26 +23,39 @@ function hex2a(hex) { function printAdvertisement(peripheralId, address, addressType, connectable, advertisement, rssi, isRefreshed) { + /* //Original if (!isRefreshed) { - console.log('peripheral discovered (' + peripheralId + - ' with address <' + address + ', ' + addressType + '>,' + - ' connectable ' + connectable + ',' + - ' RSSI ' + rssi + ':'); + console.log('Peripheral discovered ('.yellow.bold + peripheralId.cyan.bold + + ' with address <'.yellow.bold + address.cyan.bold + ', '.yellow.bold + addressType + '>,'.yellow.bold + + ' connectable '.yellow.bold + connectable + ','.yellow.bold + + ' RSSI '.yellow.bold + rssi + ')'.yellow.bold); } else { - console.log('refreshed advertisement for ' + peripheralId + ' (' + advertisement.localName +')'); + console.log('refreshed advertisement for '.yellow.bold + peripheralId.cyan.bold + ' ('.yellow.bold + advertisement.localName +')'.yellow.bold); + } + */ + + //Modified + if (!isRefreshed) { + console.log('\n-----------------------------------------------------------------------------------------'.white.bold) + console.log('[+]'.green.bold + 'New Peripheral Discovered: '.yellow.bold + peripheralId.cyan.bold); + console.log('\tMAC Address: '.yellow.bold + address.cyan.bold + ', '.yellow.bold + addressType + '>'.yellow.bold); + console.log('\tConnectable: '.yellow.bold + connectable); + console.log('\tRSSI: '.yellow.bold + rssi); + } else { + console.log('Refreshed advertisement for '.yellow.bold + peripheralId.cyan.bold + ' ('.yellow.bold + advertisement.localName +')'.yellow.bold); } if (address.substring(0,8) === 'ec:fe:7e') { - console.log('BlueRadios MAC address - check AT commands service by blueRadiosCmd script!'.red) + console.log('BlueRadios MAC address - check AT commands service by blueRadiosCmd script!'.red.bold) } if (advertisement.localName) { - console.log('\tName: ' + advertisement.localName); + console.log('\tName: '.yellow.bold + advertisement.localName); } if (advertisement.eir){ - console.log('\tEIR: ' + advertisement.eir.toString('hex') + ' (' + hex2a(advertisement.eir.toString('hex'))+')'); + console.log('\tEIR: '.yellow.bold + advertisement.eir.toString('hex') + ' ('.yellow.bold + hex2a(advertisement.eir.toString('hex'))+')'.yellow.bold); } if (advertisement.scanResponse){ - console.log('\tScan response: ' + advertisement.scanResponse.toString('hex') + ' (' + hex2a(advertisement.scanResponse.toString('hex'))+')'); + console.log('\tScan response: '.yellow.bold + advertisement.scanResponse.toString('hex') + ' ('.yellow.bold + hex2a(advertisement.scanResponse.toString('hex'))+')'.yellow.bold); } console.log(); } @@ -91,11 +104,41 @@ function checkAdvertisement(peripheralId, advertisement, callback){ } +/////////Added to time stamps during a scan - Freilich +function getDateTime() { + + var date = new Date(); + + var hour = date.getHours(); + hour = (hour < 10 ? "0" : "") + hour; + + var min = date.getMinutes(); + min = (min < 10 ? "0" : "") + min; + + var sec = date.getSeconds(); + sec = (sec < 10 ? "0" : "") + sec; + + var msec = date.getMilliseconds(); + msec = (msec < 100 ? "0" : "") + msec; + + var year = date.getFullYear(); + + var month = date.getMonth() + 1; + month = (month < 10 ? "0" : "") + month; + + var day = date.getDate(); + day = (day < 10 ? "0" : "") + day; + + return year + "." + month + "." + day + " " + hour + ":" + min + ":" + sec + '.' + msec; + +} +///// function saveAdvertisement(peripheralId, address, addressType, connectable, advertisement, rssi) { checkAdvertisement(peripheralId, advertisement, function(newAdv){ if (newAdv === 'same' ) { - console.log('already saved advertisement for ' + peripheralId + ' (' + advertisement.localName +')'); + console.log('\n-----------------------------------------------------------------------------------------'.white.bold) + console.log('['.green.bold + '*'.yellow.bold + ']'.green.bold + 'Previously Discovered & Saved Advertisement For: '.yellow.bold + peripheralId.cyan.bold + ' ('.yellow.bold + advertisement.localName +')'.yellow.bold + getDateTime().bgCyan.bold); //no-op return } else { @@ -143,7 +186,7 @@ function saveAdvertisement(peripheralId, address, addressType, connectable, adve if(err) { return console.log(err); } - console.log("advertisement saved: "+ fileName ); + console.log('[+]'.green.bold + "Advertisement saved: ".yellow.bold+ fileName ); }); }