huangcm
2025-08-30 0269911b91ed7e03c24005924cc6423abf245fb8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 
#ifndef ART_TOOLS_VERIDEX_VERIDEX_H_
#define ART_TOOLS_VERIDEX_VERIDEX_H_
 
#include <map>
 
#include "dex/primitive.h"
 
namespace art {
 
namespace dex {
struct ClassDef;
}  // namespace dex
 
static int gTargetSdkVersion = 1000;  // Will be initialized after parsing options.
 
/**
 * Abstraction for fields defined in dex files. Currently, that's a pointer into their
 * `encoded_field` description.
 */
using VeriField = const uint8_t*;
 
/**
 * Abstraction for methods defined in dex files. Currently, that's a pointer into their
 * `encoded_method` description.
 */
using VeriMethod = const uint8_t*;
 
/**
 * Abstraction for classes defined, or implicitly defined (for arrays and primitives)
 * in dex files.
 */
class VeriClass {
 public:
  VeriClass() = default;
  VeriClass(Primitive::Type k, uint8_t dims, const dex::ClassDef* cl)
      : kind_(k), dimensions_(dims), class_def_(cl) {}
 
  bool IsUninitialized() const {
    return kind_ == Primitive::Type::kPrimNot && dimensions_ == 0 && class_def_ == nullptr;
  }
 
  bool IsPrimitive() const {
    return kind_ != Primitive::Type::kPrimNot && dimensions_ == 0;
  }
 
  bool IsArray() const {
    return dimensions_ != 0;
  }
 
  Primitive::Type GetKind() const { return kind_; }
  uint8_t GetDimensions() const { return dimensions_; }
  const dex::ClassDef* GetClassDef() const { return class_def_; }
 
  static VeriClass* object_;
  static VeriClass* class_;
  static VeriClass* class_loader_;
  static VeriClass* string_;
  static VeriClass* throwable_;
  static VeriClass* boolean_;
  static VeriClass* byte_;
  static VeriClass* char_;
  static VeriClass* short_;
  static VeriClass* integer_;
  static VeriClass* float_;
  static VeriClass* double_;
  static VeriClass* long_;
  static VeriClass* void_;
 
  static VeriMethod forName_;
  static VeriMethod getField_;
  static VeriMethod getDeclaredField_;
  static VeriMethod getMethod_;
  static VeriMethod getDeclaredMethod_;
  static VeriMethod getClass_;
  static VeriMethod loadClass_;
 
  static VeriField sdkInt_;
 
 private:
  Primitive::Type kind_;
  uint8_t dimensions_;
  const dex::ClassDef* class_def_;
};
 
inline bool IsGetMethod(VeriMethod method) {
  return method == VeriClass::getMethod_ || method == VeriClass::getDeclaredMethod_;
}
 
inline bool IsGetField(VeriMethod method) {
  return method == VeriClass::getField_ || method == VeriClass::getDeclaredField_;
}
 
/**
 * Map from name to VeriClass to quickly lookup classes.
 */
using TypeMap = std::map<std::string, VeriClass*>;
 
}  // namespace art
 
#endif  // ART_TOOLS_VERIDEX_VERIDEX_H_