Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 85 additions & 43 deletions pwndroid.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import time
import logging
import requests
import subprocess
Expand All @@ -22,6 +23,8 @@ def __init__(self):
self.running = False
self.coordinates = dict()
self.options = dict()
self.last_update_time = 0
self.update_interval = 120

def on_loaded(self):
logging.info("[PwnDroid] Plugin loaded")
Expand All @@ -31,6 +34,7 @@ def on_ready(self, agent):
while True:
if (subprocess.run(['bluetoothctl', 'info'], capture_output=True, text=True)).stdout.find('Connected: yes') != -1:
self.running = True
self.last_update_time = time.time()
return False

def get_location_data(self, server_url):
Expand Down Expand Up @@ -83,62 +87,100 @@ def on_ui_setup(self, ui):
lat_pos = (pos[0] + 5, pos[1])
lon_pos = (pos[0], pos[1] + line_spacing)
alt_pos = (pos[0] + 5, pos[1] + (2 * line_spacing))
spd_pos = (pos[0], pos[1] + (3 * line_spacing))
except Exception:
# Set default value based on display type
lat_pos = (127, 64)
lon_pos = (127, 74)
alt_pos = (127, 84)

ui.add_element(
"latitude",
LabeledValue(
color=BLACK,
label="lat:",
value="-",
position=lat_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)
ui.add_element(
"longitude",
LabeledValue(
color=BLACK,
label="long:",
value="-",
position=lon_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)
ui.add_element(
"altitude",
LabeledValue(
color=BLACK,
label="alt:",
value="-",
position=alt_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)
spd_pos = (127, 94)
if self.options['lat']:
ui.add_element(
"latitude",
LabeledValue(
color=BLACK,
label="lat:",
value="-",
position=lat_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)
if self.options['long']:
ui.add_element(
"longitude",
LabeledValue(
color=BLACK,
label="long:",
value="-",
position=lon_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)
if self.options['alt']:
ui.add_element(
"altitude",
LabeledValue(
color=BLACK,
label="alt:",
value="-",
position=alt_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)
if self.options['spd']:
ui.add_element(
"speed",
LabeledValue(
color=BLACK,
label="spd:",
value="-",
position=spd_pos,
label_font=fonts.Small,
text_font=fonts.Small,
label_spacing=self.LABEL_SPACING,
),
)

def on_unload(self, ui):
with ui._lock:
ui.remove_element('latitude')
ui.remove_element('longitude')
ui.remove_element('altitude')
if self.options['lat']:
ui.remove_element('latitude')
if self.options['long']:
ui.remove_element('longitude')
if self.options['alt']:
ui.remove_element('altitude')
if self.options['spd']:
ui.remove_element('speed')

def on_ui_update(self, ui):
"""Update the UI elements and fetch new coordinates if the interval has passed."""
if self.options['display']:
current_time = time.time()
if self.running and current_time - self.last_update_time >= self.update_interval:
server_url = f"http://192.168.44.1:8080"
location_data = self.get_location_data(server_url)
if location_data:
self.coordinates = location_data
logging.info("[PwnDroid] Updated coordinates successfully.")
else:
logging.info("[PwnDroid] Failed to retrieve updated coordinates.")
self.last_update_time = current_time
with ui._lock:
if self.coordinates and all([
# avoid 0.000... measurements
self.coordinates["latitude"], self.coordinates["longitude"]
]):
ui.set("latitude", f"{self.coordinates['latitude']:.4f} ")
ui.set("longitude", f"{self.coordinates['longitude']:.4f} ")
ui.set("altitude", f"{self.coordinates['altitude']:.1f}m ")
if self.options['lat']:
ui.set("latitude", f"{self.coordinates['latitude']:.4f} ")
if self.options['long']:
ui.set("longitude", f"{self.coordinates['longitude']:.4f} ")
if self.options['alt']:
ui.set("altitude", f"{self.coordinates['altitude']:.1f}m ")
if self.options['spd']:
ui.set("speed", f"{self.coordinates['speed']:.1f}m ")