Fixed Hello packet scanning.

This commit is contained in:
Joe Kearney 2025-02-27 19:43:52 -06:00
parent 010361066e
commit 72b9eaa61d
2 changed files with 21 additions and 3 deletions

View file

@ -370,7 +370,16 @@ fun parseKTagPacket(data: ByteArray): KTagPacket {
0x04 -> ConsolePacket(
type = type,
eventNumber = eventNumber,
consoleString = data.slice(6..26).toByteArray().toString(Charsets.US_ASCII).trim(0.toChar())
consoleString = data.slice(6..26).toByteArray().let { bytes ->
// Find the position of the first null byte if any
val nullPos = bytes.indexOfFirst { it == 0.toByte() }
// If there's a null byte, take only up to that position, otherwise take all bytes
if (nullPos >= 0) {
bytes.slice(0 until nullPos).toByteArray()
} else {
bytes
}.toString(Charsets.US_ASCII).trim()
}
)
0x05 -> StatusPacket(
@ -405,7 +414,16 @@ fun parseKTagPacket(data: ByteArray): KTagPacket {
minorVersion = data[7].toInt(),
deviceType = bytesToInt(data, 8, 2),
teamId = data[10].toInt(),
deviceName = data.slice(11..26).toByteArray().toString(Charsets.US_ASCII).trim(0.toChar())
deviceName = data.slice(11..26).toByteArray().let { bytes ->
// Find the position of the first null byte if any
val nullPos = bytes.indexOfFirst { it == 0.toByte() }
// If there's a null byte, take only up to that position, otherwise take all bytes
if (nullPos >= 0) {
bytes.slice(0 until nullPos).toByteArray()
} else {
bytes
}.toString(Charsets.US_ASCII).trim()
}
)
else -> StatusPacket(