Proxy Master v3.4.9版本的 MD5 值为:14d0aa2468d13530c8f6e96bcc114bf5
以下内容为反编译后的 OpenVPNService.java 源代码,内容仅作参考
package de.blinkt.openvpn.core;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.UiModeManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.net.ProxyInfo;
import android.net.Uri;
import android.net.VpnService;
import android.os.Build;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.IBinder;
import android.os.Message;
import android.text.TextUtils;
import android.widget.Toast;
import com.google.android.gms.games.Games;
import com.yandex.mobile.ads.impl.z32;
import de.blinkt.openvpn.R$drawable;
import de.blinkt.openvpn.R$string;
import de.blinkt.openvpn.core.b;
import de.blinkt.openvpn.core.e;
import de.blinkt.openvpn.core.j;
import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Set;
import java.util.Vector;
public class OpenVPNService extends VpnService implements j.c, Handler.Callback, j.a, b {
public static boolean f21767z;
public wa.g f21773g;
public int f21776j;
public de.blinkt.openvpn.core.a f21778l;
public long f21781o;
public g f21782p;
public Bitmap f21783q;
public String f21785s;
public String f21786t;
public Handler f21787u;
public Toast f21788v;
public ProxyInfo f21789w;
public HandlerThread f21790x;
public Handler f21791y;
public final Vector<String> f21768b = new Vector<>();
public final e f21769c = new e();
public final e f21770d = new e();
public final Object f21771e = new Object();
public Thread f21772f = null;
public String f21774h = null;
public o.f f21775i = null;
public String f21777k = null;
public boolean f21779m = false;
public boolean f21780n = false;
public final a f21784r = new a();
public class a extends b.a {
public a() {
}
@Override
public final boolean a(boolean z6) {
return OpenVPNService.this.a(z6);
}
@Override
public final boolean c(String str) {
return OpenVPNService.this.c(str);
}
@Override
public final void h(boolean z6) {
OpenVPNService.this.h(z6);
}
@Override
public final boolean protect(int i10) {
return OpenVPNService.this.protect(i10);
}
@Override
public final void r(String str) {
OpenVPNService.this.r(str);
}
}
public static boolean B(String str) {
return str != null && (str.startsWith("tun") || "(null)".equals(str) || "vpnservice-tun".equals(str));
}
public static String z(long j10, boolean z6, Resources resources) {
if (z6) {
j10 *= 8;
}
double d10 = j10;
double d11 = z6 ? 1000 : 1024;
int max = Math.max(0, Math.min((int) (Math.log(d10) / Math.log(d11)), 3));
float pow = (float) (d10 / Math.pow(d11, max));
return z6 ? max != 0 ? max != 1 ? max != 2 ? resources.getString(R$string.gbits_per_second, Float.valueOf(pow)) : resources.getString(R$string.mbits_per_second, Float.valueOf(pow)) : resources.getString(R$string.kbits_per_second, Float.valueOf(pow)) : resources.getString(R$string.bits_per_second, Float.valueOf(pow)) : max != 0 ? max != 1 ? max != 2 ? resources.getString(R$string.volume_gbyte, Float.valueOf(pow)) : resources.getString(R$string.volume_mbyte, Float.valueOf(pow)) : resources.getString(R$string.volume_kbyte, Float.valueOf(pow)) : resources.getString(R$string.volume_byte, Float.valueOf(pow));
}
public final void A(VpnService.Builder builder, e eVar) {
Iterator it = eVar.a(true).iterator();
while (it.hasNext()) {
e.a aVar = (e.a) it.next();
try {
builder.addRoute(aVar.i());
} catch (IllegalArgumentException | UnknownHostException e10) {
j.l(getString(R$string.route_rejected) + aVar + " " + e10.getLocalizedMessage());
}
}
Iterator it2 = eVar.a(false).iterator();
while (it2.hasNext()) {
e.a aVar2 = (e.a) it2.next();
try {
builder.excludeRoute(aVar2.i());
} catch (IllegalArgumentException | UnknownHostException e11) {
j.l(getString(R$string.route_rejected) + aVar2 + " " + e11.getLocalizedMessage());
}
}
}
public final void C(String str, String str2, String str3, long j10, ConnectionStatus connectionStatus, Intent intent) {
try {
NotificationManager notificationManager = (NotificationManager) getSystemService("notification");
Notification.Builder builder = new Notification.Builder(this);
char c10 = str3.equals("myvpn_bg") ? (char) 65534 : str3.equals("myvpn_userreq") ? (char) 2 : (char) 0;
wa.g gVar = this.f21773g;
if (gVar != null) {
builder.setContentTitle(gVar.f36222c);
} else {
builder.setContentTitle(getString(R$string.notifcation_title_notconnect));
}
builder.setContentText(str);
builder.setOnlyAlertOnce(true);
builder.setOngoing(true);
builder.setSmallIcon(R$drawable.ic_notification);
Bitmap bitmap = this.f21783q;
if (bitmap != null && !bitmap.isRecycled()) {
builder.setLargeIcon(this.f21783q);
}
if (connectionStatus == ConnectionStatus.LEVEL_WAITING_FOR_USER_INPUT) {
builder.setContentIntent(PendingIntent.getActivity(this, 0, intent, 67108864));
} else {
builder.setContentIntent(w());
}
if (j10 != 0) {
builder.setWhen(j10);
}
builder.setCategory("service");
builder.setLocalOnly(true);
if (Build.VERSION.SDK_INT >= 26) {
builder.setChannelId(str3);
wa.g gVar2 = this.f21773g;
if (gVar2 != null) {
builder.setShortcutId(gVar2.j());
}
}
if (str2 != null && !str2.equals("")) {
builder.setTicker(str2);
}
Notification notification = builder.getNotification();
int hashCode = str3.hashCode();
notificationManager.notify(hashCode, notification);
startForeground(hashCode, notification);
if (!(((UiModeManager) getSystemService("uimode")).getCurrentModeType() == 4) || c10 < 0) {
return;
}
this.f21787u.post(new t0.b(25, this, str));
} catch (Exception e10) {
e10.printStackTrace();
}
}
public final synchronized void D(de.blinkt.openvpn.core.a aVar) {
if (this.f21778l != null) {
try {
LinkedList<LogItem> linkedList = j.f21877a;
synchronized (j.class) {
j.f21880d.remove(aVar);
}
unregisterReceiver(aVar);
} catch (IllegalArgumentException e10) {
e10.printStackTrace();
}
}
}
@Override
public final boolean a(boolean z6) {
g gVar = this.f21782p;
if (gVar != null) {
boolean i10 = g.i();
if (i10) {
gVar.f21860m = true;
}
return i10;
}
return false;
}
@Override
public final IBinder asBinder() {
return this.f21784r;
}
@Override
public final boolean c(String str) {
return new ya.a(this).b(this, str);
}
@Override
public final void d(long j10, long j11, long j12, long j13) {
if (this.f21779m) {
C(String.format(getString(R$string.statusline_bytecount), z(j10, false, getResources()), z(j12 / 2, true, getResources()), z(j11, false, getResources()), z(j13 / 2, true, getResources())), null, "myvpn_bg", this.f21781o, ConnectionStatus.LEVEL_CONNECTED, null);
}
}
@Override
public final void h(boolean z6) {
de.blinkt.openvpn.core.a aVar = this.f21778l;
if (aVar != null) {
aVar.e(z6);
}
}
@Override
public final boolean handleMessage(Message message) {
Runnable callback = message.getCallback();
if (callback != null) {
callback.run();
return true;
}
return false;
}
@Override
public final void j(String str) {
}
@Override
public final void k(String str, String str2, int i10, ConnectionStatus connectionStatus, Intent intent) {
String str3;
Intent intent2 = new Intent();
intent2.setAction("de.blinkt.openvpn.VPN_STATUS");
intent2.putExtra(Games.EXTRA_STATUS, connectionStatus.toString());
intent2.putExtra("detailstatus", str);
sendBroadcast(intent2, "android.permission.ACCESS_NETWORK_STATE");
if (this.f21772f != null || f21767z) {
if (connectionStatus == ConnectionStatus.LEVEL_CONNECTED) {
this.f21779m = true;
this.f21781o = System.currentTimeMillis();
if (!(((UiModeManager) getSystemService("uimode")).getCurrentModeType() == 4)) {
str3 = "myvpn_bg";
C(j.d(this), j.d(this), str3, 0L, connectionStatus, intent);
}
} else {
this.f21779m = false;
}
str3 = "myvpn_newstat";
C(j.d(this), j.d(this), str3, 0L, connectionStatus, intent);
}
}
@Override
public final IBinder onBind(Intent intent) {
String action = intent.getAction();
return (action == null || !action.equals("de.blinkt.openvpn.START_SERVICE")) ? super.onBind(intent) : this.f21784r;
}
@Override
public final void onCreate() {
super.onCreate();
this.f21787u = new Handler(getMainLooper());
HandlerThread handlerThread = new HandlerThread("OpenVPNServiceCommandThread");
this.f21790x = handlerThread;
handlerThread.start();
this.f21791y = new Handler(this.f21790x.getLooper());
this.f21783q = r7.h.a(r7.a.a());
}
@Override
public final void onDestroy() {
synchronized (this.f21771e) {
try {
if (this.f21772f != null) {
g gVar = this.f21782p;
gVar.getClass();
if (g.i()) {
gVar.f21860m = true;
}
}
} catch (Throwable th) {
throw th;
}
}
de.blinkt.openvpn.core.a aVar = this.f21778l;
if (aVar != null) {
D(aVar);
this.f21778l = null;
}
j.v(this);
za.e eVar = j.f21895s;
if (eVar != null) {
eVar.sendEmptyMessage(101);
}
try {
if (this.f21783q.isRecycled()) {
return;
}
this.f21783q.recycle();
} catch (Exception e10) {
e10.printStackTrace();
}
}
@Override
public final void onRevoke() {
j.j(R$string.permission_revoked);
g gVar = this.f21782p;
gVar.getClass();
if (g.i()) {
gVar.f21860m = true;
}
v();
}
@Override
public final int onStartCommand(Intent intent, int i10, int i11) {
if (intent != null && intent.getBooleanExtra("de.blinkt.openvpn.NOTIFICATION_ALWAYS_VISIBLE", false)) {
f21767z = true;
}
j.c(this);
j.a(this);
if (intent != null && "de.blinkt.openvpn.PAUSE_VPN".equals(intent.getAction())) {
de.blinkt.openvpn.core.a aVar = this.f21778l;
if (aVar != null) {
aVar.e(true);
}
return 2;
} else if (intent != null && "de.blinkt.openvpn.RESUME_VPN".equals(intent.getAction())) {
de.blinkt.openvpn.core.a aVar2 = this.f21778l;
if (aVar2 != null) {
aVar2.e(false);
}
return 2;
} else if (intent == null || !"de.blinkt.openvpn.START_SERVICE".equals(intent.getAction())) {
if (intent == null || !"de.blinkt.openvpn.START_SERVICE_STICKY".equals(intent.getAction())) {
int i12 = R$string.building_configration;
j.o(i12, new Object[0]);
ConnectionStatus connectionStatus = ConnectionStatus.LEVEL_START;
j.A("VPN_GENERATE_CONFIG", "", i12, connectionStatus);
C(j.d(this), j.d(this), "myvpn_newstat", 0L, connectionStatus, null);
this.f21791y.post(new z32(this, intent, i11));
return 1;
}
return 3;
} else {
return 2;
}
}
@Override
public final void r(String str) {
Set<String> stringSet = ad.h.n0(this).getStringSet("allowed_apps", new HashSet());
stringSet.add(str);
SharedPreferences n02 = ad.h.n0(this);
SharedPreferences.Editor edit = n02.edit();
edit.putStringSet("allowed_apps", stringSet);
edit.putInt("counter", n02.getInt("counter", 0) + 1);
edit.apply();
}
public final void t(String str, String str2, String str3, String str4) {
o.f fVar = new o.f(str, str2);
boolean B = B(str4);
e.a aVar = new e.a(new o.f(str3, 32), false);
o.f fVar2 = this.f21775i;
if (fVar2 == null) {
j.l("Local IP address unset and received. Neither pushed server config nor local config specifies an IP addresses. Opening tun device is most likely going to fail.");
return;
}
if (new e.a(fVar2, true).a(aVar)) {
B = true;
}
if (str3 != null && (str3.equals("255.255.255.255") || str3.equals(this.f21786t))) {
B = true;
}
if (fVar.f29035c == 32 && !str2.equals("255.255.255.255")) {
j.s(R$string.route_not_cidr, str, str2);
}
if (fVar.c()) {
j.s(R$string.route_not_netip, str, Integer.valueOf(fVar.f29035c), (String) fVar.f29034b);
}
this.f21769c.f21837a.add(new e.a(fVar, B));
}
public final void u(String str, boolean z6) {
String[] split = str.split("/");
try {
this.f21770d.f21837a.add(new e.a((Inet6Address) InetAddress.getAllByName(split[0])[0], Integer.parseInt(split[1]), z6));
} catch (UnknownHostException e10) {
j.n(e10);
}
}
public final void v() {
synchronized (this.f21771e) {
this.f21772f = null;
}
LinkedList<LogItem> linkedList = j.f21877a;
synchronized (j.class) {
j.f21880d.remove(this);
}
D(this.f21778l);
this.f21778l = null;
SharedPreferences.Editor edit = ad.h.n0(this).edit();
edit.putString("lastConnectedProfile", null);
edit.apply();
if (this.f21780n) {
return;
}
stopForeground(!f21767z);
if (f21767z) {
return;
}
stopSelf();
j.v(this);
}
public final PendingIntent w() {
Intent intent = new Intent();
intent.setAction("android.intent.action.VIEW");
intent.setPackage(getApplicationContext().getPackageName());
intent.putExtra("PAGE", "graph");
intent.addFlags(131072);
PendingIntent activity = PendingIntent.getActivity(this, 0, intent, 67108864);
intent.addFlags(131072);
return activity;
}
public final String x() {
String str = "TUNCFG UNQIUE STRING ips:";
if (this.f21775i != null) {
str = "TUNCFG UNQIUE STRING ips:" + this.f21775i.toString();
}
if (this.f21777k != null) {
StringBuilder b6 = o.h.b(str);
b6.append(this.f21777k);
str = b6.toString();
}
StringBuilder t10 = android.support.v4.media.b.t(str, "routes: ");
e eVar = this.f21769c;
t10.append(TextUtils.join("|", eVar.a(true)));
e eVar2 = this.f21770d;
t10.append(TextUtils.join("|", eVar2.a(true)));
StringBuilder t11 = android.support.v4.media.b.t(t10.toString(), "excl. routes:");
t11.append(TextUtils.join("|", eVar.a(false)));
t11.append(TextUtils.join("|", eVar2.a(false)));
StringBuilder t12 = android.support.v4.media.b.t(t11.toString(), "dns: ");
t12.append(TextUtils.join("|", this.f21768b));
StringBuilder t13 = android.support.v4.media.b.t(t12.toString(), "domain: ");
t13.append(this.f21774h);
StringBuilder t14 = android.support.v4.media.b.t(t13.toString(), "mtu: ");
t14.append(this.f21776j);
StringBuilder t15 = android.support.v4.media.b.t(t14.toString(), "proxyInfo: ");
t15.append(this.f21789w);
return t15.toString();
}
public final Intent y(String str, boolean z6, Notification.Builder builder) {
builder.setContentTitle(getString(R$string.openurl_requested));
builder.setContentText(str);
Intent intent = z6 ? new Intent("android.intent.action.VIEW") : new Intent(this, xa.c.class);
intent.setData(Uri.parse(str));
intent.addFlags(268435456);
return intent;
}
}