/* 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. */ #include "LIEF/DEX/File.hpp" #include "LIEF/DEX/hash.hpp" #include "pyIterators.hpp" #include "pyDEX.hpp" namespace LIEF { namespace DEX { template using getter_t = T (File::*)(void) const; template using no_const_getter_t = T (File::*)(void); template using setter_t = void (File::*)(T); template<> void create(py::module& m) { py::class_ file(m, "File", "DEX File representation"); init_ref_iterator(file, "it_classes"); init_ref_iterator(file, "it_methods"); init_ref_iterator(file, "it_strings"); init_ref_iterator(file, "it_types"); init_ref_iterator(file, "it_prototypes"); init_ref_iterator(file, "it_fields"); file .def_property_readonly("version", &File::version, "Dex version") .def_property_readonly("header", static_cast>(&File::header), "Dex File " RST_CLASS_REF(lief.DEX.Header) "", py::return_value_policy::reference) .def_property_readonly("classes", static_cast>(&File::classes), "Iterator over Dex " RST_CLASS_REF(lief.DEX.Class) "") .def("has_class", &File::has_class, "Check if a class with a name given in parameter exists", "classname"_a) .def("get_class", static_cast(&File::get_class), "classname"_a, py::return_value_policy::reference) .def("get_class", static_cast(&File::get_class), "classname"_a, py::return_value_policy::reference) .def_property_readonly("methods", static_cast>(&File::methods), "Iterator over Dex " RST_CLASS_REF(lief.DEX.Method) "") .def_property_readonly("fields", static_cast>(&File::fields), "Iterator over Dex " RST_CLASS_REF(lief.DEX.Field) "") .def_property_readonly("strings", static_cast>(&File::strings), "Iterator over Dex strings") .def_property_readonly("types", static_cast>(&File::types), "Iterator over Dex " RST_CLASS_REF(lief.DEX.Type) "") .def_property_readonly("prototypes", static_cast>(&File::prototypes), "Iterator over Dex " RST_CLASS_REF(lief.DEX.Prototype) "") .def_property_readonly("map", static_cast>(&File::map), "Dex " RST_CLASS_REF(lief.DEX.MapList) "") .def("raw", &File::raw, "Original raw file", "deoptimize"_a = true) .def_property("name", static_cast>(&File::name), static_cast>(&File::name), "Name of the dex file") .def_property("location", static_cast>(&File::location), static_cast>(&File::location), "Original location of the dex file") //.def_property_readonly("dex2dex_info", // &File::dex2dex_info) .def_property_readonly("dex2dex_json_info", &File::dex2dex_json_info) .def("save", &File::save, "Save the **original** file into the file given in first parameter", "output"_a = "", "deoptimize"_a = true) .def("__eq__", &File::operator==) .def("__ne__", &File::operator!=) .def("__hash__", [] (const File& file) { return Hash::hash(file); }) .def("__str__", [] (const File& file) { std::ostringstream stream; stream << file; return stream.str(); }); } } }