package p138.p329.p362.p368;

import com.hierynomus.msdfsc.DFSException;
import com.hierynomus.protocol.commons.buffer.Buffer;
import com.hierynomus.protocol.transport.TransportException;
import com.hierynomus.smbj.common.SMBRuntimeException;
import java.io.IOException;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p242.p246.p251.C4303;
import p138.p329.p338.C6141;
import p138.p329.p338.C6142;
import p138.p329.p338.C6144;
import p138.p329.p338.p339.AbstractC6148;
import p138.p329.p338.p339.C6151;
import p138.p329.p338.p339.C6152;
import p138.p329.p338.p339.C6153;
import p138.p329.p338.p339.C6154;
import p138.p329.p341.EnumC6158;
import p138.p329.p346.C6228;
import p138.p329.p346.C6231;
import p138.p329.p346.C6237;
import p138.p329.p346.p347.C6250;
import p138.p329.p346.p347.C6251;
import p138.p329.p351.p352.C6288;
import p138.p329.p351.p352.p354.InterfaceC6301;
import p138.p329.p361.C6332;
import p138.p329.p362.p364.C6353;
import p138.p329.p362.p367.C6371;
import p138.p329.p362.p369.C6386;
import p138.p329.p362.p370.C6406;
import p138.p329.p362.p370.InterfaceC6411;
import p463.p481.C7162;
import p463.p481.InterfaceC7161;

