Skip to content

Commit

Permalink
Code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Nov 2, 2024
1 parent f7a127e commit d3ae4de
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/MachO/BinaryParser.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ ok_error_t BinaryParser::parse_load_commands() {
break;
}
auto section = std::make_unique<Section>(*section_header);

binary_->sections_.push_back(section.get());
if (section->size_ > 0 &&
section->type() != Section::TYPE::ZEROFILL &&
Expand Down Expand Up @@ -3599,14 +3600,18 @@ ok_error_t BinaryParser::post_process(DynamicSymbolCommand& cmd) {
template<class MACHO_T>
ok_error_t BinaryParser::post_process(LinkerOptHint& cmd) {
LIEF_DEBUG("[^] Post processing LC_LINKER_OPTIMIZATION_HINT");
if (binary_->header().file_type() == Header::FILE_TYPE::OBJECT) {
return ok();
}

SegmentCommand* linkedit = config_.from_dyld_shared_cache ?
binary_->get_segment("__LINKEDIT") :
binary_->segment_from_offset(cmd.data_offset());

if (linkedit == nullptr) {
LIEF_WARN("Can't find the segment that contains the LC_LINKER_OPTIMIZATION_HINT");
return make_error_code(lief_errors::not_found);
};
}

span<uint8_t> content = linkedit->writable_content();

Expand Down Expand Up @@ -3636,7 +3641,7 @@ ok_error_t BinaryParser::post_process(CodeSignature& cmd) {
if (linkedit == nullptr) {
LIEF_WARN("Can't find the segment that contains the LC_CODE_SIGNATURE");
return make_error_code(lief_errors::not_found);
};
}

span<uint8_t> content = linkedit->writable_content();

Expand Down Expand Up @@ -3666,7 +3671,7 @@ ok_error_t BinaryParser::post_process(CodeSignatureDir& cmd) {
if (linkedit == nullptr) {
LIEF_WARN("Can't find the segment that contains the LC_DYLIB_CODE_SIGN_DRS");
return make_error_code(lief_errors::not_found);
};
}

span<uint8_t> content = linkedit->writable_content();

Expand Down Expand Up @@ -3697,7 +3702,7 @@ ok_error_t BinaryParser::post_process(TwoLevelHints& cmd) {
if (linkedit == nullptr) {
LIEF_WARN("Can't find the segment that contains the LC_TWOLEVEL_HINTS");
return make_error_code(lief_errors::not_found);
};
}

const size_t raw_size = cmd.original_nb_hints() * sizeof(uint32_t);
span<uint8_t> content = linkedit->writable_content();
Expand Down
1 change: 0 additions & 1 deletion tests/macho/test_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,4 +348,3 @@ def test_routine():
def test_arm64e():
sample = lief.MachO.parse(get_sample("private/MachO/libCoreKE_arm64e.dylib")).at(0)
assert sample.support_arm64_ptr_auth

0 comments on commit d3ae4de

Please sign in to comment.