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();