-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathmerge_packages.py
More file actions
executable file
·50 lines (46 loc) · 1.55 KB
/
merge_packages.py
File metadata and controls
executable file
·50 lines (46 loc) · 1.55 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
# 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 argparse
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
"""
def main():
parser = argparse.ArgumentParser(description=USAGE_TEXT)
mutex_group = parser.add_mutually_exclusive_group(required=True)
required_group = parser.add_argument_group('required arguments')
mutex_group.add_argument(
'-l', '--list', nargs='+',
help='single whitespace separated list of MAEC Package files'
)
mutex_group.add_argument(
'-d', '--directory',
help='directory name'
)
required_group.add_argument(
'-o', '--output', required=True,
help='output file name'
)
args = parser.parse_args()
sys.stdout.write("Merging...")
# Get the list of input files and perform the merge operation
if args.list:
merge_documents(args.list, args.output)
elif args.directory:
file_list = []
for filename in os.listdir(args.directory):
if '.xml' not in filename:
pass
else:
file_list.append(os.path.join(args.directory, filename))
merge_documents(file_list, args.output)
sys.stdout.write("Done.")
if __name__ == "__main__":
main()