619 Commits

Author SHA1 Message Date
Ben Gruver
1590b4a05e Use HeaderItem.ITEM_SIZE in the new DexBackedDexFile constructor 2020-01-22 16:50:28 -08:00
Huaxin Li
b7a1052c66 Add support for constructing a DexBackedDexFile from a DexBuffer 2020-01-22 16:50:20 -08:00
Ben Gruver
b3b8778ef8 Add support for Oat versions up to 173
The only relevant differences are some added/removed fields in the
OatHeader that affect the offsets of some fields we use.
2019-10-02 16:36:26 -07:00
Ben Gruver
539353a85c Use the correct path separator character when looking for classpath entries 2019-10-02 16:34:04 -07:00
Ben Gruver
751fe1ce61 Fix Preconditions.checkArrayPayloadElements
The previous implementation did not correctly handle negative numbers.
2019-09-12 11:30:27 -07:00
Ben Gruver
cf73ce28fd Fix the getters in ImmutableInstruction45cc 2019-08-28 12:15:05 -07:00
Ben Gruver
3b70c36296 Add better error messages when finding embedded dex files for oat files 2019-08-23 14:19:07 -07:00
Ben Gruver
bdbea44b98 Gracefully handle malformed array payload instructions with element width=0
These get handled as if they had element width=1 and element count=0
2019-08-23 14:04:40 -07:00
Ben Gruver
225a00c768 Use DexBacked* classes for the various sections in DexBackedDexFile 2019-08-23 11:22:13 -07:00
Alex Melkonyan
b044a00353 Fix bug #709 2019-08-23 11:16:30 -07:00
Ben Gruver
a29a420d2f Update the version map to reflect the released version of api 28 2019-08-07 14:49:31 -07:00
Ben Gruver
1ac14a1082 Add a workaround for the sym linked vdex files in api 28
In api 28, the vdex files in, e.g. the framework/arm directory are actually
just sym links to a shared vdex file in the framework directory. However,
the sym links use an absolute path, and so they don't resolve correctly in
the loop mounted system image.

As a simple workaround, we'll just search upward one directory in the path
if the vdex file can't be resolved.
2019-08-07 14:12:19 -07:00
Ben Gruver
c639d229c6 Add support for the new debug offset table for cdex files 2019-08-07 14:12:19 -07:00
Ben Gruver
8e4391262d Some dex files are listed in the oat file, but aren't present in the oat/vdex
Oat version 138 introduced the concept of an "uncompressed" dex file, where
the dex file is listed in the oat file, but it's not actually present in
the oat or vdex files, instead, it's in the apk as per usual.

This change makes dexlib2 ignore these files, treating them as if they are
not a part of the oat file.
2019-08-07 14:12:19 -07:00
Ben Gruver
6c110c1d96 Allow '!' as a separator char in embedded dex file names
Newer versions of art seem to use ! instead of : to separate the
inner dex filename from the name of the container containing it.

e.g.
/system/framework/framework.jar!classes2.dex
instead of
/system/framework/framework.jar:classes2.dex
2019-08-07 14:12:19 -07:00
Ben Gruver
732fe07403 Add initial support for cdex files
Loading cdex files is mostly supported, except for the new debug info
structures.

Dumping is somewhat supported, but only when there's a single cdex file
in the vdex.
2019-08-07 14:12:19 -07:00
Ben Gruver
eb3ab41fb1 Refactor CodeItem in preparation for cdex implementation
This extracts out the SectionAnnotator implementation into a named class,
which can be overridden by the cdex implementation
2019-08-07 14:05:34 -07:00
Ben Gruver
927a8b3c7c Refactor DexBackedDexFile in preparation for cdex implementation
This pulls out some of the functionality into protected methods that can
be overrided by the cdex implementation
2019-08-07 14:05:34 -07:00
Ben Gruver
dc79917ece Refactor DexBackedMethodImplementation in preparation for the cdex implementation
This pulls out some of the operations into protected methods, to be
overridden in the cdex implementation.
2019-08-07 14:05:34 -07:00
Ben Gruver
862c767d58 Let a section override how it calculates the item offsets
This will be needed for the cdex code_item section, whose format doesn't
allow direct enumeration like we use for everything else.
2019-08-07 14:05:34 -07:00
Ben Gruver
1eb12ffc68 Continue dumping other sections after an error in one section 2019-08-07 14:05:34 -07:00
Ben Gruver
a1fa38da8d Update all the data offset references to use the data buffer 2019-08-07 14:05:34 -07:00
Ben Gruver
587efc71dd Add a separate data buffer for DexBackedDexFile
For cdex files, offsets into the data section are specified relative to
the start of the data section, instead of relative to the start of the dex
file.

