当前位置:网站首页>Extraction system apk

Extraction system apk

2022-06-25 23:32:00 android_ cai_ niao

Extraction system apk

Have a company Android equipment , There is a built-in application provided by the manufacturer , There should be some prompt voice in the , I want to extract the manufacturer's application , In order to obtain voice resources in the application , So a APK Extractor, But this app doesn't list the apps I need , The system application also shows , It just doesn't show the application I need . After Baidu , Found another way to extract , I have successfully extracted what I need apk.

  1. adopt adb Command lists Android All applications in the device

    adb shell pm list packages
    

    The effect is as follows :
     Insert picture description here
    Make sure that these package names contain the package names of the applications you need , You can copy these package names to Notepad , Then press search to find out if there is a package name for your application . About how to know what the package name of the required application is , You can view the following “ Get the package name of the application running at the top ” chapter .

  2. View the saving path of the application you need , Suppose the application package you want to view is named :rst.rst3.hc_client, The operation is as follows :

    adb shell pm path rst.rst3.hc_client
    

    After executing this command , You can see rst.rst3.hc_client Where to save the package name application , as follows :
     Insert picture description here
    The storage location here is /data/app/ Under the table of contents , In this directory apk All belong to the system apk Of .

  3. obtain apk, In the last step , We have found what we need apk Where to save , Copy this path , Then the operation is as follows :

    adb pull /data/app/rst.rst3.hc_client-1/base.apk
    

    The implementation effect is as follows :
     Insert picture description here
    This shows that we have succeeded in apk Saved to the computer , In the above command, we did not specify the path to save , It will be saved to the current location by default , The current position in the above command line is Even, So we are Even In the directory, you can see the newly obtained file named base.apk The application of , Use compression software to compress apk decompression , Then you can get the resource file inside , Resources like audio , It's usually kept in asserts Directory , Or save it in res/raw Directory .

    In this way , Not only can you get common applications , Even system applications can be obtained . For example, in this example ,/data/app/ The system application is saved in the directory .

Get the package name of the application running at the top

How to know the package name of an unknown application , The method is that we can run applications with unknown package names , And let it run first . Then we can write a program to detect the package name of the application running in the front , In one of my projects , There is a service class that detects the program currently running at the top , If it is detected that the first program is not ours app when , Will put their own app Run on top , Compare rogues . Here I will directly copy the code ( Currently in Android 7.1 The last test is OK Of , In a later version, I don't know if it's OK ), The code is as follows :

/** *  To the top of the stack app Check  */
class StackTopAppCheckService : Service() {
    

    private lateinit var powerManager: PowerManager

    companion object {
    
        var needMoveToTop = true
    }

    override fun onBind(intent: Intent): IBinder? = null

    private var run = false

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
    
        if (run) {
    
            //  If the check task is already running , Then return directly 
            return super.onStartCommand(intent, flags, startId)
        }

        run = true
        val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        thread {
    
            try {
    
                while (run) {
    
                    checkStackTopApp(activityManager)
                    Thread.sleep(6000) //  Every time 6 Every second 
                }
            } catch (e: Exception) {
    
                Timber.fw(e, " Check App Whether there is an exception at the top of the stack ")
            }
            Timber.fi("while Loop execution ends ")

            //  Restore variables 
            run = false
        }

        return super.onStartCommand(intent, flags, startId)
    }

    private fun checkStackTopApp(activityManager: ActivityManager) {
    
        if (!isRunningForeground(activityManager)) {
     //  If not at the top of the stack , Move to the top of the stack 
            Timber.fw(" Our application is not at the top of the stack , The current stack top application is :${
      getStackTopAppPackageName(activityManager)},needMoveToTop = $needMoveToTop")
            if (needMoveToTop) {
      //  Sometimes I don't want to play all the way to the front desk , This variable will be set to false
                moveToStackTop(activityManager)
            }
        }
    }


    fun getStackTopAppPackageName(activityManager: ActivityManager? = null): String {
    
        val manager = activityManager ?: getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
        return manager.runningAppProcesses?.find {
    
            it.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
        }?.processName ?: " Unknown "
    }

    /**  Move the law enforcement instrument to the top of the stack  */
    @Suppress("DEPRECATION")
    private fun moveToStackTop(activityManager: ActivityManager) {
    
        activityManager.getRunningTasks(100)?.find {
     it.topActivity?.packageName == App.getContext().packageName }?.let {
    
            activityManager.moveTaskToFront(it.id, 0)
        }
    }

    /**  Determine whether the application is already at the front end : When it is already at the front end , return  true; Otherwise return to  false */
    private fun isRunningForeground(activityManager: ActivityManager): Boolean {
    
        return activityManager.runningAppProcesses?.any {
    
            it.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND
            && it.processName == App.getContext().applicationInfo.processName
        } ?: false
    }



    override fun onCreate() {
    
        super.onCreate()
        Timber.fi("onCreate")
        powerManager = App.getContext().powerManager
    }

    override fun onDestroy() {
    
        super.onDestroy()
        Timber.fi("onDestroy")
        run = false
    }

}
原网站

版权声明
本文为[android_ cai_ niao]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206252033299167.html