Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def read_mem(self, addr, rec=0):
try:
logging.debug(" [+] gdb.read addr [0x%x]: ... "% (addr))
r = self.gdb.write("x/xw %#x" % addr, timeout_sec=self.internal_timeout)[1].get('payload').split('\\t')[1].replace("\\n","")
logging.debug(" [+] gdb.read addr [0x%x]: %s "% (addr, r))
r = int(r,16)
return r
except (GdbTimeoutError,TypeError,ValueError,NoGdbProcessError,IndexError,AttributeError):
if (rec == 0):
logging.warning("Inconsistente GDB response. (GDB timeout or bad format). New try.")
self.read_mem(addr, rec=1)
else:
logging.warning("Inconsistente GDB response. (GDB timeout or bad format). Quit")
self.stop()
raise Exception("GDB timeout reached. Quit")
def read_and_forward_gdb_output():
"""A task that runs on a different thread, and emits websocket messages
of gdb responses"""
while True:
socketio.sleep(0.05)
controllers_to_remove = []
controller_items = _state.controller_to_client_ids.items()
for controller, client_ids in controller_items:
try:
try:
response = controller.get_gdb_response(
timeout_sec=0, raise_error_on_timeout=False
)
except NoGdbProcessError:
response = None
send_msg_to_clients(
client_ids,
"The underlying gdb process has been killed. This tab will no longer function as expected.",
error=True,
)
controllers_to_remove.append(controller)
if response:
for client_id in client_ids:
logger.info(
"emiting message to websocket client id " + client_id
)
socketio.emit(
"gdb_response",
response,