File size: 1,047 Bytes
baeb5f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df1cef8
 
baeb5f8
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import zipfile
import json
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--filepath", help="Specify a filepath to an agent's zip file, .zip extension required.", type=str, required=True)
parser.add_argument("-s", "--savefile", help="Specify a name and location for the saved configuration file. Will be saved in .json format.", default="config")
args = parser.parse_args()

filepath = args.filepath
savefile = args.savefile

archive = zipfile.ZipFile(filepath, "r")
file = archive.open("data")
json_file = json.loads(file.read().decode("utf-8"))

# Only want to remove serialized objects from dictionary
val_to_remove = ":serialized:"

for key in json_file.keys():
    # So if each value is a type dict, then I want to iterate through it and remove the serialized key
    if type(json_file[key]) is dict:
        if val_to_remove in json_file[key].keys():
            json_file[key].pop(val_to_remove)

with open(f"{savefile}.json", "w") as outfile:
    outfile.write(json.dumps(json_file, indent=2))

file.close()