/// <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; }
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; } }
/// <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; } }
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; } }
/// <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; } }
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; } }
/// <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; } }
/// <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)); }
/// <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; }
/// <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)); }
/// <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; }
public BlamStructureElementAttribute(StructureValueType valueType, string xmlValueName) { }
/// <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); }
/// <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; }