X-plore v4.37.09版本的 MD5 值为:1ac588cd7c13e9578c2d4266387e2f4f

以下内容为反编译后的 b.java 源代码,内容仅作参考


package L6;

import D3.dl.ysONN;
import F6.AbstractC1142k;
import F6.AbstractC1143l;
import F6.C;
import F6.C1141j;
import F6.C1145n;
import F7.C1160d;
import F7.w;
import F7.x;
import F7.z;
import P.AbstractC1363o;
import P.InterfaceC1357l;
import S4.oWw.yBiTelOWBwmsB;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import c8.HV.eTehUBU;
import com.google.firebase.remoteconfig.lE.PkPO;
import com.lonelycatgames.Xplore.App;
import com.lonelycatgames.Xplore.FileSystem.h;
import com.lonelycatgames.Xplore.compose.omp.bRSET;
import h7.AbstractC6736y;
import h7.C6709J;
import h7.C6730s;
import i7.AbstractC6838o;
import i7.AbstractC6839p;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.net.HttpURLConnection;
import java.security.GeneralSecurityException;
import java.security.Key;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.SecureRandom;
import java.security.spec.RSAPrivateKeySpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Set;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.SecretKeySpec;
import javax.net.ssl.SSLException;
import m8.hl.siskKbxSSIi;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import p3.KLvM.OJPcPhffzFBKVl;
import t6.C7377h;
import u6.AbstractC7556B;
import u6.F;
import v7.InterfaceC7625a;
import w7.AbstractC7771k;
import w7.AbstractC7777q;
import w7.AbstractC7780t;
import w7.AbstractC7781u;
import z.InterfaceC7946a;
import z6.AbstractC7990b;
import z6.AbstractC7992d;
import z6.C7989a;

public final class b extends AbstractC7990b {

    public static final c f7261N0 = new c(null);

    public static final int f7262O0 = 8;

    private static final AbstractC7990b.C0993b f7263P0 = new a(AbstractC7556B.f55719d1, C0212b.f7284I);

    private static final IvParameterSpec f7264Q0 = new IvParameterSpec(new byte[16]);

    private final HashMap f7265A0;

    private final HashMap f7266B0;

    private String f7267C0;

    private String f7268D0;

    private SecretKeySpec f7269E0;

    private PrivateKey f7270F0;

    private String f7271G0;

    private String f7272H0;

    private byte[] f7273I0;

    private String f7274J0;

    private m f7275K0;

    private String f7276L0;

    private Integer f7277M0;

    private final Uri f7278v0;

    private final Cipher f7279w0;

    private final char[] f7280x0;

    private final k f7281y0;

    private final k f7282z0;

    public static final class a extends AbstractC7990b.C0993b {

        private final String f7283f;

        a(int i9, C0212b c0212b) {
            super(i9, "Mega.co.nz", c0212b, false, 8, null);
            this.f7283f = "Mega.nz";
        }

        @Override
        public String c() {
            return this.f7283f;
        }
    }

    class C0212b extends AbstractC7777q implements v7.p {

        public static final C0212b f7284I = new C0212b();

        C0212b() {
            super(2, b.class, "<init>", "<init>(Lcom/lonelycatgames/Xplore/FileSystem/net/CloudFileSystem;Landroid/net/Uri;)V", 0);
        }

        @Override
        public final b r(C7989a c7989a, Uri uri) {
            AbstractC7780t.f(c7989a, "p0");
            AbstractC7780t.f(uri, "p1");
            return new b(c7989a, uri);
        }
    }

    public static final class c {
        private c() {
        }

        public c(AbstractC7771k abstractC7771k) {
            this();
        }

        public final byte[] j(CharSequence charSequence) {
            return L6.a.f7258a.a(charSequence);
        }

        public final String k(byte[] bArr) {
            return l(bArr, bArr.length);
        }

        private final String l(byte[] bArr, int i9) {
            return L6.a.f7258a.b(bArr, 0, i9);
        }

        public final String m(int i9) {
            if (i9 == -11) {
                return "access denied";
            }
            int i10 = 0 & (-5);
            return i9 != -5 ? i9 != -2 ? i9 != -1 ? String.valueOf(i9) : "internal error" : "bad arguments" : "request failed";
        }

        public final int n(String str) {
            char U02;
            char X02;
            if (str.length() > 0) {
                U02 = z.U0(str);
                if (U02 == '[') {
                    X02 = z.X0(str);
                    if (X02 == ']') {
                        str = str.substring(1, str.length() - 1);
                        AbstractC7780t.e(str, "substring(...)");
                    }
                }
            }
            return Integer.parseInt(str);
        }

        public final boolean p(CharSequence charSequence) {
            int i9;
            if (charSequence.length() == 0) {
                return false;
            }
            int length = charSequence.length();
            if (charSequence.charAt(0) != '[') {
                i9 = 0;
            } else {
                if (length == 1) {
                    return false;
                }
                i9 = 1;
            }
            int i10 = i9;
            if (charSequence.charAt(i9) == '-' && length == (i9 = i9 + 1)) {
                return false;
            }
            while (i9 < length) {
                char charAt = charSequence.charAt(i9);
                if (AbstractC7780t.g(charAt, 48) >= 0 && AbstractC7780t.g(charAt, 57) <= 0) {
                    i9++;
                }
                return i10 != 0 && charAt == ']';
            }
            return true;
        }

        public final boolean q(String str) {
            return AbstractC7780t.a(str, "[0]");
        }

        public final byte[] r(CharSequence charSequence) {
            int length = charSequence.length();
            int[] iArr = new int[(length + 3) / 4];
            for (int i9 = 0; i9 < length; i9++) {
                int i10 = i9 >> 2;
                iArr[i10] = Integer.reverseBytes(charSequence.charAt(i9) << (24 - ((i9 & 3) * 8))) | iArr[i10];
            }
            byte[] bArr = new byte[length];
            for (int i11 = 0; i11 < length; i11++) {
                bArr[i11] = (byte) (iArr[i11 / 4] >>> ((i11 & 3) * 8));
            }
            return bArr;
        }

        public final void s(byte[] bArr, byte[] bArr2) {
            for (int i9 = 0; i9 < 16; i9++) {
                bArr2[i9] = (byte) (bArr2[i9] ^ bArr[i9]);
            }
        }

        public final byte[] t(byte[] bArr) {
            byte[] bArr2 = new byte[16];
            for (int i9 = 0; i9 < 16; i9++) {
                bArr2[i9] = (byte) (bArr[i9] ^ bArr[i9 + 16]);
            }
            return bArr2;
        }

        public final AbstractC7990b.C0993b o() {
            return b.f7263P0;
        }
    }

    public final class d extends AbstractC7990b.e {

        private final i f7285E;

        private final File f7286F;

        private final h f7287G;

        private final C1141j f7288H;

        private final Long f7289I;

        private final ArrayList f7290J;

        final b f7291K;

        private final SecretKeySpec f7292e;

        public final class a extends CipherOutputStream {

            private long f7293E;

            private FileOutputStream f7294F;

            private int f7295G;

            final d f7296H;

            private final int f7297a;

            private final Cipher f7298b;

            private final byte[] f7299c;

            private e f7300d;

            private long f7301e;

            public a(d dVar, OutputStream outputStream, Cipher cipher) {
                super(outputStream, cipher);
                AbstractC7780t.f(outputStream, yBiTelOWBwmsB.CYusuSRxZAeVU);
                AbstractC7780t.f(cipher, "c");
                this.f7296H = dVar;
                this.f7297a = 131072;
                Cipher cipher2 = Cipher.getInstance("AES/CBC/NOPADDING");
                cipher2.init(1, dVar.l(), b.f7264Q0);
                this.f7298b = cipher2;
                this.f7299c = new byte[16];
                if (dVar.v() != null) {
                    try {
                        this.f7294F = new FileOutputStream(dVar.v());
                    } catch (FileNotFoundException e9) {
                        e9.printStackTrace();
                    }
                }
            }

            private final void b() {
                try {
                    i(this.f7299c, 0, this.f7295G);
                    this.f7295G = 0;
                } catch (Exception e9) {
                    IOException iOException = e9 instanceof IOException ? (IOException) e9 : null;
                    if (iOException == null) {
                        iOException = new IOException(t6.k.Q(e9));
                    }
                    throw iOException;
                }
            }

            private final long d() {
                long j9 = 0;
                int i9 = 1;
                while (i9 < 9) {
                    long j10 = (this.f7297a * i9) + j9;
                    long j11 = this.f7301e;
                    if (j9 <= j11 && j11 < j10) {
                        return j10;
                    }
                    i9++;
                    j9 = j10;
                }
                return ((this.f7301e - j9) & (this.f7297a * (-8))) + j9 + (r4 * 8);
            }

            private final void f() {
                this.f7300d = new e(this.f7296H.k().e());
                ArrayList s9 = this.f7296H.s();
                e eVar = this.f7300d;
                if (eVar == null) {
                    AbstractC7780t.r("mac");
                    eVar = null;
                    int i9 = 7 & 0;
                }
                s9.add(eVar);
                this.f7293E = d();
            }

            private final void h(byte[] bArr, int i9, int i10) {
                int i11 = 1 << 0;
                if ((i10 & 15) != 0) {
                    Arrays.fill(bArr, i10, 16, (byte) 0);
                }
                e eVar = this.f7300d;
                if (eVar == null) {
                    AbstractC7780t.r("mac");
                    eVar = null;
                }
                byte[] a9 = eVar.a();
                for (int i12 = 0; i12 < i10; i12 += 16) {
                    for (int i13 = 0; i13 < 16; i13++) {
                        a9[i13] = (byte) (a9[i13] ^ bArr[(i9 + i12) + i13]);
                    }
                    this.f7298b.doFinal(a9, 0, 16, a9);
                }
                super.write(bArr, i9, i10);
                this.f7301e += i10;
            }

            private final void i(byte[] bArr, int i9, int i10) {
                while (true) {
                    long j9 = this.f7301e;
                    long j10 = i10 + j9;
                    long j11 = this.f7293E;
                    if (j10 <= j11) {
                        break;
                    }
                    int i11 = (int) (j11 - j9);
                    if (i11 > 0) {
                        h(bArr, i9, i11);
                        i9 += i11;
                        i10 -= i11;
                    }
                    f();
                }
                if (i10 > 0) {
                    h(bArr, i9, i10);
                }
            }

            @Override
            public void close() {
                super.close();
                FileOutputStream fileOutputStream = this.f7294F;
                if (fileOutputStream != null) {
                    fileOutputStream.close();
                }
            }

