コード例 #1
0
ファイル: StructureLayout.cs プロジェクト: ChadSki/Assembly
        /// <summary>
        ///     Adds a basic field to the structure layout.
        /// </summary>
        /// <param name="name">The name of the field.</param>
        /// <param name="type">The type of the field's value.</param>
        /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param>
        public void AddBasicField(string name, StructureValueType type, int offset)
        {
            var field = new BasicField(name, type, offset);

            _fields.Add(field);
            _fieldsByName[name] = field;
        }
コード例 #2
0
ファイル: StructureWriter.cs プロジェクト: ChadSki/Assembly
        public void VisitBasicField(string name, StructureValueType type, int offset)
        {
            // Skip over the field if it isn't in the value collection
            if (type == StructureValueType.Asciiz)
            {
                if (!_collection.HasString(name))
                {
                    return;
                }
            }
            else if (!_collection.HasInteger(name))
            {
                return;
            }

            SeekWriter(offset);
            switch (type)
            {
            case StructureValueType.Byte:
                _writer.WriteByte((byte)_collection.GetInteger(name));
                _offset++;
                break;

            case StructureValueType.SByte:
                _writer.WriteSByte((sbyte)_collection.GetInteger(name));
                _offset++;
                break;

            case StructureValueType.UInt16:
                _writer.WriteUInt16((ushort)_collection.GetInteger(name));
                _offset += 2;
                break;

            case StructureValueType.Int16:
                _writer.WriteInt16((short)_collection.GetInteger(name));
                _offset += 2;
                break;

            case StructureValueType.UInt32:
                _writer.WriteUInt32(_collection.GetInteger(name));
                _offset += 4;
                break;

            case StructureValueType.Int32:
                _writer.WriteInt32((int)_collection.GetInteger(name));
                _offset += 4;
                break;

            case StructureValueType.Asciiz:
                _writer.WriteAscii(_collection.GetString(name));
                _offset = _writer.Position;
                break;

            case StructureValueType.Float32:
                _writer.WriteFloat(_collection.GetFloat(name));
                _offset += 4;
                break;
            }
        }
コード例 #3
0
ファイル: StructureReader.cs プロジェクト: Akarias/Assembly
        /// <summary>
        ///     Reads a basic value from the stream and adds it to the value
        ///     collection which is currently being built.
        /// </summary>
        /// <param name="name">The name to store the value under.</param>
        /// <param name="type">The type of the value to read.</param>
        /// <param name="offset">The value's offset (in bytes) from the beginning of the structure.</param>
        /// <seealso cref="IStructureLayoutVisitor.VisitBasicField" />
        public void VisitBasicField(string name, StructureValueType type, int offset)
        {
            SeekReader(offset);
            switch (type)
            {
            case StructureValueType.Byte:
                _collection.SetInteger(name, _reader.ReadByte());
                _offset++;
                break;

            case StructureValueType.SByte:
                _collection.SetInteger(name, (uint)_reader.ReadSByte());
                _offset++;
                break;

            case StructureValueType.UInt16:
                _collection.SetInteger(name, _reader.ReadUInt16());
                _offset += 2;
                break;

            case StructureValueType.Int16:
                _collection.SetInteger(name, (uint)_reader.ReadInt16());
                _offset += 2;
                break;

            case StructureValueType.UInt32:
                _collection.SetInteger(name, _reader.ReadUInt32());
                _offset += 4;
                break;

            case StructureValueType.Int32:
                _collection.SetInteger(name, (uint)_reader.ReadInt32());
                _offset += 4;
                break;

            case StructureValueType.UInt64:
                _collection.SetInteger(name, _reader.ReadUInt64());
                _offset += 8;
                break;

            case StructureValueType.Int64:
                _collection.SetInteger(name, (ulong)_reader.ReadInt64());
                _offset += 8;
                break;

            case StructureValueType.Asciiz:
                _collection.SetString(name, _reader.ReadAscii());
                _offset = _reader.Position;
                break;

            case StructureValueType.Float32:
                _collection.SetFloat(name, _reader.ReadFloat());
                _offset += 4;
                break;
            }
        }
コード例 #4
0
ファイル: StructureWriter.cs プロジェクト: XboxChaos/Liberty
        public void VisitBasicField(string name, StructureValueType type, int offset)
        {
            // Seeking is SLOW - only seek if we have to
            if (_offset != _baseOffset + offset)
            {
                _offset = _baseOffset + offset;
                _writer.SeekTo(_offset);
            }

            switch (type)
            {
            case StructureValueType.Byte:
                _writer.WriteByte((byte)_collection.GetNumber(name));
                _offset++;
                break;

            case StructureValueType.SByte:
                _writer.WriteSByte((sbyte)_collection.GetNumber(name));
                _offset++;
                break;

            case StructureValueType.UInt16:
                _writer.WriteUInt16((ushort)_collection.GetNumber(name));
                _offset += 2;
                break;

            case StructureValueType.Int16:
                _writer.WriteInt16((short)_collection.GetNumber(name));
                _offset += 2;
                break;

            case StructureValueType.UInt32:
                _writer.WriteUInt32(_collection.GetNumber(name));
                _offset += 4;
                break;

            case StructureValueType.Int32:
                _writer.WriteInt32((int)_collection.GetNumber(name));
                _offset += 4;
                break;

            case StructureValueType.Asciiz:
                _writer.WriteAscii(_collection.GetString(name));
                _offset = _writer.Position;
                break;

            case StructureValueType.Utf16z:
                _writer.WriteUTF16(_collection.GetString(name));
                _offset = _writer.Position;
                break;
            }
        }
コード例 #5
0
ファイル: StructureReader.cs プロジェクト: XboxChaos/Liberty
        /// <summary>
        /// Reads a basic value from the stream and adds it to the value
        /// collection which is currently being built.
        /// </summary>
        /// <param name="name">The name to store the value under.</param>
        /// <param name="type">The type of the value to read.</param>
        /// <param name="offset">The value's offset (in bytes) from the beginning of the structure.</param>
        /// <seealso cref="IStructureLayoutVisitor.VisitBasicField"/>
        public void VisitBasicField(string name, StructureValueType type, int offset)
        {
            // Seeking is SLOW - only seek if we have to
            if (_offset != _baseOffset + offset)
            {
                _offset = _baseOffset + offset;
                _reader.SeekTo(_offset);
            }

            switch (type)
            {
            case StructureValueType.Byte:
                _collection.SetNumber(name, _reader.ReadByte());
                _offset++;
                break;

            case StructureValueType.SByte:
                _collection.SetNumber(name, (uint)_reader.ReadSByte());
                _offset++;
                break;

            case StructureValueType.UInt16:
                _collection.SetNumber(name, _reader.ReadUInt16());
                _offset += 2;
                break;

            case StructureValueType.Int16:
                _collection.SetNumber(name, (uint)_reader.ReadInt16());
                _offset += 2;
                break;

            case StructureValueType.UInt32:
                _collection.SetNumber(name, _reader.ReadUInt32());
                _offset += 4;
                break;

            case StructureValueType.Int32:
                _collection.SetNumber(name, (uint)_reader.ReadInt32());
                _offset += 4;
                break;

            case StructureValueType.Asciiz:
                _collection.SetString(name, _reader.ReadAscii());
                _offset = _reader.Position;
                break;

            case StructureValueType.Utf16z:
                _collection.SetString(name, _reader.ReadUTF16());
                _offset = _reader.Position;
                break;
            }
        }
コード例 #6
0
ファイル: StructureWriter.cs プロジェクト: t3hm00kz/Assembly
        public void VisitBasicField(string name, StructureValueType type, int offset)
        {
            // Skip over the field if it isn't in the value collection
            if (type == StructureValueType.Asciiz)
            {
                if (!_collection.HasString(name))
                    return;
            }
            else if (!_collection.HasInteger(name))
            {
                return;
            }

            SeekWriter(offset);
            switch (type)
            {
                case StructureValueType.Byte:
                    _writer.WriteByte((byte) _collection.GetInteger(name));
                    _offset++;
                    break;
                case StructureValueType.SByte:
                    _writer.WriteSByte((sbyte) _collection.GetInteger(name));
                    _offset++;
                    break;
                case StructureValueType.UInt16:
                    _writer.WriteUInt16((ushort) _collection.GetInteger(name));
                    _offset += 2;
                    break;
                case StructureValueType.Int16:
                    _writer.WriteInt16((short) _collection.GetInteger(name));
                    _offset += 2;
                    break;
                case StructureValueType.UInt32:
                    _writer.WriteUInt32(_collection.GetInteger(name));
                    _offset += 4;
                    break;
                case StructureValueType.Int32:
                    _writer.WriteInt32((int) _collection.GetInteger(name));
                    _offset += 4;
                    break;
                case StructureValueType.Asciiz:
                    _writer.WriteAscii(_collection.GetString(name));
                    _offset = _writer.Position;
                    break;
                case StructureValueType.Float32:
                    _writer.WriteFloat(_collection.GetFloat(name));
                    _offset += 4;
                    break;
            }
        }
