Skip to content

Commit

Permalink
fix apple protobuf version length
Browse files Browse the repository at this point in the history
  • Loading branch information
rec0de committed Dec 19, 2024
1 parent 4e6c551 commit 1d0d8ff
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/commonMain/kotlin/decoders/AppleProtobuf.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,12 @@ class AppleProtobuf : ParseCompanion() {
private fun decode(bytes: ByteArray, sourceOffset: Int) : ByteWitchResult {
parseOffset = 0
val startOffset = parseOffset
val version = readInt(bytes, 1)
val version = readInt(bytes, 2)
check(version == 1){ "expecting version 1 in first byte, got $version" }

// try to see if we have metadata strings or not
val localeLen = UInt.fromBytes(bytes.sliceArray(1 until 3), ByteOrder.BIG)
Logger.log(localeLen)
val localeLen = UInt.fromBytes(bytes.sliceArray(parseOffset until parseOffset+2), ByteOrder.BIG)
val hasMetadata = localeLen >= 2u && localeLen < 64u && looksLikeUtf8String(bytes.sliceArray(3 until 3+localeLen.toInt())) > 0.4
Logger.log(hasMetadata)

val metadata = if(hasMetadata) {
var stringStart = parseOffset
Expand Down

0 comments on commit 1d0d8ff

Please sign in to comment.