InetAddress.getAllByName

This hook prevents apps from getting a successful DNS resolution for a user-defined list of domains. The host/domain blacklist can be edited with XPrivacyLua Pro, under "Custom Values", "Firewall host/domain blacklist". List items are whitespace separated, and will match the whole string and/or any subdomains. For example, if the blacklist is "google.com facebook.com", all of google.com, www.google.com, we.love.google.com and www.facebook.com will be blocked.

CollectionFif
GroupInternet.Firewall
NameInetAddress.getAllByName
AuthorFif_
Version4
Updated (UTC)2018-03-22 20:53:11
Created (UTC)2018-02-20 23:00:04
Downloads1566
Class namejava.net.InetAddress
Method namegetAllByName
Parameter typesjava.lang.String
Return type[Ljava.net.InetAddress;
Min SDK1
Max SDK999
Min APK0
Max APK2147483647
Excluded packages-
EnabledYes
OptionalNo
UsageYes
NotifyNo
SettingsFirewall host/domain blacklist
-- Fif.InetAdress.getXByName is a Lua hook designed to work with XPrivacyLua.
-- Copyright (C) 2018 Philippe Troin (Fif_ on XDA)

-- Fif.InetAdress.getXByName is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.

-- Fif.InetAdress.getXByName is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.

-- You should have received a copy of the GNU General Public License
-- along with XPrivacyLua.  If not, see <http://www.gnu.org/licenses/>.

function before(hook, param)
    local scope = param:getApplicationContext()
    local BlacklistHosts = param:getValue('Fif.InetAddress.getXByName.BlacklistHosts', scope)
    if BlacklistHosts == nil then
        local blacklist = param:getSetting("Firewall host/domain blacklist")
        BlacklistHosts = {}
        local blacklistLog = {}
        if blacklist ~= nil then
            blacklist:gsub('[%S]+', function(x) local h = x:gsub('[.]*$', ''):lower() BlacklistHosts[h] = true table.insert(blacklistLog, h) end)
        end
        param:putValue('Fif.InetAddress.getXByName.BlacklistHosts', BlacklistHosts, scope)
        log('DNS blacklist: ' .. table.concat(blacklistLog, ', '))
    end

    local host = param:getArgument(0)
    local pass = true
    if host == nil then
        host = '(null)'
    else
        local shost = host:gsub('[.]*$', ''):lower()
        while true do
            if BlacklistHosts[shost] == true then
                pass = false
                break
            else
                local nsubs
                shost, nsubs = shost:gsub('^[^.]*[.]', '')
                if nsubs ~= 1 then
                    break
                end
            end
        end
    end
    if pass then
        log('Allow ' .. host)
        return false
    else
        log('Deny ' .. host)
        local clsHostNotFound = luajava.bindClass('java.net.UnknownHostException')
        local fake = luajava.new(clsHostNotFound, 'Privacy')
        param:setResult(fake)
        return true, host
    end
end