; Copyright (C) 2022 Apple Inc. All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
; 1. Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; 2. Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
; THE POSSIBILITY OF SUCH DAMAGE.
; Copyright (C) 2022 Apple Inc. All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
; 1. Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; 2. Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
; THE POSSIBILITY OF SUCH DAMAGE.
(version 1)
(deny default)
(deny nvram*)
(deny system-privilege)
(allow system-audit file-read-metadata)
;; Silence spurious logging due to rdar:
(deny system-privilege (privilege-id PRIV_GLOBAL_PROC_INFO) (with no-report))
;; Sandbox extensions
(define (apply-read-and-issue-extension op path-filter)
    (op file-read* path-filter)
    (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") path-filter)))
(define (apply-write-and-issue-extension op path-filter)
    (op file-write* path-filter)
    (op file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") path-filter)))
(define (read-only-and-issue-extensions path-filter)
    (apply-read-and-issue-extension allow path-filter))
(define (read-write-and-issue-extensions path-filter)
    (apply-read-and-issue-extension allow path-filter)
    (apply-write-and-issue-extension allow path-filter))
(define (webcontent-process-launched)
    (state-flag "local:WebContentProcessLaunched"))
(define (notify-blocking) (require-entitlement "com.apple.developer.web-browser-engine.restrict.notifyd"))
;; Utility functions for home directory relative path filters
(define (home-regex home-relative-regex)
    (regex (string-append "^" (regex-quote (param "HOME_DIR")) home-relative-regex)))
(define (home-subpath home-relative-subpath)
    (subpath (string-append (param "HOME_DIR") home-relative-subpath)))
(define (home-literal home-relative-literal)
    (literal (string-append (param "HOME_DIR") home-relative-literal)))
; Copyright (C) 2021 Apple Inc. All rights reserved.
;
; Redistribution and use in source and binary forms, with or without
; modification, are permitted provided that the following conditions
; are met:
; 1. Redistributions of source code must retain the above copyright
; notice, this list of conditions and the following disclaimer.
; 2. Redistributions in binary form must reproduce the above copyright
; notice, this list of conditions and the following disclaimer in the
; documentation and/or other materials provided with the distribution.
;
; THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
; THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
; PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
; BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
; THE POSSIBILITY OF SUCH DAMAGE.
(define (home-library-preferences-regex home-library-preferences-relative-regex)
    (regex (string-append "^" (regex-quote (param "HOME_LIBRARY_PREFERENCES_DIR")) home-library-preferences-relative-regex)))
(define (home-library-preferences-literal home-library-preferences-relative-literal)
    (literal (string-append (param "HOME_LIBRARY_PREFERENCES_DIR") home-library-preferences-relative-literal)))
(define (shared-preferences-read . domains)
    (for-each (lambda (domain)
        (begin
            (allow user-preference-read
            (with telemetry)
            (preference-domain domain))
            (allow file-read*
                (literal (string-append "/Library/Preferences/" domain ".plist"))
                (home-library-preferences-literal (string-append "/" domain ".plist"))
                (home-library-preferences-regex (string-append #"/ByHost/" (regex-quote domain) #"\..*\.plist$")))))
        domains))
(define (allow-reading-global-preferences)
    (allow user-preference-read (preference-domain "kCFPreferencesAnyApplication"))
    (allow file-read*
        (literal "/Library/Preferences/.GlobalPreferences.plist")
        (home-subpath "/Library/Preferences/.GlobalPreferences.plist")
        (home-subpath "/Library/Preferences/.GlobalPreferences_m.plist")
        (home-regex #"/Library/Preferences/ByHost/\.GlobalPreferences\..*\.plist$")
    )
)
(define (lockdown-mode)
    (require-not (require-entitlement "com.apple.security.cs.allow-jit")))
(define (webcontent_gpu_sandbox_extensions_blocking)
    #f
)
(allow mach-register
    (local-name
        "com.apple.axserver"
        "com.apple.tsm.portname"))
(allow file-read*
    (require-all (file-mode #o0004)
    (require-any (subpath "/Library/Filesystems/NetFSPlugins")
    (subpath "/Library/Apple/System")
    (subpath "/Library/Preferences/Logging")
    (subpath "/System")
    (subpath "/private/var/db/timezone")
    (subpath "/usr/lib")
    (subpath "/usr/share"))))
(allow file-read*
    (require-all (file-mode #o0004)
    (subpath "/AppleInternal/Library/Preferences/Logging")
    (system-attribute apple-internal)))
(allow file-map-executable
    (subpath "/Library/Apple/System/Library/Frameworks")
    (subpath "/Library/Apple/System/Library/PrivateFrameworks")
    (subpath "/System/Library/Frameworks")
    (subpath "/System/Library/PrivateFrameworks")
    (subpath "/usr/lib")
    (subpath "/usr/local/lib/sanitizers")
    (subpath "/usr/appleinternal/lib")
)
(allow file-read-metadata
    (literal "/etc")
    (literal "/tmp")
    (literal "/var")
    (literal "/private/etc/localtime"))
(allow file-read*
    (literal "/dev/autofs_nowait")
    (literal "/dev/random")
    (literal "/dev/urandom")
    (literal "/private/etc/master.passwd")
    (literal "/private/etc/passwd")
)
(allow file-read*
       file-write-data
    (literal "/dev/null")
    (literal "/dev/zero"))
(allow file-read*
       file-write-data
       file-ioctl
    (require-all
        (literal "/dev/dtracehelper")
        (require-any
            (csr CSR_ALLOW_APPLE_INTERNAL)
            (csr CSR_ALLOW_UNRESTRICTED_DTRACE)))
)
(allow file-write-create
    (require-all (prefix "/cores/")
        (vnode-type REGULAR-FILE)))
(define (IOAcceleratorMessageFilter)
    (apply-message-filter
        (deny (with message "IOAccelerator")
            iokit-async-external-method
            iokit-external-method)
        (allow iokit-async-external-method
        )
        (allow iokit-external-method
        )
        (deny iokit-external-trap)
    ))
(define (IOSurfaceRootUserClientMessageFilter)
    (apply-message-filter
        (deny (with message "IOSurfaceRootUserClient")
            iokit-async-external-method
            iokit-external-method)
        (allow iokit-async-external-method
        )
        (allow iokit-external-method
        )
        (allow iokit-external-trap)
    ))
(define (AppleAVDUserClientMessageFilter)
    (apply-message-filter
        (deny (with message "AppleAVDUserClient")
            iokit-async-external-method
            iokit-external-method
            iokit-external-trap)))
(define (IOSurfaceAcceleratorClientMessageFilter)
    (apply-message-filter
        (deny (with message "IOSurfaceAcceleratorClient")
            iokit-async-external-method
            iokit-external-trap)
        (allow iokit-external-method
            (iokit-method-number 1)
            )))
(define (IOMobileFramebufferUserClientMessageFilter)
    (apply-message-filter
        (deny (with message "IOMobileFramebufferUserClient")
            iokit-async-external-method
            iokit-external-trap)
        (allow iokit-external-method
            (iokit-method-number 8 28)
            )))
(define (system-graphics)
    (allow user-preference-read
        (preference-domain "com.apple.opengl")
        (preference-domain "com.nvidia.OpenGL"))
    (deny mach-lookup
        (with telemetry-backtrace)
        (global-name "com.apple.cvmsServ"))
    (deny file-read*
        (prefix "/private/var/db/CVMS/cvmsCodeSignObj"))
    (when (not (webcontent_gpu_sandbox_extensions_blocking))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "IOAccelerator"))
            (IOAcceleratorMessageFilter))
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "IOAccelerator"))))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "IOAccelerationUserClient"))
            (apply-message-filter
                (deny
                    iokit-async-external-method
                    iokit-external-trap
                    iokit-external-method)))
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "IOAccelerationUserClient"))))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "IOSurfaceRootUserClient"))
            (IOSurfaceRootUserClientMessageFilter))
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "IOSurfaceRootUserClient"))))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "AppleIntelMEUserClient"))
            (apply-message-filter
                (deny (with message "AppleIntelMEUserClient") iokit-external-method)
                (allow iokit-external-method
                    (iokit-method-number 120)
                    )
                (deny
                    iokit-async-external-method
                    iokit-external-trap)))
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "AppleIntelMEUserClient"))))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "AppleSNBFBUserClient"))
            (apply-message-filter
                (deny (with message "AppleSNBFBUserClient") iokit-external-method)
                (allow iokit-external-method
                    (iokit-method-number 120)
                    )
                (deny
                    iokit-async-external-method
                    iokit-external-trap)))
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "AppleSNBFBUserClient")))))
    (deny iokit-open (with no-report)
        (iokit-registry-entry-class "AGPMClient"))
    (when (not (webcontent_gpu_sandbox_extensions_blocking))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "AppleGraphicsControlClient"))
            (apply-message-filter
                (deny (with message "AppleGraphicsControlClient")
                    iokit-async-external-method
                    iokit-external-method)
                (allow iokit-external-method
                    (iokit-method-number 0 1 3 11)
                    )
                (deny iokit-external-trap)))
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "AppleGraphicsControlClient"))))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "AppleGraphicsPolicyClient"))
            (apply-message-filter
                (deny
                    iokit-async-external-method
                    iokit-external-trap
                    iokit-external-method)))
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "AppleGraphicsPolicyClient"))))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "AppleMGPUPowerControlClient"))
            (apply-message-filter
                (deny (with message "AppleMGPUPowerControlClient") iokit-external-method)
                (allow iokit-external-method
                    (iokit-method-number 0 1 3)
                    )
                (deny
                    iokit-async-external-method
                    iokit-external-trap)))
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-registry-entry-class "AppleMGPUPowerControlClient")))))
    (allow file-read*
        (subpath "/Library/GPUBundles")))
