public void AddXRef(TokenXRefEntry xref) { PdfIndirectObject indirect = new PdfIndirectObject(this, xref); if (_gens == null) { if (_single == null) { // Cache the single object _single = indirect; return; } else { // Convert from single entry to using a dictionary _gens = new Dictionary <int, PdfIndirectObject> { { _single.Gen, _single } }; _single = null; } } if (_gens.ContainsKey(xref.Gen)) { // PH: ignore this ref and let the document be still loaded // TODO: should signal any kind of warning to the caller return; //throw new ApplicationException($"Indirect object with Id:{xref.Id} Gen:{xref.Gen} already exists."); } _gens.Add(indirect.Gen, indirect); }
public void AddXRef(TokenXRefEntry xref) { PdfIndirectObject indirect = new PdfIndirectObject(this, xref); if (_gens == null) { if (_single == null) { // Cache the single object _single = indirect; return; } else { // Convert from single entry to using a dictionary _gens = new Dictionary <int, PdfIndirectObject> { { _single.Gen, _single } }; _single = null; } } if (_gens.ContainsKey(xref.Gen)) { throw new ApplicationException($"Indirect object with Id:{xref.Id} Gen:{xref.Gen} already exists."); } _gens.Add(indirect.Gen, indirect); }
public void Visit(PdfIndirectObject indirectObject) { PushLevel(); Append($"Id:{indirectObject.Id} Gen:{indirectObject.Gen} Offset:{indirectObject.Offset}"); VisitNotNull(indirectObject.Child); CurrentLevelNewLine(); PopLevel(); }
public PdfObject ResolveReference(Parser parser, PdfIndirectObject indirect) { if (indirect != null) { if (indirect.Child == null) { ParseIndirectObject parseIndirectObject = parser.ParseIndirectObject(indirect.Offset); indirect.Child = indirect.WrapObject(parseIndirectObject.Object); } return(indirect.Child); } return(null); }
private byte[] DecodeBytes(PdfObject obj, byte[] bytes) { PdfIndirectObject indirectObject = obj.TypedParent <PdfIndirectObject>(); if (indirectObject == null) { throw new ApplicationException($"Cannot decrypt a string that is not inside an indirect object."); } // Create bytes that need hashing by combining the encryption key with the indirect object numbers byte[] key = new byte[_encryptionKey.Length + 5]; Array.Copy(_encryptionKey, 0, key, 0, _encryptionKey.Length); int index = _encryptionKey.Length; int id = indirectObject.Id; key[index++] = (byte)(id >> 0); key[index++] = (byte)(id >> 8); key[index++] = (byte)(id >> 16); int gen = indirectObject.Gen; key[index++] = (byte)(gen >> 0); key[index++] = (byte)(gen >> 8); // MD5 hash the bytes to get raw decrypt key key = _md5.ComputeHash(key); // Limit check the decrypt key length int keyLength = _encryptionKey.Length + 5; if (keyLength > 16) { keyLength = 16; } // Create the RC4 key byte[] rc4Key = new Byte[keyLength]; Array.Copy(key, 0, rc4Key, 0, keyLength); return(RC4.Transform(rc4Key, bytes)); }
public PdfObject ResolveReference(PdfIndirectObject indirect) { return(ResolveReference(_parser, indirect)); }