-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanPolicyDecode.command
More file actions
executable file
·157 lines (146 loc) · 3.79 KB
/
Copy pathScanPolicyDecode.command
File metadata and controls
executable file
·157 lines (146 loc) · 3.79 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/usr/bin/env python3
import sys, os, re
oc_list = {'1': "OC_SCAN_FILE_SYSTEM_LOCK",
'2': "OC_SCAN_DEVICE_LOCK",
'256': "OC_SCAN_ALLOW_FS_APFS",
'512': "OC_SCAN_ALLOW_FS_HFS",
'1024': "OC_SCAN_ALLOW_FS_ESP",
'2048': "OC_SCAN_ALLOW_FS_NTFS",
'4096': "OC_SCAN_ALLOW_FS_LINUX_ROOT",
'8192': "OC_SCAN_ALLOW_FS_LINUX_DATA",
'16384': "OC_SCAN_ALLOW_FS_XBOOTLDR",
'65536': "OC_SCAN_ALLOW_DEVICE_SATA",
'131072': "OC_SCAN_ALLOW_DEVICE_SASEX",
'262144': "OC_SCAN_ALLOW_DEVICE_SCSI",
'524288': "OC_SCAN_ALLOW_DEVICE_NVME",
'1048576': "OC_SCAN_ALLOW_DEVICE_ATAPI",
'2097152': "OC_SCAN_ALLOW_DEVICE_USB",
'4194304': "OC_SCAN_ALLOW_DEVICE_FIREWIRE",
'8388608': "OC_SCAN_ALLOW_DEVICE_SDCARD",
'16777216': "OC_SCAN_ALLOW_DEVICE_PCI"
}
def cls():
os.system('cls' if os.name=='nt' else 'clear')
def grab(prompt = ""):
if sys.version_info >= (3, 0):
return input(prompt)
else:
return str(raw_input(prompt))
def _check_hex(hex_string):
# Remove 0x/0X
hex_string = hex_string.replace("0x", "").replace("0X", "")
hex_string = re.sub(r'[^0-9A-Fa-f]+', '', hex_string)
return hex_string
def hex_to_dec(hex_string):
hex_string = _check_hex(hex_string)
if not len(hex_string):
return None
try:
dec = int(hex_string, 16)
except:
return None
return dec
def hex_to_vals(hex_string):
# Convert the hex to decimal string - then start with a reversed list
# and find out which values we have enabled
dec = hex_to_dec(hex_string)
if not dec:
return []
has = []
for key in sorted(oc_list, key=lambda x:int(x), reverse=True):
if int(key) <= dec:
has.append(oc_list[str(key)])
dec -= int(key)
return has
def main():
cls()
print("# ScanPolicyDecode #")
print("")
print("1. Hex To Values")
print("2. Values to Hex")
print("")
print("Q. Quit")
print("")
menu = grab("Please select an option: ").lower()
if not len(menu):
return
if menu == "q":
exit()
elif menu == "1":
h_to_v()
elif menu == "2":
v_to_h()
return
def h_to_v():
cls()
print("# ScanPolicy Hex To Values #")
print("")
while True:
h = grab("Please type a ScanPolicy value in hex (m for main menu): ")
if not h:
continue
if h.lower() == "m":
return
elif h.lower() == "q":
exit()
has = hex_to_vals(h)
if not len(has):
print("\nNo values found.\n")
else:
nl = '\n' #che porcata sta cosa, ma vabbe, thx python
print(f"""{nl}Active values:{nl}{nl}{nl.join(has)}{nl}""")
def v_to_h():
# Create a dict with all values unchecked
toggle_dict = []
for x in sorted(oc_list, key=lambda x:int(x)):
toggle_dict.append({"value":int(x),"enabled":False,"name":oc_list[x]})
while True:
cls()
print("# ScanPolicy Values To Hex #")
print("")
# Print them out
for x,y in enumerate(toggle_dict,1):
print(f"""[{"#" if y["enabled"] else " "}] {x}. {y["name"]} - {hex(y["value"])}""")
print("")
# Add the values of the enabled together
curr = 0
for x in toggle_dict:
if not x["enabled"]:
continue
curr += x["value"]
print(f"Current: {hex(curr)} / {curr}")
print("")
print("A. Select All")
print("N. Select None")
print("M. Main Menu")
print("Q. Quit")
print("")
print("Select options to toggle with comma-delimited lists (eg. 1,2,3,4,5)")
print("")
menu = grab("Please make your selection: ").lower()
if not len(menu):
continue
if menu == "m":
return
elif menu == "q":
exit()
elif menu == "a":
for x in toggle_dict:
x["enabled"] = True
continue
elif menu == "n":
for x in toggle_dict:
x["enabled"] = False
continue
# Should be numbers
try:
nums = [int(x) for x in menu.replace(" ","").split(",")]
for x in nums:
if x < 1 or x > len(toggle_dict):
# Out of bounds - skip
continue
toggle_dict[x-1]["enabled"] ^= True
except:
continue
while True:
main()