(deny process-info*)
(allow process-info-pidinfo (target self))
(allow process-info-setcontrol (target self))
(allow process-info-dirtycontrol (target self))
(allow process-codesigning-status* (target self))
(deny sysctl*)
(allow sysctl-read
    (sysctl-name
        "hw.activecpu"
        "hw.availcpu"
        "hw.byteorder"
        "hw.busfrequency"
        "hw.busfrequency_max"
        "hw.cacheconfig"
        "hw.cachelinesize"
        "hw.cachesize"
        "hw.cpufamily"
        "hw.cpufrequency"
        "hw.cpufrequency_max"
        "hw.cpusubfamily"
        "hw.cputhreadtype"
        "hw.cputype"
        "hw.l1dcachesize"
        "hw.l1icachesize"
        "hw.l2cachesize"
        "hw.l3cachesize"
        "hw.logicalcpu"
        "hw.logicalcpu_max"
        "hw.machine"
        "hw.memsize"
        "hw.model"
        "hw.ncpu"
        "hw.nperflevels"
        "hw.pagesize"
        "hw.pagesize_compat"
        "hw.physicalcpu"
        "hw.physicalcpu_max"
        "hw.tbfrequency"
        "hw.tbfrequency_compat"
        "hw.vectorunit"
        "kern.bootargs"
        "kern.hostname"
        "kern.hv_vmm_present"
        "kern.maxfilesperproc"
        "kern.memorystatus_level"
        "kern.osproductversion"
        "kern.osrelease"
        "kern.ostype"
        "kern.osvariant_status"
        "kern.osversion"
        "kern.safeboot"
        "kern.version"
        "kern.willshutdown"
        "machdep.cpu.brand_string"
        "security.mac.sandbox.sentinel"
        "sysctl.name2oid"
        "kern.tcsm_enable"
        "kern.tcsm_available"
        "vm.footprint_suspend")
    (sysctl-name-prefix "net.routetable")
    (sysctl-name-prefix "hw.optional.")
    (sysctl-name-prefix "hw.perflevel")
)
(deny sysctl-read (with no-report)
    (sysctl-name
        "sysctl.proc_translated"
        "vm.task_no_footprint_for_debug"))
(with-filter (require-not (webcontent-process-launched))
    (allow sysctl-read (sysctl-name "vm.malloc_ranges")))
(allow sysctl-write
    (sysctl-name
        "kern.tcsm_enable"))