            @Override
            public void flush() {
                if (this.f7295G > 0) {
                    b();
                }
            }

            @Override
            public void write(byte[] bArr, int i9, int i10) {
                int i11;
                AbstractC7780t.f(bArr, "b");
                FileOutputStream fileOutputStream = this.f7294F;
                if (fileOutputStream != null) {
                    fileOutputStream.write(bArr, i9, i10);
                }
                if (this.f7295G > 0) {
                    while (true) {
                        i11 = this.f7295G;
                        if (i11 >= 16 || i10 <= 0) {
                            break;
                        }
                        byte[] bArr2 = this.f7299c;
                        this.f7295G = i11 + 1;
                        bArr2[i11] = bArr[i9];
                        i10--;
                        i9++;
                    }
                    if (i11 == 16) {
                        b();
                    }
                }
                if ((i10 & 15) != 0) {
                    int i12 = i10 & (-16);
                    int i13 = i10 - i12;
                    this.f7295G = i13;
                    System.arraycopy(bArr, i9 + i12, this.f7299c, 0, i13);
                    if (i12 == 0) {
                        return;
                    } else {
                        i10 = i12;
                    }
                }
                if (i10 > 0) {
                    try {
                        i(bArr, i9, i10);
                    } catch (Exception e9) {
                        IOException iOException = e9 instanceof IOException ? (IOException) e9 : null;
                        if (iOException == null) {
                            iOException = new IOException(t6.k.Q(e9));
                        }
                        throw iOException;
                    }
                }
            }
        }

        public d(b bVar, HttpURLConnection httpURLConnection, SecretKeySpec secretKeySpec, i iVar, File file, h hVar, C1141j c1141j, Long l9) {
            super(bVar, httpURLConnection);
            AbstractC7780t.f(httpURLConnection, "con");
            AbstractC7780t.f(secretKeySpec, "fileEncKey");
            AbstractC7780t.f(iVar, "f");
            AbstractC7780t.f(hVar, "megaParent");
            this.f7291K = bVar;
            this.f7292e = secretKeySpec;
            this.f7285E = iVar;
            this.f7286F = file;
            this.f7287G = hVar;
            this.f7288H = c1141j;
            this.f7289I = l9;
            this.f7290J = new ArrayList();
        }

        private final byte[] j(File file) {
            int i9;
            int i10;
            int i11;
            BitmapFactory.Options options = new BitmapFactory.Options();
            FileInputStream fileInputStream = new FileInputStream(file);
            int i12 = 4 ^ 1;
            try {
                options.inJustDecodeBounds = true;
                BitmapFactory.decodeStream(fileInputStream, null, options);
                t7.c.a(fileInputStream, null);
                options.inPreferredConfig = Bitmap.Config.ARGB_8888;
                options.inSampleSize = 1;
                while (true) {
                    int i13 = options.outWidth;
                    if (i13 < 240 || (i11 = options.outHeight) < 240) {
                        break;
                    }
                    options.outWidth = i13 >> 1;
                    options.outHeight = i11 >> 1;
                    options.inSampleSize <<= 1;
                }
                options.inJustDecodeBounds = false;
                FileInputStream fileInputStream2 = new FileInputStream(file);
                try {
                    Bitmap decodeStream = BitmapFactory.decodeStream(fileInputStream2, null, options);
                    if (decodeStream == null) {
                        throw new FileNotFoundException();
                    }
                    AbstractC7780t.c(decodeStream);
                    int width = decodeStream.getWidth();
                    int height = decodeStream.getHeight();
                    if (width > 120 || height > 120) {
                        if (width != height) {
                            if (width > height) {
                                i10 = (width - height) / 2;
                                i9 = 0;
                            } else {
                                i9 = (height - width) / 2;
                                height = width;
                                i10 = 0;
                            }
                            Bitmap createBitmap = Bitmap.createBitmap(decodeStream, i10, i9, height, height);
                            AbstractC7780t.e(createBitmap, "createBitmap(...)");
                            decodeStream.recycle();
                            width = createBitmap.getWidth();
                            decodeStream = createBitmap;
                        }
                        if (width > 120) {
                            Bitmap createScaledBitmap = Bitmap.createScaledBitmap(decodeStream, 120, 120, true);
                            AbstractC7780t.e(createScaledBitmap, PkPO.bEphdPHzAbmo);
                            decodeStream.recycle();
                            decodeStream = createScaledBitmap;
                        }
                    }
                    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(8192);
                    decodeStream.compress(decodeStream.hasAlpha() ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG, 90, byteArrayOutputStream);
                    decodeStream.recycle();
                    while ((byteArrayOutputStream.size() & 15) != 0) {
                        byteArrayOutputStream.write(0);
                    }
                    byte[] byteArray = byteArrayOutputStream.toByteArray();
                    t7.c.a(fileInputStream2, null);
                    AbstractC7780t.e(byteArray, "use(...)");
                    return byteArray;
                } finally {
                }
            } catch (Throwable th) {
                try {
                    throw th;
                } catch (Throwable th2) {
                    t7.c.a(fileInputStream, th);
                    throw th2;
                }
            }
        }

        @Override
        public void f(int i9) {
            byte[] bArr;
            Iterator it;
            C7989a.b bVar;
            Set E8;
            ?? r22;
            byte[] byteArray;
            super.f(i9);
            InputStream inputStream = b().getInputStream();
            try {
                AbstractC7780t.c(inputStream);
                String o02 = t6.k.o0(inputStream);
                t7.c.a(inputStream, null);
                c cVar = b.f7261N0;
                if (cVar.p(o02)) {
                    throw new IOException("API err: " + cVar.m(cVar.n(o02)));
                }
                if (o02.length() != 36) {
                    throw new IOException("Invalid handle: " + o02);
                }
                b().disconnect();
                this.f7285E.l(o02);
                try {
                    System.arraycopy(w(), 0, this.f7285E.e(), 24, 8);
                    System.arraycopy(cVar.t(this.f7285E.e()), 0, this.f7285E.e(), 0, 16);
                    File file = this.f7286F;
                    if (file != null) {
                        b bVar2 = this.f7291K;
                        try {
                            byte[] T32 = bVar2.T3(this.f7285E.f(), j(file));
                            try {
                                r22 = bVar2.Q2("POST", b.X3(bVar2, t6.k.c0(AbstractC6736y.a("a", "ufa"), AbstractC6736y.a("s", String.valueOf(T32.length))), false, 2, null).optString("p") + '/');
                                try {
                                    r22.setDoOutput(true);
                                    r22.setFixedLengthStreamingMode(T32.length);
                                    OutputStream outputStream = r22.getOutputStream();
                                    AbstractC7780t.e(outputStream, "getOutputStream(...)");
                                    t6.k.O0(outputStream, T32);
                                    InputStream inputStream2 = r22.getInputStream();
                                    try {
                                        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                                        AbstractC7780t.c(inputStream2);
                                        t7.b.b(inputStream2, byteArrayOutputStream, 0, 2, null);
                                        byteArray = byteArrayOutputStream.toByteArray();
                                    } catch (Throwable th) {
                                        th = th;
                                        r22 = 0;
                                    }
                                    try {
                                        C6709J c6709j = C6709J.f49946a;
                                        t7.c.a(inputStream2, null);
                                        bArr = byteArray;
                                    } catch (Throwable th2) {
                                        th = th2;
                                        r22 = byteArray;
                                        try {
                                            throw th;
                                        } catch (Throwable th3) {
                                            t7.c.a(inputStream2, th);
                                            throw th3;
                                        }
                                    }
                                } catch (Exception e9) {
                                    e = e9;
                                    e.printStackTrace();
                                    bArr = r22;
                                    JSONObject Y32 = this.f7291K.Y3(this.f7285E);
                                    if (bArr != null) {
                                    }
                                    b.X3(this.f7291K, Y32, false, 2, null);
                                    it = this.f7287G.p().values().iterator();
                                    while (true) {
                                        if (it.hasNext()) {
                                        }
                                    }
                                    bVar = (C7989a.b) this.f7288H;
                                    if (bVar != null) {
                                        E8.add(this.f7285E.g());
                                    }
                                    this.f7291K.r3();
                                    this.f7291K.t4();
                                }
                            } catch (h.d e10) {
                                throw new IOException(e10.getMessage());
                            }
                        } catch (Exception e11) {
                            e = e11;
                            r22 = 0;
                        }
                    } else {
                        bArr = null;
                    }
                    JSONObject Y322 = this.f7291K.Y3(this.f7285E);
                    if (bArr != null) {
                        Y322.getJSONArray("n").getJSONObject(0).put("fa", "0*" + b.f7261N0.k(bArr));
                    }
                    b.X3(this.f7291K, Y322, false, 2, null);
                    it = this.f7287G.p().values().iterator();
                    while (true) {
                        if (it.hasNext()) {
                            break;
                        }
                        j jVar = (j) it.next();
                        if (AbstractC7780t.a(jVar.g(), this.f7285E.g())) {
                            b bVar3 = this.f7291K;
                            AbstractC7780t.c(jVar);
                            bVar3.b4(jVar);
                            break;
                        }
                    }
                    bVar = (C7989a.b) this.f7288H;
                    if (bVar != null && (E8 = bVar.E()) != null) {
                        E8.add(this.f7285E.g());
                    }
                    this.f7291K.r3();
                    this.f7291K.t4();
                } catch (Exception e12) {
                    throw new IOException(e12);
                }
            } finally {
            }
        }

        @Override
        public void i() {
            byte[] bArr = new byte[16];
            System.arraycopy(this.f7285E.e(), 16, bArr, 0, 8);
            IvParameterSpec ivParameterSpec = new IvParameterSpec(bArr);
            Cipher cipher = Cipher.getInstance("AES/CTR/NOPADDING");
            cipher.init(1, this.f7292e, ivParameterSpec);
            OutputStream outputStream = b().getOutputStream();
            AbstractC7780t.e(outputStream, eTehUBU.rCI);
            AbstractC7780t.c(cipher);
            h(new a(this, outputStream, cipher));
        }

        public final i k() {
            return this.f7285E;
        }

        public final SecretKeySpec l() {
            return this.f7292e;
        }

        public final ArrayList s() {
            return this.f7290J;
        }

        public final File v() {
            return this.f7286F;
        }

