Example #1
0
 private void writeFiles(GDF src, CBinaryWriter bw, GDFDirTable table)
 {
     foreach (GDFDirEntry entry in table)
     {
         if (!entry.IsDirectory)
         {
             bw.Seek(entry.Sector * src.VolDesc.SectorSize, SeekOrigin.Begin);
             string path = "";
             calcPath(table, entry, ref path);
             if (path.StartsWith(@"\"))
             {
                 path = path.Remove(0, 1);
             }
             Console.WriteLine("+ Writing '" + path + "' at Sector 0x" + entry.Sector.ToString("X02") + "...");
             src.WriteFileToStream(path, bw);
         }
     }
     foreach (GDFDirEntry entry2 in table)
     {
         if (entry2.IsDirectory && (entry2.SubDir != null))
         {
             writeFiles(src, bw, entry2.SubDir);
         }
     }
 }
Example #2
0
        private void writeFiles(GDF src, CBinaryWriter bw, GDFDirTable table)
        {
            uint fileCount = src.FileCount;

            foreach (GDFDirEntry entry in table)
            {
                if (!entry.IsDirectory)
                {
                    bw.Seek((long)(entry.Sector * src.VolDesc.SectorSize), SeekOrigin.Begin);
                    string path = "";
                    this.calcPath(table, entry, ref path);
                    if (path.StartsWith(@"\"))
                    {
                        path = path.Remove(0, 1);
                    }
                    this.progress += ((1f / ((float)fileCount)) * 0.45f) * 100f;
                    base.ReportProgress((int)this.progress, "Writing '" + path + "' at Sector 0x" + entry.Sector.ToString("X02") + "...");
                    src.WriteFileToStream(path, bw);
                }
            }
            foreach (GDFDirEntry entry2 in table)
            {
                if (entry2.IsDirectory && (entry2.SubDir != null))
                {
                    this.writeFiles(src, bw, entry2.SubDir);
                }
            }
        }
Example #3
0
        public void WriteFiles(GDF src, FileStream Iso)
        {
            CBinaryWriter bw = new CBinaryWriter(EndianType.LittleEndian, Iso);

            Console.WriteLine("+ Writing file data to new ISO image...");
            writeFiles(src, bw, rootDir);
            writeGDFsizes(bw);
        }
Example #4
0
        public void WriteFiles(GDF src, FileStream Iso)
        {
            CBinaryWriter bw = new CBinaryWriter(EndianType.LittleEndian, Iso);

            base.ReportProgress(0, "Writing file data to new ISO image...");
            this.writeFiles(src, bw, this.rootDir);
            this.writeGDFsizes(bw);
        }
Example #5
0
        public void WriteGDF(GDF src, FileStream iso)
        {
            CBinaryWriter bw = new CBinaryWriter(EndianType.LittleEndian, iso);

            base.ReportProgress(0, "Writing new GDF header...");
            this.writeGDFheader(src, bw);
            base.ReportProgress(0, "Writing new GDF directories...");
            this.writeGDFtable(src, bw, this.rootDir);
        }
Example #6
0
        public void WriteGDF(GDF src, FileStream iso)
        {
            CBinaryWriter bw = new CBinaryWriter(EndianType.LittleEndian, iso);

            Console.WriteLine("+ Writing new GDF header...");
            writeGDFheader(src, bw);
            Console.WriteLine("+ Writing new GDF directories...");
            writeGDFtable(src, bw, rootDir);
        }
Example #7
0
 public void RemapSectors(GDF src)
 {
     if (rootDir != null)
     {
         rootDir.Sector = freeSector;
         rootDir.Size   = (uint)sectorsToSize(src, sizeToSectors(src, rootDir.Size));
         freeSector    += sizeToSectors(src, rootDir.Size);
         remapDirs(src, rootDir);
         remapFiles(src, rootDir);
     }
 }
Example #8
0
 public void RemapSectors(GDF src)
 {
     if (this.rootDir != null)
     {
         this.rootDir.Sector = this.freeSector;
         this.rootDir.Size   = (uint)this.sectorsToSize(src, this.sizeToSectors(src, this.rootDir.Size));
         this.freeSector    += this.sizeToSectors(src, this.rootDir.Size);
         this.remapDirs(src, this.rootDir);
         this.remapFiles(src, this.rootDir);
     }
 }
Example #9
0
 private void writeGDFtable(GDF src, CBinaryWriter bw, GDFDirTable table)
 {
     bw.Seek(table.Sector * src.VolDesc.SectorSize, SeekOrigin.Begin);
     byte[] buffer = table.ToByteArray();
     bw.Write(buffer);
     foreach (GDFDirEntry entry in table)
     {
         if (entry.IsDirectory && (entry.SubDir != null))
         {
             writeGDFtable(src, bw, entry.SubDir);
         }
     }
 }
Example #10
0
        private void Iso2God_Full(object sender, DoWorkEventArgs e)
        {
            FileStream stream;
            FileStream stream2;

            base.ReportProgress((int)this.progress, "Preparing to rebuild ISO image...");
            IsoEntry argument = (IsoEntry)e.Argument;

            try
            {
                stream = new FileStream(argument.Path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
            }
            catch (Exception exception)
            {
                base.ReportProgress(0, "Error! " + exception.Message);
                return;
            }
            using (GDF gdf = new GDF(stream))
            {
                uint lastSector = 0;
                gdf.ParseDirectory(gdf.RootDir, true, ref lastSector);
                base.ReportProgress((int)this.progress, "Generating new GDFS structures...");
                try
                {
                    stream2 = File.OpenWrite(argument.Padding.IsoPath + argument.Path.Substring(argument.Path.LastIndexOf(Path.DirectorySeparatorChar) + 1) + "_rebuilt.iso");
                }
                catch (Exception exception2)
                {
                    base.ReportProgress(0, "Error rebuilding GDF! " + exception2.Message);
                    return;
                }
                this.rootDir = (GDFDirTable)gdf.RootDir.Clone();
                this.RemapSectors(gdf);
                this.WriteGDF(gdf, stream2);
                this.WriteFiles(gdf, stream2);
            }
            if (stream2.Length > 0L)
            {
                base.ReportProgress((int)this.progress, "ISO image rebuilt.");
                argument.Path = stream2.Name;
                argument.Size = stream2.Length;
                stream2.Close();
                stream.Close();
                this.Iso2God_Partial(sender, e, false, argument);
            }
            else
            {
                base.ReportProgress(100, "Failed to rebuild ISO. Aborting.");
            }
        }
Example #11
0
 private void writeGDFheader(GDF src, CBinaryWriter bw)
 {
     bw.Seek(0L, SeekOrigin.Begin);
     bw.Write((uint)0x1a465358);
     bw.Write((uint)0x400);
     bw.Seek(0x8000L, SeekOrigin.Begin);
     bw.Write(gdf_sector);
     bw.Seek(0x10000L, SeekOrigin.Begin);
     bw.Write(src.VolDesc.Identifier);
     bw.Write(rootDir.Sector);
     bw.Write(sizeToSectors(src, rootDir.Size) * src.VolDesc.SectorSize);
     bw.Write(src.VolDesc.ImageCreationTime);
     bw.Write((byte)1);
     bw.Seek(0x107ecL, SeekOrigin.Begin);
     bw.Write(src.VolDesc.Identifier);
 }
Example #12
0
 private void remapFiles(GDF src, GDFDirTable table)
 {
     foreach (GDFDirEntry entry in table)
     {
         if (!entry.IsDirectory)
         {
             entry.Sector = freeSector;
             freeSector  += sizeToSectors(src, entry.Size);
         }
     }
     foreach (GDFDirEntry entry2 in table)
     {
         if (entry2.IsDirectory && (entry2.SubDir != null))
         {
             remapFiles(src, entry2.SubDir);
         }
     }
 }
Example #13
0
 private bool openIso()
 {
     try
     {
         f   = new FileStream(args.PathISO, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         iso = new GDF(f);
     }
     catch (IOException exception)
     {
         Console.WriteLine("- Failed to open ISO image. Reason:\n\n" + exception.Message);
         return(false);
     }
     catch (Exception exception2)
     {
         Console.WriteLine("- Unhandled exception occured when opening ISO image. Reason:\n\n" + exception2.Message);
         return(false);
     }
     return(true);
 }
Example #14
0
 private bool openIso()
 {
     try
     {
         this.f   = new FileStream(this.args.PathISO, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
         this.iso = new GDF(this.f);
     }
     catch (IOException exception)
     {
         base.ReportProgress(0, new IsoDetailsResults(IsoDetailsResultsType.Error, "Failed to open ISO image. Reason:\n\n" + exception.Message));
         return(false);
     }
     catch (Exception exception2)
     {
         base.ReportProgress(0, new IsoDetailsResults(IsoDetailsResultsType.Error, "Unhandled exception occured when opening ISO image. Reason:\n\n" + exception2.Message));
         return(false);
     }
     return(true);
 }
Example #15
0
 private void remapDirs(GDF src, GDFDirTable table)
 {
     foreach (GDFDirEntry entry in table)
     {
         if (entry.IsDirectory)
         {
             if (entry.SubDir == null)
             {
                 entry.Sector = 0;
                 entry.Size   = 0;
             }
             else
             {
                 entry.Sector        = freeSector;
                 entry.SubDir.Sector = freeSector;
                 entry.SubDir.Parent = entry;
                 freeSector         += sizeToSectors(src, entry.Size);
                 Console.WriteLine("+ Remapped '" + entry.Name + "' (" + sizeToSectors(src, entry.Size) + " sectors) to Sector 0x" + entry.Sector.ToString("X02"));
                 remapDirs(src, entry.SubDir);
             }
         }
     }
 }
Example #16
0
 private void remapDirs(GDF src, GDFDirTable table)
 {
     foreach (GDFDirEntry entry in table)
     {
         if (entry.IsDirectory)
         {
             if (entry.SubDir == null)
             {
                 entry.Sector = 0;
                 entry.Size   = 0;
             }
             else
             {
                 entry.Sector        = this.freeSector;
                 entry.SubDir.Sector = this.freeSector;
                 entry.SubDir.Parent = entry;
                 this.freeSector    += this.sizeToSectors(src, entry.Size);
                 base.ReportProgress(0, "Remapped '" + entry.Name + "' (" + this.sizeToSectors(src, entry.Size).ToString() + " sectors) to Sector 0x" + entry.Sector.ToString("X02"));
                 this.remapDirs(src, entry.SubDir);
             }
         }
     }
 }
Example #17
0
        private void Iso2God_Partial(object sender, DoWorkEventArgs e, bool Crop, IsoEntry iso)
        {
            FileStream stream;
            GDF        gdf;

            base.ReportProgress((int)this.progress, "Examining ISO image...");
            try
            {
                stream = new FileStream(iso.Path, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            catch (Exception)
            {
                base.ReportProgress(0, "Cannot access the ISO image because it is being accessed by another application.");
                return;
            }
            try
            {
                gdf = new GDF(stream);
            }
            catch (Exception exception)
            {
                base.ReportProgress(0, "Error while parsing GDF: " + exception.Message);
                return;
            }
            ulong num = 0L;

            if (Crop)
            {
                num = (((ulong)iso.Size) - gdf.RootOffset) - (((ulong)iso.Size) - (gdf.LastOffset + gdf.RootOffset));
            }
            else
            {
                num = ((ulong)iso.Size) - gdf.RootOffset;
            }
            uint        blocksReq = (uint)Math.Ceiling((double)(((double)num) / ((double)this.blockSize)));
            uint        partsReq  = (uint)Math.Ceiling((double)(((double)blocksReq) / ((double)this.blockPerPart)));
            ContentType type      = (iso.Platform == IsoEntryPlatform.Xbox360) ? ContentType.GamesOnDemand : ContentType.XboxOriginal;

            object[] objArray = new object[] { iso.Destination, iso.ID.TitleID, Path.DirectorySeparatorChar, "0000", ((uint)type).ToString("X02"), Path.DirectorySeparatorChar };
            string   path     = string.Concat(objArray) + ((this.uniqueName != null) ? this.uniqueName : iso.ID.TitleID) + ".data";

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }
            Directory.CreateDirectory(path);
            base.ReportProgress((int)this.progress, "Beginning ISO conversion...");
            stream.Seek((long)gdf.RootOffset, SeekOrigin.Begin);
            this.writeParts(stream, path, iso, partsReq, blocksReq);
            base.ReportProgress((int)this.progress, "Calculating Master Hash Table chain...");
            byte[] lastMhtHash  = new byte[20];
            uint   lastPartSize = 0;

            this.calcMhtHashChain(path, partsReq, out lastPartSize, out lastMhtHash);
            ulong num6      = 0xa290L;
            ulong num7      = this.blockSize * num6;
            ulong sizeParts = lastPartSize + ((partsReq - 1) * num7);

            base.ReportProgress(0x5f, "Creating LIVE header...");
            this.createConHeader(path.Substring(0, path.Length - 5), iso, blocksReq, 0, partsReq, sizeParts, lastMhtHash);
            stream.Close();
            stream.Dispose();
            gdf.Dispose();
            if ((iso.Padding.Type == IsoEntryPaddingRemoval.Full) && !iso.Padding.KeepIso)
            {
                try
                {
                    File.Delete(iso.Path);
                }
                catch (Exception)
                {
                    base.ReportProgress(0x5f, "Unable to delete ISO temporary image.");
                }
            }
            this.Finish = DateTime.Now;
            TimeSpan span = (TimeSpan)(this.Finish - this.Start);

            base.ReportProgress(100, "Done!");
            e.Result = "Finished in " + span.Minutes.ToString() + "m" + span.Seconds.ToString() + "s. GOD package written to: " + path;
            GC.Collect();
        }
Example #18
0
        private void Iso2God_Partial(bool Crop, IsoEntry iso, string ID)
        {
            FileStream stream;
            GDF        gdf;

            Console.WriteLine("+ Examining ISO image...");
            try
            {
                stream = new FileStream(iso.Path, FileMode.Open, FileAccess.Read, FileShare.Read);
            }
            catch (Exception)
            {
                Console.WriteLine("- Cannot access the ISO image because it is being accessed by another application.");
                return;
            }
            try
            {
                gdf = new GDF(stream);
            }
            catch (Exception exception)
            {
                Console.WriteLine("- Error while parsing GDF: " + exception.Message);
                return;
            }
            ulong num = 0L;

            if (Crop)
            {
                num = (((ulong)iso.Size) - gdf.RootOffset) - (((ulong)iso.Size) - (gdf.LastOffset + gdf.RootOffset));
            }
            else
            {
                num = ((ulong)iso.Size) - gdf.RootOffset;
            }
            uint        blocksReq    = (uint)Math.Ceiling(num / ((double)blockSize));
            uint        partsReq     = (uint)Math.Ceiling(blocksReq / ((double)blockPerPart));
            ContentType type         = (iso.Platform == IsoEntryPlatform.Xbox360) ? ContentType.GamesOnDemand : ContentType.XboxOriginal;
            string      gameTitle    = Get360TitleName.getFromDB(ID).ToString();
            var         invalidChars = new string[] { ":" };

            foreach (var i in invalidChars)
            {
                gameTitle = gameTitle.Replace(i, " ");
            }
            Console.WriteLine(gameTitle);
            object[] objArray = { iso.Destination, gameTitle, Path.DirectorySeparatorChar, "0000", ((uint)type).ToString("X02"), Path.DirectorySeparatorChar };
            string   path     = string.Concat(objArray) + ((uniqueName != null) ? uniqueName : iso.ID.TitleID) + ".data";

            if (Directory.Exists(path))
            {
                Directory.Delete(path, true);
            }
            Directory.CreateDirectory(path);
            Console.WriteLine("+ Beginning ISO conversion...");
            Start = DateTime.Now;
            stream.Seek((long)gdf.RootOffset, SeekOrigin.Begin);
            writeParts(stream, path, partsReq, blocksReq);
            Console.WriteLine("+ Calculating Master Hash Table chain...");
            byte[] lastMhtHash  = new byte[20];
            uint   lastPartSize = 0;

            calcMhtHashChain(path, partsReq, out lastPartSize, out lastMhtHash);
            ulong num6      = 0xa290L;
            ulong num7      = blockSize * num6;
            ulong sizeParts = lastPartSize + ((partsReq - 1) * num7);

            Console.WriteLine("+ Creating LIVE header...");
            createConHeader(path.Substring(0, path.Length - 5), iso, blocksReq, 0, partsReq, sizeParts, lastMhtHash);
            stream.Close();
            stream.Dispose();
            gdf.Dispose();
            Finish = DateTime.Now;
            TimeSpan span = Finish - Start;

            Console.WriteLine("+ Done!");
            Console.WriteLine("+ Finished in " + span.Minutes + "m" + span.Seconds + "s. GOD package written to: " + path);
            GC.Collect();
        }
Example #19
0
 private long sectorsToSize(GDF src, uint sectors)
 {
     return(sectors * src.VolDesc.SectorSize);
 }
Example #20
0
 private uint sizeToSectors(GDF src, uint size)
 {
     return((uint)Math.Ceiling(size / ((double)src.VolDesc.SectorSize)));
 }