(deny iokit-get-properties)
(allow iokit-get-properties
    (iokit-property "AAPL,LCD-PowerState-ON")
    (iokit-property "AGCInfo")
    (iokit-property "AccelCaps")
    (iokit-property "AccelNativeDMARowByteAlignment")
    (iokit-property "AccurateMaxDigitizerPressureValue")
    (iokit-property "ActivationThresholds")
    (iokit-property "ActuationSupported")
    (iokit-property "AnimationThresholds")
    (iokit-property "AllowDisplaySleep")
    (iokit-property "AlwaysNeedsVelocityCalculated")
    (iokit-property "AppleGVAKeyDoesNotExist")
    (iokit-property "AppleIntelMEVABundleName")
    (iokit-property "AAPL,DisplayPipe")
    (iokit-property "AAPL,OpenCLdisabled")
    (iokit-property-prefix "AAPL,IOGraphics_LER")
    (iokit-property "AAPL,alias-policy")
    (iokit-property "AAPL,boot-display")
    (iokit-property "AAPL,display-alias")
    (iokit-property "AAPL,mux-switch-state")
    (iokit-property "AAPL,ndrv-dev")
    (iokit-property "AAPL,primary-display")
    (iokit-property "AAPL,slot-name")
    (iokit-property "ATY,cbits")
    (iokit-property "ATY,fb_linebytes")
    (iokit-property "ATY,fb_offset")
    (iokit-property "ATY,fb_size")
    (iokit-property "ATY,intrev")
    (iokit-property "ATY,DeviceName")
    (iokit-property "ATY,EFIDisplay")
    (iokit-property "ATY,FamilyName")
    (iokit-property "AVCSupported")
    (iokit-property "BacklightHandle")
    (iokit-property "BlockSize")
    (iokit-property "CEAModeID")
    (iokit-property "CEAPixelRepetition")
    (iokit-property "CFBundleIdentifier")
    (iokit-property "CFBundleIdentifierKernel")
    (iokit-property "CapsLockDelay")
    (iokit-property "CaseSensitive")
    (iokit-property "ConfigState")
    (iokit-property "DPLanes")
    (iokit-property "DPLinkBit")
    (iokit-property "DPLinkRate")
    (iokit-property "Description")
    (iokit-property "Development")
    (iokit-property "Device Characteristics")
    (iokit-property "DeviceEqID")
    (iokit-property "DiskImageURL")
    (iokit-property "DisplayRouting")
    (iokit-property "Driver is Ready")
    (iokit-property "Ejectable")
    (iokit-property "EnableLPVP")
    (iokit-property "Encrypted")
    (iokit-property "Endianness")
    (iokit-property "ExtendedMaxDigitizerPressureValue")
    (iokit-property "Family ID")
    (iokit-property "ForceSupported")
    (iokit-property "Formats")
    (iokit-property "FramebufferEnabled")
    (iokit-property "FramebufferStarted")
    (iokit-property "GPUConfigurationVariable")
    (iokit-property "GPUDCCDisplayable")
    (iokit-property "GPUDebugNullClientMask")
    (iokit-property "GpuDebugPolicy")
    (iokit-property "GPURawCounterBundleName")
    (iokit-property "GPURawCounterPluginClassName")
    (iokit-property "HEVCSupported")
    (iokit-property "HIDPointerAccelerationType")
    (iokit-property "HwCtxCacheUpdate")
    (iokit-property "IOAccelDisplayPipeCapabilities")
    (iokit-property "IOAccelIndex")
    (iokit-property "IOAccelTypes")
    (iokit-property "IOAccelRevision")
    (iokit-property-prefix "IOAudioControl")
    (iokit-property "IOAudioDeviceCanBeDefaults")
    (iokit-property "IOAudioDeviceTransportType")
    (iokit-property-prefix "IOAudioEngine")
    (iokit-property "IOAudioSampleRate")
    (iokit-property "IOAudioStreamSampleFormatByteOrder")
    (iokit-property-prefix "IOAV")
    (iokit-property "IOBacklightHandlerID")
    (iokit-property "IOBusyInterest")
    (iokit-property "IOCFPlugInTypes")
    (iokit-property "IOChildIndex")
    (iokit-property "IOClass")
    (iokit-property "IOClassNameOverride")
    (iokit-property "IOConsoleUsers")
    (iokit-property "IODVDBundleName")
    (iokit-property "IODeviceMemory")
    (iokit-property "IODisplayParameters")
    (iokit-property-prefix "IOFB")
    (iokit-property "IOFramebufferOpenGLIndex")
    (iokit-property "IOGeneralInterest")
    (iokit-property "IOGLBundleName")
    (iokit-property-prefix "IOGVA")
    (iokit-property "IOHibernateState")
    (iokit-property "IOI2CTransactionTypes")
    (iokit-property "IOInterruptControllers")
    (iokit-property "IOInterruptSpecifiers")
    (iokit-property "IOKitDebug")
    (iokit-property "IOMatchCategory")
    (iokit-property "IOMediaIcon")
    (iokit-property "IONDRVFramebufferGeneration")
    (iokit-property "IONVRAMProperty")
    (iokit-property "IOName")
    (iokit-property "IONameMatch")
    (iokit-property "IONameMatched")
    (iokit-property "IOOCDBundleName")
    (iokit-property "IOPCITunnelled")
    (iokit-property "IOPCITunnelCompatible")
    (iokit-property "IOPMStrictTreeOrder")
    (iokit-property "IOParentMatch")
    (iokit-property-prefix "IOPCI")
    (iokit-property "IOPMIsPowerManaged")
    (iokit-property "IOPersonalityPublisher")
    (iokit-property "IOPlatformSerialNumber")
    (iokit-property "IOPowerManagement")
    (iokit-property "IOProbeScore")
    (iokit-property "IOPropertyMatch")
    (iokit-property "IOProviderClass")
    (iokit-property "IOReportLures")
    (iokit-property "IOReportLegend")
    (iokit-property "IOReportLegendPublic")
    (iokit-property "IOScreenRestoreState")
    (iokit-property "IOSourceVersion")
    (iokit-property "IOVABundleName")
    (iokit-property "IOVARendererID")
    (iokit-property "IOVARendererSubID")
    (iokit-property "InternalStatistics")
    (iokit-property "InternalStatisticsAccm")
    (iokit-property "MetalPluginClassName")
    (iokit-property "MetalPluginName")
    (iokit-property "MetalStatisticsName")
    (iokit-property "MTHIDDevice")
    (iokit-property "MT Built-In")
    (iokit-property "MaintainPowerInUILock")
    (iokit-property "Max Packet Size")
    (iokit-property "MaximumBootBeepVolume")
    (iokit-property "MinDigitizerPressureValue")
    (iokit-property "Multitouch ID")
    (iokit-property "Multitouch Serial Number")
    (iokit-property "Multitouch Subdevice ID")
    (iokit-property "NVArch")
    (iokit-property "NVCAP")
    (iokit-property "NVCLASS")
    (iokit-property "NVDA,Enable-A2R10G10B10Format")
    (iokit-property "NVDA,Features")
    (iokit-property "NVDA,NVPresentment-version")
    (iokit-property "NVDA,accel-loaded")
    (iokit-property "NVDA,invalid-config")
    (iokit-property "NVDA,mm-version")
    (iokit-property "NVDAType")
    (iokit-property "NVDAinitgl_created")
    (iokit-property "NVRAMProperty")
    (iokit-property "NXSystemInfo")
    (iokit-property "VRAM,memvendorID")
    (iokit-property "VRAM,totalsize")
    (iokit-property "NoAutoRoute")
    (iokit-property "NumBlocks")
    (iokit-property "NumStreams")
    (iokit-property "PerformanceStatistics")
    (iokit-property "PerformanceStatisticsAccum")
    (iokit-property "PinConfigurations")
    (iokit-property "Protocol Characteristics")
    (iokit-property "Removable")
    (iokit-property "ResetOnLockMs")
    (iokit-property "ResetOnUnlockMs")
    (iokit-property "SWIP_properties")
    (iokit-property "SafeEjectRequested")
    (iokit-property "SampleRates")
    (iokit-property "Sensor Columns")
    (iokit-property "Sensor Rows")
    (iokit-property "Sensor Region Descriptor")
    (iokit-property "Sensor Region Param")
    (iokit-property "Sensor Region Rows")
    (iokit-property "Sensor Surface Descriptor")
    (iokit-property "Sensor Surface Height")
    (iokit-property "Sensor Surface Width")
    (iokit-property "Serial Number")
    (iokit-property "StartupDisplay")
    (iokit-property "SurfaceList")
    (iokit-property "SupportAudioAUUC")
    (iokit-property "SupportsSilentClick")
    (iokit-property "SupportTapToWake")
    (iokit-property "TimeStampFiltering")
    (iokit-property "Transport")
    (iokit-property "USBADC")
    (iokit-property "UserClientEnabled")
    (iokit-property "VRAM,totalMB")
    (iokit-property "WANTS_FRAMES_IGNORED")
    (iokit-property "acpi-device")
    (iokit-property "acpi-path")
    (iokit-property "assigned-addresses")
    (iokit-property "attached-gpu-control-path")
    (iokit-property "audio-codec-info")
    (iokit-property "audio-device-mvalue")
    (iokit-property "audio-device-nvalue")
    (iokit-property "audio-selector")
    (iokit-property "av-signal-type")
    (iokit-property "backlight-PWM-freq")
    (iokit-property "bcdVersion")
    (iokit-property "board-id")
    (iokit-property "boot-gamma-restored")
    (iokit-property "built-in")
    (iokit-property "cail_properties")
    (iokit-property "canvas-height")
    (iokit-property "canvas-width")
    (iokit-property "class-code")
    (iokit-property "color-accuracy-index")
    (iokit-property "compatible")
    (iokit-property "connector-type")
    (iokit-property "device-id")
    (iokit-property "device_type")
    (iokit-property "display-bpc")
    (iokit-property "display-connect-flags")
    (iokit-property "display-link-component-bits")
    (iokit-property "display-pixel-component-bits")
    (iokit-property "display-type")
    (iokit-property "dpm")
    (iokit-property "errordb")
    (iokit-property "filevault-image")
    (iokit-property "graphic-options")
    (iokit-property "hda-gfx")
    (iokit-property "housing-color")
    (iokit-property "idProduct")
    (iokit-property "idVendor")
    (iokit-property "iofb_version")
    (iokit-property "image-encrypted")
    (iokit-property "image-path")
    (iokit-property "layout-id")
    (iokit-property "locationID")
    (iokit-property "model")
    (iokit-property "mt-device-id")
    (iokit-property "name")
    (iokit-property "nv-stats")
    (iokit-property "parser-options")
    (iokit-property "parser-type")
    (iokit-property "pci-aspm-default")
    (iokit-property "pcidebug")
    (iokit-property "port-number")
    (iokit-property "reg")
    (iokit-property "revision-id")
    (iokit-property "rm_board_number")
    (iokit-property "rom-revision")
    (iokit-property "saved-config")
    (iokit-property "startup-timing")
    (iokit-property "subsystem-id")
    (iokit-property "subsystem-vendor-id")
    (iokit-property "touch-size-id")
    (iokit-property "vendor-id")
    (iokit-property "vbios-revision")
    (iokit-property "ATY,cbits")
    (iokit-property "ATY,intrev")
    (iokit-property "AccelNativeDMARowByteAlignment")
    (iokit-property "CompactVRAM")
    (iokit-property "EnableBlitLib")
    (iokit-property "ForceDisableEDRAM")
    (iokit-property "IOPCIMatch")
    (iokit-property "MetalStatisticsScriptName")
    (iokit-property "MetalCoalesce")
    (iokit-property "PanicOnGPUHang")
    (iokit-property "TelemetryDisable")
    (iokit-property "cail_properties")
    (iokit-property "dpm")
    (iokit-property "IOGVAH264EncodeCapabilities")
    (iokit-property "IOAVDHEVCDecodeCapabilities")
)
(deny iokit-get-properties
    (iokit-property "AppleDiagnosticDataSysCfg")
    (iokit-property "als-colorCfg")
    (iokit-property "ean-storage-present")
    (iokit-property "noMultiColorSupport")
    (iokit-property "syscfg-v2-data")
    (with no-report))
