Пример #1
0
        static void AddAppsToTar(Stream tar, string apps_directory, bool conventions)
        {
            string[] directories = Directory.GetDirectories(apps_directory);

            foreach (string directory in directories)
            {
                var app = Path.GetFileName(directory);
                Console.WriteLine($"[+] App: {app}");

                // manifest comes first
                var fManifest = Path.Combine(directory, "_manifest");
                using (var fin_manifest = File.OpenRead(fManifest)) {
                    // AddFileToTarRaw(tarOutputStream, fin_manifest, new FileInfo(fManifest), $"apps/{app}/_manifest");
                    ABTar.WriteTarFile(app, "", "_manifest", fin_manifest, tar, out var _);
                }

                // write other files
                foreach (var directory2 in Directory.GetDirectories(directory))
                {
                    var domain = Path.GetFileName(directory2);

                    if (conventions)
                    {
                        if (AndroidBackupConventions.TryGetValue(domain, out var dir2Real))
                        {
                            Console.WriteLine("[+]    {dir2} -> {dir2Real}");
                            domain = dir2Real;
                        }
                        else if (AndroidBackupConventions.ContainsValue(domain))
                        {
                            // name accepted
                        }
                        else
                        {
                            dir2Real = $"{AndroidBackupWildcardDir}/{domain}";
                            Console.WriteLine("[!]    {dir2} -> {dir2Real}");
                            domain = dir2Real;
                        }
                    }

                    Console.WriteLine($"[+]    - {domain}");
                    AddDirToTar(tar, directory2, app, domain, "", false);
                }
            }

            ABTar.FinishTar(tar);
        }
Пример #2
0
        static void AddDirToTar(Stream tar, string sourceDirectory, string app, string domain, string basePath, bool writeDirEntry = true)
        {
            // Optionally, write an entry for the directory itself.
            if (writeDirEntry)
            {
                TarEntry tarEntry = TarEntry.CreateEntryFromFile(sourceDirectory);
                tarEntry.Name = basePath;
                // tarOutputStream.PutNextEntry(tarEntry);
                ABTar.WriteTarFile(app, domain, basePath, null, tar, out var _);
            }

            // Write each file to the tar.
            string[] filenames = Directory.GetFiles(sourceDirectory);

            foreach (string filename in filenames)
            {
                using (FileStream file = File.OpenRead(filename)) {
                    //AddFileToTarRaw(tarOutputStream, inputStream, new FileInfo(filename),
                    //    PathCombineUnixUnsafe(basePath, Path.GetFileName(filename)));
                    ABTar.WriteTarFile(app, domain,
                                       PathCombineUnixUnsafe(basePath, Path.GetFileName(filename)),
                                       file, tar, out var _);
                }
            }

            // Recurse.
            string[] directories = Directory.GetDirectories(sourceDirectory);
            foreach (string directory in directories)
            {
                //AddDirToTar(tarOutputStream, directory,
                //    PathCombineUnixUnsafe(basePath, Path.GetFileName(directory)));
                ABTar.WriteTarFile(app, domain,
                                   PathCombineUnixUnsafe(basePath, Path.GetFileName(directory)),
                                   null, tar, out var _);
            }
        }