@@ -3971,3 +3971,35 @@ int uname(struct utsname *buf)
39713971 "%u" , (v >> 16 ) & 0x7fff );
39723972 return 0 ;
39733973}
3974+
3975+ /*
3976+ * Based on https://stackoverflow.com/questions/43002803
3977+ *
3978+ * [HKLM\SYSTEM\CurrentControlSet\Services\cexecsvc]
3979+ * "DisplayName"="@%systemroot%\\system32\\cexecsvc.exe,-100"
3980+ * "ErrorControl"=dword:00000001
3981+ * "ImagePath"=hex(2):25,00,73,00,79,00,73,00,74,00,65,00,6d,00,72,00,6f,00,
3982+ * 6f,00,74,00,25,00,5c,00,73,00,79,00,73,00,74,00,65,00,6d,00,33,00,32,00,
3983+ * 5c,00,63,00,65,00,78,00,65,00,63,00,73,00,76,00,63,00,2e,00,65,00,78,00,
3984+ * 65,00,00,00
3985+ * "Start"=dword:00000002
3986+ * "Type"=dword:00000010
3987+ * "Description"="@%systemroot%\\system32\\cexecsvc.exe,-101"
3988+ * "ObjectName"="LocalSystem"
3989+ * "ServiceSidType"=dword:00000001
3990+ */
3991+ int is_inside_windows_container (void )
3992+ {
3993+ static int inside_container = -1 ; /* -1 uninitialized */
3994+ const char * key = "SYSTEM\\CurrentControlSet\\Services\\cexecsvc" ;
3995+ HKEY handle = NULL ;
3996+
3997+ if (inside_container != -1 )
3998+ return inside_container ;
3999+
4000+ inside_container = ERROR_SUCCESS ==
4001+ RegOpenKeyExA (HKEY_LOCAL_MACHINE , key , 0 , KEY_READ , & handle );
4002+ RegCloseKey (handle );
4003+
4004+ return inside_container ;
4005+ }
0 commit comments