public bool CheckSignature(string fileName, out int offset, out bool isExecutable)
        {
            offset       = 0;
            isExecutable = false;

            if (!ArchiveExtensions.Contains(Path.GetExtension(fileName).ToLowerInvariant()))
            {
                return(false);
            }

            try
            {
                using var arcTest = ArchiveFactory.Open(fileName);
                switch (arcTest.Type)
                {
                case ArchiveType.Zip:
                case ArchiveType.SevenZip:
                    return(true);
                }
            }
            catch
            {
                // ignored
            }
            return(false);
        }
Esempio n. 2
0
 private static IEnumerable <RawQueryHistory> LoadFileData()
 {
     return(ArchiveExtensions.SafeDeserializeJsonFile <IEnumerable <RawQueryHistory> >(StorageFilePath,
                                                                                       tuple =>
     {
         App.ShowError(tuple.exception,
                       $"An error occurred while reading the configuration file: '{StorageFilePath}'.\n\nTo avoid this error again a new configuration will be created!");
     }) ?? Enumerable.Empty <RawQueryHistory>());
 }
Esempio n. 3
0
        public bool CheckSignature(string fileName, out int offset, out bool isExecutable)
        {
            offset       = 0;
            isExecutable = false;

            if (!ArchiveExtensions.Contains(Path.GetExtension(fileName).ToLowerInvariant()))
            {
                return(false);
            }

            try
            {
                using var arcTest = ArchiveFactory.Open(fileName);
            }
            catch
            {
                return(false);
            }
            return(true);            // no exception? good enough
        }
        public void CreateFile(Address target, string fileName, BigInteger fileSize, byte[] contentMerkle, byte[] encryptionContent)
        {
            Runtime.Expect(Runtime.IsWitness(target), "invalid witness");
            Runtime.Expect(target.IsUser, "destination address must be user address");
            Runtime.Expect(fileSize >= DomainSettings.ArchiveMinSize, "file too small");
            Runtime.Expect(fileSize <= DomainSettings.ArchiveMaxSize, "file too big");

            var merkleTree = MerkleTree.FromBytes(contentMerkle);
            var archive    = Runtime.GetArchive(merkleTree.Root);

            if (archive != null && archive.IsOwner(target))
            {
                return;
            }

            if (archive == null)
            {
                var encryption = ArchiveExtensions.ReadArchiveEncryption(encryptionContent);
                archive = Runtime.CreateArchive(merkleTree, target, fileName, fileSize, Runtime.Time, encryption);
            }

            AddFile(target, target, archive);
        }
Esempio n. 5
0
 public string[] GetArchiveExtensions()
 {
     return((string.IsNullOrWhiteSpace(ArchiveExtensions)) ? new string[] { } : ArchiveExtensions.Split(';'));
 }