Skip to content

Commit

Permalink
[Dropper] # fix unicode regex issue #182 #181
Browse files Browse the repository at this point in the history
Signed-off-by: Gheorghita Mutu <gheorghitamutu@gmail.com>
  • Loading branch information
gheorghitamutu committed Apr 11, 2024
1 parent 8dd80d9 commit e5b251a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
2 changes: 1 addition & 1 deletion AppCUI
Submodule AppCUI updated 1 files
+1 −1 vcpkg
2 changes: 1 addition & 1 deletion GenericPlugins/Dropper/include/Dropper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Instance
f->write(reinterpret_cast<const char*>(bv.GetData()), bv.GetLength());
} else {
for (uint32 i = 0; i < bv.GetLength(); i += 2) {
f->write(reinterpret_cast<const char*>(bv.GetData() + 1), 1);
f->write(reinterpret_cast<const char*>(bv.GetData() + i), 1);
}
}
f->write("\n", 1);
Expand Down
2 changes: 2 additions & 0 deletions GenericPlugins/Dropper/include/SpecialStrings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ class IpAddress : public IDrop
std::regex pattern_ascii;
std::wregex pattern_unicode;
bool unicode{ false };
bool caseSensitive{ false };
std::regex_constants::syntax_option_type regexConstants{ std::regex_constants::ECMAScript | std::regex_constants::optimize };

public:
IpAddress(bool caseSensitive, bool unicode);
Expand Down
20 changes: 8 additions & 12 deletions GenericPlugins/Dropper/src/SpecialStrings/IpAddress.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ inline static const std::u16string_view IPS_REGEX_UNICODE{ uR"(([0-9]{1,3}\.[0-9

IpAddress::IpAddress(bool caseSensitive, bool unicode)
{
this->pattern_ascii = std::regex(
IPS_REGEX_ASCII.data(),
caseSensitive ? std::regex_constants::ECMAScript | std::regex_constants::optimize
: std::regex_constants::icase | std::regex_constants::ECMAScript | std::regex_constants::optimize);

if (unicode) {
this->pattern_unicode = std::wregex(
reinterpret_cast<wchar_t const* const>(IPS_REGEX_UNICODE.data()),
caseSensitive ? std::regex_constants::ECMAScript | std::regex_constants::optimize
: std::regex_constants::icase | std::regex_constants::ECMAScript | std::regex_constants::optimize);
this->unicode = unicode;
this->caseSensitive = caseSensitive;
if (this->caseSensitive) {
this->regexConstants |= std::regex_constants::icase;
}
this->pattern_ascii = std::regex(IPS_REGEX_ASCII.data(), this->regexConstants);
this->pattern_unicode = std::wregex(reinterpret_cast<wchar_t const* const>(IPS_REGEX_UNICODE.data()), this->regexConstants);
}

const char* IpAddress::GetName()
Expand Down Expand Up @@ -74,8 +70,8 @@ Result IpAddress::Check(uint64 offset, DataCache& file, BufferView precachedBuff
const auto b2End = reinterpret_cast<wchar_t const*>(buffer.GetData() + buffer.GetLength());
std::wcmatch wcm{};
if (std::regex_search(b2Start, b2End, wcm, this->pattern_unicode)) {
start = offset + wcm.position();
end = start + wcm.length();
start = offset + wcm.position() * sizeof(wchar_t);
end = start + (wcm.length() + 1) * sizeof(wchar_t);
return Result::Unicode;
}

Expand Down

0 comments on commit e5b251a

Please sign in to comment.