Skip to content

Instantly share code, notes, and snippets.

@JamieMagee
Created January 2, 2023 21:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamieMagee/a12ce294862eb96135c123381a6aa438 to your computer and use it in GitHub Desktop.
Save JamieMagee/a12ce294862eb96135c123381a6aa438 to your computer and use it in GitHub Desktop.
Scanning Windows container images
using Registry;
var registryHive = new RegistryHive("/tmp/nanoserver/layer/Files/Windows/System32/config/SOFTWARE");
registryHive.ParseHive();
var currentVersion = registryHive.GetKey(@"Microsoft\Windows NT\CurrentVersion");
var fullVersion =
$"{currentVersion.GetValue("CurrentMajorVersionNumber")}.{currentVersion.GetValue("CurrentMinorVersionNumber")}.{currentVersion.GetValue("CurrentBuildNumber")}.{currentVersion.GetValue("UBR")}";
Console.WriteLine(fullVersion);
var packages = registryHive.GetKey(@"Microsoft\Windows\CurrentVersion\Component Based Servicing\Packages");
var updatePackageRegex = new Regex(@"^Package_\d+_for_(KB\d+)~\w{16}~\w+~~((?:\d+\.){3}\d+)$");
var updates = new Dictionary<string, string>();
foreach (var packageKey in packages.SubKeys)
{
if (!updatePackageRegex.IsMatch(packageKey.KeyName))
{
continue;
}
var currentState = packageKey.Values.Find(v => v.ValueName == "CurrentState")?.ValueData;
// Installed
if (currentState == "112")
{
var groups = updatePackageRegex.Match(packageKey.KeyName).Groups;
updates[groups[1].Value] = groups[2].Value;
}
}
foreach (var update in updates)
{
Console.WriteLine($"{update.Key}: {update.Value}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment