Runtime.exec/cmd

Please refer to the ProcessBuilder.start hook documentation.

CollectionFif
GroupUse.Shell
NameRuntime.exec/cmd
AuthorM66B, Fif_
Version1
Updated (UTC)2020-02-18 06:52:55
Created (UTC)2020-02-18 06:52:55
Downloads675
Class namejava.lang.Runtime
Method nameexec
Parameter typesjava.lang.String
Return typejava.lang.Process
Min SDK1
Max SDK999
Min APK0
Max APK2147483647
Excluded packages-
EnabledYes
OptionalNo
UsageYes
NotifyNo
SettingsAllowed commands (Java regex)
-- Fif.Runtime.exec* and Fif.ProcessBuilder.start are a set of Lua 
-- hook definition designed to work with XPrivacyLua.

-- Fif.Runtime.exec* and Fif.ProcessBuilder.start are 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.Runtime.exec* and Fif.ProcessBuilder.start are 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.

-- Copyright 2017-2018 Marcel Bokhorst (M66B)
-- Copyright 2020 Philippe Troin (Fif_ on XDA)

function before(hook, param)
    local name = hook:getName()
    local command
    local commandline = ''
    local commandlog = nil

    if name == 'ProcessBuilder.start' then
        local this = param:getThis()
        local commandList = this:command()
        command = commandList:toArray()
    else
        command = param:getArgument(0)
    end

    if command == nil then
        commandlog = 'null'
    elseif type(command) == 'string' then
        commandline = command
    else
        local index
        local length = command['length']
        for index = 1, length do
            if index ~= 1 then
                commandline = commandline .. ' '
            end
            commandline = commandline .. command[index]
        end
    end
    if commandlog == nil then
        commandlog = commandline
    end

    local scope = param:getApplicationContext()
    local regexObj = param:getValue('Fif.Runtime.exec.allowedCommandsRegex', scope)
    if regexObj == nil then
        local regexString = param:getSetting("Allowed commands (Java regex)")
        if regexString == nil then
            regexString = ''
        end
        local clsPattern = luajava.bindClass('java.util.regex.Pattern')
        local pattern = '^(?:(?:/system/bin/)?getprop debug\\.mapview\\..*|(?:' .. regexString .. '))$'
        log('Compiling pattern: ' .. pattern)
        regexObj = clsPattern:compile(pattern)
        param:putValue('Fif.Runtime.exec.allowedCommandsRegex', regexObj, scope)
    end

    local matcher = regexObj:matcher(commandline)
    if matcher:matches() then
        log('Allow ' .. commandlog)
        return false
    else
        log('Deny ' .. commandlog)
        local clsIoException = luajava.bindClass('java.io.IOException')
        local fake = luajava.new(clsIoException, 'Privacy')
        param:setResult(fake)
        return true, commandlog
    end
end