Skip to content

Commit

Permalink
PDF - bufferview string, boolean, null, indirect object
Browse files Browse the repository at this point in the history
  • Loading branch information
D1n03 committed Aug 18, 2024
1 parent f0628c1 commit e057bf6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Types/PDF/include/pdf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace Type
constexpr uint8 RIGHT_CURLY_BRACKET = 0x7D; // }
constexpr uint8 SOLIUDS = 0x2F; // /
constexpr uint8 PERCENT = 0x25; // %
constexpr uint8 REVERSE_SOLIDUS = 0x5C; // '\'
} // namespace DC

namespace FILTER
Expand Down Expand Up @@ -85,6 +86,8 @@ namespace Type
constexpr uint8_t PDF_TRUE_SIZE = 4;
constexpr uint8_t PDF_FALSE[] = "false";
constexpr uint8_t PDF_FALSE_SIZE = 5;
constexpr uint8_t PDF_NULL[] = "null";
constexpr uint8_t PDF_NULL_SIZE = 4;

constexpr uint8_t PDF_XREF[] = "xref";
constexpr uint8_t PDF_TRAILER[] = "trailer";
Expand All @@ -107,6 +110,7 @@ namespace Type
constexpr uint8_t PDF_XREF_ENTRY = 20;
constexpr uint8_t PDF_FREE_ENTRY = 'f';
constexpr uint8_t ZERO = 0;
constexpr uint8_t PDF_INDIRECTOBJ = 'R';
} // namespace KEY

namespace PREDICTOR
Expand Down
38 changes: 35 additions & 3 deletions Types/PDF/src/pdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,16 @@ void HighlightObjectTypes(GView::Utils::DataCache& data, BufferViewer::Settings&
}
switch (buffer) {
case PDF::WSC::SPACE:
case PDF::WSC::LINE_FEED:
case PDF::WSC::FORM_FEED:
case PDF::WSC::CARRIAGE_RETURN:
case PDF::DC::SOLIUDS:
case PDF::DC::RIGHT_SQUARE_BRACKET:
case PDF::DC::LEFT_SQUARE_BRACKET:
case PDF::DC::LESS_THAN:
case PDF::DC::GREATER_THAN:
case PDF::DC::LEFT_PARETHESIS:
case PDF::DC::RIGHT_PARETHESIS:
end_name = true;
break;
default:
Expand All @@ -342,6 +347,9 @@ void HighlightObjectTypes(GView::Utils::DataCache& data, BufferViewer::Settings&
}
settings.AddZone(start_segment, object_offset - start_segment, ColorPair{ Color::Red, Color::DarkBlue }, "Name");
}
} else if (buffer == PDF::KEY::PDF_INDIRECTOBJ) {
settings.AddZone(object_offset, 1, ColorPair{ Color::Yellow, Color::Blue }, "Indirect Obj");
object_offset++;
} else if (CheckType(data, object_offset, PDF::KEY::PDF_STREAM_SIZE, PDF::KEY::PDF_STREAM)) {
if (found_length) {
const uint64_t start_segment = object_offset;
Expand All @@ -364,6 +372,32 @@ void HighlightObjectTypes(GView::Utils::DataCache& data, BufferViewer::Settings&
object_offset++;
}
settings.AddZone(start_segment, object_offset - start_segment, ColorPair{ Color::Green, Color::DarkBlue }, "Numeric");
} else if (buffer == PDF::DC::LEFT_PARETHESIS) {
const uint64_t start_segment = object_offset;
object_offset++;
while (object_offset < dataSize && data.Copy(object_offset, buffer) && buffer != PDF::DC::RIGHT_PARETHESIS) {
if (buffer == PDF::DC::REVERSE_SOLIDUS) {
object_offset++;
}
object_offset++;
}
settings.AddZone(start_segment, object_offset - start_segment + 1, ColorPair{ Color::DarkGreen, Color::DarkBlue }, "Literal String");
} else if (buffer == PDF::DC::LESS_THAN) {
const uint64_t start_segment = object_offset;
object_offset++;
while (object_offset < dataSize && data.Copy(object_offset, buffer) && buffer != PDF::DC::GREATER_THAN) {
object_offset++;
}
settings.AddZone(start_segment, object_offset - start_segment + 1, ColorPair{ Color::DarkGreen, Color::DarkBlue }, "Hex String");
} else if (CheckType(data, object_offset, PDF::KEY::PDF_TRUE_SIZE, PDF::KEY::PDF_TRUE)) {
settings.AddZone(object_offset, PDF::KEY::PDF_TRUE_SIZE, ColorPair{ Color::DarkRed, Color::DarkBlue }, "Boolean");
object_offset += PDF::KEY::PDF_TRUE_SIZE;
} else if (CheckType(data, object_offset, PDF::KEY::PDF_FALSE_SIZE, PDF::KEY::PDF_FALSE)) {
settings.AddZone(object_offset, PDF::KEY::PDF_FALSE_SIZE, ColorPair{ Color::DarkRed, Color::DarkBlue }, "Boolean");
object_offset += PDF::KEY::PDF_FALSE_SIZE;
} else if (CheckType(data, object_offset, PDF::KEY::PDF_NULL_SIZE, PDF::KEY::PDF_NULL)) {
settings.AddZone(object_offset, PDF::KEY::PDF_NULL_SIZE, ColorPair{ Color::White, Color::Blue }, "Null");
object_offset += PDF::KEY::PDF_NULL_SIZE;
} else if (CheckType(data, object_offset, PDF::KEY::PDF_ENDOBJ_SIZE, PDF::KEY::PDF_ENDOBJ)) {
break;
} else {
Expand All @@ -386,8 +420,6 @@ void CreateBufferView(Reference<GView::View::WindowInterface> win, Reference<PDF
bool foundEOF = false;
std::vector<uint64_t> objectOffsets;

const std::vector<ColorPair> colors = { ColorPair{ Color::Teal, Color::DarkBlue }, ColorPair{ Color::Yellow, Color::DarkBlue } };

// HEADER
settings.AddZone(0, sizeof(PDF::Header), ColorPair{ Color::Magenta, Color::DarkBlue }, "Header");

Expand Down Expand Up @@ -653,7 +685,7 @@ void CreateBufferView(Reference<GView::View::WindowInterface> win, Reference<PDF
for (size_t i = 0; i < objectOffsets.size(); ++i) {
uint64_t objOffset = objectOffsets[i];
uint64_t length = (i + 1 < objectOffsets.size()) ? objectOffsets[i + 1] - objOffset : eofOffset - objOffset;
settings.AddZone(objOffset, length, colors[i % colors.size()], "Obj " + std::to_string(i + 1));
settings.AddZone(objOffset, length, { Color::Teal, Color::DarkBlue }, "Obj " + std::to_string(i + 1));
HighlightObjectTypes(data, settings, objOffset, dataSize);
}

Expand Down

0 comments on commit e057bf6

Please sign in to comment.