From 13f54700d1d2488a4dcfb962033114bd7c60e02d Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 27 Feb 2019 08:24:55 +0000 Subject: [PATCH] Use alt hosts names --- .../eu/faircode/netguard/ServiceSinkhole.java | 40 ++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java b/app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java index e95d8aac..e27432a9 100644 --- a/app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java +++ b/app/src/main/java/eu/faircode/netguard/ServiceSinkhole.java @@ -1525,6 +1525,8 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS mapHostsBlocked.clear(); + DatabaseHelper dh = DatabaseHelper.getInstance(ServiceSinkhole.this); + int count = 0; BufferedReader br = null; try { @@ -1540,6 +1542,19 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS if (words.length == 2) { count++; mapHostsBlocked.put(words[1], true); + + Cursor cursor = null; + try { + cursor = dh.getAlternateQNames(words[1]); + while (cursor != null && cursor.moveToNext()) { + String alt = cursor.getString(0); + mapHostsBlocked.put(alt, true); + Log.i(TAG, words[1] + " alt " + alt); + } + } finally { + if (cursor != null) + cursor.close(); + } } else Log.i(TAG, "Invalid hosts file line: " + line); } @@ -1811,9 +1826,32 @@ public class ServiceSinkhole extends VpnService implements SharedPreferences.OnS // Called from native code private void dnsResolved(ResourceRecord rr) { - if (DatabaseHelper.getInstance(ServiceSinkhole.this).insertDns(rr)) { + DatabaseHelper dh = DatabaseHelper.getInstance(ServiceSinkhole.this); + if (dh.insertDns(rr)) { Log.i(TAG, "New IP " + rr); prepareUidIPFilters(rr.QName); + + if (!mapHostsBlocked.containsKey(rr.QName)) { + lock.writeLock().lock(); + + Cursor cursor = null; + try { + cursor = dh.getAlternateQNames(rr.QName); + while (cursor != null && cursor.moveToNext()) { + String alt = cursor.getString(0); + if (mapHostsBlocked.containsKey(alt)) { + mapHostsBlocked.put(rr.QName, true); + Log.i(TAG, "New " + alt + " alt " + rr.QName); + break; + } + } + } finally { + if (cursor != null) + cursor.close(); + } + + lock.writeLock().unlock(); + } } }