Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package app.revanced.patches.all.deviceadmin
- import app.revanced.patcher.patch.*
- import app.revanced.patcher.patch.resourcePatch
- import app.revanced.patcher.patch.smaliPatch
- import app.revanced.util.Utils
- import org.w3c.dom.Element
- import java.io.File
- val deviceAdminPatch = Patch(
- name = "Device Admin Patch",
- description = "make any app into a Device Admin",
- use = true
- ) {
- // mofify andManifest
- resourcePatch {
- execute {
- document("AndroidManifest.xml").use { document ->
- val applicationNode = document.getElementsByTagName("application").item(0) as Element
- val receiverNode = document.createElement("receiver").apply {
- setAttribute("android:name", ".MyDeviceAdminReceiver")
- setAttribute("android:label", "@string/app_name")
- setAttribute("android:permission", "android.permission.BIND_DEVICE_ADMIN")
- }
- applicationNode.appendChild(receiverNode)
- val metaNode = document.createElement("meta-data").apply {
- setAttribute("android:name", "android.app.device_admin")
- setAttribute("android:resource", "@xml/device_admin")
- }
- receiverNode.appendChild(metaNode)
- val intentFilter = document.createElement("intent-filter").apply {
- val actionNode = document.createElement("action").apply {
- setAttribute("android:name", "android.app.action.DEVICE_ADMIN_ENABLED")
- }
- appendChild(actionNode)
- }
- receiverNode.appendChild(intentFilter)
- }
- }
- }
- // aadd device_admin.xml
- resourcePatch {
- execute {
- val resXmlDirectory = get("res/xml")
- File(resXmlDirectory, "device_admin.xml").apply {
- writeText(
- """
- <?xml version="1.0" encoding="utf-8"?>
- <device-admin xmlns:android="http://schemas.android.com/apk/res/android">
- <uses-policies>
- <limit-password />
- <watch-login />
- </uses-policies>
- </device-admin>
- """.trimIndent()
- )
- }
- }
- }
- // add DeviceAdminReceiver smali class
- smaliPatch {
- execute {
- val packageName = Utils.getPackageName("AndroidManifest.xml")
- val smaliDirectory = get("smali/${packageName.replace('.', '/')}/MyDeviceAdminReceiver.smali")
- File(smaliDirectory).apply {
- writeText(
- """
- .class public L${packageName.replace('.', '/')}/MyDeviceAdminReceiver;
- .super Landroid/app/admin/DeviceAdminReceiver;
- .method public constructor <init>()V
- .locals 0
- invoke-direct {p0}, Landroid/app/admin/DeviceAdminReceiver;-><init>()V
- return-void
- .end method
- """.trimIndent()
- )
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement