-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathmerge_packages.py
More file actions
59 lines (50 loc) · 1.6 KB
/
Copy pathmerge_packages.py
File metadata and controls
59 lines (50 loc) · 1.6 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# merge_packages script
# v0.10 BETA
# Merges two or more MAEC Package documents (.xml files)
# Attempts to merge related Malware Subjects
import sys
import os
import maec
from maec.utils.merge import merge_documents
USAGE_TEXT = """
MAEC Package Merge Script v0.10 BETA
*Merges two or more MAEC Package XML documents
*Attempts to merge related (e.g., same MD5 hash) Malware Subjects
Usage: python merge_packages.py -o <output file name> -l <single whitespace separated list of MAEC Package files> OR -d <directory name>
"""
def main():
infilenames = []
list_mode = False
directoryname = ''
outfilename = ''
#Get the command-line arguments
args = sys.argv[1:]
if len(args) < 3:
print USAGE_TEXT
sys.exit(1)
for i in range(0,len(args)):
if args[i] == '-o':
outfilename = args[i+1]
elif args[i] == '-l':
list_mode = True
elif args[i] == '-d':
directoryname = args[i+1]
if outfilename == '':
print USAGE_TEXT
sys.exit(1)
sys.stdout.write("Merging...")
# Get the list of input files and perform the merge operation
if list_mode:
files = args[3:]
merge_documents(files, outfilename)
elif directoryname != '':
file_list = []
for filename in os.listdir(directoryname):
if '.xml' not in filename:
pass
else:
file_list.append(os.path.join(directoryname, filename))
merge_documents(file_list, outfilename)
sys.stdout.write("Done.")
if __name__ == "__main__":
main()