public void Dispose() { _src = null; _root = null; _tables.Clear(); GC.Collect(); }
public void Dispose() { this.src = null; this.root = null; this.tables.Clear(); GC.Collect(); }
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; }
public GDFRepack(GDF Source, string TempPath) { this.src = Source; this.path = TempPath; }
public GDFRepack(GDF source, string tempPath) { _src = source; _path = tempPath; }
private void writeGDFtable(GDF src, CBinaryWriter bw, GDFDirTable table) { bw.Seek((long) (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)) { this.writeGDFtable(src, bw, entry.SubDir); } } }
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(this.rootDir.Sector); bw.Write((uint) (this.sizeToSectors(src, this.rootDir.Size) * src.VolDesc.SectorSize)); bw.Write(src.VolDesc.ImageCreationTime); bw.Write((byte) 1); bw.Seek(0x107ecL, SeekOrigin.Begin); bw.Write(src.VolDesc.Identifier); }
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(); }
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); } } }
private uint sizeToSectors(GDF src, uint size) { return (uint) Math.Ceiling((double) (((double) size) / ((double) src.VolDesc.SectorSize))); }
private long sectorsToSize(GDF src, uint sectors) { return (long) (sectors * src.VolDesc.SectorSize); }
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); } }
private void remapFiles(GDF src, GDFDirTable table) { foreach (GDFDirEntry entry in table) { if (!entry.IsDirectory) { entry.Sector = this.freeSector; this.freeSector += this.sizeToSectors(src, entry.Size); } } foreach (GDFDirEntry entry2 in table) { if (entry2.IsDirectory && (entry2.SubDir != null)) { this.remapFiles(src, entry2.SubDir); } } }
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); } } } }
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); }
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); }
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."); } }