-
-
Save erikng/407366fce4a3df6e1a5f8f44733f89ea to your computer and use it in GitHub Desktop.
gnes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/Library/ManagedFrameworks/Python/Python3.framework/Versions/Current/bin/python3 | |
"""Get status of network extension""" | |
from Foundation import NSBundle | |
import argparse | |
import objc | |
import platform | |
from pprint import pprint | |
from sys import stdout | |
def get_os_version(): | |
'''Return OS version.''' | |
return platform.mac_ver()[0] | |
def unsureWhatThisDoes(arg1, arg2): | |
global configs | |
configs = arg1 | |
def main(): | |
global configs | |
configs = None | |
"""Return status of network extension""" | |
parser = argparse.ArgumentParser( | |
description='A CLI tool for checking the status of a network extension.', | |
epilog='For further help, please contact it-eng-endpoint@uber.com' | |
) | |
# Custom arguments | |
parser.add_argument( | |
'-i', | |
'--identifier', | |
help='Network Extension identifier to check against' | |
) | |
args = parser.parse_known_args()[0] | |
identifier = args.identifier | |
enabled = False | |
if '13.' in get_os_version(): | |
try: | |
NetworkExtension = NSBundle.bundleWithPath_('/System/Library/Frameworks/NetworkExtension.framework') | |
NEProfileIngestion = NetworkExtension.classNamed_('NEProfileIngestion') | |
NEContentFilter = NetworkExtension.classNamed_('NEContentFilter') | |
NEHelper = NetworkExtension.classNamed_('NEHelper') | |
objc.registerMetaDataForSelector( | |
b"NEConfigurationManager", | |
b"loadConfigurationsWithCompletionQueue:handler:", | |
{ | |
"arguments": { | |
3: { | |
"type": b'@?', | |
"callable": { | |
"retval": {"type": b"v"}, | |
"arguments": { | |
0: {"type": b"^v"}, | |
1: {"type": b"@"}, | |
2: {"type": b"@"}, | |
}} | |
} | |
} | |
} | |
) | |
# pprint(dir(manager)) | |
NEConfigurationManager = NetworkExtension.classNamed_('NEConfigurationManager') | |
manager = NEConfigurationManager.sharedManager() | |
# err = NEProfileIngestion.loadConfigurationsForceReloadFromDisk | |
manager.initSynchronous() | |
manager.loadConfigurationsWithCompletionQueue_handler_(None, unsureWhatThisDoes) | |
if configs: | |
for index, key in enumerate(configs): | |
if key.application() == identifier: | |
if key.contentFilter(): | |
enabled = key.contentFilter().isEnabled() | |
except: | |
pass | |
else: | |
try: | |
NetworkExtension = NSBundle.bundleWithPath_('/System/Library/Frameworks/NetworkExtension.framework') | |
NEConfigurationManager = NetworkExtension.classNamed_('NEConfigurationManager') | |
manager = NEConfigurationManager.sharedManager() | |
err = manager.reloadFromDisk() | |
configs = manager.loadedConfigurations() | |
if configs: | |
for index, key in enumerate(configs): | |
config = configs[key] | |
if config.application() == identifier: | |
enabled = config.contentFilter().isEnabled() | |
except: | |
pass | |
stdout.write(str(bool(enabled))) | |
if __name__ == "__main__": | |
main() |
Author
erikng
commented
Jul 5, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment