3

In dex code (e.g., as produced by the dexdump tool), for each method definition I see "ins" and "outs" in addition to other metadata such as "registers", "insns size".

I am instrumenting dex code to introduce new registers. The instrumentation is failing, and I suspect that I may have to change the "ins" and "outs" values based on the number of new registers I add.

So my question is: What do those "ins" and "outs" represent?

(fyi: I am using dexlib2 for this.)

Saswat Anand
  • 358
  • 2
  • 10

1 Answers1

4

These fields are documented at http://source.android.com/devices/tech/dalvik/dex-format.html.

ins_size | the number of words of incoming arguments to the method that this code is for

outs_size | the number of words of outgoing argument space required by this code for method invocation

ins_size is mostly self-explanatory - it's the number of 32-bit words required to store the method arguments (including the implicit "this" argument, for non-static methods). All arguments require 1 "word" except longs (J) and doubles (D), which require 2 words.

outs_size basically the opposite. outs_size must be set large enough to hold the arguments for any method call that occurs within the method.

If you want to instrument a dex file without having to worry about details like this, you might consider using dexlib2 (the library developed for and used by smali/baksmali to read/write dex files). The library is available in the maven repository, so it's easy to link against if you're using gradle/mvn.

Community
  • 1
  • 1
JesusFreke
  • 19,784
  • 5
  • 65
  • 68
  • I am using MutableMethodImplementation of dexlib2 to do the instrumentation. – Saswat Anand Dec 04 '14 at 01:11
  • You don't have to worry about ins and outs then. dexlib2 will calculate them appropriately when you write out the new dex file. Your problem likely lies is clobbering some register with the modification you made, or something similar. I recommend looking at logcat during app installation for any dalvik/art verification errors. – JesusFreke Dec 04 '14 at 08:58