From 8498d784c4ddcbd0740d528e163a7e0276d1ef83 Mon Sep 17 00:00:00 2001 From: Jan Peter Stotz Date: Mon, 30 Oct 2023 16:48:29 +0100 Subject: [PATCH 1/3] fixed: print full, not truncated data on iOS --- frida/blemon.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/frida/blemon.js b/frida/blemon.js index af3a742..de27e50 100644 --- a/frida/blemon.js +++ b/frida/blemon.js @@ -33,12 +33,9 @@ if (Java.available) { var data = new ObjC.Object(args[2]); var CBChar = new ObjC.Object(args[3]); var dataBytes = Memory.readByteArray(data.bytes(), data.length()); - var b = new Uint8Array(dataBytes); - var hexData = ""; - for (var i = 0; i < b.length; i++) { - hexData += pad(b[i].toString(16), 2); - } - console.log(Color.Green + "[BLE Write =>]" + Color.Light.Black + " UUID: " + CBChar.$ivars['_UUID'] + Color.Reset + " data: 0x" + hexData); + var buf = new Uint8Array(dataBytes); + var hexData = `length=${data.length()} bytes=0x${buf2hex(buf)}`; + console.log(Color.Green + "[BLE Write =>]" + Color.Light.Black + " UUID: " + CBChar.$ivars['_UUID'] + Color.Reset + " data: " + hexData); } }); //end Interceptor Interceptor.attach(ObjC.classes.CBCharacteristic['- value'].implementation, { @@ -47,13 +44,14 @@ if (Java.available) { // turns <12 34> into 1234 var data = CBChar.$ivars['_value'] if (data != null) { - data = data.toString().replace(/ /g, '').slice(1, -1) + var buf = data.bytes().readByteArray(data.length()); + data = `length=${data.length()} bytes=0x${buf2hex(buf)}` } if (CBChar.$ivars['_isNotifying'] === true) { - console.log(Color.Cyan + "[BLE Notify <=]" + Color.Light.Black + " UUID: " + CBChar.$ivars['_UUID'] + Color.Reset + " data: 0x" + data); + console.log(Color.Cyan + "[BLE Notify <=]" + Color.Light.Black + " UUID: " + CBChar.$ivars['_UUID'] + Color.Reset + " data: " + data); } else { - console.log(Color.Blue + "[BLE Read <=]" + Color.Light.Black + " UUID: " + CBChar.$ivars['_UUID'] + Color.Reset + " data: 0x" + data); + console.log(Color.Blue + "[BLE Read <=]" + Color.Light.Black + " UUID: " + CBChar.$ivars['_UUID'] + Color.Reset + " data: " + data); } } }); //end Interceptor @@ -74,8 +72,13 @@ function bytes2hex(array) { result += ('0' + (array[i] & 0xFF).toString(16)).slice(-2); return result; }; +function buf2hex(buffer) { // buffer is an ArrayBuffer + return [...new Uint8Array(buffer)] + .map(x => x.toString(16).padStart(2, '0')) + .join(''); +} function pad(num, size) { var s = num + ""; while (s.length < size) s = "0" + s; return s; -} +} \ No newline at end of file From 1b570f7b90db02dac31c2800feeaef499f7d2c01 Mon Sep 17 00:00:00 2001 From: Jan Peter Stotz Date: Mon, 13 Nov 2023 11:27:51 +0100 Subject: [PATCH 2/3] bugfix: read value in setValue: onLeave --- frida/blemon.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frida/blemon.js b/frida/blemon.js index de27e50..05bbe73 100644 --- a/frida/blemon.js +++ b/frida/blemon.js @@ -38,10 +38,12 @@ if (Java.available) { console.log(Color.Green + "[BLE Write =>]" + Color.Light.Black + " UUID: " + CBChar.$ivars['_UUID'] + Color.Reset + " data: " + hexData); } }); //end Interceptor - Interceptor.attach(ObjC.classes.CBCharacteristic['- value'].implementation, { - onEnter: function (args) { - var CBChar = new ObjC.Object(args[0]); - // turns <12 34> into 1234 + Interceptor.attach(ObjC.classes.CBCharacteristic['- setValue:'].implementation, { + onEnter: function (args) { + this.CBChar = new ObjC.Object(args[0]); + }, + onLeave: function (retval) { + let CBChar = this.CBChar; var data = CBChar.$ivars['_value'] if (data != null) { var buf = data.bytes().readByteArray(data.length()); From cc303e25e08b9cbc3a86d8e0efcd8ce6543ba01f Mon Sep 17 00:00:00 2001 From: Jan Peter Stotz Date: Mon, 13 Nov 2023 11:34:40 +0100 Subject: [PATCH 3/3] use spaces for indentation --- frida/blemon.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/frida/blemon.js b/frida/blemon.js index 05bbe73..0be3b79 100644 --- a/frida/blemon.js +++ b/frida/blemon.js @@ -38,12 +38,12 @@ if (Java.available) { console.log(Color.Green + "[BLE Write =>]" + Color.Light.Black + " UUID: " + CBChar.$ivars['_UUID'] + Color.Reset + " data: " + hexData); } }); //end Interceptor - Interceptor.attach(ObjC.classes.CBCharacteristic['- setValue:'].implementation, { - onEnter: function (args) { - this.CBChar = new ObjC.Object(args[0]); - }, - onLeave: function (retval) { - let CBChar = this.CBChar; + Interceptor.attach(ObjC.classes.CBCharacteristic['- setValue:'].implementation, { + onEnter: function (args) { + this.CBChar = new ObjC.Object(args[0]); + }, + onLeave: function (retval) { + let CBChar = this.CBChar; var data = CBChar.$ivars['_value'] if (data != null) { var buf = data.bytes().readByteArray(data.length());