Skip to content

Commit

Permalink
fix crashing if wrong type of sig is entered in find input box
Browse files Browse the repository at this point in the history
  • Loading branch information
rikodot committed Nov 19, 2023
1 parent e3342d9 commit 0e1cb6a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,5 @@ cmake -S . -B build
### Building using Github Actions
- based on [binja-ci-tests](https://github.com/CouleeApps/binja-ci-tests)

### Known issues
- if a code signature is provided and the 'find norm signature' process is executed, Binary Ninja will freeze and crash, potentially caused by an infinite loop, similar issue may also occur in various other scenarios
- creating signature from `Hex Editor` view within the main frame most likely causes crash as partial instructions might be selected

### Backstory
I have been using IDA for majority of my reverse engineering career and recently decided to switch to Binary Ninja. I work with signatures on daily basis and this plugin is a must for me. Although there already is a community plugin for the exact same purpose, it is frankly unusable for binaries over 50KB in size as it is incredibly slow and on top of that contains two bugs causing creation of signatures with wrongly placed wild bytes resulting in signatures not being compatible with different compilations of the same binary. I still want to note that the python version was a nice resource in creation of this version.
38 changes: 23 additions & 15 deletions sigscan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,15 @@ std::string exctract_sig(std::string str, sig_types type, bool scan_for_custom_w
// "48 89 5c 24 08 ? 9a
// 48 89 5C 24 08 ?? 9A'
bool have_byte = false;
int cur_byte_len = 0;
for (auto& c : str)
{
if (have_byte && c == ' ')
{
if (cur_byte_len > 2) { return ""; }
sig += " ";
have_byte = false;
continue;
cur_byte_len = 0;
}
else
{
Expand All @@ -297,6 +299,7 @@ std::string exctract_sig(std::string str, sig_types type, bool scan_for_custom_w
else if (c == '?')
{
sig += "?";
++cur_byte_len;
have_byte = true;
}
else
Expand All @@ -306,6 +309,7 @@ std::string exctract_sig(std::string str, sig_types type, bool scan_for_custom_w
have_byte = true;
}
sig += c;
++cur_byte_len;
}
}
}
Expand Down Expand Up @@ -341,27 +345,30 @@ std::string exctract_sig(std::string str, sig_types type, bool scan_for_custom_w
// MASK
// find the first occurrence of ',' after pos in str
pos = str.find(',', pos);
// read characters until is 'x' or '?'
while (pos < str.size() && str[pos] != 'x' && str[pos] != '?')
if (pos != std::string::npos)
{
++pos;
}
// read characters until the end of the string or a character that is not 'x' or '?'
for (size_t i = pos, j = 0; i < str.size() && j * 3 + 2 < sig.size(); ++i, ++j)
{
char c = str[i];
if (c == '?')
// read characters until is 'x' or '?'
while (pos < str.size() && str[pos] != 'x' && str[pos] != '?')
{
sig[j * 3] = '?';
sig[j * 3 + 1] = '?';
++pos;
}
else if (c != 'x')
// read characters until the end of the string or a character that is not 'x' or '?'
for (size_t i = pos, j = 0; i < str.size() && j * 3 + 2 < sig.size(); ++i, ++j)
{
break;
char c = str[i];
if (c == '?')
{
sig[j * 3] = '?';
sig[j * 3 + 1] = '?';
}
else if (c != 'x')
{
break;
}
}
}
sig.pop_back();
}
if (sig.back() == ' ') { sig.pop_back(); }
return sig;
}

Expand All @@ -388,6 +395,7 @@ void find_sig(BinaryView* view, sig_types type)
if (sig.empty())
{
Log(ErrorLog, "INPUT IS NOT VALID SIG");
return;
}
// Log(InfoLog, "sig: %s", sig.c_str());

Expand Down

0 comments on commit 0e1cb6a

Please sign in to comment.