From 7c16c403d5f2983eebf3f65fa6f30b406acbc536 Mon Sep 17 00:00:00 2001 From: Mike Auty Date: Tue, 23 Apr 2019 22:43:16 +0100 Subject: [PATCH] Ensure we delete the temorary file even if things go wrong. --- volatility/framework/automagic/pdbscan.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/volatility/framework/automagic/pdbscan.py b/volatility/framework/automagic/pdbscan.py index 4df8f8a66..1e94ecd83 100644 --- a/volatility/framework/automagic/pdbscan.py +++ b/volatility/framework/automagic/pdbscan.py @@ -212,15 +212,18 @@ class KernelPDBScanner(interfaces.automagic.AutomagicInterface): import json, lzma filename = pdb_isf.PDBRetreiver().retreive_pdb( guid = kernel['GUID'] + str(kernel['age']), file_name = kernel['pdb_name']) - json_output = pdb_isf.PDBConvertor(filename).read_pdb() - output_file = os.path.join(symbols.__path__[0], "windows", filter_string + ".json.xz") + try: + json_output = pdb_isf.PDBConvertor(filename).read_pdb() + output_file = os.path.join(symbols.__path__[0], "windows", filter_string + ".json.xz") - # Write the JSON file to disk - os.makedirs(os.path.dirname(output_file), exist_ok = True) - with lzma.open(output_file, "w") as f: - f.write(bytes(json.dumps(json_output, indent = 2, sort_keys = True), 'utf-8')) - # Clean up after ourselves - os.remove(filename) + # Write the JSON file to disk + os.makedirs(os.path.dirname(output_file), exist_ok = True) + # FIXME: If the directory is unwritable we should ideally write this to the cache location + with lzma.open(output_file, "w") as f: + f.write(bytes(json.dumps(json_output, indent = 2, sort_keys = True), 'utf-8')) + finally: + # Clean up after ourselves + os.remove(filename) # Try again for value in intermed.IntermediateSymbolTable.file_symbol_url("windows", filter_string):