package io.netty.handler.codec.socks;

import io.netty.handler.codec.ReplayingDecoder;

/* JADX INFO: loaded from: classes.dex */
public class SocksCmdRequestDecoder extends ReplayingDecoder<State> {
    private SocksAddressType addressType;
    private SocksCmdType cmdType;

    /* JADX INFO: renamed from: io.netty.handler.codec.socks.SocksCmdRequestDecoder$1, reason: invalid class name */
    public static /* synthetic */ class AnonymousClass1 {
        public static final /* synthetic */ int[] $SwitchMap$io$netty$handler$codec$socks$SocksAddressType;
        public static final /* synthetic */ int[] $SwitchMap$io$netty$handler$codec$socks$SocksCmdRequestDecoder$State;

        static {
            State.values();
            int[] iArr = new int[3];
            $SwitchMap$io$netty$handler$codec$socks$SocksCmdRequestDecoder$State = iArr;
            try {
                iArr[State.CHECK_PROTOCOL_VERSION.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$socks$SocksCmdRequestDecoder$State[State.READ_CMD_HEADER.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$socks$SocksCmdRequestDecoder$State[State.READ_CMD_ADDRESS.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            SocksAddressType.values();
            int[] iArr2 = new int[4];
            $SwitchMap$io$netty$handler$codec$socks$SocksAddressType = iArr2;
            try {
                iArr2[SocksAddressType.IPv4.ordinal()] = 1;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$socks$SocksAddressType[SocksAddressType.DOMAIN.ordinal()] = 2;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$socks$SocksAddressType[SocksAddressType.IPv6.ordinal()] = 3;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                $SwitchMap$io$netty$handler$codec$socks$SocksAddressType[SocksAddressType.UNKNOWN.ordinal()] = 4;
            } catch (NoSuchFieldError unused7) {
            }
        }
    }

    public enum State {
        CHECK_PROTOCOL_VERSION,
        READ_CMD_HEADER,
        READ_CMD_ADDRESS
    }

    public SocksCmdRequestDecoder() {
        super(State.CHECK_PROTOCOL_VERSION);
    }

    /* JADX WARN: Removed duplicated region for block: B:16:0x004f  */
    /* JADX WARN: Removed duplicated region for block: B:25:0x0091  */
    @Override // io.netty.handler.codec.ByteToMessageDecoder
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void decode(io.netty.channel.ChannelHandlerContext r5, io.netty.buffer.ByteBuf r6, java.util.List<java.lang.Object> r7) {
        /*
            r4 = this;
            java.lang.Object r0 = r4.state()
            io.netty.handler.codec.socks.SocksCmdRequestDecoder$State r0 = (io.netty.handler.codec.socks.SocksCmdRequestDecoder.State) r0
            int r0 = r0.ordinal()
            r1 = 2
            r2 = 1
            if (r0 == 0) goto L19
            if (r0 == r2) goto L2b
            if (r0 != r1) goto L13
            goto L47
        L13:
            java.lang.Error r5 = new java.lang.Error
            r5.<init>()
            throw r5
        L19:
            byte r0 = r6.readByte()
            io.netty.handler.codec.socks.SocksProtocolVersion r3 = io.netty.handler.codec.socks.SocksProtocolVersion.SOCKS5
            byte r3 = r3.byteValue()
            if (r0 == r3) goto L26
            goto L56
        L26:
            io.netty.handler.codec.socks.SocksCmdRequestDecoder$State r0 = io.netty.handler.codec.socks.SocksCmdRequestDecoder.State.READ_CMD_HEADER
            r4.checkpoint(r0)
        L2b:
            byte r0 = r6.readByte()
            io.netty.handler.codec.socks.SocksCmdType r0 = io.netty.handler.codec.socks.SocksCmdType.valueOf(r0)
            r4.cmdType = r0
            r6.skipBytes(r2)
            byte r0 = r6.readByte()
            io.netty.handler.codec.socks.SocksAddressType r0 = io.netty.handler.codec.socks.SocksAddressType.valueOf(r0)
            r4.addressType = r0
            io.netty.handler.codec.socks.SocksCmdRequestDecoder$State r0 = io.netty.handler.codec.socks.SocksCmdRequestDecoder.State.READ_CMD_ADDRESS
            r4.checkpoint(r0)
        L47:
            io.netty.handler.codec.socks.SocksAddressType r0 = r4.addressType
            int r0 = r0.ordinal()
            if (r0 == 0) goto L91
            if (r0 == r2) goto L7b
            if (r0 == r1) goto L62
            r6 = 3
            if (r0 != r6) goto L5c
        L56:
            io.netty.handler.codec.socks.SocksRequest r6 = io.netty.handler.codec.socks.SocksCommonUtils.UNKNOWN_SOCKS_REQUEST
            r7.add(r6)
            goto La9
        L5c:
            java.lang.Error r5 = new java.lang.Error
            r5.<init>()
            throw r5
        L62:
            r0 = 16
            byte[] r0 = new byte[r0]
            r6.readBytes(r0)
            java.lang.String r0 = io.netty.handler.codec.socks.SocksCommonUtils.ipv6toStr(r0)
            int r6 = r6.readUnsignedShort()
            io.netty.handler.codec.socks.SocksCmdRequest r1 = new io.netty.handler.codec.socks.SocksCmdRequest
            io.netty.handler.codec.socks.SocksCmdType r2 = r4.cmdType
            io.netty.handler.codec.socks.SocksAddressType r3 = r4.addressType
            r1.<init>(r2, r3, r0, r6)
            goto La6
        L7b:
            byte r0 = r6.readByte()
            java.lang.String r0 = io.netty.handler.codec.socks.SocksCommonUtils.readUsAscii(r6, r0)
            int r6 = r6.readUnsignedShort()
            io.netty.handler.codec.socks.SocksCmdRequest r1 = new io.netty.handler.codec.socks.SocksCmdRequest
            io.netty.handler.codec.socks.SocksCmdType r2 = r4.cmdType
            io.netty.handler.codec.socks.SocksAddressType r3 = r4.addressType
            r1.<init>(r2, r3, r0, r6)
            goto La6
        L91:
            int r0 = r6.readInt()
            java.lang.String r0 = io.netty.util.NetUtil.intToIpAddress(r0)
            int r6 = r6.readUnsignedShort()
            io.netty.handler.codec.socks.SocksCmdRequest r1 = new io.netty.handler.codec.socks.SocksCmdRequest
            io.netty.handler.codec.socks.SocksCmdType r2 = r4.cmdType
            io.netty.handler.codec.socks.SocksAddressType r3 = r4.addressType
            r1.<init>(r2, r3, r0, r6)
        La6:
            r7.add(r1)
        La9:
            io.netty.channel.ChannelPipeline r5 = r5.pipeline()
            r5.remove(r4)
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.handler.codec.socks.SocksCmdRequestDecoder.decode(io.netty.channel.ChannelHandlerContext, io.netty.buffer.ByteBuf, java.util.List):void");
    }
}
