blob: 1ec06edef31fb8af46d085d6215c6ee17129145f [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
Mathieu Chartier292567e2017-10-12 13:24:38 -070017#ifndef ART_RUNTIME_STANDARD_DEX_FILE_H_
18#define ART_RUNTIME_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:
31 static const uint8_t kDexMagic[kDexMagicSize];
32 static constexpr size_t kNumDexVersions = 4;
33 static const uint8_t kDexMagicVersions[kNumDexVersions][kDexVersionLen];
34
35 // Returns true if the byte string points to the magic value.
36 static bool IsMagicValid(const uint8_t* magic);
37 virtual bool IsMagicValid() const OVERRIDE;
38
39 // Returns true if the byte string after the magic is the correct value.
40 static bool IsVersionValid(const uint8_t* magic);
41 virtual bool IsVersionValid() const OVERRIDE;
42
43 private:
Mathieu Chartier292567e2017-10-12 13:24:38 -070044 StandardDexFile(const uint8_t* base,
45 size_t size,
46 const std::string& location,
47 uint32_t location_checksum,
48 const OatDexFile* oat_dex_file)
Mathieu Chartier7b074bf2017-09-25 16:22:36 -070049 : DexFile(base, size, location, location_checksum, oat_dex_file) {}
50
Mathieu Chartier79c87da2017-10-10 11:54:29 -070051 friend class DexFileLoader;
Mathieu Chartier7b074bf2017-09-25 16:22:36 -070052 friend class DexFileVerifierTest;
53
54 ART_FRIEND_TEST(ClassLinkerTest, RegisterDexFileName); // for constructor
55
Mathieu Chartier292567e2017-10-12 13:24:38 -070056 DISALLOW_COPY_AND_ASSIGN(StandardDexFile);
Mathieu Chartier7b074bf2017-09-25 16:22:36 -070057};
58
59} // namespace art
60
Mathieu Chartier292567e2017-10-12 13:24:38 -070061#endif // ART_RUNTIME_STANDARD_DEX_FILE_H_