Exemple #1
0
        private void ReadFileSystem()
        {
            XFSInputFile ifile = new XFSInputFile(this, this.RootSectorBlockSize * 0x800, this.RootSectorBlock);

            this.RootDir    = new XDvdFsFileSystemEntry(ifile);
            this.CurrentDir = this.RootDir;
            ISOFileStreamer ifs = new ISOFileStreamer(this.fileSystemOffset, new BinaryReader(this.GetStream()));

            ifs.GetNewFile(ifile);
            byte[] buffer = new byte[this.RootSectorBlockSize * 0x800];
            ifs.Read(buffer, 0, this.RootSectorBlockSize * 0x800);
            this.ReadFileSystemData(buffer, 0, this.RootDir, ifs);
            List <XDvdFsFileSystemEntry> fileList = this.RootDir.GetFileList();

            fileList.Sort(new FSOutSectorComparer());
            XDvdFsFileSystemEntry fse = new XDvdFsFileSystemEntry(new FSFolder("Temp"));

            foreach (XDvdFsFileSystemEntry entry2 in fileList)
            {
                if (((fse.StartSector == entry2.StartSector) && (fse.LogicalFileSize == entry2.LogicalFileSize)) && !entry2.IsFolder)
                {
                    entry2.SetLinkedTo(fse);
                }
                fse = entry2;
            }
        }
Exemple #2
0
 private void WalkDir(XDvdFsFileSystemEntry fn, List <XDvdFsFileSystemEntry> FileSystemArray, bool folderslast)
 {
     foreach (XDvdFsFileSystemEntry entry in fn.Files)
     {
         if (!entry.IsFolder || !folderslast)
         {
             FileSystemArray.Add(entry);
             if (entry.IsFolder && (entry.Files.Count != 0))
             {
                 this.WalkDir(entry, FileSystemArray, folderslast);
             }
         }
     }
     if (folderslast)
     {
         foreach (XDvdFsFileSystemEntry entry2 in fn.Files)
         {
             if (entry2.IsFolder)
             {
                 FileSystemArray.Add(entry2);
                 if (entry2.Files.Count != 0)
                 {
                     this.WalkDir(entry2, FileSystemArray, folderslast);
                 }
             }
         }
     }
 }
Exemple #3
0
 public void SetLinkedTo(XDvdFsFileSystemEntry fse)
 {
     if (this._copymethod != OutputMethod.Crosslink)
     {
         this.ParentNode.Files.UpdateSizes(0, 0, (long)(((int)this.LogicalFileSize) * -1));
     }
     this.linkedTo    = fse;
     this._copymethod = OutputMethod.Crosslink;
 }
Exemple #4
0
        public XDvdFsFileSystemEntry GetFileSystem()
        {
            XDvdFsFileSystemEntry tofolder = this.RootDir.ShallowCopy();

            this.RecurseGetFS(this.RootDir, tofolder);
            base.isoXDvdFsFileSystem = tofolder;
            base.ParseDefaultExecutable();
            return(tofolder);
        }
Exemple #5
0
 private void RecurseGetFS(XDvdFsFileSystemEntry fromfolder, XDvdFsFileSystemEntry tofolder)
 {
     foreach (XDvdFsFileSystemEntry entry in fromfolder.Files)
     {
         XDvdFsFileSystemEntry entry2 = entry.ShallowCopy();
         tofolder.Files.Add(entry2);
         if (entry.IsFolder)
         {
             this.RecurseGetFS(entry, entry2);
         }
     }
 }
