Mathieu Chartier | 7b074bf | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_DEX_STANDARD_DEX_FILE_H_ |
| 18 | #define ART_RUNTIME_DEX_STANDARD_DEX_FILE_H_ |
Mathieu Chartier | 7b074bf | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 19 | |
| 20 | #include <iosfwd> |
| 21 | |
| 22 | #include "dex_file.h" |
| 23 | |
| 24 | namespace art { |
| 25 | |
| 26 | class OatDexFile; |
| 27 | |
Mathieu Chartier | 292567e | 2017-10-12 13:24:38 -0700 | [diff] [blame] | 28 | // Standard dex file. This is the format that is packaged in APKs and produced by tools. |
| 29 | class StandardDexFile : public DexFile { |
Mathieu Chartier | 7b074bf | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 30 | public: |
Mathieu Chartier | f95a75e | 2017-11-03 15:25:52 -0700 | [diff] [blame] | 31 | class Header : public DexFile::Header { |
| 32 | // Same for now. |
| 33 | }; |
| 34 | |
Mathieu Chartier | 69147f1 | 2017-11-06 20:02:24 -0800 | [diff] [blame] | 35 | struct CodeItem : public DexFile::CodeItem { |
| 36 | private: |
| 37 | // TODO: Insert standard dex specific fields here. |
Mathieu Chartier | 6238c83 | 2018-01-04 09:55:13 -0800 | [diff] [blame] | 38 | friend class StandardDexFile; |
Mathieu Chartier | 69147f1 | 2017-11-06 20:02:24 -0800 | [diff] [blame] | 39 | DISALLOW_COPY_AND_ASSIGN(CodeItem); |
| 40 | }; |
| 41 | |
| 42 | // Write the standard dex specific magic. |
| 43 | static void WriteMagic(uint8_t* magic); |
| 44 | |
| 45 | // Write the current version, note that the input is the address of the magic. |
| 46 | static void WriteCurrentVersion(uint8_t* magic); |
| 47 | |
Mathieu Chartier | 7b074bf | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 48 | static const uint8_t kDexMagic[kDexMagicSize]; |
| 49 | static constexpr size_t kNumDexVersions = 4; |
| 50 | static const uint8_t kDexMagicVersions[kNumDexVersions][kDexVersionLen]; |
| 51 | |
| 52 | // Returns true if the byte string points to the magic value. |
| 53 | static bool IsMagicValid(const uint8_t* magic); |
| 54 | virtual bool IsMagicValid() const OVERRIDE; |
| 55 | |
| 56 | // Returns true if the byte string after the magic is the correct value. |
| 57 | static bool IsVersionValid(const uint8_t* magic); |
| 58 | virtual bool IsVersionValid() const OVERRIDE; |
| 59 | |
Mathieu Chartier | f6e3147 | 2017-12-28 13:32:08 -0800 | [diff] [blame] | 60 | virtual bool SupportsDefaultMethods() const OVERRIDE; |
| 61 | |
Mathieu Chartier | 6238c83 | 2018-01-04 09:55:13 -0800 | [diff] [blame] | 62 | uint32_t GetCodeItemSize(const DexFile::CodeItem& item) const OVERRIDE; |
| 63 | |
Mathieu Chartier | 7b074bf | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 64 | private: |
Mathieu Chartier | 292567e | 2017-10-12 13:24:38 -0700 | [diff] [blame] | 65 | StandardDexFile(const uint8_t* base, |
| 66 | size_t size, |
| 67 | const std::string& location, |
| 68 | uint32_t location_checksum, |
David Sehr | 733bd4d | 2017-10-26 10:39:15 -0700 | [diff] [blame] | 69 | const OatDexFile* oat_dex_file, |
| 70 | DexFileContainer* container) |
Mathieu Chartier | 69147f1 | 2017-11-06 20:02:24 -0800 | [diff] [blame] | 71 | : DexFile(base, |
| 72 | size, |
| 73 | location, |
| 74 | location_checksum, |
| 75 | oat_dex_file, |
| 76 | container, |
| 77 | /*is_compact_dex*/ false) {} |
Mathieu Chartier | 7b074bf | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 78 | |
Mathieu Chartier | 79c87da | 2017-10-10 11:54:29 -0700 | [diff] [blame] | 79 | friend class DexFileLoader; |
Mathieu Chartier | 7b074bf | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 80 | friend class DexFileVerifierTest; |
| 81 | |
| 82 | ART_FRIEND_TEST(ClassLinkerTest, RegisterDexFileName); // for constructor |
| 83 | |
Mathieu Chartier | 292567e | 2017-10-12 13:24:38 -0700 | [diff] [blame] | 84 | DISALLOW_COPY_AND_ASSIGN(StandardDexFile); |
Mathieu Chartier | 7b074bf | 2017-09-25 16:22:36 -0700 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | } // namespace art |
| 88 | |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 89 | #endif // ART_RUNTIME_DEX_STANDARD_DEX_FILE_H_ |