On Aug 17, 5:16 pm, fadden <
fad...@android.com> wrote:
> On Aug 17, 9:03 am, msg555 <
msg...@gmail.com> wrote:
>
> > Thanks, I think I've found all of the information I need. deodexing
> > isn't my only goal, I also want to be able to write out odex files.
> > It seems that the interpretation of the odex file is highly dependent
> > on the dalvik vm version that created it, though hopefully I can
> > support those that are in use today.
>
> Why? Why not write a simple DEX and let dexopt do the work?
The use case is when I have to work with an already optimized odex
file (most phones it seems have the bootstrap classes pre-optimized
and these are what I want to work with). For instance I would want to
be able to add function hooks to some of the methods. I have this
working for dex files by inserting new hooking methods and putting an
invoke-direct/range instruction at the beginning of each function I
want to hook.
I feel like it would be easier to write back out an odex file rather
than trying to go from odex->dex then writing out a dex file. This
way I can treat the inline indexes, object offsets, and vtable indexes
abstractly and just write them out as I read them in assuming I do
nothing that would change their alignment. This option would also
result in the extra files being written to the dalvik-cache.
>
> > At this point I understand how the instance variables are aligned and
> > methods are set up and what the inline indexes mean though I haven't
> > written any code to actually interpret these yet. I have at this
> > point been successful in reading in the odex files and am working on
> > writing them back out. Just need to generate the class lookup table
> > and register maps. Which brings me to a few question.
>
> Field position and vtable ordering a subject to change from release to
> release. In practice these don't change much, but the execute-inline
> table has changed with every release (and not in a backward-compatible
> way).
>
I understand. And hopefully most of the time I can just treat these
numbers as black boxes and not know what they mean. If I want to try
to reverse the process I think I should be able to check the vm
version in the odex file to know the format (or at least know if I
support the format).
> Optimized DEX files are expected to be generated and used by the same
> version of the VM running on the same device. They're not meant to be
> copied between devices or work across an upgrade.
>
I understand, this is not my intention. Same odex file for the same
phone.
> > Are the expanding or reducing index maps used in production yet?
>
> No. This was a mostly dead end.
Ok, less work for me :)
>
> > What would happen if I replaced a bootstrap odex file like /system/
> > framework/framework.odex with another mostly equivalent odex file that
> > didn't have a class lookup table or didn't have register maps? I
> > imagine there would be a performance hit if it works at all?
>
> You'll need to keep the SHA-1 signature the same or the embedded
> dependency lists won't match. The class lookup table needs to be
> present. Register maps are optional; the GC will fall back to a
> conservative scan if they're not present.
Ok, so it sounds like this should be able to work in theory. I'll see
how it goes.
Thanks for the help
-Mark