(with-filter (iokit-registry-entry-class "IOPlatformDevice")
    (deny iokit-get-properties (with no-report)
        (iokit-property
            "artwork-display-gamut"
            "product-id")))
(with-filter (iokit-registry-entry-class "AppleMobileADBE0")
    (deny iokit-get-properties (with no-report)
        (iokit-property "APTDevice")))
(if (equal? (param "CPU") "arm64")
    (with-filter (iokit-registry-entry-class "AppleARMIODevice")
        (deny iokit-get-properties (with no-report)
            (iokit-property "supports-apt"))))
(if (equal? (param "CPU") "arm64")
    (with-filter (iokit-registry-entry-class "AppleJPEGDriver")
        (deny iokit-get-properties (with no-report)
            (iokit-property "AppleJPEGNumCores"))))
(if (equal? (param "CPU") "arm64")
    (allow iokit-get-properties
        (iokit-property "ADSSupported")
        (iokit-property "IOAVDHEVCDecodeCapabilities")
        (iokit-property "IOGLESBundleName")
        (iokit-property "MetalPluginClassName")
        (iokit-property "MetalPluginName")
        (iokit-property "IOSurfaceAcceleratorCapabilitiesDict")
        (iokit-property "acoustic-id")
    ))
(if (equal? (param "CPU") "arm64")
    (with-filter (iokit-registry-entry-class "IOService")
        (allow iokit-get-properties
            (iokit-property "IORegistryEntryPropertyKeys"))))
(if (equal? (param "CPU") "arm64")
    (with-filter (iokit-registry-entry-class "IOMobileFramebuffer")
        (allow iokit-get-properties
            (iokit-property "AppleTV"
                            "DisplayPipePlaneBaseAlignment"
                            "DisplayPipeStrideRequirements"
                            "dfr"
                            "external"
                            "hdcp-hoover-protocol"))))
(if (equal? (param "CPU") "arm64")
    (with-filter (iokit-registry-entry-class "IOPlatformDevice")
        (allow iokit-get-properties
            (iokit-property "soc-generation"))))
(if (equal? (param "CPU") "arm64")
    (with-filter (iokit-registry-entry-class "IOService")
        (allow iokit-get-properties
            (iokit-property "chip-id"
                            "display-rotation"
                            "display-scale"))))
(deny mach-lookup (xpc-service-name-prefix ""))
(deny mach-lookup (with no-report)
    (xpc-service-name "com.apple.audio.SandboxHelper"))
(deny mach-lookup (with no-report)
    (global-name "com.apple.windowmanager.server"))