        public final byte[] w() {
            byte[] bArr = new byte[16];
            Iterator it = this.f7290J.iterator();
            while (it.hasNext()) {
                b.f7261N0.s(((e) it.next()).a(), bArr);
                bArr = this.f7291K.Q3(this.f7292e, bArr);
            }
            for (int i9 = 0; i9 < 4; i9++) {
                int i10 = i9 + 4;
                bArr[i9] = (byte) (bArr[i9] ^ bArr[i10]);
                bArr[i10] = (byte) (bArr[i9 + 8] ^ bArr[i9 + 12]);
            }
            return bArr;
        }
    }

    public static final class e {

        private final byte[] f7302a;

        public e(byte[] bArr) {
            AbstractC7780t.f(bArr, "fileKey");
            byte[] bArr2 = new byte[16];
            this.f7302a = bArr2;
            AbstractC6838o.d(bArr, bArr2, 0, 16, 24);
            AbstractC6838o.d(bArr, bArr2, 8, 16, 24);
            System.arraycopy(bArr, 16, bArr2, 0, 8);
            System.arraycopy(bArr, 16, bArr2, 8, 8);
        }

        public final byte[] a() {
            return this.f7302a;
        }
    }

    private static final class f extends CipherInputStream {
        public f(InputStream inputStream, Cipher cipher) {
            super(inputStream, cipher);
            AbstractC7780t.f(inputStream, "s");
            AbstractC7780t.f(cipher, "c");
        }

        @Override
        public long skip(long j9) {
            long skip = super.skip(j9);
            if (skip == 0 && read() != -1) {
                skip = 1;
            }
            return skip;
        }
    }

    public static final class g extends m {
        public g(o oVar) {
            super(-2);
            AbstractC7780t.f(oVar, "user");
            n(oVar.a());
            l("__u:" + oVar.b());
        }
    }

    public static class h extends j {

        private final k f7303h;

        public h(h hVar) {
            super(hVar);
            this.f7303h = new k();
        }

        protected h(h hVar, JSONObject jSONObject) {
            super(hVar, jSONObject);
            AbstractC7780t.f(jSONObject, "js");
            this.f7303h = new k();
        }

        public h(b bVar, h hVar, JSONObject jSONObject, Key key) {
            super(hVar, jSONObject);
            AbstractC7780t.f(bVar, "svr");
            AbstractC7780t.f(hVar, "parent");
            AbstractC7780t.f(jSONObject, "js");
            AbstractC7780t.f(key, "masterKey");
            this.f7303h = new k();
            b(bVar, jSONObject, key);
        }

        @Override
        public byte[] f() {
            return e();
        }

        public final k p() {
            return this.f7303h;
        }
    }

    public static final class i extends j {

        private long f7304h;

        private String f7305i;

        public i(h hVar) {
            super(hVar);
            AbstractC7780t.f(hVar, ysONN.PVMDcYSthYQEX);
        }

        public i(b bVar, h hVar, JSONObject jSONObject, Key key) {
            super(hVar, jSONObject);
            int U8;
            AbstractC7780t.f(bVar, "svr");
            AbstractC7780t.f(hVar, "parent");
            AbstractC7780t.f(jSONObject, "js");
            AbstractC7780t.f(key, "masterKey");
            this.f7304h = jSONObject.optLong("s", -1L);
            b(bVar, jSONObject, key);
            String optString = jSONObject.optString("fa");
            AbstractC7780t.c(optString);
            if (optString.length() <= 0 || U8 == -1) {
                return;
            }
            String substring = optString.substring(U8 + 1);
            AbstractC7780t.e(substring, "substring(...)");
            this.f7305i = substring;
        }

        @Override
        public byte[] f() {
            return b.f7261N0.t(e());
        }

        public final Cipher p(int i9, long j9) {
            byte[] bArr = new byte[16];
            System.arraycopy(e(), 16, bArr, 0, 8);
            if (j9 != 0) {
                for (int i10 = 0; i10 < 8; i10++) {
                    bArr[i10 + 8] = (byte) ((j9 >> (56 - (i10 * 8))) & 255);
                }
            }
            IvParameterSpec ivParameterSpec = new IvParameterSpec(bArr);
            SecretKeySpec secretKeySpec = new SecretKeySpec(f(), "AES");
            Cipher cipher = Cipher.getInstance("AES/CTR/NOPADDING");
            cipher.init(i9, secretKeySpec, ivParameterSpec);
            AbstractC7780t.c(cipher);
            return cipher;
        }

        public final long q() {
            return this.f7304h;
        }
    }

    public static abstract class j {

        public static final a f7306g = new a(null);

        private final h f7307a;

        private String f7308b;

        private String f7309c;

        private byte[] f7310d;

        private long f7311e;

        private int f7312f;

        public static final class a {
            private a() {
            }

            public a(AbstractC7771k abstractC7771k) {
                this();
            }
        }

        public j(h hVar) {
            this.f7307a = hVar;
            this.f7308b = "";
            this.f7309c = "";
            this.f7310d = new byte[0];
        }

        public j(h hVar, JSONObject jSONObject) {
            this(hVar);
            AbstractC7780t.f(jSONObject, "js");
            String string = jSONObject.getString("h");
            AbstractC7780t.e(string, "getString(...)");
            this.f7309c = string;
            this.f7311e = jSONObject.optLong("ts") * 1000;
        }

        protected final void a(b bVar, JSONObject jSONObject, CharSequence charSequence, Key key) {
            int U8;
            Key key2;
            int U9;
            l j9;
            int h02;
            boolean D8;
            Key key3 = key;
            AbstractC7780t.f(bVar, "svr");
            AbstractC7780t.f(jSONObject, "js");
            AbstractC7780t.f(charSequence, "a");
            AbstractC7780t.f(key3, "masterKey");
            String string = jSONObject.getString("k");
            AbstractC7780t.e(string, "element");
            if (string.length() <= 0) {
                throw new IllegalStateException("Check failed.".toString());
            }
            c cVar = b.f7261N0;
            byte[] j10 = cVar.j(charSequence);
            String optString = jSONObject.optString("sk");
            String str = optString.length() > 0 ? optString : null;
            AbstractC7780t.e(string, "element");
            U8 = x.U(string, ':', 0, false, 6, null);
            if (U8 != -1) {
                AbstractC7780t.e(string, "element");
                String substring = string.substring(0, U8);
                AbstractC7780t.e(substring, "substring(...)");
                AbstractC7780t.e(string, "element");
                string = string.substring(U8 + 1);
                AbstractC7780t.e(string, "substring(...)");
                if (str == null) {
                    Object obj = bVar.f7266B0.get(substring);
                    key2 = obj;
                    if (obj == 0) {
                        Object obj2 = bVar.f7282z0.get(substring);
                        l lVar = obj2 instanceof l ? (l) obj2 : null;
                        if (lVar != null) {
                            key2 = lVar.r();
                        }
                    } else if (obj != key3) {
                        this.f7312f = 1;
                        key2 = obj;
                    }
                    AbstractC7780t.e(string, "element");
                    U9 = x.U(string, '/', 0, false, 6, null);
                    if (U9 == -1) {
                        string = string.substring(0, U9);
                        AbstractC7780t.e(string, "substring(...)");
                    } else {
                        if (str != null) {
                            this.f7312f = 2;
                        }
                        if (str != null && (this instanceof l)) {
                            byte[] j11 = cVar.j(str);
                            key2 = new SecretKeySpec(j11.length > 32 ? bVar.Z3(j11, 16) : bVar.N3(key3, j11), "AES");
                            ((l) this).s(key2);
                        } else if (key2 == null && (j9 = j()) != null) {
                            if (!AbstractC7780t.a(bVar.f7276L0, jSONObject.optString("u"))) {
                                key2 = j9.r();
                            }
                        }
                    }
                    if (key2 != null) {
                        key3 = key2;
                    }
                    AbstractC7780t.e(string, "element");
                    this.f7310d = bVar.a4(key3, cVar.j(string));
                    byte[] P32 = bVar.P3(f(), j10);
                    h02 = AbstractC6839p.h0(P32, (byte) 0);
                    if (h02 == -1) {
                        h02 = P32.length;
                    }
                    String str2 = new String(P32, 0, h02, C1160d.f4033b);
                    D8 = w.D(str2, "MEGA", false, 2, null);
                    if (D8) {
                        String substring2 = str2.substring(4);
                        AbstractC7780t.e(substring2, "substring(...)");
                        str2 = new JSONObject(substring2).getString("n");
                        AbstractC7780t.c(str2);
                    }
                    this.f7308b = str2;
                }
            }
            key2 = null;
            AbstractC7780t.e(string, "element");
            U9 = x.U(string, '/', 0, false, 6, null);
            if (U9 == -1) {
            }
            if (key2 != null) {
            }
            AbstractC7780t.e(string, "element");
            this.f7310d = bVar.a4(key3, cVar.j(string));
            byte[] P322 = bVar.P3(f(), j10);
            h02 = AbstractC6839p.h0(P322, (byte) 0);
            if (h02 == -1) {
            }
            String str22 = new String(P322, 0, h02, C1160d.f4033b);
            D8 = w.D(str22, "MEGA", false, 2, null);
            if (D8) {
            }
            this.f7308b = str22;
        }

        protected final void b(b bVar, JSONObject jSONObject, Key key) {
            AbstractC7780t.f(bVar, "svr");
            AbstractC7780t.f(jSONObject, "js");
            AbstractC7780t.f(key, "masterKey");
            String string = jSONObject.getString("a");
            AbstractC7780t.c(string);
            a(bVar, jSONObject, string, key);
        }

        public final long c() {
            return this.f7311e;
        }

        public final String d() {
            return this.f7309c;
        }

        public final byte[] e() {
            return this.f7310d;
        }

        public abstract byte[] f();

        public final String g() {
            return this.f7308b;
        }

        public final h h() {
            return this.f7307a;
        }

        public final int i() {
            return this.f7312f;
        }

        public l j() {
            h hVar = this.f7307a;
            return hVar != null ? hVar.j() : null;
        }

        public final void k(long j9) {
            this.f7311e = j9;
        }

        public final void l(String str) {
            AbstractC7780t.f(str, "<set-?>");
            this.f7309c = str;
        }

        public final void m(byte[] bArr) {
            AbstractC7780t.f(bArr, "<set-?>");
            this.f7310d = bArr;
        }

        public final void n(String str) {
            AbstractC7780t.f(str, "<set-?>");
            this.f7308b = str;
        }

        public final void o(b bVar, JSONObject jSONObject, Key key) {
            AbstractC7780t.f(bVar, "svr");
            AbstractC7780t.f(jSONObject, "js");
            AbstractC7780t.f(key, "masterKey");
            String string = jSONObject.getString("at");
            AbstractC7780t.c(string);
            a(bVar, jSONObject, string, key);
        }

