Skip to content

Commit

Permalink
[Dropper] + add dummy integration for Dropper with a special strings …
Browse files Browse the repository at this point in the history
…mini plugin - ip address #182 #181

Signed-off-by: Gheorghita Mutu <gheorghitamutu@gmail.com>
  • Loading branch information
gheorghitamutu committed Apr 5, 2024
1 parent 556bc9a commit de9af75
Show file tree
Hide file tree
Showing 6 changed files with 165 additions and 53 deletions.
71 changes: 20 additions & 51 deletions GenericPlugins/Dropper/include/Dropper.hpp
Original file line number Diff line number Diff line change
@@ -1,68 +1,37 @@
#pragma once

#include "GView.hpp"
#include <vector>
#include <memory>

#include "SpecialStrings.hpp"

using namespace GView::Utils;
using namespace GView::GenericPlugins::Droppper::SpecialStrings;

namespace GView::GenericPlugins::Droppper
{
enum Result {
NotFound, // -> nothing found
Buffer, // -> artefact found -> drop it as a buffer
Unicode, // -> artefact found -> drop it as unicode (skip 0)
Ascii, // -> artefact found -> drop it as ascii
};

class IDrop
class Instance
{
public:
// virtual methods
virtual const char* GetName() = 0; // specific dropper mini-plugin name
virtual const char* GetGroup() = 0; // Archive type recognizer, Archive type recognizer, etc
virtual const char* GetOutputExtension() = 0; // dropped file extension
virtual bool ShouldGroupInOneFile() = 0; // URLs, IPs, etc

// prechachedBufferSize, // max 8
virtual Result Check(uint64 offset, DataCache& file, unsigned char* prechachedBuffer, uint32 prechachedBufferSize, uint64& start, uint64& end) = 0;

virtual uint32 GetPriority() = 0;

// functii deja existente
inline bool is_magic_u16(unsigned char* prechachedBuffer, uint32 prechachedBufferSize, uint16 magic)
{
if (prechachedBufferSize >= 2) {
return *(uint16*) prechachedBuffer == magic;
}
return false;
}
private:
std::vector<std::unique_ptr<IDrop>> droppers;

inline bool is_magic_u32(unsigned char* prechachedBuffer, uint32 prechachedBufferSize, uint32 magic)
public:
bool Init()
{
if (prechachedBufferSize >= 4) {
return *(uint32*) prechachedBuffer == magic;
}
return false;
}
// dummy init for now
std::unique_ptr<IDrop> a = std::make_unique<IpAddress>();
droppers.push_back(std::move(a));

inline bool is_buffer(uint64 offset, DataCache& file, unsigned char* buffer, uint32 bufferSize)
{
while (bufferSize) {
if (file.GetFromCache(offset) != *buffer) {
return false;
}
buffer++;
offset++;
bufferSize--;
}
return true;
}

inline uint64 parse_ascii(uint64 offset, DataCache& file, bool (*isValidChar)(char ch))
bool Process()
{
return 0;
}
for (auto& dropper : droppers) {
// TODO: something
}

inline uint64 parse_unicode(uint64 offset, DataCache& file, bool (*isValidChar)(char ch))
{
return 0;
return true;
}
};
} // namespace GView::GenericPlugins::Droppper
86 changes: 86 additions & 0 deletions GenericPlugins/Dropper/include/IDrop.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#pragma once

#include "GView.hpp"

using namespace GView::Utils;

namespace GView::GenericPlugins::Droppper
{
enum class Result : uint32 {
NotFound = 0, // -> nothing found
Buffer, // -> artefact found -> drop it as a buffer
Unicode, // -> artefact found -> drop it as unicode (skip 0)
Ascii, // -> artefact found -> drop it as ascii
};

enum class Priority : uint32 { Binary = 0, Text = 1 };

enum class ObjectCategory : uint32 {
Archive = 0,
AVStrings = 1,
Cryptographic = 2,
Executables = 3,
HtmlObjects = 4,
Image = 5,
Multimedia = 6,
SpecialStrings = 7,
};

class IDrop
{
public:
// virtual methods
virtual const char* GetName() = 0; // specific dropper mini-plugin name
virtual ObjectCategory GetGroup() = 0; // archive type recognizer, executables type, etc
virtual const char* GetOutputExtension() = 0; // dropped file extension
virtual Priority GetPriority() = 0; // get plugin priority
virtual bool ShouldGroupInOneFile() = 0; // URLs, IPs, etc

// prechachedBufferSize -> max 8
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)
{
if (prechachedBufferSize >= 2) {
return *(uint16*) prechachedBuffer == magic;
}
return false;
}

inline bool is_magic_u32(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)
{
while (bufferSize) {
if (file.GetFromCache(offset) != *buffer) {
return false;
}
buffer++;
offset++;
bufferSize--;
}
return true;
}

inline uint64 parse_ascii(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))
{
// dummy body
const auto a = file.Get(offset, 2, true);
return isValidChar(*(uint16*) a.GetData());
}
};
} // namespace GView::GenericPlugins::Droppper
20 changes: 20 additions & 0 deletions GenericPlugins/Dropper/include/SpecialStrings.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include "IDrop.hpp"

namespace GView::GenericPlugins::Droppper::SpecialStrings
{
class IpAddress : public IDrop
{
public:
IpAddress() = default;

virtual const char* GetName() override;
virtual ObjectCategory GetGroup() override;
virtual const char* GetOutputExtension() override;
virtual Priority GetPriority() override;
virtual bool ShouldGroupInOneFile() override;

virtual Result Check(uint64 offset, DataCache& file, unsigned char* prechachedBuffer, uint32 prechachedBufferSize, uint64& start, uint64& end) override;
};
} // namespace GView::GenericPlugins::Droppper::SpecialStrings
2 changes: 1 addition & 1 deletion GenericPlugins/Dropper/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
target_sources(Dropper PRIVATE Dropper.cpp)
target_sources(Dropper PRIVATE Dropper.cpp SpecialStrings/IpAddress.cpp)
4 changes: 3 additions & 1 deletion GenericPlugins/Dropper/src/Dropper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ extern "C" {
PLUGIN_EXPORT bool Run(const string_view command, Reference<GView::Object> object)
{
if (command == "Dropper") {
// TODO: implementation
auto instance = Instance();
CHECK(instance.Init(), false, "");
CHECK(instance.Process(), false, "");
return true;
}
return false;
Expand Down
35 changes: 35 additions & 0 deletions GenericPlugins/Dropper/src/SpecialStrings/IpAddress.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "SpecialStrings.hpp"

namespace GView::GenericPlugins::Droppper::SpecialStrings
{
const char* IpAddress::GetName()
{
return "IP Address";
}

ObjectCategory IpAddress::GetGroup()
{
return ObjectCategory::SpecialStrings;
}

const char* IpAddress::GetOutputExtension()
{
return "ip";
}

Priority IpAddress::GetPriority()
{
return Priority::Text;
}

bool IpAddress::ShouldGroupInOneFile()
{
return true;
}

Result IpAddress::Check(uint64 offset, DataCache& file, unsigned char* prechachedBuffer, uint32 prechachedBufferSize, uint64& start, uint64& end)
{
return Result::NotFound;
}

} // namespace GView::GenericPlugins::Droppper::SpecialStrings

0 comments on commit de9af75

Please sign in to comment.