(define (allow-read-directory-and-issue-read-extensions path)
    (if path
        (begin
            (allow file-read* (subpath path))
            (allow file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") (subpath path))))))
(define (allow-read-write-directory-and-issue-read-write-extensions path)
    (if path
        (begin
            (allow file-read* file-write* (subpath path))
            (allow file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read") (subpath path)))
            (allow file-issue-extension (require-all (extension-class "com.apple.app-sandbox.read-write") (subpath path))))))
(define (HEX-pattern-match-generator pattern-descriptor)
    (letrec ((pattern-string ""))
        (for-each (lambda (repeat-count)
            (if (zero? repeat-count)
                (set! pattern-string (string-append pattern-string "-"))
                (let appender ((count repeat-count))
                    (if (> count 0)
                        (begin
                            (set! pattern-string (string-append pattern-string "[0-9A-F]"))
                            (appender (- count 1)))))))
            pattern-descriptor)
    pattern-string))
(define (uuid-HEX-pattern-match-string)
    (HEX-pattern-match-generator '(8 0 4 0 4 0 4 0 12)))
(define *uuid-pattern* "")
(define (uuid-regex-string)
    (if (zero? (string-length *uuid-pattern*))
        (set! *uuid-pattern* (uuid-HEX-pattern-match-string)))
    *uuid-pattern*)
(allow file-read*
    (subpath "/Library/Dictionaries")
    (subpath "/Library/Fonts")
    (subpath "/Library/Frameworks")
    (subpath "/Library/Managed Preferences")
    (subpath "/Library/Speech/Synthesizers")
    (regex #"^/private/etc/(hosts|group|passwd)$")
    (home-literal "/.CFUserTextEncoding")
    (home-subpath "/Library/Fonts")
    (subpath "/Library/Audio/Plug-Ins/HAL")
    (home-subpath "/Library/Dictionaries"))
(allow file-read-data
    (literal "/usr/local/lib/log")
    (subpath "/Library/Audio/Plug-Ins/Components"))
(shared-preferences-read
    "com.apple.Accessibility"
    "com.apple.ATS"
    "com.apple.CoreGraphics"
    "com.apple.DownloadAssessment"
    "com.apple.HIToolbox"
    "com.apple.LaunchServices"
    "com.apple.MultitouchSupport"
    "com.apple.ServicesMenu.Services"
    "com.apple.ViewBridge"
    "com.apple.WebFoundation"
    "com.apple.WebKit"
    "com.apple.avfoundation"
    "com.apple.avfoundation.frecents"
    "com.apple.avfoundation.videoperformancehud"
    "com.apple.coremedia"
    "com.apple.crypto"
    "com.apple.driver.AppleBluetoothMultitouch.mouse"
    "com.apple.driver.AppleBluetoothMultitouch.trackpad"
    "com.apple.driver.AppleHIDMouse"
    "com.apple.lookup.shared"
    "com.apple.mediaaccessibility"
    "com.apple.networkConnect"
    "com.apple.security"
    "com.apple.speech.voice.prefs"
    "com.apple.systemsound"
    "com.apple.universalaccess"
    "edu.mit.Kerberos"
    "pbs")
(allow-reading-global-preferences)
(allow-read-directory-and-issue-read-extensions (param "WEBKIT2_FRAMEWORK_DIR"))
(allow-read-directory-and-issue-read-extensions "/System/Library/PrivateFrameworks/WebInspectorUI.framework")
(read-only-and-issue-extensions (extension "com.apple.app-sandbox.read"))
(read-write-and-issue-extensions (extension "com.apple.app-sandbox.read-write"))
(allow mach-lookup
    (require-all
        (extension "com.apple.app-sandbox.mach")
        (global-name "com.apple.commerce")))
(with-filter (system-attribute apple-internal)
    (allow mach-register
        (global-name-regex #"^_oglprof_attach_<[0-9]+>$"))
)
(if (positive? (string-length (param "DARWIN_USER_CACHE_DIR")))
    (allow-read-write-directory-and-issue-read-write-extensions (param "DARWIN_USER_CACHE_DIR")))
(if (positive? (string-length (param "DARWIN_USER_TEMP_DIR")))
    (allow-read-write-directory-and-issue-read-write-extensions (param "DARWIN_USER_TEMP_DIR")))
(deny iokit-open (with no-report)
    (iokit-user-client-class "AppleJPEGDriverUserClient"))
(when (not (webcontent_gpu_sandbox_extensions_blocking))
(if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
    (allow iokit-open
        (require-all
            (extension "com.apple.webkit.extension.iokit")
            (iokit-user-client-class "AppleUpstreamUserClient"))
        (apply-message-filter
            (deny (with message "AppleUpstreamUserClient")
                iokit-external-method)
            (allow iokit-external-method
                (iokit-method-number 0 1 3 4 5)
                )
            (deny
                iokit-async-external-method
                iokit-external-trap)))
    (allow iokit-open
        (require-all
            (extension "com.apple.webkit.extension.iokit")
            (iokit-user-client-class "AppleUpstreamUserClient"))))
(if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
    (allow iokit-open
        (require-all
            (extension "com.apple.webkit.extension.iokit")
            (iokit-user-client-class "AudioAUUC"))
        (apply-message-filter
            (deny (with message "AudioAUUC")
                iokit-external-method)
            (allow iokit-external-method
                (iokit-method-number 0 1 3 4 5)
                )
            (deny
                iokit-async-external-method
                iokit-external-trap)))
    (allow iokit-open
        (require-all
            (extension "com.apple.webkit.extension.iokit")
            (iokit-user-client-class "AudioAUUC"))))
(if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
    (allow iokit-open
        (require-all
            (extension "com.apple.webkit.extension.iokit")
            (iokit-user-client-class "IOAudioControlUserClient"))
        (apply-message-filter
            (deny
                iokit-async-external-method
                iokit-external-trap
                iokit-external-method)))
    (allow iokit-open
        (require-all
            (extension "com.apple.webkit.extension.iokit")
            (iokit-user-client-class "IOAudioControlUserClient"))))
(if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
    (allow iokit-open
        (require-all
            (extension "com.apple.webkit.extension.iokit")
            (iokit-user-client-class "IOAudioEngineUserClient"))
        (apply-message-filter
            (deny
                iokit-async-external-method
                iokit-external-trap
                iokit-external-method)))
    (allow iokit-open
        (require-all
            (extension "com.apple.webkit.extension.iokit")
            (iokit-user-client-class "IOAudioEngineUserClient")))))
(when (not (webcontent_gpu_sandbox_extensions_blocking))
(when (equal? (param "CPU") "arm64")
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-user-client-class
                    "AppleAVDUserClient"))
            (AppleAVDUserClientMessageFilter)
            )
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-user-client-class "AppleAVDUserClient"))))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-user-client-class "IOMobileFramebufferUserClient"))
            (IOMobileFramebufferUserClientMessageFilter)
            )
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-user-client-class "IOMobileFramebufferUserClient"))))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-user-client-class "IOSurfaceAcceleratorClient"))
            (IOSurfaceAcceleratorClientMessageFilter)
            )
        (allow iokit-open
            (require-all
                (extension "com.apple.webkit.extension.iokit")
                (iokit-user-client-class
                    "IOSurfaceAcceleratorClient"))))))
(allow ipc-posix-shm-read* ipc-posix-shm-write-data
    (ipc-posix-name-prefix "AudioIO"))
(allow mach-lookup
    (global-name "com.apple.coreservices.launchservicesd")
)
(deny mach-lookup (with no-report)
    (global-name "com.apple.tccd.system"))
(allow mach-lookup
    (require-all
        (extension "com.apple.webkit.extension.mach")
        (global-name "com.apple.mobileassetd.v2")
))
(allow mach-lookup
    (require-all
        (extension "com.apple.webkit.extension.mach")
        (global-name "com.apple.trustd.agent")))
(allow mach-lookup (global-name
    "com.apple.logd"
    "com.apple.logd.events"))
(allow mach-lookup (global-name "com.apple.CARenderServer"))
(deny mach-lookup (with no-report)
    (global-name "com.apple.PowerManagement.control"))
