Anti Spy v30.16.1.24版本的 MD5 值为:c71fa7f3f1aa08291411b9a5a8b2e65d

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


package erfanrouhani.antispy.services;

import a9.i;
import android.annotation.TargetApi;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.net.ConnectivityManager;
import android.net.NetworkRequest;
import android.net.VpnService;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.ParcelFileDescriptor;
import android.os.Process;
import android.os.SystemClock;
import com.applovin.impl.sdk.k0;
import erfanrouhani.antispy.R;
import erfanrouhani.antispy.appwidgets.FirewallAppWidget;
import erfanrouhani.antispy.database.DBManager;
import erfanrouhani.antispy.models.Allowed;
import erfanrouhani.antispy.models.Packet;
import erfanrouhani.antispy.models.ResourceRecord;
import erfanrouhani.antispy.models.Usage;
import erfanrouhani.antispy.receivers.ServiceRunnerReceiver;
import erfanrouhani.antispy.ui.activities.FirewallActivity;
import erfanrouhani.antispy.util.VpnUtil;
import g7.c;
import j$.util.Objects;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import k7.l;
import r2.e;
import v8.f;
import z8.a;
import z8.b;
public class LocalVpnService extends VpnService {
    public static final Object M = new Object();
    public static long N;
    public PackageManager C;
    public f D;
    public SharedPreferences H;
    public SharedPreferences.Editor I;
    public ParcelFileDescriptor f13946a;
    public ConnectivityManager f13952p;
    public DBManager f13953q;
    public int f13956t;
    public e f13957v;
    public final y8.e f13947b = new y8.e(this);
    public Thread f13948c = null;
    public final b f13949d = new b();
    public final l f13950n = new l(13);
    public final ServiceRunnerReceiver f13951o = new ServiceRunnerReceiver();
    public final HashMap f13954r = new HashMap();
    public final ArrayList f13955s = new ArrayList();
    public final Handler B = new Handler(Looper.getMainLooper());
    public final a E = new a();
    public final FirewallAppWidget J = new FirewallAppWidget();
    public int K = R.drawable.firewall_notification;
    public final y8.e L = new y8.e(this, 1);

    public static void a(LocalVpnService localVpnService) {
        int i10 = 0 << 3;
        localVpnService.jni_run(N, localVpnService.f13946a.getFd(), false, 3);
        localVpnService.f13948c = null;
    }

    private void accountUsage(Usage usage) {
    }

    public static void b(y8.f fVar) {
        if (fVar != null) {
            y8.a aVar = (y8.a) fVar;
            int i10 = aVar.f20710a;
            LocalVpnService localVpnService = aVar.f20711b;
            switch (i10) {
                case 0:
                    localVpnService.e();
                    return;
                default:
                    localVpnService.getClass();
                    new Handler().postDelayed(new y8.b(localVpnService, 2), 500L);
                    return;
            }
        }
    }

    private void dnsResolved(ResourceRecord resourceRecord) {
        DBManager.f13855m.execute(new k0(this, 28, resourceRecord));
    }

    @TargetApi(29)
    private int getUidQ(int i10, int i11, String str, int i12, String str2, int i13) {
        int connectionOwnerUid;
        if ((i11 == 6 || i11 == 17) && this.f13952p != null) {
            connectionOwnerUid = this.f13952p.getConnectionOwnerUid(i11, new InetSocketAddress(str, i12), new InetSocketAddress(str2, i13));
            return connectionOwnerUid;
        }
        return -1;
    }

    private Allowed isAddressAllowed(Packet packet) {
        Allowed allowed = new Allowed();
        w8.f fVar = (w8.f) this.f13954r.get(Integer.valueOf(packet.uid));
        if (fVar != null) {
            int i10 = this.f13956t;
            if (i10 == 1) {
            }
            if (i10 == 0 && fVar.f19993d) {
                allowed = null;
            }
        }
        if ((packet.protocol != 6 || !"".equals(packet.flags)) && packet.uid != Process.myUid()) {
            logPacket(packet);
        }
        return allowed;
    }

    private boolean isDomainBlocked(String str) {
        return this.f13955s.contains(str);
    }

    private native void jni_clear(long j10);

    private native void jni_done(long j10);

    private native int jni_get_mtu();

    private native long jni_init(int i10);

    private native void jni_run(long j10, int i10, boolean z10, int i11);

    private native void jni_socks5(String str, int i10, String str2, String str3);

    private native void jni_start(long j10, int i10);

    private native void jni_stop(long j10);

    private void logPacket(Packet packet) {
        int i10;
        int i11 = packet.uid;
        if (i11 >= 0 && (i11 != 0 || (((i10 = packet.protocol) != 6 && i10 != 17) || packet.dport != 53))) {
            int i12 = packet.protocol;
            if (i12 != 6 && i12 != 17) {
                packet.dport = 0;
            }
            DBManager.f13855m.execute(new k0(this, 27, packet));
        }
    }

    private void nativeError(int i10, String str) {
        if (str != null) {
            d(str, false);
        }
    }

    private void nativeExit(String str) {
        if (str != null) {
            boolean z10 = false & false;
            d(str, false);
        }
    }

    public final VpnService.Builder c() {
        int i10;
        int i11;
        int i12;
        SharedPreferences sharedPreferences = this.H;
        a aVar = this.E;
        Objects.requireNonNull(aVar);
        boolean z10 = sharedPreferences.getBoolean("tDliaSKwvA", false);
        boolean z11 = this.H.getBoolean("hjK41XJH4Z", false);
        boolean z12 = this.H.getBoolean("KmViiULbeo", false);
        boolean z13 = this.H.getBoolean("sTFhJQlMHh", true);
        VpnService.Builder builder = new VpnService.Builder(this);
        builder.setSession(getString(R.string.app_name));
        if (Build.VERSION.SDK_INT >= 29) {
            int i13 = VpnUtil.f14015a;
            ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService("connectivity");
            builder.setMetered(connectivityManager != null && k0.a.a(connectivityManager));
        }
        builder.addAddress(this.H.getString("8Cuw0nm79Y", "10.1.10.1"), 32);
        if (z13) {
            builder.addAddress(this.H.getString("sZKwwLYNn2", "fd00:1:fd00:1:fd00:1:fd00:1"), 128);
        }
        ArrayList arrayList = new ArrayList();
        ArrayList a10 = VpnUtil.a(this);
        SharedPreferences sharedPreferences2 = this.H;
        Objects.requireNonNull(aVar);
        boolean z14 = sharedPreferences2.getBoolean("sTFhJQlMHh", true);
        this.H.getBoolean("KmViiULbeo", false);
        String string = this.H.getString("7pOKLz2ccU", null);
        String string2 = this.H.getString("rUpHTqLETV", null);
        if (string != null) {
            try {
                InetAddress byName = InetAddress.getByName(string);
                if (!byName.isLoopbackAddress()) {
                    if (!byName.isAnyLocalAddress()) {
                        if (!z14) {
                            if (byName instanceof Inet4Address) {
                            }
                        }
                        arrayList.add(byName);
                    }
                }
            } catch (Throwable unused) {
            }
        }
        if (string2 != null) {
            try {
                InetAddress byName2 = InetAddress.getByName(string2);
                if (!byName2.isLoopbackAddress()) {
                    if (!byName2.isAnyLocalAddress()) {
                        if (!z14) {
                            if (byName2 instanceof Inet4Address) {
                            }
                        }
                        arrayList.add(byName2);
                    }
                }
            } catch (Throwable unused2) {
            }
        }
        if (arrayList.size() != 2) {
            Iterator it = a10.iterator();
            while (it.hasNext()) {
                try {
                    InetAddress byName3 = InetAddress.getByName((String) it.next());
                    if (!arrayList.contains(byName3)) {
                        if (!byName3.isLoopbackAddress()) {
                            if (!byName3.isAnyLocalAddress()) {
                                if (!z14 && !(byName3 instanceof Inet4Address)) {
                                }
                                arrayList.add(byName3);
                            }
                        }
                    }
                } catch (Throwable unused3) {
                }
            }
            int size = arrayList.size();
            if (arrayList.size() == 0 || arrayList.size() < size) {
                try {
                    arrayList.add(InetAddress.getByName("8.8.8.8"));
                    arrayList.add(InetAddress.getByName("8.8.4.4"));
                    if (z14) {
                        arrayList.add(InetAddress.getByName("2001:4860:4860::8888"));
                        arrayList.add(InetAddress.getByName("2001:4860:4860::8844"));
                    }
                } catch (Throwable unused4) {
                }
            }
        }
        Iterator it2 = arrayList.iterator();
        while (it2.hasNext()) {
            InetAddress inetAddress = (InetAddress) it2.next();
            if (z13 || (inetAddress instanceof Inet4Address)) {
                builder.addDnsServer(inetAddress);
            }
        }
        if (z10) {
            ArrayList arrayList2 = new ArrayList();
            arrayList2.add(new e9.a("127.0.0.0", 8));
            if (z11 && !z12) {
                arrayList2.add(new e9.a("192.168.42.0", 23));
                arrayList2.add(new e9.a("192.168.44.0", 24));
                arrayList2.add(new e9.a("192.168.49.0", 24));
            }
            if (z12) {
                arrayList2.add(new e9.a("10.0.0.0", 8));
                arrayList2.add(new e9.a("172.16.0.0", 12));
                arrayList2.add(new e9.a("192.168.0.0", 16));
            }
            Configuration configuration = getResources().getConfiguration();
            if (configuration.mcc == 310 && ((i12 = configuration.mnc) == 160 || i12 == 200 || i12 == 210 || i12 == 220 || i12 == 230 || i12 == 240 || i12 == 250 || i12 == 260 || i12 == 270 || i12 == 310 || i12 == 490 || i12 == 660 || i12 == 800)) {
                arrayList2.add(new e9.a("66.94.2.0", 24));
                arrayList2.add(new e9.a("66.94.6.0", 23));
                arrayList2.add(new e9.a("66.94.8.0", 22));
                arrayList2.add(new e9.a("208.54.0.0", 16));
            }
            int i14 = configuration.mcc;
            if ((i14 == 310 && ((i11 = configuration.mnc) == 4 || i11 == 5 || i11 == 6 || i11 == 10 || i11 == 12 || i11 == 13 || i11 == 350 || i11 == 590 || i11 == 820 || i11 == 890 || i11 == 910)) || ((i14 == 311 && ((i10 = configuration.mnc) == 12 || i10 == 110 || ((i10 >= 270 && i10 <= 289) || i10 == 390 || ((i10 >= 480 && i10 <= 489) || i10 == 590)))) || (i14 == 312 && configuration.mnc == 770))) {
                arrayList2.add(new e9.a("66.174.0.0", 16));
                arrayList2.add(new e9.a("66.82.0.0", 15));
                arrayList2.add(new e9.a("69.96.0.0", 13));
                arrayList2.add(new e9.a("70.192.0.0", 11));
                arrayList2.add(new e9.a("97.128.0.0", 9));
                arrayList2.add(new e9.a("174.192.0.0", 9));
                arrayList2.add(new e9.a("72.96.0.0", 9));
                arrayList2.add(new e9.a("75.192.0.0", 9));
                arrayList2.add(new e9.a("97.0.0.0", 10));
            }
            arrayList2.add(new e9.a("224.0.0.0", 3));
            Collections.sort(arrayList2);
            try {
                InetAddress byName4 = InetAddress.getByName("0.0.0.0");
                Iterator it3 = arrayList2.iterator();
                while (it3.hasNext()) {
                    e9.a aVar2 = (e9.a) it3.next();
                    Iterator it4 = m4.a.W(byName4, m4.a.x(m4.a.t(m4.a.x(m4.a.t(aVar2.f13773a) & (((-4294967296) >> aVar2.f13774b) & 4294967295L))) - 1)).iterator();
                    while (it4.hasNext()) {
                        e9.a aVar3 = (e9.a) it4.next();
                        try {
                            builder.addRoute(aVar3.f13773a, aVar3.f13774b);
                        } catch (Throwable unused5) {
                        }
                    }
                    long t10 = m4.a.t(aVar2.f13773a);
                    int i15 = aVar2.f13774b;
                    byName4 = m4.a.x(m4.a.t(m4.a.x(((t10 & (((-4294967296) >> i15) & 4294967295L)) + (1 << (32 - i15))) - 1)) + 1);
                }
                Iterator it5 = m4.a.W(InetAddress.getByName("224.0.0.0"), InetAddress.getByName(z12 ? "255.255.255.254" : "255.255.255.255")).iterator();
                while (it5.hasNext()) {
                    e9.a aVar4 = (e9.a) it5.next();
                    try {
                        builder.addRoute(aVar4.f13773a, aVar4.f13774b);
                    } catch (Throwable unused6) {
                    }
                }
            } catch (UnknownHostException unused7) {
            }
        } else {
            builder.addRoute("0.0.0.0", 0);
        }
        if (z13) {
            builder.addRoute("2000::", 3);
        }
        builder.setMtu(jni_get_mtu());
        if (Build.VERSION.SDK_INT >= 21) {
            try {
                builder.addDisallowedApplication(getPackageName());
                for (Map.Entry entry : this.f13954r.entrySet()) {
                    if (((w8.f) entry.getValue()).f19994e) {
                        builder.addDisallowedApplication(((w8.f) entry.getValue()).f19991b);
                    }
                }
            } catch (Exception unused8) {
            }
        }
        Intent intent = new Intent(this, FirewallActivity.class);
        builder.setConfigureIntent(Build.VERSION.SDK_INT >= 23 ? PendingIntent.getActivity(this, 0, intent, 201326592) : PendingIntent.getActivity(this, 0, intent, 134217728));
        return builder;
    }

