/* Copyright 2017 - 2021 R. Thomas * Copyright 2017 - 2021 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" namespace LIEF { namespace DEX { class Class; class Method; //! @brief Class which parse a DEX file and transform into a DEX::File object class LIEF_API Parser { public: static std::unique_ptr parse(const std::string& file); static std::unique_ptr parse(const std::vector& data, const std::string& name = ""); Parser& operator=(const Parser& copy) = delete; Parser(const Parser& copy) = delete; private: Parser(void); Parser(const std::string& file); Parser(const std::vector& data, const std::string& name); ~Parser(void); void init(const std::string& name, dex_version_t version); template void parse_file(void); template void parse_header(void); template void parse_map(void); template void parse_strings(void); template void parse_types(void); template void parse_fields(void); template void parse_prototypes(void); template void parse_methods(void); template void parse_classes(void); template void parse_class_data(uint32_t offset, Class* cls); 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); void resolve_external_methods(void); void resolve_types(void); LIEF::DEX::File* 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_; std::unordered_multimap class_type_map_; std::unique_ptr stream_; }; } // namespace DEX } // namespace LIEF #endif