def unload_enclave_symbol(enclave_path, enclave_base_addr): if os.path.exists(enclave_path) == True: enclave_path = os.path.abspath(enclave_path) else: enclave_path = target_path_to_host_path(enclave_path) gdb_cmd = load_symbol_cmd.GetUnloadSymbolCommand(enclave_path, str(enclave_base_addr)) if gdb_cmd == -1: print ("Can't get symbol unloading command.") return False # print (gdb_cmd) gdb.execute(gdb_cmd, False, True) global g_loaded_oe_enclave_addrs g_loaded_oe_enclave_addrs.discard(int(gdb_cmd.split()[2])) return True
def fini_enclave_debug(self): # If it is HW product enclave, nothing to do if (self.enclave_type & ET_SIM) != ET_SIM and (self.enclave_type & ET_DEBUG) != ET_DEBUG: return -2 self.show_emmt() try: # clear TCS debug flag for tcs_addr in self.tcs_addr_list: string = read_from_memory(tcs_addr + 8, 4) if string == None: return -2 flag = struct.unpack('I', string)[0] flag &= (~1) gdb_cmd = "set *(unsigned int *)%#x = %#x" % (tcs_addr + 8, flag) gdb.execute(gdb_cmd, False, True) #unload symbol if os.path.exists(self.enclave_path) == True: enclave_path = self.enclave_path else: enclave_path = target_path_to_host_path(self.enclave_path) gdb_cmd = load_symbol_cmd.GetUnloadSymbolCommand( enclave_path, str(self.start_addr)) if gdb_cmd == -1: return -1 print(gdb_cmd) try: gdb.execute(gdb_cmd, False, True) global ENCLAVES_ADDR del ENCLAVES_ADDR[self.start_addr] except gdb.error: print("Old gdb doesn't support remove-file-symbol command") return 0 ##It is possible enclave has been destroyed, so may raise exception on memory access except gdb.MemoryError: return -1 except: return -1