Read record data from stream, decrypting as required

@param string $data   Data stream to read from
@param int    $pos    Position to start reading from
@param int    $length Record data length

@return string Record data
17728
private function _readRecordData($data, $pos, $len)
	{
		$data = substr($data, $pos, $len);
		
		// File not encrypted, or record before encryption start point
		if ($this->_encryption == self::MS_BIFF_CRYPTO_NONE || $pos < $this->_encryptionStartPos) {
			return $data;
		}
	
		$recordData = '';
		if ($this->_encryption == self::MS_BIFF_CRYPTO_RC4) {

			$oldBlock = floor($this->_rc4Pos / self::REKEY_BLOCK);
			$block = floor($pos / self::REKEY_BLOCK);
			$endBlock = floor(($pos + $len) / self::REKEY_BLOCK);

			// Spin an RC4 decryptor to the right spot. If we have a decryptor sitting
			// at a point earlier in the current block, re-use it as we can save some time.
			if ($block != $oldBlock || $pos < $this->_rc4Pos || !$this->_rc4Key) {
				$this->_rc4Key = $this->_makeKey($block, $this->_md5Ctxt);
				$step = $pos % self::REKEY_BLOCK;
			} else {
				$step = $pos - $this->_rc4Pos;
			}
			$this->_rc4Key->RC4(str_repeat("\0", $step));

			// Decrypt record data (re-keying at the end of every block)
			while ($block != $endBlock) {
				$step = self::REKEY_BLOCK - ($pos % self::REKEY_BLOCK);
				$recordData .= $this->_rc4Key->RC4(substr($data, 0, $step));
				$data = substr($data, $step);
				$pos += $step;
				$len -= $step;
				$block++;
				$this->_rc4Key = $this->_makeKey($block, $this->_md5Ctxt);
			}
			$recordData .= $this->_rc4Key->RC4(substr($data, 0, $len));

			// Keep track of the position of this decryptor.
			// We'll try and re-use it later if we can to speed things up
			$this->_rc4Pos = $pos + $len;
			
		} elseif ($this->_encryption == self::MS_BIFF_CRYPTO_XOR) {
			throw new PHPExcel_Reader_Exception('XOr encryption not supported');
		}
		return $recordData;
	}
363786
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getSportId();
                break;
            case 2:
                return $this->getName();
                break;
            case 3:
                return $this->getAlternativeName();
                break;
            case 4:
                return $this->getSlug();
                break;
            case 5:
                return $this->getDescription();
                break;
            case 6:
                return $this->getHistory();
                break;
            case 7:
                return $this->getIsTranslation();
                break;
            case 8:
                return $this->getIsRotation();
                break;
            case 9:
                return $this->getIsAcyclic();
                break;
            case 10:
                return $this->getIsCyclic();
                break;
            case 11:
                return $this->getLongitudinalFlags();
                break;
            case 12:
                return $this->getLatitudinalFlags();
                break;
            case 13:
                return $this->getTransversalFlags();
                break;
            case 14:
                return $this->getMovementDescription();
                break;
            case 15:
                return $this->getSequencePictureUrl();
                break;
            case 16:
                return $this->getVariationOfId();
                break;
            case 17:
                return $this->getStartPositionId();
                break;
            case 18:
                return $this->getEndPositionId();
                break;
            case 19:
                return $this->getIsComposite();
                break;
            case 20:
                return $this->getIsMultiple();
                break;
            case 21:
                return $this->getMultipleOfId();
                break;
            case 22:
                return $this->getMultiplier();
                break;
            case 23:
                return $this->getGeneration();
                break;
            case 24:
                return $this->getImportance();
                break;
            case 25:
                return $this->getPictureId();
                break;
            case 26:
                return $this->getVideoId();
                break;
            case 27:
                return $this->getTutorialId();
                break;
            case 28:
                return $this->getKstrukturId();
                break;
            case 29:
                return $this->getFunctionPhaseId();
                break;
            case 30:
                return $this->getObjectId();
                break;
            case 31:
                return $this->getVersion();
                break;
            case 32:
                return $this->getVersionCreatedAt();
                break;
            case 33:
                return $this->getVersionComment();
                break;
            case 34:
                return $this->getVariationOfIdVersion();
                break;
            case 35:
                return $this->getMultipleOfIdVersion();
                break;
            case 36:
                return $this->getKkTrixionarySkillIds();
                break;
            case 37:
                return $this->getKkTrixionarySkillVersions();
                break;
            default:
                return null;
                break;
        } // switch()
    }
1191395
private function readBottomMargin()
    {
        $length = self::getInt2d($this->data, $this->pos + 2);
        $recordData = $this->readRecordData($this->data, $this->pos + 4, $length);

        // move stream pointer to next record
        $this->pos += 4 + $length;

        if (!$this->readDataOnly) {
            // offset: 0; size: 8
            $this->phpSheet->getPageMargins()->setBottom(self::extractNumber($recordData));
        }
    }
935379
public function read(int $length = 8192): string
    {
        $isAcceptable = $this->predicate;
        while (!$this->inputStream->eof()) {
            $data = $this->inputStream->read($length);
            if ($isAcceptable($data)) {
                return $data;
            }
        }

        return '';
    }
399324
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getCode();
                break;
            case 1:
                return $this->getAtosCode();
                break;
            case 2:
                return $this->getDecimals();
                break;
            default:
                return null;
                break;
        } // switch()
    }
119774
public function read(int $length = 8192): string
    {
        $bytes           = substr($this->buffer, $this->position, $length);
        $this->position += strlen($bytes);
        return $bytes;
    }
1102458
public function parseLinkDestination($str, $pos, $max)
    {
        $lines = 0;
        $start = $pos;
        $result = new \stdClass();
        $result->ok = false;
        $result->pos = 0;
        $result->lines = 0;
        $result->str = '';

        if( $pos === $max ) return $result;

        if ($str[$pos] === '<') {
            $pos++;
            while ($pos < $max) {
                $ch= $str[$pos];
                if ($str[$pos] == "\n" || $this->utils->isSpace($ch)) { return $result; }
                if ($ch === '>') {
                    $result->pos = $pos + 1;
                    $result->str = $this->utils->unescapeAll(substr($str, $start + 1, $pos-($start+1)));
                    $result->ok = true;
                    return $result;
                }
                if ($ch === '\\' && $pos + 1 < $max) {
                    $pos += 2;
                    continue;
                }

                $pos++;
            }

            // no closing '>'
            return $result;
        }

        // this should be ... } else { ... branch

        $level = 0;
        while ($pos < $max) {
            $ch = $str[$pos];

            if ($ch === ' ') { break; }

            // ascii control characters
            $code = ord($ch);
            if ($code < 0x20 || $code === 0x7F) { break; }

            if ($ch === '\\' && $pos + 1 < $max) {
                $pos += 2;
                continue;
            }

            if ($ch === '(' ) {
                $level++;
            }

            if ($ch === ')' ) {
                if ($level === 0) { break; }
                $level--;
            }

            $pos++;
        }

        if ($start === $pos) { return $result; }
        if ($level !== 0) { return $result; }

        $result->str = $this->utils->unescapeAll(substr($str, $start, $pos-$start));
        $result->lines = $lines;
        $result->pos = $pos;
        $result->ok = true;
        return $result;
    }
