/** * Tries to read the file $this->file, and to decode it as a KeePass 2.x * database, using the key $this->key. Returns true if the operation was * successful, or false otherwise. In case of success, the array * $this->entries will contain the resulting list of entries. * * @return boolean */ public function tryLoad() { if ($this->loaded) { return $this->rawEntries != null; } $this->loaded = true; if (!is_file($this->file) || !is_readable($this->file)) { KeePassPHP::raiseError("Impossible to read " . $this->file); return false; } KeePassPHP::printDebug("Attempting to load database from " . $this->file); if (!$this->tryParse(RessourceReader::openFile($this->file))) { KeePassPHP::printDebug(" ... attempt failed !"); return false; } KeePassPHP::printDebug(" ... attempt succeeded !"); return true; }
/** * Tries to parse the given file as a binary or a hex file. * @param string $filename The name of the file to parse. * @return boolean Returns true in case of success, false otherwise. */ private function tryParse($filename) { $reader = RessourceReader::openFile($filename); if ($reader == null) { return false; } $key = $reader->readToTheEnd(); if (strlen($key) == 32) { $this->hash = $key; return true; } if (strlen($key) == 64) { $this->hash = hex2bin($key); return true; } return false; }