From 5d0aed224c3134004ef5c2adf9edfd71482c1541 Mon Sep 17 00:00:00 2001 From: layou233 Date: Sat, 12 Oct 2024 21:05:46 +0800 Subject: [PATCH] Fix DNS resolver read string --- .../com/launium/mcping/server/MinecraftResolver.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/launium/mcping/server/MinecraftResolver.kt b/app/src/main/java/com/launium/mcping/server/MinecraftResolver.kt index 5cfb406..0e1c88a 100644 --- a/app/src/main/java/com/launium/mcping/server/MinecraftResolver.kt +++ b/app/src/main/java/com/launium/mcping/server/MinecraftResolver.kt @@ -17,7 +17,8 @@ import kotlinx.io.Buffer import kotlinx.io.Source import kotlinx.io.asSource import kotlinx.io.buffered -import kotlinx.io.readByteArray +import kotlinx.io.readString +import kotlinx.io.readUByte import kotlinx.io.readUShort import kotlinx.io.writeString import java.io.ByteArrayInputStream @@ -91,7 +92,7 @@ class MinecraftResolver(uri: String) { repeat(answersCount) { addressBuilder.clear() while (true) { // skip domain name - val bytesCount = response.readByte().toUByte() + val bytesCount = response.readUByte() if (bytesCount == 0.toUByte()) break if (bytesCount and COMPRESSED_LABEL_MARK == COMPRESSED_LABEL_MARK) { response.skip(1) @@ -102,9 +103,9 @@ class MinecraftResolver(uri: String) { response.skip(14) val port = response.readUShort() while (true) { - val bytesCount = response.readByte().toUInt() - if (bytesCount == 0U) break - addressBuilder.append(response.readByteArray(bytesCount.toInt())) + val bytesCount = response.readUByte().toLong() + if (bytesCount == 0L) break + addressBuilder.append(response.readString(bytesCount)) addressBuilder.append('.') } results.add(InetSocketAddress(addressBuilder.toString(), port.toInt()))