Last active
August 30, 2020 23:02
-
-
Save devilholk/959d33d10af4026a68a9cb757236008a to your computer and use it in GitHub Desktop.
Really uggly hack to get bluetooth snoop data from non rooted android. Will output raw data, pipe to hexeditor or file location.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess, base64, sys, time, struct, zlib | |
debug = False | |
#added stuff from https://android.googlesource.com/platform/system/bt/+/master/tools/scripts/btsnooz.py | |
def get_snoop(): | |
p = subprocess.Popen(('adb', 'shell', 'dumpsys', 'bluetooth_manager'), stdout=subprocess.PIPE) | |
stdout, stderr = p.communicate() | |
extract = False | |
complete = False | |
result = b'' | |
for l in stdout.split(b'\n'): | |
if l.startswith(b'--- BEGIN:BTSNOOP_LOG_SUMMARY'): | |
extract = True | |
elif l.startswith(b'--- END:BTSNOOP_LOG_SUMMARY'): | |
break | |
elif extract: | |
result += l | |
else: | |
print('Failed to parse') | |
return base64.standard_b64decode(result) | |
inflater = zlib.decompressobj() | |
compressed = b'' | |
while 1: | |
data = get_snoop() | |
version, last_timestamp_ms = struct.unpack_from('=bQ', data) | |
compressed += data[9:] | |
decompressed = inflater.decompress(compressed) | |
assert not inflater.unconsumed_tail | |
if inflater.eof: | |
compressed = inflater.unused_data | |
inflater = zlib.decompressobj() | |
if debug: | |
print('Created new decompression stream', file=sys.stderr) | |
if debug: | |
print(version, last_timestamp_ms, len(compressed), len(decompressed), file=sys.stderr) | |
sys.stdout.buffer.write(decompressed) | |
sys.stdout.buffer.flush() | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that if the summary is not present line 30 will fail, there should be a check for this.