Skip to content

Instantly share code, notes, and snippets.

@wwj718
Last active November 5, 2023 14:19
Show Gist options
  • Save wwj718/a7aa7a2e6d5f44681983f1277092a1a7 to your computer and use it in GitHub Desktop.
Save wwj718/a7aa7a2e6d5f44681983f1277092a1a7 to your computer and use it in GitHub Desktop.
# https://chat.openai.com/share/b8bad6c7-9c24-4b1f-ad09-8de6d63588f5
# 逆向安卓代码
import asyncio
from bleak import BleakScanner
# iOS, Andriod
octo_uuids = {
"iOS": "2540b6b0-0002-4538-bcd7-7ecfb51297c1",
"Andriod": "2540b6b0-0001-4538-bcd7-7ecfb51297c1",
}
_shape_map = {
"0": "circle",
"1": "square",
"2": "star",
"3": "heart",
"4": "triangle",
}
received_datas = set()
def detection_callback(device, advertisement_data):
shape_id = None
# print("local_name: ", advertisement_data.local_name)
# print("platform_data: ", advertisement_data.platform_data)
if advertisement_data.local_name:
data = advertisement_data.local_name
if (
data not in [None, "0" * 16]
and len(data) == 16
and data not in received_datas
):
# iOS
print("iOS data: ", data) # eg: iOS data: BA957F3000000004
shape_id = data[-1]
received_datas.add(data)
if advertisement_data.service_data:
data = advertisement_data.service_data.get(octo_uuids["Andriod"])
if data:
pass
# for debugging
# print("android platform_data:", advertisement_data.platform_data)
if data and len(data) == 13 and data not in received_datas: # bytes
# Android
# print(data)
print("Android data(hex string): ", data.hex()) # eg: Android data(hex string): 73139737000000040000000000
shape_id = str((data[7])) # 3
received_datas.add(data)
if shape_id:
print("shape: ", _shape_map.get(shape_id))
# print(advertisement_data.platform_data)
async def run():
stop_event = asyncio.Event()
async with BleakScanner(
# detection_callback, service_uuids=octo_uuids.values()
detection_callback
) as scanner:
await stop_event.wait()
if __name__ == "__main__":
asyncio.run(run())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment