public static void CopyDirectory(this IDirectory source, IDirectory dest, IProgressReport logger = null, CreateFileOptions options = CreateFileOptions.None)
        {
            IFileSystem sourceFs = source.ParentFileSystem;
            IFileSystem destFs   = dest.ParentFileSystem;

            foreach (DirectoryEntry entry in source.Read())
            {
                string subSrcPath = PathTools.Normalize(source.FullPath + '/' + entry.Name);
                string subDstPath = PathTools.Normalize(dest.FullPath + '/' + entry.Name);

                if (entry.Type == DirectoryEntryType.Directory)
                {
                    destFs.CreateDirectory(subDstPath);
                    IDirectory subSrcDir = sourceFs.OpenDirectory(subSrcPath, OpenDirectoryMode.All);
                    IDirectory subDstDir = destFs.OpenDirectory(subDstPath, OpenDirectoryMode.All);

                    subSrcDir.CopyDirectory(subDstDir, logger, options);
                }

                if (entry.Type == DirectoryEntryType.File)
                {
                    destFs.CreateFile(subDstPath, entry.Size, options);

                    using (IFile srcFile = sourceFs.OpenFile(subSrcPath, OpenMode.Read))
                        using (IFile dstFile = destFs.OpenFile(subDstPath, OpenMode.Write | OpenMode.Append))
                        {
                            logger?.LogMessage(subSrcPath);
                            srcFile.CopyTo(dstFile, logger);
                        }
                }
            }
        }
Exemple #2
0
        public static void Decrypt(PartitionFileSystem pfs, string outDirPath, bool verifyBeforeDecrypting, Keyset keyset, Output Out)
        {
            Out.Log(pfs.Print());
            ProcessNsp.GetTitlekey(pfs, keyset, Out);
            var         OutDirFs   = new LocalFileSystem(outDirPath);
            IDirectory  sourceRoot = pfs.OpenDirectory("/", OpenDirectoryMode.All);
            IDirectory  destRoot   = OutDirFs.OpenDirectory("/", OpenDirectoryMode.All);
            IFileSystem sourceFs   = sourceRoot.ParentFileSystem;
            IFileSystem destFs     = destRoot.ParentFileSystem;

            foreach (var entry in FileIterator(sourceRoot))
            {
                destFs.CreateFile(entry.Name, entry.Size, CreateFileOptions.None);
                using (IFile srcFile = sourceFs.OpenFile(entry.Name, OpenMode.Read))
                    using (IFile dstFile = destFs.OpenFile(entry.Name, OpenMode.Write))
                    {
                        if (entry.Name.EndsWith(".nca"))
                        {
                            ProcessNca.Process(srcFile, dstFile, verifyBeforeDecrypting, keyset, Out);
                        }
                        else
                        {
                            srcFile.CopyTo(dstFile);
                        }
                    }
            }
        }
Exemple #3
0
        public static void ExtractTickets(PartitionFileSystem pfs, string outDirPath, Keyset keyset, Output Out)
        {
            var         OutDirFs   = new LocalFileSystem(outDirPath);
            IDirectory  sourceRoot = pfs.OpenDirectory("/", OpenDirectoryMode.All);
            IDirectory  destRoot   = OutDirFs.OpenDirectory("/", OpenDirectoryMode.All);
            IFileSystem sourceFs   = sourceRoot.ParentFileSystem;
            IFileSystem destFs     = destRoot.ParentFileSystem;

            foreach (var entry in FileIterator(sourceRoot))
            {
                if (entry.Name.EndsWith(".tik") || entry.Name.EndsWith(".cert"))
                {
                    destFs.CreateFile(entry.Name, entry.Size, CreateFileOptions.None);
                    using (IFile srcFile = sourceFs.OpenFile(entry.Name, OpenMode.Read))
                        using (IFile dstFile = destFs.OpenFile(entry.Name, OpenMode.Write))
                        {
                            srcFile.CopyTo(dstFile);
                        }
                }
            }
        }
		public bool Open(IFile file) {
			try {
				// external apps do not have access to cache directory, copy from the cache to an external location
				var newPath = this.GetReadPath(file.Name);
				file.CopyTo(newPath);

				var javaFile = new Java.IO.File(newPath);
				var uri = Android.Net.Uri.FromFile(javaFile);
				var intent = new Intent(Intent.ActionView);
				intent.SetDataAndType(uri, file.MimeType);
				if (!IsIntentManagable(intent))
					return false;

				this.StartActivity(intent);
				return true;
			}
			catch (Exception ex) {
				Mvx.Warning(ex.ToString());
				return false;
			}
		}
Exemple #5
0
        public static void ExtractTickets(Xci xci, string outDirPath, Keyset keyset, Output Out)
        {
            var         OutDirFs = new LocalFileSystem(outDirPath);
            IDirectory  destRoot = OutDirFs.OpenDirectory("/", OpenDirectoryMode.All);
            IFileSystem destFs   = destRoot.ParentFileSystem;

            foreach (var entry in FileIterator(xci, keyset, Out))
            {
                var fileName = entry.subPfsFile.Name;
                Out.Log($"{fileName}\r\n");
                if (fileName.EndsWith(".tik") || fileName.EndsWith(".cert"))
                {
                    destFs.CreateFile(fileName, entry.subPfsFile.Size, CreateFileOptions.None);
                    using (IFile srcFile = entry.subPfs.OpenFile(fileName, OpenMode.Read))
                        using (IFile dstFile = destFs.OpenFile(fileName, OpenMode.Write))
                        {
                            srcFile.CopyTo(dstFile);
                        }
                }
            }
        }
Exemple #6
0
        public void CopyFileTo(IFile source, IFile dest)
        {
            if (!_isEnabled)
            {
                return;
            }

            lock (_lockObject)
            {
                try
                {
                    source.CopyTo(dest);
                    LOG.Debug($"Copied file: {source.GetFileName()}");
                    _copyCount++;
                }
                catch (Exception ex)
                {
                    LOG.Error($"Error trying to copy the file '{source.GetFileName()}'", ex);
                }
            }
        }
        private ResultSet CreateZip(ManagerEngine man, Hashtable input)
        {
            ResultSet rs = new ResultSet(new string[] { "status", "fromfile", "tofile", "message" });

            if (man.GetFile(man.DecryptPath((string)input["topath"]), (string)input["toname"] + ".zip").Exists)
            {
                throw new ManagerException("{#error.tofile_exists}");
            }

            for (int i = 0; input["frompath" + i] != null; i++)
            {
                IFile fromFile = man.GetFile(man.DecryptPath((string)input["frompath" + i]));
                IFile toFile   = man.GetFile("zip://" + PathUtils.AddTrailingSlash(man.DecryptPath((string)input["topath"])) + input["toname"] + ".zip", fromFile.Name);

                if (!man.IsToolEnabled("zip", toFile.Config))
                {
                    throw new ManagerException("{#error.no_access}");
                }

                if (!fromFile.Exists)
                {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#error.no_from_file}");
                    continue;
                }

                // Zip check
                if (!man.VerifyFile(fromFile, "zip"))
                {
                    rs.Add("FAILED", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), man.InvalidFileMsg);
                    continue;
                }

                if (fromFile.CopyTo(toFile))
                {
                    rs.Add("OK", man.EncryptPath(fromFile.AbsolutePath), man.EncryptPath(toFile.AbsolutePath), "{#message.zip_success}");
                }
            }

            return(rs);
        }
Exemple #8
0
        private void CopyAndPrepareCoreAssembly(IFile originalAssemblyFile, IDirectory tempDirectory)
        {
            var newLocation = tempDirectory.GetFile(originalAssemblyFile.Name);

            originalAssemblyFile.CopyTo(newLocation.FullName);

            AssemblyDefinition newAssembly;

            using (var stream = newLocation.OpenRead()) {
                newAssembly = AssemblyDefinition.ReadAssembly(stream);
            }
            foreach (var reference in newAssembly.MainModule.AssemblyReferences)
            {
                var fileInTemp = GetAssemblyFile(tempDirectory, reference);
                if (!fileInTemp.Exists)
                {
                    continue;
                }

                var assemblyName = AssemblyName.GetAssemblyName(fileInTemp.FullName);
                if (assemblyName.GetPublicKey() != null)
                {
                    // ReSharper disable once RedundantCheckBeforeAssignment (in case of change tracking)
                    if (reference.Version != assemblyName.Version)
                    {
                        reference.Version = assemblyName.Version;
                    }

                    continue;
                }

                reference.PublicKey      = null;
                reference.PublicKeyToken = null;
                reference.HasPublicKey   = false;
            }
            using (var stream = newLocation.Open(FileMode.Create)) {
                newAssembly.Write(stream);
            }
        }
Exemple #9
0
        public ActionResult UploadFiles()
        {
            var r = _file.CreateList();

            _file.ReadFiles(Request.Files);
            var count = _file.UploadedFilesLength();

            _file.CopyTo(r, count);

            try
            {
                foreach (var file in _file.GetHttpPostedFile())
                {
                    _opml.ImportOpml(file);
                }
                return(Content("{\"name\":\"" + r[0].Name + "\",\"type\":\"" + r[0].Type + "\",\"size\":\"" + string.Format("{0} bytes", r[0].Length) + "\"}", "application/json"));
            }
            catch (Exception)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.ExpectationFailed));
            }
        }
Exemple #10
0
 private static void ExtractRoot(IFile inputFileBase, IFileSystem destFs, Keyset keyset, Output Out)
 {
     using (var inputFile = new FilePositionStorage(inputFileBase))
     {
         var xci = new Xci(keyset, inputFile);
         ProcessXci.GetTitleKeys(xci, keyset, Out);
         var root = xci.OpenPartition(XciPartitionType.Root);
         if (root == null)
         {
             throw new InvalidDataException("Could not find root partition");
         }
         foreach (var sub in root.Files)
         {
             using (IFile srcFile = root.OpenFile(sub.Name, OpenMode.Read))
             {
                 destFs.CreateFile(sub.Name, srcFile.GetSize(), CreateFileOptions.None);
                 using (IFile dstFile = destFs.OpenFile(sub.Name, OpenMode.Write))
                 {
                     srcFile.CopyTo(dstFile);
                 }
             }
         }
     }
 }
        public bool Open(IFile file)
        {
            try {
                // external apps do not have access to cache directory, copy from the cache to an external location
                var newPath = this.GetReadPath(file.Name);
                file.CopyTo(newPath);

                var javaFile = new Java.IO.File(newPath);
                var uri      = Android.Net.Uri.FromFile(javaFile);
                var intent   = new Intent(Intent.ActionView);
                intent.SetDataAndType(uri, file.MimeType);
                if (!IsIntentManagable(intent))
                {
                    return(false);
                }

                this.StartActivity(intent);
                return(true);
            }
            catch (Exception ex) {
                Mvx.Warning(ex.ToString());
                return(false);
            }
        }
Exemple #12
0
        private static void Process(string inputFilePath, string outDirPath, XciTaskType taskType, Keyset keyset, Output Out, bool verifyBeforeDecrypting = true)
        {
            using (var inputFile = File.Open(inputFilePath, FileMode.Open, FileAccess.Read).AsStorage())
                using (var outputFile = File.Open($"{outDirPath}/xciMeta.dat", FileMode.Create))
                {
                    var         OutDirFs = new LocalFileSystem(outDirPath);
                    IDirectory  destRoot = OutDirFs.OpenDirectory("/", OpenDirectoryMode.All);
                    IFileSystem destFs   = destRoot.ParentFileSystem;

                    var header = new byte[] { 0x6e, 0x73, 0x5a, 0x69, 0x70, 0x4d, 0x65, 0x74, 0x61, 0x58, 0x43, 0x49, 0x00 };
                    outputFile.Write(header, 0, header.Length);

                    var xci           = new Xci(keyset, inputFile);
                    var xciHeaderData = new byte[0x200];
                    var xciCertData   = new byte[0x200];
                    inputFile.Read(xciHeaderData, 0);
                    inputFile.Read(xciCertData, 0x7000);
                    outputFile.Write(xciHeaderData, 0, 0x200);
                    outputFile.Write(xciCertData, 0, 0x200);

                    Out.Log(Print.PrintXci(xci));

                    var root = xci.OpenPartition(XciPartitionType.Root);
                    if (root == null)
                    {
                        throw new InvalidDataException("Could not find root partition");
                    }

                    ProcessXci.GetTitleKeys(xci, keyset, Out);
                    foreach (var sub in root.Files)
                    {
                        outputFile.WriteByte(0x0A);
                        outputFile.WriteByte(0x0A);
                        var subDirNameChar = Encoding.ASCII.GetBytes(sub.Name);
                        outputFile.Write(subDirNameChar, 0, subDirNameChar.Length);
                        var subPfs = new PartitionFileSystem(new FileStorage(root.OpenFile(sub, OpenMode.Read)));
                        foreach (var subPfsFile in subPfs.Files)
                        {
                            outputFile.WriteByte(0x0A);
                            var subPfsFileNameChar = Encoding.ASCII.GetBytes(subPfsFile.Name);
                            outputFile.Write(subPfsFileNameChar, 0, subPfsFileNameChar.Length);
                            using (IFile srcFile = subPfs.OpenFile(subPfsFile.Name, OpenMode.Read))
                            {
                                if (taskType == XciTaskType.extractRomFS && subPfsFile.Name.EndsWith(".nca"))
                                {
                                    var fullOutDirPath = $"{outDirPath}/{sub.Name}/{subPfsFile.Name}";
                                    Out.Log($"Extracting {subPfsFile.Name}...\r\n");
                                    ProcessNca.Extract(srcFile.AsStream(), fullOutDirPath, verifyBeforeDecrypting, keyset, Out);
                                }
                                else
                                {
                                    var destFileName = Path.Combine(sub.Name, subPfsFile.Name);
                                    if (!destFs.DirectoryExists(sub.Name))
                                    {
                                        destFs.CreateDirectory(sub.Name);
                                    }
                                    destFs.CreateFile(destFileName, subPfsFile.Size, CreateFileOptions.None);
                                    using (IFile dstFile = destFs.OpenFile(destFileName, OpenMode.Write))
                                    {
                                        if (taskType == XciTaskType.decrypt && subPfsFile.Name.EndsWith(".nca"))
                                        {
                                            ProcessNca.Process(srcFile, dstFile, verifyBeforeDecrypting, keyset, Out);
                                        }
                                        else
                                        {
                                            srcFile.CopyTo(dstFile);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    outputFile.WriteByte(0x0A);
                    outputFile.Dispose();
                }
        }
Exemple #13
0
 /// <summary>
 /// <para>
 /// Azure: Copia un blob de una contenedor de Azure a otro
 /// </para>
 /// <para>
 /// Sistema de Archivos:  Copia un archivo de una carpeta a otra
 /// </para>
 /// </summary>
 /// <param name="source">
 /// <para>
 /// Azure:
 ///     Nombre del blob a copiar </para>
 /// <para> Sistema de Archivos:
 ///     Ruta del archivo a copiar</para>
 /// </param>
 /// <param name="destination">
 /// Azure:
 ///     Nombre del contendor de destino
 /// Sistema de Archivos:
 ///     Ruta de destino del archivo
 /// </param>
 public void CopyTo(string source, string destination)
 {
     _file.CopyTo(source, destination);
 }
Exemple #14
0
        public void WhenCopyToFile_ThenThrowsNotSupportedException()
        {
            IFile roFile = GetReadOnlyFileDecorator();

            Assert.Throws <NotSupportedException>(() => roFile.CopyTo(roFile, (src, dest) => { }));
        }