From 64ac3e8f320fc27007e328f6dbe0d03e1de4112d Mon Sep 17 00:00:00 2001 From: J-Jamet Date: Wed, 20 Nov 2019 16:06:59 +0100 Subject: [PATCH] Change reader header and data equals --- .../element/security/ProtectedBinary.kt | 14 +++++++-- .../keepass/database/file/load/ImporterV4.kt | 31 ++++++++++--------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/com/kunzisoft/keepass/database/element/security/ProtectedBinary.kt b/app/src/main/java/com/kunzisoft/keepass/database/element/security/ProtectedBinary.kt index 2df9a1004..f23a13576 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/element/security/ProtectedBinary.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/element/security/ProtectedBinary.kt @@ -108,11 +108,19 @@ class ProtectedBinary : Parcelable { return false if (other !is ProtectedBinary) return false + + var sameData = false + if (data != null && Arrays.equals(data, other.data)) + sameData = true + else if (dataFile != null && dataFile == other.dataFile) + sameData = true + else if (data == null && other.data == null + && dataFile == null && other.dataFile == null) + sameData = true + return isProtected == other.isProtected && size == other.size && - Arrays.equals(data, other.data) && - dataFile != null && - dataFile == other.dataFile + sameData } override fun hashCode(): Int { diff --git a/app/src/main/java/com/kunzisoft/keepass/database/file/load/ImporterV4.kt b/app/src/main/java/com/kunzisoft/keepass/database/file/load/ImporterV4.kt index 76083b925..5da201f53 100644 --- a/app/src/main/java/com/kunzisoft/keepass/database/file/load/ImporterV4.kt +++ b/app/src/main/java/com/kunzisoft/keepass/database/file/load/ImporterV4.kt @@ -220,33 +220,36 @@ class ImporterV4(private val streamDir: File, val size = lis.readInt() if (size < 0) throw IOException("Corrupted file") - var data = ByteArray(0) - if (size > 0) { - if (fieldId != PwDbHeaderV4.PwDbInnerHeaderV4Fields.Binary) - data = lis.readBytes(size) - } - - var result = true when (fieldId) { - PwDbHeaderV4.PwDbInnerHeaderV4Fields.EndOfHeader -> result = false - PwDbHeaderV4.PwDbInnerHeaderV4Fields.InnerRandomStreamID -> header.setRandomStreamID(data) - PwDbHeaderV4.PwDbInnerHeaderV4Fields.InnerRandomstreamKey -> header.innerRandomStreamKey = data + PwDbHeaderV4.PwDbInnerHeaderV4Fields.EndOfHeader -> { + return false + } + PwDbHeaderV4.PwDbInnerHeaderV4Fields.InnerRandomStreamID -> { + val data = if (size > 0) lis.readBytes(size) else ByteArray(0) + header.setRandomStreamID(data) + } + PwDbHeaderV4.PwDbInnerHeaderV4Fields.InnerRandomstreamKey -> { + val data = if (size > 0) lis.readBytes(size) else ByteArray(0) + header.innerRandomStreamKey = data + } PwDbHeaderV4.PwDbInnerHeaderV4Fields.Binary -> { val flag = lis.readBytes(1)[0].toInt() != 0 val protectedFlag = flag && PwDbHeaderV4.KdbxBinaryFlags.Protected.toInt() != PwDbHeaderV4.KdbxBinaryFlags.None.toInt() val byteLength = size - 1 // Read in a file val file = File(streamDir, unusedCacheFileName) - FileOutputStream(file).use { outputStream -> lis.readBytes(byteLength) { outputStream.write(it) } } + FileOutputStream(file).use { outputStream -> + lis.readBytes(byteLength) { outputStream.write(it) } + } val protectedBinary = ProtectedBinary(protectedFlag, file, byteLength) mDatabase.binPool.add(protectedBinary) } - else -> { + return false } } - return result + return true } private enum class KdbContext { @@ -969,7 +972,6 @@ class ImporterV4(private val streamDir: File, } val buf = processNode(xpp) - if (buf != null) { createProtectedBinaryFromData(true, buf) } @@ -1001,7 +1003,6 @@ class ImporterV4(private val streamDir: File, } return xpp.safeNextText() - } @Throws(XmlPullParserException::class, IOException::class)