コード例 #7
0
ファイル: StructureReader.cs プロジェクト: t3hm00kz/Assembly
 /// <summary>
 ///     Reads a basic value from the stream and adds it to the value
 ///     collection which is currently being built.
 /// </summary>
 /// <param name="name">The name to store the value under.</param>
 /// <param name="type">The type of the value to read.</param>
 /// <param name="offset">The value's offset (in bytes) from the beginning of the structure.</param>
 /// <seealso cref="IStructureLayoutVisitor.VisitBasicField" />
 public void VisitBasicField(string name, StructureValueType type, int offset)
 {
     SeekReader(offset);
     switch (type)
     {
         case StructureValueType.Byte:
             _collection.SetInteger(name, _reader.ReadByte());
             _offset++;
             break;
         case StructureValueType.SByte:
             _collection.SetInteger(name, (uint) _reader.ReadSByte());
             _offset++;
             break;
         case StructureValueType.UInt16:
             _collection.SetInteger(name, _reader.ReadUInt16());
             _offset += 2;
             break;
         case StructureValueType.Int16:
             _collection.SetInteger(name, (uint) _reader.ReadInt16());
             _offset += 2;
             break;
         case StructureValueType.UInt32:
             _collection.SetInteger(name, _reader.ReadUInt32());
             _offset += 4;
             break;
         case StructureValueType.Int32:
             _collection.SetInteger(name, (uint) _reader.ReadInt32());
             _offset += 4;
             break;
         case StructureValueType.Asciiz:
             _collection.SetString(name, _reader.ReadAscii());
             _offset = _reader.Position;
             break;
         case StructureValueType.Float32:
             _collection.SetFloat(name, _reader.ReadFloat());
             _offset += 4;
             break;
     }
 }
コード例 #8
0
 /// <summary>
 ///     Adds a basic field to the structure layout.
 /// </summary>
 /// <param name="name">The name of the field.</param>
 /// <param name="type">The type of the field's value.</param>
 /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param>
 public void AddBasicField(string name, StructureValueType type, int offset)
 {
     AddField(new BasicField(name, type, offset));
 }
コード例 #9
0
 /// <summary>
 ///     Constructs a new basic field.
 /// </summary>
 /// <param name="name">The name of the field.</param>
 /// <param name="type">The type of the field's value.</param>
 /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param>
 public BasicField(string name, StructureValueType type, int offset)
     : base(name, offset)
 {
     _type = type;
 }
コード例 #10
0
 /// <summary>
 /// Adds a basic field to the structure layout.
 /// </summary>
 /// <param name="name">The name of the field.</param>
 /// <param name="type">The type of the field's value.</param>
 /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param>
 public void AddBasicField(string name, StructureValueType type, int offset)
 {
     _fields.Add(new BasicField(name, type, offset));
 }
コード例 #11
0
 /// <summary>
 /// Constructs a new basic field.
 /// </summary>
 /// <param name="name">The name of the field.</param>
 /// <param name="type">The type of the field's value.</param>
 /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param>
 public BasicField(string name, StructureValueType type, int offset)
 {
     _name = name;
     _type = type;
     _offset = offset;
 }
コード例 #12
0
 public BlamStructureElementAttribute(StructureValueType valueType, string xmlValueName)
 {
 }
コード例 #13
0
        /// <summary>
        ///     Parses an XML element representing a basic structure field and adds
        ///     the field information to a structure layout.
        /// </summary>
        /// <param name="layout">The structure layout to add the field's information to.</param>
        /// <param name="element">The XML element to parse.</param>
        /// <param name="name">The name of the field to add.</param>
        /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param>
        private void HandleBasicElement(StructureLayout layout, XElement element, string name, int offset)
        {
            StructureValueType type = IdentifyValueType(element.Name.LocalName);

            layout.AddBasicField(name, type, offset);
        }
コード例 #14
0
ファイル: StructureLayout.cs プロジェクト: ChadSki/Assembly
 /// <summary>
 ///     Constructs a new basic field.
 /// </summary>
 /// <param name="name">The name of the field.</param>
 /// <param name="type">The type of the field's value.</param>
 /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param>
 public BasicField(string name, StructureValueType type, int offset)
 {
     Name   = name;
     _type  = type;
     Offset = offset;
 }
コード例 #15
0
ファイル: StructureLayout.cs プロジェクト: ChadSki/Assembly
 /// <summary>
 ///     Adds a basic field to the structure layout.
 /// </summary>
 /// <param name="name">The name of the field.</param>
 /// <param name="type">The type of the field's value.</param>
 /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param>
 public void AddBasicField(string name, StructureValueType type, int offset)
 {
     var field = new BasicField(name, type, offset);
     _fields.Add(field);
     _fieldsByName[name] = field;
 }
コード例 #16
0
ファイル: StructureLayout.cs プロジェクト: t3hm00kz/Assembly
 /// <summary>
 ///     Constructs a new basic field.
 /// </summary>
 /// <param name="name">The name of the field.</param>
 /// <param name="type">The type of the field's value.</param>
 /// <param name="offset">The offset (in bytes) of the field from the beginning of the structure.</param>
 public BasicField(string name, StructureValueType type, int offset)
     : base(name, offset)
 {
     _type = type;
 }