Exemple #6
0
        private void ReadFileSystemData(byte[] buffer, int fsOffset, XDvdFsFileSystemEntry parentEntry, ISOFileStreamer ifs)
        {
            if (fsOffset > buffer.Length)
            {
                throw new SystemException("Disaster");
            }
            XFSInputFile          ifile = new XFSInputFile(this, buffer, fsOffset);
            XDvdFsFileSystemEntry entry = new XDvdFsFileSystemEntry(ifile);

            entry.ParentNode = parentEntry;
            ushort num  = BitConverter.ToUInt16(buffer, fsOffset);
            ushort num2 = BitConverter.ToUInt16(buffer, fsOffset + 2);

            if (ifile.StartSector == -1)
            {
                throw new SystemException("Invalid TOC entry");
            }
            if (num != 0)
            {
                if ((num * 4) > buffer.Length)
                {
                    throw new SystemException("Disaster 2!");
                }
                this.ReadFileSystemData(buffer, num * 4, parentEntry, ifs);
            }
            if (ifile.IsFolder())
            {
                if ((ifile.StartSector == 0) || (ifile.GetFileLength() == 0L))
                {
                    parentEntry.Files.Add(entry);
                }
                else
                {
                    byte[] buffer2 = new byte[ifile.GetFileLength()];
                    ifs.GetNewFile(ifile);
                    ifs.Read(buffer2, 0, (int)ifile.GetFileLength());
                    parentEntry.Files.Add(entry);
                    this.ReadFileSystemData(buffer2, 0, entry, ifs);
                }
            }
            else
            {
                parentEntry.Files.Add(entry);
            }
            if (num2 != 0)
            {
                if ((num2 * 4) > buffer.Length)
                {
                    throw new SystemException("Disaster 3!");
                }
                this.ReadFileSystemData(buffer, num2 * 4, parentEntry, ifs);
            }
        }
Exemple #7
0
        public XDvdFsFileSystemEntry ShallowCopy()
        {
            XDvdFsFileSystemEntry entry = new XDvdFsFileSystemEntry(this.GetInfile());

            entry.Attributes  = this.Attributes;
            entry.StartSector = this.StartSector;
            entry.CopyMethod  = this.CopyMethod;
            if (this.CopyMethod == OutputMethod.Crosslink)
            {
                entry.SetLinkedTo(this.linkedTo);
            }
            entry.FileName = this.FileName;
            return(entry);
        }
Exemple #8
0
        public string GetPathAsString(bool ShowRoot)
        {
            XDvdFsFileSystemEntry parentNode = this;
            string str = "";

            while (parentNode.ParentNode != null)
            {
                parentNode = parentNode.ParentNode;
                if (ShowRoot || (parentNode.ParentNode != null))
                {
                    str = parentNode.FileName + "/" + str;
                }
            }
            return(str);
        }
Exemple #9
0
        public void ParseDefaultExecutable()
        {
            this.hasdefaultexe  = false;
            this.HasMediaID     = false;
            this.HasRegionFlags = false;
            XDvdFsFileSystemEntry sourceXDvdFsFile = new XDvdFsFileSystemEntry(new FSFolder("Temp"));

            if (this.GetISOType() == Format.Xbox360)
            {
                sourceXDvdFsFile = this.isoXDvdFsFileSystem.Files.GetFileByNameNoCase("default.xex");
            }
            else
            {
                sourceXDvdFsFile = this.isoXDvdFsFileSystem.Files.GetFileByNameNoCase("default.xbe");
            }
            if (sourceXDvdFsFile != null)
            {
                this.hasdefaultexe  = true;
                this.HasMediaID     = true;
                this.HasRegionFlags = true;
                Trace.WriteLine(sourceXDvdFsFile.FileName + " found, processing");
                if (!this.CanStream())
                {
                    FileWriter writer = new FileWriter();
                    Trace.WriteLine("Source Filesystem cannot be streamed from, copying executable to temp folder");
                    string destination = AppDomain.CurrentDomain.BaseDirectory + @"temp\" + Path.GetRandomFileName();
                    Trace.WriteLine("Copying to " + destination);
                    writer.SaveFileToDisk(sourceXDvdFsFile, destination);
                    sourceXDvdFsFile.SetInFile(new FSFile(destination));
                }
                if (this.GetISOType() == Format.Xbox360)
                {
                    Stream  infile = sourceXDvdFsFile.GetStream();
                    XEXFile file   = new XEXFile(infile);
                    Trace.WriteLine("Xex MediaID = " + BitConverter.ToString(file.MediaID));
                    file.MediaID.CopyTo(this.MediaID, 0);
                    infile.Close();
                }
                else
                {
                    Stream  stream = sourceXDvdFsFile.GetStream();
                    XBEFile file2  = new XBEFile(stream);
                    this.MediaID = new byte[0x10];
                    stream.Close();
                }
            }
        }