(allow mach-lookup
    (require-all
        (extension "com.apple.webkit.extension.mach")
        (global-name "com.apple.fonts")
    )
)
(deny mach-lookup (with no-report)
    (global-name "com.apple.lsd.mapdb")
)
(when (not (webcontent_gpu_sandbox_extensions_blocking))
(allow mach-lookup
    (xpc-service-name "com.apple.MTLCompilerService")))
(deny mach-lookup (with no-report)
    (global-name "com.apple.CoreServices.coreservicesd")
    (global-name "com.apple.DiskArbitration.diskarbitrationd")
    (global-name "com.apple.ViewBridgeAuxiliary")
    (global-name "com.apple.windowserver.active"))
(deny mach-lookup (with no-report)
    (global-name "com.apple.CoreDisplay.Notification"))
(allow file-read* (subpath "/private/var/db/mds/system"))
(with-filter (uid 0)
    (allow file-write*
        (subpath "/private/var/db/mds/system"))
    (allow mach-lookup
       (global-name "com.apple.system.opendirectoryd.libinfo")
       (global-name "com.apple.system.opendirectoryd.membership"))
)
(allow mach-lookup
    (require-all
        (extension "com.apple.webkit.extension.mach")
        (global-name "com.apple.system.opendirectoryd.libinfo")))
(allow file-read*
       (subpath "/private/var/db/mds")
       (literal "/private/var/db/DetachedSignatures"))
(deny mach-lookup (with no-report)
    (global-name-prefix "com.apple.distributed_notifications"))
(allow file-read-data
    (literal "/dev/autofs_nowait"))
(system-graphics)
(with-filter (system-attribute apple-internal)
    (allow network-outbound
       (literal "/private/var/run/syslog")
    )
)
(allow file-read-data (path "/private/var/db/nsurlstoraged/dafsaData.bin"))
(define (notifyd-message-numbers) (message-number 1002 1010 1011 1012 1016 1017 1018 1021 1022 1025 1026 1028 1029 1030 1031 1032))
(define (allow-notifyd)
    (allow ipc-posix-shm-read* (ipc-posix-name "apple.shm.notification_center"))
    (when (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "NO")
        (allow mach-lookup (global-name "com.apple.system.notification_center")))
    (when (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow mach-lookup (global-name "com.apple.system.notification_center")
            (apply-message-filter
                (deny mach-message-send)
                (deny mach-message-send (with no-report) (message-number 1023))
                (allow mach-message-send (notifyd-message-numbers))))))
(allow-notifyd)
(deny mach-lookup
    (global-name "com.apple.system.logger")
    (with no-report))
