Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import java.math.BigInteger;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.KeyPair;
Expand Down Expand Up @@ -122,7 +121,7 @@ public byte[] getAdbPublicKeyPayload() {
byte[] converted = convertRsaPublicKeyToAdbFormat((RSAPublicKey) this.keyPair.getPublic());
String base64 = Base64.encodeToString(converted, Base64.NO_WRAP);
String keyString = base64 + " OpenHU@localhost\u0000";
return keyString.getBytes(StandardCharsets.UTF_8);
return keyString.getBytes(AdbProtocol.UTF_8);
}

public byte[] signAdbTokenPayload(byte[] token) throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import java.io.File
import java.io.IOException
import java.net.InetSocketAddress
import java.net.Socket
import java.nio.charset.StandardCharsets

object AdbManager {

Expand Down Expand Up @@ -89,7 +88,7 @@ object AdbManager {
try {
val data = activeStream.read()
if (data.isNotEmpty()) {
outputBuilder.append(String(data, StandardCharsets.UTF_8))
outputBuilder.append(String(data, AdbProtocol.UTF_8))
}
} catch (e: Exception) {
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.nio.charset.Charset;

public class AdbProtocol {
// StandardCharsets is unavailable before API 19; keep the ADB wire encoding shared.
// Never substitute the device's default charset: payload lengths and checksums must describe
// the same UTF-8 bytes on every supported Android version.
static final Charset UTF_8 = Charset.forName("UTF-8");

public static final int ADB_HEADER_LENGTH = 24;
public static final int AUTH_TYPE_TOKEN = 1;
public static final int AUTH_TYPE_SIGNATURE = 2;
Expand All @@ -21,7 +26,7 @@ public class AdbProtocol {

public static final int CONNECT_VERSION = 0x01000000;
public static final int CONNECT_MAXDATA = 4096;
public static final byte[] CONNECT_PAYLOAD = "host::\u0000".getBytes(StandardCharsets.UTF_8);
public static final byte[] CONNECT_PAYLOAD = "host::\u0000".getBytes(UTF_8);

public static final class AdbMessage {
public int command;
Expand Down Expand Up @@ -90,7 +95,7 @@ public static byte[] generateAuth(int type, byte[] data) {
}

public static byte[] generateOpen(int localId, String destination) {
byte[] destBytes = (destination != null ? destination : "").getBytes(StandardCharsets.UTF_8);
byte[] destBytes = (destination != null ? destination : "").getBytes(UTF_8);
ByteBuffer destBuf = ByteBuffer.allocate(destBytes.length + 1);
destBuf.put(destBytes);
destBuf.put((byte) 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.Closeable;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -84,7 +83,7 @@ public void updateRemoteId(int remoteId) {

public void write(String str) throws IOException, InterruptedException {
if (str == null) return;
write(str.getBytes(StandardCharsets.UTF_8), true);
write(str.getBytes(AdbProtocol.UTF_8), true);
}

public void write(byte[] data) throws IOException, InterruptedException {
Expand Down
Loading