Skip to content

Commit

Permalink
use random UI port
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiChou committed Oct 18, 2024
1 parent 221856d commit f44bcec
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions frida_tools/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import binascii
import codecs
import email.utils
import errno
import gzip
import http
import mimetypes
Expand Down Expand Up @@ -43,7 +42,7 @@ class TracerApplication(ConsoleApplication, UI):
def __init__(self) -> None:
super().__init__(await_ctrl_c)
self._handlers = OrderedDict()
self._ui_port = 1337
self._ui_port = 0
self._ui_zip = ZipFile(Path(__file__).parent / "tracer_ui.zip", "r")
self._ui_socket_handlers: Set[UISocketHandler] = set()
self._ui_worker = None
Expand Down Expand Up @@ -306,21 +305,14 @@ def _run_ui_server(self):

async def _handle_ui_requests(self):
self._asyncio_loop = asyncio.get_running_loop()
while True:
try:
async with websockets.asyncio.server.serve(
self._handle_websocket_connection,
"localhost",
self._ui_port,
process_request=self._handle_asset_request,
):
await asyncio.get_running_loop().create_future()
return
except OSError as e:
if e.errno == errno.EADDRINUSE:
self._ui_port += 1
else:
raise
async with websockets.asyncio.server.serve(
self._handle_websocket_connection,
"localhost",
process_request=self._handle_asset_request,
) as server:
self._ui_port = server.sockets[0].getsockname()[1]
await asyncio.get_running_loop().create_future()
return

async def _handle_websocket_connection(self, websocket: websockets.asyncio.server.ServerConnection):
if self._tracer is None:
Expand Down

0 comments on commit f44bcec

Please sign in to comment.