@@ -3885,3 +3885,35 @@ int uname(struct utsname *buf)
38853885 "%u" , (v >> 16 ) & 0x7fff );
38863886 return 0 ;
38873887}
3888+
3889+ /*
3890+ * Based on https://stackoverflow.com/questions/43002803
3891+ *
3892+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3893+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3894+ * "ErrorControl"=dword:00000001
3895+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3896+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3897+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3898+ * 65,00,00,00
3899+ * "Start"=dword:00000002
3900+ * "Type"=dword:00000010
3901+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3902+ * "ObjectName"="LocalSystem"
3903+ * "ServiceSidType"=dword:00000001
3904+ */
3905+ int is_inside_windows_container (void )
3906+ {
3907+ static int inside_container = -1 ; /* -1 uninitialized */
3908+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3909+ HKEY handle = NULL ;
3910+
3911+ if (inside_container != -1 )
3912+ return inside_container ;
3913+
3914+ inside_container = ERROR_SUCCESS ==
3915+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
3916+ RegCloseKey (handle );
3917+
3918+ return inside_container ;
3919+ }
0 commit comments