Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #ifndef ART_SRC_DEX_FILE_H_ |
| 4 | #define ART_SRC_DEX_FILE_H_ |
| 5 | |
| 6 | #include "src/globals.h" |
| 7 | #include "src/macros.h" |
| 8 | #include "src/object.h" |
| 9 | #include "src/raw_dex_file.h" |
| 10 | |
| 11 | namespace art { |
| 12 | |
| 13 | class DexFile { |
| 14 | public: |
Carl Shapiro | 80d4dde | 2011-06-28 16:24:07 -0700 | [diff] [blame] | 15 | // Opens a .dex file from the file system. Returns NULL on failure. |
| 16 | static DexFile* OpenFile(const char* filename); |
| 17 | |
| 18 | // Opens a .dex file from a base64 encoded array. Returns NULL on |
| 19 | // failure. |
Carl Shapiro | a506cb0 | 2011-06-28 22:53:46 -0700 | [diff] [blame^] | 20 | // TODO: move this into the DexFile unit test |
Carl Shapiro | 80d4dde | 2011-06-28 16:24:07 -0700 | [diff] [blame] | 21 | static DexFile* OpenBase64(const char* base64); |
| 22 | |
| 23 | // Opens a .dex file from a RawDexFile. Takes ownership of the |
| 24 | // RawDexFile. |
| 25 | static DexFile* Open(RawDexFile* raw); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 26 | |
| 27 | // Close and deallocate. |
| 28 | ~DexFile(); |
| 29 | |
| 30 | size_t NumTypes() { |
| 31 | return num_classes_; |
| 32 | } |
| 33 | |
| 34 | size_t NumMethods() { |
| 35 | return num_methods_; |
| 36 | } |
| 37 | |
| 38 | Class* LoadClass(const char* descriptor); |
| 39 | |
| 40 | Class* LoadClass(const RawDexFile::ClassDef& class_def); |
| 41 | |
| 42 | private: |
| 43 | DexFile(RawDexFile* raw) : raw_(raw) {}; |
| 44 | |
| 45 | void Init(); |
| 46 | |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 47 | void LoadInterfaces(const RawDexFile::ClassDef& class_def, Class *klass); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 48 | |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 49 | void LoadField(Class* klass, const RawDexFile::Field& src, Field* dst); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 50 | |
Carl Shapiro | 3ee755d | 2011-06-28 12:11:04 -0700 | [diff] [blame] | 51 | void LoadMethod(Class* klass, const RawDexFile::Method& src, Method* dst); |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 52 | |
| 53 | // Table of contents for interned String objects. |
| 54 | String** strings_; |
| 55 | size_t num_strings_; |
| 56 | |
| 57 | // Table of contents for Class objects. |
| 58 | Class** classes_; |
| 59 | size_t num_classes_; |
| 60 | |
| 61 | // Table of contents for methods. |
| 62 | Method** methods_; |
| 63 | size_t num_methods_; |
| 64 | |
| 65 | // Table of contents for fields. |
| 66 | Field** fields_; |
| 67 | size_t num_fields_; |
| 68 | |
| 69 | // The size of the DEX file, in bytes. |
| 70 | size_t length_; |
| 71 | |
| 72 | // The underlying dex file. |
Carl Shapiro | 7e78248 | 2011-06-28 16:30:04 -0700 | [diff] [blame] | 73 | scoped_ptr<RawDexFile> raw_; |
Carl Shapiro | 1fb8620 | 2011-06-27 17:43:13 -0700 | [diff] [blame] | 74 | |
| 75 | DISALLOW_COPY_AND_ASSIGN(DexFile); |
| 76 | }; |
| 77 | |
| 78 | } // namespace art |
| 79 | |
| 80 | #endif // ART_SRC_DEX_FILE_H_ |