Skip to content

Commit

Permalink
[Dropper] + add regexes for IP Address mini-plugin for Dropper #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 6, 2024
1 parent 00907c0 commit cae4df7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion GenericPlugins/Dropper/include/Dropper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Instance
bool Init()
{
// dummy init for now
std::unique_ptr<IDrop> a = std::make_unique<IpAddress>();
std::unique_ptr<IDrop> a = std::make_unique<IpAddress>(false, true);
droppers.push_back(std::move(a));

return true;
Expand Down
10 changes: 5 additions & 5 deletions GenericPlugins/Dropper/include/IDrop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@ class IDrop
virtual Result Check(uint64 offset, DataCache& file, unsigned char* prechachedBuffer, uint32 prechachedBufferSize, uint64& start, uint64& end) = 0;

// functii deja existente
inline bool is_magic_u16(unsigned char* prechachedBuffer, uint32 prechachedBufferSize, uint16 magic)
inline bool IsMagicU16(unsigned char* prechachedBuffer, uint32 prechachedBufferSize, uint16 magic)
{
if (prechachedBufferSize >= 2) {
return *(uint16*) prechachedBuffer == magic;
}
return false;
}

inline bool is_magic_u32(unsigned char* prechachedBuffer, uint32 prechachedBufferSize, uint32 magic)
inline bool IsMagicU32(unsigned char* prechachedBuffer, uint32 prechachedBufferSize, uint32 magic)
{
if (prechachedBufferSize >= 4) {
return *(uint32*) prechachedBuffer == magic;
}
return false;
}

inline bool is_buffer(uint64 offset, DataCache& file, unsigned char* buffer, uint32 bufferSize)
inline bool IsBuffer(uint64 offset, DataCache& file, unsigned char* buffer, uint32 bufferSize)
{
while (bufferSize) {
if (file.GetFromCache(offset) != *buffer) {
Expand All @@ -69,14 +69,14 @@ class IDrop
return true;
}

inline uint64 parse_ascii(uint64 offset, DataCache& file, bool (*isValidChar)(char ch))
inline uint64 ParseAscii(uint64 offset, DataCache& file, bool (*isValidChar)(char ch))
{
// dummy body
const auto a = file.Get(offset, 1, true);
return isValidChar(*(char*) a.GetData());
}

inline uint64 parse_unicode(uint64 offset, DataCache& file, bool (*isValidChar)(uint16 ch))
inline uint64 ParseUnicode(uint64 offset, DataCache& file, bool (*isValidChar)(uint16 ch))
{
// dummy body
const auto a = file.Get(offset, 2, true);
Expand Down
25 changes: 24 additions & 1 deletion GenericPlugins/Dropper/include/SpecialStrings.hpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,36 @@
#pragma once

#include "IDrop.hpp"
#include <string>
#include <regex>

inline static const std::string_view IPS_REGEX_ASCII{ R"(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\:[0-9]{1,5})*))" };
inline static const std::u16string_view IPS_REGEX_UNICODE{ uR"(([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}(\:[0-9]{1,5})*))" };

namespace GView::GenericPlugins::Droppper::SpecialStrings
{
class IpAddress : public IDrop
{
private:
std::regex pattern_ascii;
std::wregex pattern_unicode;
bool unicode{ false };

public:
IpAddress() = default;
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);
}
}

virtual const char* GetName() override;
virtual ObjectCategory GetGroup() override;
Expand Down

0 comments on commit cae4df7

Please sign in to comment.