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( 0x04 -> ConsolePacket(
type = type, type = type,
eventNumber = eventNumber, 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( 0x05 -> StatusPacket(
@ -405,7 +414,16 @@ fun parseKTagPacket(data: ByteArray): KTagPacket {
minorVersion = data[7].toInt(), minorVersion = data[7].toInt(),
deviceType = bytesToInt(data, 8, 2), deviceType = bytesToInt(data, 8, 2),
teamId = data[10].toInt(), 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( else -> StatusPacket(

View file

@ -1,5 +1,5 @@
[versions] [versions]
agp = "8.8.1" agp = "8.8.2"
kotlin = "2.0.0" kotlin = "2.0.0"
coreKtx = "1.15.0" coreKtx = "1.15.0"
junit = "4.13.2" junit = "4.13.2"