This adds a separate data buffer that can be used to resolve these
references.
2019-08-07 14:05:34 -07:00
Ben Gruver
52087a0c7c Add support for dumping dex files that begin at some offset within a file 2019-08-07 14:05:34 -07:00
Ben Gruver
783943ebff Change OatFile to return DexBackedDexFiles, instead of OatDexFiles 2019-08-07 14:05:34 -07:00
Ben Gruver
1a52897373 Delete RawDexFile
This was a thin wrapper around DexBackedDexFile that really had no purpose
itself.
2019-08-07 14:05:34 -07:00
Ben Gruver
906f4d67c1 Decouple the DexEntry for MultiDexContainer
Instead of having a DexFile subclass that extends DexEntry, it's now a
separate entity, which returns the associated dex file.
2019-08-07 14:05:34 -07:00
Ben Gruver
f8e5be6afe Decouple BaseDexBuffer from DexBackedDexFile
Instead of having DexBackedDexFile extend BaseDexBuffer itself, it is now a
separate class, and can be accessed via DexBackedDexFile.getBuffer()
2019-08-07 14:05:34 -07:00
Ben Gruver
8faa4b31ec Refactor how information about indexed items are exposed in DexBackedDexFile
This adds a unified IndexedSection/OptionalIndexedSection class for
all indexed items
2019-08-07 14:05:34 -07:00
Ben Gruver
2412f1f741 Remove isOdexFile, and rename hasOdexOpcodes to supportsOptimizedOpcodes
isOdexFile was no longer being used, and hasOdexOpcodes had a slightly
misleading name, since it could potentially return true for an odex or
oat embedded dex file that didn't actually have any odex opcodes.
2019-08-07 14:05:34 -07:00
Ben Gruver
4eb5e48578 Improve how invalid references are handled
This adds a validateReference() method to the Reference interface, where
subclasses can check themselves and throw an InvalidReferenceException
2019-08-07 14:05:34 -07:00
Ben Gruver
ad8f15d61d Add the new type and string bss mapping offsets in the oat header 2019-08-07 14:05:34 -07:00
Ben Gruver
2f31502924 Update OatVersions.txt and VdexVersions.txt 2019-08-07 14:05:34 -07:00
aki-ks
77afc7caa0 Implement immutable instructions 45cc and 4rcc 2019-08-01 19:42:47 -07:00
aki-ks
29f9020de4 Implement postponed immutable instruction assertions 2019-08-01 19:38:33 -07:00
Eric Hettiaratchi
9340652ff6 Add unit tests for org.jf.util.Hex
These tests were written using Diffblue Cover.
2019-06-13 11:47:05 -07:00
Gergely Nagy
c70a7008f6 Upgraded to Gradle 5.1; fixed two issues, caused by the changes of the version upgrade; RESULT: build succeeds on Ubuntu 18.04 with openJDK 11; version details see below
Gradle        5.1
Build time:   2019-01-02 18:57:47 UTC
Revision:     d09c2e354576ac41078c322815cc6db2b66d976e

