Home | History | Annotate | Download | only in dexlayout
      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  * Header file of dex ir verifier.
     17  *
     18  * Compares two dex files at the IR level, allowing differences in layout, but not in data.
     19  */
     20 
     21 #ifndef ART_DEXLAYOUT_DEX_VERIFY_H_
     22 #define ART_DEXLAYOUT_DEX_VERIFY_H_
     23 
     24 #include "dex_ir.h"
     25 
     26 namespace art {
     27 // Check that the output dex file contains the same data as the original.
     28 // Compares the dex IR of both dex files. Allows the dex files to have different layouts.
     29 bool VerifyOutputDexFile(dex_ir::Header* orig_header,
     30                          dex_ir::Header* output_header,
     31                          std::string* error_msg);
     32 
     33 template<class T> bool VerifyIds(std::vector<std::unique_ptr<T>>& orig,
     34                                  std::vector<std::unique_ptr<T>>& output,
     35                                  const char* section_name,
     36                                  std::string* error_msg);
     37 bool VerifyId(dex_ir::StringId* orig, dex_ir::StringId* output, std::string* error_msg);
     38 bool VerifyId(dex_ir::TypeId* orig, dex_ir::TypeId* output, std::string* error_msg);
     39 bool VerifyId(dex_ir::ProtoId* orig, dex_ir::ProtoId* output, std::string* error_msg);
     40 bool VerifyId(dex_ir::FieldId* orig, dex_ir::FieldId* output, std::string* error_msg);
     41 bool VerifyId(dex_ir::MethodId* orig, dex_ir::MethodId* output, std::string* error_msg);
     42 
     43 bool VerifyClassDefs(std::vector<std::unique_ptr<dex_ir::ClassDef>>& orig,
     44                      std::vector<std::unique_ptr<dex_ir::ClassDef>>& output,
     45                      std::string* error_msg);
     46 bool VerifyClassDef(dex_ir::ClassDef* orig, dex_ir::ClassDef* output, std::string* error_msg);
     47 
     48 bool VerifyTypeList(const dex_ir::TypeList* orig, const dex_ir::TypeList* output);
     49 
     50 bool VerifyAnnotationsDirectory(dex_ir::AnnotationsDirectoryItem* orig,
     51                                 dex_ir::AnnotationsDirectoryItem* output,
     52                                 std::string* error_msg);
     53 bool VerifyFieldAnnotations(dex_ir::FieldAnnotationVector* orig,
     54                             dex_ir::FieldAnnotationVector* output,
     55                             uint32_t orig_offset,
     56                             std::string* error_msg);
     57 bool VerifyMethodAnnotations(dex_ir::MethodAnnotationVector* orig,
     58                              dex_ir::MethodAnnotationVector* output,
     59                              uint32_t orig_offset,
     60                              std::string* error_msg);
     61 bool VerifyParameterAnnotations(dex_ir::ParameterAnnotationVector* orig,
     62                                 dex_ir::ParameterAnnotationVector* output,
     63                                 uint32_t orig_offset,
     64                                 std::string* error_msg);
     65 bool VerifyAnnotationSetRefList(dex_ir::AnnotationSetRefList* orig,
     66                                 dex_ir::AnnotationSetRefList* output,
     67                                 std::string* error_msg);
     68 bool VerifyAnnotationSet(dex_ir::AnnotationSetItem* orig,
     69                          dex_ir::AnnotationSetItem* output,
     70                          std::string* error_msg);
     71 bool VerifyAnnotation(dex_ir::AnnotationItem* orig,
     72                       dex_ir::AnnotationItem* output,
     73                       std::string* error_msg);
     74 bool VerifyEncodedAnnotation(dex_ir::EncodedAnnotation* orig,
     75                              dex_ir::EncodedAnnotation* output,
     76                              uint32_t orig_offset,
     77                              std::string* error_msg);
     78 bool VerifyAnnotationElement(dex_ir::AnnotationElement* orig,
     79                              dex_ir::AnnotationElement* output,
     80                              uint32_t orig_offset,
     81                              std::string* error_msg);
     82 bool VerifyEncodedValue(dex_ir::EncodedValue* orig,
     83                         dex_ir::EncodedValue* output,
     84                         uint32_t orig_offset,
     85                         std::string* error_msg);
     86 bool VerifyEncodedArray(dex_ir::EncodedArrayItem* orig,
     87                         dex_ir::EncodedArrayItem* output,
     88                         std::string* error_msg);
     89 
     90 bool VerifyClassData(dex_ir::ClassData* orig, dex_ir::ClassData* output, std::string* error_msg);
     91 bool VerifyFields(dex_ir::FieldItemVector* orig,
     92                   dex_ir::FieldItemVector* output,
     93                   uint32_t orig_offset,
     94                   std::string* error_msg);
     95 bool VerifyMethods(dex_ir::MethodItemVector* orig,
     96                    dex_ir::MethodItemVector* output,
     97                    uint32_t orig_offset,
     98                    std::string* error_msg);
     99 bool VerifyCode(dex_ir::CodeItem* orig, dex_ir::CodeItem* output, std::string* error_msg);
    100 bool VerifyDebugInfo(dex_ir::DebugInfoItem* orig,
    101                      dex_ir::DebugInfoItem* output,
    102                      std::string* error_msg);
    103 bool VerifyPositionInfo(dex_ir::PositionInfoVector& orig,
    104                         dex_ir::PositionInfoVector& output,
    105                         uint32_t orig_offset,
    106                         std::string* error_msg);
    107 bool VerifyLocalInfo(dex_ir::LocalInfoVector& orig,
    108                      dex_ir::LocalInfoVector& output,
    109                      uint32_t orig_offset,
    110                      std::string* error_msg);
    111 bool VerifyTries(dex_ir::TryItemVector* orig,
    112                  dex_ir::TryItemVector* output,
    113                  uint32_t orig_offset,
    114                  std::string* error_msg);
    115 bool VerifyHandlers(dex_ir::CatchHandlerVector* orig,
    116                     dex_ir::CatchHandlerVector* output,
    117                     uint32_t orig_offset,
    118                     std::string* error_msg);
    119 bool VerifyHandler(const dex_ir::CatchHandler* orig,
    120                    const dex_ir::CatchHandler* output,
    121                    uint32_t orig_offset,
    122                    std::string* error_msg);
    123 }  // namespace art
    124 
    125 #endif  // ART_DEXLAYOUT_DEX_VERIFY_H_
    126