BTGO游戏盒 v3.4.80版本的 MD5 值为:000032bab1addaabfdc671ee6a7087ab

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


package a7;

import android.content.Context;
import android.net.Uri;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketException;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class f {

    public static final Logger f402i = LoggerFactory.getLogger("HttpProxyCacheServer");

    public final Object f403a;

    public final ExecutorService f404b;

    public final Map<String, g> f405c;

    public final ServerSocket f406d;

    public final int f407e;

    public final Thread f408f;

    public final a7.c f409g;

    public final k f410h;

    public static final class b {

        public File f411a;

        public d7.c f414d;

        public b7.a f413c = new b7.h(536870912);

        public b7.c f412b = new b7.f();

        public c7.b f415e = new c7.a();

        public b(Context context) {
            this.f414d = d7.d.b(context);
            this.f411a = r.c(context);
        }

        public f a() {
            return new f(b());
        }

        public final a7.c b() {
            return new a7.c(this.f411a, this.f412b, this.f413c, this.f414d, this.f415e);
        }

        public b c(int i10) {
            this.f413c = new b7.g(i10);
            return this;
        }

        public b d(long j10) {
            this.f413c = new b7.h(j10);
            return this;
        }
    }

    public final class c implements Runnable {

        public final Socket f416a;

        public c(Socket socket) {
            this.f416a = socket;
        }

        @Override
        public void run() {
            f.this.o(this.f416a);
        }
    }

    public final class d implements Runnable {

        public final CountDownLatch f418a;

        public d(CountDownLatch countDownLatch) {
            this.f418a = countDownLatch;
        }

        @Override
        public void run() {
            this.f418a.countDown();
            f.this.r();
        }
    }

    public final String c(String str) {
        return String.format(Locale.US, "http://%s:%d/%s", "127.0.0.1", Integer.valueOf(this.f407e), o.f(str));
    }

    public final void d(Socket socket) {
        try {
            if (!socket.isClosed()) {
                socket.close();
            }
        } catch (IOException e10) {
            n(new n("Error closing socket", e10));
        }
    }

    public final void e(Socket socket) {
        try {
            if (!socket.isInputShutdown()) {
                socket.shutdownInput();
            }
        } catch (SocketException unused) {
            f402i.debug("Releasing input stream… Socket is closed by client.");
        } catch (IOException e10) {
            n(new n("Error closing socket input stream", e10));
        }
    }

    public final void f(Socket socket) {
        try {
            if (!socket.isOutputShutdown()) {
                socket.shutdownOutput();
            }
        } catch (IOException e10) {
            f402i.warn("Failed to close socket on proxy side: {}. It seems client have already closed connection.", e10.getMessage());
        }
    }

    public final File g(String str) {
        a7.c cVar = this.f409g;
        return new File(cVar.f389a, cVar.f390b.a(str));
    }

    public final g h(String str) throws n {
        g gVar;
        synchronized (this.f403a) {
            gVar = this.f405c.get(str);
            if (gVar == null) {
                gVar = new g(str, this.f409g);
                this.f405c.put(str, gVar);
            }
        }
        return gVar;
    }

    public final int i() {
        int i10;
        synchronized (this.f403a) {
            i10 = 0;
            Iterator<g> it = this.f405c.values().iterator();
            while (it.hasNext()) {
                i10 += it.next().b();
            }
        }
        return i10;
    }

    public String j(String str) {
        return k(str, true);
    }

    public String k(String str, boolean z10) {
        if (z10 && m(str)) {
            File g10 = g(str);
            q(g10);
            return Uri.fromFile(g10).toString();
        }
        if (l()) {
            return c(str);
        }
        return str;
    }

    public final boolean l() {
        return this.f410h.e(3, 70);
    }

    public boolean m(String str) {
        l.e(str, "Url can't be null!");
        return g(str).exists();
    }

    public final void n(Throwable th) {
        f402i.error("HttpProxyCacheServer error", th);
    }

    public final void o(Socket socket) {
        try {
            try {
                a7.d c10 = a7.d.c(socket.getInputStream());
                Logger logger = f402i;
                logger.debug("Request to cache proxy:" + c10);
                String e10 = o.e(c10.f396a);
                if (this.f410h.d(e10)) {
                    this.f410h.g(socket);
                } else {
                    h(e10).d(c10, socket);
                }
                p(socket);
                logger.debug("Opened connections: " + i());
            } catch (n e11) {
                e = e11;
                n(new n("Error processing request", e));
            } catch (SocketException unused) {
                Logger logger2 = f402i;
                logger2.debug("Closing socket… Socket is closed by client.");
                p(socket);
                logger2.debug("Opened connections: " + i());
            } catch (IOException e12) {
                e = e12;
                n(new n("Error processing request", e));
            }
        } finally {
            p(socket);
            f402i.debug("Opened connections: " + i());
        }
    }

    public final void p(Socket socket) {
        e(socket);
        f(socket);
        d(socket);
    }

    public final void q(File file) {
        try {
            this.f409g.f391c.a(file);
        } catch (IOException e10) {
            f402i.error("Error touching file " + file, (Throwable) e10);
        }
    }

    public final void r() {
        while (!Thread.currentThread().isInterrupted()) {
            try {
                Socket accept = this.f406d.accept();
                f402i.debug("Accept new socket " + accept);
                this.f404b.submit(new c(accept));
            } catch (IOException e10) {
                n(new n("Error during waiting connection", e10));
                return;
            }
        }
    }

    public f(a7.c cVar) {
        this.f403a = new Object();
        this.f404b = Executors.newFixedThreadPool(8);
        this.f405c = new ConcurrentHashMap();
        this.f409g = (a7.c) l.d(cVar);
        try {
            ServerSocket serverSocket = new ServerSocket(0, 8, InetAddress.getByName("127.0.0.1"));
            this.f406d = serverSocket;
            int localPort = serverSocket.getLocalPort();
            this.f407e = localPort;
            i.a("127.0.0.1", localPort);
            CountDownLatch countDownLatch = new CountDownLatch(1);
            Thread thread = new Thread(new d(countDownLatch));
            this.f408f = thread;
            thread.start();
            countDownLatch.await();
            this.f410h = new k("127.0.0.1", localPort);
            f402i.info("Proxy cache server started. Is it alive? " + l());
        } catch (IOException | InterruptedException e10) {
            this.f404b.shutdown();
            throw new IllegalStateException("Error starting local proxy server", e10);
        }
    }
}