Exemple #10
0
        // Methods
        private int alignTree(FileSystemFolder fsfolder, List <BinaryTree> treelist, Dictionary <string, int> fsDictionary, string[] fsArray)
        {
            bool flag = true;
            int  num  = 0;

            while (flag)
            {
                int num2 = 1;
                flag = false;
                foreach (BinaryTree tree in treelist)
                {
                    string str = fsArray[tree.listposition];
                    XDvdFsFileSystemEntry entry = fsfolder[fsDictionary[str]];
                    if ((tree.offset < (0x800 * num2)) && ((tree.offset + (entry.FileName.Length + 14)) > (0x800 * num2)))
                    {
                        int offset = tree.offset;
                        int num4   = (0x800 * num2) - tree.offset;
                        num += num4;
                        foreach (BinaryTree tree2 in treelist)
                        {
                            if (tree2.offset >= offset)
                            {
                                tree2.offset += num4;
                            }
                            if (tree2.leftNodeOffset >= offset)
                            {
                                tree2.leftNodeOffset += num4;
                            }
                            if (tree2.rightNodeOffset >= offset)
                            {
                                tree2.rightNodeOffset += num4;
                            }
                        }
                        flag = true;
                        num2++;
                    }
                }
            }
            return(num);
        }
Exemple #11
0
        public byte[] DirContentsToByteArray(FileSystemFolder fsfolder)
        {
            if (fsfolder.Count == 0)
            {
                return(new byte[0]);
            }
            Dictionary <string, int> fsDictionary = new Dictionary <string, int>();
            List <string>            list         = new List <string>(fsfolder.Count);

            for (int i = 0; i < fsfolder.Count; i++)
            {
                if (fsfolder[i].CopyMethod != OutputMethod.Special)
                {
                    fsDictionary.Add(fsfolder[i].FileName, i);
                    list.Add(fsfolder[i].FileName);
                }
            }
            string[] array = list.ToArray();
            Array.Sort <string>(array, new FSFilenameComparer());
            BinaryTree tree      = new BinaryTree();
            int        maxcentre = (array.Length - 1) / 2;

            if (maxcentre != 0)
            {
                maxcentre = BinaryTree.findTreeCentre(maxcentre, array.Length - 1);
            }
            List <BinaryTree> treeList = new List <BinaryTree>();
            int num3 = tree.populate(array, array.Length - 1, 0, 0, maxcentre, treeList);

            if (num3 > 0x800)
            {
                num3 += this.alignTree(fsfolder, treeList, fsDictionary, array);
            }
            byte[] buffer = new byte[num3];
            for (int j = 0; j < num3; j++)
            {
                buffer[j] = 0xff;
            }
            foreach (BinaryTree tree2 in treeList)
            {
                string str = array[tree2.listposition];
                XDvdFsFileSystemEntry entry = fsfolder[fsDictionary[str]];
                tree2.leftNodeOffset  /= 4;
                tree2.rightNodeOffset /= 4;
                BitConverter.GetBytes((short)tree2.leftNodeOffset).CopyTo(buffer, tree2.offset);
                BitConverter.GetBytes((short)tree2.rightNodeOffset).CopyTo(buffer, (int)(tree2.offset + 2));
                BitConverter.GetBytes(entry.StartSector).CopyTo(buffer, (int)(tree2.offset + 4));
                if (entry.IsFolder)
                {
                    BitConverter.GetBytes((uint)entry.Files.LogicalDirTableSize).CopyTo(buffer, (int)(tree2.offset + 8));
                }
                else
                {
                    BitConverter.GetBytes((uint)entry.LogicalFileSize).CopyTo(buffer, (int)(tree2.offset + 8));
                }
                BitConverter.GetBytes((short)entry.Attributes).CopyTo(buffer, (int)(tree2.offset + 12));
                BitConverter.GetBytes((short)((byte)entry.FileName.Length)).CopyTo(buffer, (int)(tree2.offset + 13));
                ASCIIEncoding encoding = new ASCIIEncoding();
                encoding.GetBytes(entry.FileName).CopyTo(buffer, (int)(tree2.offset + 14));
            }
            return(buffer);
        }