Replace new dexlib2 failing method

I am using dexlib2 to overwrite an existing apk through a single jar utility. I want to change one instruction with my own instruction. It basically returns some object, and I want to replace it with another method that returns another object. It can replace the method, but when I looked at the updated dex, I see the following line with .local v1, manager: Lblah / KeyguardManager;

The code I want to replace

KeyguardManager keyguardManager = (KeyguardManager) getSystemService(KEYGUARD_SERVICE); 

Code to be replaced above:

 Manager mgr=Manager.getInstance(this) 

I used the getInstructionRewriter method to replace it. It replaces the method, but I cannot figure out how to replace .local v1, manager: Lblah / KeyguardManager; with .local v1, manager: Lblah / Manager;

+7
java android dex smali
source share
1 answer

You must make sure that Lblah/Manager exists in your apk. If you just want to make this change in one .smali file and leave the other files unchanged, it will be easy. You must clear all KeyguardManager events in this file and replace the call they make with the corresponding call in the Manager class. Then repack your apk and test it.

If you encounter an error while reconstructing the apk file or after installing a new apk, there may be some inconsistencies in the cahnges you made, and you need to find out what the problem is. In this case, you can post an error here, and we will see what we can do! :)

0
source share

All Articles