865358
public function decode($d, &$pos = 0)
	{
		if (!is_string($d)) {
			throw new Exception('Tried to decode non-string data.', 1);
		}

		if (strlen($d) <= $pos) {
			return null;
		}

		switch ($d[$pos]) {
			case 'd':
				$ret = [];
				$pos++;
				
				while ($d[$pos] != 'e') {
					$key = $this->decode($d, $pos);
					$value = $this->decode($d, $pos);
					if (is_null($key) || is_null($value)) {
						break;
					}
					$ret[$key] = $value;
				}
				$pos++;
				return $ret;
			case 'l':
				$ret = [];
				$pos++;
				while ($d[$pos] != 'e') {
					$value = $this->decode($d, $pos);
					if (is_null($value)) {
						break;
					}
					$ret[] = $value;
				}
				$pos++;
				return $ret;
			case 'i':
				$pos++;
				$length = strpos($d, 'e', $pos) - $pos;
				$value = intval(substr($d, $pos, $length));
				$pos += $length + 1;
				return $value;
			default:
				$length = strpos($d, ':', $pos) - $pos;

				if (!$this->validLength($length)) {
					return null;
				}

				$valueLength = intval(substr($d, $pos, $length));
				$pos += $length + 1;
				$str = substr($d, $pos, $valueLength);
				$pos += $valueLength;
				return $str;
		}
	}
274566
protected function getNextFragment($string, $length = null, &$pos = null) {
			$state = self::STATE_DATA;
			$buffer = '';

			$length = $length ?: strlen($string);
			$pos = $pos ?: 0;
			$depth = 0;

			while ($pos < $length) {
				$char = $string[$pos++];

				if ($char === self::TOKEN_FIELD_SEPARATOR && $depth === 0 && $state === self::STATE_DATA)
					return $buffer;
				else if ($char === self::TOKEN_SUBFIELD_OPEN) {
					$state = self::STATE_SUBFIELD;

					++$depth;
				} else if ($char === self::TOKEN_SUBFIELD_CLOSE) {
					$state = self::STATE_DATA;

					--$depth;
				}

				$buffer .= $char;
			}

			if ($state !== self::STATE_DATA)
				throw new \Exception('Unexpected end of string');

			return $buffer;
		}
512930
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getUsername();
                break;
            case 2:
                return $this->getPassword();
                break;
            case 3:
                return $this->getFirstName();
                break;
            case 4:
                return $this->getLastName();
                break;
            case 5:
                return $this->getCreateDate();
                break;
            case 6:
                return $this->getUpdateDate();
                break;
            case 7:
                return $this->getStatus();
                break;
            default:
                return null;
                break;
        } // switch()
    }
812932
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getTrackuid();
                break;
            case 2:
                return $this->getGbxmapname();
                break;
            case 3:
                return $this->getTrackid();
                break;
            case 4:
                return $this->getUserid();
                break;
            case 5:
                return $this->getUsername();
                break;
            case 6:
                return $this->getUploadedat();
                break;
            case 7:
                return $this->getUpdatedat();
                break;
            case 8:
                return $this->getMaptype();
                break;
            case 9:
                return $this->getTitlepack();
                break;
            case 10:
                return $this->getStylename();
                break;
            case 11:
                return $this->getDisplaycost();
                break;
            case 12:
                return $this->getModname();
                break;
            case 13:
                return $this->getLightmap();
                break;
            case 14:
                return $this->getExeversion();
                break;
            case 15:
                return $this->getExebuild();
                break;
            case 16:
                return $this->getEnvironmentname();
                break;
            case 17:
                return $this->getVehiclename();
                break;
            case 18:
                return $this->getUnlimiterrequired();
                break;
            case 19:
                return $this->getRoutename();
                break;
            case 20:
                return $this->getLengthname();
                break;
            case 21:
                return $this->getLaps();
                break;
            case 22:
                return $this->getDifficultyname();
                break;
            case 23:
                return $this->getReplaytypename();
                break;
            case 24:
                return $this->getReplaywrid();
                break;
            case 25:
                return $this->getReplaywrtime();
                break;
            case 26:
                return $this->getReplaywruserid();
                break;
            case 27:
                return $this->getReplaywrusername();
                break;
            case 28:
                return $this->getRatingvotecount();
                break;
            case 29:
                return $this->getRatingvoteaverage();
                break;
            case 30:
                return $this->getReplaycount();
                break;
            case 31:
                return $this->getTrackvalue();
                break;
            case 32:
                return $this->getComments();
                break;
            case 33:
                return $this->getCommentscount();
                break;
            case 34:
                return $this->getAwardcount();
                break;
            case 35:
                return $this->getHasscreenshot();
                break;
            case 36:
                return $this->getHasthumbnail();
                break;
            case 37:
                return $this->getHasghostblocks();
                break;
            case 38:
                return $this->getEmbeddedobjectscount();
                break;
            default:
                return null;
                break;
        } // switch()
    }