        public String toString() {
            return this.f7308b;
        }
    }

    public static final class k extends HashMap {
        public boolean a(String str) {
            return super.containsKey(str);
        }

        public boolean b(j jVar) {
            return super.containsValue(jVar);
        }

        public j c(String str) {
            return (j) super.get(str);
        }

        @Override
        public final boolean containsKey(Object obj) {
            if (obj == null || (obj instanceof String)) {
                return a((String) obj);
            }
            return false;
        }

        @Override
        public final boolean containsValue(Object obj) {
            if (obj instanceof j) {
                return b((j) obj);
            }
            return false;
        }

        public Set e() {
            return super.entrySet();
        }

        @Override
        public final Set entrySet() {
            return e();
        }

        public Set f() {
            return super.keySet();
        }

        @Override
        public final Object get(Object obj) {
            if (obj != null && !(obj instanceof String)) {
                return null;
            }
            return c((String) obj);
        }

        @Override
        public final Object getOrDefault(Object obj, Object obj2) {
            if (obj != null && !(obj instanceof String)) {
                return obj2;
            }
            return h((String) obj, (j) obj2);
        }

        public j h(String str, j jVar) {
            return (j) super.getOrDefault(str, jVar);
        }

        public int j() {
            return super.size();
        }

        public Collection k() {
            return super.values();
        }

        @Override
        public final Set keySet() {
            return f();
        }

        public j m(String str) {
            return (j) super.remove(str);
        }

        public boolean o(String str, j jVar) {
            return super.remove(str, jVar);
        }

        @Override
        public final Object remove(Object obj) {
            if (obj != null && !(obj instanceof String)) {
                return null;
            }
            return m((String) obj);
        }

        @Override
        public final boolean remove(Object obj, Object obj2) {
            if (obj != null && !(obj instanceof String)) {
                return false;
            }
            if (obj2 instanceof j) {
                return o((String) obj, (j) obj2);
            }
            return false;
        }

        @Override
        public final int size() {
            return j();
        }

        @Override
        public final Collection values() {
            return k();
        }
    }

    public static final class l extends h {

        private final int f7313i;

        private Key f7314j;

        public l(b bVar, h hVar, JSONObject jSONObject, Key key) {
            super(bVar, hVar, jSONObject, key);
            AbstractC7780t.f(bVar, "svr");
            AbstractC7780t.f(hVar, "parent");
            AbstractC7780t.f(jSONObject, "js");
            AbstractC7780t.f(key, "masterKey");
            this.f7313i = jSONObject.optInt("r", -1);
        }

        @Override
        public l j() {
            return this;
        }

        public final int q() {
            return this.f7313i;
        }

        public final Key r() {
            return this.f7314j;
        }

        public final void s(Key key) {
            this.f7314j = key;
        }
    }

    public static class m extends h {

        private final int f7315i;

        public m(int i9) {
            super(null);
            this.f7315i = i9;
        }

        public m(Context context, JSONObject jSONObject, int i9) {
            super(null, jSONObject);
            AbstractC7780t.f(context, "ctx");
            AbstractC7780t.f(jSONObject, "js");
            this.f7315i = i9;
            if (i9 == 2) {
                String string = context.getString(F.f56461q2);
                AbstractC7780t.e(string, "getString(...)");
                n(string);
            } else {
                if (i9 != 4) {
                    return;
                }
                String string2 = context.getString(F.f56481s2);
                AbstractC7780t.e(string2, "getString(...)");
                n(string2);
            }
        }

        public final int q() {
            return this.f7315i;
        }
    }

    public static final class n extends Exception {
    }

    public static final class o {

        public static final a f7316d = new a(null);

        private final int f7317a;

        private final String f7318b;

        private final String f7319c;

        public static final class a {
            private a() {
            }

            public a(AbstractC7771k abstractC7771k) {
                this();
            }
        }

        public o(int i9, String str, String str2) {
            AbstractC7780t.f(str, "uid");
            AbstractC7780t.f(str2, "email");
            this.f7317a = i9;
            this.f7318b = str;
            this.f7319c = str2;
        }

        public o(JSONObject jSONObject) {
            this(r0, r1, r5);
            AbstractC7780t.f(jSONObject, "js");
            int i9 = jSONObject.getInt("c");
            String string = jSONObject.getString("u");
            AbstractC7780t.e(string, "getString(...)");
            String string2 = jSONObject.getString("m");
            AbstractC7780t.e(string2, "getString(...)");
        }

        public final String a() {
            return this.f7319c;
        }

        public final String b() {
            return this.f7318b;
        }

        public final int c() {
            return this.f7317a;
        }

        public String toString() {
            return this.f7319c;
        }
    }

    public static final class p extends AbstractC7781u implements InterfaceC7625a {
        p() {
            super(0);
        }

        public final void a() {
            b.this.V().B2("First login to Mega takes longer, please wait.", true);
        }

        @Override
        public Object c() {
            a();
            return C6709J.f49946a;
        }
    }

    public static final class q extends AbstractC7992d.b {

        final j f7321j0;

        q(b bVar, j jVar, String str) {
            super(bVar, str, 0L, null, 12, null);
            this.f7321j0 = jVar;
        }

        @Override
        public Object clone() {
            return super.clone();
        }

        @Override
        public void k1(InterfaceC7946a interfaceC7946a, b0.g gVar, InterfaceC1357l interfaceC1357l, int i9) {
            AbstractC7780t.f(interfaceC7946a, "<this>");
            AbstractC7780t.f(gVar, "modifier");
            interfaceC1357l.e(1795263648);
            if (AbstractC1363o.G()) {
                AbstractC1363o.S(1795263648, i9, -1, "com.lonelycatgames.Xplore.clouds.mega.MegaCoServer.listDir.<no name provided>.DrawIconOverlay (MegaCoServer.kt:1237)");
            }
            if (this.f7321j0 instanceof m) {
                interfaceC1357l.e(-44733834);
                int q9 = ((m) this.f7321j0).q();
                if (q9 == -2) {
                    interfaceC1357l.e(-44733622);
                    AbstractC1142k.f(interfaceC7946a, gVar, interfaceC1357l, (i9 & 112) | (i9 & 14));
                    interfaceC1357l.M();
                } else if (q9 != 4) {
                    interfaceC1357l.e(-44733559);
                    interfaceC1357l.M();
                } else {
                    interfaceC1357l.e(-44733718);
                    AbstractC1142k.e(interfaceC7946a, gVar, interfaceC1357l, (i9 & 112) | (i9 & 14));
                    interfaceC1357l.M();
                }
                interfaceC1357l.M();
            } else {
                interfaceC1357l.e(-44733525);
                int i10 = this.f7321j0.i();
                if (i10 == 1) {
                    interfaceC1357l.e(-44733314);
                    AbstractC1142k.f(interfaceC7946a, gVar, interfaceC1357l, (i9 & 112) | (i9 & 14));
                    interfaceC1357l.M();
                } else if (i10 != 2) {
                    interfaceC1357l.e(-44733251);
                    interfaceC1357l.M();
                } else {
                    interfaceC1357l.e(-44733408);
                    AbstractC1142k.c(interfaceC7946a, gVar, interfaceC1357l, (i9 & 112) | (i9 & 14));
                    interfaceC1357l.M();
                }
                interfaceC1357l.M();
            }
            if (AbstractC1363o.G()) {
                AbstractC1363o.R();
            }
            interfaceC1357l.M();
        }
    }

    public static final class r extends AbstractC7781u implements InterfaceC7625a {

        final Uri f7323c;

        final String f7324d;

        r(Uri uri, String str) {
            super(0);
            this.f7323c = uri;
            this.f7324d = str;
        }

        public final void a() {
            b.this.t2(this.f7323c.buildUpon().fragment(this.f7324d).build());
        }

        @Override
        public Object c() {
            a();
            return C6709J.f49946a;
        }
    }

    public static final class s extends AbstractC7781u implements InterfaceC7625a {

        final String f7325E;

        final String f7326b;

        final String f7327c;

        final byte[] f7328d;

        final b f7329e;

        s(String str, String str2, byte[] bArr, b bVar, String str3) {
            super(0);
            this.f7326b = str;
            this.f7327c = str2;
            this.f7328d = bArr;
            this.f7329e = bVar;
            this.f7325E = str3;
        }

        public final void a() {
            String str = this.f7326b;
            if (this.f7327c != null && this.f7328d != null) {
                str = str + '\n' + this.f7327c + '\n' + b.f7261N0.k(this.f7328d);
            }
            b.super.x2(this.f7325E, str);
            this.f7329e.f7267C0 = this.f7325E;
            this.f7329e.f7268D0 = this.f7326b;
            this.f7329e.f7273I0 = this.f7328d;
            this.f7329e.f7274J0 = this.f7327c;
        }

        @Override
        public Object c() {
            a();
            return C6709J.f49946a;
        }
    }

    public b(C7989a c7989a, Uri uri) {
        super(c7989a, AbstractC7556B.f55719d1, null, 4, null);
        AbstractC7780t.f(c7989a, "fs");
        AbstractC7780t.f(uri, "uri");
        this.f7278v0 = Uri.parse("https://g.api.mega.co.nz");
        this.f7279w0 = Cipher.getInstance("AES/CBC/NOPADDING");
        char[] cArr = new char[10];
        for (int i9 = 0; i9 < 10; i9++) {
            cArr[i9] = (char) (A7.c.f419a.c(26) + 97);
        }
        this.f7280x0 = cArr;
        this.f7281y0 = new k();
        this.f7282z0 = new k();
        this.f7265A0 = new HashMap();
        this.f7266B0 = new HashMap();
        t2(uri);
    }