(with-filter (uid 0)
    (allow mach-lookup
        (global-name "com.apple.system.logger"))
)
(deny file-write-create (vnode-type SYMLINK))
(deny file-read-xattr file-write-xattr (xattr-prefix "com.apple.security.private."))
(deny file-read* file-write* (with no-report)
       (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2")
       (home-literal "/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV2-journal"))
(deny file-read* (with no-report)
       (subpath "/Library/InputManagers")
       (home-subpath "/Library/InputManagers"))
(deny user-preference-read (with no-report)
    (preference-domain "com.apple.speech.recognition.AppleSpeechRecognition.prefs"))
(deny mach-lookup (with no-report)
       (global-name "com.apple.coreservices.appleevents")
       (global-name "com.apple.pasteboard.1")
       (global-name "com.apple.speech.recognitionserver"))
(allow file-read*
       (subpath "/Library/Components")
       (subpath "/Library/Keyboard Layouts")
       (subpath "/Library/Input Methods")
       (home-subpath "/Library/Components")
       (home-subpath "/Library/Keyboard Layouts")
       (home-subpath "/Library/Input Methods"))
(allow file-read* (subpath "/private/var/db/datadetectors/sys"))
(if (not (defined? 'sbpl-filter?))
  (define (sbpl-filter? x)
      (and (list? x)
           (eq? (car x) 'filter))))
(macro (with-filter form)
   (let* ((ps (cdr form))
          (extra-filter (car ps))
          (rules (cdr ps)))
    `(letrec
        ((collect
             (lambda (l filters non-filters)
                 (if (null? l)
                     (list filters non-filters)
                     (let*
                         ((x (car l))
                          (rest (cdr l)))
                         (if (sbpl-filter? x)
                             (collect rest (cons x filters) non-filters)
                             (collect rest filters (cons x non-filters)))))))
         (inject-filter
             (lambda args
                 (let* ((collected (collect args '() '()))
                        (filters (car collected))
                        (non-filters (cadr collected)))
                 (if (null? filters)
                     (cons ,extra-filter non-filters)
                     (cons (require-all (apply require-any filters) ,extra-filter) non-filters)))))
         (orig-allow allow)
         (orig-deny deny)
         (wrapper
             (lambda (action)
                 (lambda args (apply action (apply inject-filter args))))))
        (set! allow (wrapper orig-allow))
        (set! deny (wrapper orig-deny))
        ,@rules
        (set! deny orig-deny)
        (set! allow orig-allow))))
(with-filter (extension "com.apple.webkit.camera")
    (shared-preferences-read "com.apple.cmio")
    (shared-preferences-read "com.apple.coremedia")
    (allow file-read* (subpath "/Library/CoreMediaIO/Plug-Ins/DAL"))
    (allow mach-lookup
        (global-name "com.apple.cmio.AppleCameraAssistant")
        (global-name "com.apple.cmio.registerassistantservice")
        (global-name "com.apple.cmio.registerassistantservice.system-extensions")
        (global-name "com.apple.cmio.VDCAssistant")
        (global-name "com.apple.cmio.AVCAssistant")
        (global-name "com.apple.cmio.IIDCVideoAssistant")
        (global-name "com.apple.IIDCAssistant")
        (require-all
            (extension "com.apple.webkit.extension.mach")
            (global-name "com.apple.applecamerad")
        ))
    (when (not (webcontent_gpu_sandbox_extensions_blocking))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (iokit-usb-interface-class kUSBVideoInterfaceClass)
                (iokit-user-client-class "IOUSBDeviceUserClientV2"))
            (apply-message-filter
                (allow
                    iokit-external-method)
                (deny
                    iokit-async-external-method
                    iokit-external-trap)))
        (allow iokit-open
            (require-all
                (iokit-usb-interface-class kUSBVideoInterfaceClass)
                (iokit-user-client-class "IOUSBDeviceUserClientV2"))))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (iokit-usb-interface-class kUSBVideoInterfaceClass)
                (iokit-user-client-class "IOUSBInterfaceUserClientV2"))
            (apply-message-filter
                (allow
                    iokit-external-method)
                (deny
                    iokit-async-external-method
                    iokit-external-trap)))
        (allow iokit-open
            (require-all
                (iokit-usb-interface-class kUSBVideoInterfaceClass)
                (iokit-user-client-class "IOUSBInterfaceUserClientV2")))))
    (allow device-camera))
(deny file-write*
    (home-subpath "/Library/Preferences/")
    (with no-report))
(deny mach-lookup (with no-report)
    (xpc-service-name "com.apple.audio.toolbox.reporting.service")
)
(deny mach-lookup
    (global-name "com.apple.audio.SystemSoundServer-OSX")
    (global-name "com.apple.containermanagerd")
    (global-name "com.apple.cookied")
    (global-name "com.apple.coreservices.launchservicesd")
)
(with-filter (system-attribute apple-internal)
    (allow mach-lookup
        (global-name "com.apple.analyticsd")
        (global-name "com.apple.diagnosticd")))
(allow mach-lookup
    (require-all
        (extension "com.apple.webkit.extension.mach")
        (global-name
            "com.apple.webinspector"
            "com.apple.coreservices.launchservicesd"
            "com.apple.iconservices"
            "com.apple.iconservices.store"
            "com.apple.tccd"
            "com.apple.accessibility.mediaaccessibilityd"
            "com.apple.audio.AudioComponentRegistrar" "com.apple.audio.audiohald" "com.apple.coremedia.endpoint.xpc" "com.apple.coremedia.endpointstream.xpc"
            "com.apple.coremedia.endpointplaybacksession.xpc" "com.apple.coremedia.endpointremotecontrolsession.xpc" "com.apple.coremedia.routediscoverer.xpc"
            "com.apple.coremedia.routingcontext.xpc" "com.apple.coremedia.volumecontroller.xpc" "com.apple.lskdd" "com.apple.mediaremoted.xpc" "com.apple.trustd.agent"
            "com.apple.coremedia.samplebufferconsumer.xpc"
            )))
(deny mach-lookup (with no-report)
    (global-name "com.apple.audio.AudioComponentRegistrar"))
(allow mach-lookup
    (require-all
        (extension "com.apple.webkit.extension.mach")
        (xpc-service-name
            "com.apple.audio.SandboxHelper"
            "com.apple.coremedia.videodecoder"
            "com.apple.coremedia.videoencoder"
        )
    )
)
(allow system-fsctl
    (fsctl-command (_IO "h" 47)))
(deny file-ioctl)
(allow file-ioctl (literal "/dev/dtracehelper"))
(deny socket-ioctl)
(when (defined? 'system-fcntl)
    (deny system-fcntl)
    (allow system-fcntl
       (fcntl-command
            F_ADDFILESIGS_RETURN
            F_BARRIERFSYNC
            F_CHECK_LV
            F_GETCONFINED
            F_GETFL
            F_GETPATH
            F_GETPROTECTIONCLASS
            F_GETSIGSINFO
            F_NOCACHE
            F_RDADVISE
            F_SETCONFINED
            F_SETFD
            F_SETPROTECTIONCLASS))
)
(when (defined? 'process-codesigning*)
    (deny process-codesigning-text-offset-get)
    (deny process-codesigning-cdhash-get)
    (deny process-codesigning-blob-get)
    (deny process-codesigning-teamid-get)
    (allow process-codesigning-identity-get)
    (allow process-codesigning-entitlements-blob-get)
    (allow process-codesigning-status-get)
    (allow process-codesigning-status-set (target self))
    (deny process-info-codesignature (with no-report))
)
(when (defined? 'socket-option-get)
    (deny socket-option-get)
)
(when (defined? 'socket-option-set)
    (deny socket-option-set)
)
(disable-syscall-inference)
(define (syscall-unix-only-in-use-before-launch)
    (syscall-number
        SYS_getaudit_addr
        SYS_kdebug_trace
        SYS_pathconf))
(define (syscall-unix-in-use-after-launch)
    (syscall-number
        SYS_ftruncate
        SYS_fsync
        SYS___disable_threadsignal
        SYS___mac_syscall
        SYS_access
        SYS_bsdthread_create
        SYS_bsdthread_ctl
        SYS_bsdthread_terminate
        SYS_close
        SYS_close_nocancel
        SYS_csops
        SYS_csops_audittoken
        SYS_csrctl
        SYS_dup
        SYS_exit
        SYS_fcntl
        SYS_fcntl_nocancel
        SYS_fgetxattr
        SYS_fsgetpath
        SYS_fstat64
        SYS_fstatfs64
        SYS_getattrlist
        SYS_getattrlistbulk
        SYS_getdirentries64
        SYS_getentropy
        SYS_geteuid
        SYS_getfsstat64
        SYS_getgid
        SYS_getrlimit
        SYS_getrusage
        SYS_gettimeofday
        SYS_getuid
        SYS_getxattr
        SYS_ioctl
        SYS_issetugid
        SYS_kdebug_trace64
        SYS_kdebug_trace_string
        SYS_kdebug_typefilter
        SYS_kevent_id
        SYS_kevent_qos
        SYS_lseek
        SYS_lstat64
        SYS_madvise
        SYS_mkdir
        SYS_mmap
        SYS_mprotect
        SYS_munmap
        SYS_open
        SYS_open_nocancel
        SYS_openat
        SYS_pread
        SYS_proc_info
        SYS_psynch_cvbroad
        SYS_psynch_cvclrprepost
        SYS_psynch_cvsignal
        SYS_psynch_cvwait
        SYS_psynch_mutexdrop
        SYS_psynch_mutexwait
        SYS_read
        SYS_read_nocancel
        SYS_readlink
        SYS_sendto
        SYS_stat64
        SYS_statfs64
        SYS_sysctl
        SYS_thread_selfid
        SYS_ulock_wait
        SYS_ulock_wait2
        SYS_ulock_wake
        SYS_workq_kernreturn
        SYS_write_nocancel
        SYS_writev))
(define (syscall-unix-apple-silicon)
    (syscall-number
        SYS_guarded_open_dprotected_np
        SYS_mremap_encrypted))
(define (syscalls-rarely-used)
    (syscall-number
        SYS_getegid
        SYS___semwait_signal
        SYS_write))
(define (syscalls-rarely-used-blocked-in-lockdown-mode)
    (syscall-number
        SYS___pthread_kill
        SYS_openat_nocancel
        SYS___semwait_signal_nocancel
        SYS_change_fdguard_np
        SYS_chmod
        SYS_fchmod
        SYS_fsync
        SYS_getpriority
        SYS_guarded_close_np
        SYS_guarded_open_np
        SYS_guarded_pwrite_np
        SYS_kevent
        SYS_mlock
        SYS_munlock
        SYS_openat_nocancel
        SYS_proc_rlimit_control
        SYS_psynch_rw_rdlock
))
(define (syscall-unix-blocked-in-lockdown-mode) (syscall-number
    SYS___pthread_sigmask
    SYS_faccessat
    SYS_fileport_makefd
    SYS_fstatat64
    SYS_gethostuuid
    SYS_kqueue
    SYS_kqueue_workloop_ctl
    SYS_listxattr
    SYS_mincore
    SYS_psynch_rw_unlock
    SYS_psynch_rw_wrlock
    SYS_sigprocmask
    SYS_sysctlbyname
    SYS_umask
    SYS_work_interval_ctl))
(define (syscall-unix-downlevels)
    (syscall-number
        SYS_flock
        SYS_fsetxattr
        SYS_msync
        SYS_rename))
(define (syscall-unix-downlevels-blocked-in-lockdown-mode)
    (syscall-number
        SYS___semwait_signal_nocancel
        SYS_change_fdguard_np
        SYS_chmod
        SYS_fchmod
        SYS_getpriority
        SYS_guarded_close_np
        SYS_guarded_open_np
        SYS_guarded_pwrite_np
        SYS_kevent
        SYS_mlock
        SYS_munlock
        SYS_openat_nocancel
        SYS_proc_rlimit_control
        SYS_shm_open
        SYS_sigaction
        SYS_unlink))
(deny syscall-unix)
(when (defined? 'SYS_crossarch_trap)
    (deny syscall-unix (with no-report) (syscall-number
        SYS_crossarch_trap)))
(with-filter (require-not (webcontent-process-launched))
    (allow syscall-unix (syscall-unix-only-in-use-before-launch)))
(with-filter (webcontent-process-launched)
    (deny syscall-unix (with telemetry) (with message "Syscall unexpectedly used after launch") (syscall-unix-only-in-use-before-launch)))
(allow syscall-unix (syscall-unix-in-use-after-launch))
(with-filter (require-not (state-flag "BlockIOKitInWebContentSandbox"))
    (allow syscall-unix (syscall-unix-downlevels)))
(with-filter (require-all (require-not (lockdown-mode)) (require-not (state-flag "BlockIOKitInWebContentSandbox")))
    (allow syscall-unix (syscall-unix-downlevels-blocked-in-lockdown-mode)))
(allow syscall-unix (with report) (with telemetry) (syscalls-rarely-used))
(allow syscall-unix (syscall-unix-downlevels))
(with-filter (require-not (lockdown-mode))
    (allow syscall-unix (syscall-unix-downlevels-blocked-in-lockdown-mode)))
(with-filter (require-not (lockdown-mode))
    (allow syscall-unix (syscall-unix-blocked-in-lockdown-mode))
    (when (equal? (param "CPU") "arm64")
        (allow syscall-unix (syscall-unix-apple-silicon)))
    (allow syscall-unix (with report) (with telemetry) (syscalls-rarely-used-blocked-in-lockdown-mode)))
(when (defined? 'SYS_objc_bp_assist_cfg_np)
    (allow syscall-unix (syscall-number SYS_objc_bp_assist_cfg_np)))
(when (defined? 'SYS_map_with_linking_np)
    (allow syscall-unix (syscall-number SYS_map_with_linking_np)))
(with-filter (uid 0)
    (allow syscall-unix (syscall-number SYS_gettid)))
(with-filter (require-not (webcontent-process-launched))
    (allow syscall-unix (syscall-number SYS_quotactl)))
(with-filter (lockdown-mode)
    (deny syscall-unix (with telemetry) (syscall-unix-blocked-in-lockdown-mode))
    (deny syscall-unix (with telemetry) (syscalls-rarely-used-blocked-in-lockdown-mode))
    (when (equal? (param "CPU") "arm64")
        (deny syscall-unix (with telemetry) (syscall-unix-apple-silicon))))
(if (equal? (param "CPU") "arm64")
    (with-filter (extension "com.apple.webkit.camera")
        (allow mach-lookup
            (require-all
                (extension "com.apple.webkit.extension.mach")
                (global-name "com.apple.appleh13camerad")
            ))))
(when (not (webcontent_gpu_sandbox_extensions_blocking))
(if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
    (allow iokit-open
        (require-all
            (require-not (extension "com.apple.webkit.extension.iokit"))
            (iokit-registry-entry-class "IOSurfaceRootUserClient"))
        (IOSurfaceRootUserClientMessageFilter))
    (allow iokit-open
        (require-all
            (require-not (extension "com.apple.webkit.extension.iokit"))
            (iokit-registry-entry-class "IOSurfaceRootUserClient"))))
(when (equal? (param "CPU") "arm64")
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (require-not (extension "com.apple.webkit.extension.iokit"))
                (iokit-user-client-class "AppleAVDUserClient"))
            (AppleAVDUserClientMessageFilter)
            )
        (allow iokit-open
            (require-all
                (require-not (extension "com.apple.webkit.extension.iokit"))
                (iokit-user-client-class "AppleAVDUserClient"))))
    (if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
        (allow iokit-open
            (require-all
                (require-not (extension "com.apple.webkit.extension.iokit"))
                (iokit-user-client-class "IOSurfaceAcceleratorClient"))
            (IOSurfaceAcceleratorClientMessageFilter)
            )
        (allow iokit-open
            (require-all
                (require-not (extension "com.apple.webkit.extension.iokit"))
                (iokit-user-client-class "IOSurfaceAcceleratorClient")))))
(if (equal? (param "ENABLE_SANDBOX_MESSAGE_FILTER") "YES")
    (allow iokit-open
        (require-all
            (require-not (extension "com.apple.webkit.extension.iokit"))
            (iokit-connection "IOAccelerator"))
        (IOAcceleratorMessageFilter))
    (allow iokit-open
        (require-all
            (require-not (extension "com.apple.webkit.extension.iokit"))
            (iokit-connection "IOAccelerator")))))
(deny iokit-open
    (require-all
        (require-not (extension "com.apple.webkit.extension.iokit"))
        (iokit-user-client-class
            "AudioAUUC"
            "IOAudioControlUserClient"
            "IOAudioEngineUserClient")))
(deny iokit-open
    (require-all
        (require-not (extension "com.apple.webkit.extension.iokit"))
        (iokit-registry-entry-class
            "AGPMClient"
            "AppleGraphicsControlClient"
            "AppleGraphicsPolicyClient"
            "AppleIntelMEUserClient"
            "AppleMGPUPowerControlClient"
            "AppleSNBFBUserClient"
            "IOAccelerationUserClient")))
(deny iokit-open
    (require-all
        (require-not (extension "com.apple.webkit.extension.iokit"))
        (iokit-user-client-class "RootDomainUserClient")))
(when (webcontent_gpu_sandbox_extensions_blocking)
    (deny iokit-open-service (with telemetry-backtrace))
    (deny iokit-open-user-client (with telemetry-backtrace)))
(with-filter (state-flag "BlockIOKitInWebContentSandbox")
    (deny iokit-open-service (with telemetry-backtrace))
    (deny iokit-open-user-client (with telemetry-backtrace))
    (deny mach-lookup (with telemetry-backtrace)
        (require-all
            (require-not (extension "com.apple.webkit.extension.mach"))
            (xpc-service-name "com.apple.MTLCompilerService"))))
(deny darwin-notification-post)
(allow darwin-notification-post
    (notification-name
        "com.apple.accessibility.AirPodsSpatialAudioLockToDeviceChanged"
        "com.apple.webinspectord.availability_check"))
(deny file-read* (with no-report)
    (home-literal "/Library/Preferences/com.apple.CFNetwork.plist")
    (home-literal "/Library/Preferences/com.apple.networkd.plist")
    (literal "/Library/Preferences/com.apple.networkd.plist")
)
