Skip to content

Commit

Permalink
Resolve #995
Browse files Browse the repository at this point in the history
  • Loading branch information
romainthomas committed Nov 9, 2023
1 parent 07df2f0 commit a7270ae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
3 changes: 2 additions & 1 deletion include/LIEF/MachO/BinaryParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ class LIEF_API BinaryParser : public LIEF::Parser {
ok_error_t parse_dyld_exports();

ok_error_t parse_export_trie(exports_list_t& exports, uint64_t start,
uint64_t end, const std::string& prefix);
uint64_t end, const std::string& prefix,
bool* invalid_names);

void copy_from(ChainedBindingInfo& to, ChainedBindingInfo& from);

Expand Down
23 changes: 17 additions & 6 deletions src/MachO/BinaryParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@

#include "LIEF/BinaryStream/VectorStream.hpp"


#include "LIEF/MachO/BinaryParser.hpp"

#include "LIEF/MachO/utils.hpp"
#include "LIEF/MachO/SegmentCommand.hpp"
#include "LIEF/MachO/Symbol.hpp"
#include "LIEF/MachO/ExportInfo.hpp"
#include "LIEF/MachO/DyldExportsTrie.hpp"

#include "LIEF/utils.hpp"

namespace LIEF {
namespace MachO {

Expand Down Expand Up @@ -136,7 +136,8 @@ ok_error_t BinaryParser::init_and_parse() {


ok_error_t BinaryParser::parse_export_trie(exports_list_t& exports, uint64_t start,
uint64_t end, const std::string& prefix)
uint64_t end, const std::string& prefix,
bool* invalid_names)
{
if (stream_->pos() >= end) {
return make_error_code(lief_errors::read_error);
Expand Down Expand Up @@ -281,6 +282,13 @@ ok_error_t BinaryParser::parse_export_trie(exports_list_t& exports, uint64_t sta
}
std::string name = prefix + std::move(*suffix);

if (!is_printable(name)) {
if (!*invalid_names) {
LIEF_WARN("The export trie contains non-printable symbols");
*invalid_names = true;
}
}

auto res_child_node_offet = stream_->read_uleb128();
if (!res_child_node_offet) {
LIEF_ERR("Can't read child_node_offet");
Expand All @@ -298,7 +306,7 @@ ok_error_t BinaryParser::parse_export_trie(exports_list_t& exports, uint64_t sta
visited_.insert(start + child_node_offet);
size_t current_pos = stream_->pos();
stream_->setpos(start + child_node_offet);
parse_export_trie(exports, start, end, name);
parse_export_trie(exports, start, end, name, invalid_names);
stream_->setpos(current_pos);
}
return ok();
Expand Down Expand Up @@ -336,7 +344,9 @@ ok_error_t BinaryParser::parse_dyld_exports() {
exports->content_ = content.subspan(rel_offset, size);

stream_->setpos(offset);
parse_export_trie(exports->export_info_, offset, end_offset, "");
bool invalid_names = false;
parse_export_trie(exports->export_info_, offset, end_offset, "",
&invalid_names);
return ok();

}
Expand Down Expand Up @@ -374,7 +384,8 @@ ok_error_t BinaryParser::parse_dyldinfo_export() {
dyldinfo->export_trie_ = content.subspan(rel_offset, size);

stream_->setpos(offset);
parse_export_trie(dyldinfo->export_info_, offset, end_offset, "");
bool invalid_names = false;
parse_export_trie(dyldinfo->export_info_, offset, end_offset, "", &invalid_names);
return ok();
}

Expand Down

0 comments on commit a7270ae

Please sign in to comment.