    public final void d(String str, boolean z10) {
        f fVar = this.D;
        b bVar = this.f13949d;
        Objects.requireNonNull(bVar);
        String string = getString(R.string.firewall);
        Objects.requireNonNull(bVar);
        fVar.a("firewall_notification_id", string, 11111, this.K, getString(R.string.firewall_disabled), str, new Intent(getApplicationContext(), FirewallActivity.class));
        if (z10) {
            i.y(this.E, this.I, "Rt3Lkfhr8C", false);
            b.f20901l = true;
            stopSelf();
        }
    }

    public final void e() {
        try {
            this.f13946a = c().establish();
        } catch (Exception e10) {
            d(getString(R.string.firewall_error_message), true);
            c.a().b(e10);
        }
        if (this.f13946a != null) {
            SharedPreferences sharedPreferences = this.H;
            Objects.requireNonNull(this.E);
            if (sharedPreferences.getBoolean("zwEr4tv67J", false)) {
                jni_socks5(this.H.getString("YMzH9ilTI4", ""), this.H.getInt("FDguxwMskM", 0), this.H.getString("aEY0Hzqp0s", ""), this.H.getString("HDKqNjBjtE", ""));
            } else {
                jni_socks5("", 0, "", "");
            }
            if (this.f13948c == null) {
                jni_start(N, 5);
                Thread thread = new Thread(new y8.b(this, 3));
                this.f13948c = thread;
                thread.start();
            }
        } else {
            d(getString(R.string.firewall_error_message), true);
        }
    }

