NetGuard v2.328版本的 MD5 值为:4adaa6f0accf8a6a5ab62c36e5a5d3f8
以下内容为反编译后的 ActivityLog.java 源代码,内容仅作参考
package eu.faircode.netguard;
import B.b;
import K0.r;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.CompoundButton;
import android.widget.FilterQueryProvider;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupMenu;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.ActivityC0095q;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.SwitchCompat;
import androidx.core.app.C0127j;
import androidx.core.text.d;
import eu.faircode.netguard.DatabaseHelper;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class ActivityLog extends ActivityC0095q implements SharedPreferences.OnSharedPreferenceChangeListener {
private AdapterLog adapter;
private boolean live;
private ListView lvLog;
private boolean organization;
private boolean resolve;
private boolean running = false;
private MenuItem menuSearch = null;
private InetAddress vpn4 = null;
private InetAddress vpn6 = null;
private DatabaseHelper.LogChangedListener listener = new DatabaseHelper.LogChangedListener() {
@Override
public void onChanged() {
ActivityLog.this.runOnUiThread(new Runnable() {
@Override
public void run() {
ActivityLog.this.updateAdapter();
}
});
}
};
private Intent getIntentPCAPDocument() {
Intent intent = new Intent("android.intent.action.CREATE_DOCUMENT");
intent.addCategory("android.intent.category.OPENABLE");
intent.setType("application/octet-stream");
intent.putExtra("android.intent.extra.TITLE", "netguard_" + new SimpleDateFormat("yyyyMMdd").format(Long.valueOf(new Date().getTime())) + ".pcap");
return intent;
}
public String getUidForName(String str) {
if (str != null && str.length() > 0) {
for (Rule rule : Rule.getRules(true, this)) {
String str2 = rule.name;
if (str2 != null && str2.toLowerCase().contains(str.toLowerCase())) {
String num = Integer.toString(rule.uid);
Log.i("NetGuard.Log", "Search " + str + " found " + rule.name + " new " + num);
return num;
}
}
Log.i("NetGuard.Log", "Search " + str + " not found");
}
return str;
}
private void handleExportPCAP(final Intent intent) {
new AsyncTask() {
@Override
public Throwable doInBackground(Object... objArr) {
FileInputStream fileInputStream;
Throwable th;
OutputStream outputStream;
try {
ServiceSinkhole.setPcap(false, ActivityLog.this);
Uri data = intent.getData();
if (intent.hasExtra("org.openintents.extra.DIR_PATH")) {
data = Uri.parse(data + "/netguard.pcap");
}
Log.i("NetGuard.Log", "Export PCAP URI=" + data);
outputStream = ActivityLog.this.getContentResolver().openOutputStream(data);
try {
fileInputStream = new FileInputStream(new File(ActivityLog.this.getDir("data", 0), "netguard.pcap"));
try {
byte[] bArr = new byte[4096];
long j2 = 0;
while (true) {
int read = fileInputStream.read(bArr);
if (read <= 0) {
break;
}
outputStream.write(bArr, 0, read);
j2 += read;
}
Log.i("NetGuard.Log", "Copied bytes=" + j2);
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e2) {
r.f(e2, new StringBuilder(), "\n", e2, "NetGuard.Log");
}
}
try {
fileInputStream.close();
} catch (IOException e3) {
r.f(e3, new StringBuilder(), "\n", e3, "NetGuard.Log");
}
if (b.f(ActivityLog.this).getBoolean("pcap", false)) {
ServiceSinkhole.setPcap(true, ActivityLog.this);
}
return null;
} catch (Throwable th2) {
th = th2;
try {
Log.e("NetGuard.Log", th.toString() + "\n" + Log.getStackTraceString(th));
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e4) {
r.f(e4, new StringBuilder(), "\n", e4, "NetGuard.Log");
}
}
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e5) {
r.f(e5, new StringBuilder(), "\n", e5, "NetGuard.Log");
}
}
if (b.f(ActivityLog.this).getBoolean("pcap", false)) {
ServiceSinkhole.setPcap(true, ActivityLog.this);
}
return th;
} catch (Throwable th3) {
if (outputStream != null) {
try {
outputStream.close();
} catch (IOException e6) {
r.f(e6, new StringBuilder(), "\n", e6, "NetGuard.Log");
}
}
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (IOException e7) {
r.f(e7, new StringBuilder(), "\n", e7, "NetGuard.Log");
}
}
if (b.f(ActivityLog.this).getBoolean("pcap", false)) {
ServiceSinkhole.setPcap(true, ActivityLog.this);
}
throw th3;
}
}
} catch (Throwable th4) {
fileInputStream = null;
th = th4;
}
} catch (Throwable th5) {
fileInputStream = null;
th = th5;
outputStream = null;
}
}
@Override
public void onPostExecute(Throwable th) {
if (th == null) {
Toast.makeText(ActivityLog.this, (int) R.string.msg_completed, 1).show();
} else {
Toast.makeText(ActivityLog.this, th.toString(), 1).show();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
}
public void updateAdapter() {
if (this.adapter != null) {
SharedPreferences f = b.f(this);
this.adapter.changeCursor(DatabaseHelper.getInstance(this).getLog(f.getBoolean("proto_udp", true), f.getBoolean("proto_tcp", true), f.getBoolean("proto_other", true), f.getBoolean("traffic_allowed", true), f.getBoolean("traffic_blocked", true)));
MenuItem menuItem = this.menuSearch;
if (menuItem != null && menuItem.isActionViewExpanded()) {
this.adapter.getFilter().filter(getUidForName(((SearchView) this.menuSearch.getActionView()).getQuery().toString()));
}
}
}
@Override
public void onActivityResult(int i2, int i3, Intent intent) {
StringBuilder sb = new StringBuilder("onActivityResult request=");
sb.append(i2);
sb.append(" result=");
sb.append(i2);
sb.append(" ok=");
sb.append(i3 == -1);
Log.i("NetGuard.Log", sb.toString());
if (i2 == 1) {
if (i3 != -1 || intent == null) {
return;
}
handleExportPCAP(intent);
return;
}
Log.w("NetGuard.Log", "Unknown activity result request=" + i2);
super.onActivityResult(i2, i3, intent);
}
@Override
public void onCreate(Bundle bundle) {
if (!IAB.isPurchased("log", this)) {
startActivity(new Intent(this, ActivityPro.class));
finish();
}
Util.setTheme(this);
super.onCreate(bundle);
setContentView(R.layout.logging);
this.running = true;
View inflate = getLayoutInflater().inflate(R.layout.actionlog, (ViewGroup) null, false);
SwitchCompat switchCompat = (SwitchCompat) inflate.findViewById(R.id.swEnabled);
getSupportActionBar().d();
getSupportActionBar().b(inflate);
getSupportActionBar().e(R.string.menu_log);
getSupportActionBar().c(true);
final SharedPreferences f = b.f(this);
this.resolve = f.getBoolean("resolve", false);
this.organization = f.getBoolean("organization", false);
boolean z2 = f.getBoolean("log", false);
((TextView) findViewById(R.id.tvDisabled)).setVisibility(z2 ? 8 : 0);
switchCompat.setChecked(z2);
switchCompat.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean z3) {
d.d(f, "log", z3);
}
});
f.registerOnSharedPreferenceChangeListener(this);
this.lvLog = (ListView) findViewById(R.id.lvLog);
AdapterLog adapterLog = new AdapterLog(this, DatabaseHelper.getInstance(this).getLog(f.getBoolean("proto_udp", true), f.getBoolean("proto_tcp", true), f.getBoolean("proto_other", true), f.getBoolean("traffic_allowed", true), f.getBoolean("traffic_blocked", true)), this.resolve, this.organization);
this.adapter = adapterLog;
adapterLog.setFilterQueryProvider(new FilterQueryProvider() {
@Override
public Cursor runQuery(CharSequence charSequence) {
return DatabaseHelper.getInstance(ActivityLog.this).searchLog(charSequence.toString());
}
});
this.lvLog.setAdapter((ListAdapter) this.adapter);
try {
this.vpn4 = InetAddress.getByName(f.getString("vpn4", "10.1.10.1"));
this.vpn6 = InetAddress.getByName(f.getString("vpn6", "fd00:1:fd00:1:fd00:1:fd00:1"));
} catch (UnknownHostException e2) {
Log.e("NetGuard.Log", e2.toString() + "\n" + Log.getStackTraceString(e2));
}
this.lvLog.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView adapterView, View view, int i2, long j2) {
InetAddress inetAddress;
String str;
Intent intent;
long j3;
int i3;
PackageManager packageManager = ActivityLog.this.getPackageManager();
Cursor cursor = (Cursor) ActivityLog.this.adapter.getItem(i2);
long j4 = cursor.getLong(cursor.getColumnIndex("time"));
int i4 = cursor.getInt(cursor.getColumnIndex("version"));
int i5 = cursor.getInt(cursor.getColumnIndex("protocol"));
String string = cursor.getString(cursor.getColumnIndex("saddr"));
int i6 = cursor.isNull(cursor.getColumnIndex("sport")) ? -1 : cursor.getInt(cursor.getColumnIndex("sport"));
final String string2 = cursor.getString(cursor.getColumnIndex("daddr"));
int i7 = cursor.isNull(cursor.getColumnIndex("dport")) ? -1 : cursor.getInt(cursor.getColumnIndex("dport"));
String string3 = cursor.getString(cursor.getColumnIndex("dname"));
int i8 = cursor.isNull(cursor.getColumnIndex("uid")) ? -1 : cursor.getInt(cursor.getColumnIndex("uid"));
int i9 = cursor.isNull(cursor.getColumnIndex("allowed")) ? -1 : cursor.getInt(cursor.getColumnIndex("allowed"));
try {
inetAddress = InetAddress.getByName(string2);
} catch (UnknownHostException e3) {
Log.e("NetGuard.Log", e3.toString() + "\n" + Log.getStackTraceString(e3));
inetAddress = null;
}
if (!inetAddress.equals(ActivityLog.this.vpn4) && !inetAddress.equals(ActivityLog.this.vpn6)) {
string = string2;
i6 = i7;
}
ActivityLog activityLog = ActivityLog.this;
PopupMenu popupMenu = new PopupMenu(activityLog, activityLog.findViewById(R.id.vwPopupAnchor));
popupMenu.inflate(R.menu.log);
if (i8 >= 0) {
str = string3;
popupMenu.getMenu().findItem(R.id.menu_application).setTitle(TextUtils.join(", ", Util.getApplicationNames(i8, ActivityLog.this)));
} else {
str = string3;
popupMenu.getMenu().removeItem(R.id.menu_application);
}
popupMenu.getMenu().findItem(R.id.menu_protocol).setTitle(Util.getProtocolName(i5, i4, false));
Intent intent2 = new Intent("android.intent.action.VIEW", Uri.parse("https://www.dnslytics.com/whois-lookup/" + string));
if (packageManager.resolveActivity(intent2, 0) == null) {
popupMenu.getMenu().removeItem(R.id.menu_whois);
j3 = j4;
i3 = i9;
intent = intent2;
} else {
intent = intent2;
j3 = j4;
i3 = i9;
popupMenu.getMenu().findItem(R.id.menu_whois).setTitle(ActivityLog.this.getString(R.string.title_log_whois, string));
}
final Intent intent3 = new Intent("android.intent.action.VIEW", Uri.parse("https://www.speedguide.net/port.php?port=" + i6));
if (i6 <= 0 || packageManager.resolveActivity(intent3, 0) == null) {
popupMenu.getMenu().removeItem(R.id.menu_port);
} else {
popupMenu.getMenu().findItem(R.id.menu_port).setTitle(ActivityLog.this.getString(R.string.title_log_port, Integer.valueOf(i6)));
}
if (!f.getBoolean("filter", false)) {
popupMenu.getMenu().removeItem(R.id.menu_allow);
popupMenu.getMenu().removeItem(R.id.menu_block);
} else if (i8 <= 0) {
popupMenu.getMenu().removeItem(R.id.menu_allow);
popupMenu.getMenu().removeItem(R.id.menu_block);
}
final Packet packet = new Packet();
packet.version = i4;
packet.protocol = i5;
packet.daddr = string2;
packet.dport = i7;
long j5 = j3;
packet.time = j5;
packet.uid = i8;
packet.allowed = i3 > 0;
popupMenu.getMenu().findItem(R.id.menu_time).setTitle(DateFormat.getDateTimeInstance().format(Long.valueOf(j5)));
final int i10 = i8;
final Intent intent4 = intent;
final String str2 = str;
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.menu_allow:
if (IAB.isPurchased("filter", ActivityLog.this)) {
DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, str2, 0);
ServiceSinkhole.reload("allow host", ActivityLog.this, false);
Intent intent5 = new Intent(ActivityLog.this, ActivityMain.class);
intent5.putExtra("Search", Integer.toString(i10));
ActivityLog.this.startActivity(intent5);
} else {
ActivityLog.this.startActivity(new Intent(ActivityLog.this, ActivityPro.class));
}
return true;
case R.id.menu_application:
Intent intent6 = new Intent(ActivityLog.this, ActivityMain.class);
intent6.putExtra("Search", Integer.toString(i10));
ActivityLog.this.startActivity(intent6);
return true;
case R.id.menu_block:
if (IAB.isPurchased("filter", ActivityLog.this)) {
DatabaseHelper.getInstance(ActivityLog.this).updateAccess(packet, str2, 1);
ServiceSinkhole.reload("block host", ActivityLog.this, false);
Intent intent7 = new Intent(ActivityLog.this, ActivityMain.class);
intent7.putExtra("Search", Integer.toString(i10));
ActivityLog.this.startActivity(intent7);
} else {
ActivityLog.this.startActivity(new Intent(ActivityLog.this, ActivityPro.class));
}
return true;
case R.id.menu_copy:
ClipboardManager clipboardManager = (ClipboardManager) ActivityLog.this.getSystemService("clipboard");
String str3 = str2;
if (str3 == null) {
str3 = string2;
}
clipboardManager.setPrimaryClip(ClipData.newPlainText("netguard", str3));
return true;
case R.id.menu_port:
ActivityLog.this.startActivity(intent3);
return true;
case R.id.menu_whois:
ActivityLog.this.startActivity(intent4);
return true;
default:
return false;
}
}
});
popupMenu.show();
}
});
this.live = true;
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.logging, menu);
MenuItem findItem = menu.findItem(R.id.menu_search);
this.menuSearch = findItem;
SearchView searchView = (SearchView) findItem.getActionView();
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextChange(String str) {
if (ActivityLog.this.adapter != null) {
ActivityLog.this.adapter.getFilter().filter(ActivityLog.this.getUidForName(str));
}
return true;
}
@Override
public boolean onQueryTextSubmit(String str) {
if (ActivityLog.this.adapter != null) {
ActivityLog.this.adapter.getFilter().filter(ActivityLog.this.getUidForName(str));
}
return true;
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
if (ActivityLog.this.adapter != null) {
ActivityLog.this.adapter.getFilter().filter(null);
return true;
}
return true;
}
});
return true;
}
@Override
public void onDestroy() {
this.running = false;
this.adapter = null;
b.f(this).unregisterOnSharedPreferenceChangeListener(this);
super.onDestroy();
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
final SharedPreferences f = b.f(this);
final File file = new File(getDir("data", 0), "netguard.pcap");
int itemId = menuItem.getItemId();
if (itemId == 16908332) {
Log.i("NetGuard.Log", "Up");
C0127j.e(this);
return true;
}
switch (itemId) {
case R.id.menu_log_clear:
new AsyncTask() {
@Override
protected Object doInBackground(Object... objArr) {
boolean z2 = true | true;
DatabaseHelper.getInstance(ActivityLog.this).clearLog(-1);
if (f.getBoolean("pcap", false)) {
ServiceSinkhole.setPcap(false, ActivityLog.this);
if (file.exists() && !file.delete()) {
Log.w("NetGuard.Log", "Delete PCAP failed");
}
ServiceSinkhole.setPcap(true, ActivityLog.this);
} else if (file.exists() && !file.delete()) {
Log.w("NetGuard.Log", "Delete PCAP failed");
}
return null;
}
@Override
protected void onPostExecute(Object obj) {
if (ActivityLog.this.running) {
ActivityLog.this.updateAdapter();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Object[0]);
return true;
case R.id.menu_log_live:
menuItem.setChecked(!menuItem.isChecked());
boolean isChecked = menuItem.isChecked();
this.live = isChecked;
if (isChecked) {
DatabaseHelper.getInstance(this).addLogChangedListener(this.listener);
updateAdapter();
} else {
DatabaseHelper.getInstance(this).removeLogChangedListener(this.listener);
}
return true;
case R.id.menu_log_organization:
menuItem.setChecked(!menuItem.isChecked());
f.edit().putBoolean("organization", menuItem.isChecked()).apply();
this.adapter.setOrganization(menuItem.isChecked());
this.adapter.notifyDataSetChanged();
return true;
case R.id.menu_log_resolve:
menuItem.setChecked(!menuItem.isChecked());
f.edit().putBoolean("resolve", menuItem.isChecked()).apply();
this.adapter.setResolve(menuItem.isChecked());
this.adapter.notifyDataSetChanged();
return true;
case R.id.menu_log_support:
Intent intent = new Intent("android.intent.action.VIEW");
intent.setData(Uri.parse("https://github.com/M66B/NetGuard/blob/master/FAQ.md#user-content-faq27"));
if (getPackageManager().resolveActivity(intent, 0) != null) {
startActivity(intent);
}
return true;
default:
switch (itemId) {
case R.id.menu_pcap_enabled:
menuItem.setChecked(!menuItem.isChecked());
f.edit().putBoolean("pcap", menuItem.isChecked()).apply();
ServiceSinkhole.setPcap(menuItem.isChecked(), this);
return true;
case R.id.menu_pcap_export:
startActivityForResult(getIntentPCAPDocument(), 1);
return true;
default:
switch (itemId) {
case R.id.menu_protocol_other:
menuItem.setChecked(!menuItem.isChecked());
f.edit().putBoolean("proto_other", menuItem.isChecked()).apply();
updateAdapter();
return true;
case R.id.menu_protocol_tcp:
menuItem.setChecked(!menuItem.isChecked());
f.edit().putBoolean("proto_tcp", menuItem.isChecked()).apply();
updateAdapter();
return true;
case R.id.menu_protocol_udp:
menuItem.setChecked(!menuItem.isChecked());
f.edit().putBoolean("proto_udp", menuItem.isChecked()).apply();
updateAdapter();
return true;
case R.id.menu_refresh:
updateAdapter();
return true;
default:
switch (itemId) {
case R.id.menu_traffic_allowed:
menuItem.setChecked(!menuItem.isChecked());
f.edit().putBoolean("traffic_allowed", menuItem.isChecked()).apply();
updateAdapter();
return true;
case R.id.menu_traffic_blocked:
menuItem.setChecked(!menuItem.isChecked());
f.edit().putBoolean("traffic_blocked", menuItem.isChecked()).apply();
updateAdapter();
return true;
default:
return super.onOptionsItemSelected(menuItem);
}
}
}
}
}
@Override
public void onPause() {
super.onPause();
if (this.live) {
DatabaseHelper.getInstance(this).removeLogChangedListener(this.listener);
}
}
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
SharedPreferences f = b.f(this);
boolean z2 = false;
File file = new File(getDir("data", 0), "netguard.pcap");
boolean z3 = getPackageManager().resolveActivity(getIntentPCAPDocument(), 0) != null;
menu.findItem(R.id.menu_protocol_udp).setChecked(f.getBoolean("proto_udp", true));
menu.findItem(R.id.menu_protocol_tcp).setChecked(f.getBoolean("proto_tcp", true));
menu.findItem(R.id.menu_protocol_other).setChecked(f.getBoolean("proto_other", true));
menu.findItem(R.id.menu_traffic_allowed).setEnabled(f.getBoolean("filter", false));
menu.findItem(R.id.menu_traffic_allowed).setChecked(f.getBoolean("traffic_allowed", true));
menu.findItem(R.id.menu_traffic_blocked).setChecked(f.getBoolean("traffic_blocked", true));
menu.findItem(R.id.menu_refresh).setEnabled(!menu.findItem(R.id.menu_log_live).isChecked());
menu.findItem(R.id.menu_log_resolve).setChecked(f.getBoolean("resolve", false));
menu.findItem(R.id.menu_log_organization).setChecked(f.getBoolean("organization", false));
menu.findItem(R.id.menu_pcap_enabled).setChecked(f.getBoolean("pcap", false));
MenuItem findItem = menu.findItem(R.id.menu_pcap_export);
if (file.exists() && z3) {
z2 = true;
}
findItem.setEnabled(z2);
return super.onPrepareOptionsMenu(menu);
}
@Override
public void onResume() {
super.onResume();
if (this.live) {
DatabaseHelper.getInstance(this).addLogChangedListener(this.listener);
updateAdapter();
}
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String str) {
Log.i("NetGuard.Log", "Preference " + str + "=" + sharedPreferences.getAll().get(str));
if ("log".equals(str)) {
boolean z2 = sharedPreferences.getBoolean(str, false);
((TextView) findViewById(R.id.tvDisabled)).setVisibility(z2 ? 8 : 0);
SwitchCompat switchCompat = (SwitchCompat) getSupportActionBar().a().findViewById(R.id.swEnabled);
if (switchCompat.isChecked() != z2) {
switchCompat.setChecked(z2);
}
ServiceSinkhole.reload("changed " + str, this, false);
}
}
}