| // Copyright 2011 Google Inc. All Rights Reserved. |
| |
| #ifndef ART_SRC_DEX_FILE_H_ |
| #define ART_SRC_DEX_FILE_H_ |
| |
| #include "src/globals.h" |
| #include "src/macros.h" |
| #include "src/object.h" |
| #include "src/raw_dex_file.h" |
| |
| namespace art { |
| |
| class DexFile { |
| public: |
| // Opens a .dex file from the file system. Returns NULL on failure. |
| static DexFile* OpenFile(const char* filename); |
| |
| // Opens a .dex file from a base64 encoded array. Returns NULL on |
| // failure. |
| // TODO: move this into the DexFile unit test |
| static DexFile* OpenBase64(const char* base64); |
| |
| // Opens a .dex file from a RawDexFile. Takes ownership of the |
| // RawDexFile. |
| static DexFile* Open(RawDexFile* raw); |
| |
| // Close and deallocate. |
| ~DexFile(); |
| |
| size_t NumTypes() { |
| return num_classes_; |
| } |
| |
| size_t NumMethods() { |
| return num_methods_; |
| } |
| |
| Class* LoadClass(const char* descriptor); |
| |
| Class* LoadClass(const RawDexFile::ClassDef& class_def); |
| |
| private: |
| DexFile(RawDexFile* raw) : raw_(raw) {}; |
| |
| void Init(); |
| |
| void LoadInterfaces(const RawDexFile::ClassDef& class_def, Class *klass); |
| |
| void LoadField(Class* klass, const RawDexFile::Field& src, Field* dst); |
| |
| void LoadMethod(Class* klass, const RawDexFile::Method& src, Method* dst); |
| |
| // Table of contents for interned String objects. |
| String** strings_; |
| size_t num_strings_; |
| |
| // Table of contents for Class objects. |
| Class** classes_; |
| size_t num_classes_; |
| |
| // Table of contents for methods. |
| Method** methods_; |
| size_t num_methods_; |
| |
| // Table of contents for fields. |
| Field** fields_; |
| size_t num_fields_; |
| |
| // The size of the DEX file, in bytes. |
| size_t length_; |
| |
| // The underlying dex file. |
| scoped_ptr<RawDexFile> raw_; |
| |
| DISALLOW_COPY_AND_ASSIGN(DexFile); |
| }; |
| |
| } // namespace art |
| |
| #endif // ART_SRC_DEX_FILE_H_ |