Beispiel #1
0
        /// <summary>
        /// Returns a stream pointed to the decompressed file at the given address
        /// </summary>
        /// <param name="virtualAddress"></param>
        /// <param name="recordCopy"></param>
        /// <returns></returns>
        public RomFile GetFile(long virtualAddress)
        {
            FileRecord record; //file we're looking up

            if (!DmaTable.TryGetValue(virtualAddress, out record))
            {
                throw new Exception();
            }

            return(GetFile(new FileRecord(record)));
        }
Beispiel #2
0
        /// <summary>
        /// Gets the virtual FileAddress of a file with a given start address
        /// </summary>
        /// <param name="address">The file's VROM address. Must match FileAddress's Vrom.Start</param>
        /// <returns>The returned FileAddress</returns>
        public FileAddress GetVRomAddress(long address)
        {
            FileRecord record;

            if (!DmaTable.TryGetValue(address, out record))
            {
                throw new FileNotFoundException();
            }

            return(record.VirtualAddress);
        }
Beispiel #3
0
        /// <summary>
        /// Tries to return the virtual FileAddress of a file with a given start address
        /// </summary>
        /// <param name="address">The file's VROM address. Must match FileAddress's Vrom.Start</param>
        /// <param name="resultAddress">The returned FileAddress</param>
        /// <returns>True if the operation is successful</returns>
        public bool TryGetVirtualAddress(long address, out FileAddress resultAddress)
        {
            FileRecord record;
            bool       getValue;

            getValue = DmaTable.TryGetValue(address, out record);
            if (getValue)
            {
                resultAddress = record.VirtualAddress;
            }
            else
            {
                resultAddress = new FileAddress();
            }
            return(getValue);
        }
Beispiel #4
0
        /// <summary>
        /// Returns a stream pointed to the decompressed file at the given address
        /// </summary>
        /// <param name="virtualAddress"></param>
        /// <returns></returns>
        public RomFile GetFile(FileAddress virtualAddress)
        {
            FileRecord record, temp;

            temp = new FileRecord(virtualAddress, new FileAddress(virtualAddress.Start, 0), -1);

            if (DmaTable.TryGetValue(virtualAddress.Start, out record))
            {
                if (virtualAddress.Size != record.VirtualAddress.Size)
                {
                    record = temp;
                }
            }
            else
            {
                record = temp;
            }
            return(GetFile(record));
        }
Beispiel #5
0
        /// <summary>
        /// Returns a file without attempting to decompress it.
        /// </summary>
        /// <param name="virtualAddress">Address containing the location of the file</param>
        /// <returns></returns>
        public Stream GetPhysicalFile(long virtualAddress)
        {
            MemoryStream ms;

            byte[]     data;
            FileRecord tableRecord; //file we're looking up

            if (!DmaTable.TryGetValue(virtualAddress, out tableRecord))
            {
                throw new Exception();
            }

            using (FileStream fs = new FileStream(RomLocation, FileMode.Open, FileAccess.Read))
            {
                data        = new byte[tableRecord.DataAddress.Size];
                fs.Position = tableRecord.DataAddress.Start;
                fs.Read(data, 0, (int)tableRecord.DataAddress.Size);
            }
            return(ms = new MemoryStream(data));
        }
Beispiel #6
0
 /// <summary>
 /// Tries to get the full FileRecord for a file with the given starting virtual address
 /// </summary>
 /// <param name="virtualAddress">The virtual address of the record to return.</param>
 /// <param name="record">Returns the full FileRecord for that file</param>
 /// <returns>True if operation is successful</returns>
 public bool TryGetFileRecord(long virtualAddress, out FileRecord record)
 {
     return(DmaTable.TryGetValue(virtualAddress, out record));
 }
Beispiel #7
0
 /// <summary>
 /// Tries to get the full FileRecord for a file with the given virtual FileAddress
 /// </summary>
 /// <param name="virtualAddress">The virtual FileAddress of the record to return. Does not verify end address</param>
 /// <param name="record">Returns the full FileRecord for that file</param>
 /// <returns>True if operation is successful</returns>
 public bool TryGetFileRecord(FileAddress virtualAddress, out FileRecord record)
 {
     return(DmaTable.TryGetValue(virtualAddress.Start, out record));
 }
Beispiel #8
0
 /// <summary>
 /// Returns the full FileRecord for a file that contains the given address
 /// </summary>
 /// <param name="virtualAddress"></param>
 /// <returns>The FileRecord of the containing file, or null if no file contains the given address</returns>
 public FileRecord GetFileStart(long virtualAddress)
 {
     return(DmaTable.FirstOrDefault(x => x.Value.VirtualAddress.Start <= virtualAddress &&
                                    virtualAddress < x.Value.VirtualAddress.End).Value);
 }