    private final void L3(JSONObject jSONObject) {
        h hVar;
        Object obj;
        k kVar;
        int i9 = jSONObject.getInt("t");
        String X8 = t6.k.X(jSONObject, "p");
        SecretKeySpec secretKeySpec = null;
        m mVar = null;
        SecretKeySpec secretKeySpec2 = null;
        SecretKeySpec secretKeySpec3 = null;
        if (X8 == null || X8.length() == 0) {
            hVar = null;
        } else {
            j jVar = (j) this.f7282z0.get(X8);
            if (jVar instanceof h) {
                hVar = (h) jVar;
            } else {
                if (i9 == 1) {
                    String optString = jSONObject.optString("u");
                    o oVar = (o) this.f7265A0.get(optString);
                    if (oVar != null) {
                        j jVar2 = (j) this.f7282z0.get("__u:" + oVar.b());
                        if (jVar2 instanceof h) {
                            h hVar2 = (h) jVar2;
                            r4 = AbstractC7780t.a(optString, this.f7276L0) ? false : true;
                            hVar = hVar2;
                            if (hVar == null) {
                                App.f43875F0.o("Can't find parent dir " + X8);
                                return;
                            }
                        }
                    }
                }
                hVar = null;
                if (hVar == null) {
                }
            }
        }
        try {
            if (i9 != 0) {
                if (i9 != 1) {
                    if (i9 == 2) {
                        mVar = new m(V(), jSONObject, i9);
                    } else if (i9 == 4) {
                        mVar = new m(V(), jSONObject, i9);
                        this.f7275K0 = mVar;
                    }
                    if (mVar == null) {
                        if (hVar == null || (kVar = hVar.p()) == null) {
                            kVar = this.f7281y0;
                        }
                        kVar.put(mVar.d(), mVar);
                        this.f7282z0.put(mVar.d(), mVar);
                        return;
                    }
                    return;
                }
                if (r4) {
                    if (hVar == null) {
                        throw new IllegalArgumentException("Required value was null.".toString());
                    }
                    SecretKeySpec secretKeySpec4 = this.f7269E0;
                    if (secretKeySpec4 == null) {
                        AbstractC7780t.r("masterKey");
                    } else {
                        secretKeySpec2 = secretKeySpec4;
                    }
                    obj = new l(this, hVar, jSONObject, secretKeySpec2);
                } else {
                    if (hVar == null) {
                        throw new IllegalArgumentException("Required value was null.".toString());
                    }
                    SecretKeySpec secretKeySpec5 = this.f7269E0;
                    if (secretKeySpec5 == null) {
                        AbstractC7780t.r("masterKey");
                    } else {
                        secretKeySpec3 = secretKeySpec5;
                    }
                    obj = new h(this, hVar, jSONObject, secretKeySpec3);
                }
            } else {
                if (hVar == null) {
                    throw new IllegalArgumentException("Required value was null.".toString());
                }
                SecretKeySpec secretKeySpec6 = this.f7269E0;
                if (secretKeySpec6 == null) {
                    AbstractC7780t.r("masterKey");
                } else {
                    secretKeySpec = secretKeySpec6;
                }
                obj = new i(this, hVar, jSONObject, secretKeySpec);
            }
            mVar = obj;
            if (mVar == null) {
            }
        } catch (Exception e9) {
            App.f43875F0.v("Mega err: " + t6.k.Q(e9));
        }
    }

    private final void M3(JSONArray jSONArray) {
        int length = jSONArray.length();
        for (int i9 = 0; i9 < length; i9++) {
            L3((JSONObject) jSONArray.get(i9));
        }
    }

    public final byte[] N3(Key key, byte[] bArr) {
        return O3(key, bArr, 0, bArr.length);
    }

    private final byte[] O3(Key key, byte[] bArr, int i9, int i10) {
        byte[] doFinal;
        if ((i10 & 15) != 0) {
            throw new IllegalStateException("Check failed.".toString());
        }
        Cipher cipher = this.f7279w0;
        AbstractC7780t.e(cipher, "cipherAesCbc");
        synchronized (cipher) {
            this.f7279w0.init(2, key, f7264Q0);
            doFinal = this.f7279w0.doFinal(bArr, i9, i10);
        }
        AbstractC7780t.e(doFinal, "synchronized(...)");
        return doFinal;
    }

    public final byte[] P3(byte[] bArr, byte[] bArr2) {
        return N3(new SecretKeySpec(bArr, "AES"), bArr2);
    }

    public final byte[] Q3(Key key, byte[] bArr) {
        return R3(key, bArr, 0, bArr.length);
    }

    private final byte[] R3(Key key, byte[] bArr, int i9, int i10) {
        byte[] doFinal;
        if ((i10 & 15) != 0) {
            int i11 = (i10 + 15) & (-16);
            byte[] bArr2 = new byte[i11];
            System.arraycopy(bArr, i9, bArr2, 0, i10);
            i10 = i11;
            bArr = bArr2;
            i9 = 0;
        }
        Cipher cipher = this.f7279w0;
        AbstractC7780t.e(cipher, "cipherAesCbc");
        synchronized (cipher) {
            this.f7279w0.init(1, key, f7264Q0);
            doFinal = this.f7279w0.doFinal(bArr, i9, i10);
        }
        AbstractC7780t.e(doFinal, "synchronized(...)");
        return doFinal;
    }

    private final byte[] S3(byte[] bArr, int i9, byte[] bArr2) {
        return Q3(new SecretKeySpec(bArr, 0, i9, "AES"), bArr2);
    }

    public final byte[] T3(byte[] bArr, byte[] bArr2) {
        return S3(bArr, bArr.length, bArr2);
    }

    private final String U3(JSONObject jSONObject, boolean z8, boolean z9, int i9) {
        Uri.Builder buildUpon = this.f7278v0.buildUpon();
        buildUpon.appendPath(z8 ? OJPcPhffzFBKVl.EhcCLNxGzQnE : "sc");
        buildUpon.appendQueryParameter("id", this.f7280x0.toString());
        g4();
        String str = this.f7271G0;
        if (str != null) {
            buildUpon.appendQueryParameter("sid", str);
            String str2 = this.f7272H0;
            if (str2 != null) {
                buildUpon.appendQueryParameter("sn", str2);
            }
        }
        try {
            String builder = buildUpon.toString();
            AbstractC7780t.e(builder, "toString(...)");
            HttpURLConnection Q22 = Q2("POST", builder);
            if (jSONObject != null) {
                Q22.setRequestProperty("Content-Type", "application/json");
                Q22.setDoOutput(true);
                OutputStream outputStream = Q22.getOutputStream();
                AbstractC7780t.e(outputStream, "getOutputStream(...)");
                StringBuilder sb = new StringBuilder();
                sb.append('[');
                sb.append(jSONObject);
                sb.append(']');
                t6.k.N0(outputStream, sb.toString());
            }
            try {
                return AbstractC7990b.f60542s0.h(Q22);
            } catch (OutOfMemoryError unused) {
                throw new C7377h();
            }
        } catch (h.d e9) {
            throw new IOException(e9.getMessage());
        }
    }

    static String V3(b bVar, JSONObject jSONObject, boolean z8, boolean z9, int i9, int i10, Object obj) {
        if ((i10 & 2) != 0) {
            z8 = true;
        }
        if ((i10 & 4) != 0) {
            z9 = false;
        }
        if ((i10 & 8) != 0) {
            i9 = 25;
        }
        return bVar.U3(jSONObject, z8, z9, i9);
    }

    private final JSONObject W3(JSONObject jSONObject, boolean z8) {
        char U02;
        int i9 = 25;
        while (true) {
            String V32 = V3(this, jSONObject, z8, false, 0, 12, null);
            c cVar = f7261N0;
            if (!cVar.p(V32)) {
                if (V32.length() > 0) {
                    U02 = z.U0(V32);
                    if (U02 == '[') {
                        V32 = V32.substring(1, V32.length() - 1);
                        AbstractC7780t.e(V32, "substring(...)");
                    }
                }
                try {
                    return new JSONObject(V32);
                } catch (JSONException e9) {
                    throw new IOException(e9);
                }
            }
            int n9 = cVar.n(V32);
            if (n9 == -26) {
                throw new h.k();
            }
            if (n9 != -6 && n9 != -4 && n9 != -3) {
                if (this.f7277M0 != null) {
                    this.f7277M0 = null;
                    throw new h.k();
                }
                throw new IOException("API error: " + cVar.m(n9));
            }
            try {
                Thread.sleep(i9);
                i9 *= 2;
            } catch (InterruptedException e10) {
                throw new IOException(e10.getMessage());
            }
        }
    }

    static JSONObject X3(b bVar, JSONObject jSONObject, boolean z8, int i9, Object obj) {
        if ((i9 & 2) != 0) {
            z8 = true;
        }
        return bVar.W3(jSONObject, z8);
    }

    public final JSONObject Y3(j jVar) {
        C6730s[] c6730sArr = new C6730s[3];
        c6730sArr[0] = AbstractC6736y.a("a", "p");
        h h9 = jVar.h();
        SecretKeySpec secretKeySpec = null;
        c6730sArr[1] = AbstractC6736y.a("t", h9 != null ? h9.d() : null);
        JSONArray jSONArray = new JSONArray();
        C6730s[] c6730sArr2 = new C6730s[4];
        c6730sArr2[0] = AbstractC6736y.a("t", Integer.valueOf(!(jVar instanceof i) ? 1 : 0));
        c6730sArr2[1] = AbstractC6736y.a("h", jVar.d());
        c6730sArr2[2] = AbstractC6736y.a("a", c4(jVar.g(), jVar.f()));
        c cVar = f7261N0;
        SecretKeySpec secretKeySpec2 = this.f7269E0;
        if (secretKeySpec2 == null) {
            AbstractC7780t.r("masterKey");
        } else {
            secretKeySpec = secretKeySpec2;
        }
        c6730sArr2[3] = AbstractC6736y.a("k", cVar.k(d4(secretKeySpec, jVar.e())));
        jSONArray.put(t6.k.c0(c6730sArr2));
        C6709J c6709j = C6709J.f49946a;
        c6730sArr[2] = AbstractC6736y.a("n", jSONArray);
        return t6.k.c0(c6730sArr);
    }

    public final byte[] Z3(byte[] bArr, int i9) {
        byte[] p9;
        Cipher cipher = Cipher.getInstance("RSA/ECB/NoPadding");
        int i10 = 2;
        cipher.init(2, this.f7270F0);
        byte[] doFinal = cipher.doFinal(bArr, 2, bArr.length - 2);
        int i11 = doFinal[0] == 0 ? 1 : 0;
        i10 = i11;
        AbstractC7780t.c(doFinal);
        p9 = AbstractC6838o.p(doFinal, i10, i9 + i10);
        return p9;
    }

    public final byte[] a4(Key key, byte[] bArr) {
        if ((bArr.length & 15) != 0) {
            throw new IllegalStateException("Check failed.".toString());
        }
        byte[] bArr2 = new byte[bArr.length];
        for (int i9 = 0; i9 < bArr.length; i9 += 16) {
            AbstractC7780t.c(key);
            System.arraycopy(O3(key, bArr, i9, 16), 0, bArr2, i9, 16);
        }
        return bArr2;
    }

