Skip to content

Commit

Permalink
[Unpacker] + add quoted printable decoding
Browse files Browse the repository at this point in the history
  • Loading branch information
gheorghitamutu committed Aug 20, 2024
1 parent 9bc280a commit d621433
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions GenericPlugins/Unpacker/include/Unpacker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Plugin : public Window, public Handlers::OnButtonPressedInterface

bool SetAreaToDecode(Buffer& b, BufferView& bv, uint64& start, uint64& end);
bool DecodeBase64(BufferView input, uint64 start, uint64 end);
bool DecodeQuotedPrintable(BufferView input, uint64 start, uint64 end);
bool DecodeZLib(BufferView input, uint64 start, uint64 end);

void OnButtonPressed(Reference<Button> button) override;
Expand Down
41 changes: 36 additions & 5 deletions GenericPlugins/Unpacker/src/Unpacker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ using namespace GView;
constexpr int BTN_ID_DECODE = 1;
constexpr int BTN_ID_CANCEL = 2;

constexpr uint64 ITEM_INVALID = 0xFFFFFFFF;
constexpr uint64 ITEM_BASE64 = 1;
constexpr uint64 ITEM_ZLIB = 2;
constexpr uint64 ITEM_INVALID = 0xFFFFFFFF;
constexpr uint64 ITEM_BASE64 = 1;
constexpr uint64 ITEM_QUOTED_PRINTABLE = 2;
constexpr uint64 ITEM_ZLIB = 3;

namespace GView::GenericPlugins::Unpacker
{
Expand All @@ -36,6 +37,7 @@ Plugin::Plugin(Reference<GView::Object> object, Reference<Window> parent) : Wind
list = Factory::ListView::Create(this, "x:1,y:0,w:50%,h:90%", { "n:Type,w:100%" }, ListViewFlags::AllowMultipleItemsSelection);

list->AddItem({ "Base64" }).SetData(ITEM_BASE64);
list->AddItem({ "QuotedPrintable" }).SetData(ITEM_QUOTED_PRINTABLE);
list->AddItem({ "ZLib" }).SetData(ITEM_ZLIB);

list->SetCurrentItem(list->GetItem(0));
Expand Down Expand Up @@ -66,6 +68,10 @@ void Plugin::OnButtonPressed(Reference<Button> button)
SetAreaToDecode(b, bv, start, end);
DecodeBase64(bv, start, end);
} break;
case ITEM_QUOTED_PRINTABLE:
SetAreaToDecode(b, bv, start, end);
DecodeQuotedPrintable(bv, start, end);
break;
case ITEM_ZLIB:
SetAreaToDecode(b, bv, start, end);
DecodeZLib(bv, start, end);
Expand All @@ -90,8 +96,8 @@ bool Plugin::OnEvent(Reference<Control> control, Event eventType, int32 ID)

switch (eventType) {
case AppCUI::Controls::Event::ListViewCurrentItemChanged: {
CHECK(description.IsValid(), false ,"");
CHECK(list.IsValid(), false ,"");
CHECK(description.IsValid(), false, "");
CHECK(list.IsValid(), false, "");

auto item = this->list->GetCurrentItem();
auto id = item.GetData(ITEM_INVALID);
Expand All @@ -101,6 +107,9 @@ bool Plugin::OnEvent(Reference<Control> control, Event eventType, int32 ID)
case ITEM_BASE64:
description->SetText("Base64 encoded payloads");
break;
case ITEM_QUOTED_PRINTABLE:
description->SetText("QP encoded payloads");
break;
case ITEM_ZLIB:
description->SetText("Zlib encoded payloads");
break;
Expand Down Expand Up @@ -168,6 +177,28 @@ bool Plugin::DecodeBase64(BufferView input, uint64 start, uint64 end)
return false;
}

bool Plugin::DecodeQuotedPrintable(BufferView input, uint64 start, uint64 end)
{
String message;
Buffer output;
if (GView::Decoding::QuotedPrintable::Decode(input, output)) {
LocalString<128> name;
name.Format("Buffer_qp_%llx_%llx", start, end);

LocalUnicodeStringBuilder<2048> fullPath;
fullPath.Add(this->object->GetPath());
fullPath.AddChar((char16_t) std::filesystem::path::preferred_separator);
fullPath.Add(name);

GView::App::OpenBuffer(output, name, fullPath, GView::App::OpenMethod::BestMatch, "", this->parent);
return true;
}

AppCUI::Dialogs::MessageBox::ShowError("Error!", input);

return false;
}

bool Plugin::DecodeZLib(BufferView input, uint64 start, uint64 end)
{
struct Data {
Expand Down

0 comments on commit d621433

Please sign in to comment.