From b34c0124da83047affa9816174507b846a1811de Mon Sep 17 00:00:00 2001 From: purofle Date: Sun, 18 Feb 2024 15:11:07 +0800 Subject: [PATCH] fix: crash on 1.3.0 Closes #543 Closes #439 Closes #514 Closes #540 --- .../sagernet/fmt/v2ray/StandardV2RayBean.java | 35 +++++++++++++++---- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/StandardV2RayBean.java b/app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/StandardV2RayBean.java index 45107233..46b37ecf 100644 --- a/app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/StandardV2RayBean.java +++ b/app/src/main/java/io/nekohasekai/sagernet/fmt/v2ray/StandardV2RayBean.java @@ -105,9 +105,8 @@ public void initializeDefaultValues() { @Override public void serialize(ByteBufferOutput output) { - output.writeInt(0); + output.writeInt(1); super.serialize(output); - output.writeString(uuid); output.writeString(encryption); if (this instanceof VMessBean) { @@ -211,11 +210,33 @@ public void deserialize(ByteBufferInput input) { realityShortId = input.readString(); } - enableECH = input.readBoolean(); - if (enableECH) { - enablePqSignature = input.readBoolean(); - disabledDRS = input.readBoolean(); - echConfig = input.readString(); + if (version >= 1) { // 从老版本升级上来 + enableECH = input.readBoolean(); + if (enableECH) { + enablePqSignature = input.readBoolean(); + disabledDRS = input.readBoolean(); + echConfig = input.readString(); + } + } + + if (version == 0) { + // 从老版本升级上来但是 version == 0, 可能有 enableECH 也可能没有,需要做判断 + int position = input.getByteBuffer().position(); // 当前位置 + + boolean tmpEnableECH = input.readBoolean(); + int tmpPacketEncoding = input.readInt(); + + input.setPosition(position); // 读后归位 + + if (tmpPacketEncoding != 1 && tmpPacketEncoding != 2) { + input.getByteBuffer().position(position); + enableECH = tmpEnableECH; + if (enableECH) { + enablePqSignature = input.readBoolean(); + disabledDRS = input.readBoolean(); + echConfig = input.readString(); + } + } // 否则后一位就是 packetEncoding } packetEncoding = input.readInt();