    public final void b4(j jVar) {
        String V32 = V3(this, t6.k.c0(AbstractC6736y.a("a", "d"), AbstractC6736y.a("n", jVar.d())), false, false, 0, 14, null);
        c cVar = f7261N0;
        if (cVar.q(V32)) {
            return;
        }
        if (cVar.p(V32)) {
            V32 = cVar.m(cVar.n(V32));
        }
        throw new IOException("Delete error: " + V32);
    }

    private final String c4(String str, byte[] bArr) {
        String B8;
        StringBuilder sb = new StringBuilder();
        sb.append("MEGA{\"n\":\"");
        B8 = w.B(str, "\"", "\\\"", false, 4, null);
        sb.append(B8);
        sb.append("\"}");
        byte[] bytes = sb.toString().getBytes(C1160d.f4033b);
        AbstractC7780t.e(bytes, "getBytes(...)");
        return f7261N0.k(T3(bArr, bytes));
    }

    private final byte[] d4(Key key, byte[] bArr) {
        byte[] bArr2 = new byte[bArr.length];
        for (int i9 = 0; i9 < bArr.length; i9 += 16) {
            System.arraycopy(R3(key, bArr, i9, 16), 0, bArr2, i9, 16);
        }
        return bArr2;
    }

    private final void e4() {
        SecretKeySpec secretKeySpec;
        synchronized (this) {
            try {
                boolean z8 = true;
                secretKeySpec = null;
                JSONObject X32 = X3(this, t6.k.c0(AbstractC6736y.a("a", "f"), AbstractC6736y.a("c", "1"), AbstractC6736y.a("r", "1")), false, 2, null);
                this.f7281y0.clear();
                this.f7282z0.clear();
                this.f7266B0.clear();
                this.f7275K0 = null;
                JSONArray jSONArray = X32.getJSONArray("u");
                AbstractC7780t.e(jSONArray, "getJSONArray(...)");
                o4(jSONArray);
                n4();
                String optString = X32.optString("sn");
                if (optString.length() <= 0) {
                    z8 = false;
                }
                if (!z8) {
                    optString = null;
                }
                this.f7272H0 = optString;
                JSONArray jSONArray2 = X32.getJSONArray("ok");
                AbstractC7780t.e(jSONArray2, "getJSONArray(...)");
                m4(jSONArray2);
                JSONArray jSONArray3 = X32.getJSONArray("f");
                AbstractC7780t.e(jSONArray3, "getJSONArray(...)");
                int length = jSONArray3.length();
                for (int i9 = 0; i9 < length; i9++) {
                    L3((JSONObject) jSONArray3.get(i9));
                }
                C6709J c6709j = C6709J.f49946a;
            } catch (Throwable th) {
                throw th;
            }
        }
        HashMap hashMap = this.f7266B0;
        String str = this.f7276L0;
        SecretKeySpec secretKeySpec2 = this.f7269E0;
        if (secretKeySpec2 == null) {
            AbstractC7780t.r("masterKey");
        } else {
            secretKeySpec = secretKeySpec2;
        }
        hashMap.put(str, secretKeySpec);
    }

    private final j f4(C c9) {
        if (c9 instanceof AbstractC7992d.j) {
            return (j) this.f7282z0.get(((AbstractC7992d.j) c9).a());
        }
        return null;
    }

    private final void g4() {
        int length = this.f7280x0.length;
        while (true) {
            length--;
            if (length < 0) {
                return;
            }
            char[] cArr = this.f7280x0;
            char c9 = cArr[length];
            cArr[length] = (char) (c9 + 1);
            if (AbstractC7780t.g(c9, 122) < 0) {
                return;
            } else {
                this.f7280x0[length] = 'a';
            }
        }
    }

