/* Copyright 2017 - 2022 R. Thomas * Copyright 2017 - 2022 Quarkslab * * 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 LIEF_DEX_PARSER_H_ #define LIEF_DEX_PARSER_H_ #include #include "LIEF/visibility.h" #include "LIEF/BinaryStream/VectorStream.hpp" #include "LIEF/DEX/File.hpp" struct Profiler; namespace LIEF { namespace DEX { class Class; class Method; class Field; //! Class which parses a DEX file to produce a DEX::File object class LIEF_API Parser { public: friend struct ::Profiler; //! Parse the DEX file from the file path given in parameter static std::unique_ptr parse(const std::string& file); static std::unique_ptr parse(std::vector data, const std::string& name = ""); Parser& operator=(const Parser& copy) = delete; Parser(const Parser& copy) = delete; private: Parser(); Parser(const std::string& file); Parser(std::vector data); ~Parser(); void init(const std::string& name, dex_version_t version); template void parse_file(); template void parse_header(); template void parse_map(); template void parse_strings(); template void parse_types(); template void parse_fields(); template void parse_prototypes(); template void parse_methods(); template void parse_classes(); template void parse_class_data(uint32_t offset, Class& cls); template void parse_field(size_t index, Class& cls, bool is_static); template void parse_method(size_t index, Class& cls, bool is_virtual); template void parse_code_info(uint32_t offset, Method& method); void resolve_inheritance(); void resolve_external_methods(); void resolve_external_fields(); void resolve_types(); std::unique_ptr file_; // Map of inheritance relationship when parsing classes ('parse_classes') // The key is the parent class name of the value std::unordered_multimap inheritance_; // Map of method/class relationship when parsing methods ('parse_methods') // The key is the Class name in which the method is defined std::unordered_multimap class_method_map_; // Map of field/class relationship when parsing fields ('parse_fields') // The key is the Class name in which the field is defined std::unordered_multimap class_field_map_; std::unordered_multimap class_type_map_; std::unique_ptr stream_; }; } // namespace DEX } // namespace LIEF #endif