diff options
author | Martin Kretzschmar <mkretzschmar@src.gnome.org> | 2002-09-18 20:32:18 (GMT) |
---|---|---|
committer | Martin Kretzschmar <mkretzschmar@src.gnome.org> | 2002-09-18 20:32:18 (GMT) |
commit | 7aac8dc8533347e21311b15186e0af82f1b22fd6 (patch) | |
tree | 02650bb02c8a1d8468c22f50ff151885d233016b /pdf/xpdf/Parser.cc | |
parent | d99fb4f4acd14fcdbda968abd907547dcc7af40c (diff) |
Synched with Xpdf 0.92
this adds "decryption" support
testing this code after six weeks immediately gives me segfaults (image drawing) :-O
must have fixed that later without knowing :-O
Diffstat (limited to 'pdf/xpdf/Parser.cc')
-rw-r--r-- | pdf/xpdf/Parser.cc | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/pdf/xpdf/Parser.cc b/pdf/xpdf/Parser.cc index 5568580..6ad0c5a 100644 --- a/pdf/xpdf/Parser.cc +++ b/pdf/xpdf/Parser.cc @@ -15,7 +15,11 @@ #include "Array.h" #include "Dict.h" #include "Parser.h" +#include "XRef.h" #include "Error.h" +#ifndef NO_DECRYPTION +#include "Decrypt.h" +#endif Parser::Parser(Lexer *lexer1) { lexer = lexer1; @@ -30,11 +34,22 @@ Parser::~Parser() { delete lexer; } +#ifndef NO_DECRYPTION +Object *Parser::getObj(Object *obj, + Guchar *fileKey, int objNum, int objGen) { +#else Object *Parser::getObj(Object *obj) { +#endif char *key; Stream *str; Object obj2; int num; +#ifndef NO_DECRYPTION + Decrypt *decrypt; + GString *s; + char *p; + int i; +#endif // refill buffer after inline image data if (inlineImg == 2) { @@ -50,7 +65,11 @@ Object *Parser::getObj(Object *obj) { shift(); obj->initArray(); while (!buf1.isCmd("]") && !buf1.isEOF()) +#ifndef NO_DECRYPTION + obj->arrayAdd(getObj(&obj2, fileKey, objNum, objGen)); +#else obj->arrayAdd(getObj(&obj2)); +#endif if (buf1.isEOF()) error(getPos(), "End of file inside array"); shift(); @@ -68,7 +87,11 @@ Object *Parser::getObj(Object *obj) { shift(); if (buf1.isEOF() || buf1.isError()) break; +#ifndef NO_DECRYPTION + obj->dictAdd(key, getObj(&obj2, fileKey, objNum, objGen)); +#else obj->dictAdd(key, getObj(&obj2)); +#endif } } if (buf1.isEOF()) @@ -76,6 +99,11 @@ Object *Parser::getObj(Object *obj) { if (buf2.isCmd("stream")) { if ((str = makeStream(obj))) { obj->initStream(str); +#ifndef NO_DECRYPTION + if (fileKey) { + str->getBaseStream()->doDecryption(fileKey, objNum, objGen); + } +#endif } else { obj->free(); obj->initError(); @@ -96,6 +124,21 @@ Object *Parser::getObj(Object *obj) { obj->initInt(num); } +#ifndef NO_DECRYPTION + // string + } else if (buf1.isString() && fileKey) { + buf1.copy(obj); + s = obj->getString(); + decrypt = new Decrypt(fileKey, objNum, objGen); + for (i = 0, p = obj->getString()->getCString(); + i < s->getLength(); + ++i, ++p) { + *p = decrypt->decryptByte(*p); + } + delete decrypt; + shift(); +#endif + // simple object } else { buf1.copy(obj); @@ -108,7 +151,7 @@ Object *Parser::getObj(Object *obj) { Stream *Parser::makeStream(Object *dict) { Object obj; Stream *str; - int pos, length; + int pos, endPos, length; // get stream start position lexer->skipToNextLine(); @@ -125,6 +168,11 @@ Stream *Parser::makeStream(Object *dict) { return NULL; } + // check for length in damaged file + if ((endPos = xref->getStreamEnd(pos)) >= 0) { + length = endPos - pos; + } + // make base stream str = lexer->getStream()->getBaseStream()->makeSubStream(pos, length, dict); |