Skip to content

Commit

Permalink
Cleaning up print inside the python script
Browse files Browse the repository at this point in the history
  • Loading branch information
gilanghamidy committed Oct 28, 2022
1 parent 8d4b671 commit 790672c
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions sdk/debugger_interface/linux/gdb-sgx-plugin/gdb_sgx_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ def fini_enclave_debug(self):
# Delete the dumped enclave if any
global DUMPED_ENCLAVE
if self.enclave_path in DUMPED_ENCLAVE:
print ("Free-ing pointer {0}".format(DUMPED_ENCLAVE[self.enclave_path]))
gdb.execute("call (void)free({0})".format(DUMPED_ENCLAVE[self.enclave_path]))
os.remove(self.enclave_path)
del DUMPED_ENCLAVE[self.enclave_path]
Expand Down Expand Up @@ -396,7 +395,7 @@ def retrieve_enclave_info(info_addr = 0):
if name_str == None:
return None
fmt = str(info_tuple[4]) + 's'
enclave_path = struct.unpack_from(fmt, name_str)[0].decode(encoding='UTF-8')
enclave_path = struct.unpack_from(fmt, name_str)[0].decode(encoding='UTF-8')
# get the stack addr list
stack_addr_list = []
tcs_addr_list = []
Expand Down Expand Up @@ -706,12 +705,11 @@ def __init__(self):
def stop(self):
bp_in_urts = is_bp_in_urts()
if bp_in_urts == True:
print ("_create_enclave_from_buffer_ex")
# Get se_file_t pointer (4th parameter)
file_addr = gdb.parse_and_eval("$rcx")
file_str = read_from_memory(file_addr, 8 + 2*4)
file_tuple = struct.unpack_from("QII", file_str)
print ("File: " + str(file_tuple[1]))

if file_tuple[1] == 0:
# If it is null, then it does not have a file. So we dump the buffer

Expand All @@ -723,24 +721,20 @@ def stop(self):
f = open(dump_name, "wb")
f.write(bytearray(enclave_bin))
f.close()
print ("Done dumping")

# patch the file to malloc'ed buffer
str_filepath_buf = gdb.execute("call (void*)malloc({0})".format(len(dump_name) + 1), False, True)
str_filepath_buf = int(re.search(r"0x[0-9a-f]+", str_filepath_buf).group(), 16)
print ("Got malloc {0}".format(str_filepath_buf))
filepath_bytes = bytearray()
filepath_bytes.extend(map(ord, dump_name))
filepath_bytes.extend(bytes(0))
write_to_memory(str_filepath_buf, filepath_bytes)
print ("Done writing filename")
write_to_memory(file_addr, struct.pack('QII', str_filepath_buf, len(dump_name), 0))

# Store the malloc-ed pointer
global DUMPED_ENCLAVE
DUMPED_ENCLAVE[dump_name] = str_filepath_buf

print ("Done patching")
return False

def sgx_debugger_init():
Expand Down

0 comments on commit 790672c

Please sign in to comment.