forked from M66B/XPrivacyLua
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook_148.json
1 lines (1 loc) · 5.04 KB
/
hook_148.json
1
{"builtin":false,"collection":"Intika-Google-FCM","group":"Use firebase","name":"PackageManager.getPackageInfo\/versionedPackage","author":"Intika","version":2,"description":"Use firebase (Block Google Firebase Cloud Messaging)\nDescription: Check main hook\nPart: 11\/15 (Optional)","className":"android.content.pm.PackageManager","methodName":"getPackageInfo","parameterTypes":["android.content.pm.VersionedPackage","int"],"returnType":"android.content.pm.PackageInfo","minSdk":26,"maxSdk":999,"minApk":0,"maxApk":2147483647,"enabled":true,"optional":false,"usage":true,"notify":false,"luaScript":"-- Copyright (C) 2022 Intika\n-- Copyright (C) 2018 Philippe Troin (Fif_ on XDA)\n\n-- This is free software: you can redistribute it and\/or modify\n-- it under the terms of the GNU General Public License as published by\n-- the Free Software Foundation, either version 3 of the License, or\n-- (at your option) any later version.\n\n-- This is distributed in the hope that it will be useful,\n-- but WITHOUT ANY WARRANTY; without even the implied warranty of\n-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n-- GNU General Public License for more details.\n\n-- You should have received a copy of the GNU General Public License\n-- along with XPrivacyLua. If not, see <http:\/\/www.gnu.org\/licenses\/>.\n\nfunction after(hook, param)\n local result = param:getResult()\n if result == nil then\n return false\n end\n\n local scope = param:getApplicationContext()\n local applicationInfo, packageName\n local hookName = hook:getName()\n local hookNameGetPackageInfo = 'PackageManager.getPackageInfo'\n local hookNameGetPackage = 'PackageManager.getPackage'\n local hookNameGetApplication = 'PackageManager.getApplication'\n\n if hookName:sub(1, hookNameGetPackage:len()) == hookNameGetPackage then\n local packageInfo\n if hookName:sub(1, hookNameGetPackageInfo:len()) == hookNameGetPackageInfo then\n if (hookName == 'PackageManager.getPackageInfo\/packageName' \n or hookName == 'PackageManager.getPackageInfoAsUser' )\n and param:getValue('Intika.PackageManager.getPackage.selfCall.package.' .. param:getArgument(0), scope) == '1' then\n return false\n end\n packageInfo = result\n else\n local pm = param:getThis()\n -- Ugh, our hooked version of getPackageInfo can throw and exception\n -- which will show up as an error (even though the hooks together \n -- performed as expected). Signal to the other hook this is us calling ourselves.\n param:putValue('Intika.PackageManager.getPackage.selfCall.package.' .. param:getArgument(0), '1', scope)\n packageInfo = pm:getPackageInfo(param:getArgument(0), 0)\n param:putValue('Intika.PackageManager.getPackage.selfCall.package.' .. param:getArgument(0), nil, scope)\n end\n applicationInfo = packageInfo.applicationInfo\n packageName = packageInfo.packageName\n elseif hookName:sub(1, hookNameGetApplication:len()) == hookNameGetApplication then\n if hookName == 'PackageManager.getApplicationInfo' or hookName == 'PackageManager.getApplicationInfoAsUser' then\n if param:getValue('Intika.PackageManager.getPackage.selfCall.application.' .. param:getArgument(0), scope) == '1' then\n return false\n end\n applicationInfo = result\n else\n local pm = param:getThis()\n -- Ugh, our hooked version of getApplicationInfo can throw and exception\n -- which will show up as an error (even though the hooks together \n -- performed as expected). Signal to the other hook this is us calling ourselves.\n param:putValue('Intika.PackageManager.getPackage.selfCall.application.' .. param:getArgument(0), '1', scope)\n applicationInfo = pm:getApplicationInfo(param:getArgument(0), 0)\n param:putValue('Intika.PackageManager.getPackage.selfCall.application.' .. param:getArgument(0), nil, scope)\n end\n packageName = param:getArgument(0)\n else\n local crash = \"Unexpected hookName=\" .. hookName\n crash.crash()\n end\n\n if packageName ~= 'com.google.android.gms' and packageName ~= 'com.google.android.gsf' then\n -- not our target\n return false \n end\n\n local cuid = param:getUid()\n -- if hookName:sub(-6) == 'AsUser' then\n -- cuid = param:getArgument(2)\n -- end\n\n if cuid == applicationInfo.uid then\n -- allow same uid\n return false\n end\n\n local clsException\n if hookName == 'PackageManager.getApplicationEnabledSetting' then\n clsException = luajava.bindClass('java.lang.IllegalArgumentException')\n else\n clsException = luajava.bindClass('android.content.pm.PackageManager$NameNotFoundException')\n end\n local fake = luajava.new(clsException, packageName)\n param:setResult(fake)\n log('Deny ' .. packageName)\n return true, packageName, tostring(fake)\nend\n"}