Kotlin DSL:   1.1.0
Kotlin:       1.3.11
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          11.0.2 (Oracle Corporation 11.0.2+9-Ubuntu-3ubuntu118.04.3)
OS:           Linux 4.15.0-47-generic amd64
Distro:       Ubuntu 18.04.2 LTS
2019-05-17 15:42:24 -07:00
Ben Gruver
0d4443a19a Gracefully deal with code addresses that are out of range in MutableMethodImplementation
The code addresses in debug info items are not verified, and may be out of
bounds. If this happens, we just clamp them to the maximum code address.
2019-03-21 13:41:00 -07:00
Erik Derr
72c0d9d89a make opcodes nullable in loadDexContainer 2019-01-23 00:17:12 -08:00
Assaf
1bf8f2544b Refactor LocatedItems to use the function addItem() instead of
initItemsIfNull().
2018-08-27 12:59:22 -07:00
Assaf
af8bc1d9cd Refactor LocatedItems::mergeItemsIntoNext
Add test for mergeInto to make sure the order is kept.
2018-08-27 12:59:05 -07:00
Assaf
dd242aa735 Remove code duplication - extract Labels and debugItems from MethodLocation. 2018-08-27 12:41:41 -07:00
Assaf
7542a6b531 Simplify getLabels() by using two separate methods. 2018-08-22 12:43:34 -07:00
Albert Gorski
86963ccb43 Change BlankReader to the correct location in SmaliLexer for idea 2018-08-20 12:55:29 -07:00
Albert Gorski
d33818773e Update the tests to handle MethodHandle kind fixes 2018-08-20 12:55:29 -07:00
Albert Gorski
c6b0408092 Fix support for the kind values of MethodHandle
The current implementation only supported 6 of the possible kind values for a MethodHandle object.
However, as the link below shows there are in fact 9. All 9 can be seen in the MethodHandleType
class which is used by dexdump to translate the kind value of a MethodHandle object to a string
representation.

https://android.googlesource.com/platform/art/+/android-8.1.0_r41/runtime/dex_file.h

Moreover, this in fact lines up with the 9 different kinds for a MethodHandle object in standard
java bytecode (though the values are swapped around for some reason).

https://docs.oracle.com/javase/8/docs/api/java/lang/invoke/MethodHandleInfo.html

These changes add in the additional 3 kind values and make sure all nesscary hooks using the
kind values of MethodHandle reference them.

For testing purposes, I found the easiest way to get correctly formatted invoke-custom and
invoke-polymorphic instructions was to use the already generated dex files used to test
dexdump. They can be found at the link below (invoke-custom.dex and invoke-polymorphic.dex).

https://android.googlesource.com/platform/art/+/android-8.1.0_r41/test/dexdump/
2018-08-20 12:55:29 -07:00
Albert Gorski
49ecdb334b Fix instructions 45cc and 4rcc (invoke-polymorphic)
Previously the offset of the method prototype was 3 bytes from the
instruction start for both instructions. This would put it somewhere in
the middle of the register values and method reference. Changed it to
the correct offset which is 6 bytes in both cases.

45cc Instruction Format
  op(8 bits)
  number_of_regs(4 bits)
  reg_g(4 bits)
  method_reference(16 bits)
  reg_d(4 bits)
  reg_c(4 bits)
  reg_f(4 bits)
  ref_e(4 bits)
  method_prototype(16 bits)

Example of invoke-polymorphic using 45cc
  Instruction: fa302f0021030800
  DexDump: invoke-polymorphic  {v1, v2, v3}, Ljava/lang/invoke/MethodHandle;
           .invoke:([Ljava/lang/Object;)Ljava/lang/Object;,
           (II)Ljava/lang/Object; // method@002f, proto@0008

4rcc Instruction Format
  op(8 bits)
  number_of_regs(8 bits)
  method_reference(16 bits)
  start_register(16 bits)
  method_prototype(16 bits)

Example of invoke-polymorphic using 4rcc
  Instruction: fb092f0000000800
  DexDump: invoke-polymorphic/range  {v0, v1, v2, v3, v4, v5, v6, v7, v8},
           Ljava/lang/invoke/MethodHandle;.invoke:([Ljava/lang/Object;)
           Ljava/lang/Object;, (IIIIIIILjava/lang/String;)Ljava/lang/Object;
           // method@002f, proto@0008
2018-07-11 13:43:01 -07:00
Assaf
5a6b891ef0 Extract new class, PathEntryLoader from ClassPathResolver.
Extract method ClassPathResolver::getDefaultBootClassPath()
2018-07-10 16:16:45 -07:00
Lanchon
71ea09fc8e Add reminder to keep section arrays in sync 2018-07-10 16:09:40 -07:00
Lanchon
da571dbe71 Use similar formatting for section arrays 2018-07-10 16:09:40 -07:00