P2X v5.6.5版本的 MD5 值为:c9754e3fb9716daeb935e470461cc2a2
以下内容为反编译后的 DNSVpnService.java 源代码,内容仅作参考
package org.sopcast.android.dnschanger;
import a0.j;
import a0.k;
import a0.l;
import a0.o;
import a0.p;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.VpnService;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.os.Parcelable;
import android.util.SparseArray;
import com.p2x.dns.phx5.R;
import java.io.IOException;
import java.lang.Thread;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.nio.channels.DatagramChannel;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Random;
import org.sopcast.android.BsConf;
import org.sopcast.android.SopHandler;
import org.sopcast.android.SplashActivity;
import org.sopcast.android.dnschanger.api.API;
import org.sopcast.android.dnschanger.api.Preferences;
import org.sopcast.android.utils.Utils;
public class DNSVpnService extends VpnService {
public static final String TAG = "DNSVpnService";
private String dns1;
private String dns1_v6;
private String dns2;
private String dns2_v6;
private l notificationBuilder;
private NotificationManager notificationManager;
private Thread thread;
private ParcelFileDescriptor tunnelInterface;
private boolean run = true;
private boolean isRunning = false;
private boolean stopped = false;
private VpnService.Builder builder = new VpnService.Builder(this);
private final int NOTIFICATION_ID = SopHandler.EVENT_FOCUS_HISTORY_BUTTON;
private Handler handler = new Handler();
private BroadcastReceiver stateRequestReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
DNSVpnService dNSVpnService = DNSVpnService.this;
dNSVpnService.broadcastServiceState(dNSVpnService.isRunning);
}
};
public void broadcastServiceState(boolean z) {
sendBroadcast(new Intent(API.BROADCAST_SERVICE_STATUS_CHANGE).putExtra("vpn_running", z));
}
public void initNotification() {
if (this.notificationBuilder == null) {
l lVar = new l(this);
this.notificationBuilder = lVar;
lVar.f37m.icon = R.drawable.vpn_ic_stat_small_icon;
lVar.f30e = l.a(getString(R.string.app_name));
this.notificationBuilder.f31f = PendingIntent.getActivity(this, 0, new Intent(this, (Class<?>) SplashActivity.class), Utils.getMutabilityFlags(true) | 134217728);
l lVar2 = this.notificationBuilder;
Notification notification = lVar2.f37m;
int i9 = notification.flags & (-17);
notification.flags = i9;
notification.flags = i9 | 2;
lVar2.f28b.add(new j(R.drawable.vpn_ic_stat_pause, getString(R.string.action_pause)));
l lVar3 = this.notificationBuilder;
lVar3.f28b.add(new j(R.drawable.vpn_ic_stat_stop, getString(R.string.action_stop)));
this.notificationBuilder.h = true;
this.notificationManager = (NotificationManager) getSystemService("notification");
}
}
public void updateNotification() {
int i9;
int i10;
String str;
int i11;
int i12;
initNotification();
if (!this.stopped && this.notificationBuilder != null && Preferences.getBoolean("setting_show_notification", false) && this.notificationManager != null) {
int mutabilityFlags = Utils.getMutabilityFlags(true) | 268435456;
j jVar = (j) this.notificationBuilder.f28b.get(0);
boolean z = this.isRunning;
if (z) {
i9 = R.drawable.vpn_ic_stat_pause;
} else {
i9 = R.drawable.vpn_ic_stat_resume;
}
jVar.f22e = i9;
if (z) {
i10 = R.string.action_pause;
} else {
i10 = R.string.action_resume;
}
jVar.f23f = getString(i10);
Intent action = new Intent(this, (Class<?>) DNSVpnService.class).setAction(new Random().nextInt(50) + "_action");
if (this.isRunning) {
str = "stop_vpn";
} else {
str = "start_vpn";
}
jVar.f24g = PendingIntent.getService(this, 0, action.putExtra(str, true), mutabilityFlags);
((j) this.notificationBuilder.f28b.get(1)).f24g = PendingIntent.getService(this, 1, new Intent(this, (Class<?>) DNSVpnService.class).setAction(API.randomString(80) + "_action").putExtra("destroy", true), mutabilityFlags);
l lVar = this.notificationBuilder;
if (this.isRunning) {
i11 = R.string.active;
} else {
i11 = R.string.paused;
}
String string = getString(i11);
lVar.getClass();
lVar.f30e = l.a(string);
l lVar2 = this.notificationBuilder;
k kVar = new k();
kVar.f26b = l.a("DNS 1: " + this.dns1 + "\nDNS 2: " + this.dns2 + "\nDNSV6 1: " + this.dns1_v6 + "\nDNSV6 2: " + this.dns2_v6);
if (lVar2.f33i != kVar) {
lVar2.f33i = kVar;
kVar.a(lVar2);
}
l lVar3 = this.notificationBuilder;
if (this.isRunning) {
i12 = R.string.notification_running;
} else {
i12 = R.string.notification_paused;
}
String string2 = getString(i12);
lVar3.getClass();
lVar3.f34j = l.a(string2);
this.handler.postDelayed(new Runnable() {
@Override
public void run() {
Bundle bundle;
if (DNSVpnService.this.notificationManager != null && DNSVpnService.this.notificationBuilder != null && !DNSVpnService.this.stopped) {
NotificationManager notificationManager = DNSVpnService.this.notificationManager;
l lVar4 = DNSVpnService.this.notificationBuilder;
lVar4.getClass();
o oVar = new o(lVar4);
l lVar5 = oVar.f40b;
k kVar2 = lVar5.f33i;
Notification.Builder builder = oVar.f39a;
SparseArray<? extends Parcelable> sparseArray = null;
if (kVar2 != null) {
new Notification.BigTextStyle(builder).setBigContentTitle(null).bigText(kVar2.f26b);
}
int i13 = Build.VERSION.SDK_INT;
if (i13 < 26 && i13 < 24) {
Bundle bundle2 = oVar.d;
if (i13 < 21 && i13 < 20) {
ArrayList arrayList = oVar.f41c;
Object obj = p.f42a;
int size = arrayList.size();
for (int i14 = 0; i14 < size; i14++) {
Bundle bundle3 = (Bundle) arrayList.get(i14);
if (bundle3 != null) {
if (sparseArray == null) {
sparseArray = new SparseArray<>();
}
sparseArray.put(i14, bundle3);
}
}
if (sparseArray != null) {
bundle2.putSparseParcelableArray("android.support.actionExtras", sparseArray);
}
}
builder.setExtras(bundle2);
}
Notification build = builder.build();
if (i13 >= 21 && kVar2 != null) {
lVar5.f33i.getClass();
}
if (kVar2 != null && (bundle = build.extras) != null) {
bundle.putString("androidx.core.app.extra.COMPAT_TEMPLATE", "androidx.core.app.NotificationCompat$BigTextStyle");
if (i13 < 21) {
bundle.putCharSequence("android.bigText", kVar2.f26b);
}
}
notificationManager.notify(SopHandler.EVENT_FOCUS_HISTORY_BUTTON, build);
}
}
}, 10L);
return;
}
NotificationManager notificationManager = this.notificationManager;
if (notificationManager != null) {
notificationManager.cancel(SopHandler.EVENT_FOCUS_HISTORY_BUTTON);
}
}
@Override
public void onCreate() {
super.onCreate();
initNotification();
registerReceiver(this.stateRequestReceiver, new IntentFilter(API.BROADCAST_SERVICE_STATE_REQUEST));
}
@Override
public void onDestroy() {
this.stopped = true;
this.run = false;
Thread thread = this.thread;
if (thread != null) {
thread.interrupt();
}
this.thread = null;
this.notificationManager.cancel(SopHandler.EVENT_FOCUS_HISTORY_BUTTON);
this.notificationManager = null;
this.notificationBuilder = null;
unregisterReceiver(this.stateRequestReceiver);
super.onDestroy();
}
@Override
public int onStartCommand(Intent intent, int i9, int i10) {
if (intent != null) {
if (intent.getBooleanExtra("stop_vpn", false)) {
Thread thread = this.thread;
if (thread != null) {
this.run = false;
thread.interrupt();
this.thread = null;
}
} else if (intent.getBooleanExtra("start_vpn", false)) {
Thread thread2 = this.thread;
if (thread2 != null) {
this.run = false;
thread2.interrupt();
}
Thread thread3 = new Thread(new Runnable() {
@Override
public void run() {
DatagramSocket datagramSocket;
DatagramChannel open;
List<String> list;
List<String> list2;
DatagramChannel datagramChannel = null;
r4 = null;
DatagramSocket datagramSocket2 = null;
datagramChannel = null;
try {
try {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread4, Throwable th) {
th.getMessage();
th.printStackTrace();
DNSVpnService.this.stopSelf();
}
});
DNSVpnService.this.initNotification();
if (DNSVpnService.this.notificationBuilder != null) {
DNSVpnService.this.notificationBuilder.f37m.when = System.currentTimeMillis();
}
DNSVpnService.this.dns1 = Preferences.DNS_1;
DNSVpnService.this.dns2 = Preferences.DNS_2;
DNSVpnService.this.dns1_v6 = Preferences.DNS_1_V6;
DNSVpnService.this.dns2_v6 = Preferences.DNS_2_V6;
String value = Utils.getValue(BsConf.DNS_IPV4_SERVER_NAME, "");
LinkedHashMap<String, List<String>> linkedHashMap = VPNUtils.serverListV4;
if (linkedHashMap.containsKey(value) && (list2 = linkedHashMap.get(value)) != null && list2.size() >= 2) {
DNSVpnService.this.dns1 = list2.get(0);
DNSVpnService.this.dns2 = list2.get(1);
}
String value2 = Utils.getValue(BsConf.DNS_IPV6_SERVER_NAME, "");
LinkedHashMap<String, List<String>> linkedHashMap2 = VPNUtils.serverListV6;
if (linkedHashMap2.containsKey(value2) && (list = linkedHashMap2.get(value2)) != null && list.size() >= 2) {
DNSVpnService.this.dns1_v6 = list.get(0);
DNSVpnService.this.dns2_v6 = list.get(1);
}
DNSVpnService dNSVpnService = DNSVpnService.this;
dNSVpnService.tunnelInterface = dNSVpnService.builder.setSession("DnsChanger").addAddress("172.31.255.250", 30).addAddress(API.randomLocalIPv6Address(), 48).addDnsServer(DNSVpnService.this.dns1).addDnsServer(DNSVpnService.this.dns2).addDnsServer(DNSVpnService.this.dns1_v6).addDnsServer(DNSVpnService.this.dns2_v6).establish();
open = DatagramChannel.open();
} catch (Exception e7) {
e7.printStackTrace();
return;
}
} catch (Exception e9) {
e = e9;
datagramSocket = null;
} catch (Throwable th) {
th = th;
datagramSocket = null;
}
try {
open.connect(new InetSocketAddress("127.0.0.1", 8087));
DNSVpnService dNSVpnService2 = DNSVpnService.this;
datagramSocket2 = open.socket();
dNSVpnService2.protect(datagramSocket2);
DNSVpnService.this.isRunning = true;
DNSVpnService.this.sendBroadcast(new Intent(API.BROADCAST_SERVICE_STATUS_CHANGE).putExtra("vpn_running", true));
DNSVpnService.this.updateNotification();
while (DNSVpnService.this.run) {
try {
Thread.sleep(250L);
} catch (InterruptedException unused) {
}
}
DNSVpnService.this.isRunning = false;
DNSVpnService.this.sendBroadcast(new Intent(API.BROADCAST_SERVICE_STATUS_CHANGE).putExtra("vpn_running", false));
DNSVpnService.this.updateNotification();
if (DNSVpnService.this.tunnelInterface != null) {
try {
DNSVpnService.this.tunnelInterface.close();
} catch (IOException e10) {
e10.printStackTrace();
}
}
try {
open.close();
} catch (Exception e11) {
e11.printStackTrace();
}
} catch (Exception e12) {
DatagramSocket datagramSocket3 = datagramSocket2;
datagramChannel = open;
e = e12;
datagramSocket = datagramSocket3;
try {
e.printStackTrace();
DNSVpnService.this.isRunning = false;
DNSVpnService.this.sendBroadcast(new Intent(API.BROADCAST_SERVICE_STATUS_CHANGE).putExtra("vpn_running", false));
DNSVpnService.this.updateNotification();
if (DNSVpnService.this.tunnelInterface != null) {
try {
DNSVpnService.this.tunnelInterface.close();
} catch (IOException e13) {
e13.printStackTrace();
}
}
if (datagramChannel != null) {
try {
datagramChannel.close();
} catch (Exception e14) {
e14.printStackTrace();
}
}
if (datagramSocket != null) {
datagramSocket.close();
}
return;
} catch (Throwable th2) {
th = th2;
DNSVpnService.this.isRunning = false;
DNSVpnService.this.sendBroadcast(new Intent(API.BROADCAST_SERVICE_STATUS_CHANGE).putExtra("vpn_running", false));
DNSVpnService.this.updateNotification();
if (DNSVpnService.this.tunnelInterface != null) {
try {
DNSVpnService.this.tunnelInterface.close();
} catch (IOException e15) {
e15.printStackTrace();
}
}
if (datagramChannel != null) {
try {
datagramChannel.close();
} catch (Exception e16) {
e16.printStackTrace();
}
}
if (datagramSocket == null) {
try {
datagramSocket.close();
throw th;
} catch (Exception e17) {
e17.printStackTrace();
throw th;
}
}
throw th;
}
} catch (Throwable th3) {
DatagramSocket datagramSocket4 = datagramSocket2;
datagramChannel = open;
th = th3;
datagramSocket = datagramSocket4;
DNSVpnService.this.isRunning = false;
DNSVpnService.this.sendBroadcast(new Intent(API.BROADCAST_SERVICE_STATUS_CHANGE).putExtra("vpn_running", false));
DNSVpnService.this.updateNotification();
if (DNSVpnService.this.tunnelInterface != null) {
}
if (datagramChannel != null) {
}
if (datagramSocket == null) {
}
}
if (datagramSocket2 != null) {
datagramSocket2.close();
}
}
});
this.thread = thread3;
this.run = true;
thread3.start();
} else if (intent.getBooleanExtra("destroy", false)) {
this.stopped = true;
Thread thread4 = this.thread;
if (thread4 != null) {
this.run = false;
thread4.interrupt();
}
stopSelf();
}
}
updateNotification();
return 1;
}
}