246015
public function readBytes($length)
    {
        $read = $this->read($length);
        if (false !== $read) {
            $ret = array_map('ord', str_split($read, 1));

            return $ret;
        }

        return false;
    }
1106548
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getMaxClients();
                break;
            case 2:
                return $this->getDomain();
                break;
            case 3:
                return $this->getValidUntil();
                break;
            case 4:
                return $this->getSerial();
                break;
            default:
                return null;
                break;
        } // switch()
    }
965378
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getUsername();
                break;
            case 2:
                return $this->getPassword();
                break;
            case 3:
                return $this->getSalt();
                break;
            case 4:
                return $this->getFirstname();
                break;
            case 5:
                return $this->getLastname();
                break;
            case 6:
                return $this->getEmail();
                break;
            case 7:
                return $this->getPhone();
                break;
            case 8:
                return $this->getMemo();
                break;
            case 9:
                return $this->getActivated();
                break;
            case 10:
                return $this->getLastLogin();
                break;
            case 11:
                return $this->getNotificationChange();
                break;
            case 12:
                return $this->getNotificationError();
                break;
            default:
                return null;
                break;
        } // switch()
    }
1022720
public function readintarray($unpack, $pos, $count)
    {
        return unpack($unpack . $count, $this->read($pos, 4 * $count));
    }
935259
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getType();
                break;
            case 2:
                return $this->getTitle();
                break;
            case 3:
                return $this->getYear();
                break;
            case 4:
                return $this->getPublisher();
                break;
            case 5:
                return $this->getJournal();
                break;
            case 6:
                return $this->getNumber();
                break;
            case 7:
                return $this->getSchool();
                break;
            case 8:
                return $this->getAuthor();
                break;
            case 9:
                return $this->getEdition();
                break;
            case 10:
                return $this->getVolume();
                break;
            case 11:
                return $this->getAddress();
                break;
            case 12:
                return $this->getEditor();
                break;
            case 13:
                return $this->getHowpublished();
                break;
            case 14:
                return $this->getNote();
                break;
            case 15:
                return $this->getBooktitle();
                break;
            case 16:
                return $this->getPages();
                break;
            case 17:
                return $this->getUrl();
                break;
            case 18:
                return $this->getLastchecked();
                break;
            case 19:
                return $this->getManaged();
                break;
            default:
                return null;
                break;
        } // switch()
    }
1204495
public function getByPosition($pos)
    {
        switch ($pos) {
            case 0:
                return $this->getId();
                break;
            case 1:
                return $this->getSourceId();
                break;
            case 2:
                return $this->getPageid();
                break;
            case 3:
                return $this->getTitle();
                break;
            case 4:
                return $this->getFiles();
                break;
            case 5:
                return $this->getSubcats();
                break;
            case 6:
                return $this->getPages();
                break;
            case 7:
                return $this->getSize();
                break;
            case 8:
                return $this->getHidden();
                break;
            case 9:
                return $this->getCreatedAt();
                break;
            case 10:
                return $this->getUpdatedAt();
                break;
            case 11:
                return $this->getTreeLeft();
                break;
            case 12:
                return $this->getTreeRight();
                break;
            case 13:
                return $this->getTreeLevel();
                break;
            default:
                return null;
                break;
        } // switch()
    }