Example #1
0
        static void SplitFile(string path)
        {
            var file = new MachOFile(path);

            foreach (var entry in file.FatEntries)
            {
                var newPath = Path.ChangeExtension(path, "." + entry.cputype.ToString() + Path.GetExtension(path));

                using (var src = new FileStream(path, FileMode.Open, FileAccess.Read))
                    using (var dst = new FileStream(newPath, FileMode.Create, FileAccess.Write))
                    {
                        src.Seek(entry.offset, SeekOrigin.Begin);

                        var remaining = (int)entry.size;
                        var buf       = new byte[64 * 1024];
                        while (remaining != 0)
                        {
                            var size = Math.Min(remaining, buf.Length);
                            src.Read(buf, 0, size);
                            dst.Write(buf, 0, size);
                            remaining -= size;
                        }
                    }

                Console.WriteLine($"Wrote {entry.cputype} to {newPath}");
            }
        }
Example #2
0
 public void AppendFile(MachOFile file)
 {
     if (file.Entry != null)
     {
         AppendEntry(new MachOFatEntry
         {
             cputype    = file.Entry.cputype,
             cpusubtype = file.Entry.cpusubtype,
             offset     = 0,
             size       = (uint)file._size,
             align      = 0,
             path       = file._path,
             archentry  = file.Entry
         });
     }
     else
     {
         file.FatEntries.ForEach(AppendEntry);
     }
 }
Example #3
0
        static void MergeFile(string outPath, List <string> sources)
        {
            if (Directory.Exists(outPath))
            {
                outPath = Path.Combine(outPath, Path.GetFileName(sources[0]));
            }

            if (!MachOFile.IsValidFile(sources[0]))
            {
                File.Copy(sources[0], outPath);
                return;
            }

            var sourceItems = sources.ConvertAll(v => new MachOFile(v));

            var outFile = new MachOFile(outPath, true);

            sourceItems.ForEach(outFile.AppendFile);

            outFile.Write();
        }
Example #4
0
 static void PrintInfo(string path)
 {
     var file = new MachOFile(path);
 }