Remove temp files and dir when exit (#720)

pull/723/head
Bet4 6 years ago committed by GitHub
parent 64ca9a66cf
commit 08a78ad4b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -11,18 +11,17 @@ from __future__ import print_function
from __future__ import unicode_literals
import binascii
import errno as _errno
import os
import subprocess
import tempfile
import gdb
import pwndbg.qemu
import pwndbg.remote
import pwndbg.symbol
def get_file(path, recurse=1):
def get_file(path):
"""
Downloads the specified file from the system where the current process is
being debugged.
@ -32,10 +31,10 @@ def get_file(path, recurse=1):
"""
local_path = path
if pwndbg.qemu.root() and recurse:
if pwndbg.qemu.root():
return os.path.join(pwndbg.qemu.binfmt_root, path)
elif pwndbg.remote.is_remote() and not pwndbg.qemu.is_qemu():
local_path = tempfile.mktemp()
local_path = tempfile.mktemp(dir=pwndbg.symbol.remote_files_dir)
error = None
try:
error = gdb.execute('remote get "%s" "%s"' % (path, local_path),
@ -49,7 +48,7 @@ def get_file(path, recurse=1):
return local_path
def get(path, recurse=1):
def get(path):
"""
Retrieves the contents of the specified file on the system
where the current process is being debugged.
@ -57,7 +56,7 @@ def get(path, recurse=1):
Returns:
A byte array, or None.
"""
local_path = get_file(path, recurse)
local_path = get_file(path)
try:
with open(local_path,'rb') as f:

@ -14,6 +14,7 @@ from __future__ import unicode_literals
import os
import re
import shutil
import tempfile
import elftools.common.exceptions
@ -71,7 +72,9 @@ def reset_remote_files():
global remote_files
global remote_files_dir
remote_files = {}
remote_files_dir = tempfile.mkdtemp()
if remote_files_dir is not None:
shutil.rmtree(remote_files_dir)
remote_files_dir = None
@pwndbg.events.new_objfile
def autofetch():

Loading…
Cancel
Save