4
0
mirror of https://github.com/QuasarApp/LIEF.git synced 2025-05-12 03:19:34 +00:00

Merge pull request from aguinet/feature/fatmacho_take

Fat MachO: API to "take" a binary from the fat MachO object
This commit is contained in:
Romain 2020-12-31 07:03:56 +01:00 committed by GitHub
commit eccc0bbc61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions
include/LIEF/MachO
src/MachO

@ -17,6 +17,7 @@
#define LIEF_MACHO_FAT_BINARY_H_
#include <string>
#include <vector>
#include <memory>
#include "LIEF/types.hpp"
#include "LIEF/visibility.h"
@ -62,6 +63,11 @@ class LIEF_API FatBinary {
Binary& operator[](size_t index);
const Binary& operator[](size_t index) const;
//! Extract a @link MachO::Binary@ object. Gives ownership to the caller, and
// remove it from this @link FatBinary object. Warning: this invalidates any
// previously hold iterator!
std::unique_ptr<Binary> take(size_t index);
//! Reconstruct the Fat binary object and write it in `filename`
//! @param filename Path to write the reconstructed binary
void write(const std::string& filename);

@ -91,6 +91,16 @@ const Binary& FatBinary::operator[](size_t index) const {
return this->at(index);
}
std::unique_ptr<Binary> FatBinary::take(size_t index) {
if (index >= binaries_.size()) {
return {};
}
auto it = binaries_.begin();
std::advance(it, index);
std::unique_ptr<Binary> ret(*it);
binaries_.erase(it);
return ret;
}
void FatBinary::write(const std::string& filename) {
Builder::write(this, filename);