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