/* Copyright 2017 - 2021 R. Thomas * Copyright 2017 - 2021 Quarkslab * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef LIEF_MACHO_BUIDLER_H_ #define LIEF_MACHO_BUIDLER_H_ #include #include #include #include #include "LIEF/visibility.h" #include "LIEF/exception.hpp" #include "LIEF/iostream.hpp" namespace LIEF { namespace MachO { class Binary; class FatBinary; class DylibCommand; class DylinkerCommand; class VersionMin; class SourceVersion; class FunctionStarts; class MainCommand; class DyldInfo; class SymbolCommand; class DynamicSymbolCommand; class DataInCode; class CodeSignature; class SegmentSplitInfo; class SubFramework; class DyldEnvironment; class ThreadCommand; class BuildVersion; class LIEF_API Builder { public: static void write(Binary *binary, const std::string& filename); static void write(FatBinary* fatbinary, const std::string& filename); public: Builder(Binary *binary); Builder(std::vector binaries); Builder(FatBinary* fat); Builder(void) = delete; ~Builder(void); std::vector operator()(void); void build(void); const std::vector& get_build(void); void write(const std::string& filename) const; private: template void build(void); void build_fat(void); void build_fat_header(void); void build_header(void); void build_load_commands(void); template void build(DylibCommand* library); template void build(DylinkerCommand* linker); template void build(VersionMin* version_min); template void build(SourceVersion* source_version); template void build(FunctionStarts* function_starts); template void build(MainCommand* main_cmd); template void build(DyldInfo* dyld_info); template void build(SymbolCommand* symbol_command); template void build(DynamicSymbolCommand* symbol_command); template void build(DataInCode* datacode); template void build(CodeSignature* code_signature); template void build(SegmentSplitInfo* ssi); template void build(SubFramework* sf); template void build(DyldEnvironment* de); template void build(ThreadCommand* tc); template void build_segments(void); template void build(BuildVersion* bv); void build_uuid(void); template void build_symbols(void); std::vector binaries_; Binary* binary_{nullptr}; mutable vector_iostream raw_; }; } // namespace MachO } // namespace LIEF #endif