Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added JPG for dropper #321

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}

}
Loading