forked from raymanfx/android-cve-checker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_patches.py
95 lines (66 loc) · 2.14 KB
/
check_patches.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import getopt
import os
import sys
# to query CVE list from Lineage tracker
import json
import requests
def parse_patches_from_tracker():
patches = []
URL = "https://cve.lineageos.org/api/cves"
response = requests.get(URL)
for key in response.json():
patches.append(key)
return patches
def find_missing_patches(patches, patches_dir):
missing_patches = {}
subdirs = [node for node in os.listdir(patches_dir)
if os.path.isdir(os.path.join(patches_dir, node))]
for subdir in subdirs:
missing_patches[subdir] = list()
for patch in patches:
patch_path = os.path.join(patches_dir, subdir, patch)
if not os.path.isfile(patch_path):
missing_patches[subdir].append(patch)
return missing_patches
"""
Print usage information about this program.
"""
def print_usage():
print("usage: check_patches.py <OPTIONS> patches_dir")
def main():
try:
opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
except getopt.GetoptError as err:
# print help information and exit
print(str(err))
print_usage()
sys.exit(2)
# check for required args
if len(sys.argv) != 2:
print("[E] Invalid number of args (required: 2, found: "
+ str(len(sys.argv)) + ")!")
print_usage()
sys.exit(2)
# directory containing the git patchfiles
patches_dir = sys.argv[-1]
for o, a in opts:
if o in ("-h", "--help"):
print_usage()
sys.exit()
else:
print("[E] unhandled option: " + o)
sys.exit(2)
if not patches_dir or not os.path.isdir(patches_dir):
print("[E] invalid patchfile directory: " + patches_dir)
return
# query CVE list from Lineage tracker
patches = parse_patches_from_tracker()
missing_patches = find_missing_patches(patches, patches_dir)
print("missing patchfiles:\n")
for subdir in missing_patches:
print(subdir)
for patch in sorted(missing_patches[subdir]):
print("\t" + patch)
print("")
if __name__ == "__main__":
main()