    private final synchronized void h4() {
        byte[] p9;
        try {
            if (this.f7271G0 == null) {
                try {
                    try {
                        String str = this.f7274J0;
                        byte[] bArr = this.f7273I0;
                        if (bArr == null) {
                            t6.k.l0(0, new p(), 1, null);
                            JSONObject X32 = X3(this, t6.k.c0(AbstractC6736y.a(PkPO.vbRzBqZ, "us0"), AbstractC6736y.a("user", this.f7267C0)), false, 2, null);
                            if (X32.optInt("v") == 2) {
                                c cVar = f7261N0;
                                String string = X32.getString("s");
                                AbstractC7780t.e(string, "getString(...)");
                                byte[] j9 = cVar.j(string);
                                String str2 = this.f7268D0;
                                AbstractC7780t.c(str2);
                                byte[] l42 = l4(str2, j9);
                                p9 = AbstractC6838o.p(l42, 16, 32);
                                str = cVar.k(p9);
                                bArr = AbstractC6838o.p(l42, 0, 16);
                            } else {
                                String str3 = this.f7268D0;
                                AbstractC7780t.c(str3);
                                bArr = k4(str3);
                                String str4 = this.f7267C0;
                                AbstractC7780t.c(str4);
                                str = r4(str4, bArr);
                            }
                        }
                        AbstractC7780t.c(str);
                        i4(bArr, str);
                        if (this.f7273I0 == null) {
                            String str5 = this.f7267C0;
                            AbstractC7780t.c(str5);
                            q4(str5, this.f7268D0, str, bArr);
                        }
                        e4();
                    } catch (IllegalArgumentException e9) {
                        throw e9;
                    } catch (Exception e10) {
                        throw new h.j("Login failed: " + t6.k.Q(e10));
                    }
                } catch (h.j e11) {
                    throw e11;
                } catch (SSLException e12) {
                    throw e12;
                }
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    private final void i4(byte[] bArr, String str) {
        byte[] p9;
        JSONObject c02 = t6.k.c0(AbstractC6736y.a("a", "us"), AbstractC6736y.a("user", this.f7267C0), AbstractC6736y.a("uh", str));
        Integer num = this.f7277M0;
        if (num != null) {
            c02.put("mfa", num.intValue());
        }
        JSONObject X32 = X3(this, c02, false, 2, null);
        c cVar = f7261N0;
        String string = X32.getString("k");
        AbstractC7780t.e(string, "getString(...)");
        SecretKeySpec secretKeySpec = new SecretKeySpec(P3(bArr, cVar.j(string)), "AES");
        this.f7269E0 = secretKeySpec;
        String string2 = X32.getString("privk");
        AbstractC7780t.e(string2, "getString(...)");
        byte[] a42 = a4(secretKeySpec, cVar.j(string2));
        BigInteger[] bigIntegerArr = new BigInteger[4];
        int i9 = 0;
        for (int i10 = 0; i10 < 4; i10++) {
            int j9 = (((t6.k.j(a42[i9]) * 256) + t6.k.j(a42[i9 + 1])) + 7) / 8;
            i9 += j9 + 2;
            p9 = AbstractC6838o.p(a42, i9 - j9, i9);
            bigIntegerArr[i10] = new BigInteger(1, p9);
        }
        this.f7270F0 = KeyFactory.getInstance("RSA").generatePrivate(new RSAPrivateKeySpec(bigIntegerArr[0].multiply(bigIntegerArr[1]), bigIntegerArr[2]));
        c cVar2 = f7261N0;
        String string3 = X32.getString("csid");
        AbstractC7780t.e(string3, "getString(...)");
        this.f7271G0 = cVar2.k(Z3(cVar2.j(string3), 43));
    }

    private final boolean j4(j jVar, String str) {
        try {
        } catch (IOException e9) {
            e9.printStackTrace();
        }
        return f7261N0.q(V3(this, t6.k.c0(AbstractC6736y.a("a", "m"), AbstractC6736y.a("n", jVar.d()), AbstractC6736y.a("t", str)), false, false, 0, 14, null));
    }

    private final byte[] k4(CharSequence charSequence) {
        byte[] r9 = f7261N0.r(charSequence);
        int length = r9.length;
        int max = Math.max(16, (length + 15) & (-16));
        byte[] bArr = new byte[max];
        System.arraycopy(r9, 0, bArr, 0, length);
        int i9 = max / 16;
        SecretKeySpec[] secretKeySpecArr = new SecretKeySpec[i9];
        for (int i10 = 0; i10 < i9; i10++) {
            secretKeySpecArr[i10] = new SecretKeySpec(bArr, i10 * 16, 16, "AES");
        }
        byte[] bArr2 = {-109, -60, 103, -29, 125, -80, -57, -92, -47, -66, 63, -127, 1, 82, -53, 86};
        for (int i11 = 0; i11 < 65536; i11++) {
            for (int i12 = 0; i12 < i9; i12++) {
                bArr2 = Q3(secretKeySpecArr[i12], bArr2);
            }
        }
        return bArr2;
    }

    private final byte[] l4(CharSequence charSequence, byte[] bArr) {
        if (Build.VERSION.SDK_INT < 26) {
            return L6.c.f7330a.b("HmacSHA512", C1160d.f4033b, bArr, 100000, charSequence.toString(), 32);
        }
        char[] charArray = charSequence.toString().toCharArray();
        AbstractC7780t.e(charArray, "toCharArray(...)");
        byte[] encoded = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA512").generateSecret(new PBEKeySpec(charArray, bArr, 100000, 256)).getEncoded();
        AbstractC7780t.c(encoded);
        return encoded;
    }

    private final void m4(JSONArray jSONArray) {
        this.f7266B0.clear();
        int length = jSONArray.length();
        for (int i9 = 0; i9 < length; i9++) {
            JSONObject jSONObject = (JSONObject) jSONArray.get(i9);
            String optString = jSONObject.optString("h");
            String optString2 = jSONObject.optString("k");
            String optString3 = jSONObject.optString("ha");
            try {
                SecretKeySpec secretKeySpec = this.f7269E0;
                SecretKeySpec secretKeySpec2 = null;
                if (secretKeySpec == null) {
                    AbstractC7780t.r("masterKey");
                    secretKeySpec = null;
                }
                byte[] bytes = (optString + optString).getBytes(C1160d.f4033b);
                AbstractC7780t.e(bytes, "getBytes(...)");
                byte[] d42 = d4(secretKeySpec, bytes);
                c cVar = f7261N0;
                if (AbstractC7780t.a(optString3, cVar.k(d42))) {
                    SecretKeySpec secretKeySpec3 = this.f7269E0;
                    if (secretKeySpec3 == null) {
                        AbstractC7780t.r("masterKey");
                    } else {
                        secretKeySpec2 = secretKeySpec3;
                    }
                    AbstractC7780t.c(optString2);
                    this.f7266B0.put(optString, new SecretKeySpec(a4(secretKeySpec2, cVar.j(optString2)), "AES"));
                }
            } catch (GeneralSecurityException e9) {
                e9.printStackTrace();
            }
        }
    }

    private final void n4() {
        m mVar = null;
        for (o oVar : this.f7265A0.values()) {
            if (oVar.c() == 1) {
                if (mVar == null) {
                    mVar = new m(-1);
                    mVar.n("Contacts");
                    this.f7282z0.put(mVar.d(), mVar);
                    this.f7281y0.put(mVar.d(), mVar);
                }
                AbstractC7780t.c(oVar);
                g gVar = new g(oVar);
                mVar.p().put(oVar.b(), gVar);
                this.f7282z0.put(gVar.d(), gVar);
            }
        }
    }

    private final void o4(JSONArray jSONArray) {
        this.f7265A0.clear();
        this.f7276L0 = null;
        int length = jSONArray.length();
        for (int i9 = 0; i9 < length; i9++) {
            o oVar = new o((JSONObject) jSONArray.get(i9));
            if (oVar.c() == 2) {
                this.f7276L0 = oVar.b();
            }
            this.f7265A0.put(oVar.b(), oVar);
        }
    }

    private final void p4(j jVar) {
        this.f7282z0.remove(jVar.d());
        if (jVar instanceof h) {
            for (j jVar2 : ((h) jVar).p().values()) {
                AbstractC7780t.c(jVar2);
                p4(jVar2);
            }
        }
    }

    private final void q4(String str, String str2, String str3, byte[] bArr) {
        m2(new s(str2, str3, bArr, this, str));
    }

    private final String r4(String str, byte[] bArr) {
        String lowerCase = str.toLowerCase(Locale.ROOT);
        AbstractC7780t.e(lowerCase, "toLowerCase(...)");
        byte[] bytes = lowerCase.getBytes(C1160d.f4033b);
        AbstractC7780t.e(bytes, "getBytes(...)");
        byte[] bArr2 = new byte[16];
        int length = bytes.length;
        for (int i9 = 0; i9 < length; i9++) {
            int i10 = i9 & 15;
            bArr2[i10] = (byte) (bArr2[i10] ^ bytes[i9]);
        }
        SecretKeySpec secretKeySpec = new SecretKeySpec(bArr, "AES");
        for (int i11 = 0; i11 < 16384; i11++) {
            bArr2 = Q3(secretKeySpec, bArr2);
        }
        return f7261N0.k(new byte[]{bArr2[0], bArr2[1], bArr2[2], bArr2[3], bArr2[8], bArr2[9], bArr2[10], bArr2[11]});
    }

    private final void s4(JSONObject jSONObject) {
        k kVar;
        String X8 = t6.k.X(jSONObject, "n");
        SecretKeySpec secretKeySpec = null;
        j jVar = X8 == null ? null : (j) this.f7282z0.get(X8);
        String string = jSONObject.getString("a");
        if (string != null) {
            int hashCode = string.hashCode();
            if (hashCode != 99) {
                if (hashCode != 100) {
                    if (hashCode != 3259) {
                        switch (hashCode) {
                            case 115:
                                if (string.equals("s")) {
                                    throw new n();
                                }
                                break;
                            case 116:
                                if (string.equals("t")) {
                                    JSONArray jSONArray = jSONObject.getJSONObject("t").getJSONArray("f");
                                    AbstractC7780t.c(jSONArray);
                                    M3(jSONArray);
                                    return;
                                }
                                break;
                            case 117:
                                if (string.equals("u")) {
                                    if (jVar == null) {
                                        throw new IOException("Can't find file " + X8);
                                    }
                                    SecretKeySpec secretKeySpec2 = this.f7269E0;
                                    if (secretKeySpec2 == null) {
                                        AbstractC7780t.r("masterKey");
                                    } else {
                                        secretKeySpec = secretKeySpec2;
                                    }
                                    jVar.o(this, jSONObject, secretKeySpec);
                                    return;
                                }
                                break;
                        }
                    } else if (string.equals("fa")) {
                        return;
                    }
                } else if (string.equals("d")) {
                    if (jVar == null) {
                        throw new IOException("Can't find file " + X8);
                    }
                    p4(jVar);
                    h h9 = jVar.h();
                    if (h9 == null || (kVar = h9.p()) == null) {
                        kVar = this.f7281y0;
                    }
                    kVar.remove(X8);
                    return;
                }
            } else if (string.equals("c")) {
                throw new n();
            }
        }
        App.f43875F0.o("Unknown action: " + string);
    }

    public final void t4() {
        synchronized (this) {
            try {
                JSONObject W32 = W3(null, false);
                if (!W32.has("w")) {
                    this.f7272H0 = W32.optString("sn");
                    JSONArray jSONArray = W32.getJSONArray("a");
                    AbstractC7780t.e(jSONArray, "getJSONArray(...)");
                    int length = jSONArray.length();
                    for (int i9 = 0; i9 < length; i9++) {
                        s4((JSONObject) jSONArray.get(i9));
                    }
                }
                C6709J c6709j = C6709J.f49946a;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override
    public boolean A2() {
        return true;
    }

    @Override
    public boolean B2() {
        return true;
    }

    @Override
    public boolean F2(C1141j c1141j) {
        AbstractC7780t.f(c1141j, "de");
        if (AbstractC7780t.a(c1141j, this)) {
            return false;
        }
        if (!(c1141j instanceof AbstractC7992d.b)) {
            return true;
        }
        j f42 = f4(c1141j);
        if ((f42 instanceof g) || f42 == null) {
            return false;
        }
        l j9 = f42.j();
        if (j9 != null) {
            return j9.q() >= 1;
        }
        return true;
    }

    @Override
    public boolean G2(C1141j c1141j) {
        AbstractC7780t.f(c1141j, "de");
        if (AbstractC7780t.a(c1141j, this)) {
            return false;
        }
        j f42 = f4(c1141j);
        if (f42 instanceof m) {
            m mVar = (m) f42;
            if (mVar.q() != 1 && mVar.q() != 2) {
                return false;
            }
        } else if ((f42 instanceof l) || f42 == null || f42.j() != null) {
            return false;
        }
        return true;
    }

    @Override
    public boolean H2(C c9) {
        AbstractC7780t.f(c9, "le");
        j f42 = f4(c9);
        return ((f42 instanceof m) || (f42 instanceof l) || f42 == null || f42.j() != null) ? false : true;
    }

    @Override
    protected boolean M2(C1141j c1141j, String str) {
        AbstractC7780t.f(c1141j, "dir");
        AbstractC7780t.f(str, "name");
        j f42 = f4(c1141j);
        h hVar = f42 instanceof h ? (h) f42 : null;
        if (hVar == null) {
            return false;
        }
        Collection values = hVar.p().values();
        AbstractC7780t.e(values, bRSET.mPQp);
        Collection collection = values;
        if ((collection instanceof Collection) && collection.isEmpty()) {
            return false;
        }
        Iterator it = collection.iterator();
        while (it.hasNext()) {
            if (AbstractC7780t.a(((j) it.next()).g(), str)) {
                return true;
            }
        }
        return false;
    }

    @Override
    public C1141j P2(C1141j c1141j, String str) {
        Object obj;
        AbstractC7780t.f(c1141j, yBiTelOWBwmsB.Qki);
        AbstractC7780t.f(str, "name");
        j f42 = f4(c1141j);
        AbstractC7780t.d(f42, "null cannot be cast to non-null type com.lonelycatgames.Xplore.clouds.mega.MegaCoServer.MegaDir");
        h hVar = (h) f42;
        Collection values = hVar.p().values();
        AbstractC7780t.e(values, "<get-values>(...)");
        Iterator it = values.iterator();
        while (true) {
            if (!it.hasNext()) {
                obj = null;
                break;
            }
            obj = it.next();
            if (AbstractC7780t.a(((j) obj).g(), str)) {
                break;
            }
        }
        j jVar = (j) obj;
        if (jVar != null) {
            if (jVar instanceof h) {
                return new AbstractC7992d.b(this, jVar.d(), 0L, null, 12, null);
            }
            throw new IOException("Conflict with file");
        }
        h hVar2 = new h(hVar);
        byte[] generateSeed = new SecureRandom().generateSeed(16);
        AbstractC7780t.e(generateSeed, "generateSeed(...)");
        hVar2.m(generateSeed);
        hVar2.l("xxxxxxxx");
        hVar2.n(str);
        JSONArray jSONArray = X3(this, Y3(hVar2), false, 2, null).getJSONArray("f");
        if (jSONArray.length() != 1) {
            throw new IOException("Can't create dir");
        }
        JSONObject jSONObject = jSONArray.getJSONObject(0);
        String string = jSONObject.getString("h");
        AbstractC7780t.c(string);
        hVar2.l(string);
        hVar2.k(jSONObject.getLong("ts"));
        hVar2.n(str);
        hVar.p().put(string, hVar2);
        this.f7282z0.put(string, hVar2);
        t4();
        return new AbstractC7992d.b(this, string, 0L, null, 12, null);
    }

    @Override
    public HttpURLConnection Q2(String str, String str2) {
        AbstractC7780t.f(str2, "uri");
        HttpURLConnection Q22 = super.Q2(str, str2);
        Q22.setReadTimeout(180000);
        Q22.setConnectTimeout(180000);
        return Q22;
    }

    @Override
    public void R2(C c9) {
        m mVar;
        AbstractC7780t.f(c9, "le");
        j f42 = f4(c9);
        C6709J c6709j = null;
        if (f42 != null) {
            if (AbstractC7780t.a(f42.h(), this.f7275K0) || f42.j() != null || (mVar = this.f7275K0) == null) {
                b4(f42);
                r3();
            } else {
                if (!j4(f42, mVar != null ? mVar.d() : null)) {
                    throw new IOException("Failed to delete");
                }
            }
            t4();
            c6709j = C6709J.f49946a;
        }
        if (c6709j == null) {
            throw new FileNotFoundException();
        }
    }

    @Override
    public OutputStream S1(C c9, String str, long j9, Long l9) {
        h h9;
        File file;
        C1141j u02;
        C1141j c1141j;
        AbstractC7780t.f(c9, "le");
        try {
            h4();
            if (str != null) {
                h9 = (h) f4(c9);
                if (h9 == null) {
                    throw new FileNotFoundException();
                }
            } else {
                j f42 = f4(c9);
                if (f42 == null || (h9 = f42.h()) == null) {
                    throw new FileNotFoundException();
                }
            }
            h hVar = h9;
            String p02 = str == null ? c9.p0() : str;
            String string = X3(this, t6.k.c0(AbstractC6736y.a(siskKbxSSIi.oKRTJnQhGHBkCF, "u"), AbstractC6736y.a("ms", "0"), AbstractC6736y.a("s", Long.valueOf(j9))), false, 2, null).getString("p");
            i iVar = new i(hVar);
            byte[] generateSeed = new SecureRandom().generateSeed(32);
            AbstractC7780t.e(generateSeed, "generateSeed(...)");
            iVar.m(generateSeed);
            iVar.n(p02);
            SecretKeySpec secretKeySpec = new SecretKeySpec(iVar.e(), 0, 16, "AES");
            AbstractC7780t.c(string);
            HttpURLConnection Q22 = Q2("POST", string);
            if (j9 != -1) {
                Q22.setFixedLengthStreamingMode((int) j9);
            } else {
                Q22.setChunkedStreamingMode(16384);
            }
            if (AbstractC7780t.a(x5.p.f58787a.g(V().C0(p02)), "image")) {
                file = File.createTempFile("mega", '.' + t6.k.F(p02), App.V0(V(), false, 1, null));
            } else {
                file = null;
            }
            if (str == null) {
                u02 = c9.u0();
            } else {
                if (!(c9 instanceof C1141j)) {
                    c1141j = null;
                    d dVar = new d(this, Q22, secretKeySpec, iVar, file, hVar, c1141j, l9);
                    dVar.i();
                    return dVar;
                }
                u02 = (C1141j) c9;
            }
            c1141j = u02;
            d dVar2 = new d(this, Q22, secretKeySpec, iVar, file, hVar, c1141j, l9);
            dVar2.i();
            return dVar2;
        } catch (IOException e9) {
            throw e9;
        } catch (Exception e10) {
            throw new IOException(t6.k.Q(e10));
        }
    }

    @Override
    public AbstractC7990b.C0993b U2() {
        return f7263P0;
    }

    @Override
    public Object clone() {
        return super.clone();
    }

    @Override
    public void d3(C c9, C1141j c1141j, String str) {
        AbstractC7780t.f(c9, "le");
        AbstractC7780t.f(c1141j, "newParent");
        j f42 = f4(c9);
        if (f42 == null) {
            throw new FileNotFoundException();
        }
        j f43 = f4(c1141j);
        if (f43 == null) {
            throw new FileNotFoundException();
        }
        if (!j4(f42, f43.d())) {
            throw new IOException("Failed to move");
        }
        if (str != null) {
            i3(c9, str);
        }
    }

    @Override
    public String e2() {
        return "Enter your 2FA code";
    }

    @Override
    public boolean e3() {
        return false;
    }

    @Override
    public void i3(C c9, String str) {
        AbstractC7780t.f(c9, "le");
        AbstractC7780t.f(str, "newName");
        if (AbstractC7780t.a(c9, this)) {
            c1(str);
            Uri a22 = a2();
            if (a22 != null) {
                m2(new r(a22, str));
                return;
            }
            return;
        }
        j f42 = f4(c9);
        if (f42 == null) {
            throw new FileNotFoundException();
        }
        JSONObject c02 = t6.k.c0(AbstractC6736y.a("a", "a"), AbstractC6736y.a("n", f42.d()));
        c02.put("at", c4(str, f42.f()));
        SecretKeySpec secretKeySpec = this.f7269E0;
        if (secretKeySpec == null) {
            AbstractC7780t.r("masterKey");
            secretKeySpec = null;
        }
        byte[] d42 = d4(secretKeySpec, f42.e());
        c cVar = f7261N0;
        c02.put("k", cVar.k(d42));
        String V32 = V3(this, c02, false, false, 0, 14, null);
        if (cVar.q(V32)) {
            t4();
            return;
        }
        if (cVar.p(V32)) {
            V32 = cVar.m(cVar.n(V32));
        }
        throw new IOException("Rename error: " + V32);
    }

    @Override
    public void j2(h.f fVar) {
        String str;
        Collection<j> values;
        ?? R12;
        AbstractC7780t.f(fVar, "lister");
        String str2 = this.f7267C0;
        if (str2 == null || str2.length() == 0 || (str = this.f7268D0) == null || str.length() == 0) {
            throw new h.j(null, 1, null);
        }
        if (AbstractC7780t.a(fVar.m(), this)) {
            if (this.f7277M0 == null) {
                this.f7271G0 = null;
            }
            o3(true);
        }
        try {
            h4();
            super.j2(fVar);
            try {
                t4();
            } catch (n unused) {
                e4();
            }
            if (AbstractC7780t.a(fVar.m(), this)) {
                values = this.f7281y0.values();
            } else {
                j f42 = f4(fVar.m());
                if (!(f42 instanceof h)) {
                    return;
                } else {
                    values = ((h) f42).p().values();
                }
            }
            AbstractC7780t.c(values);
            for (j jVar : values) {
                String g9 = jVar.g();
                if (jVar instanceof h) {
                    R12 = new q(this, jVar, jVar.d());
                    R12.I1(!((h) jVar).p().isEmpty());
                } else {
                    long c9 = jVar.c();
                    AbstractC7780t.d(jVar, "null cannot be cast to non-null type com.lonelycatgames.Xplore.clouds.mega.MegaCoServer.MegaFile");
                    R12 = AbstractC7992d.R1(this, fVar, g9, c9, ((i) jVar).q(), jVar.d(), null, 32, null);
                }
                fVar.c(R12, g9);
            }
        } catch (h.j e9) {
            throw e9;
        } catch (IOException e10) {
            throw e10;
        } catch (GeneralSecurityException e11) {
            throw new IOException(e11);
        } catch (Exception e12) {
            e12.printStackTrace();
            throw new IOException(t6.k.Q(e12));
        }
    }

    @Override
    public InputStream k2(C c9, int i9, long j9) {
        AbstractC7780t.f(c9, "le");
        try {
            h4();
            i iVar = (i) f4(c9);
            if (iVar == null) {
                throw new FileNotFoundException();
            }
            try {
                String string = X3(this, t6.k.c0(AbstractC6736y.a("a", "g"), AbstractC6736y.a("g", "1"), AbstractC6736y.a("n", iVar.d())), false, 2, null).getString("g");
                AbstractC7780t.c(string);
                HttpURLConnection Q22 = Q2(null, string);
                long j10 = 0;
                int i10 = 200;
                if (j9 > 0) {
                    long j11 = j9 & (-16);
                    if (j11 > 0) {
                        AbstractC7992d.C0994d.b(AbstractC7992d.f60582j0, Q22, j11, 0L, 2, null);
                        i10 = 206;
                    }
                    j10 = j11;
                }
                Cipher p9 = iVar.p(2, j10 / 16);
                int responseCode = Q22.getResponseCode();
                if (responseCode != i10) {
                    throw new IOException("HTTP error " + responseCode);
                }
                InputStream inputStream = Q22.getInputStream();
                AbstractC7780t.e(inputStream, "getInputStream(...)");
                f fVar = new f(inputStream, p9);
                if (j10 != j9) {
                    t6.k.p0(fVar, new byte[(int) (j9 - j10)]);
                }
                return fVar;
            } catch (Exception e9) {
                throw new IOException(t6.k.Q(e9));
            }
        } catch (h.j e10) {
            throw new IOException(t6.k.Q(e10));
        }
    }

    @Override
    public C1141j o2(C c9) {
        h h9;
        AbstractC7780t.f(c9, "le");
        j f42 = f4(c9);
        if (f42 == null || (h9 = f42.h()) == null) {
            return null;
        }
        return new AbstractC7992d.b(this, h9.d(), 0L, null, 12, null);
    }

    @Override
    public void q3(C c9) {
        AbstractC7780t.f(c9, "le");
        if (c9 instanceof C1145n) {
            try {
                t4();
            } catch (n unused) {
                e4();
            }
            j f42 = f4(c9);
            if (f42 == null) {
                throw new FileNotFoundException();
            }
            C1145n c1145n = (C1145n) c9;
            c1145n.m1(f42.c());
            i iVar = f42 instanceof i ? (i) f42 : null;
            c1145n.l1(iVar != null ? iVar.q() : -1L);
        }
    }

    @Override
    protected void r3() {
        JSONObject X32 = X3(this, t6.k.c0(AbstractC6736y.a("a", "uq"), AbstractC6736y.a("xfer", "1"), AbstractC6736y.a("strg", "1")), false, 2, null);
        m3(new AbstractC1143l.b(X32.optLong("cstrg"), X32.optLong("mstrg")));
        Uri a22 = a2();
        if ((a22 != null ? a22.getFragment() : null) == null) {
            JSONObject X33 = X3(this, t6.k.c0(AbstractC6736y.a("a", "ug")), false, 2, null);
            String optString = X33.optString("name");
            String optString2 = X33.optString("email");
            AbstractC7780t.c(optString2);
            if (optString2.length() > 0) {
                AbstractC7780t.c(optString);
                if (optString.length() == 0) {
                    optString = optString2;
                } else {
                    optString = optString + " (" + optString2 + ')';
                }
            }
            AbstractC7780t.c(optString);
            if (optString.length() > 0) {
                AbstractC7780t.c(optString);
                i3(this, optString);
            }
        }
        o3(false);
    }

    @Override
    public void t2(Uri uri) {
        List s02;
        super.t2(uri);
        String[] h22 = h2();
        if (h22 == null || h22.length != 2) {
            return;
        }
        this.f7267C0 = h22[0];
        s02 = x.s0(h22[1], new char[]{'\n'}, false, 0, 6, null);
        if (s02.size() == 1) {
            this.f7268D0 = h22[1];
            this.f7273I0 = null;
            this.f7274J0 = null;
        } else if (s02.size() == 3) {
            this.f7268D0 = (String) s02.get(0);
            this.f7274J0 = (String) s02.get(1);
            this.f7273I0 = f7261N0.j((CharSequence) s02.get(2));
        }
    }

    @Override
    public void w2(String str) {
        Integer num = null;
        if (str != null) {
            try {
                num = Integer.valueOf(Integer.parseInt(str));
            } catch (NumberFormatException unused) {
                App.D2(V(), "Invalid code: " + str, false, 2, null);
            }
        }
        this.f7277M0 = num;
    }

    @Override
    public void x2(String str, String str2) {
        AbstractC7780t.f(str, "user");
        q4(str, str2, null, null);
    }
}