    public final void f() {
        if (this.f13948c != null) {
            jni_stop(N);
            Thread thread = this.f13948c;
            while (thread != null && thread.isAlive()) {
                try {
                    thread.join();
                } catch (InterruptedException unused) {
                }
                thread = this.f13948c;
            }
            this.f13948c = null;
            jni_clear(N);
        }
    }

    public final void g() {
        try {
            ParcelFileDescriptor parcelFileDescriptor = this.f13946a;
            if (parcelFileDescriptor != null) {
                parcelFileDescriptor.close();
                this.f13946a = null;
            }
        } catch (Exception unused) {
        }
    }

    @Override
    public final void onCreate() {
        PendingIntent broadcast;
        PendingIntent broadcast2;
        super.onCreate();
        this.f13953q = DBManager.I(this);
        Objects.requireNonNull(this.E);
        SharedPreferences sharedPreferences = getSharedPreferences("31VBhR66hv", 0);
        this.H = sharedPreferences;
        this.I = sharedPreferences.edit();
        this.D = new f(getApplicationContext());
        this.f13952p = (ConnectivityManager) getSystemService("connectivity");
        this.C = getPackageManager();
        int i10 = Build.VERSION.SDK_INT;
        if (i10 >= 34) {
            this.K = R.drawable.firewall;
            Objects.requireNonNull(this.f13949d);
            f fVar = this.D;
            String string = getString(R.string.firewall_active);
            int i11 = this.K;
            Objects.requireNonNull(this.f13949d);
            startForeground(6969, fVar.c(i11, string, "firewall_notification_id", false, false), 1024);
        } else if (i10 >= 21) {
            this.K = R.drawable.firewall;
            Objects.requireNonNull(this.f13949d);
            f fVar2 = this.D;
            String string2 = getString(R.string.firewall_active);
            int i12 = this.K;
            Objects.requireNonNull(this.f13949d);
            startForeground(6969, fVar2.c(i12, string2, "firewall_notification_id", false, false));
        } else {
            this.K = R.drawable.firewall_notification;
            Objects.requireNonNull(this.f13949d);
            f fVar3 = this.D;
            String string3 = getString(R.string.firewall_active);
            int i13 = this.K;
            Objects.requireNonNull(this.f13949d);
            startForeground(6969, fVar3.c(i13, string3, "firewall_notification_id", false, false));
        }
        DBManager.f13855m.execute(new y8.b(this, 1));
        System.loadLibrary("antispy");
        long j10 = N;
        if (j10 != 0) {
            jni_stop(j10);
            synchronized (M) {
                try {
                    jni_done(N);
                    N = 0L;
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
        N = jni_init(i10);
        IntentFilter intentFilter = new IntentFilter();
        Objects.requireNonNull(this.f13949d);
        intentFilter.addAction("action_stop_firewall");
        intentFilter.addAction("action_restart_firewall");
        intentFilter.addAction("action_reload_firewall_apps");
        intentFilter.addAction("action_reload_firewall_blocked_domains");
        intentFilter.addAction("action_cleanup_dns");
        intentFilter.addAction("action_cleanup_logs");
        f0.i.f(this, this.f13947b, intentFilter, 4);
        if (i10 >= 23) {
            try {
                NetworkRequest.Builder builder = new NetworkRequest.Builder();
                builder.addCapability(12);
                builder.addCapability(16);
                e eVar = new e(this, 3);
                this.f13952p.registerNetworkCallback(builder.build(), eVar);
                this.f13957v = eVar;
            } catch (Exception unused) {
                IntentFilter intentFilter2 = new IntentFilter();
                intentFilter2.addAction("android.net.conn.CONNECTIVITY_CHANGE");
                registerReceiver(this.L, intentFilter2);
            }
        } else {
            IntentFilter intentFilter3 = new IntentFilter();
            intentFilter3.addAction("android.net.conn.CONNECTIVITY_CHANGE");
            registerReceiver(this.L, intentFilter3);
        }
        DBManager.f13855m.execute(new k0(this, 29, new y8.a(this, 0)));
        b.f20900k = true;
        this.f13950n.t();
        Intent intent = new Intent(this, y8.e.class);
        Objects.requireNonNull(this.f13949d);
        intent.setAction("action_cleanup_dns");
        Intent intent2 = new Intent(this, y8.e.class);
        Objects.requireNonNull(this.f13949d);
        intent2.setAction("action_cleanup_logs");
        if (Build.VERSION.SDK_INT >= 23) {
            broadcast = PendingIntent.getBroadcast(this, 0, intent, 201326592);
            broadcast2 = PendingIntent.getBroadcast(this, 1, intent2, 201326592);
        } else {
            broadcast = PendingIntent.getBroadcast(this, 0, intent, 134217728);
            broadcast2 = PendingIntent.getBroadcast(this, 1, intent2, 134217728);
        }
        PendingIntent pendingIntent = broadcast;
        PendingIntent pendingIntent2 = broadcast2;
        AlarmManager alarmManager = (AlarmManager) getSystemService("alarm");
        alarmManager.setInexactRepeating(1, SystemClock.elapsedRealtime() + 60000, 43200000L, pendingIntent);
        alarmManager.setInexactRepeating(1, SystemClock.elapsedRealtime() + 60000, 43200000L, pendingIntent2);
        this.J.b(this);
        this.J.d(this);
    }

    @Override
    public final void onDestroy() {
        stopForeground(true);
        unregisterReceiver(this.f13947b);
        if (Build.VERSION.SDK_INT >= 23) {
            this.f13952p.unregisterNetworkCallback(this.f13957v);
        } else {
            unregisterReceiver(this.L);
        }
        b.f20900k = false;
        try {
            if (this.f13946a != null) {
                f();
                g();
                this.f13946a = null;
            }
        } catch (Throwable unused) {
        }
        synchronized (M) {
            jni_done(N);
            N = 0L;
        }
        new Thread(new y8.b(this, 0)).start();
        this.f13950n.t();
        this.J.a(this);
        this.J.d(this);
        super.onDestroy();
    }

    @Override
    public final void onRevoke() {
        d(getString(R.string.firewall_disabled_message), true);
    }

    @Override
    public final int onStartCommand(Intent intent, int i10, int i11) {
        return 1;
    }
}