Exemplo n.º 1
0
        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}");
            Console.WriteLine();

            using (KeePassPluginReader reader = new KeePassPluginReader(plgxPath))
            {
                PlgxObject plgxObject;

                while ((plgxObject = reader.ReadNextObject()) != null)
                {
                    if (plgxObject is FilePlgxObject)
                    {
                        using (FilePlgxObjectReader filePlgxObjectReader = new FilePlgxObjectReader((FilePlgxObject)plgxObject))
                        {
                            PlgxObject plgxFileObject;
                            while ((plgxFileObject = filePlgxObjectReader.ReadNextObject()) != null)
                            {
                                Console.WriteLine(plgxFileObject.ToString());
                            }
                        }
                    }
                    else
                    {
                        Console.WriteLine(plgxObject.ToString());
                    }
                }
            }

            ConsoleUtils.Exit(0);
        }
Exemplo n.º 2
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);
            }
        }