Increase / Use / Modify smali registers

2019-07-27 03:24发布

问题:

Background: We have a code, in which we are trying to insert some debug logs. We need two extra registers per method to enable these logs.

What we have tried so far: 1) Increasing registers - Did not work as registers > v15 are breaking the code.

2) Moving v0 and v1 register values to some high value registers like v250 or something, then use v0-v1 and reassign values back from vTMP to v0-v1 - No errors but app crashes with Compile time verification error.

回答1:

It sounds like you have a good grasp of why 1) is problematic.

Re: 2) - if you're getting verification errors, then you're doing the modification incorrectly. To debug this, you'll want to look at the actual verification errors reported by art and/or dalvik when it first loads the dex file (typically at application install time). These errors are usually pretty good and give enough info to pinpoint the problem.

You might consider trying to do what you need to do without allocating any new registers. e.g. You could create a new method with your new functionality and simply insert a method call to that method and pass in whatever values/objects that it needs.