OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "core/src/fpdfapi/fpdf_edit/editint.h" | 7 #include "core/src/fpdfapi/fpdf_edit/editint.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 14 matching lines...) Expand all Loading... |
25 FX_FILESIZE& offset) { | 25 FX_FILESIZE& offset) { |
26 int32_t len = 0; | 26 int32_t len = 0; |
27 if (!pObj) { | 27 if (!pObj) { |
28 if (pFile->AppendString(" null") < 0) { | 28 if (pFile->AppendString(" null") < 0) { |
29 return -1; | 29 return -1; |
30 } | 30 } |
31 offset += 5; | 31 offset += 5; |
32 return 1; | 32 return 1; |
33 } | 33 } |
34 switch (pObj->GetType()) { | 34 switch (pObj->GetType()) { |
35 case PDFOBJ_NULL: | 35 case CPDF_Object::NULLOBJ: |
36 if (pFile->AppendString(" null") < 0) { | 36 if (pFile->AppendString(" null") < 0) { |
37 return -1; | 37 return -1; |
38 } | 38 } |
39 offset += 5; | 39 offset += 5; |
40 break; | 40 break; |
41 case PDFOBJ_BOOLEAN: | 41 case CPDF_Object::BOOLEAN: |
42 case PDFOBJ_NUMBER: | 42 case CPDF_Object::NUMBER: |
43 if (pFile->AppendString(" ") < 0) { | 43 if (pFile->AppendString(" ") < 0) { |
44 return -1; | 44 return -1; |
45 } | 45 } |
46 if ((len = pFile->AppendString(pObj->GetString())) < 0) { | 46 if ((len = pFile->AppendString(pObj->GetString())) < 0) { |
47 return -1; | 47 return -1; |
48 } | 48 } |
49 offset += len + 1; | 49 offset += len + 1; |
50 break; | 50 break; |
51 case PDFOBJ_STRING: { | 51 case CPDF_Object::STRING: { |
52 CFX_ByteString str = pObj->GetString(); | 52 CFX_ByteString str = pObj->GetString(); |
53 FX_BOOL bHex = pObj->AsString()->IsHex(); | 53 FX_BOOL bHex = pObj->AsString()->IsHex(); |
54 if ((len = pFile->AppendString(PDF_EncodeString(str, bHex))) < 0) { | 54 if ((len = pFile->AppendString(PDF_EncodeString(str, bHex))) < 0) { |
55 return -1; | 55 return -1; |
56 } | 56 } |
57 offset += len; | 57 offset += len; |
58 break; | 58 break; |
59 } | 59 } |
60 case PDFOBJ_NAME: { | 60 case CPDF_Object::NAME: { |
61 if (pFile->AppendString("/") < 0) { | 61 if (pFile->AppendString("/") < 0) { |
62 return -1; | 62 return -1; |
63 } | 63 } |
64 CFX_ByteString str = pObj->GetString(); | 64 CFX_ByteString str = pObj->GetString(); |
65 if ((len = pFile->AppendString(PDF_NameEncode(str))) < 0) { | 65 if ((len = pFile->AppendString(PDF_NameEncode(str))) < 0) { |
66 return -1; | 66 return -1; |
67 } | 67 } |
68 offset += len + 1; | 68 offset += len + 1; |
69 break; | 69 break; |
70 } | 70 } |
71 case PDFOBJ_REFERENCE: { | 71 case CPDF_Object::REFERENCE: { |
72 if (pFile->AppendString(" ") < 0) | 72 if (pFile->AppendString(" ") < 0) |
73 return -1; | 73 return -1; |
74 if ((len = pFile->AppendDWord(pObj->AsReference()->GetRefObjNum())) < 0) | 74 if ((len = pFile->AppendDWord(pObj->AsReference()->GetRefObjNum())) < 0) |
75 return -1; | 75 return -1; |
76 if (pFile->AppendString(" 0 R ") < 0) | 76 if (pFile->AppendString(" 0 R ") < 0) |
77 return -1; | 77 return -1; |
78 offset += len + 6; | 78 offset += len + 6; |
79 break; | 79 break; |
80 } | 80 } |
81 case PDFOBJ_ARRAY: { | 81 case CPDF_Object::ARRAY: { |
82 if (pFile->AppendString("[") < 0) { | 82 if (pFile->AppendString("[") < 0) { |
83 return -1; | 83 return -1; |
84 } | 84 } |
85 offset += 1; | 85 offset += 1; |
86 const CPDF_Array* p = pObj->AsArray(); | 86 const CPDF_Array* p = pObj->AsArray(); |
87 for (FX_DWORD i = 0; i < p->GetCount(); i++) { | 87 for (FX_DWORD i = 0; i < p->GetCount(); i++) { |
88 CPDF_Object* pElement = p->GetElement(i); | 88 CPDF_Object* pElement = p->GetElement(i); |
89 if (pElement->GetObjNum()) { | 89 if (pElement->GetObjNum()) { |
90 if (pFile->AppendString(" ") < 0) { | 90 if (pFile->AppendString(" ") < 0) { |
91 return -1; | 91 return -1; |
(...skipping 10 matching lines...) Expand all Loading... |
102 return -1; | 102 return -1; |
103 } | 103 } |
104 } | 104 } |
105 } | 105 } |
106 if (pFile->AppendString("]") < 0) { | 106 if (pFile->AppendString("]") < 0) { |
107 return -1; | 107 return -1; |
108 } | 108 } |
109 offset += 1; | 109 offset += 1; |
110 break; | 110 break; |
111 } | 111 } |
112 case PDFOBJ_DICTIONARY: { | 112 case CPDF_Object::DICTIONARY: { |
113 if (pFile->AppendString("<<") < 0) { | 113 if (pFile->AppendString("<<") < 0) { |
114 return -1; | 114 return -1; |
115 } | 115 } |
116 offset += 2; | 116 offset += 2; |
117 const CPDF_Dictionary* p = pObj->AsDictionary(); | 117 const CPDF_Dictionary* p = pObj->AsDictionary(); |
118 for (const auto& it : *p) { | 118 for (const auto& it : *p) { |
119 const CFX_ByteString& key = it.first; | 119 const CFX_ByteString& key = it.first; |
120 CPDF_Object* pValue = it.second; | 120 CPDF_Object* pValue = it.second; |
121 if (pFile->AppendString("/") < 0) { | 121 if (pFile->AppendString("/") < 0) { |
122 return -1; | 122 return -1; |
(...skipping 18 matching lines...) Expand all Loading... |
141 return -1; | 141 return -1; |
142 } | 142 } |
143 } | 143 } |
144 } | 144 } |
145 if (pFile->AppendString(">>") < 0) { | 145 if (pFile->AppendString(">>") < 0) { |
146 return -1; | 146 return -1; |
147 } | 147 } |
148 offset += 2; | 148 offset += 2; |
149 break; | 149 break; |
150 } | 150 } |
151 case PDFOBJ_STREAM: { | 151 case CPDF_Object::STREAM: { |
152 const CPDF_Stream* p = pObj->AsStream(); | 152 const CPDF_Stream* p = pObj->AsStream(); |
153 if (PDF_CreatorAppendObject(p->GetDict(), pFile, offset) < 0) { | 153 if (PDF_CreatorAppendObject(p->GetDict(), pFile, offset) < 0) { |
154 return -1; | 154 return -1; |
155 } | 155 } |
156 if (pFile->AppendString("stream\r\n") < 0) { | 156 if (pFile->AppendString("stream\r\n") < 0) { |
157 return -1; | 157 return -1; |
158 } | 158 } |
159 offset += 8; | 159 offset += 8; |
160 CPDF_StreamAcc acc; | 160 CPDF_StreamAcc acc; |
161 acc.LoadAllData(p, TRUE); | 161 acc.LoadAllData(p, TRUE); |
(...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 FX_BOOL bEncrypt) { | 1102 FX_BOOL bEncrypt) { |
1103 int32_t len = 0; | 1103 int32_t len = 0; |
1104 if (!pObj) { | 1104 if (!pObj) { |
1105 if (m_File.AppendString(" null") < 0) { | 1105 if (m_File.AppendString(" null") < 0) { |
1106 return -1; | 1106 return -1; |
1107 } | 1107 } |
1108 m_Offset += 5; | 1108 m_Offset += 5; |
1109 return 1; | 1109 return 1; |
1110 } | 1110 } |
1111 switch (pObj->GetType()) { | 1111 switch (pObj->GetType()) { |
1112 case PDFOBJ_NULL: | 1112 case CPDF_Object::NULLOBJ: |
1113 if (m_File.AppendString(" null") < 0) { | 1113 if (m_File.AppendString(" null") < 0) { |
1114 return -1; | 1114 return -1; |
1115 } | 1115 } |
1116 m_Offset += 5; | 1116 m_Offset += 5; |
1117 break; | 1117 break; |
1118 case PDFOBJ_BOOLEAN: | 1118 case CPDF_Object::BOOLEAN: |
1119 case PDFOBJ_NUMBER: | 1119 case CPDF_Object::NUMBER: |
1120 if (m_File.AppendString(" ") < 0) { | 1120 if (m_File.AppendString(" ") < 0) { |
1121 return -1; | 1121 return -1; |
1122 } | 1122 } |
1123 if ((len = m_File.AppendString(pObj->GetString())) < 0) { | 1123 if ((len = m_File.AppendString(pObj->GetString())) < 0) { |
1124 return -1; | 1124 return -1; |
1125 } | 1125 } |
1126 m_Offset += len + 1; | 1126 m_Offset += len + 1; |
1127 break; | 1127 break; |
1128 case PDFOBJ_STRING: { | 1128 case CPDF_Object::STRING: { |
1129 CFX_ByteString str = pObj->GetString(); | 1129 CFX_ByteString str = pObj->GetString(); |
1130 FX_BOOL bHex = pObj->AsString()->IsHex(); | 1130 FX_BOOL bHex = pObj->AsString()->IsHex(); |
1131 if (!m_pCryptoHandler || !bEncrypt) { | 1131 if (!m_pCryptoHandler || !bEncrypt) { |
1132 CFX_ByteString content = PDF_EncodeString(str, bHex); | 1132 CFX_ByteString content = PDF_EncodeString(str, bHex); |
1133 if ((len = m_File.AppendString(content)) < 0) { | 1133 if ((len = m_File.AppendString(content)) < 0) { |
1134 return -1; | 1134 return -1; |
1135 } | 1135 } |
1136 m_Offset += len; | 1136 m_Offset += len; |
1137 break; | 1137 break; |
1138 } | 1138 } |
1139 CPDF_Encryptor encryptor; | 1139 CPDF_Encryptor encryptor; |
1140 encryptor.Initialize(m_pCryptoHandler, objnum, (uint8_t*)str.c_str(), | 1140 encryptor.Initialize(m_pCryptoHandler, objnum, (uint8_t*)str.c_str(), |
1141 str.GetLength()); | 1141 str.GetLength()); |
1142 CFX_ByteString content = PDF_EncodeString( | 1142 CFX_ByteString content = PDF_EncodeString( |
1143 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize), | 1143 CFX_ByteString((const FX_CHAR*)encryptor.m_pData, encryptor.m_dwSize), |
1144 bHex); | 1144 bHex); |
1145 if ((len = m_File.AppendString(content)) < 0) { | 1145 if ((len = m_File.AppendString(content)) < 0) { |
1146 return -1; | 1146 return -1; |
1147 } | 1147 } |
1148 m_Offset += len; | 1148 m_Offset += len; |
1149 break; | 1149 break; |
1150 } | 1150 } |
1151 case PDFOBJ_STREAM: { | 1151 case CPDF_Object::STREAM: { |
1152 CPDF_FlateEncoder encoder; | 1152 CPDF_FlateEncoder encoder; |
1153 encoder.Initialize(const_cast<CPDF_Stream*>(pObj->AsStream()), | 1153 encoder.Initialize(const_cast<CPDF_Stream*>(pObj->AsStream()), |
1154 m_bCompress); | 1154 m_bCompress); |
1155 CPDF_Encryptor encryptor; | 1155 CPDF_Encryptor encryptor; |
1156 CPDF_CryptoHandler* pHandler = m_pCryptoHandler; | 1156 CPDF_CryptoHandler* pHandler = m_pCryptoHandler; |
1157 encryptor.Initialize(pHandler, objnum, encoder.m_pData, encoder.m_dwSize); | 1157 encryptor.Initialize(pHandler, objnum, encoder.m_pData, encoder.m_dwSize); |
1158 if ((FX_DWORD)encoder.m_pDict->GetInteger("Length") != | 1158 if ((FX_DWORD)encoder.m_pDict->GetInteger("Length") != |
1159 encryptor.m_dwSize) { | 1159 encryptor.m_dwSize) { |
1160 encoder.CloneDict(); | 1160 encoder.CloneDict(); |
1161 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); | 1161 encoder.m_pDict->SetAtInteger("Length", encryptor.m_dwSize); |
1162 } | 1162 } |
1163 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { | 1163 if (WriteDirectObj(objnum, encoder.m_pDict) < 0) { |
1164 return -1; | 1164 return -1; |
1165 } | 1165 } |
1166 if ((len = m_File.AppendString("stream\r\n")) < 0) { | 1166 if ((len = m_File.AppendString("stream\r\n")) < 0) { |
1167 return -1; | 1167 return -1; |
1168 } | 1168 } |
1169 m_Offset += len; | 1169 m_Offset += len; |
1170 if (m_File.AppendBlock(encryptor.m_pData, encryptor.m_dwSize) < 0) { | 1170 if (m_File.AppendBlock(encryptor.m_pData, encryptor.m_dwSize) < 0) { |
1171 return -1; | 1171 return -1; |
1172 } | 1172 } |
1173 m_Offset += encryptor.m_dwSize; | 1173 m_Offset += encryptor.m_dwSize; |
1174 if ((len = m_File.AppendString("\r\nendstream")) < 0) { | 1174 if ((len = m_File.AppendString("\r\nendstream")) < 0) { |
1175 return -1; | 1175 return -1; |
1176 } | 1176 } |
1177 m_Offset += len; | 1177 m_Offset += len; |
1178 break; | 1178 break; |
1179 } | 1179 } |
1180 case PDFOBJ_NAME: { | 1180 case CPDF_Object::NAME: { |
1181 if (m_File.AppendString("/") < 0) { | 1181 if (m_File.AppendString("/") < 0) { |
1182 return -1; | 1182 return -1; |
1183 } | 1183 } |
1184 CFX_ByteString str = pObj->GetString(); | 1184 CFX_ByteString str = pObj->GetString(); |
1185 if ((len = m_File.AppendString(PDF_NameEncode(str))) < 0) { | 1185 if ((len = m_File.AppendString(PDF_NameEncode(str))) < 0) { |
1186 return -1; | 1186 return -1; |
1187 } | 1187 } |
1188 m_Offset += len + 1; | 1188 m_Offset += len + 1; |
1189 break; | 1189 break; |
1190 } | 1190 } |
1191 case PDFOBJ_REFERENCE: { | 1191 case CPDF_Object::REFERENCE: { |
1192 if (m_File.AppendString(" ") < 0) | 1192 if (m_File.AppendString(" ") < 0) |
1193 return -1; | 1193 return -1; |
1194 if ((len = m_File.AppendDWord(pObj->AsReference()->GetRefObjNum())) < 0) | 1194 if ((len = m_File.AppendDWord(pObj->AsReference()->GetRefObjNum())) < 0) |
1195 return -1; | 1195 return -1; |
1196 if (m_File.AppendString(" 0 R") < 0) | 1196 if (m_File.AppendString(" 0 R") < 0) |
1197 return -1; | 1197 return -1; |
1198 m_Offset += len + 5; | 1198 m_Offset += len + 5; |
1199 break; | 1199 break; |
1200 } | 1200 } |
1201 case PDFOBJ_ARRAY: { | 1201 case CPDF_Object::ARRAY: { |
1202 if (m_File.AppendString("[") < 0) { | 1202 if (m_File.AppendString("[") < 0) { |
1203 return -1; | 1203 return -1; |
1204 } | 1204 } |
1205 m_Offset += 1; | 1205 m_Offset += 1; |
1206 const CPDF_Array* p = pObj->AsArray(); | 1206 const CPDF_Array* p = pObj->AsArray(); |
1207 for (FX_DWORD i = 0; i < p->GetCount(); i++) { | 1207 for (FX_DWORD i = 0; i < p->GetCount(); i++) { |
1208 CPDF_Object* pElement = p->GetElement(i); | 1208 CPDF_Object* pElement = p->GetElement(i); |
1209 if (pElement->GetObjNum()) { | 1209 if (pElement->GetObjNum()) { |
1210 if (m_File.AppendString(" ") < 0) { | 1210 if (m_File.AppendString(" ") < 0) { |
1211 return -1; | 1211 return -1; |
(...skipping 10 matching lines...) Expand all Loading... |
1222 return -1; | 1222 return -1; |
1223 } | 1223 } |
1224 } | 1224 } |
1225 } | 1225 } |
1226 if (m_File.AppendString("]") < 0) { | 1226 if (m_File.AppendString("]") < 0) { |
1227 return -1; | 1227 return -1; |
1228 } | 1228 } |
1229 m_Offset += 1; | 1229 m_Offset += 1; |
1230 break; | 1230 break; |
1231 } | 1231 } |
1232 case PDFOBJ_DICTIONARY: { | 1232 case CPDF_Object::DICTIONARY: { |
1233 if (!m_pCryptoHandler || pObj == m_pEncryptDict) { | 1233 if (!m_pCryptoHandler || pObj == m_pEncryptDict) { |
1234 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset); | 1234 return PDF_CreatorAppendObject(pObj, &m_File, m_Offset); |
1235 } | 1235 } |
1236 if (m_File.AppendString("<<") < 0) { | 1236 if (m_File.AppendString("<<") < 0) { |
1237 return -1; | 1237 return -1; |
1238 } | 1238 } |
1239 m_Offset += 2; | 1239 m_Offset += 2; |
1240 const CPDF_Dictionary* p = pObj->AsDictionary(); | 1240 const CPDF_Dictionary* p = pObj->AsDictionary(); |
1241 bool bSignDict = IsSignatureDict(p); | 1241 bool bSignDict = IsSignatureDict(p); |
1242 for (const auto& it : *p) { | 1242 for (const auto& it : *p) { |
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2078 m_bNewCrypto = FALSE; | 2078 m_bNewCrypto = FALSE; |
2079 if (!m_bStandardSecurity) { | 2079 if (!m_bStandardSecurity) { |
2080 return; | 2080 return; |
2081 } | 2081 } |
2082 if (m_pEncryptDict) { | 2082 if (m_pEncryptDict) { |
2083 m_pEncryptDict->Release(); | 2083 m_pEncryptDict->Release(); |
2084 m_pEncryptDict = NULL; | 2084 m_pEncryptDict = NULL; |
2085 } | 2085 } |
2086 m_bStandardSecurity = FALSE; | 2086 m_bStandardSecurity = FALSE; |
2087 } | 2087 } |
OLD | NEW |