Example #1
0
 /// <summary>
 /// Patches the file at a given sector in an ISO.
 /// </summary>
 /// <param name="isoType">The type of ISO</param>
 /// <param name="isoFile">Path to the ISO image</param>
 /// <param name="patchEccEdc">Whether or not ECC/EDC blocks should be updated</param>
 /// <param name="sectorNumber">The sector number where the file begins</param>
 /// <param name="offset">Where in the file to start writing</param>
 /// <param name="input">Bytes to write</param>
 public static void PatchFileAtSector(IsoType isoType, string isoFile, bool patchEccEdc, int sectorNumber, long offset, IList <byte> input, bool patchIso)
 {
     using (FileStream stream = new FileStream(isoFile, FileMode.Open))
     {
         PatchFileAtSector(isoType, stream, patchEccEdc, sectorNumber, offset, input, patchIso);
     }
 }
Example #2
0
 private void readVolume()
 {
     volDesc            = new GDFVolumeDescriptor();
     volDesc.SectorSize = 0x800;
     fr.Seek(0x20 * volDesc.SectorSize, SeekOrigin.Begin);
     if (Encoding.ASCII.GetString(fr.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
     {
         type = IsoType.Xsf;
         volDesc.RootOffset = (uint)type;
     }
     else
     {
         file.Seek((0x20 * volDesc.SectorSize) + 0xfd90000, SeekOrigin.Begin);
         if (Encoding.ASCII.GetString(fr.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
         {
             type = IsoType.Gdf;
             volDesc.RootOffset = (uint)type;
         }
         else
         {
             type = IsoType.XGD3;
             volDesc.RootOffset = (uint)type;
         }
     }
     file.Seek((0x20 * volDesc.SectorSize) + volDesc.RootOffset, SeekOrigin.Begin);
     volDesc.Identifier        = fr.ReadBytes(20);
     volDesc.RootDirSector     = fr.ReadUInt32();
     volDesc.RootDirSize       = fr.ReadUInt32();
     volDesc.ImageCreationTime = fr.ReadBytes(8);
     volDesc.VolumeSize        = (ulong)(fr.BaseStream.Length - volDesc.RootOffset);
     volDesc.VolumeSectors     = (uint)(volDesc.VolumeSize / volDesc.SectorSize);
 }
Example #3
0
 private void readVolume()
 {
     this.volDesc            = new GDFVolumeDescriptor();
     this.volDesc.SectorSize = 0x800;
     this.fr.Seek((long)(0x20 * this.volDesc.SectorSize), SeekOrigin.Begin);
     if (Encoding.ASCII.GetString(this.fr.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
     {
         this.type = IsoType.Xsf;
         this.volDesc.RootOffset = (uint)this.type;
     }
     else
     {
         this.file.Seek((long)((0x20 * this.volDesc.SectorSize) + 0xfd90000), SeekOrigin.Begin);
         if (Encoding.ASCII.GetString(this.fr.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
         {
             this.type = IsoType.Gdf;
             this.volDesc.RootOffset = (uint)this.type;
         }
         else
         {
             this.type = IsoType.XGD3;
             this.volDesc.RootOffset = (uint)this.type;
         }
     }
     this.file.Seek((long)((0x20 * this.volDesc.SectorSize) + this.volDesc.RootOffset), SeekOrigin.Begin);
     this.volDesc.Identifier        = this.fr.ReadBytes(20);
     this.volDesc.RootDirSector     = this.fr.ReadUInt32();
     this.volDesc.RootDirSize       = this.fr.ReadUInt32();
     this.volDesc.ImageCreationTime = this.fr.ReadBytes(8);
     this.volDesc.VolumeSize        = (ulong)(this.fr.BaseStream.Length - this.volDesc.RootOffset);
     this.volDesc.VolumeSectors     = (uint)(this.volDesc.VolumeSize / ((ulong)this.volDesc.SectorSize));
 }
Example #4
0
        /// <summary>
        /// Creates a new instance to store a value of a given type. This constructor
        /// is used for variable-length types (LLVAR, LLLVAR, ALPHA, NUMERIC) -
        /// variable in the sense that that length of the value does not depend
        /// solely on the ISO type.
        /// </summary>
        /// <param name="t">the ISO8583 type of the value to be stored.</param>
        /// <param name="val">The value to be stored.</param>
        /// <param name="len">The length of the field.</param>
        /// <param name="originalValue">The original value of field</param>
        public IsoValue(IsoType t, Parsing.ConfigParser.Base configBase, Object val, Int32 len, String originalValue, TypeElement typeElement)
        {
            if (val == null)
            {
                throw new ArgumentException("Value cannot be null");
            }

            type               = t;
            fval               = val;
            length             = len;
            b                  = configBase;
            this.originalValue = originalValue;

            if (typeElement == TypeElement.Field || typeElement == TypeElement.SubField)
            {
                if (length == 0 && IsoTypeHelper.NeedsLength(t))
                {
                    throw new ArgumentException("Length must be greater than zero");
                }
            }

            if (t == IsoType.LLVAR || t == IsoType.LLLVAR)
            {
                length = val.ToString().Length;
            }
        }
Example #5
0
 public static string Format(this IsoType isoType,
                             long value,
                             int length)
 {
     if (isoType == IsoType.NUMERIC)
     {
         var x = value.ToString().PadLeft(length,
                                          '0');
         if (x.Length > length)
         {
             throw new ArgumentException("Numeric value is larger than intended length: " + value + " LEN " +
                                         length);
         }
         return(x);
     }
     if (isoType == IsoType.ALPHA || isoType == IsoType.LLVAR || isoType == IsoType.LLLVAR ||
         isoType == IsoType.LLLLVAR)
     {
         return(isoType.Format(Convert.ToString(value),
                               length));
     }
     if (isoType == IsoType.AMOUNT)
     {
         return(value.ToString("0000000000") + "00");
     }
     if (isoType == IsoType.BINARY || isoType == IsoType.LLBIN || isoType == IsoType.LLLBIN ||
         isoType == IsoType.LLLLBIN)
     {
         //TODO
     }
     throw new ArgumentException("Cannot format number as " + isoType);
 }
Example #6
0
        /// <summary>
        /// Creates a new instance to store a value of a given type. This constructor
        /// is used for variable-length types (LLVAR, LLLVAR, ALPHA, NUMERIC) -
        /// variable in the sense that that length of the value does not depend
        /// solely on the ISO type.
        /// </summary>
        /// <param name="t">the ISO8583 type of the value to be stored.</param>
        /// <param name="val">The value to be stored.</param>
        /// <param name="len">The length of the field.</param>
        /// <param name="originalValue">The original value of field</param>
        /// <param name="req">Indicates the requiremts (M,C, CE, ME, O )</param>
        /// <param name="typeElement">Indicates the Type of Element (Field, SubField, SubElement)</param>
        public IsoValue(IsoType t, Parsing.ConfigParser.Base configBase, Object val, Int32 len, String originalValue, String req, TypeElement typeElement, Dictionary <Int32, IsoValue> subData, Int32 subElementIDLength, Int32 lengthLengthSubElement)
        {
            if (val == null)
            {
                throw new ArgumentException("Value cannot be null");
            }

            type                        = t;
            fval                        = val;
            length                      = len;
            this.originalValue          = originalValue;
            requirements                = req;
            this.typeElement            = typeElement;
            this.subElementIDLength     = subElementIDLength;
            this.lengthLengthSubElement = lengthLengthSubElement;
            this.subData                = subData;
            b = configBase;

            if (typeElement == TypeElement.Field || typeElement == TypeElement.SubField)
            {
                if (length == 0 && IsoTypeHelper.NeedsLength(t))
                {
                    throw new ArgumentException("Length must be greater than zero");
                }
            }

            if (t == IsoType.LLVAR || t == IsoType.LLLVAR)
            {
                length = val.ToString().Length;
            }
        }
Example #7
0
        /// <summary>
        /// Creates a new instance to store a value of a given type. This constructor
        /// is used for variable-length types (LLVAR, LLLVAR, ALPHA, NUMERIC) -
        /// variable in the sense that that length of the value does not depend
        /// solely on the ISO type.
        /// </summary>
        /// <param name="t">the ISO8583 type of the value to be stored.</param>
        /// <param name="val">The value to be stored.</param>
        /// <param name="len">The length of the field.</param>
        /// <param name="req">Indicates the requiremts (M,C, CE, ME, O )</param>
        /// <param name="subData">Collection of subDatas (SubField/SubElements) of field</param>
        public IsoValue(IsoType t, Parsing.ConfigParser.Base configBase, Object val, Int32 len, String originalValue, String req, Dictionary <Int32, IsoValue> subData)
        {
            if (val == null)
            {
                throw new ArgumentException("Value cannot be null");
            }

            type         = t;
            fval         = val;
            length       = len;
            b            = configBase;
            this.subData = subData;
            requirements = req;
            FormatOriginalValue();

            if (length == 0 && IsoTypeHelper.NeedsLength(t))
            {
                throw new ArgumentException("Length must be greater than zero");
            }

            if (t == IsoType.LLVAR || t == IsoType.LLLVAR)
            {
                length = val.ToString().Length;
            }
        }
Example #8
0
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(string.Format("Protease={0}\n", Protease.ToString()));

            sb.Append(string.Format("RemoveIonWindow={0:0.####} Dalton\n", MzTolerance));
            sb.Append("RemoveIsobaricIon=" + IsoType.ToString() + ",");

            foreach (var ion in FixIonRanges)
            {
                sb.Append(string.Format("{0:0.####}-{1:0.####},", ion.First, ion.Second));
            }

            if (RemoveHighRange)
            {
                sb.Append(">=" + Protease.GetHighBYFreeWindowDescription() + ",");
            }

            if (RemovePrecursorMinusLabel)
            {
                sb.Append("Precursor-Label;");
            }
            return(sb.ToString());
        }
Example #9
0
        public static void FixupECC( IsoType isoType, Stream iso )
        {
            int type = (int)isoType;
            int sectorSize = sectorSizes[type];
            byte[] sector = new byte[sectorSize];

            if ( iso.Length % sectorSize != 0 )
            {
                throw new ArgumentException( "ISO does not have correct length for its type", "isoType" );
            }
            if ( isoType == IsoType.Mode1 )
            {
                throw new ArgumentException( "Mode1 does not support ECC/EDC", "isoType" );
            }

            Int64 numberOfSectors = iso.Length / sectorSize;
            iso.Seek( 0, SeekOrigin.Begin );
            for ( Int64 i = 0; i < numberOfSectors; i++ )
            {
                iso.Read( sector, 0, sectorSize );

                if ( isoType != IsoType.Mode1 && ( sector[0x12] & 8 ) == 0 )
                {
                    sector[0x12] = 8;
                    sector[0x16] = 8;
                }

                GenerateEccEdc( sector, isoType );
                iso.Seek( -sectorSize, SeekOrigin.Current );
                iso.Write( sector, 0, sectorSize );
            }
        }
Example #10
0
 /// <summary>
 /// Patches the bytes at a given offset.
 /// </summary>
 /// <param name="isoType">The type of ISO</param>
 /// <param name="iso">Stream that contains the ISO</param>
 /// <param name="patchEccEdc">Whether or not ECC/EDC blocks should be updated</param>
 /// <param name="offset">Where in the ISO to start writing</param>
 /// <param name="input">Bytes to write</param>
 public static void PatchFile(IsoType isoType, Stream iso, bool patchEccEdc, long offset, IList <byte> input, bool patchIso)
 {
     using (MemoryStream inputStream = new MemoryStream(input.ToArray()))
     {
         PatchFile(isoType, iso, patchEccEdc, offset, inputStream, patchIso);
     }
 }
        /// <summary>
        /// Gets the type of the input.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <param name="videoType">Type of the video.</param>
        /// <param name="isoType">Type of the iso.</param>
        /// <returns>InputType.</returns>
        public static InputType GetInputType(string path, VideoType? videoType, IsoType? isoType)
        {
            var type = InputType.AudioFile;

            if (videoType.HasValue)
            {
                switch (videoType.Value)
                {
                    case VideoType.BluRay:
                        type = InputType.Bluray;
                        break;
                    case VideoType.Dvd:
                        type = InputType.Dvd;
                        break;
                    case VideoType.Iso:
                        if (isoType.HasValue)
                        {
                            switch (isoType.Value)
                            {
                                case IsoType.BluRay:
                                    type = InputType.Bluray;
                                    break;
                                case IsoType.Dvd:
                                    type = InputType.Dvd;
                                    break;
                            }
                        }
                        break;
                }
            }

            return type;
        }
Example #12
0
        /// <summary>
        /// Formats a DateTime of the specified IsoType as a string.
        /// </summary>
        /// <param name="d">A DateTime object.</param>
        /// <param name="t">An IsoType (must be DATE10, DATE4, DATE_EXP or TIME).</param>
        /// <returns>The date formatted as a string according to the specified IsoType.</returns>
        public static String Format(DateTime d, IsoType t)
        {
            if (t == IsoType.DATE10)
            {
                return(d.ToString("MMddHHmmss"));
            }
            if (t == IsoType.DATE12)
            {
                return(d.ToString("yyMMddHHmmss"));
            }
            if (t == IsoType.DATE4)
            {
                return(d.ToString("MMdd"));
            }
            if (t == IsoType.DATE6)
            {
                return(d.ToString("yyMMdd"));
            }
            if (t == IsoType.DATE_EXP)
            {
                return(d.ToString("yyMM"));
            }
            if (t == IsoType.TIME)
            {
                return(d.ToString("HHmmss"));
            }

            throw new ArgumentException("IsoType must be DATE10, DATE12, DATE4, DATE6, DATE_EXP or TIME");
        }
Example #13
0
        public static byte[] ReadFile(IsoType isoType, Stream iso, int fileSector, int offset, int length)
        {
            int dataSize   = dataSizes[(int)isoType];
            int dataStart  = dataStarts[(int)isoType];
            int sectorSize = sectorSizes[(int)isoType];

            int desiredStartSector = fileSector + offset / dataSize;
            int startOffset        = offset % dataSize;

            int bytesLeftInFirstSector = dataSize - startOffset;

            iso.Seek(desiredStartSector * sectorSize + dataStart + startOffset, SeekOrigin.Begin);

            byte[] result = new byte[length];

            int bytesRead = iso.Read(result, 0, Math.Min(bytesLeftInFirstSector, length));

            desiredStartSector++;

            while (bytesRead < length)
            {
                iso.Seek(desiredStartSector * sectorSize + dataStart, SeekOrigin.Begin);
                bytesRead += iso.Read(result, bytesRead, Math.Min(length - bytesRead, dataSize));
                desiredStartSector++;
            }

            return(result);
        }
Example #14
0
        /// <summary>
        /// Creates a new instance to store a value of a fixed-length type.
        /// Fixed-length types are DATE4, DATE_EXP, DATE10, TIME, AMOUNT.
        /// </summary>
        /// <param name="t">The ISO8583 type of the value that is going to be stored.</param>
        /// <param name="value">The value to store.s</param>
        /// <param name="originalValue">The original value of field</param>
        /// <param name="req">Indicates the requiremts (M,C, CE, ME, O )</param>
        public IsoValue(IsoType t, Parsing.ConfigParser.Base configBase, Object value, String originalValue, String req)
        {
            if (value == null)
            {
                throw new ArgumentException("Value cannot be null");
            }

            if (IsoTypeHelper.NeedsLength(t))
            {
                throw new ArgumentException("Use IsoValue constructor for Fixed-value types");
            }

            type = t;
            fval = value;
            b    = configBase;
            this.originalValue = originalValue;
            requirements       = req;
            if (t == IsoType.LLVAR || type == IsoType.LLLVAR)
            {
                length = value.ToString().Length;
            }
            else
            {
                length = IsoTypeHelper.GetLength(t);
            }
        }
Example #15
0
 /// <summary>
 ///     Sets the specified value in the specified field, creating an IsoValue internally.
 /// </summary>
 /// <param name="index">The field number (2 to 128)</param>
 /// <param name="value">The value to be stored.</param>
 /// <param name="encoder">An optional CustomField to encode/decode the value.</param>
 /// <param name="t"></param>
 /// <param name="length"></param>
 /// <returns></returns>
 public IsoMessage SetValue(int index,
                            object value,
                            ICustomField encoder,
                            IsoType t,
                            int length)
 {
     if (index < 2 || index > 128)
     {
         throw new IndexOutOfRangeException("Field index must be between 2 and 128");
     }
     if (value == null)
     {
         _fields[index] = null;
     }
     else
     {
         IsoValue v;
         v = t.NeedsLength()
             ? new IsoValue(t,
                            value,
                            length,
                            encoder)
             : new IsoValue(t,
                            value,
                            encoder);
         v.Encoding     = Encoding;
         _fields[index] = v;
     }
     return(this);
 }
Example #16
0
 public void Dispose()
 {
     this.CloseFile();
     this.defaultXeX.Dispose();
     this.isoType = IsoType.GDF;
     this.isoInfo = new XkeyBrew.Utils.IsoGameReader.IsoInfo();
 }
Example #17
0
 public void Dispose()
 {
     CloseFile();
     this.defaultXeX.Dispose();
     this.isoType = IsoType.GDF;
     this.isoInfo = new IsoInfo();
 }
Example #18
0
        public static void FixupECC(IsoType isoType, Stream iso)
        {
            int type       = (int)isoType;
            int sectorSize = sectorSizes[type];

            byte[] sector = new byte[sectorSize];

            if (iso.Length % sectorSize != 0)
            {
                throw new ArgumentException("ISO does not have correct length for its type", "isoType");
            }
            if (isoType == IsoType.Mode1)
            {
                throw new ArgumentException("Mode1 does not support ECC/EDC", "isoType");
            }

            Int64 numberOfSectors = iso.Length / sectorSize;

            iso.Seek(0, SeekOrigin.Begin);
            for (Int64 i = 0; i < numberOfSectors; i++)
            {
                iso.Read(sector, 0, sectorSize);

                if (isoType != IsoType.Mode1 && (sector[0x12] & 8) == 0)
                {
                    sector[0x12] = 8;
                    sector[0x16] = 8;
                }

                GenerateEccEdc(sector, isoType);
                iso.Seek(-sectorSize, SeekOrigin.Current);
                iso.Write(sector, 0, sectorSize);
            }
        }
Example #19
0
        /// <summary>
        /// Formats a decimal value as an ISO8583 type.
        /// </summary>
        /// <param name="value">The decimal value to format.</param>
        /// <param name="t">The ISO8583 type to format the value as.</param>
        /// <param name="length">The length for the formatting, useful if the type is NUMERIC or ALPHA.</param>
        /// <returns>The formatted string representation of the value.</returns>
        public static String Format(Decimal value, IsoType t, Int32 length)
        {
            if (t == IsoType.AMOUNT)
            {
                Char[] x      = value.ToString("0000000000.00").ToCharArray();
                Char[] digits = new Char[12];

                Array.Copy(x, digits, 10);
                Array.Copy(x, 11, digits, 10, 2);

                return(new String(digits));
            }

            if (t == IsoType.NUMERIC || t == IsoType.ALPHA)
            {
                return(Format(value.ToString(), t, length));
            }

            if (t == IsoType.LLVAR || t == IsoType.LLLVAR)
            {
                return(value.ToString());
            }

            throw new ArgumentException("IsoType must be AMOUNT, NUMERIC, ALPHA, LLLVAR or LLVAR");
        }
Example #20
0
        /// <summary>
        /// Returns the length of a type, for types that always have the same
        /// length, of 0 in case of types that can have a variable length.
        /// </summary>
        /// <param name="t">The type in question.</param>
        /// <returns>The length of the type if it's a fixed-length type,
        /// or 0 if it's a variable-length type.</returns>
        public static Int32 GetLength(IsoType t)
        {
            if (t == IsoType.DATE10)
            {
                return(10);
            }
            if (t == IsoType.TIME)
            {
                return(6);
            }
            if (t == IsoType.AMOUNT || t == IsoType.DATE12)
            {
                return(12);
            }
            if (t == IsoType.DATE4 || t == IsoType.DATE_EXP)
            {
                return(4);
            }
            if (t == IsoType.DATE6 || t == IsoType.DATE_EXP)
            {
                return(6);
            }

            return(0);
        }
Example #21
0
 public void Dispose()
 {
     this.path      = string.Empty;
     this.isoType   = IsoType.GDF;
     this.xexHeader = null;
     this.xexHeader.Dispose();
     this.defaultXexFile = null;
 }
Example #22
0
 /// <summary>
 /// Disposes object
 /// </summary>
 public void Dispose()
 {
     path      = String.Empty;
     isoType   = IsoType.GDF;
     xexHeader = null;
     xexHeader.Dispose();
     defaultXexFile = null;
 }
Example #23
0
 /// <summary>
 /// Formats a string to the given length, padding it if necessary.
 /// </summary>
 /// <param name="value">The string to format.</param>
 /// <param name="t">The ISO8583 type to format the string as.</param>
 /// <param name="length">The length (in case of ALPHA or NUMERIC).</param>
 /// <returns>The formatted string.</returns>
 public static string Format(string value, IsoType t, int length)
 {
     if (t == IsoType.ALPHA)
     {
         char[] c = new char[length];
         if (value == null)
         {
             value = "";
         }
         else if (value.Length == length)
         {
             return(value);
         }
         else if (value.Length > length)
         {
             return(value.Substring(0, length));
         }
         Array.Copy(value.ToCharArray(), c, value.Length);
         for (int i = value.Length; i < length; i++)
         {
             c[i] = ' ';
         }
         return(new string(c));
     }
     else if (t == IsoType.LLVAR || t == IsoType.LLLVAR)
     {
         //TAM for packed values if ODD the padd with F
         if (value.Length % 2 == 0)
         {
             return(value);
         }
         else
         {
             return(value + "F");
         }
     }
     else if (t == IsoType.NUMERIC)
     {
         if (value.Length == length)
         {
             return(value);
         }
         char[] c = new char[length];
         char[] x = value.ToCharArray();
         if (x.Length > length)
         {
             throw new ArgumentOutOfRangeException("Numeric value is larger than intended length");
         }
         int lim = c.Length - x.Length;
         for (int i = 0; i < lim; i++)
         {
             c[i] = '0';
         }
         Array.Copy(x, 0, c, lim, x.Length);
         return(new string(c));
     }
     throw new ArgumentException("IsoType must be ALPHA, LLVAR, LLLVAR or NUMERIC");
 }
Example #24
0
 public void Close()
 {
     this.volDesc = new GDFVolumeDescriptor();
     this.Exceptions.Clear();
     this.type = IsoType.Gdf;
     this.rootDir.Clear();
     this.fr.Close();
     this.file.Close();
 }
Example #25
0
 public void Close()
 {
     this.volDesc = new GDFVolumeDescriptor();
     this.Exceptions.Clear();
     this.type = IsoType.Gdf;
     this.rootDir.Clear();
     this.fr.Close();
     this.file.Close();
 }
Example #26
0
 /// <summary>
 /// Creates a new instance that knows how to parse a value of the given
 /// type and the given length (the length is necessary for ALPHA and NUMERIC
 /// values only).
 /// </summary>
 /// <param name="t">The ISO8583 type.</param>
 /// <param name="len">The length of the value to parse (for ALPHA and NUMERIC values).</param>
 /// <param name="req">Define mandatory xml item</param>
 public FieldParseInfo(IsoType t, Int32 len, Boolean req, TypeElement st, Dictionary <Int32, FieldParseInfo> sub, ConfigParser.Base b)
 {
     type     = t;
     length   = len;
     required = req;
     subDataElements_Fields = sub;
     typeElement            = st;
     this.b = b;
 }
Example #27
0
 public void Close()
 {
     volDesc = new GDFVolumeDescriptor();
     Exceptions.Clear();
     type = IsoType.Gdf;
     rootDir.Clear();
     fr.Close();
     file.Close();
 }
Example #28
0
 private void ReadIsoData()
 {
     try
     {
         this.isoInfo            = new XkeyBrew.Utils.IsoGameReader.IsoInfo();
         this.isoInfo.SectorSize = 0x800;
         this.reader.BaseStream.Seek((long)(0x20 * (long)this.isoInfo.SectorSize), SeekOrigin.Begin);
         if (Encoding.ASCII.GetString(this.reader.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
         {
             this.isoType            = IsoType.XSF;
             this.isoInfo.RootOffset = (uint)this.isoType;
         }
         else
         {
             this.file.Seek((long)((0x20 * (long)this.isoInfo.SectorSize) + (long)IsoType.GDF), SeekOrigin.Begin);
             if (Encoding.ASCII.GetString(this.reader.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
             {
                 this.isoType            = IsoType.GDF;
                 this.isoInfo.RootOffset = (uint)this.isoType;
             }
             else
             {
                 this.file.Seek((long)((0x20 * (long)this.isoInfo.SectorSize) + (long)IsoType.XGD3), SeekOrigin.Begin);
                 if (Encoding.ASCII.GetString(this.reader.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
                 {
                     this.isoType            = IsoType.XGD3;
                     this.isoInfo.RootOffset = (uint)this.isoType;
                 }
                 else
                 {
                     this.file.Seek((long)((0x20 * (long)this.isoInfo.SectorSize) + (long)IsoType.XBOX1), SeekOrigin.Begin);
                     if (Encoding.ASCII.GetString(this.reader.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
                     {
                         this.isoType            = IsoType.XBOX1;
                         this.isoInfo.RootOffset = (uint)this.isoType;
                     }
                     else
                     {
                         throw new Exception("Invalid Iso Type");
                     }
                 }
             }
         }
         this.reader.BaseStream.Seek((long)((0x20 * (long)this.isoInfo.SectorSize) + (long)this.isoInfo.RootOffset), SeekOrigin.Begin);
         this.isoInfo.Identifier        = this.reader.ReadBytes(20);
         this.isoInfo.RootDirSector     = this.reader.ReadUInt32();
         this.isoInfo.RootDirSize       = this.reader.ReadUInt32();
         this.isoInfo.ImageCreationTime = this.reader.ReadBytes(8);
         this.isoInfo.VolumeSize        = (ulong)(this.reader.BaseStream.Length - this.isoInfo.RootOffset);
         this.isoInfo.VolumeSectors     = (uint)(this.isoInfo.VolumeSize / ((ulong)this.isoInfo.SectorSize));
     }
     catch (Exception exception)
     {
         throw new Exception("Cannot read ISO info", exception);
     }
 }
Example #29
0
 /// <summary>
 /// Creates a new instance that knows how to parse a value of the given
 /// type and the given length (the length is necessary for ALPHA and NUMERIC
 /// values only).
 /// </summary>
 /// <param name="t">The ISO8583 type.</param>
 /// <param name="len">The length of the value to parse (for ALPHA and NUMERIC values).</param>
 /// <param name="req">Define mandatory xml item</param>
 public FieldParseInfo(IsoType t, Int32 len, Boolean req, TypeElement st, Dictionary <Int32, FieldParseInfo> sub, Int32 subElementIDLength, Int32 lengthLengthSubElement)
 {
     type                        = t;
     length                      = len;
     required                    = req;
     typeElement                 = st;
     this.subElementIDLength     = subElementIDLength;
     this.lengthLengthSubElement = lengthLengthSubElement;
     subDataElements_Fields      = sub;
 }
Example #30
0
 /// <summary>
 ///     Sets the specified value in the specified field, creating an IsoValue internally.
 /// </summary>
 /// <param name="index">The field number (2 to 128)</param>
 /// <param name="value">The value to be stored.</param>
 /// <param name="t">he ISO type.</param>
 /// <param name="length">The length of the field, used for ALPHA and NUMERIC values only, ignored with any other type.</param>
 /// <returns></returns>
 public IsoMessage SetValue(int index,
                            object value,
                            IsoType t,
                            int length)
 {
     return(SetValue(index,
                     value,
                     null,
                     t,
                     length));
 }
Example #31
0
        /// <summary>
        /// Patches the file at a given sector in an ISO.
        /// </summary>
        /// <param name="isoType">The type of ISO</param>
        /// <param name="iso">Stream that contains the ISO</param>
        /// <param name="patchEccEdc">Whether or not ECC/EDC blocks should be updated</param>
        /// <param name="sectorNumber">The sector number where the file begins</param>
        /// <param name="offset">Where in the file to start writing</param>
        /// <param name="input">Bytes to write</param>
        public static void PatchFileAtSector(IsoType isoType, Stream iso, bool patchEccEdc, int sectorNumber, long offset, IList <byte> input, bool patchIso)
        {
            int dataSize   = dataSizes[(int)isoType];
            int dataStart  = dataStarts[(int)isoType];
            int sectorSize = sectorSizes[(int)isoType];

            long sectorsToAdvance = offset / dataSize;
            long newOffset        = offset % dataSize;

            long realOffset = (sectorNumber + sectorsToAdvance) * sectorSize + dataStart + newOffset;

            PatchFile(isoType, iso, patchEccEdc, realOffset, input, patchIso);
        }
Example #32
0
 public CompositeField AddValue(object val,
                                ICustomField encoder,
                                IsoType t,
                                int length)
 {
     return(AddValue(t.NeedsLength()
         ? new IsoValue(t,
                        val,
                        length,
                        encoder)
         : new IsoValue(t,
                        val,
                        encoder)));
 }
Example #33
0
 /// <summary>
 /// Formats a number as an ISO8583 type.
 /// </summary>
 /// <param name="value">The number to format.</param>
 /// <param name="t">The ISO8583 type to format the value as.</param>
 /// <param name="length">The length to format to (in case of ALPHA or NUMERIC)</param>
 /// <returns>The formatted string representation of the value.</returns>
 public static string Format(long value, IsoType t, int length)
 {
     if (t == IsoType.NUMERIC || t == IsoType.ALPHA)
     {
         return(Format(value.ToString(), t, length));
     }
     else if (t == IsoType.LLLVAR || t == IsoType.LLVAR)
     {
         return(value.ToString());
     }
     else if (t == IsoType.AMOUNT)
     {
         return(value.ToString("0000000000") + "00");
     }
     throw new ArgumentException("IsoType must be AMOUNT, NUMERIC, ALPHA, LLLVAR or LLVAR");
 }
        /// <summary>
        /// Gets the input argument.
        /// </summary>
        /// <param name="videoPath">The video path.</param>
        /// <param name="isRemote">if set to <c>true</c> [is remote].</param>
        /// <param name="videoType">Type of the video.</param>
        /// <param name="isoType">Type of the iso.</param>
        /// <param name="isoMount">The iso mount.</param>
        /// <param name="playableStreamFileNames">The playable stream file names.</param>
        /// <param name="type">The type.</param>
        /// <returns>System.String[][].</returns>
        public static string[] GetInputArgument(string videoPath, bool isRemote, VideoType videoType, IsoType? isoType, IIsoMount isoMount, IEnumerable<string> playableStreamFileNames, out InputType type)
        {
            var inputPath = isoMount == null ? new[] { videoPath } : new[] { isoMount.MountedPath };

            type = InputType.File;

            switch (videoType)
            {
                case VideoType.BluRay:
                    type = InputType.Bluray;
                    inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray();
                    break;
                case VideoType.Dvd:
                    type = InputType.Dvd;
                    inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray();
                    break;
                case VideoType.Iso:
                    if (isoType.HasValue)
                    {
                        switch (isoType.Value)
                        {
                            case IsoType.BluRay:
                                type = InputType.Bluray;
                                inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray();
                                break;
                            case IsoType.Dvd:
                                type = InputType.Dvd;
                                inputPath = GetPlayableStreamFiles(inputPath[0], playableStreamFileNames).ToArray();
                                break;
                        }
                    }
                    break;
                case VideoType.VideoFile:
                    {
                        if (isRemote)
                        {
                            type = InputType.Url;
                        }
                        break;
                    }
            }

            return inputPath;
        }
Example #35
0
        /// <summary>
        /// Main constructor of IsoGameInfo
        /// </summary>
        /// <param name="path">path to iso file</param>
        public IsoGameInfo(string path)
        {
            try
            {
                this.path = path;
                Iso iso = new Iso(path);

                this.xexHeader = ObjectCopier.Clone<XeXHeader>(iso.DefaultXeX.XeXHeader);
                this.defaultXexFile = new byte[iso.DefaultXeX.File.Length];
                iso.DefaultXeX.File.CopyTo(this.defaultXexFile, 0);
                this.isoType = iso.IsoType;
                //this.gameInfo = new GameInfo(this.xexHeader.TitleId);

                iso.Dispose();
                iso = null;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #36
0
 private void readVolume()
 {
     this.volDesc = new GDFVolumeDescriptor();
     this.volDesc.SectorSize = 0x800;
     this.fr.Seek((long) (0x20 * this.volDesc.SectorSize), SeekOrigin.Begin);
     if (Encoding.ASCII.GetString(this.fr.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
     {
         this.type = IsoType.Xsf;
         this.volDesc.RootOffset = (uint) this.type;
     }
     else
     {
         this.file.Seek((long) ((0x20 * this.volDesc.SectorSize) + 0xfd90000), SeekOrigin.Begin);
         if (Encoding.ASCII.GetString(this.fr.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
         {
             this.type = IsoType.Gdf;
             this.volDesc.RootOffset = (uint) this.type;
         }
         else
         {
             this.type = IsoType.XGD3;
             this.volDesc.RootOffset = (uint) this.type;
         }
     }
     this.file.Seek((long) ((0x20 * this.volDesc.SectorSize) + this.volDesc.RootOffset), SeekOrigin.Begin);
     this.volDesc.Identifier = this.fr.ReadBytes(20);
     this.volDesc.RootDirSector = this.fr.ReadUInt32();
     this.volDesc.RootDirSize = this.fr.ReadUInt32();
     this.volDesc.ImageCreationTime = this.fr.ReadBytes(8);
     this.volDesc.VolumeSize = (ulong) (this.fr.BaseStream.Length - this.volDesc.RootOffset);
     this.volDesc.VolumeSectors = (uint) (this.volDesc.VolumeSize / ((ulong) this.volDesc.SectorSize));
 }
Example #37
0
 public void Dispose()
 {
     CloseFile();
     this.defaultXeX.Dispose();
     this.isoType = IsoType.GDF;
     this.isoInfo = new IsoInfo();
 }
Example #38
0
 /// <summary>
 /// Reads file system info
 /// </summary>
 private void ReadIsoData()
 {
     try
     {
         this.isoInfo = new IsoInfo();
         this.isoInfo.SectorSize = 0x800;
         this.reader.BaseStream.Seek((long)(0x20 * this.isoInfo.SectorSize), SeekOrigin.Begin);
         if (Encoding.ASCII.GetString(this.reader.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
         {
             this.isoType = IsoType.XSF;
             this.isoInfo.RootOffset = (uint)this.isoType;
         }
         else
         {
             this.file.Seek((long)((0x20 * this.isoInfo.SectorSize) + 0xfd90000), SeekOrigin.Begin);
             if (Encoding.ASCII.GetString(this.reader.ReadBytes(20)) == "MICROSOFT*XBOX*MEDIA")
             {
                 this.isoType = IsoType.GDF;
                 this.isoInfo.RootOffset = (uint)this.isoType;
             }
             else
             {
                 this.isoType = IsoType.XGD3;
                 this.isoInfo.RootOffset = (uint)this.isoType;
             }
         }
         this.reader.BaseStream.Seek((long)((0x20 * this.isoInfo.SectorSize) + this.isoInfo.RootOffset), SeekOrigin.Begin);
         this.isoInfo.Identifier = this.reader.ReadBytes(20);
         this.isoInfo.RootDirSector = this.reader.ReadUInt32();
         this.isoInfo.RootDirSize = this.reader.ReadUInt32();
         this.isoInfo.ImageCreationTime = this.reader.ReadBytes(8);
         this.isoInfo.VolumeSize = (ulong)(this.reader.BaseStream.Length - this.isoInfo.RootOffset);
         this.isoInfo.VolumeSectors = (uint)(this.isoInfo.VolumeSize / ((ulong)this.isoInfo.SectorSize));
     }
     catch (Exception ex)
     {
         throw new Exception("Cannot read ISO info", ex);
     }
 }
Example #39
0
 public static void GenerateEccEdc( IList<byte> sector, IsoType isoType )
 {
     switch( isoType )
     {
         case IsoType.Mode2Form1:
             ComputeEdcBlock( sector.Sub( 0x10 ), 0x808, sector.Sub( 0x818 ) );
             GenerateEcc( sector, true );
             break;
         case IsoType.Mode2Form2:
             ComputeEdcBlock( sector.Sub( 0x10 ), 0x91C, sector.Sub( 0x92C ) );
             break;
         case IsoType.Mode1:
         default:
             throw new ArgumentException( "isotype" );
     }
 }
Example #40
0
 /// <summary>
 /// Patches the bytes at a given offset.
 /// </summary>
 /// <param name="isoType">The type of ISO</param>
 /// <param name="iso">Stream that contains the ISO</param>
 /// <param name="patchEccEdc">Whether or not ECC/EDC blocks should be updated</param>
 /// <param name="offset">Where in the ISO to start writing</param>
 /// <param name="input">Bytes to write</param>
 public static void PatchFile( IsoType isoType, Stream iso, bool patchEccEdc, long offset, IList<byte> input, bool patchIso )
 {
     using ( MemoryStream inputStream = new MemoryStream( input.ToArray() ) )
     {
         PatchFile( isoType, iso, patchEccEdc, offset, inputStream, patchIso );
     }
 }
Example #41
0
        /// <summary>
        /// Patches the bytes at a given offset.
        /// </summary>
        /// <param name="isoType">The type of ISO</param>
        /// <param name="iso">Stream that contains the ISO</param>
        /// <param name="patchEccEdc">Whether or not ECC/EDC blocks should be updated</param>
        /// <param name="offset">Where in the ISO to start writing</param>
        /// <param name="input">Stream that contains the bytes to write</param>
        public static void PatchFile( IsoType isoType, Stream iso, bool patchEccEdc, long offset, Stream input, bool patchIso )
        {
            int type = (int)isoType;
            int sectorSize = sectorSizes[type];
            byte[] sector = new byte[sectorSize];

            long sectorStart = offset % sectorSize;
            if( sectorStart < dataStarts[type] ||
                sectorStart >= (dataStarts[type] + dataSizes[type]) )
            {
                throw new ArgumentException( "start offset is incorrect", "offset" );
            }
            if( patchEccEdc && isoType == IsoType.Mode1 )
            {
                throw new ArgumentException( "Mode1 does not support ECC/EDC", "patchEccEdc" );
            }

            long sectorLength = dataSizes[type] + dataStarts[type] - sectorStart;
            int totalPatchedBytes = 0;
            int sizeRead = 0;
            long temp = offset - (offset % sectorSize);
            iso.Seek( temp, SeekOrigin.Begin );

            input.Seek( 0, SeekOrigin.Begin );
            while( input.Position < input.Length )
            {
                iso.Read( sector, 0, sectorSize );
                byte[] originalSector = sector.ToArray();

                sizeRead = input.Read( sector, (int)sectorStart, (int)sectorLength );

                if( isoType != IsoType.Mode1 && (sector[0x12] & 8) == 0 )
                {
                    sector[0x12] = 8;
                    sector[0x16] = 8;
                }

                if( patchEccEdc )
                {
                    GenerateEccEdc( sector, isoType );
                }

                iso.Seek( -sectorSize, SeekOrigin.Current );

                if( patchIso )
                {
                    iso.Write( sector, 0, sectorSize );
                }
                else
                {
                    iso.Seek( sectorSize, SeekOrigin.Current );
                }

                totalPatchedBytes += sizeRead;
                sectorStart = dataStarts[type];
                sectorLength = dataSizes[type];
            }
        }
Example #42
0
 /// <summary>
 /// Patches the file at a given sector in an ISO.
 /// </summary>
 /// <param name="isoType">The type of ISO</param>
 /// <param name="isoFile">Path to the ISO image</param>
 /// <param name="patchEccEdc">Whether or not ECC/EDC blocks should be updated</param>
 /// <param name="sectorNumber">The sector number where the file begins</param>
 /// <param name="input">Bytes to write</param>
 public static void PatchFileAtSector( IsoType isoType, string isoFile, bool patchEccEdc, int sectorNumber, IList<byte> input, bool patchIso )
 {
     PatchFileAtSector( isoType, isoFile, patchEccEdc, sectorNumber, 0, input, patchIso );
 }
Example #43
0
 /// <summary>
 /// Patches the file at a given sector in an ISO.
 /// </summary>
 /// <param name="isoType">The type of ISO</param>
 /// <param name="isoFile">Path to the ISO image</param>
 /// <param name="patchEccEdc">Whether or not ECC/EDC blocks should be updated</param>
 /// <param name="sectorNumber">The sector number where the file begins</param>
 /// <param name="offset">Where in the file to start writing</param>
 /// <param name="input">Bytes to write</param>
 public static void PatchFileAtSector( IsoType isoType, string isoFile, bool patchEccEdc, int sectorNumber, long offset, IList<byte> input, bool patchIso )
 {
     using ( FileStream stream = new FileStream( isoFile, FileMode.Open ) )
     {
         PatchFileAtSector( isoType, stream, patchEccEdc, sectorNumber, offset, input, patchIso );
     }
 }
Example #44
0
        /// <summary>
        /// Patches the file at a given sector in an ISO.
        /// </summary>
        /// <param name="isoType">The type of ISO</param>
        /// <param name="iso">Stream that contains the ISO</param>
        /// <param name="patchEccEdc">Whether or not ECC/EDC blocks should be updated</param>
        /// <param name="sectorNumber">The sector number where the file begins</param>
        /// <param name="offset">Where in the file to start writing</param>
        /// <param name="input">Bytes to write</param>
        public static void PatchFileAtSector( IsoType isoType, Stream iso, bool patchEccEdc, int sectorNumber, long offset, IList<byte> input, bool patchIso )
        {
            int dataSize = dataSizes[(int)isoType];
            int dataStart = dataStarts[(int)isoType];
            int sectorSize = sectorSizes[(int)isoType];

            long sectorsToAdvance = offset / dataSize;
            long newOffset = offset % dataSize;

            long realOffset = (sectorNumber + sectorsToAdvance) * sectorSize + dataStart + newOffset;

            PatchFile( isoType, iso, patchEccEdc, realOffset, input, patchIso );
        }
Example #45
0
        public static byte[] ReadFile( IsoType isoType, Stream iso, int fileSector, int offset, int length )
        {
            int dataSize = dataSizes[(int)isoType];
            int dataStart = dataStarts[(int)isoType];
            int sectorSize = sectorSizes[(int)isoType];

            int desiredStartSector = fileSector + offset / dataSize;
            int startOffset = offset % dataSize;

            int bytesLeftInFirstSector = dataSize - startOffset;

            iso.Seek( desiredStartSector * sectorSize + dataStart + startOffset, SeekOrigin.Begin );

            byte[] result = new byte[length];

            int bytesRead = iso.Read( result, 0, Math.Min( bytesLeftInFirstSector, length ) );
            desiredStartSector++;

            while ( bytesRead < length )
            {
               iso.Seek( desiredStartSector * sectorSize + dataStart, SeekOrigin.Begin );
               bytesRead += iso.Read( result, bytesRead, Math.Min( length - bytesRead, dataSize) );
               desiredStartSector++;
            }

            return result;
        }
Example #46
0
 /// <summary>
 /// Disposes object
 /// </summary>
 public void Dispose()
 {
     path = String.Empty;
     isoType = IsoType.GDF;
     xexHeader = null;
     xexHeader.Dispose();
     defaultXexFile = null;
 }
        /// <summary>
        /// Gets the probe size argument.
        /// </summary>
        /// <param name="mediaPath">The media path.</param>
        /// <param name="isVideo">if set to <c>true</c> [is video].</param>
        /// <param name="videoType">Type of the video.</param>
        /// <param name="isoType">Type of the iso.</param>
        /// <returns>System.String.</returns>
        protected string GetProbeSizeArgument(string mediaPath, bool isVideo, VideoType? videoType, IsoType? isoType)
        {
            var type = !isVideo ? MediaEncoderHelpers.GetInputType(mediaPath, null, null) :
                MediaEncoderHelpers.GetInputType(mediaPath, videoType, isoType);

            return MediaEncoder.GetProbeSizeArgument(type);
        }