Ejemplo n.º 1
0
        public DARC(byte[] Data = null)
        {
            if (Data == null) return;
            using (BinaryReader br = new BinaryReader(new MemoryStream(Data)))
            try
            {
                Header = new DARCHeader(br);
                br.BaseStream.Position = Header.FileTableOffset;
                FileTableEntry root = new FileTableEntry(br);
                Entries = new FileTableEntry[root.DataLength];
                Entries[0] = root;
                for (int i = 1; i < root.DataLength; i++) Entries[i] = new FileTableEntry(br);
                FileNameTable = new NameTableEntry[root.DataLength];
                uint offs = 0;
                for (int i = 0; i < root.DataLength; i++)
                {
                    char c; string s = string.Empty;
                    while ((c = (char) br.ReadUInt16()) > 0) s += c;

                    FileNameTable[i] = new NameTableEntry(offs, s);
                    offs += (uint)s.Length * 2 + 2;
                }
                br.BaseStream.Position = Header.FileDataOffset;
                this.Data = br.ReadBytes((int)(Header.FileSize - Header.FileDataOffset));
            }
            catch (Exception)
            { br.Close(); }
        }
Ejemplo n.º 2
0
        public FileTableEntry AddChild(string name, EntryType type, uint mapsBitmask)
        {
            FileTableEntry entry = AddChild(name, type);

            ((TagArchiveFileTableEntry)entry).MapsBitmask = mapsBitmask;
            return(entry);
        }
