Ejemplo n.º 1
0
        private IEnumerable <FirmwareStringMetadata> ReadStringTable([CanBeNull] StringTableDefinition stringTableDefinition, [NotNull] BinaryReader reader, int startIndex = 0)
        {
            if (stringTableDefinition == null)
            {
                return(new List <FirmwareStringMetadata>());
            }
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            var charLength = GetCharLength(stringTableDefinition.TwoBytesPerChar);
            var result     = new List <FirmwareStringMetadata>();

            {
                long offsetFrom;
                long offsetTo;
                GetOffsets(stringTableDefinition, reader, out offsetFrom, out offsetTo);

                reader.BaseStream.Seek(offsetFrom, SeekOrigin.Begin);
                while (reader.BaseStream.Position <= offsetTo)
                {
                    var offset     = reader.BaseStream.Position;
                    var dataLength = 0;

                    while (true)
                    {
                        if (reader.BaseStream.Position <= offsetTo)
                        {
                            var char1 = ReadChar(reader, stringTableDefinition.TwoBytesPerChar);
                            dataLength += charLength;

                            short?char2;
                            if (reader.BaseStream.Position <= offsetTo)
                            {
                                char2 = ReadChar(reader, stringTableDefinition.TwoBytesPerChar);
                                reader.BaseStream.Position -= charLength;
                            }
                            else
                            {
                                break;
                            }

                            if (char1 == 0x00 && char2 != 0x00)
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    result.Add(new FirmwareStringMetadata(startIndex + result.Count + 1, offset, dataLength, stringTableDefinition.TwoBytesPerChar));
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        private IEnumerable <FirmwareStringMetadata> ReadStringTable([CanBeNull] StringTableDefinition stringTableDefinition, BlockType blockType, [NotNull] BinaryReader reader)
        {
            if (stringTableDefinition == null)
            {
                return(new List <FirmwareStringMetadata>());
            }
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            var result = new List <FirmwareStringMetadata>();

            {
                reader.BaseStream.Seek(stringTableDefinition.OffsetFrom, SeekOrigin.Begin);
                while (reader.BaseStream.Position <= stringTableDefinition.OffsetTo)
                {
                    var offset     = reader.BaseStream.Position;
                    var dataLength = 0;

                    while (true)
                    {
                        if (reader.BaseStream.Position <= stringTableDefinition.OffsetTo)
                        {
                            dataLength++;
                            var  byte1 = reader.ReadByte();
                            byte?byte2;
                            if (reader.BaseStream.Position <= stringTableDefinition.OffsetTo)
                            {
                                byte2 = reader.ReadByte();
                                reader.BaseStream.Position--;
                            }
                            else
                            {
                                break;
                            }

                            if (byte1 == 0x00 && byte2 != 0x00)
                            {
                                break;
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    result.Add(new FirmwareStringMetadata(result.Count + 1, offset, dataLength, blockType));
                }
            }
            return(result);
        }