blob: fb2f720920d6de7ec8a5e7e962e4d3d502f1491f [file] [log] [blame]
Mathieu Chartier7b074bf2017-09-25 16:22:36 -07001/*
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 Sehr9e734c72018-01-04 17:56:19 -080017#ifndef ART_RUNTIME_DEX_STANDARD_DEX_FILE_H_
18#define ART_RUNTIME_DEX_STANDARD_DEX_FILE_H_
Mathieu Chartier7b074bf2017-09-25 16:22:36 -070019
20#include <iosfwd>
21
22#include "dex_file.h"
23
24namespace art {
25
26class OatDexFile;
27
Mathieu Chartier292567e2017-10-12 13:24:38 -070028// Standard dex file. This is the format that is packaged in APKs and produced by tools.
29class StandardDexFile : public DexFile {
Mathieu Chartier7b074bf2017-09-25 16:22:36 -070030 public:
Mathieu Chartierf95a75e2017-11-03 15:25:52 -070031 class Header : public DexFile::Header {
32 // Same for now.
33 };
34
Mathieu Chartier69147f12017-11-06 20:02:24 -080035 struct CodeItem : public DexFile::CodeItem {
36 private:
37 // TODO: Insert standard dex specific fields here.
Mathieu Chartier6238c832018-01-04 09:55:13 -080038 friend class StandardDexFile;
Mathieu Chartier69147f12017-11-06 20:02:24 -080039 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 Chartier7b074bf2017-09-25 16:22:36 -070048 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 Chartierf6e31472017-12-28 13:32:08 -080060 virtual bool SupportsDefaultMethods() const OVERRIDE;
61
Mathieu Chartier6238c832018-01-04 09:55:13 -080062 uint32_t GetCodeItemSize(const DexFile::CodeItem& item) const OVERRIDE;
63
Mathieu Chartier7b074bf2017-09-25 16:22:36 -070064 private:
Mathieu Chartier292567e2017-10-12 13:24:38 -070065 StandardDexFile(const uint8_t* base,
66 size_t size,
67 const std::string& location,
68 uint32_t location_checksum,
David Sehr733bd4d2017-10-26 10:39:15 -070069 const OatDexFile* oat_dex_file,
70 DexFileContainer* container)
Mathieu Chartier69147f12017-11-06 20:02:24 -080071 : DexFile(base,
72 size,
73 location,
74 location_checksum,
75 oat_dex_file,
76 container,
77 /*is_compact_dex*/ false) {}
Mathieu Chartier7b074bf2017-09-25 16:22:36 -070078
Mathieu Chartier79c87da2017-10-10 11:54:29 -070079 friend class DexFileLoader;
Mathieu Chartier7b074bf2017-09-25 16:22:36 -070080 friend class DexFileVerifierTest;
81
82 ART_FRIEND_TEST(ClassLinkerTest, RegisterDexFileName); // for constructor
83
Mathieu Chartier292567e2017-10-12 13:24:38 -070084 DISALLOW_COPY_AND_ASSIGN(StandardDexFile);
Mathieu Chartier7b074bf2017-09-25 16:22:36 -070085};
86
87} // namespace art
88
David Sehr9e734c72018-01-04 17:56:19 -080089#endif // ART_RUNTIME_DEX_STANDARD_DEX_FILE_H_