From 306a191a033a734b0ac8c932194ebcb93ec2363b Mon Sep 17 00:00:00 2001 From: Romain Thomas Date: Thu, 30 Mar 2017 16:56:49 +0200 Subject: [PATCH] First public release --- .appveyor.yml | 89 + .dockerignore | 10 + .travis.yml | 156 + AUTHORS | 3 + Acknowledgements | 16 + CHANGELOG | 7 + CMakeLists.txt | 552 ++ CMakeModules/CodeCoverage.cmake | 197 + CMakeModules/CppcheckTargets.cmake | 231 + CMakeModules/FindYamlCpp.cmake | 98 + CMakeModules/Findcppcheck.cmake | 167 + CMakeModules/Findcppcheck.cpp | 16 + CMakeModules/Toolchain-mingw32.cmake | 19 + LICENSE | 202 + README.md | 107 + api/c/CMakeLists.txt | 52 + api/c/ELF/Binary.cpp | 112 + api/c/ELF/Binary.hpp | 30 + api/c/ELF/DynamicEntry.cpp | 174 + api/c/ELF/DynamicEntry.hpp | 34 + api/c/ELF/EnumToString.cpp | 73 + api/c/ELF/Header.cpp | 46 + api/c/ELF/Header.hpp | 33 + api/c/ELF/Section.cpp | 71 + api/c/ELF/Section.hpp | 34 + api/c/ELF/Segment.cpp | 67 + api/c/ELF/Segment.hpp | 34 + api/c/ELF/Symbol.cpp | 90 + api/c/ELF/Symbol.hpp | 37 + api/c/MachO/Binary.cpp | 58 + api/c/MachO/Binary.hpp | 30 + api/c/MachO/EnumToString.cpp | 76 + api/c/MachO/Header.cpp | 33 + api/c/MachO/Header.hpp | 33 + api/c/MachO/LoadCommand.cpp | 62 + api/c/MachO/LoadCommand.hpp | 34 + api/c/MachO/Parser.cpp | 41 + api/c/MachO/Section.cpp | 72 + api/c/MachO/Section.hpp | 34 + api/c/MachO/Segment.cpp | 69 + api/c/MachO/Segment.hpp | 34 + api/c/MachO/Symbol.cpp | 56 + api/c/MachO/Symbol.hpp | 34 + api/c/PE/Binary.cpp | 64 + api/c/PE/Binary.hpp | 30 + api/c/PE/DataDirectory.cpp | 54 + api/c/PE/DataDirectory.hpp | 34 + api/c/PE/DosHeader.cpp | 55 + api/c/PE/DosHeader.hpp | 33 + api/c/PE/EnumToString.cpp | 40 + api/c/PE/Header.cpp | 42 + api/c/PE/Header.hpp | 33 + api/c/PE/OptionalHeader.cpp | 61 + api/c/PE/OptionalHeader.hpp | 33 + api/c/PE/Section.cpp | 68 + api/c/PE/Section.hpp | 34 + api/c/include/LIEF/ELF.h | 27 + api/c/include/LIEF/ELF/Binary.h | 79 + api/c/include/LIEF/ELF/DynamicEntry.h | 83 + api/c/include/LIEF/ELF/EnumToString.h | 45 + api/c/include/LIEF/ELF/Header.h | 58 + api/c/include/LIEF/ELF/Section.h | 58 + api/c/include/LIEF/ELF/Segment.h | 52 + api/c/include/LIEF/ELF/Symbol.h | 52 + api/c/include/LIEF/ELF/enums.h.in | 14 + api/c/include/LIEF/ELF/structures.h.in | 14 + api/c/include/LIEF/LIEF.h | 23 + api/c/include/LIEF/MachO.h | 28 + api/c/include/LIEF/MachO/Binary.h | 68 + api/c/include/LIEF/MachO/EnumToString.h | 41 + api/c/include/LIEF/MachO/Header.h | 52 + api/c/include/LIEF/MachO/LoadCommand.h | 48 + api/c/include/LIEF/MachO/Section.h | 59 + api/c/include/LIEF/MachO/Segment.h | 55 + api/c/include/LIEF/MachO/Symbol.h | 49 + api/c/include/LIEF/MachO/enums.h.in | 14 + api/c/include/LIEF/MachO/structures.h.in | 14 + api/c/include/LIEF/PE.h | 23 + api/c/include/LIEF/PE/Binary.h | 67 + api/c/include/LIEF/PE/DataDirectory.h | 47 + api/c/include/LIEF/PE/DosHeader.h | 63 + api/c/include/LIEF/PE/EnumToString.h | 37 + api/c/include/LIEF/PE/Header.h | 53 + api/c/include/LIEF/PE/OptionalHeader.h | 74 + api/c/include/LIEF/PE/Section.h | 58 + api/c/include/LIEF/PE/enums.h.in | 20 + api/c/include/LIEF/PE/structures.h.in | 14 + api/python/Abstract/init.cpp | 26 + api/python/Abstract/init.hpp | 28 + api/python/Abstract/objects/pyBinary.cpp | 102 + api/python/Abstract/objects/pyHeader.cpp | 51 + api/python/Abstract/objects/pyParser.cpp | 28 + api/python/Abstract/objects/pySection.cpp | 57 + api/python/Abstract/objects/pySymbol.cpp | 61 + api/python/Abstract/pyEnums.cpp | 28 + api/python/CMakeLists.txt | 164 + api/python/ELF/CMakeLists.txt | 29 + api/python/ELF/objects/pyBinary.cpp | 215 + api/python/ELF/objects/pyBuilder.cpp | 41 + api/python/ELF/objects/pyDynamicEntry.cpp | 66 + .../ELF/objects/pyDynamicEntryArray.cpp | 58 + .../ELF/objects/pyDynamicEntryLibrary.cpp | 60 + .../ELF/objects/pyDynamicEntryRpath.cpp | 65 + .../ELF/objects/pyDynamicEntryRunPath.cpp | 64 + .../ELF/objects/pyDynamicSharedObject.cpp | 58 + api/python/ELF/objects/pyGnuHash.cpp | 79 + api/python/ELF/objects/pyHeader.cpp | 150 + api/python/ELF/objects/pyParser.cpp | 36 + api/python/ELF/objects/pyRelocation.cpp | 74 + api/python/ELF/objects/pySection.cpp | 130 + api/python/ELF/objects/pySegment.cpp | 121 + api/python/ELF/objects/pySymbol.cpp | 110 + api/python/ELF/objects/pySymbolVersion.cpp | 69 + api/python/ELF/objects/pySymbolVersionAux.cpp | 56 + .../objects/pySymbolVersionAuxRequirement.cpp | 63 + .../ELF/objects/pySymbolVersionDefinition.cpp | 70 + .../objects/pySymbolVersionRequirement.cpp | 68 + api/python/ELF/pyELF.cpp | 54 + api/python/ELF/pyELF.hpp | 55 + api/python/ELF/pyELFStructures.cpp | 749 ++ api/python/MANIFEST.in.in | 1 + api/python/MachO/CMakeLists.txt | 18 + api/python/MachO/objects/pyBinary.cpp | 108 + api/python/MachO/objects/pyDylibCommand.cpp | 78 + api/python/MachO/objects/pyHeader.cpp | 93 + api/python/MachO/objects/pyLoadCommand.cpp | 72 + api/python/MachO/objects/pyParser.cpp | 29 + api/python/MachO/objects/pySection.cpp | 78 + api/python/MachO/objects/pySegmentCommand.cpp | 125 + api/python/MachO/objects/pySymbol.cpp | 72 + api/python/MachO/pyMachO.cpp | 41 + api/python/MachO/pyMachO.hpp | 42 + api/python/MachO/pyMachOStructures.cpp | 159 + api/python/PE/CMakeLists.txt | 34 + api/python/PE/objects/pyBinary.cpp | 198 + api/python/PE/objects/pyBuilder.cpp | 71 + api/python/PE/objects/pyDataDirectory.cpp | 69 + api/python/PE/objects/pyDebug.cpp | 82 + api/python/PE/objects/pyDosHeader.cpp | 122 + api/python/PE/objects/pyExport.cpp | 82 + api/python/PE/objects/pyExportEntry.cpp | 66 + api/python/PE/objects/pyHeader.cpp | 97 + api/python/PE/objects/pyImport.cpp | 99 + api/python/PE/objects/pyImportEntry.cpp | 82 + api/python/PE/objects/pyOptionalHeader.cpp | 176 + api/python/PE/objects/pyParser.cpp | 37 + api/python/PE/objects/pyRelocation.cpp | 62 + api/python/PE/objects/pyRelocationEntry.cpp | 63 + api/python/PE/objects/pyResourcesManager.cpp | 36 + api/python/PE/objects/pySection.cpp | 87 + api/python/PE/objects/pySymbol.cpp | 84 + api/python/PE/objects/pyTLS.cpp | 90 + .../signature/pyAuthenticatedAttributes.cpp | 63 + .../PE/objects/signature/pyContentInfo.cpp | 63 + .../PE/objects/signature/pySignature.cpp | 78 + .../PE/objects/signature/pySignerInfo.cpp | 72 + api/python/PE/objects/signature/pyx509.cpp | 79 + api/python/PE/pyPE.cpp | 59 + api/python/PE/pyPE.hpp | 53 + api/python/PE/pyPEStructures.cpp | 277 + api/python/README.in | 15 + api/python/__init__.py.in | 0 api/python/pyExceptions.cpp | 34 + api/python/pyIterators.cpp | 68 + api/python/pyIterators.hpp | 67 + api/python/pyJson.cpp | 51 + api/python/pyLIEF.cpp | 52 + api/python/pyLIEF.hpp | 39 + api/python/pyUtils.cpp | 36 + api/python/setup.py.in | 39 + doc/CMakeLists.txt | 93 + doc/doxygen/Doxyfile.in | 2392 ++++++ doc/doxygen/bootstrap.min.css | 7523 +++++++++++++++++ doc/doxygen/css/bootstrap-theme.css | 587 ++ doc/doxygen/css/bootstrap-theme.css.map | 1 + doc/doxygen/css/bootstrap-theme.min.css | 6 + doc/doxygen/css/bootstrap-theme.min.css.map | 1 + doc/doxygen/css/bootstrap.css | 6760 +++++++++++++++ doc/doxygen/css/bootstrap.css.map | 1 + doc/doxygen/css/bootstrap.min.css | 6 + doc/doxygen/css/bootstrap.min.css.map | 1 + doc/doxygen/css/font-awesome.min.css | 4 + doc/doxygen/css/style.css | 64 + doc/doxygen/css/syntax.css | 60 + doc/doxygen/customdoxygen.css | 173 + doc/doxygen/doxy-boot.js | 135 + doc/doxygen/fonts/fontawesome-webfont.eot | Bin 0 -> 76518 bytes doc/doxygen/fonts/fontawesome-webfont.svg | 685 ++ doc/doxygen/fonts/fontawesome-webfont.ttf | Bin 0 -> 152796 bytes doc/doxygen/fonts/fontawesome-webfont.woff | Bin 0 -> 90412 bytes doc/doxygen/fonts/fontawesome-webfont.woff2 | Bin 0 -> 71896 bytes .../fonts/glyphicons-halflings-regular.eot | Bin 0 -> 20127 bytes .../fonts/glyphicons-halflings-regular.svg | 288 + .../fonts/glyphicons-halflings-regular.ttf | Bin 0 -> 45404 bytes .../fonts/glyphicons-halflings-regular.woff | Bin 0 -> 23424 bytes .../fonts/glyphicons-halflings-regular.woff2 | Bin 0 -> 18028 bytes doc/doxygen/footer.html | 17 + doc/doxygen/header.html | 47 + doc/doxygen/index.doxygen | 3 + doc/doxygen/js/application.js | 4 + doc/doxygen/js/bootstrap.js | 2363 ++++++ doc/doxygen/js/bootstrap.min.js | 7 + doc/doxygen/js/jquery-1.9.1.min.js | 5 + doc/doxygen/js/jquery-2.2.4.min.js | 4 + doc/doxygen/js/jquery-3.0.0.min.js | 4 + doc/doxygen/js/npm.js | 13 + doc/doxygen/logo_lief_55.png | Bin 0 -> 6685 bytes doc/doxygen/welcome.html | 3 + doc/sphinx/Intro.rst | 37 + doc/sphinx/_static/archi.png | Bin 0 -> 141246 bytes doc/sphinx/_static/archi_elf.png | Bin 0 -> 190719 bytes doc/sphinx/_static/data_handler.png | Bin 0 -> 158171 bytes doc/sphinx/_static/example.cpp | 33 + doc/sphinx/_static/favicon.ico | Bin 0 -> 4286 bytes doc/sphinx/_static/iat3.png | Bin 0 -> 94947 bytes doc/sphinx/_static/iat4.png | Bin 0 -> 224665 bytes doc/sphinx/_static/logo_blue.png | Bin 0 -> 14955 bytes doc/sphinx/_static/logo_blue_412.png | Bin 0 -> 132432 bytes doc/sphinx/_static/tutorial/03/hashme.png | Bin 0 -> 95534 bytes doc/sphinx/_static/tutorial/03/hashme_obf.png | Bin 0 -> 101337 bytes doc/sphinx/_static/tutorial/05/pltgot.png | Bin 0 -> 311039 bytes doc/sphinx/_static/tutorial/05/pltgot2.png | Bin 0 -> 296777 bytes doc/sphinx/_static/tutorial/05/pltgot3.png | Bin 0 -> 305117 bytes doc/sphinx/api/c/elf.rst | 95 + doc/sphinx/api/c/index.rst | 12 + doc/sphinx/api/c/macho.rst | 60 + doc/sphinx/api/c/pe.rst | 34 + doc/sphinx/api/cpp/abstract.rst | 62 + doc/sphinx/api/cpp/elf.rst | 154 + doc/sphinx/api/cpp/index.rst | 116 + doc/sphinx/api/cpp/macho.rst | 126 + doc/sphinx/api/cpp/pe.rst | 163 + doc/sphinx/api/index.rst | 12 + doc/sphinx/api/python/abstract.rst | 40 + doc/sphinx/api/python/elf.rst | 293 + doc/sphinx/api/python/index.rst | 14 + doc/sphinx/api/python/macho.rst | 152 + doc/sphinx/api/python/pe.rst | 362 + doc/sphinx/compilation.rst | 76 + doc/sphinx/conf.py.in | 316 + doc/sphinx/formats/elf.rst | 131 + doc/sphinx/formats/index.rst | 9 + doc/sphinx/formats/pe.rst | 55 + doc/sphinx/getting_started.rst | 99 + doc/sphinx/index.rst | 21 + doc/sphinx/installation.rst | 30 + doc/sphinx/references.rst | 139 + doc/sphinx/tutorials/00_play_with_formats.rst | 74 + doc/sphinx/tutorials/02_pe_from_scratch.rst | 155 + .../tutorials/03_elf_change_symbols.rst | 172 + doc/sphinx/tutorials/04_elf_hooking.rst | 70 + .../tutorials/05_elf_infect_plt_got.rst | 189 + doc/sphinx/tutorials/index.rst | 14 + examples/c/CMakeLists.txt | 75 + examples/c/elf_reader.c | 252 + examples/c/macho_reader.c | 158 + examples/c/pe_reader.c | 143 + examples/cpp/CMakeLists.txt | 76 + examples/cpp/abstract_reader.cpp | 62 + examples/cpp/elf_add_section.cpp | 49 + examples/cpp/elf_builder.cpp | 47 + examples/cpp/elf_reader.cpp | 120 + examples/cpp/elf_section_rename.cpp | 71 + examples/cpp/elf_strip.cpp | 36 + examples/cpp/elf_symbols.cpp | 48 + examples/cpp/macho_builder.cpp | 50 + examples/cpp/macho_instrumentation.cpp | 92 + examples/cpp/macho_reader.cpp | 109 + examples/cpp/pe_builder.cpp | 54 + examples/cpp/pe_reader.cpp | 104 + examples/python/abstract_json.py | 25 + examples/python/abstract_reader.py | 110 + examples/python/elf_json.py | 43 + examples/python/elf_reader.py | 392 + examples/python/elf_remove_section_table.py | 41 + examples/python/elf_symbol_obfuscation.py | 59 + examples/python/elf_unstrip.py | 57 + examples/python/entropy.py | 103 + examples/python/keygen/KeygenMe | Bin 0 -> 10140 bytes examples/python/keygen/lief_patch.py | 50 + .../library_symbols_obfuscation/Makefile | 26 + .../library_symbols_obfuscation/README.md | 8 + .../library_symbols_obfuscation/binadd.c | 16 + .../library_symbols_obfuscation/libadd.c | 9 + .../library_symbols_obfuscation/libadd.h | 16 + .../library_symbols_obfuscation/obfu.py | 30 + examples/python/macho_reader.py | 91 + examples/python/nm.py | 39 + examples/python/pe_authenticode.py | 44 + examples/python/pe_from_scratch.py | 69 + examples/python/pe_reader.py | 382 + include/LIEF/Abstract/Abstract.hpp | 24 + include/LIEF/Abstract/Binary.hpp | 129 + include/LIEF/Abstract/EnumToString.hpp | 30 + include/LIEF/Abstract/Header.hpp | 62 + include/LIEF/Abstract/Parser.hpp | 48 + include/LIEF/Abstract/Section.hpp | 86 + include/LIEF/Abstract/Symbol.hpp | 50 + include/LIEF/Abstract/enums.hpp | 73 + include/LIEF/Abstract/type_traits.hpp | 34 + include/LIEF/BinaryStream/BinaryStream.hpp | 68 + include/LIEF/BinaryStream/VectorStream.hpp | 41 + include/LIEF/Builder.hpp | 24 + include/LIEF/ELF.hpp | 28 + include/LIEF/ELF/Binary.hpp | 414 + include/LIEF/ELF/Builder.hpp | 112 + include/LIEF/ELF/DataHandler/Handler.hpp | 52 + include/LIEF/ELF/DataHandler/Node.hpp | 58 + include/LIEF/ELF/DynamicEntry.hpp | 69 + include/LIEF/ELF/DynamicEntryArray.hpp | 52 + include/LIEF/ELF/DynamicEntryLibrary.hpp | 52 + include/LIEF/ELF/DynamicEntryRpath.hpp | 56 + include/LIEF/ELF/DynamicEntryRunPath.hpp | 54 + include/LIEF/ELF/DynamicSharedObject.hpp | 49 + include/LIEF/ELF/EnumToString.hpp | 43 + include/LIEF/ELF/GnuHash.hpp | 86 + include/LIEF/ELF/Header.hpp | 188 + include/LIEF/ELF/Parser.hpp | 164 + include/LIEF/ELF/Relocation.hpp | 82 + include/LIEF/ELF/Relocations/AArch64.def | 147 + include/LIEF/ELF/Relocations/ARM.def | 138 + include/LIEF/ELF/Relocations/Hexagon.def | 100 + include/LIEF/ELF/Relocations/Mips.def | 117 + include/LIEF/ELF/Relocations/PowerPC.def | 61 + include/LIEF/ELF/Relocations/PowerPC64.def | 88 + include/LIEF/ELF/Relocations/Sparc.def | 89 + include/LIEF/ELF/Relocations/SystemZ.def | 67 + include/LIEF/ELF/Relocations/i386.def | 47 + include/LIEF/ELF/Relocations/x86_64.def | 44 + include/LIEF/ELF/Section.hpp | 127 + include/LIEF/ELF/Segment.hpp | 107 + include/LIEF/ELF/Structures.hpp.in | 95 + include/LIEF/ELF/Symbol.hpp | 103 + include/LIEF/ELF/SymbolVersion.hpp | 66 + include/LIEF/ELF/SymbolVersionAux.hpp | 57 + .../LIEF/ELF/SymbolVersionAuxRequirement.hpp | 73 + include/LIEF/ELF/SymbolVersionDefinition.hpp | 94 + include/LIEF/ELF/SymbolVersionRequirement.hpp | 83 + include/LIEF/ELF/enums.hpp.in | 11 + include/LIEF/ELF/enums.inc | 952 +++ include/LIEF/ELF/structures.inc | 273 + include/LIEF/ELF/type_traits.hpp | 83 + include/LIEF/ELF/utils.hpp | 37 + include/LIEF/LIEF.hpp | 25 + include/LIEF/MachO.hpp | 24 + include/LIEF/MachO/Binary.hpp | 183 + include/LIEF/MachO/BinaryParser.hpp | 76 + include/LIEF/MachO/Builder.hpp | 66 + include/LIEF/MachO/DylibCommand.hpp | 67 + include/LIEF/MachO/DylinkerCommand.hpp | 57 + include/LIEF/MachO/DynamicSymbolCommand.hpp | 116 + include/LIEF/MachO/EnumToString.hpp | 37 + include/LIEF/MachO/Header.hpp | 85 + include/LIEF/MachO/LoadCommand.hpp | 69 + include/LIEF/MachO/MainCommand.hpp | 61 + include/LIEF/MachO/Parser.hpp | 55 + include/LIEF/MachO/Section.hpp | 113 + include/LIEF/MachO/SegmentCommand.hpp | 115 + include/LIEF/MachO/Structures.hpp.in | 505 ++ include/LIEF/MachO/Symbol.hpp | 70 + include/LIEF/MachO/SymbolCommand.hpp | 65 + include/LIEF/MachO/UUIDCommand.hpp | 58 + include/LIEF/MachO/enums.hpp.in | 11 + include/LIEF/MachO/enums.inc | 604 ++ include/LIEF/MachO/structures.inc | 611 ++ include/LIEF/MachO/type_traits.hpp | 57 + include/LIEF/MachO/utils.hpp | 33 + include/LIEF/PE.hpp | 26 + include/LIEF/PE/AuxiliarySymbol.hpp | 29 + include/LIEF/PE/Binary.hpp | 327 + include/LIEF/PE/Builder.hpp | 116 + include/LIEF/PE/DataDirectory.hpp | 78 + include/LIEF/PE/Debug.hpp | 87 + include/LIEF/PE/DosHeader.hpp | 112 + include/LIEF/PE/EnumToString.hpp | 51 + include/LIEF/PE/Export.hpp | 87 + include/LIEF/PE/ExportEntry.hpp | 75 + include/LIEF/PE/Header.hpp | 85 + include/LIEF/PE/Import.hpp | 136 + include/LIEF/PE/ImportEntry.hpp | 95 + include/LIEF/PE/OptionalHeader.hpp | 144 + include/LIEF/PE/Parser.hpp | 99 + include/LIEF/PE/Relocation.hpp | 68 + include/LIEF/PE/RelocationEntry.hpp | 68 + include/LIEF/PE/ResourceData.hpp | 63 + include/LIEF/PE/ResourceDirectory.hpp | 69 + include/LIEF/PE/ResourceNode.hpp | 72 + include/LIEF/PE/ResourcesManager.hpp | 56 + include/LIEF/PE/Section.hpp | 112 + include/LIEF/PE/Structures.hpp.in | 201 + include/LIEF/PE/Symbol.hpp | 85 + include/LIEF/PE/TLS.hpp | 96 + include/LIEF/PE/enums.hpp.in | 13 + include/LIEF/PE/enums.inc | 369 + .../PE/signature/AuthenticatedAttributes.hpp | 69 + include/LIEF/PE/signature/ContentInfo.hpp | 72 + include/LIEF/PE/signature/OIDToString.hpp | 30 + include/LIEF/PE/signature/Signature.hpp | 84 + include/LIEF/PE/signature/SignerInfo.hpp | 80 + include/LIEF/PE/signature/types.hpp | 34 + include/LIEF/PE/signature/x509.hpp | 83 + include/LIEF/PE/structures.inc | 313 + include/LIEF/PE/type_traits.hpp | 66 + include/LIEF/PE/undef.h | 277 + include/LIEF/PE/utils.hpp | 47 + include/LIEF/Visitable.hpp | 33 + include/LIEF/Visitor.hpp | 334 + include/LIEF/exception.hpp | 129 + include/LIEF/filesystem/filesystem.h | 8 + include/LIEF/filesystem/fwd.h | 24 + include/LIEF/filesystem/path.h | 339 + include/LIEF/filesystem/resolver.h | 72 + include/LIEF/iostream.hpp | 54 + include/LIEF/iterators.hpp | 745 ++ include/LIEF/json.hpp | 22 + include/LIEF/logging.hpp | 50 + include/LIEF/to_json.hpp | 42 + include/LIEF/types.hpp | 20 + include/LIEF/utf8.h | 34 + include/LIEF/utf8/checked.h | 327 + include/LIEF/utf8/core.h | 329 + include/LIEF/utf8/unchecked.h | 228 + include/LIEF/utils.hpp | 23 + include/LIEF/version.h.in | 30 + include/LIEF/visibility.h | 27 + include/LIEF/visitors/Hash.hpp | 74 + include/LIEF/visitors/elf_json.hpp | 59 + include/LIEF/visitors/json.hpp | 50 + package/CMakeLists.txt | 30 + package/CPack.STGZ_Header.sh.in | 132 + package/Welcome | 0 scripts/FindLIEF.cmake | 64 + src/Abstract/Binary.cpp | 110 + src/Abstract/EnumToString.cpp | 86 + src/Abstract/Header.cpp | 96 + src/Abstract/Parser.cpp | 82 + src/Abstract/Section.cpp | 137 + src/Abstract/Symbol.cpp | 60 + src/BinaryStream/BinaryStream.cpp | 19 + src/BinaryStream/VectorStream.cpp | 94 + src/ELF/Binary.cpp | 1575 ++++ src/ELF/Builder.cpp | 156 + src/ELF/Builder.tcc | 1264 +++ src/ELF/CMakeLists.txt | 45 + src/ELF/DataHandler/Handler.cpp | 163 + src/ELF/DataHandler/Node.cpp | 70 + src/ELF/DynamicEntry.cpp | 118 + src/ELF/DynamicEntryArray.cpp | 82 + src/ELF/DynamicEntryLibrary.cpp | 72 + src/ELF/DynamicEntryRpath.cpp | 80 + src/ELF/DynamicEntryRunPath.cpp | 77 + src/ELF/DynamicSharedObject.cpp | 66 + src/ELF/EnumToString.cpp | 763 ++ src/ELF/GnuHash.cpp | 130 + src/ELF/Header.cpp | 395 + src/ELF/Parser.cpp | 211 + src/ELF/Parser.tcc | 1251 +++ src/ELF/Relocation.cpp | 227 + src/ELF/Section.cpp | 343 + src/ELF/Segment.cpp | 326 + src/ELF/Symbol.cpp | 264 + src/ELF/SymbolVersion.cpp | 105 + src/ELF/SymbolVersionAux.cpp | 64 + src/ELF/SymbolVersionAuxRequirement.cpp | 101 + src/ELF/SymbolVersionDefinition.cpp | 156 + src/ELF/SymbolVersionRequirement.cpp | 140 + src/ELF/utils.cpp | 88 + src/MachO/Binary.cpp | 541 ++ src/MachO/BinaryParser.cpp | 128 + src/MachO/BinaryParser.tcc | 326 + src/MachO/Builder.cpp | 266 + src/MachO/Builder.tcc | 180 + src/MachO/CMakeLists.txt | 38 + src/MachO/DylibCommand.cpp | 109 + src/MachO/DylinkerCommand.cpp | 71 + src/MachO/DynamicSymbolCommand.cpp | 143 + src/MachO/EnumToString.cpp | 259 + src/MachO/Header.cpp | 230 + src/MachO/LoadCommand.cpp | 102 + src/MachO/MainCommand.cpp | 87 + src/MachO/Parser.cpp | 110 + src/MachO/Section.cpp | 284 + src/MachO/SegmentCommand.cpp | 226 + src/MachO/Symbol.cpp | 131 + src/MachO/SymbolCommand.cpp | 98 + src/MachO/UUIDCommand.cpp | 74 + src/MachO/utils.cpp | 103 + src/PE/Binary.cpp | 1109 +++ src/PE/Builder.cpp | 527 ++ src/PE/Builder.tcc | 526 ++ src/PE/CMakeLists.txt | 52 + src/PE/DataDirectory.cpp | 149 + src/PE/Debug.cpp | 160 + src/PE/DosHeader.cpp | 325 + src/PE/EnumToString.cpp | 417 + src/PE/Export.cpp | 136 + src/PE/ExportEntry.cpp | 103 + src/PE/Header.cpp | 230 + src/PE/Import.cpp | 279 + src/PE/ImportEntry.cpp | 138 + src/PE/OptionalHeader.cpp | 559 ++ src/PE/Parser.cpp | 1036 +++ src/PE/Parser.tcc | 376 + src/PE/Relocation.cpp | 105 + src/PE/RelocationEntry.cpp | 103 + src/PE/ResourceData.cpp | 72 + src/PE/ResourceDirectory.cpp | 98 + src/PE/ResourceNode.cpp | 138 + src/PE/ResourcesManager.cpp | 110 + src/PE/Section.cpp | 282 + src/PE/Symbol.cpp | 192 + src/PE/TLS.cpp | 246 + src/PE/pkcs7.h | 40 + src/PE/signature/AuthenticatedAttributes.cpp | 59 + src/PE/signature/ContentInfo.cpp | 64 + src/PE/signature/OIDToString.cpp | 2250 +++++ src/PE/signature/Signature.cpp | 83 + src/PE/signature/SignerInfo.cpp | 93 + src/PE/signature/x509.cpp | 179 + src/PE/utils.cpp | 151 + src/Visitable.cpp | 23 + src/Visitor.cpp | 265 + src/exception.cpp | 47 + src/iostream.cpp | 127 + src/logging.cpp | 39 + src/utils.cpp | 25 + src/visitors/elf_json.cpp | 337 + src/visitors/hash.cpp | 75 + src/visitors/json.cpp | 86 + tests/CMakeLists.txt | 285 + tests/GenerateConfigELF.py | 234 + tests/GenerateConfigELF32.py | 180 + tests/GenerateConfigMachO.py | 40 + tests/GenerateConfigPE.py | 188 + tests/config.yaml.in | 205 + tests/elf/CMakeLists.txt | 225 + tests/elf/add_content.py | 138 + tests/elf/add_section.py | 96 + tests/elf/add_segment.py | 95 + tests/elf/elf_test.py | 72 + tests/elf/fuzzing.py.in | 55 + tests/elf/hash_tests.py | 171 + tests/elf/hello_lief.bin | Bin 0 -> 5728 bytes tests/elf/test.py | 18 + tests/elf/test_builder.cpp | 158 + tests/elf/test_equality.cpp | 200 + tests/elf/test_modifier.cpp | 114 + tests/elf/test_parser.cpp | 184 + tests/elf/utils.cpp | 89 + tests/elf/utils.hpp | 32 + tests/elf/utils.py | 12 + tests/macho/CMakeLists.txt | 54 + tests/pe/CMakeLists.txt | 122 + tests/pe/builder.py | 14 + tests/pe/test_binary.cpp | 112 + tests/pe/test_builder.cpp | 198 + tests/pe/test_equality.cpp | 148 + tests/pe/test_parser.cpp | 350 + tests/pe/utils.cpp | 89 + tests/pe/utils.hpp | 32 + tests/run_python_test.bat.in | 5 + tests/test_iterators.cpp | 503 ++ 562 files changed, 83951 insertions(+) create mode 100644 .appveyor.yml create mode 100644 .dockerignore create mode 100644 .travis.yml create mode 100644 AUTHORS create mode 100644 Acknowledgements create mode 100644 CHANGELOG create mode 100644 CMakeLists.txt create mode 100644 CMakeModules/CodeCoverage.cmake create mode 100644 CMakeModules/CppcheckTargets.cmake create mode 100644 CMakeModules/FindYamlCpp.cmake create mode 100644 CMakeModules/Findcppcheck.cmake create mode 100644 CMakeModules/Findcppcheck.cpp create mode 100644 CMakeModules/Toolchain-mingw32.cmake create mode 100644 LICENSE create mode 100644 README.md create mode 100644 api/c/CMakeLists.txt create mode 100644 api/c/ELF/Binary.cpp create mode 100644 api/c/ELF/Binary.hpp create mode 100644 api/c/ELF/DynamicEntry.cpp create mode 100644 api/c/ELF/DynamicEntry.hpp create mode 100644 api/c/ELF/EnumToString.cpp create mode 100644 api/c/ELF/Header.cpp create mode 100644 api/c/ELF/Header.hpp create mode 100644 api/c/ELF/Section.cpp create mode 100644 api/c/ELF/Section.hpp create mode 100644 api/c/ELF/Segment.cpp create mode 100644 api/c/ELF/Segment.hpp create mode 100644 api/c/ELF/Symbol.cpp create mode 100644 api/c/ELF/Symbol.hpp create mode 100644 api/c/MachO/Binary.cpp create mode 100644 api/c/MachO/Binary.hpp create mode 100644 api/c/MachO/EnumToString.cpp create mode 100644 api/c/MachO/Header.cpp create mode 100644 api/c/MachO/Header.hpp create mode 100644 api/c/MachO/LoadCommand.cpp create mode 100644 api/c/MachO/LoadCommand.hpp create mode 100644 api/c/MachO/Parser.cpp create mode 100644 api/c/MachO/Section.cpp create mode 100644 api/c/MachO/Section.hpp create mode 100644 api/c/MachO/Segment.cpp create mode 100644 api/c/MachO/Segment.hpp create mode 100644 api/c/MachO/Symbol.cpp create mode 100644 api/c/MachO/Symbol.hpp create mode 100644 api/c/PE/Binary.cpp create mode 100644 api/c/PE/Binary.hpp create mode 100644 api/c/PE/DataDirectory.cpp create mode 100644 api/c/PE/DataDirectory.hpp create mode 100644 api/c/PE/DosHeader.cpp create mode 100644 api/c/PE/DosHeader.hpp create mode 100644 api/c/PE/EnumToString.cpp create mode 100644 api/c/PE/Header.cpp create mode 100644 api/c/PE/Header.hpp create mode 100644 api/c/PE/OptionalHeader.cpp create mode 100644 api/c/PE/OptionalHeader.hpp create mode 100644 api/c/PE/Section.cpp create mode 100644 api/c/PE/Section.hpp create mode 100644 api/c/include/LIEF/ELF.h create mode 100644 api/c/include/LIEF/ELF/Binary.h create mode 100644 api/c/include/LIEF/ELF/DynamicEntry.h create mode 100644 api/c/include/LIEF/ELF/EnumToString.h create mode 100644 api/c/include/LIEF/ELF/Header.h create mode 100644 api/c/include/LIEF/ELF/Section.h create mode 100644 api/c/include/LIEF/ELF/Segment.h create mode 100644 api/c/include/LIEF/ELF/Symbol.h create mode 100644 api/c/include/LIEF/ELF/enums.h.in create mode 100644 api/c/include/LIEF/ELF/structures.h.in create mode 100644 api/c/include/LIEF/LIEF.h create mode 100644 api/c/include/LIEF/MachO.h create mode 100644 api/c/include/LIEF/MachO/Binary.h create mode 100644 api/c/include/LIEF/MachO/EnumToString.h create mode 100644 api/c/include/LIEF/MachO/Header.h create mode 100644 api/c/include/LIEF/MachO/LoadCommand.h create mode 100644 api/c/include/LIEF/MachO/Section.h create mode 100644 api/c/include/LIEF/MachO/Segment.h create mode 100644 api/c/include/LIEF/MachO/Symbol.h create mode 100644 api/c/include/LIEF/MachO/enums.h.in create mode 100644 api/c/include/LIEF/MachO/structures.h.in create mode 100644 api/c/include/LIEF/PE.h create mode 100644 api/c/include/LIEF/PE/Binary.h create mode 100644 api/c/include/LIEF/PE/DataDirectory.h create mode 100644 api/c/include/LIEF/PE/DosHeader.h create mode 100644 api/c/include/LIEF/PE/EnumToString.h create mode 100644 api/c/include/LIEF/PE/Header.h create mode 100644 api/c/include/LIEF/PE/OptionalHeader.h create mode 100644 api/c/include/LIEF/PE/Section.h create mode 100644 api/c/include/LIEF/PE/enums.h.in create mode 100644 api/c/include/LIEF/PE/structures.h.in create mode 100644 api/python/Abstract/init.cpp create mode 100644 api/python/Abstract/init.hpp create mode 100644 api/python/Abstract/objects/pyBinary.cpp create mode 100644 api/python/Abstract/objects/pyHeader.cpp create mode 100644 api/python/Abstract/objects/pyParser.cpp create mode 100644 api/python/Abstract/objects/pySection.cpp create mode 100644 api/python/Abstract/objects/pySymbol.cpp create mode 100644 api/python/Abstract/pyEnums.cpp create mode 100644 api/python/CMakeLists.txt create mode 100644 api/python/ELF/CMakeLists.txt create mode 100644 api/python/ELF/objects/pyBinary.cpp create mode 100644 api/python/ELF/objects/pyBuilder.cpp create mode 100644 api/python/ELF/objects/pyDynamicEntry.cpp create mode 100644 api/python/ELF/objects/pyDynamicEntryArray.cpp create mode 100644 api/python/ELF/objects/pyDynamicEntryLibrary.cpp create mode 100644 api/python/ELF/objects/pyDynamicEntryRpath.cpp create mode 100644 api/python/ELF/objects/pyDynamicEntryRunPath.cpp create mode 100644 api/python/ELF/objects/pyDynamicSharedObject.cpp create mode 100644 api/python/ELF/objects/pyGnuHash.cpp create mode 100644 api/python/ELF/objects/pyHeader.cpp create mode 100644 api/python/ELF/objects/pyParser.cpp create mode 100644 api/python/ELF/objects/pyRelocation.cpp create mode 100644 api/python/ELF/objects/pySection.cpp create mode 100644 api/python/ELF/objects/pySegment.cpp create mode 100644 api/python/ELF/objects/pySymbol.cpp create mode 100644 api/python/ELF/objects/pySymbolVersion.cpp create mode 100644 api/python/ELF/objects/pySymbolVersionAux.cpp create mode 100644 api/python/ELF/objects/pySymbolVersionAuxRequirement.cpp create mode 100644 api/python/ELF/objects/pySymbolVersionDefinition.cpp create mode 100644 api/python/ELF/objects/pySymbolVersionRequirement.cpp create mode 100644 api/python/ELF/pyELF.cpp create mode 100644 api/python/ELF/pyELF.hpp create mode 100644 api/python/ELF/pyELFStructures.cpp create mode 100644 api/python/MANIFEST.in.in create mode 100644 api/python/MachO/CMakeLists.txt create mode 100644 api/python/MachO/objects/pyBinary.cpp create mode 100644 api/python/MachO/objects/pyDylibCommand.cpp create mode 100644 api/python/MachO/objects/pyHeader.cpp create mode 100644 api/python/MachO/objects/pyLoadCommand.cpp create mode 100644 api/python/MachO/objects/pyParser.cpp create mode 100644 api/python/MachO/objects/pySection.cpp create mode 100644 api/python/MachO/objects/pySegmentCommand.cpp create mode 100644 api/python/MachO/objects/pySymbol.cpp create mode 100644 api/python/MachO/pyMachO.cpp create mode 100644 api/python/MachO/pyMachO.hpp create mode 100644 api/python/MachO/pyMachOStructures.cpp create mode 100644 api/python/PE/CMakeLists.txt create mode 100644 api/python/PE/objects/pyBinary.cpp create mode 100644 api/python/PE/objects/pyBuilder.cpp create mode 100644 api/python/PE/objects/pyDataDirectory.cpp create mode 100644 api/python/PE/objects/pyDebug.cpp create mode 100644 api/python/PE/objects/pyDosHeader.cpp create mode 100644 api/python/PE/objects/pyExport.cpp create mode 100644 api/python/PE/objects/pyExportEntry.cpp create mode 100644 api/python/PE/objects/pyHeader.cpp create mode 100644 api/python/PE/objects/pyImport.cpp create mode 100644 api/python/PE/objects/pyImportEntry.cpp create mode 100644 api/python/PE/objects/pyOptionalHeader.cpp create mode 100644 api/python/PE/objects/pyParser.cpp create mode 100644 api/python/PE/objects/pyRelocation.cpp create mode 100644 api/python/PE/objects/pyRelocationEntry.cpp create mode 100644 api/python/PE/objects/pyResourcesManager.cpp create mode 100644 api/python/PE/objects/pySection.cpp create mode 100644 api/python/PE/objects/pySymbol.cpp create mode 100644 api/python/PE/objects/pyTLS.cpp create mode 100644 api/python/PE/objects/signature/pyAuthenticatedAttributes.cpp create mode 100644 api/python/PE/objects/signature/pyContentInfo.cpp create mode 100644 api/python/PE/objects/signature/pySignature.cpp create mode 100644 api/python/PE/objects/signature/pySignerInfo.cpp create mode 100644 api/python/PE/objects/signature/pyx509.cpp create mode 100644 api/python/PE/pyPE.cpp create mode 100644 api/python/PE/pyPE.hpp create mode 100644 api/python/PE/pyPEStructures.cpp create mode 100644 api/python/README.in create mode 100644 api/python/__init__.py.in create mode 100644 api/python/pyExceptions.cpp create mode 100644 api/python/pyIterators.cpp create mode 100644 api/python/pyIterators.hpp create mode 100644 api/python/pyJson.cpp create mode 100644 api/python/pyLIEF.cpp create mode 100644 api/python/pyLIEF.hpp create mode 100644 api/python/pyUtils.cpp create mode 100644 api/python/setup.py.in create mode 100644 doc/CMakeLists.txt create mode 100644 doc/doxygen/Doxyfile.in create mode 100644 doc/doxygen/bootstrap.min.css create mode 100644 doc/doxygen/css/bootstrap-theme.css create mode 100644 doc/doxygen/css/bootstrap-theme.css.map create mode 100644 doc/doxygen/css/bootstrap-theme.min.css create mode 100644 doc/doxygen/css/bootstrap-theme.min.css.map create mode 100644 doc/doxygen/css/bootstrap.css create mode 100644 doc/doxygen/css/bootstrap.css.map create mode 100644 doc/doxygen/css/bootstrap.min.css create mode 100644 doc/doxygen/css/bootstrap.min.css.map create mode 100644 doc/doxygen/css/font-awesome.min.css create mode 100644 doc/doxygen/css/style.css create mode 100644 doc/doxygen/css/syntax.css create mode 100644 doc/doxygen/customdoxygen.css create mode 100644 doc/doxygen/doxy-boot.js create mode 100644 doc/doxygen/fonts/fontawesome-webfont.eot create mode 100644 doc/doxygen/fonts/fontawesome-webfont.svg create mode 100644 doc/doxygen/fonts/fontawesome-webfont.ttf create mode 100644 doc/doxygen/fonts/fontawesome-webfont.woff create mode 100644 doc/doxygen/fonts/fontawesome-webfont.woff2 create mode 100644 doc/doxygen/fonts/glyphicons-halflings-regular.eot create mode 100644 doc/doxygen/fonts/glyphicons-halflings-regular.svg create mode 100644 doc/doxygen/fonts/glyphicons-halflings-regular.ttf create mode 100644 doc/doxygen/fonts/glyphicons-halflings-regular.woff create mode 100644 doc/doxygen/fonts/glyphicons-halflings-regular.woff2 create mode 100644 doc/doxygen/footer.html create mode 100644 doc/doxygen/header.html create mode 100644 doc/doxygen/index.doxygen create mode 100644 doc/doxygen/js/application.js create mode 100644 doc/doxygen/js/bootstrap.js create mode 100644 doc/doxygen/js/bootstrap.min.js create mode 100644 doc/doxygen/js/jquery-1.9.1.min.js create mode 100644 doc/doxygen/js/jquery-2.2.4.min.js create mode 100644 doc/doxygen/js/jquery-3.0.0.min.js create mode 100644 doc/doxygen/js/npm.js create mode 100644 doc/doxygen/logo_lief_55.png create mode 100644 doc/doxygen/welcome.html create mode 100644 doc/sphinx/Intro.rst create mode 100644 doc/sphinx/_static/archi.png create mode 100644 doc/sphinx/_static/archi_elf.png create mode 100644 doc/sphinx/_static/data_handler.png create mode 100644 doc/sphinx/_static/example.cpp create mode 100644 doc/sphinx/_static/favicon.ico create mode 100644 doc/sphinx/_static/iat3.png create mode 100644 doc/sphinx/_static/iat4.png create mode 100644 doc/sphinx/_static/logo_blue.png create mode 100644 doc/sphinx/_static/logo_blue_412.png create mode 100644 doc/sphinx/_static/tutorial/03/hashme.png create mode 100644 doc/sphinx/_static/tutorial/03/hashme_obf.png create mode 100644 doc/sphinx/_static/tutorial/05/pltgot.png create mode 100644 doc/sphinx/_static/tutorial/05/pltgot2.png create mode 100644 doc/sphinx/_static/tutorial/05/pltgot3.png create mode 100644 doc/sphinx/api/c/elf.rst create mode 100644 doc/sphinx/api/c/index.rst create mode 100644 doc/sphinx/api/c/macho.rst create mode 100644 doc/sphinx/api/c/pe.rst create mode 100644 doc/sphinx/api/cpp/abstract.rst create mode 100644 doc/sphinx/api/cpp/elf.rst create mode 100644 doc/sphinx/api/cpp/index.rst create mode 100644 doc/sphinx/api/cpp/macho.rst create mode 100644 doc/sphinx/api/cpp/pe.rst create mode 100644 doc/sphinx/api/index.rst create mode 100644 doc/sphinx/api/python/abstract.rst create mode 100644 doc/sphinx/api/python/elf.rst create mode 100644 doc/sphinx/api/python/index.rst create mode 100644 doc/sphinx/api/python/macho.rst create mode 100644 doc/sphinx/api/python/pe.rst create mode 100644 doc/sphinx/compilation.rst create mode 100644 doc/sphinx/conf.py.in create mode 100644 doc/sphinx/formats/elf.rst create mode 100644 doc/sphinx/formats/index.rst create mode 100644 doc/sphinx/formats/pe.rst create mode 100644 doc/sphinx/getting_started.rst create mode 100644 doc/sphinx/index.rst create mode 100644 doc/sphinx/installation.rst create mode 100644 doc/sphinx/references.rst create mode 100644 doc/sphinx/tutorials/00_play_with_formats.rst create mode 100644 doc/sphinx/tutorials/02_pe_from_scratch.rst create mode 100644 doc/sphinx/tutorials/03_elf_change_symbols.rst create mode 100644 doc/sphinx/tutorials/04_elf_hooking.rst create mode 100644 doc/sphinx/tutorials/05_elf_infect_plt_got.rst create mode 100644 doc/sphinx/tutorials/index.rst create mode 100644 examples/c/CMakeLists.txt create mode 100644 examples/c/elf_reader.c create mode 100644 examples/c/macho_reader.c create mode 100644 examples/c/pe_reader.c create mode 100644 examples/cpp/CMakeLists.txt create mode 100644 examples/cpp/abstract_reader.cpp create mode 100644 examples/cpp/elf_add_section.cpp create mode 100644 examples/cpp/elf_builder.cpp create mode 100644 examples/cpp/elf_reader.cpp create mode 100644 examples/cpp/elf_section_rename.cpp create mode 100644 examples/cpp/elf_strip.cpp create mode 100644 examples/cpp/elf_symbols.cpp create mode 100644 examples/cpp/macho_builder.cpp create mode 100644 examples/cpp/macho_instrumentation.cpp create mode 100644 examples/cpp/macho_reader.cpp create mode 100644 examples/cpp/pe_builder.cpp create mode 100644 examples/cpp/pe_reader.cpp create mode 100644 examples/python/abstract_json.py create mode 100644 examples/python/abstract_reader.py create mode 100644 examples/python/elf_json.py create mode 100644 examples/python/elf_reader.py create mode 100644 examples/python/elf_remove_section_table.py create mode 100644 examples/python/elf_symbol_obfuscation.py create mode 100644 examples/python/elf_unstrip.py create mode 100644 examples/python/entropy.py create mode 100644 examples/python/keygen/KeygenMe create mode 100644 examples/python/keygen/lief_patch.py create mode 100644 examples/python/library_symbols_obfuscation/Makefile create mode 100644 examples/python/library_symbols_obfuscation/README.md create mode 100644 examples/python/library_symbols_obfuscation/binadd.c create mode 100644 examples/python/library_symbols_obfuscation/libadd.c create mode 100644 examples/python/library_symbols_obfuscation/libadd.h create mode 100644 examples/python/library_symbols_obfuscation/obfu.py create mode 100644 examples/python/macho_reader.py create mode 100644 examples/python/nm.py create mode 100644 examples/python/pe_authenticode.py create mode 100644 examples/python/pe_from_scratch.py create mode 100755 examples/python/pe_reader.py create mode 100644 include/LIEF/Abstract/Abstract.hpp create mode 100644 include/LIEF/Abstract/Binary.hpp create mode 100644 include/LIEF/Abstract/EnumToString.hpp create mode 100644 include/LIEF/Abstract/Header.hpp create mode 100644 include/LIEF/Abstract/Parser.hpp create mode 100644 include/LIEF/Abstract/Section.hpp create mode 100644 include/LIEF/Abstract/Symbol.hpp create mode 100644 include/LIEF/Abstract/enums.hpp create mode 100644 include/LIEF/Abstract/type_traits.hpp create mode 100644 include/LIEF/BinaryStream/BinaryStream.hpp create mode 100644 include/LIEF/BinaryStream/VectorStream.hpp create mode 100644 include/LIEF/Builder.hpp create mode 100644 include/LIEF/ELF.hpp create mode 100644 include/LIEF/ELF/Binary.hpp create mode 100644 include/LIEF/ELF/Builder.hpp create mode 100644 include/LIEF/ELF/DataHandler/Handler.hpp create mode 100644 include/LIEF/ELF/DataHandler/Node.hpp create mode 100644 include/LIEF/ELF/DynamicEntry.hpp create mode 100644 include/LIEF/ELF/DynamicEntryArray.hpp create mode 100644 include/LIEF/ELF/DynamicEntryLibrary.hpp create mode 100644 include/LIEF/ELF/DynamicEntryRpath.hpp create mode 100644 include/LIEF/ELF/DynamicEntryRunPath.hpp create mode 100644 include/LIEF/ELF/DynamicSharedObject.hpp create mode 100644 include/LIEF/ELF/EnumToString.hpp create mode 100644 include/LIEF/ELF/GnuHash.hpp create mode 100644 include/LIEF/ELF/Header.hpp create mode 100644 include/LIEF/ELF/Parser.hpp create mode 100644 include/LIEF/ELF/Relocation.hpp create mode 100644 include/LIEF/ELF/Relocations/AArch64.def create mode 100644 include/LIEF/ELF/Relocations/ARM.def create mode 100644 include/LIEF/ELF/Relocations/Hexagon.def create mode 100644 include/LIEF/ELF/Relocations/Mips.def create mode 100644 include/LIEF/ELF/Relocations/PowerPC.def create mode 100644 include/LIEF/ELF/Relocations/PowerPC64.def create mode 100644 include/LIEF/ELF/Relocations/Sparc.def create mode 100644 include/LIEF/ELF/Relocations/SystemZ.def create mode 100644 include/LIEF/ELF/Relocations/i386.def create mode 100644 include/LIEF/ELF/Relocations/x86_64.def create mode 100644 include/LIEF/ELF/Section.hpp create mode 100644 include/LIEF/ELF/Segment.hpp create mode 100644 include/LIEF/ELF/Structures.hpp.in create mode 100644 include/LIEF/ELF/Symbol.hpp create mode 100644 include/LIEF/ELF/SymbolVersion.hpp create mode 100644 include/LIEF/ELF/SymbolVersionAux.hpp create mode 100644 include/LIEF/ELF/SymbolVersionAuxRequirement.hpp create mode 100644 include/LIEF/ELF/SymbolVersionDefinition.hpp create mode 100644 include/LIEF/ELF/SymbolVersionRequirement.hpp create mode 100644 include/LIEF/ELF/enums.hpp.in create mode 100644 include/LIEF/ELF/enums.inc create mode 100644 include/LIEF/ELF/structures.inc create mode 100644 include/LIEF/ELF/type_traits.hpp create mode 100644 include/LIEF/ELF/utils.hpp create mode 100644 include/LIEF/LIEF.hpp create mode 100644 include/LIEF/MachO.hpp create mode 100644 include/LIEF/MachO/Binary.hpp create mode 100644 include/LIEF/MachO/BinaryParser.hpp create mode 100644 include/LIEF/MachO/Builder.hpp create mode 100644 include/LIEF/MachO/DylibCommand.hpp create mode 100644 include/LIEF/MachO/DylinkerCommand.hpp create mode 100644 include/LIEF/MachO/DynamicSymbolCommand.hpp create mode 100644 include/LIEF/MachO/EnumToString.hpp create mode 100644 include/LIEF/MachO/Header.hpp create mode 100644 include/LIEF/MachO/LoadCommand.hpp create mode 100644 include/LIEF/MachO/MainCommand.hpp create mode 100644 include/LIEF/MachO/Parser.hpp create mode 100644 include/LIEF/MachO/Section.hpp create mode 100644 include/LIEF/MachO/SegmentCommand.hpp create mode 100644 include/LIEF/MachO/Structures.hpp.in create mode 100644 include/LIEF/MachO/Symbol.hpp create mode 100644 include/LIEF/MachO/SymbolCommand.hpp create mode 100644 include/LIEF/MachO/UUIDCommand.hpp create mode 100644 include/LIEF/MachO/enums.hpp.in create mode 100644 include/LIEF/MachO/enums.inc create mode 100644 include/LIEF/MachO/structures.inc create mode 100644 include/LIEF/MachO/type_traits.hpp create mode 100644 include/LIEF/MachO/utils.hpp create mode 100644 include/LIEF/PE.hpp create mode 100644 include/LIEF/PE/AuxiliarySymbol.hpp create mode 100644 include/LIEF/PE/Binary.hpp create mode 100644 include/LIEF/PE/Builder.hpp create mode 100644 include/LIEF/PE/DataDirectory.hpp create mode 100644 include/LIEF/PE/Debug.hpp create mode 100644 include/LIEF/PE/DosHeader.hpp create mode 100644 include/LIEF/PE/EnumToString.hpp create mode 100644 include/LIEF/PE/Export.hpp create mode 100644 include/LIEF/PE/ExportEntry.hpp create mode 100644 include/LIEF/PE/Header.hpp create mode 100644 include/LIEF/PE/Import.hpp create mode 100644 include/LIEF/PE/ImportEntry.hpp create mode 100644 include/LIEF/PE/OptionalHeader.hpp create mode 100644 include/LIEF/PE/Parser.hpp create mode 100644 include/LIEF/PE/Relocation.hpp create mode 100644 include/LIEF/PE/RelocationEntry.hpp create mode 100644 include/LIEF/PE/ResourceData.hpp create mode 100644 include/LIEF/PE/ResourceDirectory.hpp create mode 100644 include/LIEF/PE/ResourceNode.hpp create mode 100644 include/LIEF/PE/ResourcesManager.hpp create mode 100644 include/LIEF/PE/Section.hpp create mode 100644 include/LIEF/PE/Structures.hpp.in create mode 100644 include/LIEF/PE/Symbol.hpp create mode 100644 include/LIEF/PE/TLS.hpp create mode 100644 include/LIEF/PE/enums.hpp.in create mode 100644 include/LIEF/PE/enums.inc create mode 100644 include/LIEF/PE/signature/AuthenticatedAttributes.hpp create mode 100644 include/LIEF/PE/signature/ContentInfo.hpp create mode 100644 include/LIEF/PE/signature/OIDToString.hpp create mode 100644 include/LIEF/PE/signature/Signature.hpp create mode 100644 include/LIEF/PE/signature/SignerInfo.hpp create mode 100644 include/LIEF/PE/signature/types.hpp create mode 100644 include/LIEF/PE/signature/x509.hpp create mode 100644 include/LIEF/PE/structures.inc create mode 100644 include/LIEF/PE/type_traits.hpp create mode 100644 include/LIEF/PE/undef.h create mode 100644 include/LIEF/PE/utils.hpp create mode 100644 include/LIEF/Visitable.hpp create mode 100644 include/LIEF/Visitor.hpp create mode 100644 include/LIEF/exception.hpp create mode 100644 include/LIEF/filesystem/filesystem.h create mode 100644 include/LIEF/filesystem/fwd.h create mode 100644 include/LIEF/filesystem/path.h create mode 100644 include/LIEF/filesystem/resolver.h create mode 100644 include/LIEF/iostream.hpp create mode 100644 include/LIEF/iterators.hpp create mode 100644 include/LIEF/json.hpp create mode 100644 include/LIEF/logging.hpp create mode 100644 include/LIEF/to_json.hpp create mode 100644 include/LIEF/types.hpp create mode 100644 include/LIEF/utf8.h create mode 100644 include/LIEF/utf8/checked.h create mode 100644 include/LIEF/utf8/core.h create mode 100644 include/LIEF/utf8/unchecked.h create mode 100644 include/LIEF/utils.hpp create mode 100644 include/LIEF/version.h.in create mode 100644 include/LIEF/visibility.h create mode 100644 include/LIEF/visitors/Hash.hpp create mode 100644 include/LIEF/visitors/elf_json.hpp create mode 100644 include/LIEF/visitors/json.hpp create mode 100644 package/CMakeLists.txt create mode 100644 package/CPack.STGZ_Header.sh.in create mode 100644 package/Welcome create mode 100644 scripts/FindLIEF.cmake create mode 100644 src/Abstract/Binary.cpp create mode 100644 src/Abstract/EnumToString.cpp create mode 100644 src/Abstract/Header.cpp create mode 100644 src/Abstract/Parser.cpp create mode 100644 src/Abstract/Section.cpp create mode 100644 src/Abstract/Symbol.cpp create mode 100644 src/BinaryStream/BinaryStream.cpp create mode 100644 src/BinaryStream/VectorStream.cpp create mode 100644 src/ELF/Binary.cpp create mode 100644 src/ELF/Builder.cpp create mode 100644 src/ELF/Builder.tcc create mode 100644 src/ELF/CMakeLists.txt create mode 100644 src/ELF/DataHandler/Handler.cpp create mode 100644 src/ELF/DataHandler/Node.cpp create mode 100644 src/ELF/DynamicEntry.cpp create mode 100644 src/ELF/DynamicEntryArray.cpp create mode 100644 src/ELF/DynamicEntryLibrary.cpp create mode 100644 src/ELF/DynamicEntryRpath.cpp create mode 100644 src/ELF/DynamicEntryRunPath.cpp create mode 100644 src/ELF/DynamicSharedObject.cpp create mode 100644 src/ELF/EnumToString.cpp create mode 100644 src/ELF/GnuHash.cpp create mode 100644 src/ELF/Header.cpp create mode 100644 src/ELF/Parser.cpp create mode 100644 src/ELF/Parser.tcc create mode 100644 src/ELF/Relocation.cpp create mode 100644 src/ELF/Section.cpp create mode 100644 src/ELF/Segment.cpp create mode 100644 src/ELF/Symbol.cpp create mode 100644 src/ELF/SymbolVersion.cpp create mode 100644 src/ELF/SymbolVersionAux.cpp create mode 100644 src/ELF/SymbolVersionAuxRequirement.cpp create mode 100644 src/ELF/SymbolVersionDefinition.cpp create mode 100644 src/ELF/SymbolVersionRequirement.cpp create mode 100644 src/ELF/utils.cpp create mode 100644 src/MachO/Binary.cpp create mode 100644 src/MachO/BinaryParser.cpp create mode 100644 src/MachO/BinaryParser.tcc create mode 100644 src/MachO/Builder.cpp create mode 100644 src/MachO/Builder.tcc create mode 100644 src/MachO/CMakeLists.txt create mode 100644 src/MachO/DylibCommand.cpp create mode 100644 src/MachO/DylinkerCommand.cpp create mode 100644 src/MachO/DynamicSymbolCommand.cpp create mode 100644 src/MachO/EnumToString.cpp create mode 100644 src/MachO/Header.cpp create mode 100644 src/MachO/LoadCommand.cpp create mode 100644 src/MachO/MainCommand.cpp create mode 100644 src/MachO/Parser.cpp create mode 100644 src/MachO/Section.cpp create mode 100644 src/MachO/SegmentCommand.cpp create mode 100644 src/MachO/Symbol.cpp create mode 100644 src/MachO/SymbolCommand.cpp create mode 100644 src/MachO/UUIDCommand.cpp create mode 100644 src/MachO/utils.cpp create mode 100644 src/PE/Binary.cpp create mode 100644 src/PE/Builder.cpp create mode 100644 src/PE/Builder.tcc create mode 100644 src/PE/CMakeLists.txt create mode 100644 src/PE/DataDirectory.cpp create mode 100644 src/PE/Debug.cpp create mode 100644 src/PE/DosHeader.cpp create mode 100644 src/PE/EnumToString.cpp create mode 100644 src/PE/Export.cpp create mode 100644 src/PE/ExportEntry.cpp create mode 100644 src/PE/Header.cpp create mode 100644 src/PE/Import.cpp create mode 100644 src/PE/ImportEntry.cpp create mode 100644 src/PE/OptionalHeader.cpp create mode 100644 src/PE/Parser.cpp create mode 100644 src/PE/Parser.tcc create mode 100644 src/PE/Relocation.cpp create mode 100644 src/PE/RelocationEntry.cpp create mode 100644 src/PE/ResourceData.cpp create mode 100644 src/PE/ResourceDirectory.cpp create mode 100644 src/PE/ResourceNode.cpp create mode 100644 src/PE/ResourcesManager.cpp create mode 100644 src/PE/Section.cpp create mode 100644 src/PE/Symbol.cpp create mode 100644 src/PE/TLS.cpp create mode 100644 src/PE/pkcs7.h create mode 100644 src/PE/signature/AuthenticatedAttributes.cpp create mode 100644 src/PE/signature/ContentInfo.cpp create mode 100644 src/PE/signature/OIDToString.cpp create mode 100644 src/PE/signature/Signature.cpp create mode 100644 src/PE/signature/SignerInfo.cpp create mode 100644 src/PE/signature/x509.cpp create mode 100644 src/PE/utils.cpp create mode 100644 src/Visitable.cpp create mode 100644 src/Visitor.cpp create mode 100644 src/exception.cpp create mode 100644 src/iostream.cpp create mode 100644 src/logging.cpp create mode 100644 src/utils.cpp create mode 100644 src/visitors/elf_json.cpp create mode 100644 src/visitors/hash.cpp create mode 100644 src/visitors/json.cpp create mode 100644 tests/CMakeLists.txt create mode 100644 tests/GenerateConfigELF.py create mode 100644 tests/GenerateConfigELF32.py create mode 100644 tests/GenerateConfigMachO.py create mode 100644 tests/GenerateConfigPE.py create mode 100644 tests/config.yaml.in create mode 100644 tests/elf/CMakeLists.txt create mode 100644 tests/elf/add_content.py create mode 100644 tests/elf/add_section.py create mode 100644 tests/elf/add_segment.py create mode 100644 tests/elf/elf_test.py create mode 100644 tests/elf/fuzzing.py.in create mode 100644 tests/elf/hash_tests.py create mode 100644 tests/elf/hello_lief.bin create mode 100644 tests/elf/test.py create mode 100644 tests/elf/test_builder.cpp create mode 100644 tests/elf/test_equality.cpp create mode 100644 tests/elf/test_modifier.cpp create mode 100644 tests/elf/test_parser.cpp create mode 100644 tests/elf/utils.cpp create mode 100644 tests/elf/utils.hpp create mode 100644 tests/elf/utils.py create mode 100644 tests/macho/CMakeLists.txt create mode 100644 tests/pe/CMakeLists.txt create mode 100644 tests/pe/builder.py create mode 100644 tests/pe/test_binary.cpp create mode 100644 tests/pe/test_builder.cpp create mode 100644 tests/pe/test_equality.cpp create mode 100644 tests/pe/test_parser.cpp create mode 100644 tests/pe/utils.cpp create mode 100644 tests/pe/utils.hpp create mode 100644 tests/run_python_test.bat.in create mode 100644 tests/test_iterators.cpp diff --git a/.appveyor.yml b/.appveyor.yml new file mode 100644 index 0000000..f302d85 --- /dev/null +++ b/.appveyor.yml @@ -0,0 +1,89 @@ +version: 0.4.{build} +image: Visual Studio 2015 +clone_folder: c:\projects\lief + +configuration: Release + +clone_depth: 5 + +platform: +- x86 +- x64 + +environment: + matrix: + # Python 2.7 + - PYTHON_VERSION: "2.7" + PYTHON32_PATH: "C:\\Python27" + PYTHON32_INCLUDE: "C:\\Python27\\include" + PYTHON32_BINARY: "C:\\Python27\\python.exe" + PYTHON32_LIBRARY: "C:\\Python27\\libs\\python27.lib" + PYTHON64_PATH: "C:\\Python27-x64" + PYTHON64_INCLUDE: "C:\\Python27-x64\\include" + PYTHON64_BINARY: "C:\\Python27-x64\\python.exe" + PYTHON64_LIBRARY: "C:\\Python27-x64\\libs\\python27.lib" + + + # Python 3.5 + - PYTHON_VERSION: "3.5" + PYTHON32_PATH: "C:\\Python35" + PYTHON32_INCLUDE: "C:\\Python35\\include" + PYTHON32_BINARY: "C:\\Python35\\python.exe" + PYTHON32_LIBRARY: "C:\\Python35\\libs\\python35.lib" + PYTHON64_PATH: "C:\\Python35-x64" + PYTHON64_INCLUDE: "C:\\Python35-x64\\include" + PYTHON64_BINARY: "C:\\Python35-x64\\python.exe" + PYTHON64_LIBRARY: "C:\\Python35-x64\\libs\\python35.lib" + + + # Python 3.6 + - PYTHON_VERSION: "3.6" + PYTHON32_PATH: "C:\\Python36" + PYTHON32_INCLUDE: "C:\\Python36\\include" + PYTHON32_BINARY: "C:\\Python36\\python.exe" + PYTHON32_LIBRARY: "C:\\Python36\\libs\\python36.lib" + PYTHON64_PATH: "C:\\Python36-x64" + PYTHON64_INCLUDE: "C:\\Python36-x64\\include" + PYTHON64_BINARY: "C:\\Python36-x64\\python.exe" + PYTHON64_LIBRARY: "C:\\Python36-x64\\libs\\python36.lib" + +matrix: + fast_finish: true # set this flag to immediately finish build once one of the jobs fails. + allow_failures: + - platform: x86 + configuration: Release + - platform: x64 + configuration: Release + +install: + - ps: if ($env:PLATFORM -eq "x64") { $env:CMAKE_ARCH = "x64" } + + - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_PATH = $env:PYTHON64_PATH } + - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_INCLUDE = $env:PYTHON64_INCLUDE } + - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_BINARY = $env:PYTHON64_BINARY } + - ps: if ($env:PLATFORM -eq "x64") { $env:PYTHON_LIBRARY = $env:PYTHON64_LIBRARY } + + - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_PATH = $env:PYTHON32_PATH } + - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_INCLUDE = $env:PYTHON32_INCLUDE } + - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_BINARY = $env:PYTHON32_BINARY } + - ps: if ($env:PLATFORM -eq "x86") { $env:PYTHON_LIBRARY = $env:PYTHON32_LIBRARY } + + - set PATH=%PYTHON_PATH%;%PATH% + +build_script: + - cmake -A "%CMAKE_ARCH%" -DLIEF_TESTS=on -DLIEF_PYTHON_API=on -DPYTHON_VERSION=%PYTHON_VERSION% -DPYTHON_INCLUDE_DIR=%PYTHON_INCLUDE% -DPYTHON_EXECUTABLE=%PYTHON_BINARY% -DPYTHON_LIBRARY=%PYTHON_LIBRARY% + - set MSBuildLogger="C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" + - cmake --build . --config Release --target ALL_BUILD -- /v:m /logger:%MSBuildLogger% + +test_script: + - cmake --build . --config Release --target RUN_TESTS -- /v:m /logger:%MSBuildLogger% + +after_test: + - cd api\python + - python.exe .\setup.py sdist --formats=zip && exit 0 # Ignore warnings... + - ps: gci dist\*.zip | % { rename-item –path $_.Fullname –Newname ( "windows_" + $env:PLATFORM + "_" + $_.basename + "_py" + $env:PYTHON_VERSION + $_.extension) } + +#artifacts: +# - path: 'api\python\dist\*.zip' + + diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..5f81c69 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +* +!src +!doc +!tests +!include +!examples +!api +!CMakeLists.txt +!CMakeModules +!package diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..27e015a --- /dev/null +++ b/.travis.yml @@ -0,0 +1,156 @@ +language: cpp + + +matrix: + include: + # Linux gcc 5.0 - Python 2.7 + - os: linux + dist: trusty + compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: ['g++-5', 'ccache', 'libpython2.7'] + env: [ CXX_COMPILER=g++-5, C_COMPILER=gcc-5, PYTHON_VERSION=2.7, PYTHON_INCLUDE_DIR=/usr/include/python2.7, PYTHON_LIBRARY=/usr/lib/libpython2.7.so, PYTHON_BINARY=/usr/bin/python2.7 ] + + + ## Linux gcc 5.0 - Python 3.5 + - os: linux + dist: trusty + compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'deadsnakes'] + packages: ['g++-5', 'gcc-5', 'ccache', 'python3.5-dev'] + env: [ CXX_COMPILER=g++-5, C_COMPILER=gcc-5, PYTHON_VERSION=3.5, PYTHON_INCLUDE_DIR=/usr/include/python3.5m, PYTHON_LIBRARY=/usr/lib/libpython3.5m.so, PYTHON_BINARY=/usr/bin/python3.5] + + + # Linux gcc 6 - Python 3.6 + - os: linux + dist: trusty + compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test', 'deadsnakes'] + packages: ['g++-6', 'gcc-6', 'ccache', 'python3.6-dev', 'python-sphinx'] + env: [ CXX_COMPILER=g++-6, C_COMPILER=gcc-6, PYTHON_VERSION=3.6, PYTHON_INCLUDE_DIR=/usr/include/python3.6m, PYTHON_LIBRARY=/usr/lib/libpython3.6m.so, PYTHON_BINARY=/usr/bin/python3.6, LIEF_DOC=OFF] + + # OSX 10.11 - xcode 7.3 - Python 2.7 + - os: osx + osx_image: xcode7.3 + compiler: clang + env: [CXX_COMPILER=clang++, C_COMPILER=clang, PYTHON_VERSION=2.7] + + # OSX 10.12 - xcode 8.2 - Python 3.5 + - os: osx + osx_image: xcode8.2 + compiler: clang + env: [ CXX_COMPILER=clang++, C_COMPILER=clang, PYTHON_VERSION=3.5] + + + ## OSX 10.12 - xcode 8.2 - Python 3.6 + - os: osx + osx_image: xcode8.2 + compiler: clang + env: [CXX_COMPILER=clang++, C_COMPILER=clang, PYTHON_VERSION=3.6] + +#branches: +# only: +# - master + + +notifications: + email: false + +sudo: required + +cache: + - apt + - ccache + +before_install: + - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -q; fi + - if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install python-setuptools; fi + - export CC="$C_COMPILER" + - export CXX="$CXX_COMPILER" + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PREFIX="/usr/local"; fi + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi + + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export PYTHON_CONFIGURE_OPTS="--enable-shared"; fi + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv root; fi + - if [ "$TRAVIS_OS_NAME" == "osx" ]; then pyenv install --list ;fi + + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then pyenv install 2.7.10; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then pyenv install 3.5.0; fi + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then pyenv install 3.6.0b4; fi + + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/2.7.10/include/python2.7 ;fi + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/2.7.10/lib/libpython2.7.dylib ;fi + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/2.7.10/bin/python2.7 ;fi + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then $PYTHON_BINARY -m pip install --upgrade pip ;fi + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "2.7" ]]; then $PYTHON_BINARY -m pip install --upgrade setuptools ;fi + + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.5.0/include/python3.5m ;fi + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/3.5.0/lib/libpython3.dylib ;fi + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.5" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.5.0/bin/python3.5 ;fi + + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_INCLUDE_DIR=$(pyenv root)/versions/3.6.0b4/include/python3.6m ;fi + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_LIBRARY=$(pyenv root)/versions/3.6.0b4/lib/libpython3.dylib ;fi + - if [[ "$TRAVIS_OS_NAME" == "osx" && "$PYTHON_VERSION" == "3.6" ]]; then export PYTHON_BINARY=$(pyenv root)/versions/3.6.0b4/bin/python3.6 ;fi + +install: + - if [ "$GCOV" == "ON" ]; then sudo ln -sf /usr/bin/gcov-5 /usr/bin/gcov; fi + - if [ "$GCOV" == "ON" ]; then wget http://ftp.de.debian.org/debian/pool/main/l/lcov/lcov_1.13.orig.tar.gz; fi + - if [ "$GCOV" == "ON" ]; then tar xf lcov_1.13.orig.tar.gz; fi + - if [ "$GCOV" == "ON" ]; then sudo make -C lcov-1.13/ install; fi + + - if [[ "$LIEF_DOC" == "ON" ]]; then wget --no-check-certificate ftp://ftp.stack.nl/pub/users/dimitri/doxygen-1.8.10.linux.bin.tar.gz; fi + - if [[ "$LIEF_DOC" == "ON" ]]; then tar -xzf doxygen-1.8.10.linux.bin.tar.gz; fi + - if [[ "$LIEF_DOC" == "ON" ]]; then cd doxygen-1.8.10; fi + - if [[ "$LIEF_DOC" == "ON" ]]; then ./configure --prefix /usr; fi + - if [[ "$LIEF_DOC" == "ON" ]]; then sudo make install; fi + - if [[ "$LIEF_DOC" == "ON" ]]; then cd ..; fi + + # Setup CMake 3.1 for Linux + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget --no-check-certificate http://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz ;fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then tar -xzf cmake-3.7.2-Linux-x86_64.tar.gz ;fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then export PATH=$PWD/cmake-3.7.2-Linux-x86_64/bin:$PATH ;fi + + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then wget --no-check-certificate https://bootstrap.pypa.io/get-pip.py ;fi + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo $PYTHON_BINARY ./get-pip.py ;fi + - if [[ "$TRAVIS_OS_NAME" == "linux" && "$LIEF_DOC" == "ON" ]]; then sudo $PYTHON_BINARY -m pip install breathe ;fi + - if [[ "$TRAVIS_OS_NAME" == "linux" && "$LIEF_DOC" == "ON" ]]; then sudo $PYTHON_BINARY -m pip install sphinx_rtd_theme ;fi + + # Prepare build + - mkdir build + - cd build + + +script: + - cmake -DCMAKE_C_COMPILER=$C_COMPILER -DCMAKE_CXX_COMPILER=$CXX_COMPILER -DPYTHON_VERSION=$PYTHON_VERSION -DPYTHON_INCLUDE_DIR=$PYTHON_INCLUDE_DIR -DPYTHON_LIBRARY=$PYTHON_LIBRARY -DPYTHON_EXECUTABLE=$PYTHON_BINARY -DLIEF_TESTS=on -DLIEF_DOC=${LIEF_DOC:-OFF} .. + - make -j2 + - sudo make check-lief + +after_success: + - make package + - sudo $PYTHON_BINARY -m pip install setuptools + - sudo $PYTHON_BINARY -m pip install --upgrade setuptools + - cd api/python + - $PYTHON_BINARY setup.py sdist + - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then bash -c 'cd dist && for f in *.tar.gz; do mv $f "linux_${f%.tar.gz}_py${PYTHON_VERSION}.tar.gz"; done' ;fi + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then bash -c 'cd dist && for f in *.tar.gz; do mv $f "osx_${f%.tar.gz}_py$PYTHON_VERSION.tar.gz"; done' ;fi + + +deploy: + provider: releases + api-key: + - secure: "E+rseEB8MX81WvdM8HS/mOwGNS1kSMzaitOqVl0KA09Ir1I/gtyzli3p5M3rVRws7uYsEWqOAVEGrBeH3LhuX4D5aS5i5+IKKmlHLMhd+XT3Nmg+VsWgiHm4PVpdKLegN78CVcZs3NsbUYvEvEzmPGiNqHjUp0+EvuE1jsSXuXdDaYK3aLn2YRkQpFrMOZcHzItsbD/XXqQoupA99SdsNLVLi2UbCFh2qULi2Y/yOGGoK1PYJxuLd1H4Z992MFqcCbHFHGWRH6OTA/oPcDjluPSChj+YPJ4Logl+NpaLEH5FCbKFdpIi7b6ay5cyQ4m4BxGGmTn/qEPmp/3ouzAQY+yGKONpdMmAb8nKLcs2F+jCNLx/hCem+52yElFF4iTcCP6Xca/Ntj+D447GwZOWOlSGpBygPePVzXmj3PnI/KnRhRNHqLntkNe98Qz7QC9Sla+0e1TJJuegsTANJ0DM2iHtlCOxqRK8WskqeTkrxX4zYK3qTyouG8VxJg23qeRk5I1tNtiaZqsEfiqFVw25DWdLz6B3nDarCMS6hQhEzkQptXLNtPDWNmtvr/CFGjpZFJxACd1tgPGSARhPdhAfcRZUUyPPfptKHp5oxqTGrW8UKzOEhF+cwIg3BCMWsAGzrpuRTXKSfwMeqrVddXzgyhhyD3ywFkXwc1/wLIIEfAE=" + file_glob: true + file: + - ${TRAVIS_BUILD_DIR}/build/api/python/dist/*.tar.gz + - ${TRAVIS_BUILD_DIR}/build/*.tar.gz + skip_cleanup: true + on: + #branch: master + tags: true + diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..2f26194 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,3 @@ +Authors: + + Romain Thomas diff --git a/Acknowledgements b/Acknowledgements new file mode 100644 index 0000000..ffda7b2 --- /dev/null +++ b/Acknowledgements @@ -0,0 +1,16 @@ +Acknowledgements +---------------- + +LIEF makes use of the following open source projects: + + - mbedTLS - https://tls.mbed.org/ + - pybind11 - https://github.com/pybind/pybind11 + - json - https://nlohmann.github.io/json/ + - rang - https://agauniyal.github.io/rang/ + - easyloggingpp - https://github.com/muflihun/easyloggingpp + - Catch - https://github.com/philsquared/Catch + - yamlcpp - https://github.com/jbeder/yaml-cpp + - filesystem - https://github.com/wjakob/filesystem + - utf8-cpp - https://sourceforge.net/projects/utfcpp/ + +The logo is designed by Freepik diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..e150ff6 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,7 @@ +Changelog +========= + +v0.6: + * First public release + + diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..2036331 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,552 @@ +cmake_minimum_required(VERSION 3.1) + +# Modules +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/") +include(CheckCXXCompilerFlag) +include(CheckCCompilerFlag) +include(Findcppcheck) +include(CppcheckTargets) +include(ExternalProject) + +# LIEF version +set(LIEF_VERSION_MAJOR 0) +set(LIEF_VERSION_MINOR 6) +set(LIEF_VERSION_PATCH 0) + +project(LIEF VERSION ${LIEF_VERSION_MAJOR}.${LIEF_VERSION_MINOR}.${LIEF_VERSION_PATCH}) +message(STATUS "${PROJECT_NAME} ${PROJECT_VERSION}") + +# options +option(LIEF_TESTS "Enable tests" OFF) +option(LIEF_DOC "Enable documentation" OFF) +option(LIEF_PYTHON_API "Enable Python API" ON) +option(LIEF_INSTALL_PYTHON "Install Python bindings" OFF) +option(LIEF_C_API "C API" ON) +option(LIEF_EXAMPLES "Build LIEF C++ examples" ON) +option(LIEF_FORCE32 "Force build LIEF 32 bits version" OFF) +option(LIEF_COVERAGE "Perform code coverage" OFF) +option(LIEF_USE_CCACHE "Use ccache to speed up compilation" ON) +option(LIEF_EXTRA_WARNINGS "Enable extra warning from the compiler" OFF) +option(LIEF_LOGGING "Enable logging" ON) + +option(LIEF_ELF "Build LIEF with ELF module" ON) +option(LIEF_PE "Build LIEF with PE module" ON) +option(LIEF_MACHO "Build LIEF with MachO module" ON) + +# CCACHE +# ====== +find_program(CCACHE_FOUND ccache) +message(STATUS "ccache: ${LIEF_USE_CCACHE}") +if(CCACHE_FOUND AND LIEF_USE_CCACHE) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ccache) + set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK ccache) +endif() + + +# Dependencies +# ============ +find_package(Git REQUIRED) + +# Json +# ---- +set(LIBJSON_GIT_URL "https://github.com/nlohmann/json.git" CACHE STRING "URL to the JSON lib repo") +ExternalProject_Add(libjson + GIT_REPOSITORY ${LIBJSON_GIT_URL} + GIT_TAG v2.0.8 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "") + +ExternalProject_get_property(libjson SOURCE_DIR) +set(LIBJSON_SOURCE_DIR ${SOURCE_DIR}) + + +# Rang +# ---- +set(LIBRANG_GIT_URL "https://github.com/agauniyal/rang.git" CACHE STRING "URL to the Rang lib repo") +ExternalProject_Add(rang_cpp_color + GIT_REPOSITORY ${LIBRANG_GIT_URL} + GIT_TAG master + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "") + +ExternalProject_get_property(rang_cpp_color SOURCE_DIR) +set(LIBRANG_SOURCE_DIR ${SOURCE_DIR}) + + +# mbed TLS +# -------- +set(MBED_TLS_TAG mbedtls-2.4.0) +set(MBED_TLS_GIT_URL "https://github.com/ARMmbed/mbedtls.git" CACHE STRING "URL to MbedTLS") +set(MBED_TLS_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/mbed_tls) + + +ExternalProject_Add(mbed_tls + PREFIX ${MBED_TLS_PREFIX} + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "" + GIT_REPOSITORY ${MBED_TLS_GIT_URL} + GIT_TAG ${MBED_TLS_TAG} + UPDATE_COMMAND "" # repetitive update are a pain + BUILD_BYPRODUCTS ${MBED_TLS_PREFIX}) + +ExternalProject_get_property(mbed_tls SOURCE_DIR) +set(MBEDTLS_SOURCE_DIR ${SOURCE_DIR}) +set(MBEDTLS_INCLUDE_DIRS "${MBEDTLS_SOURCE_DIR}/include") + +set(mbedtls_src_crypto + ${MBEDTLS_SOURCE_DIR}/library/aes.c + ${MBEDTLS_SOURCE_DIR}/library/aesni.c + ${MBEDTLS_SOURCE_DIR}/library/arc4.c + ${MBEDTLS_SOURCE_DIR}/library/asn1parse.c + ${MBEDTLS_SOURCE_DIR}/library/asn1write.c + ${MBEDTLS_SOURCE_DIR}/library/base64.c + ${MBEDTLS_SOURCE_DIR}/library/bignum.c + ${MBEDTLS_SOURCE_DIR}/library/blowfish.c + ${MBEDTLS_SOURCE_DIR}/library/camellia.c + ${MBEDTLS_SOURCE_DIR}/library/ccm.c + ${MBEDTLS_SOURCE_DIR}/library/cipher.c + ${MBEDTLS_SOURCE_DIR}/library/cipher_wrap.c + ${MBEDTLS_SOURCE_DIR}/library/cmac.c + ${MBEDTLS_SOURCE_DIR}/library/ctr_drbg.c + ${MBEDTLS_SOURCE_DIR}/library/des.c + ${MBEDTLS_SOURCE_DIR}/library/dhm.c + ${MBEDTLS_SOURCE_DIR}/library/ecdh.c + ${MBEDTLS_SOURCE_DIR}/library/ecdsa.c + ${MBEDTLS_SOURCE_DIR}/library/ecjpake.c + ${MBEDTLS_SOURCE_DIR}/library/ecp.c + ${MBEDTLS_SOURCE_DIR}/library/ecp_curves.c + ${MBEDTLS_SOURCE_DIR}/library/entropy.c + ${MBEDTLS_SOURCE_DIR}/library/entropy_poll.c + ${MBEDTLS_SOURCE_DIR}/library/error.c + ${MBEDTLS_SOURCE_DIR}/library/gcm.c + ${MBEDTLS_SOURCE_DIR}/library/havege.c + ${MBEDTLS_SOURCE_DIR}/library/hmac_drbg.c + ${MBEDTLS_SOURCE_DIR}/library/md.c + ${MBEDTLS_SOURCE_DIR}/library/md2.c + ${MBEDTLS_SOURCE_DIR}/library/md4.c + ${MBEDTLS_SOURCE_DIR}/library/md5.c + ${MBEDTLS_SOURCE_DIR}/library/md_wrap.c + ${MBEDTLS_SOURCE_DIR}/library/memory_buffer_alloc.c + ${MBEDTLS_SOURCE_DIR}/library/oid.c + ${MBEDTLS_SOURCE_DIR}/library/padlock.c + ${MBEDTLS_SOURCE_DIR}/library/pem.c + ${MBEDTLS_SOURCE_DIR}/library/pk.c + ${MBEDTLS_SOURCE_DIR}/library/pk_wrap.c + ${MBEDTLS_SOURCE_DIR}/library/pkcs12.c + ${MBEDTLS_SOURCE_DIR}/library/pkcs5.c + ${MBEDTLS_SOURCE_DIR}/library/pkparse.c + ${MBEDTLS_SOURCE_DIR}/library/pkwrite.c + ${MBEDTLS_SOURCE_DIR}/library/platform.c + ${MBEDTLS_SOURCE_DIR}/library/ripemd160.c + ${MBEDTLS_SOURCE_DIR}/library/rsa.c + ${MBEDTLS_SOURCE_DIR}/library/sha1.c + ${MBEDTLS_SOURCE_DIR}/library/sha256.c + ${MBEDTLS_SOURCE_DIR}/library/sha512.c + ${MBEDTLS_SOURCE_DIR}/library/threading.c + ${MBEDTLS_SOURCE_DIR}/library/timing.c + ${MBEDTLS_SOURCE_DIR}/library/version.c + ${MBEDTLS_SOURCE_DIR}/library/version_features.c + ${MBEDTLS_SOURCE_DIR}/library/xtea.c +) + +set(mbedtls_src_x509 + ${MBEDTLS_SOURCE_DIR}/library/certs.c + ${MBEDTLS_SOURCE_DIR}/library/pkcs11.c + ${MBEDTLS_SOURCE_DIR}/library/x509.c + ${MBEDTLS_SOURCE_DIR}/library/x509_create.c + ${MBEDTLS_SOURCE_DIR}/library/x509_crl.c + ${MBEDTLS_SOURCE_DIR}/library/x509_crt.c + ${MBEDTLS_SOURCE_DIR}/library/x509_csr.c + ${MBEDTLS_SOURCE_DIR}/library/x509write_crt.c + ${MBEDTLS_SOURCE_DIR}/library/x509write_csr.c +) + +set(mbedtls_src_tls + ${MBEDTLS_SOURCE_DIR}/library/debug.c + ${MBEDTLS_SOURCE_DIR}/library/net_sockets.c + ${MBEDTLS_SOURCE_DIR}/library/ssl_cache.c + ${MBEDTLS_SOURCE_DIR}/library/ssl_ciphersuites.c + ${MBEDTLS_SOURCE_DIR}/library/ssl_cli.c + ${MBEDTLS_SOURCE_DIR}/library/ssl_cookie.c + ${MBEDTLS_SOURCE_DIR}/library/ssl_srv.c + ${MBEDTLS_SOURCE_DIR}/library/ssl_ticket.c + ${MBEDTLS_SOURCE_DIR}/library/ssl_tls.c +) + + +# easyloggingpp +# ------------- +set(ELG_GIT_URL "https://github.com/easylogging/easyloggingpp.git" CACHE STRING "URL to the easyloggingpp lib repo") +ExternalProject_Add(easyloggingpp + GIT_REPOSITORY ${ELG_GIT_URL} + #GIT_TAG "v9.83" + GIT_TAG "master" + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "") + +ExternalProject_get_property(easyloggingpp SOURCE_DIR) +set(ELG_SOURCE_DIR ${SOURCE_DIR}/src) + + + +# LIEF Source definition +# ====================== +set_source_files_properties(${mbedtls_src_crypto} PROPERTIES GENERATED TRUE) +set_source_files_properties(${mbedtls_src_x509} PROPERTIES GENERATED TRUE) +set_source_files_properties(${mbedtls_src_tls} PROPERTIES GENERATED TRUE) +set_source_files_properties(${ELG_SOURCE_DIR}/easylogging++.cc PROPERTIES GENERATED TRUE) + +set(LIEF_SRC + ${ELG_SOURCE_DIR}/easylogging++.cc + ${mbedtls_src_crypto} + ${mbedtls_src_x509} + ${mbedtls_src_tls} + ${CMAKE_CURRENT_SOURCE_DIR}/src/logging.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/exception.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/iostream.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/utils.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Visitable.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Visitor.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/BinaryStream/BinaryStream.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/BinaryStream/VectorStream.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/visitors/elf_json.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/visitors/json.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/visitors/hash.cpp) + +set(LIEF_ABSTRACT_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Binary.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Symbol.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/EnumToString.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Header.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Section.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/Abstract/Parser.cpp) + + + +set(LIBLIEF_SOURCE_FILES + ${LIEF_SRC} + ${LIEF_ABSTRACT_SRC}) + +add_library(LIB_LIEF_STATIC STATIC ${LIBLIEF_SOURCE_FILES}) # Static one +add_library(LIB_LIEF_SHARED SHARED ${LIBLIEF_SOURCE_FILES}) # Shared one + + +if (LIEF_ELF) + include(${CMAKE_CURRENT_SOURCE_DIR}/src/ELF/CMakeLists.txt) +endif() + +if (LIEF_PE) + include(${CMAKE_CURRENT_SOURCE_DIR}/src/PE/CMakeLists.txt) +endif() + +if (LIEF_MACHO) + include(${CMAKE_CURRENT_SOURCE_DIR}/src/MachO/CMakeLists.txt) +endif() + + +# LIEF includes +# ============= + +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF/version.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/version.h +) + +set (LIEF_PUBLIC_INCLUDE_DIR + ${CMAKE_CURRENT_SOURCE_DIR}/include/ + ${CMAKE_CURRENT_BINARY_DIR}/include/ + ${LIBJSON_SOURCE_DIR}/src/) + +set(LIEF_PRIVATE_INCLUDE_DIR + ${LIEF_PUBLIC_INCLUDE_DIR} + ${LIBRANG_SOURCE_DIR}/include + ${ELG_SOURCE_DIR}/ + ${MBEDTLS_INCLUDE_DIRS}) + +# Library definition +# ================== +add_definitions(-DELPP_NO_DEFAULT_LOG_FILE) +if (LIEF_ELF) + add_definitions(-DLIEF_ELF_MODULE) +endif() + +if (LIEF_PE) + add_definitions(-DLIEF_PE_MODULE) +endif() + +if (LIEF_MACHO) + add_definitions(-DLIEF_MACHO_MODULE) +endif() + +target_include_directories(LIB_LIEF_STATIC + PUBLIC ${LIEF_PUBLIC_INCLUDE_DIR} + PRIVATE ${LIEF_PRIVATE_INCLUDE_DIR}) + +target_include_directories(LIB_LIEF_SHARED + PUBLIC ${LIEF_PUBLIC_INCLUDE_DIR} + PRIVATE ${LIEF_PRIVATE_INCLUDE_DIR}) + + +add_dependencies(LIB_LIEF_STATIC libjson) +add_dependencies(LIB_LIEF_SHARED libjson) + +add_dependencies(LIB_LIEF_STATIC easyloggingpp) +add_dependencies(LIB_LIEF_SHARED easyloggingpp) + +add_dependencies(LIB_LIEF_STATIC rang_cpp_color) +add_dependencies(LIB_LIEF_SHARED rang_cpp_color) + +add_dependencies(LIB_LIEF_STATIC mbed_tls) +add_dependencies(LIB_LIEF_SHARED mbed_tls) + +# Flags definition +# ---------------- +set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY CXX_STANDARD 11) +set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY CXX_STANDARD_REQUIRED ON) +set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY POSITION_INDEPENDENT_CODE ON) +#set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY CXX_VISIBILITY_PRESET hidden) + + +CHECK_CXX_COMPILER_FLAG("-Weverything" HAS_WARN_EVERY) + +if (LIEF_EXTRA_WARNINGS AND HAS_WARN_EVERY) + set(EXTRA_FLAGS + -Weverything + -Wno-c++98-compat + -Wno-c++98-compat-pedantic + -Wno-padded + -Wno-unused-exception-parameter + -Wno-weak-vtables + -Wno-exit-time-destructors + -Wno-global-constructors + -Wno-documentation + -Wno-documentation-unknown-command + -Wno-sign-conversion) + + target_compile_options(LIB_LIEF_STATIC PRIVATE ${EXTRA_FLAGS}) + target_compile_options(LIB_LIEF_SHARED PRIVATE ${EXTRA_FLAGS}) +endif() + +if (MSVC) + add_definitions(-DNOMINMAX) + target_compile_options(LIB_LIEF_STATIC PUBLIC /FIiso646.h) + target_compile_options(LIB_LIEF_SHARED PUBLIC /FIiso646.h) + + target_compile_options(LIB_LIEF_STATIC PUBLIC /MT) + +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + if (UNIX) + if (LIEF_FORCE32) + target_compile_options(LIB_LIEF_STATIC PRIVATE -m32) + target_compile_options(LIB_LIEF_SHARED PRIVATE -m32) + + set_property(TARGET LIB_LIEF_STATIC LIB_LIEF_SHARED PROPERTY LINK_FLAGS -m32) + endif() + + set(LIB_LIEF_COMPILE_FLAGS + -Wall -Wextra -Wpedantic + -Wno-expansion-to-defined + -fno-stack-protector + -fomit-frame-pointer -fno-strict-aliasing + -fexceptions + -fvisibility=hidden) + target_compile_options(LIB_LIEF_STATIC PRIVATE ${LIB_LIEF_COMPILE_FLAGS}) + target_compile_options(LIB_LIEF_SHARED PRIVATE ${LIB_LIEF_COMPILE_FLAGS}) + endif() +endif() + + +if(CROSS_COMPILE_WINDOWS) + target_link_libraries(LIB_LIEF_STATIC -static -static-libgcc -static-libstdc++) +endif() + +if(LIEF_COVERAGE) + target_compile_options(LIB_LIEF_STATIC PRIVATE -g -O0 --coverage -fprofile-arcs -ftest-coverage) + target_compile_options(LIB_LIEF_SHARED PRIVATE -g -O0 --coverage -fprofile-arcs -ftest-coverage) + target_link_libraries(LIB_LIEF_STATIC gcov) + target_link_libraries(LIB_LIEF_SHARED gcov) +endif() + +find_package(cppcheck) + +set_target_properties( + LIB_LIEF_STATIC + PROPERTIES OUTPUT_NAME LIEF + CLEAN_DIRECT_OUTPUT 1) + +set_target_properties( + LIB_LIEF_SHARED + PROPERTIES OUTPUT_NAME LIEF + CLEAN_DIRECT_OUTPUT 1) + + + +# Set a default build type if none was specified +if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) + message(STATUS "Setting build type to 'Release' as none was specified.") + set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build." FORCE) + # Set the possible values of build type for cmake-gui + set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" + "MinSizeRel" "RelWithDebInfo") +endif() + +message(STATUS "Configuration Types: ${CMAKE_CONFIGURATION_TYPES}") +message(STATUS "Build Types: ${CMAKE_BUILD_TYPE}") + + +if(APPLE) + set_target_properties(LIB_LIEF_STATIC PROPERTIES MACOSX_RPATH ".") + set_target_properties(LIB_LIEF_SHARED PROPERTIES MACOSX_RPATH ".") +endif() + + +# API +# === + +# Python +# ------ + +if (LIEF_PYTHON_API) + if(WIN32) + set(PYTHON_BUILD_LIEF_DIRECTORY "${CMAKE_BINARY_DIR}/api/python/Release") + else() + set(PYTHON_BUILD_LIEF_DIRECTORY "${CMAKE_BINARY_DIR}/api/python") + endif() + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/api/python) +endif() + +# C API +# ----- +if(LIEF_C_API) + + # ELF + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/ELF/enums.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/ELF/enums.h + @ONLY + ) + + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/ELF/structures.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/ELF/structures.h + @ONLY + ) + + # PE + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/PE/enums.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/PE/enums.h + @ONLY + ) + + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/PE/structures.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/PE/structures.h + @ONLY + ) + + + # MachO + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/MachO/enums.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/MachO/enums.h + @ONLY + ) + + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include/LIEF/MachO/structures.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/LIEF/MachO/structures.h + @ONLY + ) + + target_include_directories(LIB_LIEF_STATIC + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include) + + target_include_directories(LIB_LIEF_SHARED + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include + PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/api/c/include) + + include(${CMAKE_CURRENT_SOURCE_DIR}/api/c/CMakeLists.txt) +endif() + + + +# Examples +# ======== +if(LIEF_EXAMPLES) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/cpp) + + if (LIEF_C_API) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/examples/c) + endif() +endif() + +# Tests +# ===== +if(LIEF_TESTS) + enable_testing() + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/tests) + add_custom_target(check-lief COMMAND ${CMAKE_CTEST_COMMAND} --output-on-failure) +endif() + +# CPP Check +# ========= +set(CPPCHECK_TEMPLATE_ARG "[{severity}][{id}] {message} {callstack} \(On {file}:{line}\)") +set(_cppcheck_args "--enable=warning,performance,portability,information") +#add_cppcheck(LIB_LIEF_STATIC FORCE) + + +# Documentation +# ============= +if (LIEF_DOC) + add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/doc) +endif() + + +# Install Prefix +# ============== +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT AND UNIX) + if (UNIX AND NOT APPLE) + set(CMAKE_INSTALL_PREFIX "/usr" CACHE PATH "Install path prefix prepended on to install directories." FORCE) + elseif (APPLE) + set(CMAKE_INSTALL_PREFIX "/usr/local" CACHE PATH "" FORCE) + endif() +endif() + +# Installation +# ============ + +install(TARGETS LIB_LIEF_STATIC + ARCHIVE + DESTINATION lib + LIBRARY + DESTINATION lib + COMPONENT libraries) + +install(TARGETS LIB_LIEF_SHARED + ARCHIVE + DESTINATION lib + LIBRARY + DESTINATION lib + COMPONENT libraries) + +install( + DIRECTORY ${LIEF_PUBLIC_INCLUDE_DIR} + DESTINATION include + COMPONENT headers + FILES_MATCHING REGEX "(.*).(hpp|h|def)$") + +# Package +add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/package) + + + + + diff --git a/CMakeModules/CodeCoverage.cmake b/CMakeModules/CodeCoverage.cmake new file mode 100644 index 0000000..d5d4940 --- /dev/null +++ b/CMakeModules/CodeCoverage.cmake @@ -0,0 +1,197 @@ +# Copyright (c) 2012 - 2015, Lars Bilke +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without modification, +# are permitted provided that the following conditions are met: +# +# 1. Redistributions of source code must retain the above copyright notice, this +# list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright notice, +# this list of conditions and the following disclaimer in the documentation +# and/or other materials provided with the distribution. +# +# 3. Neither the name of the copyright holder nor the names of its contributors +# may be used to endorse or promote products derived from this software without +# specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# +# +# +# 2012-01-31, Lars Bilke +# - Enable Code Coverage +# +# 2013-09-17, Joakim Söderberg +# - Added support for Clang. +# - Some additional usage instructions. +# +# USAGE: + +# 0. (Mac only) If you use Xcode 5.1 make sure to patch geninfo as described here: +# http://stackoverflow.com/a/22404544/80480 +# +# 1. Copy this file into your cmake modules path. +# +# 2. Add the following line to your CMakeLists.txt: +# INCLUDE(CodeCoverage) +# +# 3. Set compiler flags to turn off optimization and enable coverage: +# SET(CMAKE_CXX_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") +# SET(CMAKE_C_FLAGS "-g -O0 -fprofile-arcs -ftest-coverage") +# +# 3. Use the function SETUP_TARGET_FOR_COVERAGE to create a custom make target +# which runs your test executable and produces a lcov code coverage report: +# Example: +# SETUP_TARGET_FOR_COVERAGE( +# my_coverage_target # Name for custom target. +# test_driver # Name of the test driver executable that runs the tests. +# # NOTE! This should always have a ZERO as exit code +# # otherwise the coverage generation will not complete. +# coverage # Name of output directory. +# ) +# +# 4. Build a Debug build: +# cmake -DCMAKE_BUILD_TYPE=Debug .. +# make +# make my_coverage_target +# +# + +# Check prereqs +FIND_PROGRAM( GCOV_PATH gcov ) +FIND_PROGRAM( LCOV_PATH lcov ) +FIND_PROGRAM( GENHTML_PATH genhtml ) +FIND_PROGRAM( GCOVR_PATH gcovr PATHS ${CMAKE_SOURCE_DIR}/tests) + +IF(NOT GCOV_PATH) + MESSAGE(FATAL_ERROR "gcov not found! Aborting...") +ENDIF() # NOT GCOV_PATH + +IF("${CMAKE_CXX_COMPILER_ID}" MATCHES "(Apple)?[Cc]lang") + IF("${CMAKE_CXX_COMPILER_VERSION}" VERSION_LESS 3) + MESSAGE(FATAL_ERROR "Clang version must be 3.0.0 or greater! Aborting...") + ENDIF() +ELSEIF(NOT CMAKE_COMPILER_IS_GNUCXX) + MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...") +ENDIF() # CHECK VALID COMPILER + +SET(CMAKE_CXX_FLAGS_COVERAGE + "-g -O0 --coverage -fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the C++ compiler during coverage builds." + FORCE ) +SET(CMAKE_C_FLAGS_COVERAGE + "-g -O0 --coverage -fprofile-arcs -ftest-coverage" + CACHE STRING "Flags used by the C compiler during coverage builds." + FORCE ) +SET(CMAKE_EXE_LINKER_FLAGS_COVERAGE + "" + CACHE STRING "Flags used for linking binaries during coverage builds." + FORCE ) +SET(CMAKE_SHARED_LINKER_FLAGS_COVERAGE + "" + CACHE STRING "Flags used by the shared libraries linker during coverage builds." + FORCE ) +MARK_AS_ADVANCED( + CMAKE_CXX_FLAGS_COVERAGE + CMAKE_C_FLAGS_COVERAGE + CMAKE_EXE_LINKER_FLAGS_COVERAGE + CMAKE_SHARED_LINKER_FLAGS_COVERAGE ) + +IF ( NOT (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "Coverage")) + MESSAGE( WARNING "Code coverage results with an optimized (non-Debug) build may be misleading" ) +ENDIF() # NOT CMAKE_BUILD_TYPE STREQUAL "Debug" + + +# Param _targetname The name of new the custom make target +# Param _testrunner The name of the target which runs the tests. +# MUST return ZERO always, even on errors. +# If not, no coverage report will be created! +# Param _outputname lcov output is generated as _outputname.info +# HTML report is generated in _outputname/index.html +# Optional fourth parameter is passed as arguments to _testrunner +# Pass them in list form, e.g.: "-j;2" for -j 2 +FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname) + + IF(NOT LCOV_PATH) + MESSAGE(FATAL_ERROR "lcov not found! Aborting...") + ENDIF() # NOT LCOV_PATH + + IF(NOT GENHTML_PATH) + MESSAGE(FATAL_ERROR "genhtml not found! Aborting...") + ENDIF() # NOT GENHTML_PATH + + SET(coverage_info "${CMAKE_BINARY_DIR}/${_outputname}.info") + SET(coverage_cleaned "${coverage_info}.cleaned") + + SEPARATE_ARGUMENTS(test_command UNIX_COMMAND "${_testrunner}") + + # Setup target + ADD_CUSTOM_TARGET(${_targetname} + + # Cleanup lcov + ${LCOV_PATH} --directory . --zerocounters + + # Run tests + COMMAND ${test_command} ${ARGV3} + + # Capturing lcov counters and generating report + COMMAND ${LCOV_PATH} --directory . --capture --output-file ${coverage_info} + COMMAND ${LCOV_PATH} --remove ${coverage_info} 'tests/*' '/usr/*' --output-file ${coverage_cleaned} + COMMAND ${GENHTML_PATH} -o ${_outputname} ${coverage_cleaned} + COMMAND ${CMAKE_COMMAND} -E remove ${coverage_info} ${coverage_cleaned} + + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report." + ) + + # Show info where to find the report + ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD + COMMAND ; + COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report." + ) + +ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE + +# Param _targetname The name of new the custom make target +# Param _testrunner The name of the target which runs the tests +# Param _outputname cobertura output is generated as _outputname.xml +# Optional fourth parameter is passed as arguments to _testrunner +# Pass them in list form, e.g.: "-j;2" for -j 2 +FUNCTION(SETUP_TARGET_FOR_COVERAGE_COBERTURA _targetname _testrunner _outputname) + + IF(NOT PYTHON_EXECUTABLE) + MESSAGE(FATAL_ERROR "Python not found! Aborting...") + ENDIF() # NOT PYTHON_EXECUTABLE + + IF(NOT GCOVR_PATH) + MESSAGE(FATAL_ERROR "gcovr not found! Aborting...") + ENDIF() # NOT GCOVR_PATH + + ADD_CUSTOM_TARGET(${_targetname} + + # Run tests + ${_testrunner} ${ARGV3} + + # Running gcovr + COMMAND ${GCOVR_PATH} -x -r ${CMAKE_SOURCE_DIR} -e '${CMAKE_SOURCE_DIR}/tests/' -o ${_outputname}.xml + WORKING_DIRECTORY ${CMAKE_BINARY_DIR} + COMMENT "Running gcovr to produce Cobertura code coverage report." + ) + + # Show info where to find the report + ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD + COMMAND ; + COMMENT "Cobertura code coverage report saved in ${_outputname}.xml." + ) + +ENDFUNCTION() # SETUP_TARGET_FOR_COVERAGE_COBERTURA diff --git a/CMakeModules/CppcheckTargets.cmake b/CMakeModules/CppcheckTargets.cmake new file mode 100644 index 0000000..29bc898 --- /dev/null +++ b/CMakeModules/CppcheckTargets.cmake @@ -0,0 +1,231 @@ +# - Run cppcheck on c++ source files as a custom target and a test +# +# include(CppcheckTargets) +# add_cppcheck( [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR] [FORCE] [FAIL_ON_WARNINGS]) - +# Create a target to check a target's sources with cppcheck and the indicated options +# add_cppcheck_sources( [UNUSED_FUNCTIONS] [STYLE] [POSSIBLE_ERROR] [FORCE] [FAIL_ON_WARNINGS]) - +# Create a target to check standalone sources with cppcheck and the indicated options +# +# Requires these CMake modules: +# Findcppcheck +# +# Requires CMake 2.6 or newer (uses the 'function' command) +# +# Original Author: +# 2009-2010 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2009-2010. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +if(__add_cppcheck) + return() +endif() +set(__add_cppcheck YES) + +if(NOT CPPCHECK_FOUND) + find_package(cppcheck QUIET) +endif() + +if(CPPCHECK_FOUND) + if(NOT TARGET all_cppcheck) + add_custom_target(all_cppcheck) + set_target_properties(all_cppcheck PROPERTIES EXCLUDE_FROM_ALL TRUE) + endif() +endif() + +function(add_cppcheck_sources _targetname) + if(CPPCHECK_FOUND) + set(_cppcheck_args) + set(_input ${ARGN}) + list(FIND _input UNUSED_FUNCTIONS _unused_func) + if("${_unused_func}" GREATER "-1") + list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG}) + list(REMOVE_AT _input ${_unused_func}) + endif() + + list(FIND _input STYLE _style) + if("${_style}" GREATER "-1") + list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG}) + list(REMOVE_AT _input ${_style}) + endif() + + list(FIND _input POSSIBLE_ERROR _poss_err) + if("${_poss_err}" GREATER "-1") + list(APPEND _cppcheck_args ${CPPCHECK_POSSIBLEERROR_ARG}) + list(REMOVE_AT _input ${_poss_err}) + endif() + + list(FIND _input FORCE _force) + if("${_force}" GREATER "-1") + list(APPEND _cppcheck_args "--force") + list(REMOVE_AT _input ${_force}) + endif() + + list(FIND _input FAIL_ON_WARNINGS _fail_on_warn) + if("${_fail_on_warn}" GREATER "-1") + list(APPEND + CPPCHECK_FAIL_REGULAR_EXPRESSION + ${CPPCHECK_WARN_REGULAR_EXPRESSION}) + list(REMOVE_AT _input ${_fail_on_warn}) + endif() + + set(_files) + foreach(_source ${_input}) + get_source_file_property(_cppcheck_loc "${_source}" LOCATION) + if(_cppcheck_loc) + # This file has a source file property, carry on. + get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE) + if("${_cppcheck_lang}" MATCHES "CXX") + list(APPEND _files "${_cppcheck_loc}") + endif() + else() + # This file doesn't have source file properties - figure it out. + get_filename_component(_cppcheck_loc "${_source}" ABSOLUTE) + if(EXISTS "${_cppcheck_loc}") + list(APPEND _files "${_cppcheck_loc}") + else() + message(FATAL_ERROR + "Adding CPPCHECK for file target ${_targetname}: " + "File ${_source} does not exist or needs a corrected path location " + "since we think its absolute path is ${_cppcheck_loc}") + endif() + endif() + endforeach() + + if("1.${CMAKE_VERSION}" VERSION_LESS "1.2.8.0") + # Older than CMake 2.8.0 + add_test(${_targetname}_cppcheck_test + "${CPPCHECK_EXECUTABLE}" + ${CPPCHECK_TEMPLATE_ARG} + ${_cppcheck_args} "--inline-suppr" + ${_files}) + else() + # CMake 2.8.0 and newer + add_test(NAME + ${_targetname}_cppcheck_test + COMMAND + "${CPPCHECK_EXECUTABLE}" + ${CPPCHECK_TEMPLATE_ARG} + ${_cppcheck_args} "--inline-suppr" + ${_files}) + endif() + + set_tests_properties(${_targetname}_cppcheck_test + PROPERTIES + FAIL_REGULAR_EXPRESSION + "${CPPCHECK_FAIL_REGULAR_EXPRESSION}") + + add_custom_command(TARGET + all_cppcheck + PRE_BUILD + COMMAND + ${CPPCHECK_EXECUTABLE} + ${CPPCHECK_QUIET_ARG} + ${CPPCHECK_TEMPLATE_ARG} + ${_cppcheck_args} "--inline-suppr" + ${_files} + WORKING_DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}" + COMMENT + "${_targetname}_cppcheck: Running cppcheck on target ${_targetname}..." + VERBATIM) + endif() +endfunction() + +function(add_cppcheck _name) + if(NOT TARGET ${_name}) + message(FATAL_ERROR + "add_cppcheck given a target name that does not exist: '${_name}' !") + endif() + if(CPPCHECK_FOUND) + set(_cppcheck_args CACHE STRING "${_cppcheck_args} ") + #set(_cppcheck_args "${_cppcheck_args} ") + list(FIND ARGN UNUSED_FUNCTIONS _unused_func) + if("${_unused_func}" GREATER "-1") + list(APPEND _cppcheck_args ${CPPCHECK_UNUSEDFUNC_ARG}) + endif() + + list(FIND ARGN STYLE _style) + if("${_style}" GREATER "-1") + list(APPEND _cppcheck_args ${CPPCHECK_STYLE_ARG}) + endif() + + list(FIND ARGN POSSIBLE_ERROR _poss_err) + if("${_poss_err}" GREATER "-1") + list(APPEND _cppcheck_args ${CPPCHECK_POSSIBLEERROR_ARG}) + endif() + + list(FIND ARGN FORCE _force) + if("${_force}" GREATER "-1") + list(APPEND _cppcheck_args "--force") + endif() + + list(FIND _input FAIL_ON_WARNINGS _fail_on_warn) + if("${_fail_on_warn}" GREATER "-1") + list(APPEND + CPPCHECK_FAIL_REGULAR_EXPRESSION + ${CPPCHECK_WARN_REGULAR_EXPRESSION}) + list(REMOVE_AT _input ${_unused_func}) + endif() + + get_target_property(_cppcheck_includes "${_name}" INCLUDE_DIRECTORIES) + set(_includes) + foreach(_include ${_cppcheck_includes}) + list(APPEND _includes "-I${_include}") + endforeach() + + get_target_property(_cppcheck_sources "${_name}" SOURCES) + set(_files) + foreach(_source ${_cppcheck_sources}) + get_source_file_property(_cppcheck_lang "${_source}" LANGUAGE) + get_source_file_property(_cppcheck_loc "${_source}" LOCATION) + if("${_cppcheck_lang}" MATCHES "CXX") + list(APPEND _files "${_cppcheck_loc}") + endif() + endforeach() + + if("1.${CMAKE_VERSION}" VERSION_LESS "1.2.8.0") + # Older than CMake 2.8.0 + add_test(${_name}_cppcheck_test + "${CPPCHECK_EXECUTABLE}" + ${CPPCHECK_TEMPLATE_ARG} + ${_cppcheck_args} "--inline-suppr" + ${_files}) + else() + # CMake 2.8.0 and newer + add_test(NAME + ${_name}_cppcheck_test + COMMAND + "${CPPCHECK_EXECUTABLE}" + ${CPPCHECK_TEMPLATE_ARG} + ${_cppcheck_args} "--inline-suppr" + ${_files}) + endif() + + set_tests_properties(${_name}_cppcheck_test + PROPERTIES + FAIL_REGULAR_EXPRESSION + "${CPPCHECK_FAIL_REGULAR_EXPRESSION}") + MESSAGE(STATUS "CPPCHECKargs: ${_cppcheck_args}") + add_custom_command(TARGET + all_cppcheck + PRE_BUILD + COMMAND + ${CPPCHECK_EXECUTABLE} + ${CPPCHECK_QUIET_ARG} + ${CPPCHECK_TEMPLATE_ARG} + ${_cppcheck_args} "--inline-suppr" + ${_includes} + ${_files} + WORKING_DIRECTORY + "${CMAKE_CURRENT_SOURCE_DIR}" + COMMENT + "${_name}_cppcheck: Running cppcheck on target ${_name}..." + VERBATIM) + endif() + +endfunction() diff --git a/CMakeModules/FindYamlCpp.cmake b/CMakeModules/FindYamlCpp.cmake new file mode 100644 index 0000000..c099afa --- /dev/null +++ b/CMakeModules/FindYamlCpp.cmake @@ -0,0 +1,98 @@ +# Locate yaml-cpp +# +# This module defines +# YAMLCPP_FOUND, if false, do not try to link to yaml-cpp +# YAMLCPP_LIBNAME, name of yaml library +# YAMLCPP_LIBRARY, where to find yaml-cpp +# YAMLCPP_LIBRARY_RELEASE, where to find Release or RelWithDebInfo yaml-cpp +# YAMLCPP_LIBRARY_DEBUG, where to find Debug yaml-cpp +# YAMLCPP_INCLUDE_DIR, where to find yaml.h +# YAMLCPP_LIBRARY_DIR, the directories to find YAMLCPP_LIBRARY +# +# By default, the dynamic libraries of yaml-cpp will be found. To find the static ones instead, +# you must set the YAMLCPP_USE_STATIC_LIBS variable to TRUE before calling find_package(YamlCpp ...) + +# attempt to find static library first if this is set +if(YAMLCPP_USE_STATIC_LIBS) + set(YAMLCPP_STATIC libyaml-cpp.a) + set(YAMLCPP_STATIC_DEBUG libyaml-cpp-dbg.a) +endif() + +if(${CMAKE_SYSTEM_NAME} MATCHES "Windows") ### Set Yaml libary name for Windows + set(YAMLCPP_LIBNAME "libyaml-cppmd" CACHE STRING "Name of YAML library") + set(YAMLCPP_LIBNAME optimized ${YAMLCPP_LIBNAME} debug ${YAMLCPP_LIBNAME}d) +else() ### Set Yaml libary name for Unix, Linux, OS X, etc + set(YAMLCPP_LIBNAME "yaml-cpp" CACHE STRING "Name of YAML library") +endif() + +# find the yaml-cpp include directory +find_path(YAMLCPP_INCLUDE_DIR + NAMES yaml-cpp/yaml.h + PATH_SUFFIXES include + PATHS + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/include + ~/Library/Frameworks/yaml-cpp/include/ + /Library/Frameworks/yaml-cpp/include/ + /usr/local/include/ + /usr/include/ + /sw/yaml-cpp/ # Fink + /opt/local/yaml-cpp/ # DarwinPorts + /opt/csw/yaml-cpp/ # Blastwave + /opt/yaml-cpp/) + +# find the release yaml-cpp library +find_library(YAMLCPP_LIBRARY_RELEASE + NAMES ${YAMLCPP_STATIC} yaml-cpp libyaml-cppmd.lib + PATH_SUFFIXES lib64 lib Release RelWithDebInfo + PATHS + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/ + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/build + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt) + +# find the debug yaml-cpp library +find_library(YAMLCPP_LIBRARY_DEBUG + NAMES ${YAMLCPP_STATIC_DEBUG} yaml-cpp-dbg libyaml-cppmdd.lib + PATH_SUFFIXES lib64 lib Debug + PATHS + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/ + ${PROJECT_SOURCE_DIR}/dependencies/yaml-cpp-0.5.1/build + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /sw + /opt/local + /opt/csw + /opt) + +# set library vars +set(YAMLCPP_LIBRARY ${YAMLCPP_LIBRARY_RELEASE}) +if(CMAKE_BUILD_TYPE MATCHES Debug AND EXISTS ${YAMLCPP_LIBRARY_DEBUG}) + set(YAMLCPP_LIBRARY ${YAMLCPP_LIBRARY_DEBUG}) +endif() + +get_filename_component(YAMLCPP_LIBRARY_RELEASE_DIR ${YAMLCPP_LIBRARY_RELEASE} PATH) +get_filename_component(YAMLCPP_LIBRARY_DEBUG_DIR ${YAMLCPP_LIBRARY_DEBUG} PATH) +set(YAMLCPP_LIBRARY_DIR ${YAMLCPP_LIBRARY_RELEASE_DIR} ${YAMLCPP_LIBRARY_DEBUG_DIR}) + +# handle the QUIETLY and REQUIRED arguments and set YAMLCPP_FOUND to TRUE if all listed variables are TRUE +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(YamlCpp DEFAULT_MSG + YAMLCPP_INCLUDE_DIR + YAMLCPP_LIBRARY + YAMLCPP_LIBRARY_DIR) +mark_as_advanced( + YAMLCPP_INCLUDE_DIR + YAMLCPP_LIBRARY_DIR + YAMLCPP_LIBRARY + YAMLCPP_LIBRARY_RELEASE + YAMLCPP_LIBRARY_RELEASE_DIR + YAMLCPP_LIBRARY_DEBUG + YAMLCPP_LIBRARY_DEBUG_DIR) diff --git a/CMakeModules/Findcppcheck.cmake b/CMakeModules/Findcppcheck.cmake new file mode 100644 index 0000000..2dcf799 --- /dev/null +++ b/CMakeModules/Findcppcheck.cmake @@ -0,0 +1,167 @@ +# - try to find cppcheck tool +# +# Cache Variables: +# CPPCHECK_EXECUTABLE +# +# Non-cache variables you might use in your CMakeLists.txt: +# CPPCHECK_FOUND +# CPPCHECK_POSSIBLEERROR_ARG +# CPPCHECK_UNUSEDFUNC_ARG +# CPPCHECK_STYLE_ARG +# CPPCHECK_QUIET_ARG +# CPPCHECK_INCLUDEPATH_ARG +# CPPCHECK_FAIL_REGULAR_EXPRESSION +# CPPCHECK_WARN_REGULAR_EXPRESSION +# CPPCHECK_MARK_AS_ADVANCED - whether to mark our vars as advanced even +# if we don't find this program. +# +# Requires these CMake modules: +# FindPackageHandleStandardArgs (known included with CMake >=2.6.2) +# +# Original Author: +# 2009-2010 Ryan Pavlik +# http://academic.cleardefinition.com +# Iowa State University HCI Graduate Program/VRAC +# +# Copyright Iowa State University 2009-2010. +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at +# http://www.boost.org/LICENSE_1_0.txt) + +file(TO_CMAKE_PATH "${CPPCHECK_ROOT_DIR}" CPPCHECK_ROOT_DIR) +set(CPPCHECK_ROOT_DIR + "${CPPCHECK_ROOT_DIR}" + CACHE + PATH + "Path to search for cppcheck") + +# cppcheck app bundles on Mac OS X are GUI, we want command line only +set(_oldappbundlesetting ${CMAKE_FIND_APPBUNDLE}) +set(CMAKE_FIND_APPBUNDLE NEVER) + +if(CPPCHECK_EXECUTABLE AND NOT EXISTS "${CPPCHECK_EXECUTABLE}") + set(CPPCHECK_EXECUTABLE "notfound" CACHE PATH FORCE "") +endif() + +# If we have a custom path, look there first. +if(CPPCHECK_ROOT_DIR) + find_program(CPPCHECK_EXECUTABLE + NAMES + cppcheck + cli + PATHS + "${CPPCHECK_ROOT_DIR}" + PATH_SUFFIXES + cli + NO_DEFAULT_PATH) +endif() + +find_program(CPPCHECK_EXECUTABLE NAMES cppcheck) + +# Restore original setting for appbundle finding +set(CMAKE_FIND_APPBUNDLE ${_oldappbundlesetting}) + +# Find out where our test file is +get_filename_component(_cppcheckmoddir ${CMAKE_CURRENT_LIST_FILE} PATH) +set(_cppcheckdummyfile "${_cppcheckmoddir}/Findcppcheck.cpp") +if(NOT EXISTS "${_cppcheckdummyfile}") + message(FATAL_ERROR + "Missing file ${_cppcheckdummyfile} - should be alongside Findcppcheck.cmake, can be found at https://github.com/rpavlik/cmake-modules") +endif() + +function(_cppcheck_test_arg _resultvar _arg) + if(NOT CPPCHECK_EXECUTABLE) + set(${_resultvar} NO) + return() + endif() + execute_process(COMMAND + "${CPPCHECK_EXECUTABLE}" + "${_arg}" + "--quiet" + "${_cppcheckdummyfile}" + RESULT_VARIABLE + _cppcheck_result + OUTPUT_QUIET + ERROR_QUIET) + if("${_cppcheck_result}" EQUAL 0) + set(${_resultvar} YES PARENT_SCOPE) + else() + set(${_resultvar} NO PARENT_SCOPE) + endif() +endfunction() + +function(_cppcheck_set_arg_var _argvar _arg) + if("${${_argvar}}" STREQUAL "") + _cppcheck_test_arg(_cppcheck_arg "${_arg}") + if(_cppcheck_arg) + set(${_argvar} "${_arg}" PARENT_SCOPE) + endif() + endif() +endfunction() + +if(CPPCHECK_EXECUTABLE) + + # Check for the two types of command line arguments by just trying them + _cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--enable=style") + _cppcheck_set_arg_var(CPPCHECK_STYLE_ARG "--style") + if("${CPPCHECK_STYLE_ARG}" STREQUAL "--enable=style") + + _cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG + "--enable=unusedFunction") + _cppcheck_set_arg_var(CPPCHECK_INFORMATION_ARG "--enable=information") + _cppcheck_set_arg_var(CPPCHECK_MISSINGINCLUDE_ARG + "--enable=missingInclude") + _cppcheck_set_arg_var(CPPCHECK_POSIX_ARG "--enable=posix") + _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG + "--enable=possibleError") + _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--enable=all") + + if(MSVC) + set(CPPCHECK_TEMPLATE_ARG --template vs) + set(CPPCHECK_FAIL_REGULAR_EXPRESSION "[(]error[)]") + set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]") + elseif(CMAKE_COMPILER_IS_GNUCXX) + set(CPPCHECK_TEMPLATE_ARG --template gcc) + set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ") + set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ") + else() + set(CPPCHECK_TEMPLATE_ARG --template gcc) + set(CPPCHECK_FAIL_REGULAR_EXPRESSION " error: ") + set(CPPCHECK_WARN_REGULAR_EXPRESSION " style: ") + endif() + elseif("${CPPCHECK_STYLE_ARG}" STREQUAL "--style") + # Old arguments + _cppcheck_set_arg_var(CPPCHECK_UNUSEDFUNC_ARG "--unused-functions") + _cppcheck_set_arg_var(CPPCHECK_POSSIBLEERROR_ARG "--all") + set(CPPCHECK_FAIL_REGULAR_EXPRESSION "error:") + set(CPPCHECK_WARN_REGULAR_EXPRESSION "[(]style[)]") + else() + # No idea - some other issue must be getting in the way + message(STATUS + "WARNING: Can't detect whether CPPCHECK wants new or old-style arguments!") + endif() + + set(CPPCHECK_QUIET_ARG "--quiet") + set(CPPCHECK_INCLUDEPATH_ARG "-I") + +endif() + +set(CPPCHECK_ALL + "${CPPCHECK_EXECUTABLE} ${CPPCHECK_POSSIBLEERROR_ARG} ${CPPCHECK_UNUSEDFUNC_ARG} ${CPPCHECK_STYLE_ARG} ${CPPCHECK_QUIET_ARG} ${CPPCHECK_INCLUDEPATH_ARG} some/include/path") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(cppcheck + DEFAULT_MSG + CPPCHECK_ALL + CPPCHECK_EXECUTABLE + CPPCHECK_POSSIBLEERROR_ARG + CPPCHECK_UNUSEDFUNC_ARG + CPPCHECK_STYLE_ARG + CPPCHECK_INCLUDEPATH_ARG + CPPCHECK_QUIET_ARG) + +if(CPPCHECK_FOUND OR CPPCHECK_MARK_AS_ADVANCED) + mark_as_advanced(CPPCHECK_ROOT_DIR) +endif() + +mark_as_advanced(CPPCHECK_EXECUTABLE) diff --git a/CMakeModules/Findcppcheck.cpp b/CMakeModules/Findcppcheck.cpp new file mode 100644 index 0000000..84350db --- /dev/null +++ b/CMakeModules/Findcppcheck.cpp @@ -0,0 +1,16 @@ +/** + * \file Findcppcheck.cpp + * \brief Dummy C++ source file used by CMake module Findcppcheck.cmake + * + * \author + * Ryan Pavlik, 2009-2010 + * + * http://academic.cleardefinition.com/ + * + */ + + + +int main(int argc, char* argv[]) { + return 0; +} diff --git a/CMakeModules/Toolchain-mingw32.cmake b/CMakeModules/Toolchain-mingw32.cmake new file mode 100644 index 0000000..84470ad --- /dev/null +++ b/CMakeModules/Toolchain-mingw32.cmake @@ -0,0 +1,19 @@ +SET(CROSS_COMPILE_WINDOWS ON) + +# the name of the target operating system +SET(CMAKE_SYSTEM_NAME Windows) + +# which compilers to use for C and C++ +SET(CMAKE_C_COMPILER x86_64-w64-mingw32-gcc) +SET(CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++) +SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres) + +# here is the target environment located +SET(CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32) + +# adjust the default behaviour of the FIND_XXX() commands: +# search headers and libraries in the target environment, search +# programs in the host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5dd1fd4 --- /dev/null +++ b/LICENSE @@ -0,0 +1,202 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2017 R. Thomas + Copyright 2017 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a6fbc99 --- /dev/null +++ b/README.md @@ -0,0 +1,107 @@ +

+
+

+
+

+ + + + +

+ +The purpose of this project is to provide a cross platform library which can parse, modify and abstract ELF, PE and MachO formats. + +Main features: + + * **Parsing**: LIEF can parse ELF, PE, MachO and provides an user-friendly API to access to format internals. + * **Modify**: LIEF enables to modify some parts of these formats + * **Abstract**: Three formats have common features like sections, symbols, entry point... LIEF factors them. + * **API**: LIEF can be used in C, C++ and Python + +## Getting started + +### Python + +```python +import lief +# ELF +binary = lief.parse("/usr/bin/ls") +print(binary) + +# PE +binary = lief.parse("C:\\Windows\\explorer.exe") +print(binary) + +# Mach-O +binary = lief.parse("/usr/bin/ls") +print(binary) + +``` + +### C++ + +```cpp +#include +int main(int argc, const char** argv) { + LIEF::ELF::Binary* elf = LIEF::ELF::Parser::parse("/usr/bin/ls"); + LIEF::PE::Binary* pe = LIEF::PE::Parser::parse("C:\\Windows\\explorer.exe"); + LIEF::MachO::Binary* macho = LIEF::MachO::Parser::parse("/usr/bin/ls"); + + std::cout << *elf << std::endl; + std::cout << *pe << std::endl; + std::cout << *macho << std::endl; + + delete elf; + delete pe; + delete macho; +} +``` + +### C + +```cpp +#include +int main(int argc, const char** argv) { + + Elf_Binary_t* elf_binary = elf_parse("/usr/bin/ls"); + Pe_Binary_t* pe_binary = pe_parse("C:\\Windows\\explorer.exe"); + Macho_Binary_t** macho_binaries = macho_parse("/usr/bin/ls"); + + Pe_Section_t** pe_sections = pe_binary->sections; + Elf_Section_t** elf_sections = elf_binary->sections; + Macho_Section_t** macho_sections = macho_binaries[0]->sections; + + for (size_t i = 0; pe_sections[i] != NULL; ++i) { + printf("%s\n", pe_sections[i]->name) + } + + for (size_t i = 0; elf_sections[i] != NULL; ++i) { + printf("%s\n", elf_sections[i]->name) + } + + for (size_t i = 0; macho_sections[i] != NULL; ++i) { + printf("%s\n", macho_sections[i]->name) + } + + elf_binary_destroy(elf_binary); + pe_binary_destroy(pe_binary); + macho_binaries_destroy(macho_binaries); +} + +``` +## Documentation + +* [Tutorial](http://lief.quarkslab.com/doc) +* [API](http://lief.quarkslab.com/doc) +* [Doxygen](http://lief.quarkslab.com/doc) + +## Support + +* **Mail**: lief at quarkslab com +* **Gitter**: [lief-project](https://gitter.im/lief-project) + +## Authors + +Romain Thomas - [Quarkslab](https://www.quarkslab.com) + + diff --git a/api/c/CMakeLists.txt b/api/c/CMakeLists.txt new file mode 100644 index 0000000..3b941c5 --- /dev/null +++ b/api/c/CMakeLists.txt @@ -0,0 +1,52 @@ +include_directories( + ${CMAKE_CURRENT_SOURCE_DIR}/include/LIEF + ${CMAKE_CURRENT_SOURCE_DIR}/include +) + +set(LIEF_C_ELF_SRC + ${CMAKE_CURRENT_LIST_DIR}/ELF/Symbol.cpp + ${CMAKE_CURRENT_LIST_DIR}/ELF/Section.cpp + ${CMAKE_CURRENT_LIST_DIR}/ELF/Segment.cpp + ${CMAKE_CURRENT_LIST_DIR}/ELF/DynamicEntry.cpp + ${CMAKE_CURRENT_LIST_DIR}/ELF/Header.cpp + ${CMAKE_CURRENT_LIST_DIR}/ELF/Binary.cpp + ${CMAKE_CURRENT_LIST_DIR}/ELF/EnumToString.cpp) + + +set(LIEF_C_PE_SRC + ${CMAKE_CURRENT_LIST_DIR}/PE/Binary.cpp + ${CMAKE_CURRENT_LIST_DIR}/PE/DosHeader.cpp + ${CMAKE_CURRENT_LIST_DIR}/PE/Header.cpp + ${CMAKE_CURRENT_LIST_DIR}/PE/OptionalHeader.cpp + ${CMAKE_CURRENT_LIST_DIR}/PE/Section.cpp + ${CMAKE_CURRENT_LIST_DIR}/PE/DataDirectory.cpp + ${CMAKE_CURRENT_LIST_DIR}/PE/EnumToString.cpp) + + +set(LIEF_C_MACHO_SRC + ${CMAKE_CURRENT_LIST_DIR}/MachO/Parser.cpp + ${CMAKE_CURRENT_LIST_DIR}/MachO/LoadCommand.cpp + ${CMAKE_CURRENT_LIST_DIR}/MachO/Segment.cpp + ${CMAKE_CURRENT_LIST_DIR}/MachO/Symbol.cpp + ${CMAKE_CURRENT_LIST_DIR}/MachO/Section.cpp + ${CMAKE_CURRENT_LIST_DIR}/MachO/Header.cpp + ${CMAKE_CURRENT_LIST_DIR}/MachO/Binary.cpp + ${CMAKE_CURRENT_LIST_DIR}/MachO/EnumToString.cpp) + +set(LIEF_C_SRC) + +if (LIEF_ELF) + set(LIEF_C_SRC ${LIEF_C_SRC} ${LIEF_C_ELF_SRC}) +endif() + +if (LIEF_PE) + set(LIEF_C_SRC ${LIEF_C_SRC} ${LIEF_C_PE_SRC}) +endif() + +if (LIEF_MACHO) + set(LIEF_C_SRC ${LIEF_C_SRC} ${LIEF_C_MACHO_SRC}) +endif() + +target_sources(LIB_LIEF_STATIC PRIVATE ${LIEF_C_SRC}) +target_sources(LIB_LIEF_SHARED PRIVATE ${LIEF_C_SRC}) + diff --git a/api/c/ELF/Binary.cpp b/api/c/ELF/Binary.cpp new file mode 100644 index 0000000..9370583 --- /dev/null +++ b/api/c/ELF/Binary.cpp @@ -0,0 +1,112 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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/ELF/Binary.h" +#include "LIEF/ELF/Section.h" +#include "LIEF/ELF/Segment.h" +#include "LIEF/ELF/Header.h" +#include "LIEF/ELF/Symbol.h" + +#include "LIEF/ELF/Parser.hpp" +#include "LIEF/ELF/Binary.hpp" + +#include "Section.hpp" +#include "Segment.hpp" +#include "DynamicEntry.hpp" +#include "Symbol.hpp" +#include "Header.hpp" +#include "Binary.hpp" + +using namespace LIEF::ELF; + +namespace LIEF { +namespace ELF { +void init_c_binary(Elf_Binary_t* c_binary, Binary* binary) { + c_binary->handler = reinterpret_cast(binary); + c_binary->name = binary->name().c_str(); + c_binary->type = static_cast(binary->type()); + c_binary->interpreter = nullptr; + if (binary->has_interpreter()) { + std::string interp = binary->get_interpreter(); + c_binary->interpreter = static_cast(malloc(interp.size() * sizeof(char))); + std::memcpy( + reinterpret_cast(const_cast(c_binary->interpreter)), + reinterpret_cast(interp.data()), + interp.size()); + } + + + init_c_header(c_binary, binary); + init_c_sections(c_binary, binary); + init_c_segments(c_binary, binary); + init_c_dynamic_symbols(c_binary, binary); + init_c_static_symbols(c_binary, binary); + init_c_dynamic_entries(c_binary, binary); + + +} + +} +} + +Elf_Binary_t* elf_parse(const char *file) { + Binary* binary = Parser::parse(file); + Elf_Binary_t* c_binary = static_cast(malloc(sizeof(Elf_Binary_t))); + memset(c_binary, 0, sizeof(Elf_Binary_t)); + init_c_binary(c_binary, binary); + return c_binary; +} + +// Binary Methods +// ============== + +int elf_binary_save_header(Elf_Binary_t* binary) { + Header& hdr = reinterpret_cast(binary->handler)->get_header(); + + hdr.file_type(static_cast(binary->header.file_type)); + hdr.machine_type(static_cast(binary->header.machine_type)); + hdr.object_file_version(static_cast(binary->header.object_file_version)); + hdr.program_headers_offset(binary->header.program_headers_offset); + hdr.section_headers_offset(binary->header.section_headers_offset); + hdr.processor_flag(binary->header.processor_flags); + hdr.header_size(binary->header.header_size); + hdr.program_header_size(binary->header.program_header_size); + hdr.numberof_segments(binary->header.numberof_segments); + hdr.sizeof_section_header(binary->header.sizeof_section_header); + hdr.numberof_sections(binary->header.numberof_sections); + hdr.section_name_table_idx(binary->header.name_string_table_idx); + hdr.entrypoint(binary->header.entrypoint); + + //TODO: identity + return true; +} + + +void elf_binary_destroy(Elf_Binary_t* binary) { + destroy_sections(binary); + destroy_segments(binary); + destroy_dynamic_symbols(binary); + destroy_static_symbols(binary); + destroy_dynamic_entries(binary); + + if (binary->interpreter != nullptr) { + free(const_cast(binary->interpreter)); + } + + delete reinterpret_cast(binary->handler); + free(binary); + +} +//} diff --git a/api/c/ELF/Binary.hpp b/api/c/ELF/Binary.hpp new file mode 100644 index 0000000..61d11a2 --- /dev/null +++ b/api/c/ELF/Binary.hpp @@ -0,0 +1,30 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_ELF_BINARY_CPP_C_API_ +#define LIEF_ELF_BINARY_CPP_C_API_ + +#include "LIEF/ELF/Binary.h" +#include "LIEF/ELF/Binary.hpp" + +namespace LIEF { +namespace ELF { + +void init_c_binary(Elf_Binary_t* c_binary, Binary* binary); + +} +} + +#endif diff --git a/api/c/ELF/DynamicEntry.cpp b/api/c/ELF/DynamicEntry.cpp new file mode 100644 index 0000000..fd05d67 --- /dev/null +++ b/api/c/ELF/DynamicEntry.cpp @@ -0,0 +1,174 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "DynamicEntry.hpp" + +namespace LIEF { +namespace ELF { + +void init_c_dynamic_entries(Elf_Binary_t* c_binary, Binary* binary) { + + it_dynamic_entries dyn_entries = binary->get_dynamic_entries(); + c_binary->dynamic_entries = static_cast( + malloc((dyn_entries.size() + 1) * sizeof(Elf_DynamicEntry_t**))); + + for (size_t i = 0; i < dyn_entries.size(); ++i) { + DynamicEntry& entry = dyn_entries[i]; + switch(entry.tag()) { + case DYNAMIC_TAGS::DT_NEEDED: + { + + Elf_DynamicEntry_Library_t* e = static_cast( + malloc(sizeof(Elf_DynamicEntry_Library_t))); + + e->tag = static_cast(entry.tag()); + e->value = entry.value(); + e->name = dynamic_cast(&entry)->name().c_str(); + + c_binary->dynamic_entries[i] = reinterpret_cast(e); + break; + // cppcheck-suppress memleak + } + + case DYNAMIC_TAGS::DT_SONAME: + { + Elf_DynamicEntry_SharedObject_t* e = static_cast( + malloc(sizeof(Elf_DynamicEntry_SharedObject_t))); + + e->tag = static_cast(entry.tag()); + e->value = entry.value(); + e->name = dynamic_cast(&entry)->name().c_str(); + + c_binary->dynamic_entries[i] = reinterpret_cast(e); + break; + } + + case DYNAMIC_TAGS::DT_RPATH: + { + Elf_DynamicEntry_Rpath_t* e = static_cast( + malloc(sizeof(Elf_DynamicEntry_Rpath_t))); + + e->tag = static_cast(entry.tag()); + e->value = entry.value(); + e->rpath = dynamic_cast(&entry)->name().c_str(); + + c_binary->dynamic_entries[i] = reinterpret_cast(e); + + break; + } + + case DYNAMIC_TAGS::DT_RUNPATH: + { + Elf_DynamicEntry_RunPath_t* e = static_cast( + malloc(sizeof(Elf_DynamicEntry_RunPath_t))); + + e->tag = static_cast(entry.tag()); + e->value = entry.value(); + e->runpath = dynamic_cast(&entry)->name().c_str(); + + c_binary->dynamic_entries[i] = reinterpret_cast(e); + + break; + } + + case DYNAMIC_TAGS::DT_INIT_ARRAY: + case DYNAMIC_TAGS::DT_FINI_ARRAY: + case DYNAMIC_TAGS::DT_PREINIT_ARRAY: + { + Elf_DynamicEntry_Array_t* e = static_cast( + malloc(sizeof(Elf_DynamicEntry_Array_t))); + + e->tag = static_cast(entry.tag()); + e->value = entry.value(); + const std::vector& array = dynamic_cast(&entry)->array(); + e->array = static_cast(malloc((array.size() + 1) * sizeof(uint64_t))); + for (size_t i = 0; i < array.size(); ++i) { + e->array[i] = array[i]; + } + e->array[array.size()] = 0; + c_binary->dynamic_entries[i] = reinterpret_cast(e); + + break; + } + default: + { + c_binary->dynamic_entries[i] = + static_cast(malloc(sizeof(Elf_DynamicEntry_t))); + c_binary->dynamic_entries[i]->tag = static_cast(entry.tag()); + c_binary->dynamic_entries[i]->value = entry.value(); + + } + } + } + + c_binary->dynamic_entries[dyn_entries.size()] = nullptr; + +} + + + +void destroy_dynamic_entries(Elf_Binary_t* c_binary) { + + Elf_DynamicEntry_t **dynamic_entries = c_binary->dynamic_entries; + for (size_t idx = 0; dynamic_entries[idx] != NULL; ++idx) { + switch(dynamic_entries[idx]->tag) { + case DYNAMIC_TAGS::DT_NEEDED: + { + free(reinterpret_cast(dynamic_entries[idx])); + break; + } + + case DYNAMIC_TAGS::DT_SONAME: + { + free(reinterpret_cast(dynamic_entries[idx])); + break; + } + + case DYNAMIC_TAGS::DT_RPATH: + { + free(reinterpret_cast(dynamic_entries[idx])); + break; + } + + case DYNAMIC_TAGS::DT_RUNPATH: + { + free(reinterpret_cast(dynamic_entries[idx])); + break; + } + + case DYNAMIC_TAGS::DT_INIT_ARRAY: + case DYNAMIC_TAGS::DT_FINI_ARRAY: + case DYNAMIC_TAGS::DT_PREINIT_ARRAY: + { + free(reinterpret_cast(dynamic_entries[idx])); + break; + } + default: + { + + free(dynamic_entries[idx]); + } + + + } + } + free(c_binary->dynamic_entries); + +} + +} +} + + diff --git a/api/c/ELF/DynamicEntry.hpp b/api/c/ELF/DynamicEntry.hpp new file mode 100644 index 0000000..5004227 --- /dev/null +++ b/api/c/ELF/DynamicEntry.hpp @@ -0,0 +1,34 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_ELF_DYNAMIC_ENTRY_CPP_C_API_ +#define LIEF_ELF_DYNAMIC_ENTRY_CPP_C_API_ + +#include "LIEF/ELF/Binary.h" +#include "LIEF/ELF/Binary.hpp" + +#include "LIEF/ELF/DynamicEntry.h" +#include "LIEF/ELF/DynamicEntry.hpp" + +namespace LIEF { +namespace ELF { + +void init_c_dynamic_entries(Elf_Binary_t* c_binary, Binary* binary); +void destroy_dynamic_entries(Elf_Binary_t* c_binary); + +} +} + +#endif diff --git a/api/c/ELF/EnumToString.cpp b/api/c/ELF/EnumToString.cpp new file mode 100644 index 0000000..95e60e9 --- /dev/null +++ b/api/c/ELF/EnumToString.cpp @@ -0,0 +1,73 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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/ELF/EnumToString.h" +#include "LIEF/ELF/EnumToString.hpp" + +#include "LIEF/ELF/Structures.hpp" +#include "LIEF/ELF/structures.h" + + +extern "C" +{ + const char* E_TYPE_to_string(enum E_TYPE e) { + return LIEF::ELF::to_string(static_cast(e)); + } + + const char* SYMBOL_BINDINGS_to_string(enum SYMBOL_BINDINGS e) { + return LIEF::ELF::to_string(static_cast(e)); + } + + const char* VERSION_to_string(enum VERSION e) { + return LIEF::ELF::to_string(static_cast(e)); + } + + const char* ARCH_to_string(enum ARCH e) { + return LIEF::ELF::to_string(static_cast(e)); + } + + const char* SEGMENT_TYPES_to_string(enum SEGMENT_TYPES e) { + return LIEF::ELF::to_string(static_cast(e)); + } + + const char* DYNAMIC_TAGS_to_string(enum DYNAMIC_TAGS e) { + return LIEF::ELF::to_string(static_cast(e)); + } + + const char* SECTION_TYPES_to_string(enum SECTION_TYPES e) { + return LIEF::ELF::to_string(static_cast(e)); + } + + const char* SECTION_FLAGS_to_string(enum SECTION_FLAGS e) { + return LIEF::ELF::to_string(static_cast(e)); + } + + const char* SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e) { + return LIEF::ELF::to_string(static_cast(e)); + } + + const char* ELF_CLASS_to_string(enum ELF_CLASS e) { + return LIEF::ELF::to_string(static_cast(e)); + } + + const char* ELF_DATA_to_string(enum ELF_DATA e) { + return LIEF::ELF::to_string(static_cast(e)); + } + + const char* OS_ABI_to_string(enum OS_ABI e) { + return LIEF::ELF::to_string(static_cast(e)); + } + +} diff --git a/api/c/ELF/Header.cpp b/api/c/ELF/Header.cpp new file mode 100644 index 0000000..603bac1 --- /dev/null +++ b/api/c/ELF/Header.cpp @@ -0,0 +1,46 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "Header.hpp" + +namespace LIEF { +namespace ELF { + +void init_c_header(Elf_Binary_t* c_binary, Binary* binary) { + + const Header& hdr = binary->get_header(); + c_binary->header.file_type = static_cast(hdr.file_type()); + c_binary->header.machine_type = static_cast(hdr.machine_type()); + c_binary->header.object_file_version = static_cast(hdr.object_file_version()); + c_binary->header.program_headers_offset = hdr.program_headers_offset(); + c_binary->header.section_headers_offset = hdr.section_headers_offset(); + c_binary->header.processor_flags = hdr.processor_flag(); + c_binary->header.header_size = hdr.header_size(); + c_binary->header.program_header_size = hdr.program_header_size(); + c_binary->header.numberof_segments = hdr.numberof_segments(); + c_binary->header.sizeof_section_header = hdr.sizeof_section_header(); + c_binary->header.numberof_sections = hdr.numberof_sections(); + c_binary->header.name_string_table_idx = hdr.section_name_table_idx(); + c_binary->header.entrypoint = hdr.entrypoint(); + const Header::identity_t& ident = hdr.identity(); + std::copy( + std::begin(ident), + std::end(ident), + c_binary->header.identity); + +} + +} +} diff --git a/api/c/ELF/Header.hpp b/api/c/ELF/Header.hpp new file mode 100644 index 0000000..cc2bcd6 --- /dev/null +++ b/api/c/ELF/Header.hpp @@ -0,0 +1,33 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_ELF_HEADER_CPP_C_API_ +#define LIEF_ELF_HEADER_CPP_C_API_ + +#include "LIEF/ELF/Binary.h" +#include "LIEF/ELF/Binary.hpp" + +#include "LIEF/ELF/Header.h" +#include "LIEF/ELF/Header.hpp" + +namespace LIEF { +namespace ELF { + +void init_c_header(Elf_Binary_t* c_binary, Binary* binary); + +} +} + +#endif diff --git a/api/c/ELF/Section.cpp b/api/c/ELF/Section.cpp new file mode 100644 index 0000000..3c5facf --- /dev/null +++ b/api/c/ELF/Section.cpp @@ -0,0 +1,71 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "Section.hpp" + +namespace LIEF { +namespace ELF { +void init_c_sections(Elf_Binary_t* c_binary, Binary* binary) { + + it_sections sections = binary->get_sections(); + + c_binary->sections = static_cast( + malloc((sections.size() + 1) * sizeof(Elf_Section_t**))); + + for (size_t i = 0; i < sections.size(); ++i) { + Section& b_section = sections[i]; + c_binary->sections[i] = static_cast(malloc(sizeof(Elf_Section_t))); + const std::vector& section_content = b_section.content(); + uint8_t* content = static_cast(malloc(section_content.size() * sizeof(uint8_t))); + std::copy( + std::begin(section_content), + std::end(section_content), + content); + + c_binary->sections[i]->name = b_section.name().c_str(); + c_binary->sections[i]->flags = b_section.flags(); + c_binary->sections[i]->type = static_cast(b_section.type()); + c_binary->sections[i]->virtual_address = b_section.virtual_address(); + c_binary->sections[i]->offset = b_section.file_offset(); + c_binary->sections[i]->original_size = b_section.original_size(); + c_binary->sections[i]->link = b_section.link(); + c_binary->sections[i]->info = b_section.information(); + c_binary->sections[i]->alignment = b_section.alignment(); + c_binary->sections[i]->entry_size = b_section.entry_size(); + c_binary->sections[i]->content = content; + c_binary->sections[i]->size = section_content.size(); + c_binary->sections[i]->entropy = b_section.entropy(); + } + c_binary->sections[sections.size()] = nullptr; + +} + + + +void destroy_sections(Elf_Binary_t* c_binary) { + + Elf_Section_t **sections = c_binary->sections; + for (size_t idx = 0; sections[idx] != nullptr; ++idx) { + free(sections[idx]->content); + free(sections[idx]); + } + free(c_binary->sections); + +} + +} +} + + diff --git a/api/c/ELF/Section.hpp b/api/c/ELF/Section.hpp new file mode 100644 index 0000000..90d8ece --- /dev/null +++ b/api/c/ELF/Section.hpp @@ -0,0 +1,34 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_ELF_SECTION_CPP_C_API_ +#define LIEF_ELF_SECTION_CPP_C_API_ + +#include "LIEF/ELF/Binary.h" +#include "LIEF/ELF/Binary.hpp" + +#include "LIEF/ELF/Section.h" +#include "LIEF/ELF/Section.hpp" + +namespace LIEF { +namespace ELF { + +void init_c_sections(Elf_Binary_t* c_binary, Binary* binary); +void destroy_sections(Elf_Binary_t* c_binary); + +} +} + +#endif diff --git a/api/c/ELF/Segment.cpp b/api/c/ELF/Segment.cpp new file mode 100644 index 0000000..6ad3a19 --- /dev/null +++ b/api/c/ELF/Segment.cpp @@ -0,0 +1,67 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "Segment.hpp" + +namespace LIEF { +namespace ELF { + +void init_c_segments(Elf_Binary_t* c_binary, Binary* binary) { + + it_segments segments = binary->get_segments(); + c_binary->segments = static_cast( + malloc((segments.size() + 1) * sizeof(Elf_Segment_t**))); + for (size_t i = 0; i < segments.size(); ++i) { + Segment& segment = segments[i]; + + const std::vector& segment_content = segment.content(); + uint8_t* content = static_cast(malloc(segment_content.size() * sizeof(uint8_t))); + std::copy( + std::begin(segment_content), + std::end(segment_content), + content); + + c_binary->segments[i] = static_cast(malloc(sizeof(Elf_Segment_t))); + c_binary->segments[i]->type = static_cast(segment.type()); + c_binary->segments[i]->flags = segment.flag(); + c_binary->segments[i]->virtual_address = segment.virtual_address(); + c_binary->segments[i]->virtual_size = segment.virtual_size(); + c_binary->segments[i]->offset = segment.file_offset(); + c_binary->segments[i]->alignment = segment.alignment(); + c_binary->segments[i]->size = segment_content.size(); + c_binary->segments[i]->content = content; + } + + c_binary->segments[segments.size()] = nullptr; + +} + + + +void destroy_segments(Elf_Binary_t* c_binary) { + + Elf_Segment_t **segments = c_binary->segments; + for (size_t idx = 0; segments[idx] != nullptr; ++idx) { + free(segments[idx]->content); + free(segments[idx]); + } + free(c_binary->segments); + +} + +} +} + + diff --git a/api/c/ELF/Segment.hpp b/api/c/ELF/Segment.hpp new file mode 100644 index 0000000..858bdf2 --- /dev/null +++ b/api/c/ELF/Segment.hpp @@ -0,0 +1,34 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_ELF_SEGMENT_CPP_C_API_ +#define LIEF_ELF_SEGMENT_CPP_C_API_ + +#include "LIEF/ELF/Binary.h" +#include "LIEF/ELF/Binary.hpp" + +#include "LIEF/ELF/Segment.h" +#include "LIEF/ELF/Segment.hpp" + +namespace LIEF { +namespace ELF { + +void init_c_segments(Elf_Binary_t* c_binary, Binary* binary); +void destroy_segments(Elf_Binary_t* c_binary); + +} +} + +#endif diff --git a/api/c/ELF/Symbol.cpp b/api/c/ELF/Symbol.cpp new file mode 100644 index 0000000..fdde7f4 --- /dev/null +++ b/api/c/ELF/Symbol.cpp @@ -0,0 +1,90 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "Symbol.hpp" + +namespace LIEF { +namespace ELF { + +void init_c_dynamic_symbols(Elf_Binary_t* c_binary, Binary* binary) { + it_symbols dyn_symb = binary->get_dynamic_symbols(); + + c_binary->dynamic_symbols = static_cast( + malloc((dyn_symb.size() + 1) * sizeof(Elf_Symbol_t**))); + + for (size_t i = 0; i < dyn_symb.size(); ++i) { + Symbol& b_sym = dyn_symb[i]; + c_binary->dynamic_symbols[i] = static_cast(malloc(sizeof(Elf_Symbol_t))); + c_binary->dynamic_symbols[i]->name = b_sym.name().c_str(); + c_binary->dynamic_symbols[i]->type = static_cast(b_sym.type()); + c_binary->dynamic_symbols[i]->binding = static_cast(b_sym.binding()); + c_binary->dynamic_symbols[i]->other = b_sym.other(); + c_binary->dynamic_symbols[i]->shndx = b_sym.shndx(); + c_binary->dynamic_symbols[i]->value = b_sym.value(); + c_binary->dynamic_symbols[i]->size = b_sym.size(); + c_binary->dynamic_symbols[i]->information = b_sym.information(); + } + c_binary->dynamic_symbols[dyn_symb.size()] = nullptr; + + + +} + + +void init_c_static_symbols(Elf_Binary_t* c_binary, Binary* binary) { + it_symbols static_symb = binary->get_static_symbols(); + + c_binary->static_symbols = static_cast( + malloc((static_symb.size() + 1) * sizeof(Elf_Symbol_t**))); + + for (size_t i = 0; i < static_symb.size(); ++i) { + Symbol& b_sym = static_symb[i]; + c_binary->static_symbols[i] = static_cast(malloc(sizeof(Elf_Symbol_t))); + c_binary->static_symbols[i]->name = b_sym.name().c_str(); + c_binary->static_symbols[i]->type = static_cast(b_sym.type()); + c_binary->static_symbols[i]->binding = static_cast(b_sym.binding()); + c_binary->static_symbols[i]->other = b_sym.other(); + c_binary->static_symbols[i]->shndx = b_sym.shndx(); + c_binary->static_symbols[i]->value = b_sym.value(); + c_binary->static_symbols[i]->size = b_sym.size(); + c_binary->static_symbols[i]->information = b_sym.information(); + } + c_binary->static_symbols[static_symb.size()] = nullptr; + +} + + + +void destroy_dynamic_symbols(Elf_Binary_t* c_binary) { + Elf_Symbol_t **dynamic_symbols = c_binary->dynamic_symbols; + for (size_t idx = 0; dynamic_symbols[idx] != nullptr; ++idx) { + free(dynamic_symbols[idx]); + } + free(c_binary->dynamic_symbols); +} + + +void destroy_static_symbols(Elf_Binary_t* c_binary) { + Elf_Symbol_t **static_symbols = c_binary->static_symbols; + for (size_t idx = 0; static_symbols[idx] != nullptr; ++idx) { + free(static_symbols[idx]); + } + free(c_binary->static_symbols); +} + +} +} + + diff --git a/api/c/ELF/Symbol.hpp b/api/c/ELF/Symbol.hpp new file mode 100644 index 0000000..4597068 --- /dev/null +++ b/api/c/ELF/Symbol.hpp @@ -0,0 +1,37 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_ELF_SYMBOL_CPP_C_API_ +#define LIEF_ELF_SYMBOL_CPP_C_API_ + +#include "LIEF/ELF/Binary.h" +#include "LIEF/ELF/Binary.hpp" + +#include "LIEF/ELF/Symbol.h" +#include "LIEF/ELF/Symbol.hpp" + +namespace LIEF { +namespace ELF { + +void init_c_dynamic_symbols(Elf_Binary_t* c_binary, Binary* binary); +void init_c_static_symbols(Elf_Binary_t* c_binary, Binary* binary); + +void destroy_dynamic_symbols(Elf_Binary_t* c_binary); +void destroy_static_symbols(Elf_Binary_t* c_binary); + +} +} + +#endif diff --git a/api/c/MachO/Binary.cpp b/api/c/MachO/Binary.cpp new file mode 100644 index 0000000..8a55012 --- /dev/null +++ b/api/c/MachO/Binary.cpp @@ -0,0 +1,58 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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/MachO/Binary.h" + +#include "LIEF/MachO/Binary.hpp" + +#include "Binary.hpp" +#include "Section.hpp" +#include "Header.hpp" +#include "Symbol.hpp" +#include "Segment.hpp" +#include "LoadCommand.hpp" + + +using namespace LIEF::MachO; + +namespace LIEF { +namespace MachO { +void init_c_binary(Macho_Binary_t* c_binary, Binary* binary) { + + c_binary->handler = reinterpret_cast(binary); + c_binary->name = binary->name().c_str(); + c_binary->imagebase = binary->imagebase(); + init_c_header(c_binary, binary); + init_c_commands(c_binary, binary); + init_c_symbols(c_binary, binary); + init_c_sections(c_binary, binary); + init_c_segments(c_binary, binary); +} +} +} + +void macho_binaries_destroy(Macho_Binary_t** binaries) { + for (size_t i = 0; binaries[i] != nullptr; ++i) { + destroy_sections(binaries[i]); + destroy_commands(binaries[i]); + destroy_symbols(binaries[i]); + destroy_segments(binaries[i]); + + delete reinterpret_cast(binaries[i]->handler); + free(binaries[i]); + } + free(binaries); + +} diff --git a/api/c/MachO/Binary.hpp b/api/c/MachO/Binary.hpp new file mode 100644 index 0000000..134800a --- /dev/null +++ b/api/c/MachO/Binary.hpp @@ -0,0 +1,30 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_MACHO_BINARY_CPP_C_API_ +#define LIEF_MACHO_BINARY_CPP_C_API_ + +#include "LIEF/MachO/Binary.h" +#include "LIEF/MachO/Binary.hpp" + +namespace LIEF { +namespace MachO { + +void init_c_binary(Macho_Binary_t* c_binary, Binary* binary); + +} +} + +#endif diff --git a/api/c/MachO/EnumToString.cpp b/api/c/MachO/EnumToString.cpp new file mode 100644 index 0000000..5ff9357 --- /dev/null +++ b/api/c/MachO/EnumToString.cpp @@ -0,0 +1,76 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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/MachO/EnumToString.h" +#include "LIEF/MachO/EnumToString.hpp" + +#include "LIEF/MachO/enums.hpp" +#include "LIEF/MachO/enums.h" + + +extern "C" +{ + +const char* LOAD_COMMAND_TYPES_to_string(enum LOAD_COMMAND_TYPES e) { + return LIEF::MachO::to_string(static_cast(e)); +} + + +const char* MACHO_TYPES_to_string(enum MACHO_TYPES e) { + return LIEF::MachO::to_string(static_cast(e)); +} + + +const char* FILE_TYPES_to_string(enum FILE_TYPES e) { + return LIEF::MachO::to_string(static_cast(e)); +} + + +const char* CPU_TYPES_to_string(enum CPU_TYPES e) { + return LIEF::MachO::to_string(static_cast(e)); +} + + +const char* HEADER_FLAGS_to_string(enum HEADER_FLAGS e) { + return LIEF::MachO::to_string(static_cast(e)); +} + + +const char* MachO_SECTION_TYPES_to_string(enum SECTION_TYPES e) { + return LIEF::MachO::to_string(static_cast(e)); +} + + +const char* MachO_SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e) { + return LIEF::MachO::to_string(static_cast(e)); +} + + +const char* N_LIST_TYPES_to_string(enum N_LIST_TYPES e) { + return LIEF::MachO::to_string(static_cast(e)); +} + + +const char* SYMBOL_DESCRIPTIONS_to_string(enum SYMBOL_DESCRIPTIONS e) { + return LIEF::MachO::to_string(static_cast(e)); +} + + + + + + + +} diff --git a/api/c/MachO/Header.cpp b/api/c/MachO/Header.cpp new file mode 100644 index 0000000..5d00c17 --- /dev/null +++ b/api/c/MachO/Header.cpp @@ -0,0 +1,33 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "Header.hpp" + +namespace LIEF { +namespace MachO { +void init_c_header(Macho_Binary_t* c_binary, Binary* binary) { + Header& header = binary->header(); + c_binary->header.magic = header.magic(); + c_binary->header.cpu_type = static_cast(header.cpu_type()); + c_binary->header.cpu_subtype = header.cpu_subtype(); + c_binary->header.file_type = static_cast(header.file_type()); + c_binary->header.nb_cmds = header.nb_cmds(); + c_binary->header.sizeof_cmds = header.sizeof_cmds(); + c_binary->header.flags = header.flags(); + c_binary->header.reserved = header.reserved(); +} + +} +} diff --git a/api/c/MachO/Header.hpp b/api/c/MachO/Header.hpp new file mode 100644 index 0000000..aea92e2 --- /dev/null +++ b/api/c/MachO/Header.hpp @@ -0,0 +1,33 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_MACHO_HEADER_CPP_C_API_ +#define LIEF_MACHO_HEADER_CPP_C_API_ + +#include "LIEF/MachO/Binary.h" +#include "LIEF/MachO/Binary.hpp" + +#include "LIEF/MachO/Header.h" +#include "LIEF/MachO/Header.hpp" + +namespace LIEF { +namespace MachO { + +void init_c_header(Macho_Binary_t* c_binary, Binary* binary); + +} +} + +#endif diff --git a/api/c/MachO/LoadCommand.cpp b/api/c/MachO/LoadCommand.cpp new file mode 100644 index 0000000..89c53ed --- /dev/null +++ b/api/c/MachO/LoadCommand.cpp @@ -0,0 +1,62 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "LoadCommand.hpp" + +namespace LIEF { +namespace MachO { +void init_c_commands(Macho_Binary_t* c_binary, Binary* binary) { + it_commands commands = binary->commands(); + + c_binary->commands = static_cast( + malloc((commands.size() + 1) * sizeof(Macho_Command_t**))); + + for (size_t i = 0; i < commands.size(); ++i) { + LoadCommand& cmd = commands[i]; + + c_binary->commands[i] = static_cast(malloc(sizeof(Macho_Command_t))); + const std::vector& cmd_content = cmd.data(); + uint8_t* content = static_cast(malloc(cmd_content.size() * sizeof(uint8_t))); + std::copy( + std::begin(cmd_content), + std::end(cmd_content), + content); + + c_binary->commands[i]->command = static_cast(cmd.command()); + c_binary->commands[i]->size = cmd.size(); + c_binary->commands[i]->data = content; + c_binary->commands[i]->offset = cmd.command_offset(); + } + + c_binary->commands[commands.size()] = nullptr; + +} + + + +void destroy_commands(Macho_Binary_t* c_binary) { + Macho_Command_t **commands = c_binary->commands; + for (size_t idx = 0; commands[idx] != nullptr; ++idx) { + free(commands[idx]->data); + free(commands[idx]); + } + free(c_binary->commands); + +} + +} +} + + diff --git a/api/c/MachO/LoadCommand.hpp b/api/c/MachO/LoadCommand.hpp new file mode 100644 index 0000000..f28c509 --- /dev/null +++ b/api/c/MachO/LoadCommand.hpp @@ -0,0 +1,34 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_MACHO_LOAD_COMMAND_CPP_C_API_ +#define LIEF_MACHO_LOAD_COMMAND_CPP_C_API_ + +#include "LIEF/MachO/Binary.h" +#include "LIEF/MachO/Binary.hpp" + +#include "LIEF/MachO/LoadCommand.h" +#include "LIEF/MachO/LoadCommand.hpp" + +namespace LIEF { +namespace MachO { + +void init_c_commands(Macho_Binary_t* c_binary, Binary* binary); +void destroy_commands(Macho_Binary_t* c_binary); + +} +} + +#endif diff --git a/api/c/MachO/Parser.cpp b/api/c/MachO/Parser.cpp new file mode 100644 index 0000000..6907820 --- /dev/null +++ b/api/c/MachO/Parser.cpp @@ -0,0 +1,41 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 + +#include "LIEF/MachO/Binary.h" +#include "LIEF/MachO/Parser.hpp" + +#include "Binary.hpp" + +using namespace LIEF::MachO; + +Macho_Binary_t** macho_parse(const char *file) { + std::vector macho_binaries{Parser::parse(file)}; + + Macho_Binary_t** c_macho_binaries = static_cast( + malloc((macho_binaries.size() + 1) * sizeof(Macho_Binary_t**))); + + for (size_t i = 0; i < macho_binaries.size(); ++i) { + Binary* binary = macho_binaries [i]; + c_macho_binaries[i] = static_cast(malloc(sizeof(Macho_Binary_t))); + init_c_binary(c_macho_binaries[i], binary); + } + + c_macho_binaries[macho_binaries.size()] = nullptr; + + return c_macho_binaries; +} + diff --git a/api/c/MachO/Section.cpp b/api/c/MachO/Section.cpp new file mode 100644 index 0000000..5ffd20f --- /dev/null +++ b/api/c/MachO/Section.cpp @@ -0,0 +1,72 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "Section.hpp" + +namespace LIEF { +namespace MachO { +void init_c_sections(Macho_Binary_t* c_binary, Binary* binary) { + it_sections sections = binary->sections(); + + c_binary->sections = static_cast( + malloc((sections.size() + 1) * sizeof(Macho_Section_t**))); + + for (size_t i = 0; i < sections.size(); ++i) { + Section& section = sections[i]; + + c_binary->sections[i] = static_cast(malloc(sizeof(Macho_Section_t))); + const std::vector& section_content = section.content(); + uint8_t* content = static_cast(malloc(section_content.size() * sizeof(uint8_t))); + std::copy( + std::begin(section_content), + std::end(section_content), + content); + + c_binary->sections[i]->name = section.name().c_str(); + c_binary->sections[i]->alignment = section.alignment(); + c_binary->sections[i]->relocation_offset = section.relocation_offset(); + c_binary->sections[i]->numberof_relocations = section.numberof_relocations(); + c_binary->sections[i]->flags = section.flags(); + c_binary->sections[i]->type = static_cast(section.type()); + c_binary->sections[i]->reserved1 = section.reserved1(); + c_binary->sections[i]->reserved2 = section.reserved2(); + c_binary->sections[i]->reserved3 = section.reserved3(); + c_binary->sections[i]->virtual_address = section.virtual_address(); + c_binary->sections[i]->offset = section.offset(); + c_binary->sections[i]->size = section.size(); + c_binary->sections[i]->content = content; + c_binary->sections[i]->entropy = section.entropy(); + } + + c_binary->sections[sections.size()] = nullptr; + +} + + + +void destroy_sections(Macho_Binary_t* c_binary) { + Macho_Section_t **sections = c_binary->sections; + for (size_t idx = 0; sections[idx] != nullptr; ++idx) { + free(sections[idx]->content); + free(sections[idx]); + } + free(c_binary->sections); + +} + +} +} + + diff --git a/api/c/MachO/Section.hpp b/api/c/MachO/Section.hpp new file mode 100644 index 0000000..26fdd33 --- /dev/null +++ b/api/c/MachO/Section.hpp @@ -0,0 +1,34 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_MACHO_SECTION_CPP_C_API_ +#define LIEF_MACHO_SECTION_CPP_C_API_ + +#include "LIEF/MachO/Binary.h" +#include "LIEF/MachO/Binary.hpp" + +#include "LIEF/MachO/Section.h" +#include "LIEF/MachO/Section.hpp" + +namespace LIEF { +namespace MachO { + +void init_c_sections(Macho_Binary_t* c_binary, Binary* binary); +void destroy_sections(Macho_Binary_t* c_binary); + +} +} + +#endif diff --git a/api/c/MachO/Segment.cpp b/api/c/MachO/Segment.cpp new file mode 100644 index 0000000..2cdfa70 --- /dev/null +++ b/api/c/MachO/Segment.cpp @@ -0,0 +1,69 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "Segment.hpp" + +namespace LIEF { +namespace MachO { +void init_c_segments(Macho_Binary_t* c_binary, Binary* binary) { + it_segments segments = binary->segments(); + + c_binary->segments = static_cast( + malloc((segments.size() + 1) * sizeof(Macho_Segment_t**))); + + for (size_t i = 0; i < segments.size(); ++i) { + SegmentCommand& segment = segments[i]; + + c_binary->segments[i] = static_cast(malloc(sizeof(Macho_Segment_t))); + const std::vector& segment_content = segment.content(); + uint8_t* content = static_cast(malloc(segment_content.size() * sizeof(uint8_t))); + std::copy( + std::begin(segment_content), + std::end(segment_content), + content); + + c_binary->segments[i]->name = segment.name().c_str(); + c_binary->segments[i]->virtual_address = segment.virtual_address(); + c_binary->segments[i]->virtual_size = segment.virtual_size(); + c_binary->segments[i]->file_size = segment.file_size(); + c_binary->segments[i]->file_offset = segment.file_offset(); + c_binary->segments[i]->max_protection = segment.max_protection(); + c_binary->segments[i]->init_protection = segment.init_protection(); + c_binary->segments[i]->numberof_sections = segment.numberof_sections(); + c_binary->segments[i]->flags = segment.flags(); + c_binary->segments[i]->content = content; + c_binary->segments[i]->sections = nullptr; //TODO + } + + c_binary->segments[segments.size()] = nullptr; + +} + + + +void destroy_segments(Macho_Binary_t* c_binary) { + Macho_Segment_t **segments = c_binary->segments; + for (size_t idx = 0; segments[idx] != nullptr; ++idx) { + free(segments[idx]->content); + free(segments[idx]); + } + free(c_binary->segments); + +} + +} +} + + diff --git a/api/c/MachO/Segment.hpp b/api/c/MachO/Segment.hpp new file mode 100644 index 0000000..e56df2b --- /dev/null +++ b/api/c/MachO/Segment.hpp @@ -0,0 +1,34 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_MACHO_SEGMENT_CPP_C_API_ +#define LIEF_MACHO_SEGMENT_CPP_C_API_ + +#include "LIEF/MachO/Binary.h" +#include "LIEF/MachO/Binary.hpp" + +#include "LIEF/MachO/Segment.h" +#include "LIEF/MachO/SegmentCommand.hpp" + +namespace LIEF { +namespace MachO { + +void init_c_segments(Macho_Binary_t* c_binary, Binary* binary); +void destroy_segments(Macho_Binary_t* c_binary); + +} +} + +#endif diff --git a/api/c/MachO/Symbol.cpp b/api/c/MachO/Symbol.cpp new file mode 100644 index 0000000..68369bb --- /dev/null +++ b/api/c/MachO/Symbol.cpp @@ -0,0 +1,56 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "Symbol.hpp" + +namespace LIEF { +namespace MachO { +void init_c_symbols(Macho_Binary_t* c_binary, Binary* binary) { + it_symbols symbols = binary->symbols(); + + c_binary->symbols = static_cast( + malloc((symbols.size() + 1) * sizeof(Macho_Symbol_t**))); + + for (size_t i = 0; i < symbols.size(); ++i) { + Symbol& symbol = symbols[i]; + + c_binary->symbols[i] = static_cast(malloc(sizeof(Macho_Symbol_t))); + + c_binary->symbols[i]->name = symbol.name().c_str(); + c_binary->symbols[i]->type = symbol.type(); + c_binary->symbols[i]->numberof_sections = symbol.numberof_sections(); + c_binary->symbols[i]->description = symbol.description(); + c_binary->symbols[i]->value = symbol.value(); + } + + c_binary->symbols[symbols.size()] = nullptr; + +} + + + +void destroy_symbols(Macho_Binary_t* c_binary) { + Macho_Symbol_t **symbols = c_binary->symbols; + for (size_t idx = 0; symbols[idx] != nullptr; ++idx) { + free(symbols[idx]); + } + free(c_binary->symbols); + +} + +} +} + + diff --git a/api/c/MachO/Symbol.hpp b/api/c/MachO/Symbol.hpp new file mode 100644 index 0000000..183f429 --- /dev/null +++ b/api/c/MachO/Symbol.hpp @@ -0,0 +1,34 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_MACHO_SYMBOL_CPP_C_API_ +#define LIEF_MACHO_SYMBOL_CPP_C_API_ + +#include "LIEF/MachO/Binary.h" +#include "LIEF/MachO/Binary.hpp" + +#include "LIEF/MachO/Symbol.h" +#include "LIEF/MachO/Symbol.hpp" + +namespace LIEF { +namespace MachO { + +void init_c_symbols(Macho_Binary_t* c_binary, Binary* binary); +void destroy_symbols(Macho_Binary_t* c_binary); + +} +} + +#endif diff --git a/api/c/PE/Binary.cpp b/api/c/PE/Binary.cpp new file mode 100644 index 0000000..d10410c --- /dev/null +++ b/api/c/PE/Binary.cpp @@ -0,0 +1,64 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 + +#include "LIEF/PE/Binary.h" + +#include "LIEF/PE/Parser.hpp" +#include "LIEF/PE/Binary.hpp" + +#include "Binary.hpp" +#include "DosHeader.hpp" +#include "Header.hpp" +#include "OptionalHeader.hpp" +#include "Section.hpp" +#include "DataDirectory.hpp" + +using namespace LIEF::PE; + +namespace LIEF { +namespace PE { + +void init_c_binary(Pe_Binary_t* c_binary, Binary* binary) { + c_binary->name = binary->name().c_str(); + c_binary->handler = reinterpret_cast(binary); + + init_c_dos_header(c_binary, binary); + init_c_header(c_binary, binary); + init_c_optional_header(c_binary, binary); + init_c_sections(c_binary, binary); + init_c_data_directories(c_binary, binary); + +} + +} +} + +Pe_Binary_t* pe_parse(const char *file) { + Binary* binary = Parser::parse(file); + Pe_Binary_t* c_binary = static_cast(malloc(sizeof(Pe_Binary_t))); + std::memset(c_binary, 0, sizeof(Pe_Binary_t)); + init_c_binary(c_binary, binary); + + return c_binary; +} + +void pe_binary_destroy(Pe_Binary_t* binary) { + destroy_sections(binary); + destroy_data_directories(binary); + delete reinterpret_cast(binary->handler); + free(binary); +} diff --git a/api/c/PE/Binary.hpp b/api/c/PE/Binary.hpp new file mode 100644 index 0000000..26510ca --- /dev/null +++ b/api/c/PE/Binary.hpp @@ -0,0 +1,30 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_PE_BINARY_CPP_C_API_ +#define LIEF_PE_BINARY_CPP_C_API_ + +#include "LIEF/PE/Binary.h" +#include "LIEF/PE/Binary.hpp" + +namespace LIEF { +namespace PE { + +void init_c_binary(Pe_Binary_t* c_binary, Binary* binary); + +} +} + +#endif diff --git a/api/c/PE/DataDirectory.cpp b/api/c/PE/DataDirectory.cpp new file mode 100644 index 0000000..57d5286 --- /dev/null +++ b/api/c/PE/DataDirectory.cpp @@ -0,0 +1,54 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "DataDirectory.hpp" + +namespace LIEF { +namespace PE { +void init_c_data_directories(Pe_Binary_t* c_binary, Binary* binary) { + + it_data_directories data_directories = binary->data_directories(); + + c_binary->data_directories = static_cast( + malloc((data_directories.size() + 1) * sizeof(Pe_DataDirectory_t**))); + + for (size_t i = 0; i < data_directories.size(); ++i) { + + c_binary->data_directories[i] = static_cast(malloc(sizeof(Pe_DataDirectory_t))); + c_binary->data_directories[i]->rva = data_directories[i].RVA(); + c_binary->data_directories[i]->size = data_directories[i].size(); + } + c_binary->data_directories[data_directories.size()] = nullptr; + + + +} + + + +void destroy_data_directories(Pe_Binary_t* c_binary) { + + Pe_DataDirectory_t **data_directories = c_binary->data_directories; + for (size_t idx = 0; data_directories[idx] != nullptr; ++idx) { + free(data_directories[idx]); + } + free(c_binary->data_directories); + +} + +} +} + + diff --git a/api/c/PE/DataDirectory.hpp b/api/c/PE/DataDirectory.hpp new file mode 100644 index 0000000..9e9ea5a --- /dev/null +++ b/api/c/PE/DataDirectory.hpp @@ -0,0 +1,34 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_PE_DATA_DIRECTORY_CPP_C_API_ +#define LIEF_PE_DATA_DIRECTORY_CPP_C_API_ + +#include "LIEF/PE/Binary.h" +#include "LIEF/PE/Binary.hpp" + +#include "LIEF/PE/DataDirectory.h" +#include "LIEF/PE/DataDirectory.hpp" + +namespace LIEF { +namespace PE { + +void init_c_data_directories(Pe_Binary_t* c_binary, Binary* binary); +void destroy_data_directories(Pe_Binary_t* c_binary); + +} +} + +#endif diff --git a/api/c/PE/DosHeader.cpp b/api/c/PE/DosHeader.cpp new file mode 100644 index 0000000..bca64d6 --- /dev/null +++ b/api/c/PE/DosHeader.cpp @@ -0,0 +1,55 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "DosHeader.hpp" + +namespace LIEF { +namespace PE { +void init_c_dos_header(Pe_Binary_t* c_binary, Binary* binary) { + const DosHeader& dos_header = binary->dos_header(); + c_binary->dos_header.magic = dos_header.magic(); + c_binary->dos_header.used_bytes_in_the_last_page = dos_header.used_bytes_in_the_last_page(); + c_binary->dos_header.file_size_in_pages = dos_header.file_size_in_pages(); + c_binary->dos_header.numberof_relocation = dos_header.numberof_relocation(); + c_binary->dos_header.header_size_in_paragraphs = dos_header.header_size_in_paragraphs(); + c_binary->dos_header.minimum_extra_paragraphs = dos_header.minimum_extra_paragraphs(); + c_binary->dos_header.maximum_extra_paragraphs = dos_header.maximum_extra_paragraphs(); + c_binary->dos_header.initial_relative_ss = dos_header.initial_relative_ss(); + c_binary->dos_header.initial_sp = dos_header.initial_sp(); + c_binary->dos_header.checksum = dos_header.checksum(); + c_binary->dos_header.initial_ip = dos_header.initial_ip(); + c_binary->dos_header.initial_relative_cs = dos_header.initial_relative_cs(); + c_binary->dos_header.addressof_relocation_table = dos_header.addressof_relocation_table(); + c_binary->dos_header.overlay_number = dos_header.overlay_number(); + c_binary->dos_header.oem_id = dos_header.oem_id(); + c_binary->dos_header.oem_info = dos_header.oem_info(); + c_binary->dos_header.addressof_new_exeheader = dos_header.addressof_new_exeheader(); + + const DosHeader::reserved_t& reserved = dos_header.reserved(); + std::copy( + std::begin(reserved), + std::end(reserved), + c_binary->dos_header.reserved); + + + const DosHeader::reserved2_t& reserved2 = dos_header.reserved2(); + std::copy( + std::begin(reserved2), + std::end(reserved2), + c_binary->dos_header.reserved2); +} + +} +} diff --git a/api/c/PE/DosHeader.hpp b/api/c/PE/DosHeader.hpp new file mode 100644 index 0000000..f3f2ec3 --- /dev/null +++ b/api/c/PE/DosHeader.hpp @@ -0,0 +1,33 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_PE_DOS_HEADER_CPP_C_API_ +#define LIEF_PE_DOS_HEADER_CPP_C_API_ + +#include "LIEF/PE/Binary.h" +#include "LIEF/PE/Binary.hpp" + +#include "LIEF/PE/DosHeader.h" +#include "LIEF/PE/DosHeader.hpp" + +namespace LIEF { +namespace PE { + +void init_c_dos_header(Pe_Binary_t* c_binary, Binary* binary); + +} +} + +#endif diff --git a/api/c/PE/EnumToString.cpp b/api/c/PE/EnumToString.cpp new file mode 100644 index 0000000..ec7668c --- /dev/null +++ b/api/c/PE/EnumToString.cpp @@ -0,0 +1,40 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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/PE/EnumToString.h" +#include "LIEF/PE/EnumToString.hpp" + +#include "LIEF/PE/enums.hpp" +#include "LIEF/PE/enums.h" + + +extern "C" +{ + +const char* PE_TYPES_to_string(enum PE_TYPES e) { + return LIEF::PE::to_string(static_cast(e)); +} + + +const char* MACHINE_TYPES_to_string(enum MACHINE_TYPES e) { + return LIEF::PE::to_string(static_cast(e)); +} + + +const char* SUBSYSTEM_to_string(enum SUBSYSTEM e) { + return LIEF::PE::to_string(static_cast(e)); +} + +} diff --git a/api/c/PE/Header.cpp b/api/c/PE/Header.cpp new file mode 100644 index 0000000..6f9ff2f --- /dev/null +++ b/api/c/PE/Header.cpp @@ -0,0 +1,42 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "Header.hpp" + +namespace LIEF { +namespace PE { + +void init_c_header(Pe_Binary_t* c_binary, Binary* binary) { + + const Header& header = binary->header(); + + const Header::signature_t& signature = header.signature(); + + c_binary->header.machine = static_cast(header.machine()); + c_binary->header.numberof_sections = header.numberof_sections(); + c_binary->header.time_date_stamp = header.time_date_stamp(); + c_binary->header.pointerto_symbol_table = header.pointerto_symbol_table(); + c_binary->header.numberof_symbols = header.numberof_symbols(); + c_binary->header.sizeof_optional_header = header.sizeof_optional_header(); + c_binary->header.characteristics = header.characteristics(); + + std::copy( + std::begin(signature), + std::end(signature), + c_binary->header.signature); +} + +} +} diff --git a/api/c/PE/Header.hpp b/api/c/PE/Header.hpp new file mode 100644 index 0000000..3bfde88 --- /dev/null +++ b/api/c/PE/Header.hpp @@ -0,0 +1,33 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_PE_HEADER_CPP_C_API_ +#define LIEF_PE_HEADER_CPP_C_API_ + +#include "LIEF/PE/Binary.h" +#include "LIEF/PE/Binary.hpp" + +#include "LIEF/PE/Header.h" +#include "LIEF/PE/Header.hpp" + +namespace LIEF { +namespace PE { + +void init_c_header(Pe_Binary_t* c_binary, Binary* binary); + +} +} + +#endif diff --git a/api/c/PE/OptionalHeader.cpp b/api/c/PE/OptionalHeader.cpp new file mode 100644 index 0000000..5c69a5c --- /dev/null +++ b/api/c/PE/OptionalHeader.cpp @@ -0,0 +1,61 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "OptionalHeader.hpp" + +namespace LIEF { +namespace PE { + +void init_c_optional_header(Pe_Binary_t* c_binary, Binary* binary) { + + const OptionalHeader& optional_header = binary->optional_header(); + c_binary->optional_header.magic = static_cast(optional_header.magic()); + c_binary->optional_header.major_linker_version = optional_header.major_linker_version(); + c_binary->optional_header.minor_linker_version = optional_header.minor_linker_version(); + c_binary->optional_header.sizeof_code = optional_header.sizeof_code(); + c_binary->optional_header.sizeof_initialized_data = optional_header.sizeof_initialized_data(); + c_binary->optional_header.sizeof_uninitialized_data = optional_header.sizeof_uninitialized_data(); + c_binary->optional_header.addressof_entrypoint = optional_header.addressof_entrypoint(); + c_binary->optional_header.baseof_code = optional_header.baseof_code(); + if (optional_header.magic() == PE_TYPE::PE32) { + c_binary->optional_header.baseof_data = optional_header.baseof_data(); + } else { + c_binary->optional_header.baseof_data = 0; + } + c_binary->optional_header.imagebase = optional_header.imagebase(); + c_binary->optional_header.section_alignment = optional_header.section_alignment(); + c_binary->optional_header.file_alignment = optional_header.file_alignment(); + c_binary->optional_header.major_operating_system_version = optional_header.major_operating_system_version(); + c_binary->optional_header.minor_operating_system_version = optional_header.minor_operating_system_version(); + c_binary->optional_header.major_image_version = optional_header.major_image_version(); + c_binary->optional_header.minor_image_version = optional_header.minor_image_version(); + c_binary->optional_header.major_subsystem_version = optional_header.major_subsystem_version(); + c_binary->optional_header.minor_subsystem_version = optional_header.minor_subsystem_version(); + c_binary->optional_header.win32_version_value = optional_header.win32_version_value(); + c_binary->optional_header.sizeof_image = optional_header.sizeof_image(); + c_binary->optional_header.sizeof_headers = optional_header.sizeof_headers(); + c_binary->optional_header.checksum = optional_header.checksum(); + c_binary->optional_header.subsystem = static_cast(optional_header.subsystem()); + c_binary->optional_header.dll_characteristics = optional_header.dll_characteristics(); + c_binary->optional_header.sizeof_stack_reserve = optional_header.sizeof_stack_reserve(); + c_binary->optional_header.sizeof_stack_commit = optional_header.sizeof_stack_commit(); + c_binary->optional_header.sizeof_heap_reserve = optional_header.sizeof_heap_reserve(); + c_binary->optional_header.sizeof_heap_commit = optional_header.sizeof_heap_commit(); + c_binary->optional_header.loader_flags = optional_header.loader_flags(); + c_binary->optional_header.numberof_rva_and_size = optional_header.numberof_rva_and_size(); +} + +} +} diff --git a/api/c/PE/OptionalHeader.hpp b/api/c/PE/OptionalHeader.hpp new file mode 100644 index 0000000..c466716 --- /dev/null +++ b/api/c/PE/OptionalHeader.hpp @@ -0,0 +1,33 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_PE_OPTIONAL_HEADER_CPP_C_API_ +#define LIEF_PE_OPTIONAL_HEADER_CPP_C_API_ + +#include "LIEF/PE/Binary.h" +#include "LIEF/PE/Binary.hpp" + +#include "LIEF/PE/OptionalHeader.h" +#include "LIEF/PE/OptionalHeader.hpp" + +namespace LIEF { +namespace PE { + +void init_c_optional_header(Pe_Binary_t* c_binary, Binary* binary); + +} +} + +#endif diff --git a/api/c/PE/Section.cpp b/api/c/PE/Section.cpp new file mode 100644 index 0000000..4b8859f --- /dev/null +++ b/api/c/PE/Section.cpp @@ -0,0 +1,68 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "Section.hpp" + +namespace LIEF { +namespace PE { +void init_c_sections(Pe_Binary_t* c_binary, Binary* binary) { + + it_sections sections = binary->get_sections(); + + c_binary->sections = static_cast( + malloc((sections.size() + 1) * sizeof(Pe_Section_t**))); + + for (size_t i = 0; i < sections.size(); ++i) { + Section& b_section = sections[i]; + c_binary->sections[i] = static_cast(malloc(sizeof(Pe_Section_t))); + const std::vector& section_content = b_section.content(); + uint8_t* content = static_cast(malloc(section_content.size() * sizeof(uint8_t))); + std::copy( + std::begin(section_content), + std::end(section_content), + content); + + c_binary->sections[i]->name = b_section.name().c_str(); + c_binary->sections[i]->virtual_address = b_section.virtual_address(); + c_binary->sections[i]->size = b_section.size(); + c_binary->sections[i]->offset = b_section.offset(); + c_binary->sections[i]->virtual_size = b_section.virtual_size(); + c_binary->sections[i]->pointerto_relocation = b_section.pointerto_relocation(); + c_binary->sections[i]->pointerto_line_numbers = b_section.pointerto_line_numbers(); + c_binary->sections[i]->characteristics = b_section.characteristics(); + c_binary->sections[i]->content = content; + c_binary->sections[i]->entropy = b_section.entropy(); + } + c_binary->sections[sections.size()] = nullptr; + +} + + + +void destroy_sections(Pe_Binary_t* c_binary) { + + Pe_Section_t **sections = c_binary->sections; + for (size_t idx = 0; sections[idx] != nullptr; ++idx) { + free(sections[idx]->content); + free(sections[idx]); + } + free(c_binary->sections); + +} + +} +} + + diff --git a/api/c/PE/Section.hpp b/api/c/PE/Section.hpp new file mode 100644 index 0000000..c662604 --- /dev/null +++ b/api/c/PE/Section.hpp @@ -0,0 +1,34 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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_PE_SECTION_CPP_C_API_ +#define LIEF_PE_SECTION_CPP_C_API_ + +#include "LIEF/PE/Binary.h" +#include "LIEF/PE/Binary.hpp" + +#include "LIEF/PE/Section.h" +#include "LIEF/PE/Section.hpp" + +namespace LIEF { +namespace PE { + +void init_c_sections(Pe_Binary_t* c_binary, Binary* binary); +void destroy_sections(Pe_Binary_t* c_binary); + +} +} + +#endif diff --git a/api/c/include/LIEF/ELF.h b/api/c/include/LIEF/ELF.h new file mode 100644 index 0000000..b259f39 --- /dev/null +++ b/api/c/include/LIEF/ELF.h @@ -0,0 +1,27 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_ELF_H_ +#define C_LIEF_ELF_H_ + +//! @defgroup elf_c_api ELF C API + +#include "LIEF/ELF/Binary.h" +#include "LIEF/ELF/Symbol.h" +#include "LIEF/ELF/Section.h" +#include "LIEF/ELF/Header.h" +#include "LIEF/ELF/DynamicEntry.h" +#include "LIEF/ELF/EnumToString.h" +#endif diff --git a/api/c/include/LIEF/ELF/Binary.h b/api/c/include/LIEF/ELF/Binary.h new file mode 100644 index 0000000..1ef6c7d --- /dev/null +++ b/api/c/include/LIEF/ELF/Binary.h @@ -0,0 +1,79 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_ELF_BINARY_H_ +#define C_LIEF_ELF_BINARY_H_ + +/** @defgroup elf_binary_c_api Binary + * @ingroup elf_c_api + * @addtogroup elf_binary_c_api + * @brief Binary C API + * + * @{ + */ + +#include + +#include "LIEF/visibility.h" + +#include "LIEF/ELF/enums.h" + +#include "LIEF/ELF/Section.h" +#include "LIEF/ELF/Segment.h" +#include "LIEF/ELF/Header.h" +#include "LIEF/ELF/DynamicEntry.h" +#include "LIEF/ELF/Symbol.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief LIEF::ELF::Binary C Handler */ +struct Elf_Binary_t { + void* handler; + const char* name; + const char* interpreter; + enum ELF_CLASS type; + Elf_Header_t header; + Elf_Section_t **sections; + Elf_Segment_t **segments; + Elf_DynamicEntry_t **dynamic_entries; + Elf_Symbol_t **dynamic_symbols; + Elf_Symbol_t **static_symbols; +}; + +typedef struct Elf_Binary_t Elf_Binary_t; + +/** @brief Wrapper for LIEF::ELF::Parser::parse */ +DLL_PUBLIC Elf_Binary_t* elf_parse(const char *file); + +DLL_PUBLIC void elf_binary_destroy(Elf_Binary_t* binary); + +/* ELF::Binary methods + * ================== + */ + +/** @brief Update LIEF::ELF::Header object */ +DLL_PUBLIC int elf_binary_save_header(Elf_Binary_t* binary); + + + +#ifdef __cplusplus +} +#endif + + +/** @} */ +#endif diff --git a/api/c/include/LIEF/ELF/DynamicEntry.h b/api/c/include/LIEF/ELF/DynamicEntry.h new file mode 100644 index 0000000..5512422 --- /dev/null +++ b/api/c/include/LIEF/ELF/DynamicEntry.h @@ -0,0 +1,83 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_ELF_DYNAMIC_ENTRY_H_ +#define C_LIEF_ELF_DYNAMIC_ENTRY_H_ + +#include + +#include "LIEF/ELF/enums.h" + +/** @defgroup elf_dynamic_entry_c_api Dynamic Entry + * @ingroup elf_c_api + * @addtogroup elf_dynamic_entry_c_api + * @brief Dynamic Entry C API + * + * @{ + */ + + +#ifdef __cplusplus +extern "C" { +#endif + +struct Elf_DynamicEntry_t { + enum DYNAMIC_TAGS tag; + uint64_t value; +}; + +struct Elf_DynamicEntry_Library_t { + enum DYNAMIC_TAGS tag; + uint64_t value; + const char* name; +}; + +struct Elf_DynamicEntry_SharedObject_t { + enum DYNAMIC_TAGS tag; + uint64_t value; + const char* name; +}; + +struct Elf_DynamicEntry_Array_t { + enum DYNAMIC_TAGS tag; + uint64_t value; + uint64_t* array; +}; + +struct Elf_DynamicEntry_Rpath_t { + enum DYNAMIC_TAGS tag; + uint64_t value; + const char* rpath; +}; + +struct Elf_DynamicEntry_RunPath_t { + enum DYNAMIC_TAGS tag; + uint64_t value; + const char* runpath; +}; + +typedef struct Elf_DynamicEntry_t Elf_DynamicEntry_t; +typedef struct Elf_DynamicEntry_Library_t Elf_DynamicEntry_Library_t; +typedef struct Elf_DynamicEntry_SharedObject_t Elf_DynamicEntry_SharedObject_t; +typedef struct Elf_DynamicEntry_Array_t Elf_DynamicEntry_Array_t; +typedef struct Elf_DynamicEntry_Rpath_t Elf_DynamicEntry_Rpath_t; +typedef struct Elf_DynamicEntry_RunPath_t Elf_DynamicEntry_RunPath_t; + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/ELF/EnumToString.h b/api/c/include/LIEF/ELF/EnumToString.h new file mode 100644 index 0000000..37f3454 --- /dev/null +++ b/api/c/include/LIEF/ELF/EnumToString.h @@ -0,0 +1,45 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_ELF_ENUM_TO_STRING_H_ +#define C_LIEF_ELF_ENUM_TO_STRING_H_ + +#include "LIEF/visibility.h" + +#include "LIEF/ELF/enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +DLL_PUBLIC const char* SYMBOL_BINDINGS_to_string(enum SYMBOL_BINDINGS e); +DLL_PUBLIC const char* E_TYPE_to_string(enum E_TYPE e); +DLL_PUBLIC const char* VERSION_to_string(enum VERSION e); +DLL_PUBLIC const char* ARCH_to_string(enum ARCH e); +DLL_PUBLIC const char* SEGMENT_TYPES_to_string(enum SEGMENT_TYPES e); +DLL_PUBLIC const char* DYNAMIC_TAGS_to_string(enum DYNAMIC_TAGS e); +DLL_PUBLIC const char* SECTION_TYPES_to_string(enum SECTION_TYPES e); +DLL_PUBLIC const char* SECTION_FLAGS_to_string(enum SECTION_FLAGS e); +DLL_PUBLIC const char* SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e); +DLL_PUBLIC const char* ELF_CLASS_to_string(enum ELF_CLASS e); +DLL_PUBLIC const char* ELF_DATA_to_string(enum ELF_DATA e); +DLL_PUBLIC const char* OS_ABI_to_string(enum OS_ABI e); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/api/c/include/LIEF/ELF/Header.h b/api/c/include/LIEF/ELF/Header.h new file mode 100644 index 0000000..b9abd3e --- /dev/null +++ b/api/c/include/LIEF/ELF/Header.h @@ -0,0 +1,58 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_ELF_HEADER_H_ +#define C_LIEF_ELF_HEADER_H_ +#include + +#include "LIEF/ELF/enums.h" +/** @defgroup elf_header_c_api Header + * @ingroup elf_c_api + * @addtogroup elf_header_c_api + * @brief Header C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Elf_Header_t { + uint8_t identity[EI_NIDENT]; + enum E_TYPE file_type; + enum ARCH machine_type; + enum VERSION object_file_version; + uint64_t entrypoint; + uint64_t program_headers_offset; + uint64_t section_headers_offset; + uint32_t processor_flags; + uint32_t header_size; + uint32_t program_header_size; + uint32_t numberof_segments; + uint32_t sizeof_section_header; + uint32_t numberof_sections; + uint32_t name_string_table_idx; +}; + +typedef struct Elf_Header_t Elf_Header_t; + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/ELF/Section.h b/api/c/include/LIEF/ELF/Section.h new file mode 100644 index 0000000..fe4b7c2 --- /dev/null +++ b/api/c/include/LIEF/ELF/Section.h @@ -0,0 +1,58 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_ELF_SECTION_H_ +#define C_LIEF_ELF_SECTION_H_ + +#include + +#include "LIEF/ELF/enums.h" + +/** @defgroup elf_section_c_api Section + * @ingroup elf_c_api + * @addtogroup elf_section_c_api + * @brief Section C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Elf_Section_t { + const char* name; + uint32_t flags; + enum SECTION_TYPES type; + uint64_t virtual_address; + uint64_t offset; + uint64_t original_size; + uint32_t link; + uint32_t info; + uint64_t alignment; + uint64_t entry_size; + uint64_t size; + uint8_t* content; + double entropy; +}; + +typedef struct Elf_Section_t Elf_Section_t; + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/ELF/Segment.h b/api/c/include/LIEF/ELF/Segment.h new file mode 100644 index 0000000..a07b1b8 --- /dev/null +++ b/api/c/include/LIEF/ELF/Segment.h @@ -0,0 +1,52 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_ELF_SEGMENT_H_ +#define C_LIEF_ELF_SEGMENT_H_ + +#include +#include "LIEF/ELF/enums.h" + +/** @defgroup elf_segment_c_api Segment + * @ingroup elf_c_api + * @addtogroup elf_segment_c_api + * @brief Segment C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Elf_Segment_t { + enum SEGMENT_TYPES type; + uint32_t flags; + uint64_t virtual_address; + uint64_t virtual_size; + uint64_t offset; + uint64_t alignment; + uint64_t size; + uint8_t* content; +}; + +typedef struct Elf_Segment_t Elf_Segment_t; + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/ELF/Symbol.h b/api/c/include/LIEF/ELF/Symbol.h new file mode 100644 index 0000000..2b0c8e9 --- /dev/null +++ b/api/c/include/LIEF/ELF/Symbol.h @@ -0,0 +1,52 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_ELF_SYMBOL_H_ +#define C_LIEF_ELF_SYMBOL_H_ + +#include + +#include "LIEF/ELF/enums.h" +/* @defgroup elf_symbol_c_api Symbol + * @ingroup elf_c_api + * @addtogroup elf_symbol_c_api + * @brief Symbol C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Elf_Symbol_t { + const char* name; + enum SYMBOL_TYPES type; + enum SYMBOL_BINDINGS binding; + uint8_t information; + uint8_t other; + uint16_t shndx; + uint64_t value; + uint64_t size; +}; + +typedef struct Elf_Symbol_t Elf_Symbol_t; + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/ELF/enums.h.in b/api/c/include/LIEF/ELF/enums.h.in new file mode 100644 index 0000000..14777fa --- /dev/null +++ b/api/c/include/LIEF/ELF/enums.h.in @@ -0,0 +1,14 @@ +#ifndef LIEF_ELF_C_ENUMS_H_ +#define LIEF_ELF_C_ENUMS_H_ +#ifdef __cplusplus +extern "C" { +#endif + +@LIEF_ELF_ENUMS@ + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/api/c/include/LIEF/ELF/structures.h.in b/api/c/include/LIEF/ELF/structures.h.in new file mode 100644 index 0000000..82a8fb4 --- /dev/null +++ b/api/c/include/LIEF/ELF/structures.h.in @@ -0,0 +1,14 @@ +#ifndef LIEF_ELF_C_STRUCTURES_H_ +#define LIEF_ELF_C_STRUCTURES_H_ +#ifdef __cplusplus +extern "C" { +#endif + +@LIEF_ELF_STRUCTURES@ + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/api/c/include/LIEF/LIEF.h b/api/c/include/LIEF/LIEF.h new file mode 100644 index 0000000..39a4104 --- /dev/null +++ b/api/c/include/LIEF/LIEF.h @@ -0,0 +1,23 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_H_ +#define C_LIEF_H_ + +#include +#include +#include + +#endif diff --git a/api/c/include/LIEF/MachO.h b/api/c/include/LIEF/MachO.h new file mode 100644 index 0000000..63ab4f7 --- /dev/null +++ b/api/c/include/LIEF/MachO.h @@ -0,0 +1,28 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_MACHO_H_ +#define C_LIEF_MACHO_H_ + +//! @defgroup macho_c_api MachO C API + +#include "LIEF/MachO/Binary.h" +#include "LIEF/MachO/Symbol.h" +#include "LIEF/MachO/Segment.h" +#include "LIEF/MachO/Section.h" +#include "LIEF/MachO/LoadCommand.h" +#include "LIEF/MachO/Header.h" +#include "LIEF/MachO/EnumToString.h" +#endif diff --git a/api/c/include/LIEF/MachO/Binary.h b/api/c/include/LIEF/MachO/Binary.h new file mode 100644 index 0000000..b84d4ad --- /dev/null +++ b/api/c/include/LIEF/MachO/Binary.h @@ -0,0 +1,68 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_MACHO_BINARY_H_ +#define C_LIEF_MACHO_BINARY_H_ + +/** @defgroup macho_binary_c_api Binary + * @ingroup macho_c_api + * @addtogroup macho_binary_c_api + * @brief Binary C API + * + * @{ + */ + +#include + +#include "LIEF/visibility.h" + +#include "LIEF/MachO/Header.h" +#include "LIEF/MachO/LoadCommand.h" +#include "LIEF/MachO/Symbol.h" +#include "LIEF/MachO/Section.h" +#include "LIEF/MachO/Segment.h" +#include "LIEF/MachO/enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief LIEF::MachO::Binary C Handler */ +struct Macho_Binary_t { + void* handler; + const char* name; + uint64_t imagebase; + Macho_Header_t header; + Macho_Command_t** commands; + Macho_Symbol_t** symbols; + Macho_Section_t** sections; + Macho_Segment_t** segments; + +}; + +typedef struct Macho_Binary_t Macho_Binary_t; + +/** @brief Wrapper on LIEF::MachO::Parser::parse */ +DLL_PUBLIC Macho_Binary_t** macho_parse(const char *file); + +DLL_PUBLIC void macho_binaries_destroy(Macho_Binary_t** binaries); + +#ifdef __cplusplus +} +#endif + + +/** @} */ +#endif diff --git a/api/c/include/LIEF/MachO/EnumToString.h b/api/c/include/LIEF/MachO/EnumToString.h new file mode 100644 index 0000000..bf360ed --- /dev/null +++ b/api/c/include/LIEF/MachO/EnumToString.h @@ -0,0 +1,41 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_MACHO_ENUM_TO_STRING_H_ +#define C_LIEF_MACHO_ENUM_TO_STRING_H_ + +#include "LIEF/visibility.h" +#include "LIEF/MachO/enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + +DLL_PUBLIC const char* LOAD_COMMAND_TYPES_to_string(enum LOAD_COMMAND_TYPES e); +DLL_PUBLIC const char* MACHO_TYPES_to_string(enum MACHO_TYPES e); +DLL_PUBLIC const char* FILE_TYPES_to_string(enum FILE_TYPES e); +DLL_PUBLIC const char* CPU_TYPES_to_string(enum CPU_TYPES e); +DLL_PUBLIC const char* HEADER_FLAGS_to_string(enum HEADER_FLAGS e); +DLL_PUBLIC const char* MachO_SECTION_TYPES_to_string(enum SECTION_TYPES e); +DLL_PUBLIC const char* MachO_SYMBOL_TYPES_to_string(enum SYMBOL_TYPES e); +DLL_PUBLIC const char* N_LIST_TYPES_to_string(enum N_LIST_TYPES e); +DLL_PUBLIC const char* SYMBOL_DESCRIPTIONS_to_string(enum SYMBOL_DESCRIPTIONS e); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/api/c/include/LIEF/MachO/Header.h b/api/c/include/LIEF/MachO/Header.h new file mode 100644 index 0000000..31c8160 --- /dev/null +++ b/api/c/include/LIEF/MachO/Header.h @@ -0,0 +1,52 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_MACHO_HEADER_H_ +#define C_LIEF_MACHO_HEADER_H_ +#include + +#include "LIEF/MachO/enums.h" +/** @defgroup macho_header_c_api Header + * @ingroup macho_c_api + * @addtogroup macho_header_c_api + * @brief Header C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Macho_Header_t { + uint32_t magic; + enum CPU_TYPES cpu_type; + uint32_t cpu_subtype; + enum FILE_TYPES file_type; + uint32_t nb_cmds; + uint32_t sizeof_cmds; + uint32_t flags; + uint32_t reserved; +}; + +typedef struct Macho_Header_t Macho_Header_t; + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/MachO/LoadCommand.h b/api/c/include/LIEF/MachO/LoadCommand.h new file mode 100644 index 0000000..d88b126 --- /dev/null +++ b/api/c/include/LIEF/MachO/LoadCommand.h @@ -0,0 +1,48 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_MACHO_LOAD_COMMAND_H_ +#define C_LIEF_MACHO_LOAD_COMMAND_H_ +#include + +#include "LIEF/MachO/enums.h" +/** @defgroup macho_load_command_c_api Header + * @ingroup macho_c_api + * @addtogroup macho_load_command_c_api + * @brief Load Command C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Macho_Command_t { + enum LOAD_COMMAND_TYPES command; + uint32_t size; + uint8_t* data; + uint32_t offset; +}; + +typedef struct Macho_Command_t Macho_Command_t; + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/MachO/Section.h b/api/c/include/LIEF/MachO/Section.h new file mode 100644 index 0000000..3eba29e --- /dev/null +++ b/api/c/include/LIEF/MachO/Section.h @@ -0,0 +1,59 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_MACHO_SECTION_H_ +#define C_LIEF_MACHO_SECTION_H_ +#include + +#include "LIEF/MachO/enums.h" +/** @defgroup macho_section_c_api Header + * @ingroup macho_c_api + * @addtogroup macho_section_c_api + * @brief Section C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Macho_Section_t { + + const char* name; + uint32_t alignment; + uint32_t relocation_offset; + uint32_t numberof_relocations; + uint32_t flags; + enum SECTION_TYPES type; + uint32_t reserved1; + uint32_t reserved2; + uint32_t reserved3; + uint64_t virtual_address; + uint64_t offset; + uint64_t size; + uint8_t* content; + double entropy; +}; + +typedef struct Macho_Section_t Macho_Section_t; + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/MachO/Segment.h b/api/c/include/LIEF/MachO/Segment.h new file mode 100644 index 0000000..b263940 --- /dev/null +++ b/api/c/include/LIEF/MachO/Segment.h @@ -0,0 +1,55 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_MACHO_SEGMENT_H_ +#define C_LIEF_MACHO_SEGMENT_H_ +#include + +#include "LIEF/MachO/enums.h" +/** @defgroup macho_segment_c_api Header + * @ingroup macho_c_api + * @addtogroup macho_segment_c_api + * @brief Segment C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Macho_Segment_t { + const char* name; + uint64_t virtual_address; + uint64_t virtual_size; + uint64_t file_size; + uint64_t file_offset; + uint32_t max_protection; + uint32_t init_protection; + uint32_t numberof_sections; + uint32_t flags; + uint8_t* content; + Macho_Section_t** sections; +}; + +typedef struct Macho_Segment_t Macho_Segment_t; + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/MachO/Symbol.h b/api/c/include/LIEF/MachO/Symbol.h new file mode 100644 index 0000000..ff0181b --- /dev/null +++ b/api/c/include/LIEF/MachO/Symbol.h @@ -0,0 +1,49 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_MACHO_SYMBOL_H_ +#define C_LIEF_MACHO_SYMBOL_H_ +#include + +#include "LIEF/MachO/enums.h" +/** @defgroup macho_symbol_c_api Header + * @ingroup macho_c_api + * @addtogroup macho_symbol_c_api + * @brief Symbol C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Macho_Symbol_t { + const char* name; + uint8_t type; + uint8_t numberof_sections; + uint16_t description; + uint64_t value; +}; + +typedef struct Macho_Symbol_t Macho_Symbol_t; + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/MachO/enums.h.in b/api/c/include/LIEF/MachO/enums.h.in new file mode 100644 index 0000000..33f1617 --- /dev/null +++ b/api/c/include/LIEF/MachO/enums.h.in @@ -0,0 +1,14 @@ +#ifndef LIEF_MACHO_C_ENUMS_H_ +#define LIEF_MACHO_C_ENUMS_H_ +#ifdef __cplusplus +extern "C" { +#endif + +@LIEF_MACHO_ENUMS@ + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/api/c/include/LIEF/MachO/structures.h.in b/api/c/include/LIEF/MachO/structures.h.in new file mode 100644 index 0000000..7dc4475 --- /dev/null +++ b/api/c/include/LIEF/MachO/structures.h.in @@ -0,0 +1,14 @@ +#ifndef LIEF_MACHO_C_STRUCTURES_H_ +#define LIEF_MACHO_C_STRUCTURES_H_ +#ifdef __cplusplus +extern "C" { +#endif + +@LIEF_MACHO_STRUCTURES@ + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/api/c/include/LIEF/PE.h b/api/c/include/LIEF/PE.h new file mode 100644 index 0000000..7ca1528 --- /dev/null +++ b/api/c/include/LIEF/PE.h @@ -0,0 +1,23 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_PE_H_ +#define C_LIEF_PE_H_ + +//! @defgroup pe_c_api PE C API + +#include "LIEF/PE/Binary.h" +#include "LIEF/PE/EnumToString.h" +#endif diff --git a/api/c/include/LIEF/PE/Binary.h b/api/c/include/LIEF/PE/Binary.h new file mode 100644 index 0000000..007f621 --- /dev/null +++ b/api/c/include/LIEF/PE/Binary.h @@ -0,0 +1,67 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_PE_BINARY_H_ +#define C_LIEF_PE_BINARY_H_ + +/** @defgroup pe_binary_c_api Binary + * @ingroup pe_c_api + * @addtogroup pe_binary_c_api + * @brief Binary C API + * + * @{ + */ + +#include + +#include "LIEF/visibility.h" + +#include "LIEF/PE/enums.h" + +#include "LIEF/PE/DosHeader.h" +#include "LIEF/PE/Header.h" +#include "LIEF/PE/OptionalHeader.h" +#include "LIEF/PE/DataDirectory.h" +#include "LIEF/PE/Section.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** @brief LIEF::PE::Binary C Handler */ +struct Pe_Binary_t { + void* handler; + const char* name; + Pe_DosHeader_t dos_header; + Pe_Header_t header; + Pe_OptionalHeader_t optional_header; + Pe_DataDirectory_t** data_directories; + Pe_Section_t** sections; +}; + +typedef struct Pe_Binary_t Pe_Binary_t; + +/** @brief Wrapper on LIEF::PE::Parser::parse */ +DLL_PUBLIC Pe_Binary_t* pe_parse(const char *file); + +DLL_PUBLIC void pe_binary_destroy(Pe_Binary_t* binary); + +#ifdef __cplusplus +} +#endif + + +/** @} */ +#endif diff --git a/api/c/include/LIEF/PE/DataDirectory.h b/api/c/include/LIEF/PE/DataDirectory.h new file mode 100644 index 0000000..dc99864 --- /dev/null +++ b/api/c/include/LIEF/PE/DataDirectory.h @@ -0,0 +1,47 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_PE_DATA_DIRECTORY_H_ +#define C_LIEF_PE_DATA_DIRECTORY_H_ + +#include + +#include "LIEF/PE/enums.h" +/** @defgroup pe_data_directory_c_api Section + * @ingroup pe_c_api + * @addtogroup pe_data_directory_c_api + * @brief Data directory C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Pe_DataDirectory_t { + uint32_t rva; + uint32_t size; +}; + +typedef struct Pe_DataDirectory_t Pe_DataDirectory_t; + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/PE/DosHeader.h b/api/c/include/LIEF/PE/DosHeader.h new file mode 100644 index 0000000..1b1e5bd --- /dev/null +++ b/api/c/include/LIEF/PE/DosHeader.h @@ -0,0 +1,63 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_PE_DOS_HEADER_H_ +#define C_LIEF_PE_DOS_HEADER_H_ +#include + +#include "LIEF/ELF/enums.h" +/** @defgroup pe_dos_header_c_api DosHeader + * @ingroup pe_c_api + * @addtogroup pe_dos_header_c_api + * @brief Dos Header C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Pe_DosHeader_t { + uint16_t magic ; + uint16_t used_bytes_in_the_last_page; + uint16_t file_size_in_pages; + uint16_t numberof_relocation; + uint16_t header_size_in_paragraphs; + uint16_t minimum_extra_paragraphs; + uint16_t maximum_extra_paragraphs; + uint16_t initial_relative_ss; + uint16_t initial_sp; + uint16_t checksum; + uint16_t initial_ip; + uint16_t initial_relative_cs; + uint16_t addressof_relocation_table; + uint16_t overlay_number; + uint16_t reserved[4]; + uint16_t oem_id; + uint16_t oem_info; + uint16_t reserved2[10]; + uint32_t addressof_new_exeheader; +}; + +typedef struct Pe_DosHeader_t Pe_DosHeader_t; + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/PE/EnumToString.h b/api/c/include/LIEF/PE/EnumToString.h new file mode 100644 index 0000000..8e79ea2 --- /dev/null +++ b/api/c/include/LIEF/PE/EnumToString.h @@ -0,0 +1,37 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_PE_ENUM_TO_STRING_H_ +#define C_LIEF_PE_ENUM_TO_STRING_H_ + +#include "LIEF/visibility.h" + +#include "LIEF/PE/enums.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +DLL_PUBLIC const char* PE_TYPES_to_string(enum PE_TYPES e); +DLL_PUBLIC const char* MACHINE_TYPES_to_string(enum MACHINE_TYPES e); +DLL_PUBLIC const char* SUBSYSTEM_to_string(enum SUBSYSTEM e); + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/api/c/include/LIEF/PE/Header.h b/api/c/include/LIEF/PE/Header.h new file mode 100644 index 0000000..a71208f --- /dev/null +++ b/api/c/include/LIEF/PE/Header.h @@ -0,0 +1,53 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_PE_HEADER_H_ +#define C_LIEF_PE_HEADER_H_ + +#include + +#include "LIEF/PE/enums.h" +/** @defgroup pe_header_c_api Header + * @ingroup pe_c_api + * @addtogroup pe_header_c_api + * @brief Header C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Pe_Header_t { + uint8_t signature[4]; + enum MACHINE_TYPES machine; + uint16_t numberof_sections; + uint32_t time_date_stamp; + uint32_t pointerto_symbol_table; + uint32_t numberof_symbols; + uint16_t sizeof_optional_header; + uint16_t characteristics; +}; + +typedef struct Pe_Header_t Pe_Header_t; + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/PE/OptionalHeader.h b/api/c/include/LIEF/PE/OptionalHeader.h new file mode 100644 index 0000000..9b5c593 --- /dev/null +++ b/api/c/include/LIEF/PE/OptionalHeader.h @@ -0,0 +1,74 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_PE_OPTIONAL_HEADER_H_ +#define C_LIEF_PE_OPTIONAL_HEADER_H_ +#include + +#include "LIEF/PE/enums.h" +/** @defgroup pe_optional_header_c_api OptionalHeader + * @ingroup pe_c_api + * @addtogroup pe_optional_header_c_api + * @brief OptionalHeader C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Pe_OptionalHeader_t { + enum PE_TYPES magic; + uint8_t major_linker_version; + uint8_t minor_linker_version; + uint32_t sizeof_code; + uint32_t sizeof_initialized_data; + uint32_t sizeof_uninitialized_data; + uint32_t addressof_entrypoint; + uint32_t baseof_code; + uint32_t baseof_data; + uint64_t imagebase; + uint32_t section_alignment; + uint32_t file_alignment; + uint16_t major_operating_system_version; + uint16_t minor_operating_system_version; + uint16_t major_image_version; + uint16_t minor_image_version; + uint16_t major_subsystem_version; + uint16_t minor_subsystem_version; + uint32_t win32_version_value; + uint32_t sizeof_image; + uint32_t sizeof_headers; + uint32_t checksum; + enum SUBSYSTEM subsystem; + uint32_t dll_characteristics; + uint64_t sizeof_stack_reserve; + uint64_t sizeof_stack_commit; + uint64_t sizeof_heap_reserve; + uint64_t sizeof_heap_commit; + uint32_t loader_flags; + uint32_t numberof_rva_and_size; +}; + +typedef struct Pe_OptionalHeader_t Pe_OptionalHeader_t; + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/PE/Section.h b/api/c/include/LIEF/PE/Section.h new file mode 100644 index 0000000..b63df5e --- /dev/null +++ b/api/c/include/LIEF/PE/Section.h @@ -0,0 +1,58 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 C_LIEF_PE_SECTION_H_ +#define C_LIEF_PE_SECTION_H_ + +#include + +#include "LIEF/PE/enums.h" +/** @defgroup pe_section_c_api Section + * @ingroup pe_c_api + * @addtogroup pe_section_c_api + * @brief Section C API + * + * @{ + */ + +#ifdef __cplusplus +extern "C" { +#endif + +struct Pe_Section_t { + const char* name; + uint64_t virtual_address; + uint64_t size; + uint64_t offset; + + uint32_t virtual_size; + uint32_t pointerto_relocation; + uint32_t pointerto_line_numbers; + uint32_t characteristics; + + uint8_t* content; + double entropy; + +}; + +typedef struct Pe_Section_t Pe_Section_t; + + +#ifdef __cplusplus +} +#endif + +/** @} */ +#endif diff --git a/api/c/include/LIEF/PE/enums.h.in b/api/c/include/LIEF/PE/enums.h.in new file mode 100644 index 0000000..8e5d76d --- /dev/null +++ b/api/c/include/LIEF/PE/enums.h.in @@ -0,0 +1,20 @@ +#ifndef LIEF_PE_C_ENUMS_H_ +#define LIEF_PE_C_ENUMS_H_ +#ifdef __cplusplus +extern "C" { +#endif + +@LIEF_PE_ENUMS@ + + +enum PE_TYPES { + PE32 = 0x10b, /** 32bits */ + PE32_PLUS = 0x20b /** 64 bits */ +}; + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/api/c/include/LIEF/PE/structures.h.in b/api/c/include/LIEF/PE/structures.h.in new file mode 100644 index 0000000..893a65d --- /dev/null +++ b/api/c/include/LIEF/PE/structures.h.in @@ -0,0 +1,14 @@ +#ifndef LIEF_PE_C_STRUCTURES_H_ +#define LIEF_PE_C_STRUCTURES_H_ +#ifdef __cplusplus +extern "C" { +#endif + +@LIEF_PE_STRUCTURES@ + +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/api/python/Abstract/init.cpp b/api/python/Abstract/init.cpp new file mode 100644 index 0000000..99d81e2 --- /dev/null +++ b/api/python/Abstract/init.cpp @@ -0,0 +1,26 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyLIEF.hpp" +#include "init.hpp" + +void init_LIEF_module(py::module& m) { + init_LIEF_Enum(m); + init_LIEF_Header_class(m); + init_LIEF_Binary_class(m); + init_LIEF_Section_class(m); + init_LIEF_Symbol_class(m); + init_LIEF_Parser_class(m); +} diff --git a/api/python/Abstract/init.hpp b/api/python/Abstract/init.hpp new file mode 100644 index 0000000..0a029eb --- /dev/null +++ b/api/python/Abstract/init.hpp @@ -0,0 +1,28 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 PY_LIEF_INIT_H_ +#define PY_LIEF_INIT_H_ + +#include "pyLIEF.hpp" + +void init_LIEF_Enum(py::module&); +void init_LIEF_Header_class(py::module&); +void init_LIEF_Binary_class(py::module&); +void init_LIEF_Section_class(py::module&); +void init_LIEF_Symbol_class(py::module&); +void init_LIEF_Parser_class(py::module&); + +#endif diff --git a/api/python/Abstract/objects/pyBinary.cpp b/api/python/Abstract/objects/pyBinary.cpp new file mode 100644 index 0000000..144fa9a --- /dev/null +++ b/api/python/Abstract/objects/pyBinary.cpp @@ -0,0 +1,102 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "init.hpp" +#include "LIEF/Abstract/Binary.hpp" +#include "LIEF/ELF/Binary.hpp" + +#include + +using namespace LIEF; + +template +using getter_t = T (Binary::*)(void) const; + +template +using setter_t = void (Binary::*)(T); + +template +using it_t = T (Binary::*)(void); + +void init_LIEF_Binary_class(py::module& m) { + py::class_(m, "Binary") + .def_property("name", + static_cast>(&Binary::name), + static_cast>(&Binary::name), + "Binary's name") + + .def_property_readonly("header", + &Binary::get_header, + "Binary's header") + + .def_property_readonly("entrypoint", + &Binary::entrypoint, + "Binary's entrypoint") + + .def_property_readonly("sections", + static_cast>(&Binary::get_sections), + "Return a list in **read only** of binary's abstract " RST_CLASS_REF(lief.Section) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("exported_functions", + &Binary::get_exported_functions, + "Return binary's exported functions (name)") + + .def_property_readonly("imported_functions", + &Binary::get_imported_functions, + "Return binary's imported functions (name)") + + .def_property_readonly("libraries", + &Binary::get_imported_libraries, + "Return binary's imported libraries (name)") + + .def_property_readonly("symbols", + static_cast>(&Binary::get_symbols), + "Return a list in **read only** of binary's abstract " RST_CLASS_REF(lief.Symbol) "", + py::return_value_policy::reference_internal) + + .def("get_function_address", + &Binary::get_function_address, + "Return the address of the given function name") + + .def("patch_address", + static_cast&)>(&Binary::patch_address), + "Patch the address with the given value", + py::arg("address"), py::arg("patch_value")) + + .def("patch_address", + static_cast(&Binary::patch_address), + "Patch the address with the given value", + py::arg("address"), py::arg("patch_value"), py::arg_v("size", 8)) + + + .def("get_content_from_virtual_address", + &Binary::get_content_from_virtual_address, + "Return the content located at virtual address") + + + .def("__str__", + [] (const Binary& binary) + { + std::ostringstream stream; + stream << binary; + std::string str = stream.str(); + return str; + }); + +} + + + diff --git a/api/python/Abstract/objects/pyHeader.cpp b/api/python/Abstract/objects/pyHeader.cpp new file mode 100644 index 0000000..6ad0eb5 --- /dev/null +++ b/api/python/Abstract/objects/pyHeader.cpp @@ -0,0 +1,51 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 + +#include "init.hpp" +#include "LIEF/Abstract/Header.hpp" + +template +using getter_t = T (LIEF::Header::*)(void) const; + +template +using setter_t = void (LIEF::Header::*)(T); + +void init_LIEF_Header_class(py::module& m) { + py::class_(m, "Header") + .def(py::init()) + + .def_property("architecture", + static_cast>(&LIEF::Header::architecture), + static_cast>(&LIEF::Header::architecture), + "Target's architecture") + + + .def_property("entrypoint", + static_cast>(&LIEF::Header::entrypoint), + static_cast>(&LIEF::Header::entrypoint), + "Binary's entrypoint") + + + .def("__str__", + [] (const LIEF::Header& header) + { + std::ostringstream stream; + stream << header; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/Abstract/objects/pyParser.cpp b/api/python/Abstract/objects/pyParser.cpp new file mode 100644 index 0000000..e3b4bd8 --- /dev/null +++ b/api/python/Abstract/objects/pyParser.cpp @@ -0,0 +1,28 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "init.hpp" + +#include "LIEF/Abstract/Parser.hpp" + +#include + +void init_LIEF_Parser_class(py::module& m) { + + m.def("parse", + &LIEF::Parser::parse, + "Parse the given binary and return a " RST_CLASS_REF(lief.Binary) " object", + py::return_value_policy::take_ownership); +} diff --git a/api/python/Abstract/objects/pySection.cpp b/api/python/Abstract/objects/pySection.cpp new file mode 100644 index 0000000..acc0a1c --- /dev/null +++ b/api/python/Abstract/objects/pySection.cpp @@ -0,0 +1,57 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "init.hpp" +#include "LIEF/Abstract/Section.hpp" + +template +using getter_t = T (LIEF::Section::*)(void) const; + +template +using setter_t = void (LIEF::Section::*)(T); + +void init_LIEF_Section_class(py::module& m) { + py::class_(m, "Section") + .def(py::init()) + + .def_property("name", + static_cast>(&LIEF::Section::name), + static_cast>(&LIEF::Section::name), + "Section's name") + + .def_property("size", + static_cast>(&LIEF::Section::size), + static_cast>(&LIEF::Section::size), + "Section's size") + + .def_property("offset", + static_cast>(&LIEF::Section::offset), + static_cast>(&LIEF::Section::offset), + "Section's offset") + + .def_property("virtual_address", + static_cast>(&LIEF::Section::virtual_address), + static_cast>(&LIEF::Section::virtual_address), + "Section's size") + + .def_property("content", + static_cast>>(&LIEF::Section::content), + static_cast&>>(&LIEF::Section::content), + "section's content") + + .def_property_readonly("entropy", + &LIEF::Section::entropy, + "Section's entropy"); +} diff --git a/api/python/Abstract/objects/pySymbol.cpp b/api/python/Abstract/objects/pySymbol.cpp new file mode 100644 index 0000000..b173722 --- /dev/null +++ b/api/python/Abstract/objects/pySymbol.cpp @@ -0,0 +1,61 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "init.hpp" +#include "LIEF/Abstract/Symbol.hpp" + +#include +#include + +template +using getter_t = const T& (LIEF::Symbol::*)(void) const; + +template +using setter_t = void (LIEF::Symbol::*)(const T&); + + +class PySymbol : public LIEF::Symbol { + public: + using LIEF::Symbol::Symbol; + + virtual const std::string& name(void) const override { + PYBIND11_OVERLOAD(const std::string&, LIEF::Symbol, name,); + }; + + virtual void name(const std::string& name) override { + PYBIND11_OVERLOAD(void, LIEF::Symbol, name, name); + }; +}; + + +void init_LIEF_Symbol_class(py::module& m) { + + py::class_(m, "Symbol") + .def(py::init()) + + .def_property("name", + static_cast>(&LIEF::Symbol::name), + static_cast>(&LIEF::Symbol::name), + "Symbol's name") + + .def("__str__", + [] (const LIEF::Symbol& symbol) + { + std::ostringstream stream; + stream << symbol; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/Abstract/pyEnums.cpp b/api/python/Abstract/pyEnums.cpp new file mode 100644 index 0000000..da41456 --- /dev/null +++ b/api/python/Abstract/pyEnums.cpp @@ -0,0 +1,28 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "init.hpp" +#include "LIEF/Abstract/enums.hpp" +#include "LIEF/Abstract/EnumToString.hpp" + +#define PY_ENUM(x) LIEF::to_string(x), x + +void init_LIEF_Enum(py::module& m) { + py::enum_(m, "FILE_FORMATS") + .value(PY_ENUM(LIEF::FILE_FORMATS::FORMAT_ELF)) + .value(PY_ENUM(LIEF::FILE_FORMATS::FORMAT_PE)) + .value(PY_ENUM(LIEF::FILE_FORMATS::FORMAT_MACHO)) + .export_values(); +} diff --git a/api/python/CMakeLists.txt b/api/python/CMakeLists.txt new file mode 100644 index 0000000..d07d2ba --- /dev/null +++ b/api/python/CMakeLists.txt @@ -0,0 +1,164 @@ +cmake_minimum_required(VERSION 3.1) +include(ExternalProject) + + +set(Python_ADDITIONAL_VERSIONS 2.7 2.7.6 3.4 3.5 3.6 3.7) +if (NOT ${PYTHON_VERSION} STREQUAL "") + find_package(PythonLibs ${PYTHON_VERSION} EXACT) + + if (NOT PythonLibs_FOUND) + find_package(PythonLibs ${PYTHON_VERSION}) + endif() + + set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}") + if (NOT PythonLibs_FOUND) + # WARNING: DIRTY HACK + # ^^^^^^^^^^^^^^^^^^^ + if ((${PYTHON_VERSION} VERSION_GREATER "3") OR (${PYTHON_VERSION} VERSION_EQUAL "3")) + if (UNIX) + set(PYTHON_LIBRARY /usr/lib/libpython${PYTHON_VERSION}.so) + if(EXISTS "/usr/include/python${PYTHON_VERSION}" AND IS_DIRECTORY "/usr/include/python${PYTHON_VERSION}") + set(PYTHON_INCLUDE_DIR /usr/include/python${PYTHON_VERSION}) + set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}") + elseif(EXISTS "/usr/include/python${PYTHON_VERSION}m" AND IS_DIRECTORY "/usr/include/python${PYTHON_VERSION}m") + set(PYTHON_INCLUDE_DIR /usr/include/python${PYTHON_VERSION}m) + set(PYTHONLIBS_VERSION_STRING "${PYTHON_VERSION}m") + endif() + endif() + endif() + endif() +else() + find_package(PythonLibs REQUIRED) +endif() + + +message(STATUS "Python version: ${PYTHONLIBS_VERSION_STRING}") +message(STATUS "Python lib: ${PYTHON_LIBRARY}") +message(STATUS "Python include: ${PYTHON_INCLUDE_DIR}") + + +set(PYBIND11_GIT_URL "https://github.com/pybind/pybind11.git" CACHE STRING "URL to the Pybind11 repo") +ExternalProject_Add(pybind11 + GIT_REPOSITORY ${PYBIND11_GIT_URL} + GIT_TAG v2.0.1 + CONFIGURE_COMMAND "" + BUILD_COMMAND "" + INSTALL_COMMAND "") +ExternalProject_get_property(pybind11 SOURCE_DIR) +set(PYBIND11_SOURCE_DIR ${SOURCE_DIR}) + + +# Define source files +set(LIEF_PYTHON_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/pyLIEF.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/pyUtils.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/pyJson.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/pyIterators.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/pyExceptions.cpp + + ${CMAKE_CURRENT_SOURCE_DIR}/Abstract/init.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects + ${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyBinary.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyHeader.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pySection.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pyParser.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Abstract/objects/pySymbol.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/Abstract/pyEnums.cpp +) + + +add_library(pyLIEF SHARED ${LIEF_PYTHON_SRC}) + + +target_include_directories(pyLIEF PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR}/ + ${CMAKE_CURRENT_SOURCE_DIR}/Abstract + ${PYTHON_INCLUDE_DIR} + ${PYBIND11_SOURCE_DIR}/include) + +add_definitions(-DELPP_NO_DEFAULT_LOG_FILE) + +if(LIEF_ELF) + include(${CMAKE_CURRENT_SOURCE_DIR}/ELF/CMakeLists.txt) +endif() + +if(LIEF_PE) + include(${CMAKE_CURRENT_SOURCE_DIR}/PE/CMakeLists.txt) +endif() + +if(LIEF_MACHO) + include(${CMAKE_CURRENT_SOURCE_DIR}/MachO/CMakeLists.txt) +endif() + + +target_compile_features(pyLIEF PRIVATE cxx_attribute_deprecated) + +set_property(TARGET pyLIEF PROPERTY CXX_STANDARD 11) +set_property(TARGET pyLIEF PROPERTY CXX_STANDARD_REQUIRED ON) + +if (MSVC) + target_compile_options(pyLIEF PUBLIC /FIiso646.h) + set_property(TARGET pyLIEF PROPERTY LINK_FLAGS /NODEFAULTLIB:MSVCRT) +endif() + +set_target_properties(pyLIEF PROPERTIES PYTHON_VERSION ${PYTHONLIBS_VERSION_STRING}) +set(PYLIEF_DEPS_LIBRARIES LIB_LIEF_STATIC) + +if(LIEF_COVERAGE) + target_compile_options(pyLIEF PRIVATE -g -O0 --coverage -fprofile-arcs -ftest-coverage) + set(PYLIEF_DEPS_LIBRARIES ${PYLIEF_DEPS_LIBRARIES} gcov) +endif() + +if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang") + target_compile_options(pyLIEF PRIVATE -Wall -Wextra -Wpedantic -Wno-macro-redefined) +endif() + +set_target_properties(pyLIEF PROPERTIES PREFIX "" OUTPUT_NAME "lief") +add_dependencies(pyLIEF pybind11) + +if(APPLE) + set_target_properties(pyLIEF PROPERTIES MACOSX_RPATH ".") + set_target_properties(pyLIEF PROPERTIES LINK_FLAGS "-undefined dynamic_lookup ") +endif() + +set_target_properties(pyLIEF PROPERTIES PREFIX "") +if (UNIX) + set_target_properties(pyLIEF PROPERTIES SUFFIX ".so") +elseif(WIN32) + set_target_properties(pyLIEF PROPERTIES SUFFIX ".pyd") +endif() + +get_target_property(suffix pyLIEF SUFFIX) +set(LIEF_LIBRARY_NAME "lief${suffix}") + +if (WIN32) + set(PYLIEF_DEPS_LIBRARIES ${PYLIEF_DEPS_LIBRARIES} ${PYTHON_LIBRARIES}) +endif() + +target_link_libraries(pyLIEF PUBLIC ${PYLIEF_DEPS_LIBRARIES}) + +add_custom_command(TARGET pyLIEF POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy $ ${PROJECT_BINARY_DIR}/api/python/ +) + +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in" "${CMAKE_CURRENT_BINARY_DIR}/setup.py") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/__init__.py.in" "${CMAKE_CURRENT_BINARY_DIR}/__init__.py") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/README.in" "${CMAKE_CURRENT_BINARY_DIR}/README") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/MANIFEST.in.in" "${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.in") + +MESSAGE(STATUS "OS: ${CMAKE_HOST_SYSTEM}") + +find_program(ENV_BINARY "env") + +if (UNIX AND ENV_BINARY AND LIEF_INSTALL_PYTHON) + if ((${PYTHONLIBS_VERSION_STRING} VERSION_GREATER "3") OR (${PYTHONLIBS_VERSION_STRING} VERSION_EQUAL "3")) + install(CODE "execute_process(COMMAND ${ENV_BINARY} python3 ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)" + COMPONENT python) + else() + install( + CODE "execute_process(COMMAND ${ENV_BINARY} python2 ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)" + COMPONENT python) + endif() +endif() + + diff --git a/api/python/ELF/CMakeLists.txt b/api/python/ELF/CMakeLists.txt new file mode 100644 index 0000000..b82e344 --- /dev/null +++ b/api/python/ELF/CMakeLists.txt @@ -0,0 +1,29 @@ +set(LIEF_PYTHON_ELF_SRC + ${CMAKE_CURRENT_LIST_DIR}/pyELF.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicEntry.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySymbolVersionAuxRequirement.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySymbolVersion.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicEntryRunPath.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySymbolVersionRequirement.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyBinary.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySymbolVersionDefinition.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyHeader.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySymbolVersionAux.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicEntryArray.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySegment.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySection.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicEntryRpath.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyRelocation.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicSharedObject.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyParser.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyDynamicEntryLibrary.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySymbol.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyGnuHash.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyBuilder.cpp + ${CMAKE_CURRENT_LIST_DIR}/pyELFStructures.cpp +) + +target_sources(pyLIEF PRIVATE ${LIEF_PYTHON_ELF_SRC}) +target_include_directories(pyLIEF PUBLIC ${CMAKE_CURRENT_LIST_DIR}) + + diff --git a/api/python/ELF/objects/pyBinary.cpp b/api/python/ELF/objects/pyBinary.cpp new file mode 100644 index 0000000..1a03f58 --- /dev/null +++ b/api/python/ELF/objects/pyBinary.cpp @@ -0,0 +1,215 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 + +#include "LIEF/ELF/Binary.hpp" +#include "LIEF/Abstract/Binary.hpp" + +#include "pyELF.hpp" + +template +using no_const_getter = T (Binary::*)(void); + +template +using no_const_func = T (Binary::*)(P); + +void init_ELF_Binary_class(py::module& m) { + + // Binary object + py::class_(m, "Binary", "ELF binary representation") + .def(py::init()) + + .def_property_readonly("type", + &Binary::type) + + .def_property_readonly("header", + static_cast>(&Binary::get_header), + "Return " RST_CLASS_REF(lief.ELF.Header) " object", + py::return_value_policy::reference_internal) + + .def_property_readonly("sections", + static_cast>(&Binary::get_sections), + "Return binary's " RST_CLASS_REF(lief.ELF.Section) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("segments", + static_cast>(&Binary::get_segments), + "Return binary's " RST_CLASS_REF(lief.ELF.Segment) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("dynamic_entries", + static_cast>(&Binary::get_dynamic_entries), + "Return " RST_CLASS_REF(lief.ELF.DynamicEntry) " entries as a list", + py::return_value_policy::reference_internal) + + .def_property_readonly("static_symbols", + static_cast>(&Binary::get_static_symbols), + "Return static's " RST_CLASS_REF(lief.ELF.Symbol) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("dynamic_symbols", + static_cast>(&Binary::get_dynamic_symbols), + "Return dynamic's " RST_CLASS_REF(lief.ELF.Symbol) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("exported_symbols", + static_cast>(&Binary::get_exported_symbols), + "Return dynamic's " RST_CLASS_REF(lief.ELF.Symbol) " which are exported", + py::return_value_policy::reference_internal) + + .def_property_readonly("imported_symbols", + static_cast>(&Binary::get_imported_symbols), + "Return dynamic's " RST_CLASS_REF(lief.ELF.Symbol) " which are imported", + py::return_value_policy::reference_internal) + + .def_property_readonly("dynamic_relocations", + static_cast>(&Binary::get_dynamic_relocations), + "Return PLT/GOT " RST_CLASS_REF(lief.ELF.Relocation) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("pltgot_relocations", + static_cast>(&Binary::get_pltgot_relocations), + "Return dynamics " RST_CLASS_REF(lief.ELF.Relocation) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("symbols_version", + static_cast>(&Binary::get_symbols_version), + "Return " RST_CLASS_REF(lief.ELF.SymbolVersion) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("symbols_version_requirement", + static_cast>(&Binary::get_symbols_version_requirement), + "Return " RST_CLASS_REF(lief.ELF.SymbolVersionRequirement) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("symbols_version_definition", + static_cast>(&Binary::get_symbols_version_definition), + "Return " RST_CLASS_REF(lief.ELF.SymbolVersionDefinition) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("gnu_hash", + &Binary::get_gnu_hash, + "Return " RST_CLASS_REF(lief.ELF.GnuHash) " object", + py::return_value_policy::reference_internal) + + .def_property_readonly("imagebase", + &Binary::get_imagebase, + "Return the program image base. (e.g. 0x400000)") + + .def_property_readonly("virtual_size", + &Binary::get_virtual_size, + "Return the binary's size when mapped in memory") + + .def_property_readonly("is_pie", + &Binary::is_pie, + "Check if the binary is a ``pie`` one") + + .def_property_readonly("has_interpreter", + &Binary::has_interpreter, + "Check if the binary uses a loader") + + .def_property_readonly("interpreter", + &Binary::get_interpreter, + "Return ELF interprer if any. (e.g. ``/lib64/ld-linux-x86-64.so.2``)") + + .def("section_from_offset", + static_cast>(&Binary::section_from_offset), + "Return binary's " RST_CLASS_REF(lief.ELF.Section) " which holds the offset", + "address"_a, + py::return_value_policy::reference) + + .def("section_from_virtual_address", + static_cast>(&Binary::section_from_virtual_address), + "Return binary's " RST_CLASS_REF(lief.ELF.Section) " which holds the given virtual address", + py::return_value_policy::reference) + + .def("segment_from_virtual_address", + static_cast>(&Binary::segment_from_virtual_address), + "Return binary's " RST_CLASS_REF(lief.ELF.Segment) " which holds the address", + py::return_value_policy::reference) + + .def("segment_from_offset", + static_cast>(&Binary::segment_from_offset), + "Return binary's " RST_CLASS_REF(lief.ELF.Segment) " which holds the offset", + py::return_value_policy::reference) + + .def("dynamic_entry_from_tag", + static_cast>(&Binary::dynamic_entry_from_tag), + "Return first binary's " RST_CLASS_REF(lief.ELF.DynamicEntry) " given its tag", + py::return_value_policy::reference) + + .def("has_dynamic_entry", + &Binary::has_dynamic_entry, + "Check if the " RST_CLASS_REF(lief.ELF.DynamicEntry) " associated with the given tag exists") + + .def("patch_pltgot", + static_cast(&Binary::patch_pltgot), + "Patch the imported symbol's name with the ``address``") + + .def("patch_pltgot", + static_cast(&Binary::patch_pltgot), + "Patch the imported symbol's name with the ``address``") + + .def("has_section", + &Binary::has_section, + "Check if a section with the given name exists in the binary") + + .def("get_section", + static_cast>(&Binary::get_section), + py::return_value_policy::reference) + + .def("add_static_symbol", + &Binary::add_static_symbol, + py::return_value_policy::reference) + + .def("virtual_address_to_offset", + &Binary::virtual_address_to_offset, + "Convert the virtual address to an offset in the binary") + + .def("add_section", + &Binary::add_section, + "Add a section in the binary", + py::return_value_policy::reference) + + .def("add_segment", + &Binary::add_segment, + "Add a segment in the binary", + py::arg("segment"), py::arg_v("base", 0x400000), py::arg_v("force_note", false), + py::return_value_policy::reference) + + .def("insert_content", + &Binary::insert_content, + "Add some datas in the binary") + + .def("strip", + &Binary::strip, + "Strip the binary") + + .def("write", + &Binary::write, + "Rebuild the binary and write it in a file", + py::return_value_policy::reference_internal) + + + .def("__str__", + [] (const Binary& binary) + { + std::ostringstream stream; + stream << binary; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pyBuilder.cpp b/api/python/ELF/objects/pyBuilder.cpp new file mode 100644 index 0000000..3749eb4 --- /dev/null +++ b/api/python/ELF/objects/pyBuilder.cpp @@ -0,0 +1,41 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/ELF/Builder.hpp" + +#include +#include + + +void init_ELF_Builder_class(py::module& m) { + py::class_(m, "Builder") + .def(py::init()) + + .def("build", static_cast(&Builder::build)) + + .def("empties_gnuhash", + &Builder::empties_gnuhash, + py::return_value_policy::reference) + + .def("write", + &Builder::write) + + .def("get_build", + &Builder::get_build, + py::return_value_policy::reference_internal); + +} diff --git a/api/python/ELF/objects/pyDynamicEntry.cpp b/api/python/ELF/objects/pyDynamicEntry.cpp new file mode 100644 index 0000000..6294460 --- /dev/null +++ b/api/python/ELF/objects/pyDynamicEntry.cpp @@ -0,0 +1,66 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/ELF/DynamicEntry.hpp" +#include "LIEF/visitors/Hash.hpp" + +#include +#include + +template +using getter_t = T (DynamicEntry::*)(void) const; + +template +using setter_t = void (DynamicEntry::*)(T); + +void init_ELF_DynamicEntry_class(py::module& m) { + + // DynamicEntry object + py::class_(m, "DynamicEntry") + .def_property("tag", + static_cast>(&DynamicEntry::tag), + static_cast>(&DynamicEntry::tag), + "Return the entry's " RST_CLASS_REF(lief.ELF.DYNAMIC_TAGS) " which represent the entry type") + + + .def_property("value", + static_cast>(&DynamicEntry::value), + static_cast>(&DynamicEntry::value), + "Return the entry's value.") + + .def_property("name", + static_cast>(&DynamicEntry::name), + static_cast>(&DynamicEntry::name), + "Depending on the entry type, it return a name. For instance for a `DT_SONAME`\ + entry it returns the library name") + + .def("__eq__", &DynamicEntry::operator==) + .def("__ne__", &DynamicEntry::operator!=) + .def("__hash__", + [] (const DynamicEntry& entry) { + return LIEF::Hash::hash(entry); + }) + + .def("__str__", + [] (const DynamicEntry& dynamicEntry) + { + std::ostringstream stream; + stream << dynamicEntry; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pyDynamicEntryArray.cpp b/api/python/ELF/objects/pyDynamicEntryArray.cpp new file mode 100644 index 0000000..2601208 --- /dev/null +++ b/api/python/ELF/objects/pyDynamicEntryArray.cpp @@ -0,0 +1,58 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/visitors/Hash.hpp" + +#include "LIEF/ELF/DynamicEntryArray.hpp" +#include "LIEF/ELF/DynamicEntry.hpp" + +#include +#include + +template +using getter_t = T (DynamicEntryArray::*)(void) const; + +template +using setter_t = void (DynamicEntryArray::*)(T); + +void init_ELF_DynamicEntryArray_class(py::module& m) { + + // Dynamic Entry Array object + py::class_(m, "DynamicEntryArray") + .def(py::init<>()) + .def_property("array", + static_cast& (DynamicEntryArray::*) (void)>(&DynamicEntryArray::array), + static_cast&>>(&DynamicEntryArray::array), + "Return the array") + + .def("__eq__", &DynamicEntryArray::operator==) + .def("__ne__", &DynamicEntryArray::operator!=) + .def("__hash__", + [] (const DynamicEntryArray& entry) { + return LIEF::Hash::hash(entry); + }) + + + .def("__str__", + [] (const DynamicEntryArray& entry) + { + std::ostringstream stream; + stream << entry; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pyDynamicEntryLibrary.cpp b/api/python/ELF/objects/pyDynamicEntryLibrary.cpp new file mode 100644 index 0000000..5dd8166 --- /dev/null +++ b/api/python/ELF/objects/pyDynamicEntryLibrary.cpp @@ -0,0 +1,60 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/visitors/Hash.hpp" + +#include "LIEF/ELF/DynamicEntryLibrary.hpp" +#include "LIEF/ELF/DynamicEntry.hpp" + +#include +#include + +template +using getter_t = T (DynamicEntryLibrary::*)(void) const; + +template +using setter_t = void (DynamicEntryLibrary::*)(T); + +void init_ELF_DynamicEntryLibrary_class(py::module& m) { + + // + // Dynamic Entry Library object + // + py::class_(m, "DynamicEntryLibrary") + .def(py::init()) + .def_property("name", + static_cast>(&DynamicEntryLibrary::name), + static_cast>(&DynamicEntryLibrary::name), + "Return library's name") + + .def("__eq__", &DynamicEntryLibrary::operator==) + .def("__ne__", &DynamicEntryLibrary::operator!=) + .def("__hash__", + [] (const DynamicEntryLibrary& entry) { + return LIEF::Hash::hash(entry); + }) + + + .def("__str__", + [] (const DynamicEntryLibrary& dynamicEntryLibrary) + { + std::ostringstream stream; + stream << dynamicEntryLibrary; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pyDynamicEntryRpath.cpp b/api/python/ELF/objects/pyDynamicEntryRpath.cpp new file mode 100644 index 0000000..41fad18 --- /dev/null +++ b/api/python/ELF/objects/pyDynamicEntryRpath.cpp @@ -0,0 +1,65 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/visitors/Hash.hpp" + +#include "LIEF/ELF/DynamicEntryRpath.hpp" +#include "LIEF/ELF/DynamicEntry.hpp" + +#include +#include + +template +using getter_t = T (DynamicEntryRpath::*)(void) const; + +template +using setter_t = void (DynamicEntryRpath::*)(T); + +void init_ELF_DynamicEntryRpath_class(py::module& m) { + + // + // Dynamic Entry RPATH object + // + py::class_(m, "DynamicEntryRpath") + .def(py::init()) + .def_property("name", + static_cast>(&DynamicEntryRpath::name), + static_cast>(&DynamicEntryRpath::name), + "Return path value") + + .def_property("rpath", + static_cast>(&DynamicEntryRpath::rpath), + static_cast>(&DynamicEntryRpath::rpath), + "Return path value") + + .def("__eq__", &DynamicEntryRpath::operator==) + .def("__ne__", &DynamicEntryRpath::operator!=) + .def("__hash__", + [] (const DynamicEntryRpath& entry) { + return LIEF::Hash::hash(entry); + }) + + + .def("__str__", + [] (const DynamicEntryRpath& entry) + { + std::ostringstream stream; + stream << entry; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pyDynamicEntryRunPath.cpp b/api/python/ELF/objects/pyDynamicEntryRunPath.cpp new file mode 100644 index 0000000..8ff3f50 --- /dev/null +++ b/api/python/ELF/objects/pyDynamicEntryRunPath.cpp @@ -0,0 +1,64 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/visitors/Hash.hpp" + +#include "LIEF/ELF/DynamicEntryRunPath.hpp" +#include "LIEF/ELF/DynamicEntry.hpp" + +#include +#include + +template +using getter_t = T (DynamicEntryRunPath::*)(void) const; + +template +using setter_t = void (DynamicEntryRunPath::*)(T); + +void init_ELF_DynamicEntryRunPath_class(py::module& m) { + + // + // Dynamic Entry RUNPATH object + // + py::class_(m, "DynamicEntryRunPath") + .def(py::init()) + .def_property("name", + static_cast>(&DynamicEntryRunPath::name), + static_cast>(&DynamicEntryRunPath::name), + "Return path value") + + .def_property("runpath", + static_cast>(&DynamicEntryRunPath::runpath), + static_cast>(&DynamicEntryRunPath::runpath), + "Return path value") + + .def("__eq__", &DynamicEntryRunPath::operator==) + .def("__ne__", &DynamicEntryRunPath::operator!=) + .def("__hash__", + [] (const DynamicEntryRunPath& entry) { + return LIEF::Hash::hash(entry); + }) + + .def("__str__", + [] (const DynamicEntryRunPath& entry) + { + std::ostringstream stream; + stream << entry; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pyDynamicSharedObject.cpp b/api/python/ELF/objects/pyDynamicSharedObject.cpp new file mode 100644 index 0000000..8cf4c1a --- /dev/null +++ b/api/python/ELF/objects/pyDynamicSharedObject.cpp @@ -0,0 +1,58 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/visitors/Hash.hpp" + +#include "LIEF/ELF/DynamicSharedObject.hpp" +#include "LIEF/ELF/DynamicEntry.hpp" + +#include +#include + +template +using getter_t = T (DynamicSharedObject::*)(void) const; + +template +using setter_t = void (DynamicSharedObject::*)(T); + +void init_ELF_DynamicSharedObject_class(py::module& m) { + + // + // Dynamic Shared Object object + // + py::class_(m, "DynamicSharedObject") + .def_property("name", + static_cast>(&DynamicSharedObject::name), + static_cast>(&DynamicSharedObject::name), + "Return the library name") + + .def("__eq__", &DynamicSharedObject::operator==) + .def("__ne__", &DynamicSharedObject::operator!=) + .def("__hash__", + [] (const DynamicSharedObject& entry) { + return LIEF::Hash::hash(entry); + }) + + .def("__str__", + [] (const DynamicSharedObject& dynamicSharedObject) + { + std::ostringstream stream; + stream << dynamicSharedObject; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pyGnuHash.cpp b/api/python/ELF/objects/pyGnuHash.cpp new file mode 100644 index 0000000..b26ecea --- /dev/null +++ b/api/python/ELF/objects/pyGnuHash.cpp @@ -0,0 +1,79 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "pyELF.hpp" + +#include "LIEF/ELF/GnuHash.hpp" + + +template +using getter_t = T (GnuHash::*)(void) const; + +template +using setter_t = void (GnuHash::*)(T); + +void init_ELF_GnuHash_class(py::module& m) { + + py::class_(m, "GnuHash") + .def(py::init<>()) + + .def_property_readonly("nb_buckets", + &GnuHash::nb_buckets, + "Return the number of buckets") + + .def_property_readonly("symbol_index", + &GnuHash::symbol_index, + "Index of the first symbol in the dynamic symbols table which accessible with the hash table") + + .def_property_readonly("shift2", + &GnuHash::shift2, + "Shift count used in the bloom filter") + + .def_property_readonly("bloom_filters", + &GnuHash::bloom_filters, + "Bloom filters", + py::return_value_policy::reference_internal) + + .def_property_readonly("bloom_filters", + &GnuHash::bloom_filters, + "Bloom filters", + py::return_value_policy::reference_internal) + + .def_property_readonly("buckets", + &GnuHash::buckets, + "hash buckets", + py::return_value_policy::reference_internal) + + .def_property_readonly("hash_values", + &GnuHash::hash_values, + "Hash values", + py::return_value_policy::reference_internal) + + .def("__str__", + [] (const GnuHash& gnuhash) + { + std::ostringstream stream; + stream << gnuhash; + std::string str = stream.str(); + return str; + }); + + + +} + diff --git a/api/python/ELF/objects/pyHeader.cpp b/api/python/ELF/objects/pyHeader.cpp new file mode 100644 index 0000000..83fb4f8 --- /dev/null +++ b/api/python/ELF/objects/pyHeader.cpp @@ -0,0 +1,150 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "pyELF.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/ELF/Header.hpp" + +template +using getter_t = T (Header::*)(void) const; + +template +using setter_t = void (Header::*)(T); + +void init_ELF_Header_class(py::module& m) { + + // + // Header object + // + py::class_
(m, "Header") + .def(py::init<>()) + .def(py::init&>()) + + .def_property("identity_class", + static_cast>(&Header::identity_class), + static_cast>(&Header::identity_class), + "Return header's " RST_CLASS_REF(lief.ELF.ELF_CLASS) "." + ) + + .def_property("identity_data", + static_cast>(&Header::identity_data), + static_cast>(&Header::identity_data), + "Return header's " RST_CLASS_REF(lief.ELF.ELF_DATA) "." + ) + + .def_property("identity_version", + static_cast>(&Header::identity_version), + static_cast>(&Header::identity_version), + "Return header's " RST_CLASS_REF(lief.ELF.VERSION) "." + ) + + .def_property("identity_os_abi", + static_cast>(&Header::identity_os_abi), + static_cast>(&Header::identity_os_abi), + "Return header's " RST_CLASS_REF(lief.ELF.OS_ABI) "." + ) + + .def_property_readonly("identity", + static_cast(&Header::identity), + "Return header's identity.", + py::return_value_policy::reference_internal + ) + + .def_property("file_type", + static_cast>(&Header::file_type), + static_cast>(&Header::file_type), + "Return binary's " RST_CLASS_REF(lief.ELF.E_TYPE) ". It determine if the binary \ + is a executable, a library..." + ) + + .def_property("machine_type", + static_cast>(&Header::machine_type), + static_cast>(&Header::machine_type), + "Return target architecture (" RST_CLASS_REF(lief.ELF.ARCH) ")") + + .def_property("object_file_version", + static_cast>(&Header::object_file_version), + static_cast>(&Header::object_file_version), + "Return " RST_CLASS_REF(lief.ELF.VERSION) "") + + .def_property("entrypoint", + static_cast>(&Header::entrypoint), + static_cast>(&Header::entrypoint), + "Return binary entry point") + + .def_property("program_header_offset", + static_cast>(&Header::program_headers_offset), + static_cast>(&Header::program_headers_offset), + "Return file offset to the program header table") + + .def_property("section_header_offset", + static_cast>(&Header::section_headers_offset), + static_cast>(&Header::section_headers_offset), + "Return file offset to the section header table") + + .def_property("processor_flag", + static_cast>(&Header::processor_flag), + static_cast>(&Header::processor_flag)) + + .def_property("header_size", + static_cast>(&Header::header_size), + static_cast>(&Header::header_size), + "Return the size of the ELF header") + + .def_property("program_header_size", + static_cast>(&Header::program_header_size), + static_cast>(&Header::program_header_size), + "Return this size of a program header entry") + + .def_property("numberof_segments", + static_cast>(&Header::numberof_segments), + static_cast>(&Header::numberof_segments), + "Return the number of program headers (segments)") + + .def_property("sizeof_section_header", + static_cast>(&Header::sizeof_section_header), + static_cast>(&Header::sizeof_section_header), + "Return the size of an section header entry") + + .def_property("numberof_sections", + static_cast>(&Header::numberof_sections), + static_cast>(&Header::numberof_sections), + "Return the number of section's headers") + + .def_property("section_name_table_idx", + static_cast>(&Header::section_name_table_idx), + static_cast>(&Header::section_name_table_idx), + "Return the section index which hold sections's name") + + .def("__eq__", &Header::operator==) + .def("__ne__", &Header::operator!=) + .def("__hash__", + [] (const Header& header) { + return LIEF::Hash::hash(header); + }) + + .def("__str__", + [] (const Header& header) + { + std::ostringstream stream; + stream << header; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pyParser.cpp b/api/python/ELF/objects/pyParser.cpp new file mode 100644 index 0000000..3d74d0a --- /dev/null +++ b/api/python/ELF/objects/pyParser.cpp @@ -0,0 +1,36 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/ELF/Parser.hpp" + +#include + +void init_ELF_Parser_class(py::module& m) { + + // Parser (Parser) + m.def("parse", + static_cast(&Parser::parse), + "Parse the given binary and return a " RST_CLASS_REF(lief.ELF.Binary) " object", + py::return_value_policy::take_ownership); + + + m.def("parse_from_raw", + static_cast&, const std::string&)>(&Parser::parse), + "Parse the given raw data and return a " RST_CLASS_REF(lief.ELF.Binary) " object", + py::arg("raw"), py::arg("name") = "", + py::return_value_policy::take_ownership); +} diff --git a/api/python/ELF/objects/pyRelocation.cpp b/api/python/ELF/objects/pyRelocation.cpp new file mode 100644 index 0000000..4e7e4fe --- /dev/null +++ b/api/python/ELF/objects/pyRelocation.cpp @@ -0,0 +1,74 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/ELF/Relocation.hpp" + +#include +#include + +template +using getter_t = T (Relocation::*)(void) const; + +template +using setter_t = void (Relocation::*)(T); + +void init_ELF_Relocation_class(py::module& m) { + // Relocation object + py::class_(m, "Relocation") + .def_property("address", + static_cast>(&Relocation::address), + static_cast>(&Relocation::address)) + + .def_property("addend", + static_cast>(&Relocation::addend), + static_cast>(&Relocation::addend)) + + .def_property("type", + static_cast>(&Relocation::type), + static_cast>(&Relocation::type)) + + .def_property_readonly("has_symbol", + &Relocation::has_symbol) + + .def_property_readonly("symbol", + static_cast(&Relocation::symbol), + py::return_value_policy::reference_internal) + + .def_property_readonly("is_rela", + static_cast>(&Relocation::is_rela)) + + .def_property_readonly("is_rel", + static_cast>(&Relocation::is_rel)) + + + .def("__eq__", &Relocation::operator==) + .def("__ne__", &Relocation::operator!=) + .def("__hash__", + [] (const Relocation& relocation) { + return LIEF::Hash::hash(relocation); + }) + + .def("__str__", + [] (const Relocation& relocation) + { + std::ostringstream stream; + stream << relocation; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pySection.cpp b/api/python/ELF/objects/pySection.cpp new file mode 100644 index 0000000..2d97b2e --- /dev/null +++ b/api/python/ELF/objects/pySection.cpp @@ -0,0 +1,130 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/Abstract/Section.hpp" +#include "LIEF/ELF/Section.hpp" + +#include +#include + +template +using getter_t = T (Section::*)(void) const; + +template +using setter_t = void (Section::*)(T); + +template +using no_const_getter = T (Section::*)(void); + +void init_ELF_Section_class(py::module& m) { + + // Section object + py::class_(m, "Section") + .def(py::init<>()) + + .def("__init__", + [] (Section& section, std::vector& content, ELF_CLASS type) + { + new (§ion) Section(content.data(), type); + }) + + .def_property_readonly("name_idx", + static_cast>(&Section::name_idx), + "Index of the section's name in the string table\n\n" + ".. warning:: The value will probably change when re-building binary.") + + .def_property("type", + static_cast>(&Section::type), + static_cast>(&Section::type), + "Return a " RST_CLASS_REF(lief.ELF.SECTION_TYPES) "") + + .def_property("flags", + static_cast>(&Section::flags), + static_cast>(&Section::flags), + "Return sections flags") + + .def_property("virtual_address", + static_cast>(&Section::virtual_address), + static_cast>(&Section::virtual_address), + "Return address where the section will be mapped in memory\n\n" + ".. warning:: This value is not reliable use segment's virtual address " + "(:attr:`~lief.ELF.Segment.virtual_address`) instead.") + + .def_property("file_offset", + static_cast>(&Section::file_offset), + static_cast>(&Section::file_offset), + "Data offset in the binary") + + .def_property_readonly("original_size", + static_cast>(&Section::original_size), + "original data size. Without modification we have `original_size == size`") + + .def_property("alignment", + static_cast>(&Section::alignment), + static_cast>(&Section::alignment) + ) + + .def_property("information", + static_cast>(&Section::information), + static_cast>(&Section::information)) + + .def_property("entry_size", + static_cast>(&Section::entry_size), + static_cast>(&Section::entry_size), + "If section's content is an array, `entry_size` holds the element's size\n\n" + ":Example:\n" + "\tThe `.dynamic` section contains an array of " RST_CLASS_REF(lief.ELF.DynamicEntry) ". As the size " + "of a dynamic entry is 0x10 (for ELF64), entry_size will contains this value\n\n" + ".. warning:: This value is not necessarily reliable.") + + .def_property("link", + static_cast>(&Section::link), + static_cast>(&Section::link)) + + .def_property("data", + static_cast>>(&Section::content), + static_cast&>>(&Section::content)) + + .def_property_readonly("segments", + static_cast>(&Section::segments), + py::return_value_policy::reference_internal) + + .def("__contains__", + [] (const Section §ion, SECTION_FLAGS flag) + { + return section.has_flag(flag); + }, "Test if the current section has the given flag") + + + .def("__eq__", &Section::operator==) + .def("__ne__", &Section::operator!=) + .def("__hash__", + [] (const Section& section) { + return LIEF::Hash::hash(section); + }) + + .def("__str__", + [] (const Section& section) + { + std::ostringstream stream; + stream << section; + std::string str = stream.str(); + return str; + }); +} + diff --git a/api/python/ELF/objects/pySegment.cpp b/api/python/ELF/objects/pySegment.cpp new file mode 100644 index 0000000..552f15d --- /dev/null +++ b/api/python/ELF/objects/pySegment.cpp @@ -0,0 +1,121 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/ELF/Segment.hpp" + +#include "pyELF.hpp" + +template +using getter_t = T (Segment::*)(void) const; + +template +using setter_t = void (Segment::*)(T); + +template +using no_const_getter = T (Segment::*)(void); + + +void init_ELF_Segment_class(py::module& m) { + py::class_(m, "Segment") + + .def(py::init<>()) + .def(py::init&>()) + .def(py::init&, ELF_CLASS>()) + + .def_property("type", + static_cast>(&Segment::type), + static_cast>(&Segment::type), + "Segment's " RST_CLASS_REF(lief.ELF.SEGMENT_TYPES) "") + + .def_property("flag", + static_cast>(&Segment::flag), + static_cast>(&Segment::flag), + "Segment's flags") + + .def_property("file_offset", + static_cast>(&Segment::file_offset), + static_cast>(&Segment::file_offset), + "Data offset in the binary") + + .def_property("virtual_address", + static_cast>(&Segment::virtual_address), + static_cast>(&Segment::virtual_address), + "Address where the segment will be mapped\n\n" + ".. warning:: We must have\n\n" + "\t.. math::\n\n" + "\t\t\\text{virtual address} \\equiv \\text{file offset} \\pmod{\\text{page size}}\n\n" + "\t\t\\text{virtual address} \\equiv \\text{file offset} \\pmod{\\text{alignment}}" + ) + + .def_property("physical_address", + static_cast>(&Segment::physical_address), + static_cast>(&Segment::physical_address), + "Physical address of beginning of segment (OS-specific)") + + .def_property("physical_size", + static_cast>(&Segment::physical_size), + static_cast>(&Segment::physical_size), + "Size of data in the binary") + + .def_property("virtual_size", + static_cast>(&Segment::virtual_size), + static_cast>(&Segment::virtual_size), + "Size of this segment in memory") + + .def_property("alignment", + static_cast>(&Segment::alignment), + static_cast>(&Segment::alignment), + "This member gives the value to which the segments are aligned in memory and in the file.\n" + "Values 0 and 1 mean no alignment is required.") + + .def_property("data", + static_cast>>(&Segment::content), + static_cast&>>(&Segment::content), + "Segment's raw data") + + .def_property_readonly("sections", + static_cast>(&Segment::sections), + "" RST_CLASS_REF(lief.ELF.Section) " (s) inside this segment", + py::return_value_policy::reference_internal) + + .def("__contains__", + [] (const Segment& segment, SEGMENT_FLAGS flag) -> bool + { + return segment.has_flag(flag); + } + , "Test if the current segment has the given flag") + + + .def("__eq__", &Segment::operator==) + .def("__ne__", &Segment::operator!=) + .def("__hash__", + [] (const Segment& segment) { + return LIEF::Hash::hash(segment); + }) + + .def("__str__", + [] (const Segment& segment) + { + std::ostringstream stream; + stream << segment; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pySymbol.cpp b/api/python/ELF/objects/pySymbol.cpp new file mode 100644 index 0000000..0a10d50 --- /dev/null +++ b/api/python/ELF/objects/pySymbol.cpp @@ -0,0 +1,110 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/ELF/Symbol.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/Abstract/Symbol.hpp" + + +#include +#include + +template +using getter_t = T (Symbol::*)(void) const; + +template +using setter_t = void (Symbol::*)(T); + +void init_ELF_Symbol_class(py::module& m) { + + py::class_(m, "Symbol") + .def(py::init<>()) + .def_property_readonly("demangled_name", + &Symbol::demangled_name, + "Symbol's unmangled name") + + .def_property("type", + static_cast>(&Symbol::type), + static_cast>(&Symbol::type), + "A symbol's type provides a general classification for the associated entity") + + .def_property("binding", + static_cast>(&Symbol::binding), + static_cast>(&Symbol::binding), + "A symbol’s binding determines the linkage visibility and behavior") + + .def_property("information", + static_cast>(&Symbol::information), + static_cast>(&Symbol::information), + "This member specifies the symbol's type and binding attributes.\n") + + .def_property("other", + static_cast>(&Symbol::other), + static_cast>(&Symbol::other), + "This member currently holds 0 and has no defined meaning.") + + .def_property("value", + static_cast>(&Symbol::value), + static_cast>(&Symbol::value), + "This member have slightly different interpretations\n\n" + "\t- In relocatable files, `value` holds alignment constraints for a symbol whose section index is " + "`SHN_COMMON`.\n\n" + "\t- In relocatable files, `value` holds a section offset for a defined symbol. That is, `value` is an" + "offset from the beginning of the section associated with this symbol.\n\n" + "\t- In executable and shared object files, `value` holds a virtual address. To make these files's" + "symbols more useful for the dynamic linker, the section offset (file interpretation) gives way to" + "a virtual address (memory interpretation) for which the section number is irrelevant.") + + .def_property("size", + static_cast>(&Symbol::size), + static_cast>(&Symbol::size), + "Many symbols have associated sizes. For example, a data object's size is the number of " + "bytes contained in the object. This member holds `0` if the symbol has no size or " + "an unknown size.") + + .def_property("shndx", + static_cast>(&Symbol::shndx), + static_cast>(&Symbol::shndx), + "Section associated with the symbol") + + .def_property_readonly("has_version", + &Symbol::has_version, + "Check if this symbols has a " RST_CLASS_REF(lief.ELF.SymbolVersion) "") + + .def_property_readonly("symbol_version", + static_cast(&Symbol::symbol_version), + "Return the " RST_CLASS_REF(lief.ELF.SymbolVersion) " associated with this symbol", + py::return_value_policy::reference_internal) + + .def("__eq__", &Symbol::operator==) + .def("__ne__", &Symbol::operator!=) + .def("__hash__", + [] (const Symbol& symbol) { + return LIEF::Hash::hash(symbol); + }) + + + .def("__str__", + [] (const Symbol& symbol) + { + std::ostringstream stream; + stream << symbol; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pySymbolVersion.cpp b/api/python/ELF/objects/pySymbolVersion.cpp new file mode 100644 index 0000000..db36633 --- /dev/null +++ b/api/python/ELF/objects/pySymbolVersion.cpp @@ -0,0 +1,69 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/ELF/SymbolVersion.hpp" +#include "LIEF/visitors/Hash.hpp" + +#include +#include + +template +using getter_t = T (SymbolVersion::*)(void) const; + +template +using setter_t = void (SymbolVersion::*)(T); + +void init_ELF_SymbolVersion_class(py::module& m) { + + // SymbolVersion version object + py::class_(m, "SymbolVersion") + .def_property("value", + static_cast>(&SymbolVersion::value), + static_cast>(&SymbolVersion::value), + "- `0` : The symbol is local\n" + "- `1` : The symbol is global\n\n" + "All other values are used for versions in the own object or in any of\n" + "the dependencies. This is the version the symbol is tight to.") + + .def_property_readonly("has_auxiliary_version", + &SymbolVersion::has_auxiliary_version, + "Check if this symbols has a " RST_CLASS_REF(lief.ELF.SymbolVersionAux) "") + + .def_property_readonly( + "symbol_version_auxiliary", + static_cast( + &SymbolVersion::symbol_version_auxiliary), + "Return the " RST_CLASS_REF(lief.ELF.SymbolVersionAux) " associated with this version", + py::return_value_policy::reference_internal) + + + .def("__eq__", &SymbolVersion::operator==) + .def("__ne__", &SymbolVersion::operator!=) + .def("__hash__", + [] (const SymbolVersion& sv) { + return LIEF::Hash::hash(sv); + }) + + .def("__str__", + [] (const SymbolVersion& symbolVersion) + { + std::ostringstream stream; + stream << symbolVersion; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pySymbolVersionAux.cpp b/api/python/ELF/objects/pySymbolVersionAux.cpp new file mode 100644 index 0000000..2d74958 --- /dev/null +++ b/api/python/ELF/objects/pySymbolVersionAux.cpp @@ -0,0 +1,56 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/ELF/SymbolVersionAux.hpp" + +#include +#include + +template +using getter_t = T (SymbolVersionAux::*)(void) const; + +template +using setter_t = void (SymbolVersionAux::*)(T); + +void init_ELF_SymbolVersionAux_class(py::module& m) { + + // Symbol Version Auxiliary object + py::class_(m, "SymbolVersionAux", + "Class which modelize an Auxiliary Symbol version") + + .def_property("name", + static_cast>(&SymbolVersionAux::name), + static_cast>(&SymbolVersionAux::name), + "Symbol's name") + + .def("__eq__", &SymbolVersionAux::operator==) + .def("__ne__", &SymbolVersionAux::operator!=) + .def("__hash__", + [] (const SymbolVersionAux& sva) { + return LIEF::Hash::hash(sva); + }) + + .def("__str__", + [] (const SymbolVersionAux& symbolVersionAux) + { + std::ostringstream stream; + stream << symbolVersionAux; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pySymbolVersionAuxRequirement.cpp b/api/python/ELF/objects/pySymbolVersionAuxRequirement.cpp new file mode 100644 index 0000000..5f22cab --- /dev/null +++ b/api/python/ELF/objects/pySymbolVersionAuxRequirement.cpp @@ -0,0 +1,63 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/ELF/SymbolVersionAuxRequirement.hpp" + +#include +#include + +template +using getter_t = T (SymbolVersionAuxRequirement::*)(void) const; + +template +using setter_t = void (SymbolVersionAuxRequirement::*)(T); + +void init_ELF_SymbolVersionAuxRequirement_class(py::module& m) { + // + // Symbol Version Requirement Auxiliary object + // + py::class_(m, "SymbolVersionAuxRequirement") + .def_property("hash", + static_cast>(&SymbolVersionAuxRequirement::hash), + static_cast>(&SymbolVersionAuxRequirement::hash)) + + .def_property("flags", + static_cast>(&SymbolVersionAuxRequirement::flags), + static_cast>(&SymbolVersionAuxRequirement::flags)) + + .def_property("other", + static_cast>(&SymbolVersionAuxRequirement::other), + static_cast>(&SymbolVersionAuxRequirement::other)) + + + .def("__eq__", &SymbolVersionAuxRequirement::operator==) + .def("__ne__", &SymbolVersionAuxRequirement::operator!=) + .def("__hash__", + [] (const SymbolVersionAuxRequirement& svar) { + return LIEF::Hash::hash(svar); + }) + + .def("__str__", + [] (const SymbolVersionAuxRequirement& symbolVersionAux) + { + std::ostringstream stream; + stream << symbolVersionAux; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pySymbolVersionDefinition.cpp b/api/python/ELF/objects/pySymbolVersionDefinition.cpp new file mode 100644 index 0000000..2e325c6 --- /dev/null +++ b/api/python/ELF/objects/pySymbolVersionDefinition.cpp @@ -0,0 +1,70 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "pyELF.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/ELF/SymbolVersionDefinition.hpp" + +template +using getter_t = T (SymbolVersionDefinition::*)(void) const; + +template +using setter_t = void (SymbolVersionDefinition::*)(T); + +template +using no_const_getter = T (SymbolVersionDefinition::*)(void); + +void init_ELF_SymbolVersionDefinition_class(py::module& m) { + + py::class_(m, "SymbolVersionDefinition", + "Class which modelization of an entry defined in ``DT_VERDEF`` (or ``.gnu.version_d``)") + + .def_property("version", + static_cast>(&SymbolVersionDefinition::version), + static_cast>(&SymbolVersionDefinition::version), + "Version revision. Should holds 1") + + .def_property("flags", + static_cast>(&SymbolVersionDefinition::flags), + static_cast>(&SymbolVersionDefinition::flags)) + + .def_property("hash", + static_cast>(&SymbolVersionDefinition::hash), + static_cast>(&SymbolVersionDefinition::hash)) + + .def_property_readonly("auxiliary_symbols", + static_cast>(&SymbolVersionDefinition::symbols_aux), + py::return_value_policy::reference_internal) + + .def("__eq__", &SymbolVersionDefinition::operator==) + .def("__ne__", &SymbolVersionDefinition::operator!=) + .def("__hash__", + [] (const SymbolVersionDefinition& svd) { + return LIEF::Hash::hash(svd); + }) + + .def("__str__", + [] (const SymbolVersionDefinition& svd) + { + std::ostringstream stream; + stream << svd; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/objects/pySymbolVersionRequirement.cpp b/api/python/ELF/objects/pySymbolVersionRequirement.cpp new file mode 100644 index 0000000..0810397 --- /dev/null +++ b/api/python/ELF/objects/pySymbolVersionRequirement.cpp @@ -0,0 +1,68 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/ELF/SymbolVersionRequirement.hpp" + +#include "pyELF.hpp" + +template +using getter_t = T (SymbolVersionRequirement::*)(void) const; + +template +using setter_t = void (SymbolVersionRequirement::*)(T); + +template +using no_const_getter = T (SymbolVersionRequirement::*)(void); + +void init_ELF_SymbolVersionRequirement_class(py::module& m) { + + // Symbol Version Requirement object + py::class_(m, "SymbolVersionRequirement", + "Class which modelize an entry in ``DT_VERNEED`` or ``.gnu.version_r`` table") + + .def_property("version", + static_cast>(&SymbolVersionRequirement::version), + static_cast>(&SymbolVersionRequirement::version), + "Version revision. Should holds 1") + + .def_property("name", + static_cast>(&SymbolVersionRequirement::name), + static_cast>(&SymbolVersionRequirement::name)) + + .def("get_auxiliary_symbols", + static_cast>(&SymbolVersionRequirement::get_auxiliary_symbols), + "Auxiliary entries", + py::return_value_policy::reference_internal) + + .def("__eq__", &SymbolVersionRequirement::operator==) + .def("__ne__", &SymbolVersionRequirement::operator!=) + .def("__hash__", + [] (const SymbolVersionRequirement& svr) { + return LIEF::Hash::hash(svr); + }) + + .def("__str__", + [] (const SymbolVersionRequirement& symbolVersionRequirement) + { + std::ostringstream stream; + stream << symbolVersionRequirement; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/ELF/pyELF.cpp b/api/python/ELF/pyELF.cpp new file mode 100644 index 0000000..31df338 --- /dev/null +++ b/api/python/ELF/pyELF.cpp @@ -0,0 +1,54 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" + +// +// ELF modules +// +void init_ELF_module(py::module& m) { + py::module LIEF_ELF_module = m.def_submodule("ELF", "Python API for ELF"); + + // Objects + init_ELF_Parser_class(LIEF_ELF_module); + init_ELF_Binary_class(LIEF_ELF_module); + init_ELF_Header_class(LIEF_ELF_module); + init_ELF_Section_class(LIEF_ELF_module); + init_ELF_Segment_class(LIEF_ELF_module); + init_ELF_Symbol_class(LIEF_ELF_module); + init_ELF_Relocation_class(LIEF_ELF_module); + init_ELF_SymbolVersion_class(LIEF_ELF_module); + init_ELF_SymbolVersionAux_class(LIEF_ELF_module); + init_ELF_SymbolVersionAuxRequirement_class(LIEF_ELF_module); + init_ELF_SymbolVersionDefinition_class(LIEF_ELF_module); + init_ELF_SymbolVersionRequirement_class(LIEF_ELF_module); + init_ELF_DynamicEntry_class(LIEF_ELF_module); + init_ELF_DynamicEntryLibrary_class(LIEF_ELF_module); + init_ELF_DynamicSharedObject_class(LIEF_ELF_module); + init_ELF_DynamicEntryArray_class(LIEF_ELF_module); + init_ELF_DynamicEntryRpath_class(LIEF_ELF_module); + init_ELF_DynamicEntryRunPath_class(LIEF_ELF_module); + init_ELF_GnuHash_class(LIEF_ELF_module); + init_ELF_Builder_class(LIEF_ELF_module); + + // Enums + init_ELF_Structures_enum(LIEF_ELF_module); + + py::module LIEF_ELF32_module = LIEF_ELF_module.def_submodule("ELF32", ""); + init_ELF32_Structures(LIEF_ELF32_module); + + py::module LIEF_ELF64_module = LIEF_ELF_module.def_submodule("ELF64", ""); + init_ELF64_Structures(LIEF_ELF64_module); +} diff --git a/api/python/ELF/pyELF.hpp b/api/python/ELF/pyELF.hpp new file mode 100644 index 0000000..cb835bd --- /dev/null +++ b/api/python/ELF/pyELF.hpp @@ -0,0 +1,55 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 PY_LIEF_ELF_H_ +#define PY_LIEF_ELF_H_ + +#include "LIEF/ELF/Parser.hpp" +#include "LIEF/ELF/Binary.hpp" +#include "LIEF/ELF/Builder.hpp" + +#include "pyLIEF.hpp" +using namespace LIEF::ELF; + +void init_ELF_Parser_class(py::module&); +void init_ELF_Binary_class(py::module&); +void init_ELF_Header_class(py::module&); +void init_ELF_Section_class(py::module&); +void init_ELF_Segment_class(py::module&); +void init_ELF_Symbol_class(py::module&); +void init_ELF_Relocation_class(py::module&); +void init_ELF_SymbolVersion_class(py::module&); +void init_ELF_SymbolVersionAux_class(py::module&); +void init_ELF_SymbolVersionRequirement_class(py::module&); +void init_ELF_SymbolVersionDefinition_class(py::module&); +void init_ELF_SymbolVersionAuxRequirement_class(py::module&); +void init_ELF_DynamicEntry_class(py::module&); +void init_ELF_DynamicEntryLibrary_class(py::module&); +void init_ELF_DynamicSharedObject_class(py::module&); +void init_ELF_DynamicEntryArray_class(py::module&); +void init_ELF_DynamicEntryRpath_class(py::module&); +void init_ELF_DynamicEntryRunPath_class(py::module&); +void init_ELF_GnuHash_class(py::module&); +void init_ELF_Builder_class(py::module&); + +// Enums +void init_ELF_Structures_enum(py::module&); + +// ELF32 and ELF64 structures +void init_ELF32_Structures(py::module&); +void init_ELF64_Structures(py::module&); + + +#endif diff --git a/api/python/ELF/pyELFStructures.cpp b/api/python/ELF/pyELFStructures.cpp new file mode 100644 index 0000000..46680be --- /dev/null +++ b/api/python/ELF/pyELFStructures.cpp @@ -0,0 +1,749 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyELF.hpp" +#include "LIEF/ELF/Structures.hpp" +#include "LIEF/ELF/EnumToString.hpp" + +#define PY_ENUM(x) to_string(x), x + +void init_ELF32_Structures(py::module& m) { + //py::class_>(m, "Sizes") + // .def_property_readonly_static("ehdr", + // [] (py::object) {return Sizes::ehdr;}) + + // .def_property_readonly_static("phdr", + // [] (py::object) {return Sizes::phdr;}) + + // .def_property_readonly_static("shdr", + // [] (py::object) {return Sizes::shdr;}) + + // .def_property_readonly_static("sym", + // [] (py::object) {return Sizes::sym;}); + +} + +void init_ELF64_Structures(py::module& m) { + //py::class_>(m, "Sizes") + // .def_property_readonly_static("ehdr", + // [] (py::object) {return Sizes::ehdr;}) + + // .def_property_readonly_static("phdr", + // [] (py::object) {return Sizes::phdr;}) + + // .def_property_readonly_static("shdr", + // [] (py::object) {return Sizes::shdr;}) + + // .def_property_readonly_static("sym", + // [] (py::object) {return Sizes::sym;}); + +} + +void init_ELF_Structures_enum(py::module& m) { + + py::enum_(m, "ELF_CLASS") + .value(PY_ENUM(ELF_CLASS::ELFCLASSNONE)) + .value(PY_ENUM(ELF_CLASS::ELFCLASS32)) + .value(PY_ENUM(ELF_CLASS::ELFCLASS64)) + .export_values(); + + + py::enum_(m, "ELF_DATA") + .value(PY_ENUM(ELF_DATA::ELFDATANONE)) + .value(PY_ENUM(ELF_DATA::ELFDATA2LSB)) + .value(PY_ENUM(ELF_DATA::ELFDATA2MSB)) + .export_values(); + + py::enum_(m, "OS_ABI") + .value(PY_ENUM(OS_ABI::ELFOSABI_SYSTEMV)) + .value(PY_ENUM(OS_ABI::ELFOSABI_HPUX)) + .value(PY_ENUM(OS_ABI::ELFOSABI_NETBSD)) + .value(PY_ENUM(OS_ABI::ELFOSABI_GNU)) + .value(PY_ENUM(OS_ABI::ELFOSABI_LINUX)) + .value(PY_ENUM(OS_ABI::ELFOSABI_HURD)) + .value(PY_ENUM(OS_ABI::ELFOSABI_SOLARIS)) + .value(PY_ENUM(OS_ABI::ELFOSABI_AIX)) + .value(PY_ENUM(OS_ABI::ELFOSABI_IRIX)) + .value(PY_ENUM(OS_ABI::ELFOSABI_FREEBSD)) + .value(PY_ENUM(OS_ABI::ELFOSABI_TRU64)) + .value(PY_ENUM(OS_ABI::ELFOSABI_MODESTO)) + .value(PY_ENUM(OS_ABI::ELFOSABI_OPENBSD)) + .value(PY_ENUM(OS_ABI::ELFOSABI_OPENVMS)) + .value(PY_ENUM(OS_ABI::ELFOSABI_NSK)) + .value(PY_ENUM(OS_ABI::ELFOSABI_AROS)) + .value(PY_ENUM(OS_ABI::ELFOSABI_FENIXOS)) + .value(PY_ENUM(OS_ABI::ELFOSABI_CLOUDABI)) + .value(PY_ENUM(OS_ABI::ELFOSABI_C6000_ELFABI)) + .value(PY_ENUM(OS_ABI::ELFOSABI_AMDGPU_HSA)) + .value(PY_ENUM(OS_ABI::ELFOSABI_C6000_LINUX)) + .value(PY_ENUM(OS_ABI::ELFOSABI_ARM)) + .value(PY_ENUM(OS_ABI::ELFOSABI_STANDALONE)) + .export_values(); + + // Enum for the *e_type* of ElfXX_Ehdr + py::enum_(m, "E_TYPE") + .value(PY_ENUM(E_TYPE::ET_NONE)) + .value(PY_ENUM(E_TYPE::ET_REL)) + .value(PY_ENUM(E_TYPE::ET_EXEC)) + .value(PY_ENUM(E_TYPE::ET_DYN)) + .value(PY_ENUM(E_TYPE::ET_CORE)) + .value(PY_ENUM(E_TYPE::ET_LOPROC)) + .value(PY_ENUM(E_TYPE::ET_HIPROC)) + .export_values(); + + //! Enum for the *e_version* of ElfXX_Ehdr; + py::enum_(m, "VERSION") + .value(PY_ENUM(VERSION::EV_NONE)) + .value(PY_ENUM(VERSION::EV_CURRENT)) + .export_values(); + + // Enum for the *e_machine* of ElfXX_Ehdr + py::enum_(m, "ARCH") + .value(PY_ENUM(ARCH::EM_NONE)) + .value(PY_ENUM(ARCH::EM_M32)) + .value(PY_ENUM(ARCH::EM_SPARC)) + .value(PY_ENUM(ARCH::EM_386)) + .value(PY_ENUM(ARCH::EM_68K)) + .value(PY_ENUM(ARCH::EM_88K)) + .value(PY_ENUM(ARCH::EM_IAMCU)) + .value(PY_ENUM(ARCH::EM_860)) + .value(PY_ENUM(ARCH::EM_MIPS)) + .value(PY_ENUM(ARCH::EM_S370)) + .value(PY_ENUM(ARCH::EM_MIPS_RS3_LE)) + .value(PY_ENUM(ARCH::EM_PARISC)) + .value(PY_ENUM(ARCH::EM_VPP500)) + .value(PY_ENUM(ARCH::EM_NONE)) + .value(PY_ENUM(ARCH::EM_960)) + .value(PY_ENUM(ARCH::EM_PPC)) + .value(PY_ENUM(ARCH::EM_PPC64)) + .value(PY_ENUM(ARCH::EM_S390)) + .value(PY_ENUM(ARCH::EM_SPU)) + .value(PY_ENUM(ARCH::EM_V800)) + .value(PY_ENUM(ARCH::EM_FR20)) + .value(PY_ENUM(ARCH::EM_RH32)) + .value(PY_ENUM(ARCH::EM_RCE)) + .value(PY_ENUM(ARCH::EM_ARM)) + .value(PY_ENUM(ARCH::EM_ALPHA)) + .value(PY_ENUM(ARCH::EM_SH)) + .value(PY_ENUM(ARCH::EM_SPARCV9)) + .value(PY_ENUM(ARCH::EM_TRICORE)) + .value(PY_ENUM(ARCH::EM_ARC)) + .value(PY_ENUM(ARCH::EM_H8_300)) + .value(PY_ENUM(ARCH::EM_H8_300H)) + .value(PY_ENUM(ARCH::EM_H8S)) + .value(PY_ENUM(ARCH::EM_H8_500)) + .value(PY_ENUM(ARCH::EM_IA_64)) + .value(PY_ENUM(ARCH::EM_MIPS_X)) + .value(PY_ENUM(ARCH::EM_COLDFIRE)) + .value(PY_ENUM(ARCH::EM_68HC12)) + .value(PY_ENUM(ARCH::EM_MMA)) + .value(PY_ENUM(ARCH::EM_PCP)) + .value(PY_ENUM(ARCH::EM_NCPU)) + .value(PY_ENUM(ARCH::EM_NDR1)) + .value(PY_ENUM(ARCH::EM_STARCORE)) + .value(PY_ENUM(ARCH::EM_ME16)) + .value(PY_ENUM(ARCH::EM_ST100)) + .value(PY_ENUM(ARCH::EM_TINYJ)) + .value(PY_ENUM(ARCH::EM_X86_64)) + .value(PY_ENUM(ARCH::EM_PDSP)) + .value(PY_ENUM(ARCH::EM_PDP10)) + .value(PY_ENUM(ARCH::EM_PDP11)) + .value(PY_ENUM(ARCH::EM_FX66)) + .value(PY_ENUM(ARCH::EM_ST9PLUS)) + .value(PY_ENUM(ARCH::EM_ST7)) + .value(PY_ENUM(ARCH::EM_68HC16)) + .value(PY_ENUM(ARCH::EM_68HC11)) + .value(PY_ENUM(ARCH::EM_68HC08)) + .value(PY_ENUM(ARCH::EM_68HC05)) + .value(PY_ENUM(ARCH::EM_SVX)) + .value(PY_ENUM(ARCH::EM_ST19)) + .value(PY_ENUM(ARCH::EM_VAX)) + .value(PY_ENUM(ARCH::EM_CRIS)) + .value(PY_ENUM(ARCH::EM_JAVELIN)) + .value(PY_ENUM(ARCH::EM_FIREPATH)) + .value(PY_ENUM(ARCH::EM_ZSP)) + .value(PY_ENUM(ARCH::EM_MMIX)) + .value(PY_ENUM(ARCH::EM_HUANY)) + .value(PY_ENUM(ARCH::EM_PRISM)) + .value(PY_ENUM(ARCH::EM_AVR)) + .value(PY_ENUM(ARCH::EM_FR30)) + .value(PY_ENUM(ARCH::EM_D10V)) + .value(PY_ENUM(ARCH::EM_D30V)) + .value(PY_ENUM(ARCH::EM_V850)) + .value(PY_ENUM(ARCH::EM_M32R)) + .value(PY_ENUM(ARCH::EM_MN10300)) + .value(PY_ENUM(ARCH::EM_MN10200)) + .value(PY_ENUM(ARCH::EM_PJ)) + .value(PY_ENUM(ARCH::EM_OPENRISC)) + .value(PY_ENUM(ARCH::EM_ARC_COMPACT)) + .value(PY_ENUM(ARCH::EM_XTENSA)) + .value(PY_ENUM(ARCH::EM_VIDEOCORE)) + .value(PY_ENUM(ARCH::EM_TMM_GPP)) + .value(PY_ENUM(ARCH::EM_NS32K)) + .value(PY_ENUM(ARCH::EM_TPC)) + .value(PY_ENUM(ARCH::EM_SNP1K)) + .value(PY_ENUM(ARCH::EM_ST200)) + .value(PY_ENUM(ARCH::EM_IP2K)) + .value(PY_ENUM(ARCH::EM_MAX)) + .value(PY_ENUM(ARCH::EM_CR)) + .value(PY_ENUM(ARCH::EM_F2MC16)) + .value(PY_ENUM(ARCH::EM_MSP430)) + .value(PY_ENUM(ARCH::EM_BLACKFIN)) + .value(PY_ENUM(ARCH::EM_SE_C33)) + .value(PY_ENUM(ARCH::EM_SEP)) + .value(PY_ENUM(ARCH::EM_ARCA)) + .value(PY_ENUM(ARCH::EM_UNICORE)) + .value(PY_ENUM(ARCH::EM_EXCESS)) + .value(PY_ENUM(ARCH::EM_DXP)) + .value(PY_ENUM(ARCH::EM_ALTERA_NIOS2)) + .value(PY_ENUM(ARCH::EM_CRX)) + .value(PY_ENUM(ARCH::EM_XGATE)) + .value(PY_ENUM(ARCH::EM_C166)) + .value(PY_ENUM(ARCH::EM_M16C)) + .value(PY_ENUM(ARCH::EM_DSPIC30F)) + .value(PY_ENUM(ARCH::EM_CE)) + .value(PY_ENUM(ARCH::EM_M32C)) + .value(PY_ENUM(ARCH::EM_TSK3000)) + .value(PY_ENUM(ARCH::EM_RS08)) + .value(PY_ENUM(ARCH::EM_SHARC)) + .value(PY_ENUM(ARCH::EM_ECOG2)) + .value(PY_ENUM(ARCH::EM_SCORE7)) + .value(PY_ENUM(ARCH::EM_DSP24)) + .value(PY_ENUM(ARCH::EM_VIDEOCORE3)) + .value(PY_ENUM(ARCH::EM_LATTICEMICO32)) + .value(PY_ENUM(ARCH::EM_SE_C17)) + .value(PY_ENUM(ARCH::EM_TI_C6000)) + .value(PY_ENUM(ARCH::EM_TI_C2000)) + .value(PY_ENUM(ARCH::EM_TI_C5500)) + .value(PY_ENUM(ARCH::EM_MMDSP_PLUS)) + .value(PY_ENUM(ARCH::EM_CYPRESS_M8C)) + .value(PY_ENUM(ARCH::EM_R32C)) + .value(PY_ENUM(ARCH::EM_TRIMEDIA)) + .value(PY_ENUM(ARCH::EM_HEXAGON)) + .value(PY_ENUM(ARCH::EM_8051)) + .value(PY_ENUM(ARCH::EM_STXP7X)) + .value(PY_ENUM(ARCH::EM_NDS32)) + .value(PY_ENUM(ARCH::EM_ECOG1)) + .value(PY_ENUM(ARCH::EM_ECOG1X)) + .value(PY_ENUM(ARCH::EM_MAXQ30)) + .value(PY_ENUM(ARCH::EM_XIMO16)) + .value(PY_ENUM(ARCH::EM_MANIK)) + .value(PY_ENUM(ARCH::EM_CRAYNV2)) + .value(PY_ENUM(ARCH::EM_RX)) + .value(PY_ENUM(ARCH::EM_METAG)) + .value(PY_ENUM(ARCH::EM_MCST_ELBRUS)) + .value(PY_ENUM(ARCH::EM_ECOG16)) + .value(PY_ENUM(ARCH::EM_CR16)) + .value(PY_ENUM(ARCH::EM_ETPU)) + .value(PY_ENUM(ARCH::EM_SLE9X)) + .value(PY_ENUM(ARCH::EM_L10M)) + .value(PY_ENUM(ARCH::EM_K10M)) + .value(PY_ENUM(ARCH::EM_AARCH64)) + .value(PY_ENUM(ARCH::EM_AVR32)) + .value(PY_ENUM(ARCH::EM_STM8)) + .value(PY_ENUM(ARCH::EM_TILE64)) + .value(PY_ENUM(ARCH::EM_TILEPRO)) + .value(PY_ENUM(ARCH::EM_CUDA)) + .value(PY_ENUM(ARCH::EM_TILEGX)) + .value(PY_ENUM(ARCH::EM_CLOUDSHIELD)) + .value(PY_ENUM(ARCH::EM_COREA_1ST)) + .value(PY_ENUM(ARCH::EM_COREA_2ND)) + .value(PY_ENUM(ARCH::EM_ARC_COMPACT2)) + .value(PY_ENUM(ARCH::EM_OPEN8)) + .value(PY_ENUM(ARCH::EM_RL78)) + .value(PY_ENUM(ARCH::EM_VIDEOCORE5)) + .value(PY_ENUM(ARCH::EM_78KOR)) + .value(PY_ENUM(ARCH::EM_56800EX)) + .value(PY_ENUM(ARCH::EM_BA1)) + .value(PY_ENUM(ARCH::EM_BA2)) + .value(PY_ENUM(ARCH::EM_XCORE)) + .value(PY_ENUM(ARCH::EM_MCHP_PIC)) + .value(PY_ENUM(ARCH::EM_INTEL205)) + .value(PY_ENUM(ARCH::EM_INTEL206)) + .value(PY_ENUM(ARCH::EM_INTEL207)) + .value(PY_ENUM(ARCH::EM_INTEL208)) + .value(PY_ENUM(ARCH::EM_INTEL209)) + .value(PY_ENUM(ARCH::EM_KM32)) + .value(PY_ENUM(ARCH::EM_KMX32)) + .value(PY_ENUM(ARCH::EM_KMX16)) + .value(PY_ENUM(ARCH::EM_KMX8)) + .value(PY_ENUM(ARCH::EM_KVARC)) + .value(PY_ENUM(ARCH::EM_CDP)) + .value(PY_ENUM(ARCH::EM_COGE)) + .value(PY_ENUM(ARCH::EM_COOL)) + .value(PY_ENUM(ARCH::EM_NORC)) + .value(PY_ENUM(ARCH::EM_CSR_KALIMBA)) + .value(PY_ENUM(ARCH::EM_AMDGPU)) + .export_values(); + + + //! Enum for the *sh_type* of ElfXX_Shdr; + py::enum_(m, "SECTION_TYPES") + .value(PY_ENUM(SECTION_TYPES::SHT_NULL)) + .value(PY_ENUM(SECTION_TYPES::SHT_PROGBITS)) + .value(PY_ENUM(SECTION_TYPES::SHT_SYMTAB)) + .value(PY_ENUM(SECTION_TYPES::SHT_STRTAB)) + .value(PY_ENUM(SECTION_TYPES::SHT_RELA)) + .value(PY_ENUM(SECTION_TYPES::SHT_HASH)) + .value(PY_ENUM(SECTION_TYPES::SHT_DYNAMIC)) + .value(PY_ENUM(SECTION_TYPES::SHT_NOTE)) + .value(PY_ENUM(SECTION_TYPES::SHT_NOBITS)) + .value(PY_ENUM(SECTION_TYPES::SHT_REL)) + .value(PY_ENUM(SECTION_TYPES::SHT_SHLIB)) + .value(PY_ENUM(SECTION_TYPES::SHT_DYNSYM)) + .value(PY_ENUM(SECTION_TYPES::SHT_INIT_ARRAY)) + .value(PY_ENUM(SECTION_TYPES::SHT_FINI_ARRAY)) + .value(PY_ENUM(SECTION_TYPES::SHT_PREINIT_ARRAY)) + .value(PY_ENUM(SECTION_TYPES::SHT_GROUP)) + .value(PY_ENUM(SECTION_TYPES::SHT_SYMTAB_SHNDX)) + .value(PY_ENUM(SECTION_TYPES::SHT_LOOS)) + .value(PY_ENUM(SECTION_TYPES::SHT_GNU_ATTRIBUTES)) + .value(PY_ENUM(SECTION_TYPES::SHT_GNU_HASH)) + .value(PY_ENUM(SECTION_TYPES::SHT_GNU_verdef)) + .value(PY_ENUM(SECTION_TYPES::SHT_GNU_verneed)) + .value(PY_ENUM(SECTION_TYPES::SHT_GNU_versym)) + .value(PY_ENUM(SECTION_TYPES::SHT_HIOS)) + .value(PY_ENUM(SECTION_TYPES::SHT_LOPROC)) + .value(PY_ENUM(SECTION_TYPES::SHT_ARM_EXIDX)) + .value(PY_ENUM(SECTION_TYPES::SHT_ARM_PREEMPTMAP)) + .value(PY_ENUM(SECTION_TYPES::SHT_ARM_ATTRIBUTES)) + .value(PY_ENUM(SECTION_TYPES::SHT_ARM_DEBUGOVERLAY)) + .value(PY_ENUM(SECTION_TYPES::SHT_ARM_OVERLAYSECTION)) + .value(PY_ENUM(SECTION_TYPES::SHT_HEX_ORDERED)) + .value(PY_ENUM(SECTION_TYPES::SHT_X86_64_UNWIND)) + .value(PY_ENUM(SECTION_TYPES::SHT_MIPS_REGINFO)) + .value(PY_ENUM(SECTION_TYPES::SHT_MIPS_OPTIONS)) + .value(PY_ENUM(SECTION_TYPES::SHT_MIPS_ABIFLAGS)) + .value(PY_ENUM(SECTION_TYPES::SHT_HIPROC)) + .value(PY_ENUM(SECTION_TYPES::SHT_LOUSER)) + .value(PY_ENUM(SECTION_TYPES::SHT_HIUSER)) + .export_values(); + + + //! Enum for the *sh_flags* field of ElfXX_Shdr; + py::enum_(m, "SECTION_FLAGS", py::arithmetic()) + .value(PY_ENUM(SECTION_FLAGS::SHF_NONE)) + .value(PY_ENUM(SECTION_FLAGS::SHF_WRITE)) + .value(PY_ENUM(SECTION_FLAGS::SHF_ALLOC)) + .value(PY_ENUM(SECTION_FLAGS::SHF_EXECINSTR)) + .value(PY_ENUM(SECTION_FLAGS::SHF_MERGE)) + .value(PY_ENUM(SECTION_FLAGS::SHF_STRINGS)) + .value(PY_ENUM(SECTION_FLAGS::SHF_INFO_LINK)) + .value(PY_ENUM(SECTION_FLAGS::SHF_LINK_ORDER)) + .value(PY_ENUM(SECTION_FLAGS::SHF_OS_NONCONFORMING)) + .value(PY_ENUM(SECTION_FLAGS::SHF_GROUP)) + .value(PY_ENUM(SECTION_FLAGS::SHF_TLS)) + .value(PY_ENUM(SECTION_FLAGS::SHF_EXCLUDE)) + .value(PY_ENUM(SECTION_FLAGS::XCORE_SHF_CP_SECTION)) + .value(PY_ENUM(SECTION_FLAGS::XCORE_SHF_DP_SECTION)) + .value(PY_ENUM(SECTION_FLAGS::SHF_MASKOS)) + .value(PY_ENUM(SECTION_FLAGS::SHF_MASKPROC)) + .value(PY_ENUM(SECTION_FLAGS::SHF_HEX_GPREL)) + .value(PY_ENUM(SECTION_FLAGS::SHF_MIPS_NODUPES)) + .value(PY_ENUM(SECTION_FLAGS::SHF_MIPS_NAMES)) + .value(PY_ENUM(SECTION_FLAGS::SHF_MIPS_LOCAL)) + .value(PY_ENUM(SECTION_FLAGS::SHF_MIPS_NOSTRIP)) + .value(PY_ENUM(SECTION_FLAGS::SHF_MIPS_GPREL)) + .value(PY_ENUM(SECTION_FLAGS::SHF_MIPS_MERGE)) + .value(PY_ENUM(SECTION_FLAGS::SHF_MIPS_ADDR)) + .value(PY_ENUM(SECTION_FLAGS::SHF_MIPS_STRING)) + .export_values(); + + + //! Enum for the *p_type* field of ElfXX_Phdr + py::enum_(m, "SEGMENT_TYPES") + .value(PY_ENUM(SEGMENT_TYPES::PT_NULL)) + .value(PY_ENUM(SEGMENT_TYPES::PT_LOAD)) + .value(PY_ENUM(SEGMENT_TYPES::PT_DYNAMIC)) + .value(PY_ENUM(SEGMENT_TYPES::PT_INTERP)) + .value(PY_ENUM(SEGMENT_TYPES::PT_NOTE)) + .value(PY_ENUM(SEGMENT_TYPES::PT_SHLIB)) + .value(PY_ENUM(SEGMENT_TYPES::PT_PHDR)) + .value(PY_ENUM(SEGMENT_TYPES::PT_TLS)) + .value(PY_ENUM(SEGMENT_TYPES::PT_LOOS)) + .value(PY_ENUM(SEGMENT_TYPES::PT_HIOS)) + .value(PY_ENUM(SEGMENT_TYPES::PT_LOPROC)) + .value(PY_ENUM(SEGMENT_TYPES::PT_HIPROC)) + .value(PY_ENUM(SEGMENT_TYPES::PT_GNU_EH_FRAME)) + .value(PY_ENUM(SEGMENT_TYPES::PT_SUNW_EH_FRAME)) + .value(PY_ENUM(SEGMENT_TYPES::PT_SUNW_UNWIND)) + .value(PY_ENUM(SEGMENT_TYPES::PT_GNU_STACK)) + .value(PY_ENUM(SEGMENT_TYPES::PT_GNU_RELRO)) + .value(PY_ENUM(SEGMENT_TYPES::PT_ARM_ARCHEXT)) + .value(PY_ENUM(SEGMENT_TYPES::PT_ARM_EXIDX)) + .value(PY_ENUM(SEGMENT_TYPES::PT_ARM_UNWIND)) + .value(PY_ENUM(SEGMENT_TYPES::PT_MIPS_REGINFO)) + .value(PY_ENUM(SEGMENT_TYPES::PT_MIPS_RTPROC)) + .value(PY_ENUM(SEGMENT_TYPES::PT_MIPS_OPTIONS)) + .value(PY_ENUM(SEGMENT_TYPES::PT_MIPS_ABIFLAGS)) + .export_values(); + + //! Enum for the *p_flags* field of ElfXX_Phdr + py::enum_(m, "SEGMENT_FLAGS", py::arithmetic()) + .value("PF_X", SEGMENT_FLAGS::PF_X) + .value("PF_W", SEGMENT_FLAGS::PF_W) + .value("PF_R", SEGMENT_FLAGS::PF_R) + .value("PF_MASKOS", SEGMENT_FLAGS::PF_MASKOS) + .value("PF_MASKPROC", SEGMENT_FLAGS::PF_MASKPROC) + .export_values(); + + + + py::enum_(m, "DYNAMIC_TAGS") + .value(PY_ENUM(DYNAMIC_TAGS::DT_NULL)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_NEEDED)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_PLTRELSZ)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_PLTGOT)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_HASH)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_STRTAB)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_SYMTAB)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_RELA)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_RELASZ)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_RELAENT)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_STRSZ)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_SYMENT)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_INIT)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_FINI)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_SONAME)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_RPATH)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_SYMBOLIC)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_REL)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_RELSZ)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_RELENT)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_PLTREL)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_DEBUG)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_TEXTREL)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_JMPREL)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_BIND_NOW)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_INIT_ARRAY)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_FINI_ARRAY)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_INIT_ARRAYSZ)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_FINI_ARRAYSZ)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_RUNPATH)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_FLAGS)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_ENCODING)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_PREINIT_ARRAY)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_PREINIT_ARRAYSZ)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_LOOS)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_HIOS)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_LOPROC)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_HIPROC)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_GNU_HASH)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_RELACOUNT)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_RELCOUNT)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_FLAGS_1)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_VERSYM)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_VERDEF)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_VERDEFNUM)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_VERNEED)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_VERNEEDNUM)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_RLD_VERSION)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_TIME_STAMP)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_ICHECKSUM)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_IVERSION)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_FLAGS)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_BASE_ADDRESS)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_MSYM)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_CONFLICT)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_LIBLIST)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_LOCAL_GOTNO)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_CONFLICTNO)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_LIBLISTNO)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_SYMTABNO)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_UNREFEXTNO)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_GOTSYM)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_HIPAGENO)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_RLD_MAP)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_CLASS)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_CLASS_NO)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_INSTANCE)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_INSTANCE_NO)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_RELOC)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_RELOC_NO)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_SYM)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_SYM_NO)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_CLASSSYM)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DELTA_CLASSSYM_NO)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_CXX_FLAGS)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_PIXIE_INIT)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_SYMBOL_LIB)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_LOCALPAGE_GOTIDX)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_LOCAL_GOTIDX)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_HIDDEN_GOTIDX)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_PROTECTED_GOTIDX)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_OPTIONS)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_INTERFACE)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_DYNSTR_ALIGN)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_INTERFACE_SIZE)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_RLD_TEXT_RESOLVE_ADDR)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_PERF_SUFFIX)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_COMPACT_SIZE)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_GP_VALUE)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_AUX_DYNAMIC)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_PLTGOT)) + .value(PY_ENUM(DYNAMIC_TAGS::DT_MIPS_RWPLT)) + .export_values(); + + + py::enum_(m, "SYMBOL_TYPES") + .value(PY_ENUM(SYMBOL_TYPES::STT_NOTYPE)) + .value(PY_ENUM(SYMBOL_TYPES::STT_OBJECT)) + .value(PY_ENUM(SYMBOL_TYPES::STT_FUNC)) + .value(PY_ENUM(SYMBOL_TYPES::STT_SECTION)) + .value(PY_ENUM(SYMBOL_TYPES::STT_FILE)) + .value(PY_ENUM(SYMBOL_TYPES::STT_COMMON)) + .value(PY_ENUM(SYMBOL_TYPES::STT_TLS)) + .value(PY_ENUM(SYMBOL_TYPES::STT_GNU_IFUNC)) + .value(PY_ENUM(SYMBOL_TYPES::STT_LOOS)) + .value(PY_ENUM(SYMBOL_TYPES::STT_HIOS)) + .value(PY_ENUM(SYMBOL_TYPES::STT_LOPROC)) + .value(PY_ENUM(SYMBOL_TYPES::STT_HIPROC)) + .export_values(); + + + py::enum_(m, "SYMBOL_BINDINGS") + .value(PY_ENUM(SYMBOL_BINDINGS::STB_LOCAL)) + .value(PY_ENUM(SYMBOL_BINDINGS::STB_GLOBAL)) + .value(PY_ENUM(SYMBOL_BINDINGS::STB_WEAK)) + .value(PY_ENUM(SYMBOL_BINDINGS::STB_GNU_UNIQUE)) + .value(PY_ENUM(SYMBOL_BINDINGS::STB_LOOS)) + .value(PY_ENUM(SYMBOL_BINDINGS::STB_HIOS)) + .value(PY_ENUM(SYMBOL_BINDINGS::STB_LOPROC)) + .value(PY_ENUM(SYMBOL_BINDINGS::STB_HIPROC)) + .export_values(); + + + py::enum_(m, "RELOCATION_X86_64") + .value(PY_ENUM(RELOC_x86_64::R_X86_64_NONE)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_PC32)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOT32)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_PLT32)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_COPY)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_GLOB_DAT)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_JUMP_SLOT)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_RELATIVE)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPCREL)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_32)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_32S)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_16)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_PC16)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_8)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_PC8)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_DTPMOD64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_DTPOFF64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_TPOFF64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_TLSGD)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_TLSLD)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_DTPOFF32)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTTPOFF)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_TPOFF32)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_PC64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTOFF64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPC32)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOT64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPCREL64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPC64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPLT64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_PLTOFF64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_SIZE32)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_SIZE64)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_GOTPC32_TLSDESC)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_TLSDESC_CALL)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_TLSDESC)) + .value(PY_ENUM(RELOC_x86_64::R_X86_64_IRELATIVE)) + .export_values(); + + + py::enum_(m, "RELOCATION_ARM") + .value(PY_ENUM(RELOC_ARM::R_ARM_NONE)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PC24)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ABS32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_REL32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_PC_G0)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ABS16)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ABS12)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_ABS5)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ABS8)) + .value(PY_ENUM(RELOC_ARM::R_ARM_SBREL32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_CALL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_PC8)) + .value(PY_ENUM(RELOC_ARM::R_ARM_BREL_ADJ)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_DESC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_SWI8)) + .value(PY_ENUM(RELOC_ARM::R_ARM_XPC25)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_XPC22)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_DTPMOD32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_DTPOFF32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_TPOFF32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_COPY)) + .value(PY_ENUM(RELOC_ARM::R_ARM_GLOB_DAT)) + .value(PY_ENUM(RELOC_ARM::R_ARM_JUMP_SLOT)) + .value(PY_ENUM(RELOC_ARM::R_ARM_RELATIVE)) + .value(PY_ENUM(RELOC_ARM::R_ARM_GOTOFF32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_BASE_PREL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_GOT_BREL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PLT32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_CALL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_JUMP24)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_JUMP24)) + .value(PY_ENUM(RELOC_ARM::R_ARM_BASE_ABS)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PCREL_7_0)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PCREL_15_8)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PCREL_23_15)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_SBREL_11_0_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SBREL_19_12_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SBREL_27_20_CK)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TARGET1)) + .value(PY_ENUM(RELOC_ARM::R_ARM_SBREL31)) + .value(PY_ENUM(RELOC_ARM::R_ARM_V4BX)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TARGET2)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PREL31)) + .value(PY_ENUM(RELOC_ARM::R_ARM_MOVW_ABS_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_MOVT_ABS)) + .value(PY_ENUM(RELOC_ARM::R_ARM_MOVW_PREL_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_MOVT_PREL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVW_ABS_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVT_ABS)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVW_PREL_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVT_PREL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_JUMP19)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_JUMP6)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_ALU_PREL_11_0)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_PC12)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ABS32_NOI)) + .value(PY_ENUM(RELOC_ARM::R_ARM_REL32_NOI)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PC_G0_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PC_G0)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PC_G1_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PC_G1)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_PC_G2)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_PC_G1)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_PC_G2)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_PC_G0)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_PC_G1)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_PC_G2)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_PC_G0)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_PC_G1)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_PC_G2)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SB_G0_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SB_G0)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SB_G1_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SB_G1)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ALU_SB_G2)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_SB_G0)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_SB_G1)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDR_SB_G2)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_SB_G0)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_SB_G1)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDRS_SB_G2)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_SB_G0)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_SB_G1)) + .value(PY_ENUM(RELOC_ARM::R_ARM_LDC_SB_G2)) + .value(PY_ENUM(RELOC_ARM::R_ARM_MOVW_BREL_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_MOVT_BREL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_MOVW_BREL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVW_BREL_NC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVT_BREL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_MOVW_BREL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_GOTDESC)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_CALL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_DESCSEQ)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_TLS_CALL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PLT32_ABS)) + .value(PY_ENUM(RELOC_ARM::R_ARM_GOT_ABS)) + .value(PY_ENUM(RELOC_ARM::R_ARM_GOT_PREL)) + .value(PY_ENUM(RELOC_ARM::R_ARM_GOT_BREL12)) + .value(PY_ENUM(RELOC_ARM::R_ARM_GOTOFF12)) + .value(PY_ENUM(RELOC_ARM::R_ARM_GOTRELAX)) + .value(PY_ENUM(RELOC_ARM::R_ARM_GNU_VTENTRY)) + .value(PY_ENUM(RELOC_ARM::R_ARM_GNU_VTINHERIT)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_JUMP11)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_JUMP8)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_GD32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_LDM32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_LDO32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_IE32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_LE32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_LDO12)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_LE12)) + .value(PY_ENUM(RELOC_ARM::R_ARM_TLS_IE12GP)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_0)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_1)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_2)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_3)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_4)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_5)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_6)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_7)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_8)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_9)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_10)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_11)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_12)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_13)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_14)) + .value(PY_ENUM(RELOC_ARM::R_ARM_PRIVATE_15)) + .value(PY_ENUM(RELOC_ARM::R_ARM_ME_TOO)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_TLS_DESCSEQ16)) + .value(PY_ENUM(RELOC_ARM::R_ARM_THM_TLS_DESCSEQ32)) + .value(PY_ENUM(RELOC_ARM::R_ARM_IRELATIVE)) + .export_values(); + + + py::enum_(m, "RELOCATION_i386") + .value(PY_ENUM(RELOC_i386::R_386_NONE)) + .value(PY_ENUM(RELOC_i386::R_386_32)) + .value(PY_ENUM(RELOC_i386::R_386_PC32)) + .value(PY_ENUM(RELOC_i386::R_386_GOT32)) + .value(PY_ENUM(RELOC_i386::R_386_PLT32)) + .value(PY_ENUM(RELOC_i386::R_386_COPY)) + .value(PY_ENUM(RELOC_i386::R_386_GLOB_DAT)) + .value(PY_ENUM(RELOC_i386::R_386_JUMP_SLOT)) + .value(PY_ENUM(RELOC_i386::R_386_RELATIVE)) + .value(PY_ENUM(RELOC_i386::R_386_GOTOFF)) + .value(PY_ENUM(RELOC_i386::R_386_GOTPC)) + .value(PY_ENUM(RELOC_i386::R_386_32PLT)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_TPOFF)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_IE)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_GOTIE)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_LE)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_GD)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_LDM)) + .value(PY_ENUM(RELOC_i386::R_386_16)) + .value(PY_ENUM(RELOC_i386::R_386_PC16)) + .value(PY_ENUM(RELOC_i386::R_386_8)) + .value(PY_ENUM(RELOC_i386::R_386_PC8)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_GD_32)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_GD_PUSH)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_GD_CALL)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_GD_POP)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_LDM_32)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_LDM_PUSH)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_LDM_CALL)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_LDM_POP)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_LDO_32)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_IE_32)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_LE_32)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_DTPMOD32)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_DTPOFF32)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_TPOFF32)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_GOTDESC)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_DESC_CALL)) + .value(PY_ENUM(RELOC_i386::R_386_TLS_DESC)) + .value(PY_ENUM(RELOC_i386::R_386_IRELATIVE)) + .value(PY_ENUM(RELOC_i386::R_386_NUM)) + .export_values(); +} diff --git a/api/python/MANIFEST.in.in b/api/python/MANIFEST.in.in new file mode 100644 index 0000000..5c82446 --- /dev/null +++ b/api/python/MANIFEST.in.in @@ -0,0 +1 @@ +include README diff --git a/api/python/MachO/CMakeLists.txt b/api/python/MachO/CMakeLists.txt new file mode 100644 index 0000000..1e02634 --- /dev/null +++ b/api/python/MachO/CMakeLists.txt @@ -0,0 +1,18 @@ +set(LIEF_PYTHON_MACHO_SRC + ${CMAKE_CURRENT_LIST_DIR}/pyMachO.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyDylibCommand.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyBinary.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyLoadCommand.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySegmentCommand.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyHeader.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySection.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyParser.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySymbol.cpp + ${CMAKE_CURRENT_LIST_DIR}/pyMachOStructures.cpp +) + +target_include_directories(pyLIEF PUBLIC ${CMAKE_CURRENT_LIST_DIR}) +target_sources(pyLIEF PRIVATE ${LIEF_PYTHON_MACHO_SRC}) + + + diff --git a/api/python/MachO/objects/pyBinary.cpp b/api/python/MachO/objects/pyBinary.cpp new file mode 100644 index 0000000..80ffe7c --- /dev/null +++ b/api/python/MachO/objects/pyBinary.cpp @@ -0,0 +1,108 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 + +#include "LIEF/Abstract/Binary.hpp" +#include "LIEF/MachO/Binary.hpp" + +#include "pyMachO.hpp" + +template +using no_const_getter = T (Binary::*)(void); + +void init_MachO_Binary_class(py::module& m) { + + + py::class_(m, "Binary") + .def_property_readonly("header", + static_cast>(&Binary::header), + "Return binary's " RST_CLASS_REF(lief.MachO.Header) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("sections", + static_cast>(&Binary::sections), + "Return binary's " RST_CLASS_REF(lief.MachO.Section) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("segments", + static_cast>(&Binary::segments), + "Return binary's " RST_CLASS_REF(lief.MachO.SegmentCommand) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("libraries", + static_cast>(&Binary::libraries), + "Return binary's " RST_CLASS_REF(lief.MachO.DylibCommand) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("symbols", + static_cast>(&Binary::symbols), + "Return binary's " RST_CLASS_REF(lief.MachO.Symbol) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("imported_symbols", + static_cast>(&Binary::get_imported_symbols), + "Return binary's " RST_CLASS_REF(lief.MachO.Symbol) " which are imported", + py::return_value_policy::reference_internal) + + .def_property_readonly("exported_symbols", + static_cast>(&Binary::get_exported_symbols), + "Return binary's " RST_CLASS_REF(lief.MachO.Symbol) " which are exported", + py::return_value_policy::reference_internal) + + .def_property_readonly("commands", + static_cast>(&Binary::commands), + "Return binary's " RST_CLASS_REF(lief.MachO.Command) "", + py::return_value_policy::reference_internal) + + .def_property_readonly("imagebase", + &Binary::imagebase, + "Return binary's ``image base`` which is the base address\ + where segments are mapped (without PIE)", + py::return_value_policy::reference_internal) + + .def("section_from_offset", + static_cast(&Binary::section_from_offset), + "Return the " RST_CLASS_REF(lief.MachO.Section) " which contains the offset", + py::return_value_policy::reference) + + .def("segment_from_offset", + static_cast(&Binary::segment_from_offset), + "Return the " RST_CLASS_REF(lief.MachO.SegmentCommand) " which contains the offset", + py::return_value_policy::reference) + + .def("segment_from_virtual_address", + static_cast(&Binary::segment_from_virtual_address), + "Return the " RST_CLASS_REF(lief.MachO.SegmentCommand) " which contains the (relative) virtual address", + py::return_value_policy::reference) + + + + .def_property_readonly("entrypoint", + &Binary::entrypoint, + "Return binary's entrypoint", + py::return_value_policy::reference_internal) + + .def("__str__", + [] (const Binary& binary) + { + std::ostringstream stream; + stream << binary; + std::string str = stream.str(); + return str; + }); + +} + diff --git a/api/python/MachO/objects/pyDylibCommand.cpp b/api/python/MachO/objects/pyDylibCommand.cpp new file mode 100644 index 0000000..ec5beac --- /dev/null +++ b/api/python/MachO/objects/pyDylibCommand.cpp @@ -0,0 +1,78 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 + +#include +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/MachO/DylibCommand.hpp" + +#include "pyMachO.hpp" + +template +using getter_t = T (DylibCommand::*)(void) const; + +template +using setter_t = void (DylibCommand::*)(T); + + +void init_MachO_DylibCommand_class(py::module& m) { + + py::class_(m, "DylibCommand") + .def_property("name", + static_cast>(&DylibCommand::name), + static_cast>(&DylibCommand::name), + "Library's name", + py::return_value_policy::reference_internal) + + .def_property("timestamp", + static_cast>(&DylibCommand::timestamp), + static_cast>(&DylibCommand::timestamp), + "Library's timestamp", + py::return_value_policy::reference_internal) + + .def_property("current_version", + static_cast>(&DylibCommand::current_version), + static_cast>(&DylibCommand::current_version), + "Library's current version", + py::return_value_policy::reference_internal) + + .def_property("compatibility_version", + static_cast>(&DylibCommand::compatibility_version), + static_cast>(&DylibCommand::compatibility_version), + "Library's compatibility version", + py::return_value_policy::reference_internal) + + + .def("__eq__", &DylibCommand::operator==) + .def("__ne__", &DylibCommand::operator!=) + .def("__hash__", + [] (const DylibCommand& dylib_command) { + return LIEF::Hash::hash(dylib_command); + }) + + + .def("__str__", + [] (const DylibCommand& command) + { + std::ostringstream stream; + stream << command; + std::string str = stream.str(); + return str; + }); + +} diff --git a/api/python/MachO/objects/pyHeader.cpp b/api/python/MachO/objects/pyHeader.cpp new file mode 100644 index 0000000..b2afc73 --- /dev/null +++ b/api/python/MachO/objects/pyHeader.cpp @@ -0,0 +1,93 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/MachO/Header.hpp" + +#include "pyMachO.hpp" + +template +using getter_t = T (Header::*)(void) const; + +template +using setter_t = void (Header::*)(T); + +void init_MachO_Header_class(py::module& m) { + + py::class_
(m, "Header") + .def(py::init<>()) + + .def_property("magic", + static_cast>(&Header::magic), + static_cast>(&Header::magic), + "" + ) + + .def_property("cpu_type", + static_cast>(&Header::cpu_type), + static_cast>(&Header::cpu_type), + "Target CPU ( " RST_CLASS_REF(lief.MachO.CPU_TYPES) ")") + + .def_property("cpu_subtype", + static_cast>(&Header::cpu_subtype), + static_cast>(&Header::cpu_subtype), + "CPU subtype") + + .def_property("file_type", + static_cast>(&Header::file_type), + static_cast>(&Header::file_type), + "Binary's type ( " RST_CLASS_REF(lief.MachO.FILE_TYPES) ")") + + .def_property("flags", + &Header::flags_list, + static_cast>(&Header::flags), + "Binary's flags ( " RST_CLASS_REF(lief.MachO.HEADER_FLAGS) ")") + + .def_property("nb_cmds", + static_cast>(&Header::nb_cmds), + static_cast>(&Header::nb_cmds), + "Number of " RST_CLASS_REF(lief.MachO.LoadCommand) "") + + .def_property("sizeof_cmds", + static_cast>(&Header::sizeof_cmds), + static_cast>(&Header::sizeof_cmds), + "Size of all " RST_CLASS_REF(lief.MachO.LoadCommand) "") + + .def_property("reserved", + static_cast>(&Header::reserved), + static_cast>(&Header::reserved), + "") + + + .def("__eq__", &Header::operator==) + .def("__ne__", &Header::operator!=) + .def("__hash__", + [] (const Header& header) { + return LIEF::Hash::hash(header); + }) + + + .def("__str__", + [] (const Header& header) + { + std::ostringstream stream; + stream << header; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/MachO/objects/pyLoadCommand.cpp b/api/python/MachO/objects/pyLoadCommand.cpp new file mode 100644 index 0000000..6af7f77 --- /dev/null +++ b/api/python/MachO/objects/pyLoadCommand.cpp @@ -0,0 +1,72 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/MachO/LoadCommand.hpp" + +#include "pyMachO.hpp" + + +template +using getter_t = T (LoadCommand::*)(void) const; + +template +using setter_t = void (LoadCommand::*)(T); + +void init_MachO_LoadCommand_class(py::module& m) { + + py::class_(m, "LoadCommand") + .def(py::init<>()) + + .def_property("command", + static_cast>(&LoadCommand::command), + static_cast>(&LoadCommand::command), + "Command type ( " RST_CLASS_REF(lief.MachO.LOAD_COMMAND_TYPES) ")" + ) + + .def_property("size", + static_cast>(&LoadCommand::size), + static_cast>(&LoadCommand::size), + "Command size") + + .def_property("data", + static_cast&>>(&LoadCommand::data), + static_cast&>>(&LoadCommand::data), + "Command's data") + + .def_property("command_offset", + static_cast>(&LoadCommand::command_offset), + static_cast>(&LoadCommand::command_offset), + "Offset to the comand") + + .def("__eq__", &LoadCommand::operator==) + .def("__ne__", &LoadCommand::operator!=) + .def("__hash__", + [] (const LoadCommand& load_command) { + return LIEF::Hash::hash(load_command); + }) + + .def("__str__", + [] (const LoadCommand& command) + { + std::ostringstream stream; + stream << command; + std::string str = stream.str(); + return str; + }); +} diff --git a/api/python/MachO/objects/pyParser.cpp b/api/python/MachO/objects/pyParser.cpp new file mode 100644 index 0000000..ceec89c --- /dev/null +++ b/api/python/MachO/objects/pyParser.cpp @@ -0,0 +1,29 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/MachO/Parser.hpp" + +#include "pyMachO.hpp" + +void init_MachO_Parser_class(py::module& m) { + + // Parser (Parser) + m.def("parse", + &LIEF::MachO::Parser::parse, + py::return_value_policy::take_ownership); +} diff --git a/api/python/MachO/objects/pySection.cpp b/api/python/MachO/objects/pySection.cpp new file mode 100644 index 0000000..f7a842b --- /dev/null +++ b/api/python/MachO/objects/pySection.cpp @@ -0,0 +1,78 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/MachO/Section.hpp" + +#include "pyMachO.hpp" + + + +template +using getter_t = T (Section::*)(void) const; + +template +using setter_t = void (Section::*)(T); + +void init_MachO_Section_class(py::module& m) { + + py::class_(m, "Section") + .def(py::init<>()) + + .def_property("alignment", + static_cast>(&Section::alignment), + static_cast>(&Section::alignment), + "Section's alignment ") + + .def_property("relocation_offset", + static_cast>(&Section::relocation_offset), + static_cast>(&Section::relocation_offset), + "") + + .def_property("numberof_relocations", + static_cast>(&Section::numberof_relocations), + static_cast>(&Section::numberof_relocations), + "") + + .def_property("type", + static_cast>(&Section::type), + static_cast>(&Section::type), + "") + + + .def("__eq__", &Section::operator==) + .def("__ne__", &Section::operator!=) + .def("__hash__", + [] (const Section& section) { + return LIEF::Hash::hash(section); + }) + + + .def("__str__", + [] (const Section& section) + { + std::ostringstream stream; + stream << section; + std::string str = stream.str(); + return str; + }); + +} + + + diff --git a/api/python/MachO/objects/pySegmentCommand.cpp b/api/python/MachO/objects/pySegmentCommand.cpp new file mode 100644 index 0000000..3df7239 --- /dev/null +++ b/api/python/MachO/objects/pySegmentCommand.cpp @@ -0,0 +1,125 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyMachO.hpp" + + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/MachO/SegmentCommand.hpp" + +#include +#include + +template +using getter_t = T (SegmentCommand::*)(void) const; + +template +using setter_t = void (SegmentCommand::*)(T); + +template +using no_const_getter = T (SegmentCommand::*)(void); + +void init_MachO_SegmentCommand_class(py::module& m) { + + py::class_(m, "SegmentCommand") + .def(py::init<>()) + + .def_property("name", + static_cast>(&SegmentCommand::name), + static_cast>(&SegmentCommand::name), + "Segment's name" + ) + + .def_property("virtual_address", + static_cast>(&SegmentCommand::virtual_address), + static_cast>(&SegmentCommand::virtual_address), + "Segment's virtual address" + ) + + .def_property("virtual_size", + static_cast>(&SegmentCommand::virtual_size), + static_cast>(&SegmentCommand::virtual_size), + "Segment's virtual size" + ) + + .def_property("virtual_size", + static_cast>(&SegmentCommand::virtual_size), + static_cast>(&SegmentCommand::virtual_size), + "Segment's virtual size" + ) + + .def_property("file_size", + static_cast>(&SegmentCommand::file_size), + static_cast>(&SegmentCommand::file_size), + "Segment's file size" + ) + + .def_property("file_offset", + static_cast>(&SegmentCommand::file_offset), + static_cast>(&SegmentCommand::file_offset), + "Segment's file offset" + ) + + .def_property("max_protection", + static_cast>(&SegmentCommand::max_protection), + static_cast>(&SegmentCommand::max_protection), + "Segment's max protection" + ) + + .def_property("init_protection", + static_cast>(&SegmentCommand::init_protection), + static_cast>(&SegmentCommand::init_protection), + "Segment's initial protection" + ) + + .def_property("numberof_sections", + static_cast>(&SegmentCommand::numberof_sections), + static_cast>(&SegmentCommand::numberof_sections), + "Number of sections in this segment" + ) + + .def_property_readonly("sections", + static_cast>(&SegmentCommand::sections), + "Segment's sections" + ) + + .def_property("content", + static_cast&>>(&SegmentCommand::content), + static_cast&>>(&SegmentCommand::content), + "Segment's content" + ) + + + .def("__eq__", &SegmentCommand::operator==) + .def("__ne__", &SegmentCommand::operator!=) + .def("__hash__", + [] (const SegmentCommand& segment_command) { + return LIEF::Hash::hash(segment_command); + }) + + + .def("__str__", + [] (const Header& header) + { + std::ostringstream stream; + stream << header; + std::string str = stream.str(); + return str; + }); + +} + + + diff --git a/api/python/MachO/objects/pySymbol.cpp b/api/python/MachO/objects/pySymbol.cpp new file mode 100644 index 0000000..beea42c --- /dev/null +++ b/api/python/MachO/objects/pySymbol.cpp @@ -0,0 +1,72 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/MachO/Section.hpp" + +#include "pyMachO.hpp" + + +template +using getter_t = T (Symbol::*)(void) const; + +template +using setter_t = void (Symbol::*)(T); + +void init_MachO_Symbol_class(py::module& m) { + + py::class_(m, "Symbol") + .def(py::init<>()) + + .def_property("type", + static_cast>(&Symbol::type), + static_cast>(&Symbol::type)) + + .def_property("numberof_sections", + static_cast>(&Symbol::numberof_sections), + static_cast>(&Symbol::numberof_sections)) + + .def_property("description", + static_cast>(&Symbol::description), + static_cast>(&Symbol::description)) + + .def_property("value", + static_cast>(&Symbol::value), + static_cast>(&Symbol::value)) + + .def("__eq__", &Symbol::operator==) + .def("__ne__", &Symbol::operator!=) + .def("__hash__", + [] (const Symbol& symbol) { + return LIEF::Hash::hash(symbol); + }) + + + .def("__str__", + [] (const Symbol& symbol) + { + std::ostringstream stream; + stream << symbol; + std::string str = stream.str(); + return str; + }); + +} + + + diff --git a/api/python/MachO/pyMachO.cpp b/api/python/MachO/pyMachO.cpp new file mode 100644 index 0000000..ec97459 --- /dev/null +++ b/api/python/MachO/pyMachO.cpp @@ -0,0 +1,41 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 + +#include "pyMachO.hpp" + +// +// MachO modules +// +void init_MachO_module(py::module& m) { + py::module LIEF_MachO_module = m.def_submodule("MachO", "Python API for MachO"); + + py::bind_vector>(m, "macho_list"); + + // Objects + init_MachO_Parser_class(LIEF_MachO_module); + init_MachO_Binary_class(LIEF_MachO_module); + init_MachO_Header_class(LIEF_MachO_module); + init_MachO_LoadCommand_class(LIEF_MachO_module); + init_MachO_DylibCommand_class(LIEF_MachO_module); + init_MachO_SegmentCommand_class(LIEF_MachO_module); + init_MachO_Section_class(LIEF_MachO_module); + init_MachO_Symbol_class(LIEF_MachO_module); + + + // Enums + init_MachO_Structures_enum(LIEF_MachO_module); +} diff --git a/api/python/MachO/pyMachO.hpp b/api/python/MachO/pyMachO.hpp new file mode 100644 index 0000000..38c470d --- /dev/null +++ b/api/python/MachO/pyMachO.hpp @@ -0,0 +1,42 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 PY_LIEF_MACHO_H_ +#define PY_LIEF_MACHO_H_ + +#include "LIEF/MachO/Parser.hpp" +#include "LIEF/MachO/Binary.hpp" +#include "LIEF/MachO/Builder.hpp" + +#include "pyLIEF.hpp" + +using namespace LIEF::MachO; + +PYBIND11_MAKE_OPAQUE(std::vector) + +void init_MachO_Parser_class(py::module&); +void init_MachO_Binary_class(py::module&); +void init_MachO_Header_class(py::module&); +void init_MachO_LoadCommand_class(py::module&); +void init_MachO_DylibCommand_class(py::module&); +void init_MachO_SegmentCommand_class(py::module&); +void init_MachO_Section_class(py::module&); +void init_MachO_Symbol_class(py::module&); + +// Enums +void init_MachO_Structures_enum(py::module&); + + +#endif diff --git a/api/python/MachO/pyMachOStructures.cpp b/api/python/MachO/pyMachOStructures.cpp new file mode 100644 index 0000000..2e8f7d8 --- /dev/null +++ b/api/python/MachO/pyMachOStructures.cpp @@ -0,0 +1,159 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyMachO.hpp" +#include "LIEF/MachO/Structures.hpp" +#include "LIEF/MachO/EnumToString.hpp" + +#define PY_ENUM(x) LIEF::MachO::to_string(x), x + +void init_MachO_Structures_enum(py::module& m) { + + py::enum_(m, "CPU_TYPES") + .value(PY_ENUM(LIEF::MachO::CPU_TYPES::CPU_TYPE_ANY)) + .value(PY_ENUM(LIEF::MachO::CPU_TYPES::CPU_TYPE_X86)) + .value(PY_ENUM(LIEF::MachO::CPU_TYPES::CPU_TYPE_I386)) + .value(PY_ENUM(LIEF::MachO::CPU_TYPES::CPU_TYPE_X86_64)) + .value(PY_ENUM(LIEF::MachO::CPU_TYPES::CPU_TYPE_MC98000)) + .value(PY_ENUM(LIEF::MachO::CPU_TYPES::CPU_TYPE_ARM)) + .value(PY_ENUM(LIEF::MachO::CPU_TYPES::CPU_TYPE_ARM64)) + .value(PY_ENUM(LIEF::MachO::CPU_TYPES::CPU_TYPE_SPARC)) + .value(PY_ENUM(LIEF::MachO::CPU_TYPES::CPU_TYPE_POWERPC)) + .value(PY_ENUM(LIEF::MachO::CPU_TYPES::CPU_TYPE_POWERPC64)) + .export_values(); + + py::enum_(m, "FILE_TYPES") + .value(PY_ENUM(LIEF::MachO::FILE_TYPES::MH_OBJECT)) + .value(PY_ENUM(LIEF::MachO::FILE_TYPES::MH_EXECUTE)) + .value(PY_ENUM(LIEF::MachO::FILE_TYPES::MH_FVMLIB)) + .value(PY_ENUM(LIEF::MachO::FILE_TYPES::MH_CORE)) + .value(PY_ENUM(LIEF::MachO::FILE_TYPES::MH_PRELOAD)) + .value(PY_ENUM(LIEF::MachO::FILE_TYPES::MH_DYLIB)) + .value(PY_ENUM(LIEF::MachO::FILE_TYPES::MH_DYLINKER)) + .value(PY_ENUM(LIEF::MachO::FILE_TYPES::MH_BUNDLE)) + .value(PY_ENUM(LIEF::MachO::FILE_TYPES::MH_DYLIB_STUB)) + .value(PY_ENUM(LIEF::MachO::FILE_TYPES::MH_DSYM)) + .value(PY_ENUM(LIEF::MachO::FILE_TYPES::MH_KEXT_BUNDLE)) + .export_values(); + + py::enum_(m, "HEADER_FLAGS") + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_NOUNDEFS)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_INCRLINK)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_DYLDLINK)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_BINDATLOAD)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_PREBOUND)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_SPLIT_SEGS)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_LAZY_INIT)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_TWOLEVEL)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_FORCE_FLAT)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_NOMULTIDEFS)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_NOFIXPREBINDING)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_PREBINDABLE)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_ALLMODSBOUND)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_SUBSECTIONS_VIA_SYMBOLS)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_CANONICAL)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_WEAK_DEFINES)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_BINDS_TO_WEAK)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_ALLOW_STACK_EXECUTION)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_ROOT_SAFE)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_SETUID_SAFE)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_NO_REEXPORTED_DYLIBS)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_PIE)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_DEAD_STRIPPABLE_DYLIB)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_HAS_TLV_DESCRIPTORS)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_NO_HEAP_EXECUTION)) + .value(PY_ENUM(LIEF::MachO::HEADER_FLAGS::MH_APP_EXTENSION_SAFE)) + .export_values(); + + + + py::enum_(m, "LOAD_COMMAND_TYPES") + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_SEGMENT)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_SYMTAB)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_SYMSEG)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_THREAD)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_UNIXTHREAD)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_LOADFVMLIB)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_IDFVMLIB)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_IDENT)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_FVMFILE)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_PREPAGE)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_DYSYMTAB)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_LOAD_DYLIB)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_ID_DYLIB)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_LOAD_DYLINKER)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_ID_DYLINKER)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_PREBOUND_DYLIB)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_ROUTINES)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_SUB_FRAMEWORK)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_SUB_UMBRELLA)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_SUB_CLIENT)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_SUB_LIBRARY)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_TWOLEVEL_HINTS)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_PREBIND_CKSUM)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_LOAD_WEAK_DYLIB)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_SEGMENT_64)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_ROUTINES_64)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_UUID)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_RPATH)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_CODE_SIGNATURE)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_SEGMENT_SPLIT_INFO)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_REEXPORT_DYLIB)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_LAZY_LOAD_DYLIB)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_ENCRYPTION_INFO)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_DYLD_INFO)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_DYLD_INFO_ONLY)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_LOAD_UPWARD_DYLIB)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_VERSION_MIN_MACOSX)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_VERSION_MIN_IPHONEOS)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_FUNCTION_STARTS)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_DYLD_ENVIRONMENT)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_MAIN)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_DATA_IN_CODE)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_SOURCE_VERSION)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_DYLIB_CODE_SIGN_DRS)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_ENCRYPTION_INFO_64)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_LINKER_OPTION)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_LINKER_OPTIMIZATION_HINT)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_VERSION_MIN_TVOS)) + .value(PY_ENUM(LIEF::MachO::LOAD_COMMAND_TYPES::LC_VERSION_MIN_WATCHOS)) + .export_values(); + + + py::enum_(m, "SECTION_TYPES") + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_REGULAR)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_ZEROFILL)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_CSTRING_LITERALS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_4BYTE_LITERALS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_8BYTE_LITERALS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_LITERAL_POINTERS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_NON_LAZY_SYMBOL_POINTERS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_LAZY_SYMBOL_POINTERS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_SYMBOL_STUBS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_MOD_INIT_FUNC_POINTERS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_MOD_TERM_FUNC_POINTERS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_COALESCED)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_GB_ZEROFILL)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_INTERPOSING)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_16BYTE_LITERALS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_DTRACE_DOF)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_LAZY_DYLIB_SYMBOL_POINTERS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_THREAD_LOCAL_REGULAR)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_THREAD_LOCAL_ZEROFILL)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_THREAD_LOCAL_VARIABLES)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_THREAD_LOCAL_VARIABLE_POINTERS)) + .value(PY_ENUM(LIEF::MachO::SECTION_TYPES::S_THREAD_LOCAL_INIT_FUNCTION_POINTERS)) + .export_values(); +} diff --git a/api/python/PE/CMakeLists.txt b/api/python/PE/CMakeLists.txt new file mode 100644 index 0000000..a618754 --- /dev/null +++ b/api/python/PE/CMakeLists.txt @@ -0,0 +1,34 @@ +set(LIEF_PYTHON_PE_SRC + ${CMAKE_CURRENT_LIST_DIR}/objects/signature/pySignerInfo.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/signature/pyAuthenticatedAttributes.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/signature/pyx509.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/signature/pyContentInfo.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/signature/pySignature.cpp + + ${CMAKE_CURRENT_LIST_DIR}/objects/pyDataDirectory.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyDosHeader.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyBuilder.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyOptionalHeader.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyRelocationEntry.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyBinary.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyResourcesManager.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyHeader.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyDebug.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySection.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyExport.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyImport.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyExportEntry.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyRelocation.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyParser.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyImportEntry.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pySymbol.cpp + ${CMAKE_CURRENT_LIST_DIR}/objects/pyTLS.cpp + ${CMAKE_CURRENT_LIST_DIR}/pyPEStructures.cpp + ${CMAKE_CURRENT_LIST_DIR}/pyPE.cpp +) + +target_include_directories(pyLIEF PUBLIC ${CMAKE_CURRENT_LIST_DIR}) +target_sources(pyLIEF PRIVATE ${LIEF_PYTHON_PE_SRC}) + + + diff --git a/api/python/PE/objects/pyBinary.cpp b/api/python/PE/objects/pyBinary.cpp new file mode 100644 index 0000000..d4c9e41 --- /dev/null +++ b/api/python/PE/objects/pyBinary.cpp @@ -0,0 +1,198 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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/PE/Parser.hpp" +#include "LIEF/PE/Builder.hpp" +#include "LIEF/PE/Binary.hpp" +#include "LIEF/Abstract/Binary.hpp" + +#include "pyPE.hpp" + + +template +using no_const_func = T (Binary::*)(P); + +template +using no_const_getter = T (Binary::*)(void); + +void init_PE_Binary_class(py::module& m) { + py::class_(m, "Binary") + .def(py::init()) + + .def_property_readonly("sections", + static_cast>(&Binary::get_sections), + "Return binary's " RST_CLASS_REF(lief.PE.Section) " sections", + py::return_value_policy::reference) + + .def_property_readonly("dos_header", + static_cast(&Binary::dos_header), + "Return " RST_CLASS_REF(lief.PE.DosHeader) "", + py::return_value_policy::reference) + + .def_property_readonly("header", + static_cast(&Binary::header), + "Return " RST_CLASS_REF(lief.PE.Header) "", + py::return_value_policy::reference) + + .def_property_readonly("optional_header", + static_cast(&Binary::optional_header), + "Return " RST_CLASS_REF(lief.PE.OptionalHeader) "", + py::return_value_policy::reference) + + .def_property_readonly("virtual_size", + &Binary::get_virtual_size) + + .def_property_readonly("sizeof_headers", + &Binary::get_sizeof_headers) + + .def("rva_to_offset", + &Binary::rva_to_offset, + "Convert a relative virtual address to an offset") + + + .def("va_to_offset", + &Binary::va_to_offset, + "Convert a **absolute** virtual address to an offset") + + + .def("section_from_offset", + static_cast(&Binary::section_from_offset), + "Return the " RST_CLASS_REF(lief.PE.Section) " which contains the offset", + py::return_value_policy::reference) + + + .def("section_from_virtual_address", + static_cast(&Binary::section_from_virtual_address), + "Return the " RST_CLASS_REF(lief.PE.Section) " which contains the (relative) virtual address", + py::return_value_policy::reference) + + + .def_property("tls", + static_cast(&Binary::tls), + static_cast(&Binary::tls), + py::return_value_policy::reference) + + + .def_property_readonly("has_debug", &Binary::has_debug, + "Check if the current binary has a " RST_CLASS_REF(lief.PE.Debug) " object") + + .def_property_readonly("has_tls", &Binary::has_tls, + "Check if the current binary has a " RST_CLASS_REF(lief.PE.TLS) " object") + + .def_property_readonly("has_imports", &Binary::has_imports, + "Check if the current binary has a " RST_CLASS_REF(lief.PE.Import) " object") + + .def_property_readonly("has_exports", &Binary::has_exports, + "Check if the current binary has a " RST_CLASS_REF(lief.PE.Export) " object") + + .def_property_readonly("has_resources", &Binary::has_resources, + "Check if the current binary has a " RST_CLASS_REF(lief.PE.Resources) " object") + + .def_property_readonly("has_exceptions", &Binary::has_exceptions, + "Check if the current binary has a " RST_CLASS_REF(lief.PE.Execptions) " object") + + .def_property_readonly("has_relocations", &Binary::has_relocations, + "Check if the current binary has a " RST_CLASS_REF(lief.PE.Relocation) "") + + .def_property_readonly("has_configurations", &Binary::has_configuration, + "Check if the current binary has a " RST_CLASS_REF(lief.PE.Configuration) "") + + .def_property_readonly("has_signature", &Binary::has_signature, + "Check if the current binary has a " RST_CLASS_REF(lief.PE.Signature) "") + + .def("predict_function_rva", &Binary::predict_function_rva, + "Try to predict the RVA of the function `function` in the import library `library`", + py::arg("library"), py::arg("function")) + + + .def_property_readonly("signature", + static_cast(&Binary::signature), + py::return_value_policy::reference) + + + .def_property_readonly("debug", + static_cast(&Binary::get_debug), + py::return_value_policy::reference) + + .def("get_export", + static_cast(&Binary::get_export), + "Return a " RST_CLASS_REF(lief.PE.Export) " object", + py::return_value_policy::reference) + + .def_property_readonly("symbols", + static_cast& (Binary::*)(void)>(&Binary::symbols), + "Return binary's " RST_CLASS_REF(lief.PE.Symbol) "", + py::return_value_policy::reference) + + .def("get_section", + static_cast>(&Binary::get_section), + py::return_value_policy::reference) + + .def("add_section", + &Binary::add_section, + py::return_value_policy::reference) + + //.def("delete_section", (void (Binary::*)(const std::string&)) &Binary::delete_section) + //.def("get_import_section", + // static_cast>(&Binary::get_import_section), + // py::return_value_policy::reference_internal) + + .def_property_readonly("relocations", + static_cast>(&Binary::relocations), + py::return_value_policy::reference) + + .def("add_relocation", &Binary::add_relocation) + .def("remove_all_relocations", &Binary::remove_all_relocations) + + .def_property_readonly("data_directories", + static_cast>(&Binary::data_directories), + py::return_value_policy::reference) + + .def("data_directory", + static_cast(&Binary::data_directory), + py::return_value_policy::reference) + + .def_property_readonly("imports", + static_cast>(&Binary::imports), + py::return_value_policy::reference) + + .def_property_readonly("resources_manager", + static_cast>(&Binary::get_resources_manager)) + + .def("add_import_function", + &Binary::add_import_function, + py::return_value_policy::reference) + + .def("add_library", + &Binary::add_library, + py::return_value_policy::reference) + + .def("remove_library", &Binary::remove_library) + .def("remove_all_libraries", &Binary::remove_all_libraries) + + .def("write", &Binary::write) + + .def_property_readonly("entrypoint", &Binary::entrypoint) + + .def("__str__", + [] (const Binary& binary) + { + std::ostringstream stream; + stream << binary; + std::string str = stream.str(); + return str; + }); + +} diff --git a/api/python/PE/objects/pyBuilder.cpp b/api/python/PE/objects/pyBuilder.cpp new file mode 100644 index 0000000..993fff5 --- /dev/null +++ b/api/python/PE/objects/pyBuilder.cpp @@ -0,0 +1,71 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/PE/Builder.hpp" + +#include +#include + + +void init_PE_Builder_class(py::module& m) { + py::class_(m, "Builder") + .def(py::init()) + + .def("build", &Builder::build) + .def("build_imports", + &Builder::build_imports, + py::return_value_policy::reference) + + .def("patch_imports", + &Builder::patch_imports, + py::return_value_policy::reference) + + .def("build_relocations", + &Builder::build_relocations, + py::return_value_policy::reference) + + .def("build_tls", + static_cast(&Builder::build_tls), + py::return_value_policy::reference) + + .def("build_resources", + static_cast(&Builder::build_resources), + py::return_value_policy::reference) + + .def("build_imports", + &Builder::build_imports, + py::return_value_policy::reference) + + .def("write", + &Builder::write) + + .def("get_build", + &Builder::get_build, + py::return_value_policy::reference_internal) + + + .def("__str__", + [] (const Builder& builder) { + std::ostringstream stream; + stream << builder; + std::string str = stream.str(); + return str; + }); + + + +} diff --git a/api/python/PE/objects/pyDataDirectory.cpp b/api/python/PE/objects/pyDataDirectory.cpp new file mode 100644 index 0000000..8c9301b --- /dev/null +++ b/api/python/PE/objects/pyDataDirectory.cpp @@ -0,0 +1,69 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/DataDirectory.hpp" + +#include "pyPE.hpp" + +template +using getter_t = T (DataDirectory::*)(void) const; + +template +using setter_t = void (DataDirectory::*)(T); + +void init_PE_DataDirectory_class(py::module& m) { + py::class_(m, "DataDirectory") + .def(py::init<>()) + .def_property("rva", + static_cast>(&DataDirectory::RVA), + static_cast>(&DataDirectory::RVA)) + + .def_property("size", + static_cast>(&DataDirectory::size), + static_cast>(&DataDirectory::size)) + + .def_property_readonly("section", + static_cast(&DataDirectory::section), + py::return_value_policy::reference) + + .def_property_readonly("type", + &DataDirectory::type, + py::return_value_policy::reference_internal) + + .def_property_readonly("has_section", + &DataDirectory::has_section, + "Check if the current data directory is tied to a " RST_CLASS_REF(lief.PE.Section) "") + + .def("__eq__", &DataDirectory::operator==) + .def("__ne__", &DataDirectory::operator!=) + .def("__hash__", + [] (const DataDirectory& data_directory) { + return LIEF::Hash::hash(data_directory); + }) + + .def("__str__", [] (const DataDirectory& datadir) + { + std::ostringstream stream; + stream << datadir; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pyDebug.cpp b/api/python/PE/objects/pyDebug.cpp new file mode 100644 index 0000000..1c33351 --- /dev/null +++ b/api/python/PE/objects/pyDebug.cpp @@ -0,0 +1,82 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/Debug.hpp" + +#include +#include + +template +using getter_t = T (Debug::*)(void) const; + +template +using setter_t = void (Debug::*)(T); + +void init_PE_Debug_class(py::module& m) { + py::class_(m, "Debug") + .def(py::init<>()) + + .def_property("characteristics", + static_cast>(&Debug::characteristics), + static_cast>(&Debug::characteristics)) + + .def_property("timestamp", + static_cast>(&Debug::timestamp), + static_cast>(&Debug::timestamp)) + + .def_property("major_version", + static_cast>(&Debug::major_version), + static_cast>(&Debug::major_version)) + + .def_property("minor_version", + static_cast>(&Debug::minor_version), + static_cast>(&Debug::minor_version)) + + .def_property("type", + static_cast>(&Debug::type), + static_cast>(&Debug::type)) + + .def_property("sizeof_data", + static_cast>(&Debug::sizeof_data), + static_cast>(&Debug::sizeof_data)) + + .def_property("addressof_rawdata", + static_cast>(&Debug::addressof_rawdata), + static_cast>(&Debug::addressof_rawdata)) + + .def_property("pointerto_rawdata", + static_cast>(&Debug::pointerto_rawdata), + static_cast>(&Debug::pointerto_rawdata)) + + .def("__eq__", &Debug::operator==) + .def("__ne__", &Debug::operator!=) + .def("__hash__", + [] (const Debug& debug) { + return LIEF::Hash::hash(debug); + }) + + .def("__str__", [] (const Debug& debug) + { + std::ostringstream stream; + stream << debug; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pyDosHeader.cpp b/api/python/PE/objects/pyDosHeader.cpp new file mode 100644 index 0000000..f02695a --- /dev/null +++ b/api/python/PE/objects/pyDosHeader.cpp @@ -0,0 +1,122 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/DosHeader.hpp" + +#include +#include + +template +using getter_abs_t = T (DosHeader::*)(void) const; + +template +using setter_abs_t = void (DosHeader::*)(T); + +using getter_t = getter_abs_t; +using setter_t = setter_abs_t; + +void init_PE_DosHeader_class(py::module& m) { + py::class_(m, "DosHeader") + .def(py::init<>()) + .def_property("magic", + static_cast(&DosHeader::magic), + static_cast(&DosHeader::magic)) + + .def_property("used_bytes_in_the_last_page", + static_cast(&DosHeader::used_bytes_in_the_last_page), + static_cast(&DosHeader::used_bytes_in_the_last_page)) + + .def_property("file_size_in_pages", + static_cast(&DosHeader::file_size_in_pages), + static_cast(&DosHeader::file_size_in_pages)) + + .def_property("numberof_relocation", + static_cast(&DosHeader::numberof_relocation), + static_cast(&DosHeader::numberof_relocation)) + + .def_property("header_size_in_paragraphs", + static_cast(&DosHeader::header_size_in_paragraphs), + static_cast(&DosHeader::header_size_in_paragraphs)) + + .def_property("minimum_extra_paragraphs", + static_cast(&DosHeader::minimum_extra_paragraphs), + static_cast(&DosHeader::minimum_extra_paragraphs)) + + .def_property("maximum_extra_paragraphs", + static_cast(&DosHeader::maximum_extra_paragraphs), + static_cast(&DosHeader::maximum_extra_paragraphs)) + + .def_property("initial_relative_ss", + static_cast(&DosHeader::initial_relative_ss), + static_cast(&DosHeader::initial_relative_ss)) + + .def_property("initial_sp", + static_cast(&DosHeader::initial_sp), + static_cast(&DosHeader::initial_sp)) + + .def_property("checksum", + static_cast(&DosHeader::checksum), + static_cast(&DosHeader::checksum)) + + .def_property("initial_ip", + static_cast(&DosHeader::initial_ip), + static_cast(&DosHeader::initial_ip)) + + .def_property("initial_relative_cs", + static_cast(&DosHeader::initial_relative_cs), + static_cast(&DosHeader::initial_relative_cs)) + + .def_property("addressof_relocation_table", + static_cast(&DosHeader::addressof_relocation_table), + static_cast(&DosHeader::addressof_relocation_table)) + + .def_property("overlay_number", + static_cast(&DosHeader::overlay_number), + static_cast(&DosHeader::overlay_number)) + + .def_property("oem_id", + static_cast(&DosHeader::oem_id), + static_cast(&DosHeader::oem_id)) + + .def_property("oem_info", + static_cast(&DosHeader::oem_info), + static_cast(&DosHeader::oem_info)) + + .def_property("addressof_new_exeheader", + static_cast>(&DosHeader::addressof_new_exeheader), + static_cast>(&DosHeader::addressof_new_exeheader)) + + + .def("__eq__", &DosHeader::operator==) + .def("__ne__", &DosHeader::operator!=) + .def("__hash__", + [] (const DosHeader& dos_header) { + return LIEF::Hash::hash(dos_header); + }) + + .def("__str__", [] (const DosHeader& header) + { + std::ostringstream stream; + stream << header; + std::string str = stream.str(); + return str; + }); + + + +} diff --git a/api/python/PE/objects/pyExport.cpp b/api/python/PE/objects/pyExport.cpp new file mode 100644 index 0000000..5953671 --- /dev/null +++ b/api/python/PE/objects/pyExport.cpp @@ -0,0 +1,82 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/Export.hpp" + +#include +#include + +template +using getter_t = T (Export::*)(void) const; + +template +using setter_t = void (Export::*)(T); + +template +using no_const_getter = T (Export::*)(void); + +void init_PE_Export_class(py::module& m) { + py::class_(m, "Export") + .def(py::init<>()) + + .def_property("name", + static_cast>(&Export::name), + static_cast>(&Export::name)) + + .def_property("export_flags", + static_cast>(&Export::export_flags), + static_cast>(&Export::export_flags)) + + .def_property("timestamp", + static_cast>(&Export::timestamp), + static_cast>(&Export::timestamp)) + + .def_property("major_version", + static_cast>(&Export::major_version), + static_cast>(&Export::major_version)) + + .def_property("minor_version", + static_cast>(&Export::minor_version), + static_cast>(&Export::minor_version)) + + .def_property("ordinal_base", + static_cast>(&Export::ordinal_base), + static_cast>(&Export::ordinal_base)) + + .def_property_readonly("entries", + static_cast>(&Export::entries), + py::return_value_policy::reference_internal) + + + .def("__eq__", &Export::operator==) + .def("__ne__", &Export::operator!=) + .def("__hash__", + [] (const Export& export_) { + return LIEF::Hash::hash(export_); + }) + + .def("__str__", [] (const Export& export_) + { + std::ostringstream stream; + stream << export_; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pyExportEntry.cpp b/api/python/PE/objects/pyExportEntry.cpp new file mode 100644 index 0000000..03c2f25 --- /dev/null +++ b/api/python/PE/objects/pyExportEntry.cpp @@ -0,0 +1,66 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/ExportEntry.hpp" + +#include +#include + +template +using getter_t = T (ExportEntry::*)(void) const; + +template +using setter_t = void (ExportEntry::*)(T); + +void init_PE_ExportEntry_class(py::module& m) { + py::class_(m, "ExportEntry") + .def(py::init<>()) + + .def_property("name", + static_cast>(&ExportEntry::name), + static_cast>(&ExportEntry::name)) + + .def_property("ordinal", + static_cast>(&ExportEntry::ordinal), + static_cast>(&ExportEntry::ordinal)) + + .def_property("address", + static_cast>(&ExportEntry::address), + static_cast>(&ExportEntry::address)) + + .def_property("is_extern", + static_cast>(&ExportEntry::is_extern), + static_cast>(&ExportEntry::is_extern)) + + .def("__eq__", &ExportEntry::operator==) + .def("__ne__", &ExportEntry::operator!=) + .def("__hash__", + [] (const ExportEntry& export_entry) { + return LIEF::Hash::hash(export_entry); + }) + + .def("__str__", [] (const ExportEntry& entry) + { + std::ostringstream stream; + stream << entry; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pyHeader.cpp b/api/python/PE/objects/pyHeader.cpp new file mode 100644 index 0000000..eada0b5 --- /dev/null +++ b/api/python/PE/objects/pyHeader.cpp @@ -0,0 +1,97 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/Header.hpp" + +#include +#include + +template +using getter_t = T (Header::*)(void) const; + +template +using setter_t = void (Header::*)(T); + +void init_PE_Header_class(py::module& m) { + py::class_
(m, "Header") + .def(py::init<>()) + + .def_property("signature", + static_cast>(&Header::signature), + static_cast>(&Header::signature)) + + .def_property("machine", + static_cast>(&Header::machine), + static_cast>(&Header::machine)) + + .def_property("numberof_sections", + static_cast>(&Header::numberof_sections), + static_cast>(&Header::numberof_sections), + "Number of sections in the binary") + + .def_property("time_date_stamps", + static_cast>(&Header::time_date_stamp), + static_cast>(&Header::time_date_stamp)) + + .def_property("pointerto_symbol_table", + static_cast>(&Header::pointerto_symbol_table), + static_cast>(&Header::pointerto_symbol_table)) + + .def_property("numberof_symbols", + static_cast>(&Header::numberof_symbols), + static_cast>(&Header::numberof_symbols)) + + .def_property("sizeof_optional_header", + static_cast>(&Header::sizeof_optional_header), + static_cast>(&Header::sizeof_optional_header)) + + .def_property("characteristics", + static_cast>(&Header::characteristics), + static_cast>(&Header::characteristics)) + + .def("has_characteristic", + &Header::has_characteristic) + + .def("add_characteristic", + &Header::add_characteristic) + + .def("remove_characteristic", + &Header::remove_characteristic) + + .def_property_readonly("characteristics_list", + &Header::characteristics_list) + + + .def("__eq__", &Header::operator==) + .def("__ne__", &Header::operator!=) + .def("__hash__", + [] (const Header& header) { + return LIEF::Hash::hash(header); + }) + + + .def("__str__", [] (const Header& header) + { + std::ostringstream stream; + stream << header; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pyImport.cpp b/api/python/PE/objects/pyImport.cpp new file mode 100644 index 0000000..5e4f2f0 --- /dev/null +++ b/api/python/PE/objects/pyImport.cpp @@ -0,0 +1,99 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/Import.hpp" + +#include +#include + +template +using getter_t = T (Import::*)(void) const; + +template +using setter_t = void (Import::*)(T); + +template +using no_const_getter = T (Import::*)(void); + +template +using no_const_func = T (Import::*)(P); + +void init_PE_Import_class(py::module& m) { + py::class_(m, "Import") + .def(py::init<>()) + .def(py::init()) + + .def_property_readonly("entries", + static_cast>(&Import::entries), + py::return_value_policy::reference) + + .def_property_readonly("name", + static_cast>(&Import::name), + py::return_value_policy::reference) + + .def_property_readonly("directory", + static_cast>(&Import::directory), + py::return_value_policy::reference) + + .def_property_readonly("iat_directory", + static_cast>(&Import::iat_directory), + py::return_value_policy::reference) + + .def_property("import_address_table_rva", + static_cast>(&Import::import_address_table_rva), + static_cast>(&Import::import_address_table_rva)) + + .def_property("import_lookup_table_rva", + static_cast>(&Import::import_lookup_table_rva), + static_cast>(&Import::import_lookup_table_rva)) + + .def("get_function_rva_from_iat", + &Import::get_function_rva_from_iat) + + .def("add_entry", + static_cast(&Import::add_entry), + py::return_value_policy::reference) + + .def("add_entry", + static_cast(&Import::add_entry), + py::return_value_policy::reference) + + .def("get_entry", + static_cast>(&Import::get_entry), + "Check return " RST_CLASS_REF(lief.PE.ImportEntry) " with the given name", + py::return_value_policy::reference) + + + .def("__eq__", &Import::operator==) + .def("__ne__", &Import::operator!=) + .def("__hash__", + [] (const Import& import) { + return LIEF::Hash::hash(import); + }) + + + .def("__str__", [] (const Import& import) + { + std::ostringstream stream; + stream << import; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pyImportEntry.cpp b/api/python/PE/objects/pyImportEntry.cpp new file mode 100644 index 0000000..7d7ea74 --- /dev/null +++ b/api/python/PE/objects/pyImportEntry.cpp @@ -0,0 +1,82 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/ImportEntry.hpp" + +#include "pyPE.hpp" + +template +using getter_t = T (ImportEntry::*)(void) const; + +template +using setter_t = void (ImportEntry::*)(T); + +void init_PE_ImportEntry_class(py::module& m) { + py::class_(m, "ImportEntry") + .def(py::init<>()) + .def_property("name", + static_cast>(&ImportEntry::name), + static_cast>(&ImportEntry::name), + "Import name if not ordinal") + + .def_property("data", + static_cast>(&ImportEntry::data), + static_cast>(&ImportEntry::data), + "Raw value") + + .def_property_readonly("is_ordinal", + &ImportEntry::is_ordinal, + "``True`` if ordinal is used") + + .def_property_readonly("ordinal", + &ImportEntry::ordinal, + "``True`` if ordinal is used") + + .def_property_readonly("hint", + &ImportEntry::hint, + "Index into the :attr:`~lief.PE.Export.entries`") + + .def_property_readonly("iat_value", + &ImportEntry::iat_value, + "Value of the current entry in the Import Address Table") + + .def_property_readonly("iat_address", + &ImportEntry::iat_address, + "**Original** address of the entry in the Import Address Table") + + + + .def("__eq__", &ImportEntry::operator==) + .def("__ne__", &ImportEntry::operator!=) + .def("__hash__", + [] (const ImportEntry& import_entry) { + return LIEF::Hash::hash(import_entry); + }) + + .def("__str__", [] (const ImportEntry& importEntry) + { + std::ostringstream stream; + stream << importEntry; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pyOptionalHeader.cpp b/api/python/PE/objects/pyOptionalHeader.cpp new file mode 100644 index 0000000..414a8c9 --- /dev/null +++ b/api/python/PE/objects/pyOptionalHeader.cpp @@ -0,0 +1,176 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/OptionalHeader.hpp" + +#include +#include + +template +using getter_t = T (OptionalHeader::*)(void) const; + +template +using setter_t = void (OptionalHeader::*)(T); + +void init_PE_OptionalHeader_class(py::module& m) { + py::class_(m, "OptionalHeader") + .def(py::init<>()) + .def_property("magic", + static_cast>(&OptionalHeader::magic), + static_cast>(&OptionalHeader::magic)) + + .def_property("major_linker_version", + static_cast>(&OptionalHeader::major_linker_version), + static_cast>(&OptionalHeader::major_linker_version)) + + .def_property("minor_linker_version", + static_cast>(&OptionalHeader::minor_linker_version), + static_cast>(&OptionalHeader::minor_linker_version)) + + .def_property("sizeof_code", + static_cast>(&OptionalHeader::sizeof_code), + static_cast>(&OptionalHeader::sizeof_code)) + + .def_property("sizeof_initialized_data", + static_cast>(&OptionalHeader::sizeof_initialized_data), + static_cast>(&OptionalHeader::sizeof_initialized_data)) + + .def_property("sizeof_uninitialized_data", + static_cast>(&OptionalHeader::sizeof_uninitialized_data), + static_cast>(&OptionalHeader::sizeof_uninitialized_data)) + + .def_property("addressof_entrypoint", + static_cast>(&OptionalHeader::addressof_entrypoint), + static_cast>(&OptionalHeader::addressof_entrypoint)) + + .def_property("baseof_code", + static_cast>(&OptionalHeader::baseof_code), + static_cast>(&OptionalHeader::baseof_code)) + + .def_property("baseof_data", + static_cast>(&OptionalHeader::baseof_data), + static_cast>(&OptionalHeader::baseof_data)) + + .def_property("imagebase", + static_cast>(&OptionalHeader::imagebase), + static_cast>(&OptionalHeader::imagebase)) + + .def_property("section_alignment", + static_cast>(&OptionalHeader::section_alignment), + static_cast>(&OptionalHeader::section_alignment)) + + .def_property("file_alignment", + static_cast>(&OptionalHeader::file_alignment), + static_cast>(&OptionalHeader::file_alignment)) + + .def_property("major_operating_system_version", + static_cast>(&OptionalHeader::major_operating_system_version), + static_cast>(&OptionalHeader::major_operating_system_version)) + + .def_property("minor_operating_system_version", + static_cast>(&OptionalHeader::minor_operating_system_version), + static_cast>(&OptionalHeader::minor_operating_system_version)) + + .def_property("major_image_version", + static_cast>(&OptionalHeader::major_image_version), + static_cast>(&OptionalHeader::major_image_version)) + + .def_property("minor_image_version", + static_cast>(&OptionalHeader::minor_image_version), + static_cast>(&OptionalHeader::minor_image_version)) + + .def_property("major_subsystem_version", + static_cast>(&OptionalHeader::major_subsystem_version), + static_cast>(&OptionalHeader::major_subsystem_version)) + + .def_property("minor_subsystem_version", + static_cast>(&OptionalHeader::minor_subsystem_version), + static_cast>(&OptionalHeader::minor_subsystem_version)) + + .def_property("win32_version_value", + static_cast>(&OptionalHeader::win32_version_value), + static_cast>(&OptionalHeader::win32_version_value)) + + .def_property("sizeof_image", + static_cast>(&OptionalHeader::sizeof_image), + static_cast>(&OptionalHeader::sizeof_image)) + + .def_property("sizeof_headers", + static_cast>(&OptionalHeader::sizeof_headers), + static_cast>(&OptionalHeader::sizeof_headers)) + + .def_property("checksum", + static_cast>(&OptionalHeader::checksum), + static_cast>(&OptionalHeader::checksum)) + + .def_property("subsystem", + static_cast>(&OptionalHeader::subsystem), + static_cast>(&OptionalHeader::subsystem)) + + .def_property("dll_characteristics", + static_cast>(&OptionalHeader::dll_characteristics), + static_cast>(&OptionalHeader::dll_characteristics)) + + .def_property_readonly("dll_characteristics_lists", + &OptionalHeader::dll_characteristics_list) + + .def("has_dll_characteristics", + &OptionalHeader::has_dll_characteristics) + + .def_property("sizeof_stack_reserve", + static_cast>(&OptionalHeader::sizeof_stack_reserve), + static_cast>(&OptionalHeader::sizeof_stack_reserve)) + + .def_property("sizeof_stack_commit", + static_cast>(&OptionalHeader::sizeof_stack_commit), + static_cast>(&OptionalHeader::sizeof_stack_commit)) + + .def_property("sizeof_heap_reserve", + static_cast>(&OptionalHeader::sizeof_heap_reserve), + static_cast>(&OptionalHeader::sizeof_heap_reserve)) + + .def_property("sizeof_heap_commit", + static_cast>(&OptionalHeader::sizeof_heap_commit), + static_cast>(&OptionalHeader::sizeof_heap_commit)) + + .def_property("loader_flags", + static_cast>(&OptionalHeader::loader_flags), + static_cast>(&OptionalHeader::loader_flags)) + + .def_property("numberof_rva_and_size", + static_cast>(&OptionalHeader::numberof_rva_and_size), + static_cast>(&OptionalHeader::numberof_rva_and_size)) + + + .def("__eq__", &OptionalHeader::operator==) + .def("__ne__", &OptionalHeader::operator!=) + .def("__hash__", + [] (const OptionalHeader& optional_header) { + return LIEF::Hash::hash(optional_header); + }) + + .def("__str__", [] (const OptionalHeader& header) + { + std::ostringstream stream; + stream << header; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pyParser.cpp b/api/python/PE/objects/pyParser.cpp new file mode 100644 index 0000000..7b2bc37 --- /dev/null +++ b/api/python/PE/objects/pyParser.cpp @@ -0,0 +1,37 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/PE/Parser.hpp" + +#include + +void init_PE_Parser_class(py::module& m) { + + // Parser (Parser) + m.def("parse", + static_cast(&Parser::parse), + "Parse the given binary and return a " RST_CLASS_REF(lief.PE.Binary) " object", + py::arg("filename"), + py::return_value_policy::take_ownership); + + + m.def("parse_from_raw", + static_cast&, const std::string&)>(&Parser::parse), + "Parse the given raw data and return a " RST_CLASS_REF(lief.PE.Binary) " object", + py::arg("raw"), py::arg("name") = "", + py::return_value_policy::take_ownership); +} diff --git a/api/python/PE/objects/pyRelocation.cpp b/api/python/PE/objects/pyRelocation.cpp new file mode 100644 index 0000000..f97263f --- /dev/null +++ b/api/python/PE/objects/pyRelocation.cpp @@ -0,0 +1,62 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/Relocation.hpp" + +#include +#include + +template +using getter_t = T (Relocation::*)(void) const; + +template +using setter_t = void (Relocation::*)(T); + +void init_PE_Relocation_class(py::module& m) { + py::class_(m, "Relocation") + .def(py::init<>()) + + .def_property("virtual_address", + static_cast>(&Relocation::virtual_address), + static_cast>(&Relocation::virtual_address)) + + .def_property_readonly("entries", + &Relocation::entries, + py::return_value_policy::reference) + + .def("add_entry", + &Relocation::add_entry) + + + .def("__eq__", &Relocation::operator==) + .def("__ne__", &Relocation::operator!=) + .def("__hash__", + [] (const Relocation& relocation) { + return LIEF::Hash::hash(relocation); + }) + + .def("__str__", [] (const Relocation& relocation) + { + std::ostringstream stream; + stream << relocation; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pyRelocationEntry.cpp b/api/python/PE/objects/pyRelocationEntry.cpp new file mode 100644 index 0000000..fc9df51 --- /dev/null +++ b/api/python/PE/objects/pyRelocationEntry.cpp @@ -0,0 +1,63 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/RelocationEntry.hpp" + +#include +#include + +template +using getter_t = T (RelocationEntry::*)(void) const; + +template +using setter_t = void (RelocationEntry::*)(T); + +void init_PE_RelocationEntry_class(py::module& m) { + py::class_(m, "RelocationEntry") + .def(py::init<>()) + + .def_property("data", + static_cast>(&RelocationEntry::data), + static_cast>(&RelocationEntry::data)) + + .def_property("position", + static_cast>(&RelocationEntry::position), + static_cast>(&RelocationEntry::position)) + + .def_property("type", + static_cast>(&RelocationEntry::type), + static_cast>(&RelocationEntry::type)) + + + .def("__eq__", &RelocationEntry::operator==) + .def("__ne__", &RelocationEntry::operator!=) + .def("__hash__", + [] (const RelocationEntry& relocation_entry) { + return LIEF::Hash::hash(relocation_entry); + }) + + .def("__str__", [] (const RelocationEntry& relocation) + { + std::ostringstream stream; + stream << relocation; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pyResourcesManager.cpp b/api/python/PE/objects/pyResourcesManager.cpp new file mode 100644 index 0000000..eea4390 --- /dev/null +++ b/api/python/PE/objects/pyResourcesManager.cpp @@ -0,0 +1,36 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/ResourcesManager.hpp" + +#include +#include + + +void init_PE_ResourcesManager_class(py::module& m) { + py::class_(m, "ResourcesManager") + + .def("__str__", [] (const ResourcesManager& manager) + { + std::ostringstream stream; + stream << manager; + std::string str = stream.str(); + return str; + }); +} + diff --git a/api/python/PE/objects/pySection.cpp b/api/python/PE/objects/pySection.cpp new file mode 100644 index 0000000..c4a17b4 --- /dev/null +++ b/api/python/PE/objects/pySection.cpp @@ -0,0 +1,87 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/Abstract/Section.hpp" +#include "LIEF/PE/Section.hpp" + +#include +#include + +template +using getter_t = T (Section::*)(void) const; + +template +using setter_t = void (Section::*)(T); + +void init_PE_Section_class(py::module& m) { + py::class_(m, "Section") + .def(py::init<>()) + .def(py::init&, const std::string&, uint32_t>()) + .def(py::init()) + .def_property("virtual_size", + static_cast>(&Section::virtual_size), + static_cast>(&Section::virtual_size)) + + .def_property("pointerto_relocation", + static_cast>(&Section::pointerto_relocation), + static_cast>(&Section::pointerto_relocation)) + + .def_property("pointerto_line_numbers", + static_cast>(&Section::pointerto_line_numbers), + static_cast>(&Section::pointerto_line_numbers)) + + .def_property("numberof_relocations", + static_cast>(&Section::numberof_relocations), + static_cast>(&Section::numberof_relocations)) + + .def_property("numberof_line_numbers", + static_cast>(&Section::numberof_line_numbers), + static_cast>(&Section::numberof_line_numbers)) + + .def_property("characteristics", + static_cast>(&Section::characteristics), + static_cast>(&Section::characteristics)) + + .def_property_readonly("characteristics_lists", + &Section::characteristics_list) + + .def("has_characteristic", + &Section::has_characteristic) + + .def_property("data", + static_cast>>(&Section::content), + static_cast&>>(&Section::content)) + + + .def("__eq__", &Section::operator==) + .def("__ne__", &Section::operator!=) + .def("__hash__", + [] (const Section& section) { + return LIEF::Hash::hash(section); + }) + + .def("__str__", + [] (const Section& section) { + std::ostringstream stream; + stream << section; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pySymbol.cpp b/api/python/PE/objects/pySymbol.cpp new file mode 100644 index 0000000..074d83c --- /dev/null +++ b/api/python/PE/objects/pySymbol.cpp @@ -0,0 +1,84 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/Symbol.hpp" + +#include +#include + +template +using getter_t = T (Symbol::*)(void) const; + +template +using setter_t = void (Symbol::*)(T); + +template +using no_const_getter = T (Symbol::*)(void); + +void init_PE_Symbol_class(py::module& m) { + py::class_(m, "Symbol") + .def(py::init<>()) + + .def_property("name", + static_cast> (&Symbol::wname), + static_cast>(&Symbol::name)) + + .def_property_readonly("value", + &Symbol::value) + + .def_property_readonly("section_number", + &Symbol::section_number) + + .def_property_readonly("type", + &Symbol::type) + + .def_property_readonly("base_type", + &Symbol::base_type) + + .def_property_readonly("complex_type", + &Symbol::complex_type) + + .def_property_readonly("storage_class", + &Symbol::storage_class) + + .def_property_readonly("numberof_aux_symbols", + &Symbol::numberof_aux_symbols) + + .def_property_readonly("section", + static_cast>(&Symbol::section), + py::return_value_policy::reference_internal) + + + .def("__eq__", &Symbol::operator==) + .def("__ne__", &Symbol::operator!=) + .def("__hash__", + [] (const Symbol& symbol) { + return LIEF::Hash::hash(symbol); + }) + + + .def("__str__", [] (const Symbol& symbol) + { + std::ostringstream stream; + stream << symbol; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/pyTLS.cpp b/api/python/PE/objects/pyTLS.cpp new file mode 100644 index 0000000..d9cf422 --- /dev/null +++ b/api/python/PE/objects/pyTLS.cpp @@ -0,0 +1,90 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/TLS.hpp" + +#include +#include + +template +using getter_t = T (TLS::*)(void) const; + +template +using setter_t = void (TLS::*)(T); + +template +using no_const_getter = T (TLS::*)(void); + +void init_PE_TLS_class(py::module& m) { + py::class_(m, "TLS") + .def(py::init<>()) + + .def_property("callbacks", + static_cast&>>(&TLS::callbacks), + static_cast&>>(&TLS::callbacks)) + + .def_property("addressof_index", + static_cast>(&TLS::addressof_index), + static_cast>(&TLS::addressof_index)) + + .def_property("addressof_callbacks", + static_cast>(&TLS::addressof_callbacks), + static_cast>(&TLS::addressof_callbacks)) + + .def_property("sizeof_zero_fill", + static_cast>(&TLS::sizeof_zero_fill), + static_cast>(&TLS::sizeof_zero_fill)) + + .def_property("characteristics", + static_cast>(&TLS::characteristics), + static_cast>(&TLS::characteristics)) + + .def_property("addressof_raw_data", + static_cast>>(&TLS::addressof_raw_data), + static_cast>>(&TLS::addressof_raw_data)) + + .def_property("data_template", + static_cast&>>(&TLS::data_template), + static_cast&>>(&TLS::data_template)) + + .def_property_readonly("directory", + static_cast>(&TLS::directory), + py::return_value_policy::reference) + + .def_property_readonly("section", + static_cast>(&TLS::section), + py::return_value_policy::reference) + + + .def("__eq__", &TLS::operator==) + .def("__ne__", &TLS::operator!=) + .def("__hash__", + [] (const TLS& tls) { + return LIEF::Hash::hash(tls); + }) + + .def("__str__", [] (const TLS& tls) + { + std::ostringstream stream; + stream << tls; + std::string str = stream.str(); + return str; + }); + + +} diff --git a/api/python/PE/objects/signature/pyAuthenticatedAttributes.cpp b/api/python/PE/objects/signature/pyAuthenticatedAttributes.cpp new file mode 100644 index 0000000..a7b729f --- /dev/null +++ b/api/python/PE/objects/signature/pyAuthenticatedAttributes.cpp @@ -0,0 +1,63 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/signature/AuthenticatedAttributes.hpp" + +#include "pyPE.hpp" + + +template +using getter_t = T (AuthenticatedAttributes::*)(void) const; + +template +using setter_t = void (AuthenticatedAttributes::*)(T); + + +void init_PE_AuthenticatedAttributes_class(py::module& m) { + + py::class_(m, "AuthenticatedAttributes") + + .def_property_readonly("content_type", + &AuthenticatedAttributes::content_type, + "Should return the ``messageDigest`` OID") + + .def_property_readonly("message_digest", + &AuthenticatedAttributes::message_digest, + "Return an hash of the signed attributes") + + .def_property_readonly("program_name", + &AuthenticatedAttributes::program_name, + "Return the program description (if any)") + + .def_property_readonly("more_info", + &AuthenticatedAttributes::more_info, + "Return an URL to website with more information about the signer") + + .def("__str__", + [] (const AuthenticatedAttributes& authenticated_attributes) + { + std::ostringstream stream; + stream << authenticated_attributes; + std::string str = stream.str(); + return str; + }); + +} + diff --git a/api/python/PE/objects/signature/pyContentInfo.cpp b/api/python/PE/objects/signature/pyContentInfo.cpp new file mode 100644 index 0000000..851017b --- /dev/null +++ b/api/python/PE/objects/signature/pyContentInfo.cpp @@ -0,0 +1,63 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/signature/ContentInfo.hpp" + +#include "pyPE.hpp" + + +template +using getter_t = T (ContentInfo::*)(void) const; + +template +using setter_t = void (ContentInfo::*)(T); + + +void init_PE_ContentInfo_class(py::module& m) { + + py::class_(m, "ContentInfo") + + .def_property_readonly("content_type", + &ContentInfo::content_type, + "OID of the content type. This value should match ``SPC_INDIRECT_DATA_OBJID``") + + .def_property_readonly("type", + &ContentInfo::type) + + .def_property_readonly("digest_algorithm", + &ContentInfo::digest_algorithm, + "Algorithm (OID) used to hash the file. This value should match SignerInfo.digest_algorithm and Signature.digest_algorithm") + + + .def_property_readonly("digest", + &ContentInfo::digest, + "The digest") + + + .def("__str__", + [] (const ContentInfo& content_info) + { + std::ostringstream stream; + stream << content_info; + std::string str = stream.str(); + return str; + }); + +} + diff --git a/api/python/PE/objects/signature/pySignature.cpp b/api/python/PE/objects/signature/pySignature.cpp new file mode 100644 index 0000000..9c7e8fd --- /dev/null +++ b/api/python/PE/objects/signature/pySignature.cpp @@ -0,0 +1,78 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/signature/Signature.hpp" + +#include "pyPE.hpp" + + +template +using getter_t = T (Signature::*)(void) const; + +template +using setter_t = void (Signature::*)(T); + + +void init_PE_Signature_class(py::module& m) { + + py::class_(m, "Signature") + + .def_property_readonly("version", + &Signature::version, + "Should be 1") + + .def_property_readonly("digest_algorithm", + &Signature::digest_algorithm, + "Return the algorithm (OID) used to sign the content of " RST_CLASS_REF(lief.PE.ContentInfo) "") + + + .def_property_readonly("content_info", + &Signature::content_info, + "Return the " RST_CLASS_REF(lief.PE.ContentInfo) "", + py::return_value_policy::reference) + + + .def_property_readonly("certificates", + &Signature::certificates, + "Return an iterator over " RST_CLASS_REF(lief.PE.x509) " certificates", + py::return_value_policy::reference) + + + .def_property_readonly("signer_info", + &Signature::signer_info, + "Return the " RST_CLASS_REF(lief.PE.SignerInfo) "", + py::return_value_policy::reference) + + + .def_property_readonly("original_signature", + &Signature::original_signature, + "Return the raw original signature") + + + .def("__str__", + [] (const Signature& signature) + { + std::ostringstream stream; + stream << signature; + std::string str = stream.str(); + return str; + }); + +} + diff --git a/api/python/PE/objects/signature/pySignerInfo.cpp b/api/python/PE/objects/signature/pySignerInfo.cpp new file mode 100644 index 0000000..fe97c37 --- /dev/null +++ b/api/python/PE/objects/signature/pySignerInfo.cpp @@ -0,0 +1,72 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/signature/SignerInfo.hpp" + +#include "pyPE.hpp" + + +template +using getter_t = T (SignerInfo::*)(void) const; + +template +using setter_t = void (SignerInfo::*)(T); + + +void init_PE_SignerInfo_class(py::module& m) { + + py::class_(m, "SignerInfo") + + .def_property_readonly("version", + &SignerInfo::version, + "Should be 1") + + .def_property_readonly("issuer", + &SignerInfo::issuer, + "Issuer and serial number", + py::return_value_policy::reference) + + .def_property_readonly("digest_algorithm", + &SignerInfo::digest_algorithm, + "Algorithm (OID) used to hash the file. This value should match ContentInfo.digest_algorithm and Signature.digest_algorithm") + + .def_property_readonly("signature_algorithm", + &SignerInfo::signature_algorithm, + "Return the signature algorithm (OID)") + + .def_property_readonly("encrypted_digest", + &SignerInfo::encrypted_digest, + "Return the signature created by the signing certificate's private key") + + .def_property_readonly("authenticated_attributes", + &SignerInfo::authenticated_attributes, + "Return the " RST_CLASS_REF(lief.PE.AuthenticatedAttributes) " object", + py::return_value_policy::reference) + + .def("__str__", + [] (const SignerInfo& signer_info) + { + std::ostringstream stream; + stream << signer_info; + std::string str = stream.str(); + return str; + }); + +} + diff --git a/api/python/PE/objects/signature/pyx509.cpp b/api/python/PE/objects/signature/pyx509.cpp new file mode 100644 index 0000000..952433a --- /dev/null +++ b/api/python/PE/objects/signature/pyx509.cpp @@ -0,0 +1,79 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 +#include + +#include "LIEF/visitors/Hash.hpp" +#include "LIEF/PE/signature/x509.hpp" + +#include "pyPE.hpp" + + +template +using getter_t = T (x509::*)(void) const; + +template +using setter_t = void (x509::*)(T); + + +void init_PE_x509_class(py::module& m) { + + py::class_(m, "x509") + + .def_property_readonly("version", + &x509::version, + "X.509 version. (1=v1, 2=v2, 3=v3)") + + .def_property_readonly("serial_number", + &x509::serial_number, + "Unique id for certificate issued by a specific CA.") + + .def_property_readonly("signature_alogrithm", + &x509::signature_alogrithm, + "Signature algorithm (OID)") + + + .def_property_readonly("valid_from", + &x509::valid_from, + "Start time of certificate validity") + + + .def_property_readonly("valid_to", + &x509::valid_to, + "End time of certificate validity") + + + .def_property_readonly("issuer", + &x509::issuer, + "Issuer informations") + + + .def_property_readonly("subject", + &x509::subject, + "Subject informations") + + + .def("__str__", + [] (const x509& x509_crt) + { + std::ostringstream stream; + stream << x509_crt; + std::string str = stream.str(); + return str; + }); + +} + diff --git a/api/python/PE/pyPE.cpp b/api/python/PE/pyPE.cpp new file mode 100644 index 0000000..9504979 --- /dev/null +++ b/api/python/PE/pyPE.cpp @@ -0,0 +1,59 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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/PE/signature/OIDToString.hpp" + +#include "pyPE.hpp" + +// +// PE modules +// +void init_PE_module(py::module& m) { + py::module LIEF_PE_module = m.def_submodule("PE", "Python API for PE"); + + LIEF_PE_module.def("oid_to_string", + &oid_to_string, + "Convert an OID to a human-readable string"); + + + // Objects + init_PE_Parser_class(LIEF_PE_module); + init_PE_Binary_class(LIEF_PE_module); + init_PE_DataDirectory_class(LIEF_PE_module); + init_PE_Header_class(LIEF_PE_module); + init_PE_DosHeader_class(LIEF_PE_module); + init_PE_OptionalHeader_class(LIEF_PE_module); + init_PE_Section_class(LIEF_PE_module); + init_PE_Import_class(LIEF_PE_module); + init_PE_ImportEntry_class(LIEF_PE_module); + init_PE_TLS_class(LIEF_PE_module); + init_PE_Symbol_class(LIEF_PE_module); + init_PE_Relocation_class(LIEF_PE_module); + init_PE_RelocationEntry_class(LIEF_PE_module); + init_PE_Export_class(LIEF_PE_module); + init_PE_ExportEntry_class(LIEF_PE_module); + init_PE_Builder_class(LIEF_PE_module); + init_PE_Debug_class(LIEF_PE_module); + init_PE_ResourcesManager_class(LIEF_PE_module); + + init_PE_Signature_class(LIEF_PE_module); + init_PE_ContentInfo_class(LIEF_PE_module); + init_PE_x509_class(LIEF_PE_module); + init_PE_SignerInfo_class(LIEF_PE_module); + init_PE_AuthenticatedAttributes_class(LIEF_PE_module); + + // Enums + init_PE_Structures_enum(LIEF_PE_module); +} diff --git a/api/python/PE/pyPE.hpp b/api/python/PE/pyPE.hpp new file mode 100644 index 0000000..782626e --- /dev/null +++ b/api/python/PE/pyPE.hpp @@ -0,0 +1,53 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 PY_LIEF_PE_H_ +#define PY_LIEF_PE_H_ +#include "LIEF/PE.hpp" + +#include "pyLIEF.hpp" + +using namespace LIEF::PE; + +void init_PE_Parser_class(py::module&); +void init_PE_Binary_class(py::module&); +void init_PE_DataDirectory_class(py::module&); +void init_PE_Header_class(py::module&); +void init_PE_DosHeader_class(py::module&); +void init_PE_Section_class(py::module&); +void init_PE_OptionalHeader_class(py::module&); +void init_PE_Import_class(py::module&); +void init_PE_ImportEntry_class(py::module&); +void init_PE_TLS_class(py::module&); +void init_PE_Symbol_class(py::module&); +void init_PE_Relocation_class(py::module&); +void init_PE_RelocationEntry_class(py::module&); +void init_PE_Export_class(py::module&); +void init_PE_ExportEntry_class(py::module&); +void init_PE_Builder_class(py::module&); +void init_PE_Debug_class(py::module&); +void init_PE_ResourcesManager_class(py::module&); + +void init_PE_Signature_class(py::module&); +void init_PE_ContentInfo_class(py::module&); +void init_PE_x509_class(py::module&); +void init_PE_SignerInfo_class(py::module&); +void init_PE_AuthenticatedAttributes_class(py::module&); + +// Enums +void init_PE_Structures_enum(py::module&); + + +#endif diff --git a/api/python/PE/pyPEStructures.cpp b/api/python/PE/pyPEStructures.cpp new file mode 100644 index 0000000..6738e77 --- /dev/null +++ b/api/python/PE/pyPEStructures.cpp @@ -0,0 +1,277 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyPE.hpp" +#include "LIEF/PE/Structures.hpp" +#include "LIEF/PE/EnumToString.hpp" + +#define PY_ENUM(x) LIEF::PE::to_string(x), x + +void init_PE_Structures_enum(py::module& m) { + + py::enum_(m, "PE_TYPE") + .value(PY_ENUM(LIEF::PE::PE_TYPE::PE32)) + .value(PY_ENUM(LIEF::PE::PE_TYPE::PE32_PLUS)) + .export_values(); + + py::enum_(m, "MACHINE_TYPES") + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::MT_Invalid)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_UNKNOWN)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_AM33)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_AMD64)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_ARM)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_ARMNT)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_EBC)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_I386)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_IA64)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_M32R)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_MIPS16)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_MIPSFPU)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_MIPSFPU16)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_POWERPC)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_POWERPCFP)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_R4000)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_SH3)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_SH3DSP)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_SH4)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_SH5)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_THUMB)) + .value(PY_ENUM(LIEF::PE::MACHINE_TYPES::IMAGE_FILE_MACHINE_WCEMIPSV2)) + .export_values(); + + py::enum_(m, "PE_CHARACTERISTICS") + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_RELOCS_STRIPPED)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_EXECUTABLE_IMAGE)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_LINE_NUMS_STRIPPED)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_LOCAL_SYMS_STRIPPED)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_AGGRESSIVE_WS_TRIM)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_LARGE_ADDRESS_AWARE)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_BYTES_REVERSED_LO)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_32BIT_MACHINE)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_DEBUG_STRIPPED)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_REMOVABLE_RUN_FROM_SWAP)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_NET_RUN_FROM_SWAP)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_SYSTEM)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_DLL)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_UP_SYSTEM_ONLY)) + .value(PY_ENUM(LIEF::PE::HEADER_CHARACTERISTICS::IMAGE_FILE_BYTES_REVERSED_HI)) + .export_values(); + + py::enum_(m, "SUBSYSTEM") + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_UNKNOWN)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_NATIVE)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_WINDOWS_GUI)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_WINDOWS_CUI)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_OS2_CUI)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_POSIX_CUI)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_NATIVE_WINDOWS)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_WINDOWS_CE_GUI)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_EFI_APPLICATION)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_EFI_ROM)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_XBOX)) + .value(PY_ENUM(LIEF::PE::SUBSYSTEM::IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION)) + .export_values(); + + py::enum_(m, "DATA_DIRECTORY") + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::EXPORT_TABLE)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::IMPORT_TABLE)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::RESOURCE_TABLE)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::EXCEPTION_TABLE)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::CERTIFICATE_TABLE)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::BASE_RELOCATION_TABLE)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::DEBUG)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::ARCHITECTURE)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::GLOBAL_PTR)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::TLS_TABLE)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::LOAD_CONFIG_TABLE)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::BOUND_IMPORT)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::IAT)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::DELAY_IMPORT_DESCRIPTOR)) + .value(PY_ENUM(LIEF::PE::DATA_DIRECTORY::CLR_RUNTIME_HEADER)) + .export_values(); + + py::enum_(m, "DLL_CHARACTERISTICS") + .value(PY_ENUM(LIEF::PE::DLL_CHARACTERISTICS::IMAGE_DLL_CHARACTERISTICS_HIGH_ENTROPY_VA)) + .value(PY_ENUM(LIEF::PE::DLL_CHARACTERISTICS::IMAGE_DLL_CHARACTERISTICS_DYNAMIC_BASE)) + .value(PY_ENUM(LIEF::PE::DLL_CHARACTERISTICS::IMAGE_DLL_CHARACTERISTICS_FORCE_INTEGRITY)) + .value(PY_ENUM(LIEF::PE::DLL_CHARACTERISTICS::IMAGE_DLL_CHARACTERISTICS_NX_COMPAT)) + .value(PY_ENUM(LIEF::PE::DLL_CHARACTERISTICS::IMAGE_DLL_CHARACTERISTICS_NO_ISOLATION)) + .value(PY_ENUM(LIEF::PE::DLL_CHARACTERISTICS::IMAGE_DLL_CHARACTERISTICS_NO_SEH)) + .value(PY_ENUM(LIEF::PE::DLL_CHARACTERISTICS::IMAGE_DLL_CHARACTERISTICS_NO_BIND)) + .value(PY_ENUM(LIEF::PE::DLL_CHARACTERISTICS::IMAGE_DLL_CHARACTERISTICS_APPCONTAINER)) + .value(PY_ENUM(LIEF::PE::DLL_CHARACTERISTICS::IMAGE_DLL_CHARACTERISTICS_WDM_DRIVER)) + .value(PY_ENUM(LIEF::PE::DLL_CHARACTERISTICS::IMAGE_DLL_CHARACTERISTICS_GUARD_CF)) + .value(PY_ENUM(LIEF::PE::DLL_CHARACTERISTICS::IMAGE_DLL_CHARACTERISTICS_TERMINAL_SERVER_AWARE)) + .export_values(); + + + py::enum_(m, "SECTION_CHARACTERISTICS") + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_TYPE_NO_PAD)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_CNT_CODE)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_CNT_INITIALIZED_DATA)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_CNT_UNINITIALIZED_DATA)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_LNK_OTHER)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_LNK_INFO)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_LNK_REMOVE)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_LNK_COMDAT)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_GPREL)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_MEM_PURGEABLE)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_MEM_16BIT)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_MEM_LOCKED)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_MEM_PRELOAD)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_1BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_2BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_4BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_8BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_16BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_32BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_64BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_128BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_256BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_512BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_1024BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_2048BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_4096BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_ALIGN_8192BYTES)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_LNK_NRELOC_OVFL)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_MEM_DISCARDABLE)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_MEM_NOT_CACHED)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_MEM_NOT_PAGED)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_MEM_SHARED)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_MEM_EXECUTE)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_MEM_READ)) + .value(PY_ENUM(LIEF::PE::SECTION_CHARACTERISTICS::IMAGE_SCN_MEM_WRITE)) + .export_values(); + + py::enum_(m, "SECTION_TYPES") + .value(PY_ENUM(LIEF::PE::SECTION_TYPES::TEXT)) + .value(PY_ENUM(LIEF::PE::SECTION_TYPES::TLS)) + .value(PY_ENUM(LIEF::PE::SECTION_TYPES::IMPORT)) + .value(PY_ENUM(LIEF::PE::SECTION_TYPES::DATA)) + .value(PY_ENUM(LIEF::PE::SECTION_TYPES::BSS)) + .value(PY_ENUM(LIEF::PE::SECTION_TYPES::RESOURCE)) + .value(PY_ENUM(LIEF::PE::SECTION_TYPES::RELOCATION)) + .value(PY_ENUM(LIEF::PE::SECTION_TYPES::EXPORT)) + .value(PY_ENUM(LIEF::PE::SECTION_TYPES::UNKNOWN)) + .export_values(); + + + py::enum_(m, "SYMBOL_BASE_TYPES") + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_NULL)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_VOID)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_CHAR)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_SHORT)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_INT)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_LONG)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_FLOAT)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_DOUBLE)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_STRUCT)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_UNION)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_ENUM)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_MOE)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_BYTE)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_WORD)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_UINT)) + .value(PY_ENUM(LIEF::PE::SYMBOL_BASE_TYPES::IMAGE_SYM_TYPE_DWORD)) + .export_values(); + + + py::enum_(m, "SYMBOL_COMPLEX_TYPES") + .value(PY_ENUM(LIEF::PE::SYMBOL_COMPLEX_TYPES::IMAGE_SYM_DTYPE_NULL)) + .value(PY_ENUM(LIEF::PE::SYMBOL_COMPLEX_TYPES::IMAGE_SYM_DTYPE_POINTER)) + .value(PY_ENUM(LIEF::PE::SYMBOL_COMPLEX_TYPES::IMAGE_SYM_DTYPE_FUNCTION)) + .value(PY_ENUM(LIEF::PE::SYMBOL_COMPLEX_TYPES::IMAGE_SYM_DTYPE_ARRAY)) + .value(PY_ENUM(LIEF::PE::SYMBOL_COMPLEX_TYPES::SCT_COMPLEX_TYPE_SHIFT)) + .export_values(); + + + py::enum_(m, "SYMBOL_SECTION_NUMBER") + .value(PY_ENUM(LIEF::PE::SYMBOL_SECTION_NUMBER::IMAGE_SYM_DEBUG)) + .value(PY_ENUM(LIEF::PE::SYMBOL_SECTION_NUMBER::IMAGE_SYM_ABSOLUTE)) + .value(PY_ENUM(LIEF::PE::SYMBOL_SECTION_NUMBER::IMAGE_SYM_UNDEFINED)) + .export_values(); + + + py::enum_(m, "SYMBOL_STORAGE_CLASS") + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_END_OF_FUNCTION)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_NULL)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_AUTOMATIC)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_EXTERNAL)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_STATIC)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_REGISTER)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_EXTERNAL_DEF)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_LABEL)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_UNDEFINED_LABEL)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_MEMBER_OF_STRUCT)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_UNION_TAG)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_TYPE_DEFINITION)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_UNDEFINED_STATIC)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_ENUM_TAG)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_MEMBER_OF_ENUM)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_REGISTER_PARAM)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_BIT_FIELD)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_BLOCK)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_FUNCTION)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_END_OF_STRUCT)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_FILE)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_SECTION)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_WEAK_EXTERNAL)) + .value(PY_ENUM(LIEF::PE::SYMBOL_STORAGE_CLASS::IMAGE_SYM_CLASS_CLR_TOKEN)) + .export_values(); + + + py::enum_(m, "RELOCATIONS_BASE_TYPES") + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_ABSOLUTE)) + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_HIGH)) + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_LOW)) + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_HIGHLOW)) + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_HIGHADJ)) + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_MIPS_JMPADDR)) + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_SECTION)) + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_REL)) + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_MIPS_JMPADDR16)) + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_IA64_IMM64)) + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_DIR64)) + .value(PY_ENUM(LIEF::PE::RELOCATIONS_BASE_TYPES::IMAGE_REL_BASED_HIGH3ADJ)) + .export_values(); + + + py::enum_(m, "DEBUG_TYPES") + .value(PY_ENUM(LIEF::PE::DEBUG_TYPES::IMAGE_DEBUG_TYPE_UNKNOWN)) + .value(PY_ENUM(LIEF::PE::DEBUG_TYPES::IMAGE_DEBUG_TYPE_COFF)) + .value(PY_ENUM(LIEF::PE::DEBUG_TYPES::IMAGE_DEBUG_TYPE_CODEVIEW)) + .value(PY_ENUM(LIEF::PE::DEBUG_TYPES::IMAGE_DEBUG_TYPE_FPO)) + .value(PY_ENUM(LIEF::PE::DEBUG_TYPES::IMAGE_DEBUG_TYPE_MISC)) + .value(PY_ENUM(LIEF::PE::DEBUG_TYPES::IMAGE_DEBUG_TYPE_EXCEPTION)) + .value(PY_ENUM(LIEF::PE::DEBUG_TYPES::IMAGE_DEBUG_TYPE_FIXUP)) + .value(PY_ENUM(LIEF::PE::DEBUG_TYPES::IMAGE_DEBUG_TYPE_OMAP_TO_SRC)) + .value(PY_ENUM(LIEF::PE::DEBUG_TYPES::IMAGE_DEBUG_TYPE_OMAP_FROM_SRC)) + .value(PY_ENUM(LIEF::PE::DEBUG_TYPES::IMAGE_DEBUG_TYPE_BORLAND)) + .value(PY_ENUM(LIEF::PE::DEBUG_TYPES::IMAGE_DEBUG_TYPE_CLSID)) + .export_values(); + + + + + + + + + + +} + diff --git a/api/python/README.in b/api/python/README.in new file mode 100644 index 0000000..501ac01 --- /dev/null +++ b/api/python/README.in @@ -0,0 +1,15 @@ +LIEF - Python API +----------------- + +The purpose of this project is to provide a cross platform library which can parse, modify and abstract ELF, PE and MachO formats. + +Main features: + + * Parsing: LIEF can parse ELF, PE, MachO and provides an user-friendly API to access to format internals. + * Modify: LIEF enables to modify some parts of these formats + * Abstract: Three formats have common features like sections, symbols, entry point... LIEF factors them. + * API: LIEF can be used in C, C++ and Python + + + + diff --git a/api/python/__init__.py.in b/api/python/__init__.py.in new file mode 100644 index 0000000..e69de29 diff --git a/api/python/pyExceptions.cpp b/api/python/pyExceptions.cpp new file mode 100644 index 0000000..e2e0386 --- /dev/null +++ b/api/python/pyExceptions.cpp @@ -0,0 +1,34 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyLIEF.hpp" +#include "LIEF/exception.hpp" + +void init_LIEF_exceptions(py::module& m) { + auto&& exception = py::register_exception(m, "exception"); + auto&& bad_file = py::register_exception(m, "bad_file", exception.ptr()); + py::register_exception(m, "bad_format", bad_file.ptr()); + py::register_exception(m, "not_implemented", exception.ptr()); + py::register_exception(m, "not_supported", exception.ptr()); + py::register_exception(m, "read_out_of_bound", exception.ptr()); + py::register_exception(m, "not_found", exception.ptr()); + py::register_exception(m, "corrupted", exception.ptr()); + py::register_exception(m, "conversion_error", exception.ptr()); + py::register_exception(m, "type_error", exception.ptr()); + py::register_exception(m, "builder_error", exception.ptr()); + py::register_exception(m, "parser_error", exception.ptr()); + auto&& pe_error = py::register_exception(m, "pe_error", exception.ptr()); + py::register_exception(m, "pe_bad_section_name", pe_error.ptr()); +} diff --git a/api/python/pyIterators.cpp b/api/python/pyIterators.cpp new file mode 100644 index 0000000..ae528b2 --- /dev/null +++ b/api/python/pyIterators.cpp @@ -0,0 +1,68 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 "pyLIEF.hpp" +#include "pyIterators.hpp" + +#include "LIEF/PE/signature/types.hpp" + +void init_LIEF_iterators(py::module& m) { + // Abstract + // ======== + init_ref_iterator(m); + init_ref_iterator(m); + + // ELF + // === +#if defined(LIEF_ELF_MODULE) + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator>(m); + init_ref_iterator(m); + init_ref_iterator(m); +#endif + + // PE + // == +#if defined(LIEF_PE_MODULE) + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); +#endif + + + // MachO + // ===== +#if defined(LIEF_MACHO_MODULE) + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator>(m); + init_ref_iterator(m); + init_ref_iterator(m); + init_ref_iterator(m); +#endif + +} diff --git a/api/python/pyIterators.hpp b/api/python/pyIterators.hpp new file mode 100644 index 0000000..f412803 --- /dev/null +++ b/api/python/pyIterators.hpp @@ -0,0 +1,67 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 PY_LIEF_ITERATORS_H_ +#define PY_LIEF_ITERATORS_H_ +#include + + +#include "LIEF/LIEF.hpp" +#include "LIEF/Abstract/type_traits.hpp" +#include "LIEF/ELF/type_traits.hpp" +#include "LIEF/PE/type_traits.hpp" +#include "LIEF/MachO/type_traits.hpp" + + +namespace py = pybind11; + + +void init_LIEF_iterators(py::module&); + +template +void init_ref_iterator(py::module& m) { + py::class_(m, typeid(T).name()) + .def("__getitem__", + [](T& v, size_t i) -> typename T::reference { + if (i >= v.size()) + throw py::index_error(); + return v[i]; + }, + py::return_value_policy::reference) + + .def("__len__", + [](T& v) { + return v.size(); + }) + + .def("__iter__", + [](T& v) -> T { + return std::begin(v); + }, py::return_value_policy::reference_internal) + + .def("__next__", + [] (T& v) -> typename T::reference { + if (v == std::end(v)) { + throw py::stop_iteration(); + } + return *(v++); + + }, py::return_value_policy::reference); + + + +} + +#endif diff --git a/api/python/pyJson.cpp b/api/python/pyJson.cpp new file mode 100644 index 0000000..d650acc --- /dev/null +++ b/api/python/pyJson.cpp @@ -0,0 +1,51 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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/to_json.hpp" + +#include "pyLIEF.hpp" + +void init_json_functions(py::module& m) { + +#if defined(LIEF_ELF_MODULE) + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); +#endif + + m.def("to_json", &LIEF::to_json_str); + m.def("abstract_to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + m.def("to_json", &LIEF::to_json_str); + + + + +} diff --git a/api/python/pyLIEF.cpp b/api/python/pyLIEF.cpp new file mode 100644 index 0000000..b768f72 --- /dev/null +++ b/api/python/pyLIEF.cpp @@ -0,0 +1,52 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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/logging.hpp" +#include "pyLIEF.hpp" + +PYBIND11_PLUGIN(lief) { + + py::module LIEF_module("lief", "Python API for LIEF"); + + init_LIEF_iterators(LIEF_module); + + // Init custom LIEF exceptions + init_LIEF_exceptions(LIEF_module); + + // Init the LIEF module + init_LIEF_module(LIEF_module); + + // Init the ELF module +#if defined(LIEF_ELF_MODULE) + init_ELF_module(LIEF_module); +#endif + + // Init the PE module +#if defined(LIEF_PE_MODULE) + init_PE_module(LIEF_module); +#endif + + // Init the MachO module +#if defined(LIEF_MACHO_MODULE) + init_MachO_module(LIEF_module); +#endif + + // Init util functions + init_utils_functions(LIEF_module); + + init_json_functions(LIEF_module); + + return LIEF_module.ptr(); +} diff --git a/api/python/pyLIEF.hpp b/api/python/pyLIEF.hpp new file mode 100644 index 0000000..c89df5a --- /dev/null +++ b/api/python/pyLIEF.hpp @@ -0,0 +1,39 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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 PY_LIEF_H_ +#define PY_LIEF_H_ + +#include +#include +#include + +#include "pyIterators.hpp" + +namespace py = pybind11; + +using namespace pybind11::literals; + +void init_LIEF_exceptions(py::module&); +void init_LIEF_module(py::module&); +void init_ELF_module(py::module&); +void init_PE_module(py::module&); +void init_MachO_module(py::module&); +void init_utils_functions(py::module&); +void init_json_functions(py::module&); + +#define RST_CLASS_REF(X) ":class:`~"#X"`" + +#endif diff --git a/api/python/pyUtils.cpp b/api/python/pyUtils.cpp new file mode 100644 index 0000000..dc7ff83 --- /dev/null +++ b/api/python/pyUtils.cpp @@ -0,0 +1,36 @@ +/* Copyright 2017 R. Thomas + * Copyright 2017 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/PE/utils.hpp" +#include "LIEF/MachO/utils.hpp" +#include "LIEF/ELF/utils.hpp" + +#include "pyLIEF.hpp" + +void init_utils_functions(py::module& m) { + +#if defined(LIEF_PE_MODULE) + m.def("is_pe", static_cast(&LIEF::PE::is_pe), "Check if the given binary is ``PE``"); +#endif + +#if defined(LIEF_ELF_MODULE) + m.def("is_elf", &LIEF::ELF::is_elf, "Check if the given binary is ``ELF``"); +#endif + +#if defined(LIEF_MACHO_MODULE) + m.def("is_macho", &LIEF::MachO::is_macho, "Check if the given binary is ``MachO``"); +#endif + +} diff --git a/api/python/setup.py.in b/api/python/setup.py.in new file mode 100644 index 0000000..27576db --- /dev/null +++ b/api/python/setup.py.in @@ -0,0 +1,39 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +from setuptools import setup +import os +import site + + +package_description = ''' +LIEF is a library to instrument executable formats +'''.strip() + +setup( + name = 'lief', + version = '@LIEF_VERSION_MAJOR@.@LIEF_VERSION_MINOR@.@LIEF_VERSION_PATCH@', + license = "Apache 2.0", + description = package_description, + url = 'http://lief.quarkslab.com', + author = 'Romain Thomas', + author_email = 'rthomas@quarkslab.com', + packages = [''], + package_data = {'': ['@LIEF_LIBRARY_NAME@']}, + keywords = 'elf pe macho', + classifiers = [ + 'License :: OSI Approved :: Apache Software License', + 'Development Status :: 4 - Beta', + 'Environment :: Console', + 'Intended Audience :: Developers', + 'Intended Audience :: Science/Research', + 'Operating System :: MacOS :: MacOS X', + 'Operating System :: POSIX :: Linux', + 'Operating System :: Windows :: Windows', + 'Programming Language :: C++', + 'Programming Language :: Python :: @PYTHON_VERSION@', + 'Topic :: Software Development :: Libraries', + 'Topic :: Security', + 'Topic :: Scientific/Engineering :: Information Analysis', + 'Topic :: Software Development :: Build Tools', + ] +) diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt new file mode 100644 index 0000000..d164a30 --- /dev/null +++ b/doc/CMakeLists.txt @@ -0,0 +1,93 @@ +find_package(Doxygen) +find_program(SPHINX_BUILD_BIN NAMES sphinx-build) + +if(NOT DOXYGEN_FOUND) + message(STATUS "Doc disabled: doxygen not found") +elseif(NOT SPHINX_BUILD_BIN) + message(STATUS "Doc disabled: sphinx-build not found") +elseif(${CMAKE_CURRENT_SOURCE_DIR} STREQUAL ${CMAKE_CURRENT_BINARY_DIR}) + message(STATUS "You have to build the doc in another directory !") +else() + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/Doxyfile.in + ${CMAKE_CURRENT_BINARY_DIR}/doxygen/Doxyfile @ONLY) + + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/conf.py.in + ${CMAKE_CURRENT_BINARY_DIR}/sphinx-src/conf.py @ONLY) + + file(GLOB PACKER_DOC_RST RELATIVE + "${CMAKE_CURRENT_SOURCE_DIR}/sphinx" + "${CMAKE_CURRENT_SOURCE_DIR}/sphinx/*.rst") + + file( + COPY ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/ + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/sphinx-src + PATTERN "*.in" EXCLUDE) + + file( + COPY ${CMAKE_CURRENT_SOURCE_DIR}/sphinx/_static + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/sphinx-src/_static + ) + + file( + COPY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/ + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html + PATTERN "*.css") + + file( + COPY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/ + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html + PATTERN "*.js") + + file( + COPY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/fonts + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html + ) + + file( + COPY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/js + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html + ) + + file( + COPY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/css + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html + ) + + file( + COPY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/header.html + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/doxygen) + + + file( + COPY ${CMAKE_CURRENT_SOURCE_DIR}/doxygen/footer.html + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/doxygen) + + file( + COPY ${CMAKE_SOURCE_DIR}/README.md + DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/doxygen + ) + + add_custom_target(doc-lief ALL + COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/doxygen/Doxyfile + COMMAND ${CMAKE_COMMAND} -E env "PYTHONPATH=${PROJECT_BINARY_DIR}/api/python:$ENV{PYTHONPATH}" ${SPHINX_BUILD_BIN} ${CMAKE_CURRENT_BINARY_DIR}/sphinx-src sphinx-doc + DEPENDS pyLIEF LIB_LIEF_STATIC + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + COMMENT "Generating documentation with Doxygen and Sphinx" VERBATIM) + + install( + DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/doxygen/html/ + DESTINATION + share/doc/lief/doxygen + COMPONENT doc) + + install( + DIRECTORY + ${CMAKE_CURRENT_BINARY_DIR}/sphinx-doc/ + DESTINATION + share/doc/lief/sphinx + COMPONENT doc) + +endif() diff --git a/doc/doxygen/Doxyfile.in b/doc/doxygen/Doxyfile.in new file mode 100644 index 0000000..e810c82 --- /dev/null +++ b/doc/doxygen/Doxyfile.in @@ -0,0 +1,2392 @@ +# Doxyfile 1.8.10 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project. +# +# All text after a double hash (##) is considered a comment and is placed in +# front of the TAG it is preceding. +# +# All text after a single hash (#) is considered a comment and will be ignored. +# The format is: +# TAG = value [value, ...] +# For lists, items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (\" \"). + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all text +# before the first occurrence of this tag. Doxygen uses libiconv (or the iconv +# built into libc) for the transcoding. See http://www.gnu.org/software/libiconv +# for the list of possible encodings. +# The default value is: UTF-8. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded by +# double-quotes, unless you are using Doxywizard) that should identify the +# project for which the documentation is generated. This name is used in the +# title of most generated pages and in a few other places. +# The default value is: My Project. + +PROJECT_NAME = "Library to Instrument Executable Formats (LIEF)" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. This +# could be handy for archiving the generated documentation or if some version +# control system is used. + +PROJECT_NUMBER = "version @LIEF_VERSION_MAJOR@.@LIEF_VERSION_MINOR@.@LIEF_VERSION_PATCH@" + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer a +# quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = + +# With the PROJECT_LOGO tag one can specify a logo or an icon that is included +# in the documentation. The maximum height of the logo should not exceed 55 +# pixels and the maximum width should not exceed 200 pixels. Doxygen will copy +# the logo to the output directory. + +PROJECT_LOGO = @PROJECT_SOURCE_DIR@/doc/doxygen/logo_lief_55.png + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) path +# into which the generated documentation will be written. If a relative path is +# entered, it will be relative to the location where doxygen was started. If +# left blank the current directory will be used. + +OUTPUT_DIRECTORY = ./doxygen + +# If the CREATE_SUBDIRS tag is set to YES then doxygen will create 4096 sub- +# directories (in 2 levels) under the output directory of each output format and +# will distribute the generated files over these directories. Enabling this +# option can be useful when feeding doxygen a huge amount of source files, where +# putting all generated files in the same directory would otherwise causes +# performance problems for the file system. +# The default value is: NO. + +CREATE_SUBDIRS = NO + +# If the ALLOW_UNICODE_NAMES tag is set to YES, doxygen will allow non-ASCII +# characters to appear in the names of generated files. If set to NO, non-ASCII +# characters will be escaped, for example _xE3_x81_x84 will be used for Unicode +# U+3044. +# The default value is: NO. + +ALLOW_UNICODE_NAMES = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# Possible values are: Afrikaans, Arabic, Armenian, Brazilian, Catalan, Chinese, +# Chinese-Traditional, Croatian, Czech, Danish, Dutch, English (United States), +# Esperanto, Farsi (Persian), Finnish, French, German, Greek, Hungarian, +# Indonesian, Italian, Japanese, Japanese-en (Japanese with English messages), +# Korean, Korean-en (Korean with English messages), Latvian, Lithuanian, +# Macedonian, Norwegian, Persian (Farsi), Polish, Portuguese, Romanian, Russian, +# Serbian, Serbian-Cyrillic, Slovak, Slovene, Spanish, Swedish, Turkish, +# Ukrainian and Vietnamese. +# The default value is: English. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES, doxygen will include brief member +# descriptions after the members that are listed in the file and class +# documentation (similar to Javadoc). Set to NO to disable this. +# The default value is: YES. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES, doxygen will prepend the brief +# description of a member or function before the detailed description +# +# Note: If both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. +# The default value is: YES. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator that is +# used to form the text in various listings. Each string in this list, if found +# as the leading text of the brief description, will be stripped from the text +# and the result, after processing the whole list, is used as the annotated +# text. Otherwise, the brief description is used as-is. If left blank, the +# following values are used ($name is automatically replaced with the name of +# the entity):The $name class, The $name widget, The $name file, is, provides, +# specifies, contains, represents, a, an and the. + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# doxygen will generate a detailed section even if there is only a brief +# description. +# The default value is: NO. + +ALWAYS_DETAILED_SEC = NO + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. +# The default value is: NO. + +INLINE_INHERITED_MEMB = NO + +# If the FULL_PATH_NAMES tag is set to YES, doxygen will prepend the full path +# before files name in the file list and in the header files. If set to NO the +# shortest path that makes the file name unique will be used +# The default value is: YES. + +FULL_PATH_NAMES = YES + +# The STRIP_FROM_PATH tag can be used to strip a user-defined part of the path. +# Stripping is only done if one of the specified strings matches the left-hand +# part of the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the path to +# strip. +# +# Note that you can specify absolute paths here, but also relative paths, which +# will be relative from the directory where doxygen is started. +# This tag requires that the tag FULL_PATH_NAMES is set to YES. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of the +# path mentioned in the documentation of a class, which tells the reader which +# header file to include in order to use a class. If left blank only the name of +# the header file containing the class definition is used. Otherwise one should +# specify the list of include paths that are normally passed to the compiler +# using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter (but +# less readable) file names. This can be useful is your file systems doesn't +# support long names like on DOS, Mac, or CD-ROM. +# The default value is: NO. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then doxygen will interpret the +# first line (until the first dot) of a Javadoc-style comment as the brief +# description. If set to NO, the Javadoc-style will behave just like regular Qt- +# style comments (thus requiring an explicit @brief command for a brief +# description.) +# The default value is: NO. + +JAVADOC_AUTOBRIEF = NO + +# If the QT_AUTOBRIEF tag is set to YES then doxygen will interpret the first +# line (until the first dot) of a Qt-style comment as the brief description. If +# set to NO, the Qt-style will behave just like regular Qt-style comments (thus +# requiring an explicit \brief command for a brief description.) +# The default value is: NO. + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make doxygen treat a +# multi-line C++ special comment block (i.e. a block of //! or /// comments) as +# a brief description. This used to be the default behavior. The new default is +# to treat a multi-line C++ comment block as a detailed description. Set this +# tag to YES if you prefer the old behavior instead. +# +# Note that setting this tag to YES also means that rational rose comments are +# not recognized any more. +# The default value is: NO. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES then an undocumented member inherits the +# documentation from any documented member that it re-implements. +# The default value is: YES. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES then doxygen will produce a new +# page for each member. If set to NO, the documentation of a member will be part +# of the file/class/namespace that contains it. +# The default value is: NO. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. Doxygen +# uses this value to replace tabs by spaces in code fragments. +# Minimum value: 1, maximum value: 16, default value: 4. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that act as commands in +# the documentation. An alias has the form: +# name=value +# For example adding +# "sideeffect=@par Side Effects:\n" +# will allow you to put the command \sideeffect (or @sideeffect) in the +# documentation, which will result in a user-defined paragraph with heading +# "Side Effects:". You can put \n's in the value part of an alias to insert +# newlines. + +ALIASES = + +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding "class=itcl::class" +# will allow you to use the command class in the itcl::class meaning. + +TCL_SUBST = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C sources +# only. Doxygen will then generate output that is more tailored for C. For +# instance, some of the names that are used will be different. The list of all +# members will be omitted, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java or +# Python sources only. Doxygen will then generate output that is more tailored +# for that language. For instance, namespaces will be presented as packages, +# qualified scopes will look different, etc. +# The default value is: NO. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources. Doxygen will then generate output that is tailored for Fortran. +# The default value is: NO. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for VHDL. +# The default value is: NO. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, and +# language is one of the parsers supported by doxygen: IDL, Java, Javascript, +# C#, C, C++, D, PHP, Objective-C, Python, Fortran (fixed format Fortran: +# FortranFixed, free formatted Fortran: FortranFree, unknown formatted Fortran: +# Fortran. In the later case the parser tries to guess whether the code is fixed +# or free formatted code, this is the default for Fortran type files), VHDL. For +# instance to make doxygen treat .inc files as Fortran files (default is PHP), +# and .f files as C (default is Fortran), use: inc=Fortran f=C. +# +# Note: For files without extension you can use no_extension as a placeholder. +# +# Note that for custom extensions you also need to set FILE_PATTERNS otherwise +# the files are not read by doxygen. + +EXTENSION_MAPPING = + +# If the MARKDOWN_SUPPORT tag is enabled then doxygen pre-processes all comments +# according to the Markdown format, which allows for more readable +# documentation. See http://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you can +# mix doxygen, HTML, and XML commands with Markdown formatting. Disable only in +# case of backward compatibilities issues. +# The default value is: YES. + +MARKDOWN_SUPPORT = YES + +# When enabled doxygen tries to link words that correspond to documented +# classes, or namespaces to their corresponding documentation. Such a link can +# be prevented in individual cases by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. +# The default value is: YES. + +AUTOLINK_SUPPORT = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should set this +# tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); +# versus func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. +# The default value is: NO. + +BUILTIN_STL_SUPPORT = NO + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. +# The default value is: NO. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip (see: +# http://www.riverbankcomputing.co.uk/software/sip/intro) sources only. Doxygen +# will parse them like normal C++ but will assume all classes use public instead +# of private inheritance when no explicit protection keyword is present. +# The default value is: NO. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES will make +# doxygen to replace the get and set methods by a property in the documentation. +# This will only work if the methods are indeed getting or setting a simple +# type. If this is not the case, or you want to show the methods anyway, you +# should set this option to NO. +# The default value is: YES. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. +# The default value is: NO. + +DISTRIBUTE_GROUP_DOC = NO + +# If one adds a struct or class to a group and this option is enabled, then also +# any nested class or struct is added to the same group. By default this option +# is disabled and one has to add nested compounds explicitly via \ingroup. +# The default value is: NO. + +GROUP_NESTED_COMPOUNDS = NO + +# Set the SUBGROUPING tag to YES to allow class member groups of the same type +# (for instance a group of public functions) to be put as a subgroup of that +# type (e.g. under the Public Functions section). Set it to NO to prevent +# subgrouping. Alternatively, this can be done per class using the +# \nosubgrouping command. +# The default value is: YES. + +SUBGROUPING = YES + +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and unions +# are shown inside the group in which they are included (e.g. using \ingroup) +# instead of on a separate page (for HTML and Man pages) or section (for LaTeX +# and RTF). +# +# Note that this feature does not work in combination with +# SEPARATE_MEMBER_PAGES. +# The default value is: NO. + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and unions +# with only public data fields or simple typedef fields will be shown inline in +# the documentation of the scope in which they are defined (i.e. file, +# namespace, or group documentation), provided this scope is documented. If set +# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# Man pages) or section (for LaTeX and RTF). +# The default value is: NO. + +INLINE_SIMPLE_STRUCTS = NO + +# When TYPEDEF_HIDES_STRUCT tag is enabled, a typedef of a struct, union, or +# enum is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically be +# useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. +# The default value is: NO. + +TYPEDEF_HIDES_STRUCT = NO + +# The size of the symbol lookup cache can be set using LOOKUP_CACHE_SIZE. This +# cache is used to resolve symbols given their name and scope. Since this can be +# an expensive process and often the same symbol appears multiple times in the +# code, doxygen keeps a cache of pre-resolved symbols. If the cache is too small +# doxygen will become slower. If the cache is too large, memory is wasted. The +# cache size is given by this formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range +# is 0..9, the default is 0, corresponding to a cache size of 2^16=65536 +# symbols. At the end of a run doxygen will report the cache usage and suggest +# the optimal cache size from a speed point of view. +# Minimum value: 0, maximum value: 9, default value: 0. + +LOOKUP_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES, doxygen will assume all entities in +# documentation are documented, even if no documentation was available. Private +# class members and static file members will be hidden unless the +# EXTRACT_PRIVATE respectively EXTRACT_STATIC tags are set to YES. +# Note: This will also disable the warnings about undocumented members that are +# normally produced when WARNINGS is set to YES. +# The default value is: NO. + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES, all private members of a class will +# be included in the documentation. +# The default value is: NO. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_PACKAGE tag is set to YES, all members with package or internal +# scope will be included in the documentation. +# The default value is: NO. + +EXTRACT_PACKAGE = NO + +# If the EXTRACT_STATIC tag is set to YES, all static members of a file will be +# included in the documentation. +# The default value is: NO. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES, classes (and structs) defined +# locally in source files will be included in the documentation. If set to NO, +# only classes defined in header files are included. Does not have any effect +# for Java sources. +# The default value is: YES. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. If set to YES, local methods, +# which are defined in the implementation section but not in the interface are +# included in the documentation. If set to NO, only methods in the interface are +# included. +# The default value is: NO. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base name of +# the file that contains the anonymous namespace. By default anonymous namespace +# are hidden. +# The default value is: NO. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, doxygen will hide all +# undocumented members inside documented classes or files. If set to NO these +# members will be included in the various overviews, but no documentation +# section is generated. This option has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. If set +# to NO, these classes will be included in the various overviews. This option +# has no effect if EXTRACT_ALL is enabled. +# The default value is: NO. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, doxygen will hide all friend +# (class|struct|union) declarations. If set to NO, these declarations will be +# included in the documentation. +# The default value is: NO. + +HIDE_FRIEND_COMPOUNDS = YES + +# If the HIDE_IN_BODY_DOCS tag is set to YES, doxygen will hide any +# documentation blocks found inside the body of a function. If set to NO, these +# blocks will be appended to the function's detailed documentation block. +# The default value is: NO. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation that is typed after a +# \internal command is included. If the tag is set to NO then the documentation +# will be excluded. Set it to YES to include the internal documentation. +# The default value is: NO. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then doxygen will only generate file +# names in lower-case letters. If set to YES, upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. +# The default value is: system dependent. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO then doxygen will show members with +# their full class and namespace scopes in the documentation. If set to YES, the +# scope will be hidden. +# The default value is: NO. + +HIDE_SCOPE_NAMES = NO + +# If the HIDE_COMPOUND_REFERENCE tag is set to NO (default) then doxygen will +# append additional text to a page's title, such as Class Reference. If set to +# YES the compound reference will be hidden. +# The default value is: NO. + +HIDE_COMPOUND_REFERENCE= NO + +# If the SHOW_INCLUDE_FILES tag is set to YES then doxygen will put a list of +# the files that are included by a file in the documentation of that file. +# The default value is: YES. + +SHOW_INCLUDE_FILES = YES + +# If the SHOW_GROUPED_MEMB_INC tag is set to YES then Doxygen will add for each +# grouped member an include statement to the documentation, telling the reader +# which file to include in order to use the member. +# The default value is: NO. + +SHOW_GROUPED_MEMB_INC = NO + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then doxygen will list include +# files with double quotes in the documentation rather than with sharp brackets. +# The default value is: NO. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES then a tag [inline] is inserted in the +# documentation for inline members. +# The default value is: YES. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES then doxygen will sort the +# (detailed) documentation of file and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. +# The default value is: YES. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the brief +# descriptions of file, namespace and class members alphabetically by member +# name. If set to NO, the members will appear in declaration order. Note that +# this will also influence the order of the classes in the class list. +# The default value is: NO. + +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen will sort the +# (brief and detailed) documentation of class members so that constructors and +# destructors are listed first. If set to NO the constructors will appear in the +# respective orders defined by SORT_BRIEF_DOCS and SORT_MEMBER_DOCS. +# Note: If SORT_BRIEF_DOCS is set to NO this option is ignored for sorting brief +# member documentation. +# Note: If SORT_MEMBER_DOCS is set to NO this option is ignored for sorting +# detailed member documentation. +# The default value is: NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the hierarchy +# of group names into alphabetical order. If set to NO the group names will +# appear in their defined order. +# The default value is: NO. + +SORT_GROUP_NAMES = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be sorted by +# fully-qualified names, including namespaces. If set to NO, the class list will +# be sorted only by class name, not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the alphabetical +# list. +# The default value is: NO. + +SORT_BY_SCOPE_NAME = NO + +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to do proper +# type resolution of all parameters of a function it will reject a match between +# the prototype and the implementation of a member function even if there is +# only one candidate or it is obvious which candidate to choose by doing a +# simple string match. By disabling STRICT_PROTO_MATCHING doxygen will still +# accept a match between prototype and implementation in such cases. +# The default value is: NO. + +STRICT_PROTO_MATCHING = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or disable (NO) the todo +# list. This list is created by putting \todo commands in the documentation. +# The default value is: YES. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or disable (NO) the test +# list. This list is created by putting \test commands in the documentation. +# The default value is: YES. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or disable (NO) the bug +# list. This list is created by putting \bug commands in the documentation. +# The default value is: YES. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or disable (NO) +# the deprecated list. This list is created by putting \deprecated commands in +# the documentation. +# The default value is: YES. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional documentation +# sections, marked by \if ... \endif and \cond +# ... \endcond blocks. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines that the +# initial value of a variable or macro / define can have for it to appear in the +# documentation. If the initializer consists of more lines than specified here +# it will be hidden. Use a value of 0 to hide initializers completely. The +# appearance of the value of individual variables and macros / defines can be +# controlled using \showinitializer or \hideinitializer command in the +# documentation regardless of this setting. +# Minimum value: 0, maximum value: 10000, default value: 30. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated at +# the bottom of the documentation of classes and structs. If set to YES, the +# list will mention the files that were used to generate the documentation. +# The default value is: YES. + +SHOW_USED_FILES = NO + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. This +# will remove the Files entry from the Quick Index and from the Folder Tree View +# (if specified). +# The default value is: YES. + +SHOW_FILES = NO + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the Namespaces +# page. This will remove the Namespaces entry from the Quick Index and from the +# Folder Tree View (if specified). +# The default value is: YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command command input-file, where command is the value of the +# FILE_VERSION_FILTER tag, and input-file is the name of an input file provided +# by doxygen. Whatever the program writes to standard output is used as the file +# version. For an example see the documentation. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. You can +# optionally specify a file name after the option, if omitted DoxygenLayout.xml +# will be used as the name of the layout file. +# +# Note that if you run doxygen from a directory containing a file called +# DoxygenLayout.xml, doxygen will parse it automatically even if the LAYOUT_FILE +# tag is left empty. + +LAYOUT_FILE = + +# The CITE_BIB_FILES tag can be used to specify one or more bib files containing +# the reference definitions. This must be a list of .bib files. The .bib +# extension is automatically appended if omitted. This requires the bibtex tool +# to be installed. See also http://en.wikipedia.org/wiki/BibTeX for more info. +# For LaTeX the style of the bibliography can be controlled using +# LATEX_BIB_STYLE. To use this feature you need bibtex and perl available in the +# search path. See also \cite for info how to create references. + +CITE_BIB_FILES = + +#--------------------------------------------------------------------------- +# Configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated to +# standard output by doxygen. If QUIET is set to YES this implies that the +# messages are off. +# The default value is: NO. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated to standard error (stderr) by doxygen. If WARNINGS is set to YES +# this implies that the warnings are on. +# +# Tip: Turn warnings on while writing the documentation. +# The default value is: YES. + +WARNINGS = YES + +# If the WARN_IF_UNDOCUMENTED tag is set to YES then doxygen will generate +# warnings for undocumented members. If EXTRACT_ALL is set to YES then this flag +# will automatically be disabled. +# The default value is: YES. + +WARN_IF_UNDOCUMENTED = NO + +# If the WARN_IF_DOC_ERROR tag is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some parameters +# in a documented function, or documenting parameters that don't exist or using +# markup commands wrongly. +# The default value is: YES. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be enabled to get warnings for functions that +# are documented, but have no documentation for their parameters or return +# value. If set to NO, doxygen will only warn about wrong or incomplete +# parameter documentation, but not about the absence of documentation. +# The default value is: NO. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that doxygen +# can produce. The string should contain the $file, $line, and $text tags, which +# will be replaced by the file and line number from which the warning originated +# and the warning text. Optionally the format may contain $version, which will +# be replaced by the version of the file (if it could be obtained via +# FILE_VERSION_FILTER) +# The default value is: $file:$line: $text. + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning and error +# messages should be written. If left blank the output is written to standard +# error (stderr). + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# Configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag is used to specify the files and/or directories that contain +# documented source files. You may enter file names like myfile.cpp or +# directories like /usr/src/myproject. Separate the files or directories with +# spaces. See also FILE_PATTERNS and EXTENSION_MAPPING +# Note: If this tag is empty the current directory is searched. + +INPUT = \ + @PROJECT_SOURCE_DIR@/src \ + @PROJECT_SOURCE_DIR@/include/LIEF \ + @PROJECT_SOURCE_DIR@/api/c \ + @PROJECT_BINARY_DIR@/include/LIEF \ + @PROJECT_SOURCE_DIR@/doc/doxygen/index.doxygen + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses +# libiconv (or the iconv built into libc) for the transcoding. See the libiconv +# documentation (see: http://www.gnu.org/software/libiconv) for the list of +# possible encodings. +# The default value is: UTF-8. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard patterns (like *.cpp and +# *.h) to filter out the source-files in the directories. +# +# Note that for custom extensions or not directly supported extensions you also +# need to set EXTENSION_MAPPING for the extension otherwise the files are not +# read by doxygen. +# +# If left blank the following patterns are tested:*.c, *.cc, *.cxx, *.cpp, +# *.c++, *.java, *.ii, *.ixx, *.ipp, *.i++, *.inl, *.idl, *.ddl, *.odl, *.h, +# *.hh, *.hxx, *.hpp, *.h++, *.cs, *.d, *.php, *.php4, *.php5, *.phtml, *.inc, +# *.m, *.markdown, *.md, *.mm, *.dox, *.py, *.f90, *.f, *.for, *.tcl, *.vhd, +# *.vhdl, *.ucf, *.qsf, *.as and *.js. + +FILE_PATTERNS = *.cpp *.hpp *.h *.c *.def + +# The RECURSIVE tag can be used to specify whether or not subdirectories should +# be searched for input files as well. +# The default value is: NO. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should be +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# +# Note that relative paths are relative to the directory from which doxygen is +# run. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded +# from the input. +# The default value is: NO. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test +# +# Note that the wildcards are matched against the file with absolute path, so to +# exclude all test directories use the pattern */test/* + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or directories +# that contain example code fragments that are included (see the \include +# command). + +EXAMPLE_PATH = @PROJECT_SOURCE_DIR@/doc/doxygen/welcome.html + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and +# *.h) to filter out the source-files in the directories. If left blank all +# files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude commands +# irrespective of the value of the RECURSIVE tag. +# The default value is: NO. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or directories +# that contain images that are to be included in the documentation (see the +# \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command: +# +# +# +# where is the value of the INPUT_FILTER tag, and is the +# name of an input file. Doxygen will then use the output that the filter +# program writes to standard output. If FILTER_PATTERNS is specified, this tag +# will be ignored. +# +# Note that the filter must not add or remove lines; it is applied before the +# code is scanned, but not when the output code is generated. If lines are added +# or removed, the anchors will not be placed correctly. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: pattern=filter +# (like *.cpp=my_cpp_filter). See INPUT_FILTER for further information on how +# filters are used. If the FILTER_PATTERNS tag is empty or if none of the +# patterns match the file name, INPUT_FILTER is applied. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will also be used to filter the input files that are used for +# producing the source files to browse (i.e. when SOURCE_BROWSER is set to YES). +# The default value is: NO. + +FILTER_SOURCE_FILES = NO + +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) and +# it is also possible to disable source filtering for a specific pattern using +# *.ext= (so without naming a filter). +# This tag requires that the tag FILTER_SOURCE_FILES is set to YES. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MDFILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page +# (index.html). This can be useful if you have a project on for instance GitHub +# and want to reuse the introduction page also for the doxygen output. + +#USE_MDFILE_AS_MAINPAGE = index.md + +#--------------------------------------------------------------------------- +# Configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will be +# generated. Documented entities will be cross-referenced with these sources. +# +# Note: To get rid of all source code in the generated output, make sure that +# also VERBATIM_HEADERS is set to NO. +# The default value is: NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body of functions, +# classes and enums directly into the documentation. +# The default value is: NO. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES will instruct doxygen to hide any +# special comment blocks from generated source code fragments. Normal C, C++ and +# Fortran comments will always remain visible. +# The default value is: YES. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES then for each documented +# function all documented functions referencing it will be listed. +# The default value is: NO. + +REFERENCED_BY_RELATION = NO + +# If the REFERENCES_RELATION tag is set to YES then for each documented function +# all documented entities called/used by that function will be listed. +# The default value is: NO. + +REFERENCES_RELATION = NO + +# If the REFERENCES_LINK_SOURCE tag is set to YES and SOURCE_BROWSER tag is set +# to YES then the hyperlinks from functions in REFERENCES_RELATION and +# REFERENCED_BY_RELATION lists will link to the source code. Otherwise they will +# link to the documentation. +# The default value is: YES. + +REFERENCES_LINK_SOURCE = YES + +# If SOURCE_TOOLTIPS is enabled (the default) then hovering a hyperlink in the +# source code will show a tooltip with additional information such as prototype, +# brief description and links to the definition and documentation. Since this +# will make the HTML file larger and loading of large files a bit slower, you +# can opt to disable this feature. +# The default value is: YES. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +SOURCE_TOOLTIPS = YES + +# If the USE_HTAGS tag is set to YES then the references to source code will +# point to the HTML generated by the htags(1) tool instead of doxygen built-in +# source browser. The htags tool is part of GNU's global source tagging system +# (see http://www.gnu.org/software/global/global.html). You will need version +# 4.8.6 or higher. +# +# To use it do the following: +# - Install the latest version of global +# - Enable SOURCE_BROWSER and USE_HTAGS in the config file +# - Make sure the INPUT points to the root of the source tree +# - Run doxygen as normal +# +# Doxygen will invoke htags (and that will in turn invoke gtags), so these +# tools must be available from the command line (i.e. in the search path). +# +# The result: instead of the source browser generated by doxygen, the links to +# source code will now point to the output of htags. +# The default value is: NO. +# This tag requires that the tag SOURCE_BROWSER is set to YES. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set the YES then doxygen will generate a +# verbatim copy of the header file for each class for which an include is +# specified. Set to NO to disable this. +# See also: Section \class. +# The default value is: YES. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# Configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index of all +# compounds will be generated. Enable this if the project contains a lot of +# classes, structs, unions or interfaces. +# The default value is: YES. + +ALPHABETICAL_INDEX = YES + +# The COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns in +# which the alphabetical index list will be split. +# Minimum value: 1, maximum value: 20, default value: 5. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all classes will +# be put under the same header in the alphabetical index. The IGNORE_PREFIX tag +# can be used to specify a prefix (or a list of prefixes) that should be ignored +# while generating the index headers. +# This tag requires that the tag ALPHABETICAL_INDEX is set to YES. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES, doxygen will generate HTML output +# The default value is: YES. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. If a +# relative path is entered the value of OUTPUT_DIRECTORY will be put in front of +# it. +# The default directory is: html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for each +# generated HTML page (for example: .htm, .php, .asp). +# The default value is: .html. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a user-defined HTML header file for +# each generated HTML page. If the tag is left blank doxygen will generate a +# standard header. +# +# To get valid HTML the header file that includes any scripts and style sheets +# that doxygen needs, which is dependent on the configuration options used (e.g. +# the setting GENERATE_TREEVIEW). It is highly recommended to start with a +# default header using +# doxygen -w html new_header.html new_footer.html new_stylesheet.css +# YourConfigFile +# and then modify the file new_header.html. See also section "Doxygen usage" +# for information on how to generate the default header that doxygen normally +# uses. +# Note: The header is subject to change so you typically have to regenerate the +# default header when upgrading to a newer version of doxygen. For a description +# of the possible markers and block names see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_HEADER = @CMAKE_CURRENT_BINARY_DIR@/doxygen/header.html + +# The HTML_FOOTER tag can be used to specify a user-defined HTML footer for each +# generated HTML page. If the tag is left blank doxygen will generate a standard +# footer. See HTML_HEADER for more information on how to generate a default +# footer and what special commands can be used inside the footer. See also +# section "Doxygen usage" for information on how to generate the default footer +# that doxygen normally uses. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_FOOTER = @CMAKE_CURRENT_BINARY_DIR@/doxygen/footer.html + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading style +# sheet that is used by each HTML page. It can be used to fine-tune the look of +# the HTML output. If left blank doxygen will generate a default style sheet. +# See also section "Doxygen usage" for information on how to generate the style +# sheet that doxygen normally uses. +# Note: It is recommended to use HTML_EXTRA_STYLESHEET instead of this tag, as +# it is more robust and this tag (HTML_STYLESHEET) will in the future become +# obsolete. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_STYLESHEET = +# The HTML_EXTRA_STYLESHEET tag can be used to specify additional user-defined +# cascading style sheets that are included after the standard style sheets +# created by doxygen. Using this option one can overrule certain style aspects. +# This is preferred over using HTML_STYLESHEET since it does not replace the +# standard style sheet and is therefore more robust against future updates. +# Doxygen will copy the style sheet files to the output directory. +# Note: The order of the extra style sheet files is of importance (e.g. the last +# style sheet in the list overrules the setting of the previous ones in the +# list). For an example see the documentation. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_STYLESHEET = +#HTML_EXTRA_STYLESHEET = @CMAKE_CURRENT_BINARY_DIR@/doxygen/customdoxygen.css + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath^ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that the +# files will be copied as-is; there are no commands or markers available. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. Doxygen +# will adjust the colors in the style sheet and background images according to +# this color. Hue is specified as an angle on a colorwheel, see +# http://en.wikipedia.org/wiki/Hue for more information. For instance the value +# 0 represents red, 60 is yellow, 120 is green, 180 is cyan, 240 is blue, 300 +# purple, and 360 is red again. +# Minimum value: 0, maximum value: 359, default value: 220. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of the colors +# in the HTML output. For a value of 0 the output will use grayscales only. A +# value of 255 will produce the most vivid colors. +# Minimum value: 0, maximum value: 255, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to the +# luminance component of the colors in the HTML output. Values below 100 +# gradually make the output lighter, whereas values above 100 make the output +# darker. The value divided by 100 is the actual gamma applied, so 80 represents +# a gamma of 0.8, The value 220 represents a gamma of 2.2, and 100 does not +# change the gamma. +# Minimum value: 40, maximum value: 240, default value: 80. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting this +# to YES can help to show when doxygen was last run and thus if the +# documentation is up to date. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_TIMESTAMP = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_DYNAMIC_SECTIONS = NO + +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of entries +# shown in the various tree structured indices initially; the user can expand +# and collapse entries dynamically later on. Doxygen will expand the tree to +# such a level that at most the specified number of entries are visible (unless +# a fully collapsed tree already exceeds this amount). So setting the number of +# entries 1 will produce a full collapsed tree by default. 0 is a special value +# representing an infinite number of entries and will result in a full expanded +# tree by default. +# Minimum value: 0, maximum value: 9999, default value: 100. +# This tag requires that the tag GENERATE_HTML is set to YES. + +HTML_INDEX_NUM_ENTRIES = 100 + +# If the GENERATE_DOCSET tag is set to YES, additional index files will be +# generated that can be used as input for Apple's Xcode 3 integrated development +# environment (see: http://developer.apple.com/tools/xcode/), introduced with +# OSX 10.5 (Leopard). To create a documentation set, doxygen will generate a +# Makefile in the HTML output directory. Running make will produce the docset in +# that directory and running make install will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find it at +# startup. See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_DOCSET = NO + +# This tag determines the name of the docset feed. A documentation feed provides +# an umbrella under which multiple documentation sets from a single provider +# (such as a company or product suite) can be grouped. +# The default value is: Doxygen generated docs. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# This tag specifies a string that should uniquely identify the documentation +# set bundle. This should be a reverse domain-name style string, e.g. +# com.mycompany.MyDocSet. Doxygen will append .docset to the name. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# The DOCSET_PUBLISHER_ID tag specifies a string that should uniquely identify +# the documentation publisher. This should be a reverse domain-name style +# string, e.g. com.mycompany.MyDocSet.documentation. +# The default value is: org.doxygen.Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The DOCSET_PUBLISHER_NAME tag identifies the documentation publisher. +# The default value is: Publisher. +# This tag requires that the tag GENERATE_DOCSET is set to YES. + +DOCSET_PUBLISHER_NAME = Publisher + +# If the GENERATE_HTMLHELP tag is set to YES then doxygen generates three +# additional HTML index files: index.hhp, index.hhc, and index.hhk. The +# index.hhp is a project file that can be read by Microsoft's HTML Help Workshop +# (see: http://www.microsoft.com/en-us/download/details.aspx?id=21138) on +# Windows. +# +# The HTML Help Workshop contains a compiler that can convert all HTML output +# generated by doxygen into a single compiled HTML file (.chm). Compiled HTML +# files are now used as the Windows 98 help format, and will replace the old +# Windows help format (.hlp) on all Windows platforms in the future. Compressed +# HTML files also contain an index, a table of contents, and you can search for +# words in the documentation. The HTML workshop also contains a viewer for +# compressed HTML files. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_HTMLHELP = NO + +# The CHM_FILE tag can be used to specify the file name of the resulting .chm +# file. You can add a path in front of the file if the result should not be +# written to the html output directory. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_FILE = + +# The HHC_LOCATION tag can be used to specify the location (absolute path +# including file name) of the HTML help compiler (hhc.exe). If non-empty, +# doxygen will try to run the HTML help compiler on the generated index.hhp. +# The file has to be specified with full path. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +HHC_LOCATION = + +# The GENERATE_CHI flag controls if a separate .chi index file is generated +# (YES) or that it should be included in the master .chm file (NO). +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +GENERATE_CHI = NO + +# The CHM_INDEX_ENCODING is used to encode HtmlHelp index (hhk), content (hhc) +# and project file content. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +CHM_INDEX_ENCODING = + +# The BINARY_TOC flag controls whether a binary table of contents is generated +# (YES) or a normal table of contents (NO) in the .chm file. Furthermore it +# enables the Previous and Next buttons. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +BINARY_TOC = YES + +# The TOC_EXPAND flag can be set to YES to add extra items for group members to +# the table of contents of the HTML help documentation and to the tree view. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTMLHELP is set to YES. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated that +# can be used as input for Qt's qhelpgenerator to generate a Qt Compressed Help +# (.qch) of the generated HTML documentation. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_QHP = YES + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can be used to specify +# the file name of the resulting .qch file. The path specified is relative to +# the HTML output folder. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QCH_FILE = lief.qch + +# The QHP_NAMESPACE tag specifies the namespace to use when generating Qt Help +# Project output. For more information please see Qt Help Project / Namespace +# (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#namespace). +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_NAMESPACE = org.lief + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating Qt +# Help Project output. For more information please see Qt Help Project / Virtual +# Folders (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#virtual- +# folders). +# The default value is: doc. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_VIRTUAL_FOLDER = liefdoc + +# If the QHP_CUST_FILTER_NAME tag is set, it specifies the name of a custom +# filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILTER_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see Qt Help Project / Custom +# Filters (see: http://qt-project.org/doc/qt-4.8/qthelpproject.html#custom- +# filters). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's filter section matches. Qt Help Project / Filter Attributes (see: +# http://qt-project.org/doc/qt-4.8/qthelpproject.html#filter-attributes). +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHP_SECT_FILTER_ATTRS = + +# The QHG_LOCATION tag can be used to specify the location of Qt's +# qhelpgenerator. If non-empty doxygen will try to run qhelpgenerator on the +# generated .qhp file. +# This tag requires that the tag GENERATE_QHP is set to YES. + +QHG_LOCATION = /usr/bin/qhelpgenerator + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files will be +# generated, together with the HTML files, they form an Eclipse help plugin. To +# install this plugin and make it available under the help contents menu in +# Eclipse, the contents of the directory containing the HTML and XML files needs +# to be copied into the plugins directory of eclipse. The name of the directory +# within the plugins directory should be the same as the ECLIPSE_DOC_ID value. +# After copying Eclipse needs to be restarted before the help appears. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the Eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have this +# name. Each documentation set should have its own identifier. +# The default value is: org.doxygen.Project. +# This tag requires that the tag GENERATE_ECLIPSEHELP is set to YES. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# If you want full control over the layout of the generated HTML pages it might +# be necessary to disable the index and replace it with your own. The +# DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) at top +# of each HTML page. A value of NO enables the index and the value YES disables +# it. Since the tabs in the index contain the same information as the navigation +# tree, you can set this option to YES if you also set GENERATE_TREEVIEW to YES. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +DISABLE_INDEX = NO + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. If the tag +# value is set to YES, a side panel will be generated containing a tree-like +# index structure (just like the one that is generated for HTML Help). For this +# to work a browser that supports JavaScript, DHTML, CSS and frames is required +# (i.e. any modern browser). Windows users are probably better off using the +# HTML help feature. Via custom style sheets (see HTML_EXTRA_STYLESHEET) one can +# further fine-tune the look of the index. As an example, the default style +# sheet generated by doxygen has an example that shows how to put an image at +# the root of the tree instead of the PROJECT_NAME. Since the tree basically has +# the same information as the tab index, you could consider setting +# DISABLE_INDEX to YES when enabling this option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +GENERATE_TREEVIEW = NO + +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values that +# doxygen will group on one line in the generated HTML documentation. +# +# Note that a value of 0 will completely suppress the enum values from appearing +# in the overview section. +# Minimum value: 0, maximum value: 20, default value: 4. +# This tag requires that the tag GENERATE_HTML is set to YES. + +ENUM_VALUES_PER_LINE = 4 + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be used +# to set the initial width (in pixels) of the frame in which the tree is shown. +# Minimum value: 0, maximum value: 1500, default value: 250. +# This tag requires that the tag GENERATE_HTML is set to YES. + +TREEVIEW_WIDTH = 250 + +# If the EXT_LINKS_IN_WINDOW option is set to YES, doxygen will open links to +# external symbols imported via tag files in a separate window. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +EXT_LINKS_IN_WINDOW = NO + +# Use this tag to change the font size of LaTeX formulas included as images in +# the HTML documentation. When you change the font size after a successful +# doxygen run you need to manually remove any form_*.png images from the HTML +# output directory to force them to be regenerated. +# Minimum value: 8, maximum value: 50, default value: 10. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_FONTSIZE = 10 + +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are not +# supported properly for IE 6.0, but are supported on all modern browsers. +# +# Note that when changing this option you need to delete any form_*.png files in +# the HTML output directory before the changes have effect. +# The default value is: YES. +# This tag requires that the tag GENERATE_HTML is set to YES. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax (see +# http://www.mathjax.org) which uses client side Javascript for the rendering +# instead of using pre-rendered bitmaps. Use this if you do not have LaTeX +# installed or if you want to formulas look prettier in the HTML output. When +# enabled you may also need to install MathJax separately and configure the path +# to it using the MATHJAX_RELPATH option. +# The default value is: NO. +# This tag requires that the tag GENERATE_HTML is set to YES. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# the MathJax output. See the MathJax site (see: +# http://docs.mathjax.org/en/latest/output.html) for more details. +# Possible values are: HTML-CSS (which is slower, but has the best +# compatibility), NativeMML (i.e. MathML) and SVG. +# The default value is: HTML-CSS. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the HTML +# output directory using the MATHJAX_RELPATH option. The destination directory +# should contain the MathJax.js script. For instance, if the mathjax directory +# is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to the MathJax +# Content Delivery Network so you can quickly see the result without installing +# MathJax. However, it is strongly recommended to install a local copy of +# MathJax from http://www.mathjax.org before deployment. +# The default value is: http://cdn.mathjax.org/mathjax/latest. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest + +# The MATHJAX_EXTENSIONS tag can be used to specify one or more MathJax +# extension names that should be enabled during MathJax rendering. For example +# MATHJAX_EXTENSIONS = TeX/AMSmath TeX/AMSsymbols +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_EXTENSIONS = + +# The MATHJAX_CODEFILE tag can be used to specify a file with javascript pieces +# of code that will be used on startup of the MathJax code. See the MathJax site +# (see: http://docs.mathjax.org/en/latest/output.html) for more details. For an +# example see the documentation. +# This tag requires that the tag USE_MATHJAX is set to YES. + +MATHJAX_CODEFILE = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box for +# the HTML output. The underlying search engine uses javascript and DHTML and +# should work on any modern browser. Note that when using HTML help +# (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets (GENERATE_DOCSET) +# there is already a search function so this one should typically be disabled. +# For large projects the javascript based search engine can be slow, then +# enabling SERVER_BASED_SEARCH may provide a better solution. It is possible to +# search using the keyboard; to jump to the search box use + S +# (what the is depends on the OS and browser, but it is typically +# , /