/* JADX INFO: renamed from: ދ.ށ.މ.އ.֏, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public class C6374 implements InterfaceC6379 {

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public static final InterfaceC7161 f17792 = C7162.m10575((Class<?>) C6374.class);

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final InterfaceC6411 f17793;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final InterfaceC6379 f17794;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public C6144 f17795 = new C6144();

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public C6142 f17796 = new C6142();

    /* JADX INFO: renamed from: ދ.ށ.މ.އ.֏$֏, reason: contains not printable characters */
    public class C6375 implements InterfaceC6411 {

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final /* synthetic */ InterfaceC6379 f17797;

        public C6375(C6374 c6374, InterfaceC6379 interfaceC6379) {
            this.f17797 = interfaceC6379;
        }

        @Override // p138.p329.p362.p370.InterfaceC6411
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public boolean mo9604(long j) {
            return j == EnumC6158.STATUS_PATH_NOT_COVERED.f17193 || this.f17797.mo9600().mo9604(j);
        }
    }

    /* JADX INFO: renamed from: ދ.ށ.މ.އ.֏$ؠ, reason: contains not printable characters */
    public enum EnumC6376 {
        DOMAIN,
        DC,
        SYSVOL,
        ROOT,
        LINK
    }

    /* JADX INFO: renamed from: ދ.ށ.މ.އ.֏$ހ, reason: contains not printable characters */
    public static class C6377 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public long f17804;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public C6144.C6145 f17805;

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public C6142.C6143 f17806;

        public /* synthetic */ C6377(long j, C6375 c6375) {
            this.f17804 = j;
        }
    }

    /* JADX INFO: renamed from: ދ.ށ.މ.އ.֏$ށ, reason: contains not printable characters */
    public static class C6378 {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public C6141 f17807;

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public boolean f17808 = false;

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public boolean f17809 = false;

        /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
        public String f17810 = null;

        public C6378(C6141 c6141) {
            this.f17807 = c6141;
        }

        public String toString() {
            StringBuilder sbM4889 = C2803.m4889("ResolveState{path=");
            sbM4889.append(this.f17807);
            sbM4889.append(", resolvedDomainEntry=");
            sbM4889.append(this.f17808);
            sbM4889.append(", isDFSPath=");
            sbM4889.append(this.f17809);
            sbM4889.append(", hostName='");
            sbM4889.append(this.f17810);
            sbM4889.append('\'');
            sbM4889.append('}');
            return sbM4889.toString();
        }
    }

    public C6374(InterfaceC6379 interfaceC6379) {
        this.f17794 = interfaceC6379;
        this.f17793 = new C6375(this, interfaceC6379);
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0047  */
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final String m9592(C6386 c6386, String str) throws DFSException {
        C6141 c6141M9594;
        f17792.mo10561("Starting DFS resolution for {}", str);
        C6378 c6378 = new C6378(new C6141(str));
        f17792.mo10570("DFS[1]: {}", c6378);
        if (!(c6378.f17807.f17048.size() == 1)) {
            C6141 c6141 = c6378.f17807;
            if (c6141.f17048.size() > 1 ? "IPC$".equals(c6141.f17048.get(1)) : false) {
                f17792.mo10570("DFS[12]: {}", c6378);
                c6141M9594 = c6378.f17807;
            } else {
                c6141M9594 = m9594(c6386, c6378);
            }
        }
        return c6141M9594.m9472();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C6141 m9593(C6378 c6378, C6377 c6377) throws DFSException {
        f17792.mo10570("DFS[13]: {}", c6378);
        throw new DFSException(c6377.f17804, C2803.m4884(C2803.m4889("Cannot get DC for domain '"), c6378.f17807.f17048.get(0), "'"));
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C6141 m9594(C6386 c6386, C6378 c6378) throws DFSException {
        f17792.mo10570("DFS[2]: {}", c6378);
        C6144 c6144 = this.f17795;
        C6141 c6141 = c6378.f17807;
        if (c6144 == null) {
            throw null;
        }
        C6144.C6145 c6145M9474 = c6144.f17053.m9474(c6141.f17048.iterator());
        if (c6145M9474 != null) {
            if (!(System.currentTimeMillis() > c6145M9474.f17058) || !c6145M9474.m9473()) {
                if (!(System.currentTimeMillis() > c6145M9474.f17058)) {
                    return c6145M9474.f17055 == AbstractC6148.EnumC6150.LINK ? m9603(c6386, c6378, c6145M9474) : m9595(c6386, c6378, c6145M9474);
                }
                f17792.mo10570("DFS[9]: {}", c6378);
                C6141 c61412 = new C6141(c6378.f17807.f17048.subList(0, 2));
                C6144 c61442 = this.f17795;
                if (c61442 == null) {
                    throw null;
                }
                C6144.C6145 c6145M94742 = c61442.f17053.m9474(c61412.f17048.iterator());
                if (c6145M94742 == null) {
                    throw new IllegalStateException("Could not find referral cache entry for " + c61412);
                }
                C6377 c6377M9598 = m9598(EnumC6376.LINK, c6145M94742.f17059.f17064, c6386, c6378.f17807);
                if (EnumC6158.m9480(c6377M9598.f17804)) {
                    return c6377M9598.f17805.m9473() ? m9595(c6386, c6378, c6377M9598.f17805) : m9603(c6386, c6378, c6377M9598.f17805);
                }
                m9601(c6378, c6377M9598);
                throw null;
            }
        }
        f17792.mo10570("DFS[5]: {}", c6378);
        String str = c6378.f17807.f17048.get(0);
        C6142.C6143 c6143 = this.f17796.f17049.get(str);
        if (c6143 == null) {
            c6378.f17810 = str;
            c6378.f17808 = false;
            return m9602(c6386, c6378);
        }
        String str2 = c6143.f17051;
        if (str2 == null || str2.isEmpty()) {
            C6377 c6377M95982 = m9598(EnumC6376.DC, c6386.f17833.f17716, c6386, c6378.f17807);
            if (!EnumC6158.m9480(c6377M95982.f17804)) {
                m9593(c6378, c6377M95982);
                throw null;
            }
            c6143 = c6377M95982.f17806;
        }
        if (!c6378.f17807.m9471()) {
            c6378.f17810 = c6143.f17051;
            c6378.f17808 = true;
            return m9602(c6386, c6378);
        }
        f17792.mo10570("DFS[10]: {}", c6378);
        C6377 c6377M95983 = m9598(EnumC6376.SYSVOL, c6143.f17051, c6386, c6378.f17807);
        if (EnumC6158.m9480(c6377M95983.f17804)) {
            return m9595(c6386, c6378, c6377M95983.f17805);
        }
        m9593(c6378, c6377M95983);
        throw null;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C6141 m9595(C6386 c6386, C6378 c6378, C6144.C6145 c6145) {
        f17792.mo10570("DFS[3]: {}", c6378);
        c6378.f17807 = c6378.f17807.m9470(c6145.f17054, c6145.f17059.f17064);
        c6378.f17809 = true;
        f17792.mo10570("DFS[8]: {}", c6378);
        return c6378.f17807;
    }

    @Override // p138.p329.p362.p368.InterfaceC6379
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public C6353 mo9596(C6386 c6386, C6237 c6237, C6353 c6353) {
        if (c6353.f17736 != null && c6237.mo9556().f17394 == EnumC6158.STATUS_PATH_NOT_COVERED.f17193) {
            f17792.mo10567("DFS Share {} does not cover {}, resolve through DFS", c6353.f17735, c6353);
            C6353 c6353M9568 = C6353.m9568(m9592(c6386, c6353.m9570()));
            f17792.mo10567("DFS resolved {} -> {}", c6353, c6353M9568);
            return c6353M9568;
        }
        if (c6353.f17736 != null || !EnumC6158.m9479(c6237.mo9556().f17394)) {
            return this.f17794.mo9596(c6386, c6237, c6353);
        }
        f17792.mo10561("Attempting to resolve {} through DFS", c6353);
        return C6353.m9568(m9592(c6386, c6353.m9570()));
    }

    @Override // p138.p329.p362.p368.InterfaceC6379
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public C6353 mo9597(C6386 c6386, C6353 c6353) {
        C6353 c6353M9568 = C6353.m9568(m9592(c6386, c6353.m9570()));
        if (c6353.equals(c6353M9568)) {
            return this.f17794.mo9597(c6386, c6353);
        }
        f17792.mo10567("DFS resolved {} -> {}", c6353, c6353M9568);
        return c6353M9568;
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C6377 m9598(EnumC6376 enumC6376, String str, C6386 c6386, C6141 c6141) throws DFSException {
        if (!str.equals(c6386.f17828.f17745)) {
            try {
                c6386 = c6386.f17828.f17746.m9558(str, 445).m9576(c6386.f17833);
            } catch (IOException e) {
                throw new DFSException(e);
            }
        }
        try {
            C6406 c6406M9610 = c6386.m9610("IPC$");
            try {
                C6377 c6377M9599 = m9599(enumC6376, c6406M9610, c6141);
                c6406M9610.close();
                return c6377M9599;
            } finally {
            }
        } catch (Buffer.BufferException | IOException e2) {
            throw new DFSException(e2);
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C6377 m9599(EnumC6376 enumC6376, C6406 c6406, C6141 c6141) {
        AbstractC6148 c6151;
        String strM9472 = c6141.m9472();
        C6332 c6332 = new C6332();
        c6332.f2169.mo9532((Buffer) c6332, 4);
        c6332.m1462(strM9472, C6288.f17630);
        C6371 c6371 = new C6371(c6332);
        C6375 c6375 = null;
        if (c6406 == null) {
            throw null;
        }
        C6228 c6228 = C6406.f17880;
        int iMo9589 = c6371.mo9589();
        int i = c6406.f17894;
        if (iMo9589 > i) {
            StringBuilder sbM4889 = C2803.m4889("Input data size exceeds maximum allowed by server: ");
            sbM4889.append(c6371.mo9589());
            sbM4889.append(" > ");
            sbM4889.append(c6406.f17894);
            throw new SMBRuntimeException(sbM4889.toString());
        }
        C6251 c6251 = (C6251) C4303.m7012(c6406.m9633(new C6250(c6406.f17889, c6406.f17896, c6406.f17887, 393620L, c6228, c6371, true, i)), (InterfaceC6301) TransportException.f2172);
        C6377 c6377 = new C6377(((C6231) c6251.f17677).f17394, c6375);
        if (c6377.f17804 == EnumC6158.STATUS_SUCCESS.f17193) {
            C6154 c6154 = new C6154(c6141.m9472());
            C6332 c63322 = new C6332(c6251.f17471);
            c63322.m1475();
            int iM1475 = c63322.m1475();
            c6154.f17084 = C4303.m7041(c63322.m1477(), C6154.EnumC6155.class);
            for (int i2 = 0; i2 < iM1475; i2++) {
                int iM14752 = c63322.m1475();
                c63322.f2170 -= 2;
                if (iM14752 == 1) {
                    c6151 = new C6151();
                    c6151.m9477(c63322);
                } else if (iM14752 == 2) {
                    c6151 = new C6152();
                    c6151.m9477(c63322);
                } else {
                    if (iM14752 != 3 && iM14752 != 4) {
                        throw new IllegalArgumentException(C2803.m4872("Incorrect version number ", iM14752, " while parsing DFS Referrals"));
                    }
                    c6151 = new C6153();
                    c6151.m9477(c63322);
                }
                if (c6151.f17071 == null) {
                    c6151.f17071 = c6154.f17083;
                }
                c6154.f17085.add(c6151);
            }
            int iOrdinal = enumC6376.ordinal();
            if (iOrdinal == 0) {
                throw new UnsupportedOperationException(EnumC6376.DOMAIN + " not used yet.");
            }
            if (iOrdinal != 1) {
                if (iOrdinal != 2 && iOrdinal != 3 && iOrdinal != 4) {
                    throw new IllegalStateException("Encountered unhandled DFS RequestType: " + enumC6376);
                }
                if (c6154.f17085.isEmpty()) {
                    c6377.f17804 = EnumC6158.STATUS_OBJECT_PATH_NOT_FOUND.f17193;
                } else {
                    C6144.C6145 c6145 = new C6144.C6145(c6154, this.f17796);
                    f17792.mo10561("Got DFS Referral result: {}", c6145);
                    C6144 c6144 = this.f17795;
                    if (c6144 == null) {
                        throw null;
                    }
                    c6144.f17053.m9475(C6141.m9469(c6145.f17054).iterator(), c6145);
                    c6377.f17805 = c6145;
                }
            } else if ((c6154.f17085.isEmpty() ? 0 : c6154.f17085.get(0).f17066) >= 3) {
                C6142.C6143 c6143 = new C6142.C6143(c6154);
                this.f17796.f17049.put(c6143.f17050, c6143);
                c6377.f17806 = c6143;
            }
        }
        return c6377;
    }

    @Override // p138.p329.p362.p368.InterfaceC6379
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public InterfaceC6411 mo9600() {
        return this.f17793;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final C6141 m9601(C6378 c6378, C6377 c6377) throws DFSException {
        f17792.mo10570("DFS[14]: {}", c6378);
        long j = c6377.f17804;
        StringBuilder sbM4889 = C2803.m4889("DFS request failed for path ");
        sbM4889.append(c6378.f17807);
        throw new DFSException(j, sbM4889.toString());
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final C6141 m9602(C6386 c6386, C6378 c6378) throws DFSException {
        f17792.mo10570("DFS[6]: {}", c6378);
        C6377 c6377M9598 = m9598(EnumC6376.ROOT, c6378.f17807.f17048.get(0), c6386, c6378.f17807);
        if (EnumC6158.m9480(c6377M9598.f17804)) {
            C6144.C6145 c6145 = c6377M9598.f17805;
            f17792.mo10570("DFS[7]: {}", c6378);
            return c6145.m9473() ? m9595(c6386, c6378, c6145) : m9603(c6386, c6378, c6145);
        }
        if (c6378.f17808) {
            m9593(c6378, c6377M9598);
            throw null;
        }
        if (c6378.f17809) {
            m9601(c6378, c6377M9598);
            throw null;
        }
        f17792.mo10570("DFS[12]: {}", c6378);
        return c6378.f17807;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final C6141 m9603(C6386 c6386, C6378 c6378, C6144.C6145 c6145) {
        f17792.mo10570("DFS[4]: {}", c6378);
        if (c6378.f17807.m9471()) {
            return m9595(c6386, c6378, c6145);
        }
        boolean z = false;
        if ((c6145.f17055 == AbstractC6148.EnumC6150.LINK) && c6145.f17056) {
            z = true;
        }
        if (!z) {
            return m9595(c6386, c6378, c6145);
        }
        f17792.mo10570("DFS[11]: {}", c6378);
        c6378.f17807 = c6378.f17807.m9470(c6145.f17054, c6145.f17059.f17064);
        c6378.f17809 = true;
        return m9594(c6386, c6378);
    }
}
