Skip to content

Commit

Permalink
Fixed an issue in the JSON output and Imports plugin caused by the fact
Browse files Browse the repository at this point in the history
that DLLs/functions can be imported multiple times by a PE.
  • Loading branch information
JusticeRage committed Jul 29, 2017
1 parent 47dd678 commit dbd5e41
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
6 changes: 6 additions & 0 deletions include/manacommons/output_tree_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ class OutputTreeNode

// ----------------------------------------------------------------------------

DECLSPEC_MANACOMMONS void set_name(const std::string& name) {
_name->assign(name);
}

// ----------------------------------------------------------------------------

DECLSPEC_MANACOMMONS node_type get_type() const {
return _type;
}
Expand Down
18 changes: 18 additions & 0 deletions manacommons/output_tree_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,24 @@ void OutputTreeNode::append(pNode node)
if (!_list_data || !*_list_data) {
_list_data = boost::make_shared<boost::optional<nodes> >(nodes());
}

// The JSON formatter cannot handle identical names in a list. Rename duplicates if necessary.
int i = 2;
auto initial_name = *node->get_name();
auto current_name = initial_name;
for (auto it = (*_list_data)->begin() ; it != (*_list_data)->end() ; ++it)
{
if (*(*it)->get_name() == current_name)
{
std::stringstream ss;
ss << initial_name << " (#" << i++ << ")";
current_name = ss.str();
}
}
if (current_name != initial_name) {
node->set_name(current_name);
}

(*_list_data)->push_back(node);
}

Expand Down
3 changes: 2 additions & 1 deletion manape/imports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,8 @@ const_shared_strings PE::find_imports(const std::string& function_name_regexp,
else {
name = (*it2)->Name;
}
if (boost::regex_match(name, e)) {
// Functions may be imported multiple times, don't add the same one twice.
if (boost::regex_match(name, e) && std::find(destination->begin(), destination->end(), name) == destination->end()) {
destination->push_back(name);
}
}
Expand Down

0 comments on commit dbd5e41

Please sign in to comment.