static void Main(string[] args) { if (args.Length == 0) { Console.Error.WriteLine("You must provide a path to a PLGX file."); ConsoleUtils.Exit(1); } string plgxPath = args[0]; Console.WriteLine($"PLGX File: {plgxPath}"); PlgxInfo plgxInfo = PlgxUtils.ReadPlgxPlugin(plgxPath); PrintInfoMetadata(plgxInfo.InfoMetadata); string indentRootLevel = "".PadLeft(SPACES_PER_INDENT_LEVEL); Console.WriteLine($"{indentRootLevel}UUID: {BitConverter.ToString(plgxInfo.Uuid)}"); Console.WriteLine($"{indentRootLevel}Creation Time: {plgxInfo.CreationTime}"); PrintGeneratorInfo(plgxInfo.Generator); PrintRequirements(plgxInfo.Requirements); Console.WriteLine($"{indentRootLevel}Pre-Build Command: {PrintableString(plgxInfo.PreBuildCommand)}"); Console.WriteLine($"{indentRootLevel}Post-Build Command: {PrintableString(plgxInfo.PostBuildCommand)}"); PrintFileInfo(plgxInfo.Files); Console.WriteLine(); ConsoleUtils.Exit(0); }
public static PlgxInfo ReadPlgxPlugin(string pluginFile) { PlgxInfo plgxInfo = new PlgxInfo(); using (KeePassPluginReader reader = new KeePassPluginReader(pluginFile)) { plgxInfo.InfoMetadata.Signature1 = reader.Signature1; plgxInfo.InfoMetadata.Signature2 = reader.Signature2; plgxInfo.InfoMetadata.InfoVersion = reader.PlgxVersion; PlgxObject nextObject; while ((nextObject = reader.ReadNextObject()) != null) { if (nextObject is UuidPlgxObject) { plgxInfo.Uuid = ((UuidPlgxObject)nextObject).Uuid; } else if (nextObject is BaseFileNamePlgxObject) { plgxInfo.BaseFileName = ((BaseFileNamePlgxObject)nextObject).BaseFileName; } else if (nextObject is CreationTimePlgxObject) { plgxInfo.CreationTime = ((CreationTimePlgxObject)nextObject).CreationTime; } else if (nextObject is GeneratorNamePlgxObject) { plgxInfo.Generator.Name = ((GeneratorNamePlgxObject)nextObject).GeneratorName; } else if (nextObject is GeneratorVersionPlgxObject) { plgxInfo.Generator.Version = ((GeneratorVersionPlgxObject)nextObject).GeneratorVersion; } else if (nextObject is KeePassVersionRequirementPlgxObject) { plgxInfo.Requirements.KeePassVersion = ((KeePassVersionRequirementPlgxObject)nextObject).RequiredKeePassVersion; } else if (nextObject is DotNetVersionRequirementPlgxObject) { plgxInfo.Requirements.DotNetVersion = ((DotNetVersionRequirementPlgxObject)nextObject).RequiredDotNetVersion; } else if (nextObject is OperatingSystemRequirementPlgxObject) { string osRawValue = ((OperatingSystemRequirementPlgxObject)nextObject).RequiredOperatingSystem; if (System.Enum.TryParse(osRawValue, out OperatingSystem os)) { plgxInfo.Requirements.OS = os; } else { throw new InvalidDataException($"Operating system type '{osRawValue}' was not recognised."); } } else if (nextObject is PointerSizeRequirementPlgxObject) { plgxInfo.Requirements.PointerSize = ((PointerSizeRequirementPlgxObject)nextObject).RequiredPointerSize; } else if (nextObject is PreBuildPlgxObject) { plgxInfo.PreBuildCommand = ((PreBuildPlgxObject)nextObject).PreBuildCommand; } else if (nextObject is PostBuildPlgxObject) { plgxInfo.PostBuildCommand = ((PostBuildPlgxObject)nextObject).PostBuildCommand; } else if (nextObject is BeginContentPlgxObject) { // Nothing to do here as this object type contains no data. } else if (nextObject is FilePlgxObject) { PlgxEmbeddedFile file = PlgxUtils.ReadEmbeddedFileFromPlgxData((FilePlgxObject)nextObject); plgxInfo.Files.Add(file); } else if (nextObject is EndContentPlgxObject) { // Nothing to do here as this object type contains no data. } else { // Unrecognised plgx object type. Nothing to do. } } return(plgxInfo); } }
public static void ValidatePlgxPluginMetadata(this PlgxInfo plgxInfo) { plgxInfo.InfoMetadata.Validate(); }