package f1;

import java.io.IOException;
import k1.C0599q;
import k1.Y;
import k1.Z;
import k1.b0;
import l1.AbstractC0619b;
import okhttp3.HttpUrl;

/* JADX INFO: renamed from: f1.h, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0471h extends AbstractC0469f {

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    b0 f3932g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    Y f3933h = null;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    Z f3934i = null;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    boolean f3935j = true;

    public C0471h(String str, C0599q c0599q) {
        this.f3922b = AbstractC0469f.f(str);
        String str2 = "smb://" + this.f3922b.f3910b + "/IPC$/" + this.f3922b.f3911c.substring(6);
        String str3 = (String) this.f3922b.a("server");
        String str4 = HttpUrl.FRAGMENT_ENCODE_SET;
        if (str3 != null) {
            str4 = HttpUrl.FRAGMENT_ENCODE_SET + "&server=" + str3;
        }
        String str5 = (String) this.f3922b.a("address");
        if (str3 != null) {
            str4 = str4 + "&address=" + str5;
        }
        if (str4.length() > 0) {
            str2 = str2 + "?" + str4.substring(1);
        }
        this.f3932g = new b0(str2, 27198979, c0599q);
    }

    @Override // f1.AbstractC0469f
    public void b() {
        this.f3925e = 0;
        Z z2 = this.f3934i;
        if (z2 != null) {
            z2.close();
        }
    }

    @Override // f1.AbstractC0469f
    protected void c(byte[] bArr, boolean z2) throws IOException {
        if (bArr.length < this.f3924d) {
            throw new IllegalArgumentException("buffer too small");
        }
        int iA = (!this.f3935j || z2) ? this.f3933h.a(bArr, 0, bArr.length) : this.f3933h.read(bArr, 0, 1024);
        if (bArr[0] != 5 && bArr[1] != 0) {
            throw new IOException("Unexpected DCERPC PDU header");
        }
        this.f3935j = (bArr[3] & 2) == 2;
        short sB = AbstractC0619b.b(bArr, 8);
        if (sB <= this.f3924d) {
            while (iA < sB) {
                iA += this.f3933h.a(bArr, iA, sB - iA);
            }
        } else {
            throw new IOException("Unexpected fragment length: " + ((int) sB));
        }
    }

    @Override // f1.AbstractC0469f
    protected void d(byte[] bArr, int i2, int i3, boolean z2) throws IOException {
        Z z3 = this.f3934i;
        if (z3 != null && !z3.isOpen()) {
            throw new IOException("DCERPC pipe is no longer open");
        }
        if (this.f3933h == null) {
            this.f3933h = (Y) this.f3932g.U();
        }
        if (this.f3934i == null) {
            this.f3934i = (Z) this.f3932g.V();
        }
        if (z2) {
            this.f3934i.b(bArr, i2, i3, 1);
        } else {
            this.f3934i.write(bArr, i2, i3);
        }
    }
}
