Skip to content

Commit

Permalink
Merge pull request #321 from gdt050579/dropper-jpg
Browse files Browse the repository at this point in the history
added JPG for dropper
  • Loading branch information
gheorghitamutu authored Jul 22, 2024
2 parents b7256fb + aa912d3 commit c0b54ee
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
16 changes: 16 additions & 0 deletions GenericPlugins/Dropper/include/Images.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,20 @@ class PNG : public IDrop

virtual bool Check(uint64 offset, DataCache& file, BufferView precachedBuffer, Finding& finding) override;
};

class JPG : public IDrop
{
private:
public:
JPG() = default;

virtual const std::string_view GetName() const override;
virtual Category GetCategory() const override;
virtual Subcategory GetSubcategory() const override;
virtual const std::string_view GetOutputExtension() const override;
virtual Priority GetPriority() const override;
virtual bool ShouldGroupInOneFile() const override;

virtual bool Check(uint64 offset, DataCache& file, BufferView precachedBuffer, Finding& finding) override;
};
} // namespace GView::GenericPlugins::Droppper::Images
3 changes: 2 additions & 1 deletion GenericPlugins/Dropper/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ target_sources(Dropper PRIVATE
HtmlObjects/PHP.cpp
HtmlObjects/Script.cpp
HtmlObjects/XML.cpp
Multimedia/PNG.cpp)
Multimedia/PNG.cpp
Multimedia/JPG.cpp)
1 change: 1 addition & 0 deletions GenericPlugins/Dropper/src/Dropper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ bool Instance::Init(Reference<GView::Object> object)
// binary
context.objectDroppers.emplace_back(std::make_unique<MZPE>());
context.objectDroppers.emplace_back(std::make_unique<PNG>());
context.objectDroppers.emplace_back(std::make_unique<JPG>());

// html objects
context.objectDroppers.emplace_back(std::make_unique<IFrame>());
Expand Down
73 changes: 73 additions & 0 deletions GenericPlugins/Dropper/src/Multimedia/JPG.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "Images.hpp"

namespace GView::GenericPlugins::Droppper::Images
{
constexpr uint16 IMAGE_JPG_MAGIC_SOI = 0xFFD8; // Start of Image marker
constexpr uint16 IMAGE_JPG_MAGIC_EOI = 0xFFD9; // End of Image marker

const std::string_view JPG::GetName() const
{
return "JPG";
}
Category JPG::GetCategory() const
{
return Category::Multimedia;
}

Subcategory JPG::GetSubcategory() const
{
return Subcategory::JPG;
}

const std::string_view JPG::GetOutputExtension() const
{
return "jpg";
}

Priority JPG::GetPriority() const
{
return Priority::Binary;
}

bool JPG::ShouldGroupInOneFile() const
{
return false;
}

bool JPG::Check(uint64 offset, DataCache& file, BufferView precachedBuffer, Finding& finding)
{
CHECK(IsMagicU16(precachedBuffer, IMAGE_JPG_MAGIC_SOI), false, "");

finding.start = offset;
finding.end = offset + sizeof(IMAGE_JPG_MAGIC_SOI);
auto pos = finding.end;
auto found = false;

while (true) {
auto buffer = file.CopyToBuffer(pos, sizeof(uint32), true);
CHECKBK(buffer.IsValid(), "");

auto marker = *reinterpret_cast<const uint16*>(buffer.GetData());
pos += sizeof(uint16);

if (marker == IMAGE_JPG_MAGIC_EOI) {
finding.end = pos;
found = true;
break;
}
else if ((marker & 0xFF00) == 0xFF00) {
const auto segment_length = Endian::BigToNative(*reinterpret_cast<const uint16*>(buffer.GetData() + sizeof(uint16)));
pos += segment_length;
} else {
break;
}
}
// https://stackoverflow.com/questions/2253404/what-is-the-smallest-valid-jpeg-file-size-in-bytes
CHECK(finding.end - finding.start >= 125, false, ""); // Minimum size for JPG?

finding.result = Result::Buffer;

return true;
}

}

0 comments on commit c0b54ee

Please sign in to comment.