Ejemplo n.º 3
0
        public DARC(byte[] Data)
        {
            EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(Data), Endianness.LittleEndian);

            try
            {
                Header = new darcHeader(er);
                er.BaseStream.Position = Header.FileTableOffset;
                FileTableEntry root = new FileTableEntry(er);
                Entries    = new FileTableEntry[root.DataLength];
                Entries[0] = root;
                for (int i = 1; i < root.DataLength; i++)
                {
                    Entries[i] = new FileTableEntry(er);
                }
                FileNameTable = new Dictionary <uint, string>();
                uint offs = 0;
                for (int i = 0; i < root.DataLength; i++)
                {
                    String s = er.ReadStringNT(Encoding.Unicode);
                    FileNameTable.Add(offs, s);
                    offs += (uint)s.Length * 2 + 2;
                }
                er.BaseStream.Position = Header.FileDataOffset;
                this.Data = er.ReadBytes((int)(Header.FileSize - Header.FileDataOffset));
            }
            finally
            {
                er.Close();
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns a boolean indicating if the specified entry has file data.
 /// </summary>
 public bool Match(FileTableEntry entry)
 {
     if (entry.FullPath.Contains("collectidsfsdon"))
     {
         System.Diagnostics.Debugger.Break();
     }
     return(entry.DataOffset == FileTableEntry.NullOffset);
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Reads a file from the archive.
 /// </summary>
 public override byte[] ReadFile(FileTableEntry entry)
 {
     if (entry.DataOffset == FileTableEntry.NullOffset)
     {
         throw new Exception("The specified file does not exist in the archive: " + entry.FullPath);
     }
     return(base.ReadFile(entry));
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Searches the archive to see if the specified file exists.
        /// </summary>
        public override bool FileExists(string filename)
        {
            string         path   = Path.GetDirectoryName(filename);
            FileTableEntry folder = fileTable.GetEntry(path, EntryType.Folder);

            if (folder == null)
            {
                return(false);
            }

            return(folder.GetChildren(new NameFilter(Path.GetFileName(filename)),
                                      new EntryTypeFilter(EntryType.File), DataFilter).Count > 0);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Adds a tag to the archive.
        /// An entry for the tag must exist in the filetable.
        /// </summary>
        public override void AddFile(string filename, byte[] buffer)
        {
            // See if an entry for this file already exists in the filetable.
            FileTableEntry entry = fileTable.GetEntry(filename, EntryType.File);

            if (entry == null)
            {
                throw new Exception("The specified file is not allowed in this archive: " + filename);
            }

            // Add the file under the existing entry in the file table.
            AddFile(entry, buffer);
            OnFileAdded(filename);
        }
Ejemplo n.º 8
0
        public override string[] GetFileList(string path, string extension, bool recursive)
        {
            // Make sure that the path we are looking in exists.
            FileTableEntry folder = fileTable.GetEntry(path, EntryType.Folder);

            if (folder == null)
            {
                return(new string[0]);
            }

            List <FileTableEntry> entries = folder.GetChildren(recursive,
                                                               new ExtensionFilter(extension), new EntryTypeFilter(EntryType.File), DataFilter);

            return(FileTableEntry.EntriesToPaths(entries.ToArray()));
        }
Ejemplo n.º 9
0
        public RARC(byte[] Data)
        {
            EndianBinaryReader er = new EndianBinaryReader(new MemoryStream(Data), Endianness.BigEndian);

            try
            {
                Header                 = new RARCHeader(er);
                ArchiveInfo            = new InfoBlock(er);
                er.BaseStream.Position = ArchiveInfo.FolderTableOffset + Header.HeaderSize;
                FolderTable            = new FolderTableEntry[ArchiveInfo.NrFolderTableEntries];
                for (int i = 0; i < ArchiveInfo.NrFolderTableEntries; i++)
                {
                    FolderTable[i] = new FolderTableEntry(er);
                }

                er.BaseStream.Position = ArchiveInfo.FileTableOffset + Header.HeaderSize;
                FileTable = new FileTableEntry[ArchiveInfo.NrFileTableEntries];
                for (int i = 0; i < ArchiveInfo.NrFileTableEntries; i++)
                {
                    FileTable[i] = new FileTableEntry(er);
                }

                for (int i = 0; i < ArchiveInfo.NrFolderTableEntries; i++)
                {
                    er.BaseStream.Position = ArchiveInfo.StringTableOffset + Header.HeaderSize + FolderTable[i].NameOffset;
                    FolderTable[i].Name    = er.ReadStringNT(Encoding.ASCII);
                }

                for (int i = 0; i < ArchiveInfo.NrFileTableEntries; i++)
                {
                    er.BaseStream.Position = ArchiveInfo.StringTableOffset + Header.HeaderSize + FileTable[i].NameOffset;
                    FileTable[i].Name      = er.ReadStringNT(Encoding.ASCII);
                }

                er.BaseStream.Position = Header.HeaderSize + Header.FileDataOffset;
                this.Data = er.ReadBytes((int)Header.FileDataLength1);
            }
            finally
            {
                er.Close();
            }
        }
        public void ParseFileTable(FileStream isoStream)
        {
            FileTableEntry tableEntry = new FileTableEntry();
            long           fileTableMinOffset;
            long           fileTableMaxOffset;

            long fileSize = isoStream.Length;

            // get offset for blocks
            fileTableMinOffset = ComputeBlockNumberAndGetOffset(this.FileTableBlockNumber, this.HeaderSize, this.BlockSeparation);
            fileTableMaxOffset = ComputeBlockNumberAndGetOffset(this.FileTableBlockNumber + this.FileTableBlockCount, this.HeaderSize, this.BlockSeparation);

            // check offsets
            if ((fileTableMinOffset >= MicrosoftSTFS.FIRST_BLOCK_OFFSET) &&
                (fileTableMinOffset < fileTableMaxOffset) &&
                (fileTableMaxOffset < fileSize))
            {
                for (long i = fileTableMinOffset; i < fileTableMaxOffset; i += 0x40)
                {
                    tableEntry.FileName = ParseFile.ReadAsciiString(isoStream, i);

                    if (!String.IsNullOrEmpty(tableEntry.FileName))
                    {
                        tableEntry.Flags                  = ParseFile.ReadByte(isoStream, i + 0x28);
                        tableEntry.BlocksForFileLE1       = ParseFile.ReadInt24LE(isoStream, i + 0x29);
                        tableEntry.BlocksForFileLE2       = ParseFile.ReadInt24LE(isoStream, i + 0x2C);
                        tableEntry.StartingBlockForFileLE = ParseFile.ReadInt24LE(isoStream, i + 0x2F);
                        tableEntry.PathIndicator          = ParseFile.ReadInt16BE(isoStream, i + 0x32);
                        tableEntry.FileSize               = ParseFile.ReadUintBE(isoStream, i + 0x34);
                        tableEntry.UpdateDateTime         = ParseFile.ReadInt32BE(isoStream, i + 0x38);
                        tableEntry.AccessDateTime         = ParseFile.ReadInt32BE(isoStream, i + 0x3C);

                        FileTableEntryArray.Add(tableEntry);
                    }
                }
            }
            else
            {
                throw new IndexOutOfRangeException("File Table block IDs do not make sense.");
            }
        }
Ejemplo n.º 11
0
        public Darc(byte[] data = null)
        {
            if (data == null)
            {
                return;
            }
            using (BinaryReader br = new BinaryReader(new MemoryStream(data)))
                try
                {
                    this.Header            = new DarcHeader(br);
                    br.BaseStream.Position = this.Header.FileTableOffset;
                    FileTableEntry root = new FileTableEntry(br);
                    this.Entries    = new FileTableEntry[root.DataLength];
                    this.Entries[0] = root;
                    for (int i = 1; i < root.DataLength; i++)
                    {
                        this.Entries[i] = new FileTableEntry(br);
                    }
                    this.FileNameTable = new NameTableEntry[root.DataLength];
                    uint offs = 0;
                    for (int i = 0; i < root.DataLength; i++)
                    {
                        char   c;
                        string s = string.Empty;
                        while ((c = (char)br.ReadUInt16()) > 0)
                        {
                            s += c;
                        }

                        this.FileNameTable[i] = new NameTableEntry(offs, s);
                        offs += (uint)s.Length * 2 + 2;
                    }
                    br.BaseStream.Position = this.Header.FileDataOffset;
                    this.Data = br.ReadBytes((int)(this.Header.FileSize - this.Header.FileDataOffset));
                }
                catch (Exception)
                {
                    br.Close();
                }
        }
Ejemplo n.º 12
0
        public override string[] GetFolderList(string path)
        {
            // TEST CODE ::: Writes (supposedly) all entries in the filetable to a txt file.
            //List<FileTableEntry> test = fileTable.RootEntry.GetChildren(true);
            //System.IO.StreamWriter writer = new StreamWriter("C:\\test.txt");
            //foreach (FileTableEntry testEntry in test)
            //  writer.WriteLine(testEntry.FullPath + " - " + Enum.GetName(typeof(EntryType), testEntry.EntryType));
            //writer.Close();

            // Make sure that the path we are looking in exists.
            FileTableEntry folder = fileTable.GetEntry(path, EntryType.Folder);

            if (folder == null)
            {
                return(new string[0]);
            }

            // Get the results.
            List <IEntryFilter> filters = new List <IEntryFilter>();

            filters.Add(new EntryTypeFilter(EntryType.Folder));

            // Apply the proper filters based on the constraint.
            if (resultConstraint == ResultConstraint.ExistingFiles)
            {
                filters.Add(new ContainsFilesFilter());
            }
            if (resultConstraint == ResultConstraint.MissingFiles)
            {
                filters.Add(new ContainsMissingFilesFilter());
            }

            // Get the results.
            List <FileTableEntry> entries = folder.GetChildren(filters.ToArray());

            return(FileTableEntry.EntriesToPaths(entries.ToArray()));
        }
Ejemplo n.º 13
0
 /// <summary>
 /// Returns a boolean indicating if the specified entry matches the name.
 /// </summary>
 public bool Match(FileTableEntry entry)
 {
     return(entry.Name.ToUpper() == name);
 }
        public void BuildDirectoryTree()
        {
            Dictionary <int, MicrosoftSTFSDirectoryStructure> directoryList = new Dictionary <int, MicrosoftSTFSDirectoryStructure>();

            FileTableEntry fileTableEntry = new FileTableEntry();
            MicrosoftSTFSDirectoryStructure parentDirectoryStructure;
            MicrosoftSTFSDirectoryStructure directoryStructure;
            MicrosoftSTFSFileStructure      fileStructure;

            String parentDirectoryName = String.Empty;

            ArrayList keyListArray = new ArrayList();

            int[] keyList;

            //------------------
            // add root folder
            //------------------
            directoryStructure = new MicrosoftSTFSDirectoryStructure(this.SourceFileName, String.Empty, String.Empty, MicrosoftSTFS.ROOT_DIRECTORY_PATH_INDICATOR);
            directoryList.Add(MicrosoftSTFS.ROOT_DIRECTORY_PATH_INDICATOR, directoryStructure);

            //----------------------
            // build directory list
            //----------------------
            for (int i = 0; i < FileTableEntries.Length; i++)
            {
                fileTableEntry = FileTableEntries[i];

                // build parent directory name
                parentDirectoryName = Path.Combine(directoryList[fileTableEntry.PathIndicator].ParentDirectoryName,
                                                   directoryList[fileTableEntry.PathIndicator].DirectoryName);

                if (fileTableEntry.IsDirectory)
                {
                    // create directory
                    directoryStructure =
                        new MicrosoftSTFSDirectoryStructure(this.SourceFileName,
                                                            fileTableEntry.FileName, parentDirectoryName, fileTableEntry.PathIndicator);

                    // add to list
                    directoryList.Add(i, directoryStructure);
                }
                else
                {
                    // create file structure
                    fileStructure = new MicrosoftSTFSFileStructure(
                        parentDirectoryName, this.SourceFileName,
                        fileTableEntry.FileName, this.VolumeBaseOffset,
                        fileTableEntry.StartingBlockForFileLE,
                        fileTableEntry.FileSize,
                        ByteConversion.GetDateTimeFromFAT32Date(fileTableEntry.UpdateDateTime),
                        fileTableEntry.BlocksForFileLE1,
                        this.HeaderSize, this.BlockSeparation);

                    // add to directory
                    directoryList[fileTableEntry.PathIndicator].FileArray.Add(fileStructure);
                }
            } // for (int i = 0; i < FileTableEntries.Length; i++)

            //-----------------------
            // assemble directories
            //-----------------------

            // build reversed keyList
            foreach (int key in directoryList.Keys)
            {
                keyListArray.Add(key);
            }

            keyListArray.Sort();
            keyList = (int[])keyListArray.ToArray(typeof(int));

            // loop through dirs backwards
            for (int i = keyList.GetUpperBound(0); i > 0; i--)
            {
                // add to sub directory of parent
                directoryStructure       = directoryList[keyList[i]];
                parentDirectoryStructure = directoryList[directoryStructure.ParentDirectoryId];
                parentDirectoryStructure.SubDirectoryArray.Add(directoryStructure);

                // remove from directoryList
                directoryList.Remove(keyList[i]);
            }

            // Add root element to Volumes directory list
            this.DirectoryStructureArray.Add(directoryList[MicrosoftSTFS.ROOT_DIRECTORY_PATH_INDICATOR]);
        }
Ejemplo n.º 15
0
 public bool Match(FileTableEntry entry)
 {
     return(entry.EntryType == entryType);
 }
Ejemplo n.º 16
0
 /// <summary>
 /// Returns a boolean indicating if the specified entry has file data.
 /// </summary>
 public bool Match(FileTableEntry entry)
 {
     return(entry.DataOffset != FileTableEntry.NullOffset);
 }
Ejemplo n.º 17
0
 public bool Match(FileTableEntry entry)
 {
     return((Path.GetExtension(entry.Name).Trim('.').ToLower() == fileExtension) || fileExtension == "*");
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Returns a boolean indicating if the specified entry exists at the specified offset.
 /// </summary>
 public bool Match(FileTableEntry entry)
 {
     return(entry.Offset == offset);
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Returns a boolean indicating if the specified entry matches the filter's criteria.
        /// </summary>
        public bool Match(FileTableEntry entry)
        {
            List <FileTableEntry> files = entry.GetChildren(true, new EntryTypeFilter(EntryType.File), new HasNoDataFilter());

            return(files.Count > 0);
        }