blob: d9a07a85074ee0de52f855300c8a11e86a534fac [file] [log] [blame]
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07001// Copyright 2014 PDFium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
Lei Zhanga6d9f0e2015-06-13 00:48:38 -07004
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -07005// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
Tom Sepez37458412015-10-06 11:33:46 -07007#include "JS_GlobalData.h"
8
Lei Zhanga688a042015-11-09 13:57:49 -08009#include "core/include/fdrm/fx_crypt.h"
Lei Zhangbde53d22015-11-12 22:21:30 -080010#include "fpdfsdk/include/javascript/IJavaScript.h"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070011
Nico Weber9d8ec5a2015-08-04 13:00:21 -070012#define JS_MAXGLOBALDATA (1024 * 4 - 8)
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070013
14/* --------------------- CJS_GlobalVariableArray --------------------- */
15
Nico Weber9d8ec5a2015-08-04 13:00:21 -070016CJS_GlobalVariableArray::CJS_GlobalVariableArray() {}
17
18CJS_GlobalVariableArray::~CJS_GlobalVariableArray() {
19 Empty();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070020}
21
Nico Weber9d8ec5a2015-08-04 13:00:21 -070022void CJS_GlobalVariableArray::Copy(const CJS_GlobalVariableArray& array) {
23 Empty();
24 for (int i = 0, sz = array.Count(); i < sz; i++) {
25 CJS_KeyValue* pOldObjData = array.GetAt(i);
26 ASSERT(pOldObjData != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070027
Nico Weber9d8ec5a2015-08-04 13:00:21 -070028 switch (pOldObjData->nType) {
29 case JS_GLOBALDATA_TYPE_NUMBER: {
30 CJS_KeyValue* pNewObjData = new CJS_KeyValue;
31 pNewObjData->sKey = pOldObjData->sKey;
32 pNewObjData->nType = pOldObjData->nType;
33 pNewObjData->dData = pOldObjData->dData;
34 Add(pNewObjData);
35 } break;
36 case JS_GLOBALDATA_TYPE_BOOLEAN: {
37 CJS_KeyValue* pNewObjData = new CJS_KeyValue;
38 pNewObjData->sKey = pOldObjData->sKey;
39 pNewObjData->nType = pOldObjData->nType;
40 pNewObjData->bData = pOldObjData->bData;
41 Add(pNewObjData);
42 } break;
43 case JS_GLOBALDATA_TYPE_STRING: {
44 CJS_KeyValue* pNewObjData = new CJS_KeyValue;
45 pNewObjData->sKey = pOldObjData->sKey;
46 pNewObjData->nType = pOldObjData->nType;
47 pNewObjData->sData = pOldObjData->sData;
48 Add(pNewObjData);
49 } break;
50 case JS_GLOBALDATA_TYPE_OBJECT: {
51 CJS_KeyValue* pNewObjData = new CJS_KeyValue;
52 pNewObjData->sKey = pOldObjData->sKey;
53 pNewObjData->nType = pOldObjData->nType;
54 pNewObjData->objData.Copy(pOldObjData->objData);
55 Add(pNewObjData);
56 }
57 case JS_GLOBALDATA_TYPE_NULL: {
58 CJS_KeyValue* pNewObjData = new CJS_KeyValue;
59 pNewObjData->sKey = pOldObjData->sKey;
60 pNewObjData->nType = pOldObjData->nType;
61 Add(pNewObjData);
62 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -070063 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -070064 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070065}
66
Nico Weber9d8ec5a2015-08-04 13:00:21 -070067void CJS_GlobalVariableArray::Add(CJS_KeyValue* p) {
68 array.Add(p);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070069}
70
Nico Weber9d8ec5a2015-08-04 13:00:21 -070071int CJS_GlobalVariableArray::Count() const {
72 return array.GetSize();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070073}
74
Nico Weber9d8ec5a2015-08-04 13:00:21 -070075CJS_KeyValue* CJS_GlobalVariableArray::GetAt(int index) const {
76 return array.GetAt(index);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070077}
78
Nico Weber9d8ec5a2015-08-04 13:00:21 -070079void CJS_GlobalVariableArray::Empty() {
80 for (int i = 0, sz = array.GetSize(); i < sz; i++)
81 delete array.GetAt(i);
82 array.RemoveAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070083}
84
85/* -------------------------- CJS_GlobalData -------------------------- */
86
Nico Weber9d8ec5a2015-08-04 13:00:21 -070087#define READER_JS_GLOBALDATA_FILENAME L"Reader_JsGlobal.Data"
88#define PHANTOM_JS_GLOBALDATA_FILENAME L"Phantom_JsGlobal.Data"
89#define SDK_JS_GLOBALDATA_FILENAME L"SDK_JsGlobal.Data"
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -070090
Nico Weber9d8ec5a2015-08-04 13:00:21 -070091static const uint8_t JS_RC4KEY[] = {
92 0x19, 0xa8, 0xe8, 0x01, 0xf6, 0xa8, 0xb6, 0x4d, 0x82, 0x04, 0x45, 0x6d,
93 0xb4, 0xcf, 0xd7, 0x77, 0x67, 0xf9, 0x75, 0x9f, 0xf0, 0xe0, 0x1e, 0x51,
94 0xee, 0x46, 0xfd, 0x0b, 0xc9, 0x93, 0x25, 0x55, 0x4a, 0xee, 0xe0, 0x16,
95 0xd0, 0xdf, 0x8c, 0xfa, 0x2a, 0xa9, 0x49, 0xfd, 0x97, 0x1c, 0x0e, 0x22,
96 0x13, 0x28, 0x7c, 0xaf, 0xc4, 0xfc, 0x9c, 0x12, 0x65, 0x8c, 0x4e, 0x5b,
97 0x04, 0x75, 0x89, 0xc9, 0xb1, 0xed, 0x50, 0xca, 0x96, 0x6f, 0x1a, 0x7a,
98 0xfe, 0x58, 0x5d, 0xec, 0x19, 0x4a, 0xf6, 0x35, 0x6a, 0x97, 0x14, 0x00,
99 0x0e, 0xd0, 0x6b, 0xbb, 0xd5, 0x75, 0x55, 0x8b, 0x6e, 0x6b, 0x19, 0xa0,
100 0xf8, 0x77, 0xd5, 0xa3};
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700101
Tom Sepezf4583622015-09-14 15:06:53 -0700102CJS_GlobalData* CJS_GlobalData::g_Instance = nullptr;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700103
Tom Sepezf4583622015-09-14 15:06:53 -0700104// static
105CJS_GlobalData* CJS_GlobalData::GetRetainedInstance(CPDFDoc_Environment* pApp) {
106 if (!g_Instance) {
Tom Sepezdfbf8e72015-10-14 14:17:26 -0700107 g_Instance = new CJS_GlobalData();
Tom Sepezf4583622015-09-14 15:06:53 -0700108 }
109 ++g_Instance->m_RefCount;
110 return g_Instance;
111}
112
113void CJS_GlobalData::Release() {
114 if (!--m_RefCount) {
115 delete g_Instance;
116 g_Instance = nullptr;
117 }
118}
119
Tom Sepezdfbf8e72015-10-14 14:17:26 -0700120CJS_GlobalData::CJS_GlobalData() : m_RefCount(0) {
Tom Sepezf4583622015-09-14 15:06:53 -0700121 m_sFilePath += SDK_JS_GLOBALDATA_FILENAME;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700122 LoadGlobalPersistentVariables();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700123}
124
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700125CJS_GlobalData::~CJS_GlobalData() {
126 SaveGlobalPersisitentVariables();
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700127 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++)
128 delete m_arrayGlobalData.GetAt(i);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700129
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700130 m_arrayGlobalData.RemoveAll();
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700131}
132
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700133int CJS_GlobalData::FindGlobalVariable(const FX_CHAR* propname) {
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700134 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) {
135 CJS_GlobalData_Element* pTemp = m_arrayGlobalData.GetAt(i);
Tom Sepezf4583622015-09-14 15:06:53 -0700136 if (pTemp->data.sKey[0] == *propname && pTemp->data.sKey == propname)
137 return i;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700138 }
Tom Sepezf4583622015-09-14 15:06:53 -0700139 return -1;
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700140}
141
142CJS_GlobalData_Element* CJS_GlobalData::GetGlobalVariable(
143 const FX_CHAR* propname) {
144 ASSERT(propname != NULL);
145
146 int nFind = FindGlobalVariable(propname);
147 if (nFind >= 0)
148 return m_arrayGlobalData.GetAt(nFind);
149
150 return NULL;
151}
152
153void CJS_GlobalData::SetGlobalVariableNumber(const FX_CHAR* propname,
154 double dData) {
155 ASSERT(propname != NULL);
156
157 CFX_ByteString sPropName = propname;
158 sPropName.TrimLeft();
159 sPropName.TrimRight();
160 if (sPropName.GetLength() == 0)
161 return;
162
163 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) {
164 pData->data.nType = JS_GLOBALDATA_TYPE_NUMBER;
165 pData->data.dData = dData;
166 } else {
167 CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
168 pNewData->data.sKey = sPropName;
169 pNewData->data.nType = JS_GLOBALDATA_TYPE_NUMBER;
170 pNewData->data.dData = dData;
171 m_arrayGlobalData.Add(pNewData);
172 }
173}
174
175void CJS_GlobalData::SetGlobalVariableBoolean(const FX_CHAR* propname,
176 bool bData) {
177 ASSERT(propname != NULL);
178 CFX_ByteString sPropName = propname;
179
180 sPropName.TrimLeft();
181 sPropName.TrimRight();
182
183 if (sPropName.GetLength() == 0)
184 return;
185
186 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) {
187 pData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN;
188 pData->data.bData = bData;
189 } else {
190 CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
191 pNewData->data.sKey = sPropName;
192 pNewData->data.nType = JS_GLOBALDATA_TYPE_BOOLEAN;
193 pNewData->data.bData = bData;
194
195 m_arrayGlobalData.Add(pNewData);
196 }
197}
198
199void CJS_GlobalData::SetGlobalVariableString(const FX_CHAR* propname,
200 const CFX_ByteString& sData) {
201 ASSERT(propname != NULL);
202 CFX_ByteString sPropName = propname;
203
204 sPropName.TrimLeft();
205 sPropName.TrimRight();
206
207 if (sPropName.GetLength() == 0)
208 return;
209
210 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) {
211 pData->data.nType = JS_GLOBALDATA_TYPE_STRING;
212 pData->data.sData = sData;
213 } else {
214 CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
215 pNewData->data.sKey = sPropName;
216 pNewData->data.nType = JS_GLOBALDATA_TYPE_STRING;
217 pNewData->data.sData = sData;
218
219 m_arrayGlobalData.Add(pNewData);
220 }
221}
222
223void CJS_GlobalData::SetGlobalVariableObject(
224 const FX_CHAR* propname,
225 const CJS_GlobalVariableArray& array) {
226 ASSERT(propname != NULL);
227 CFX_ByteString sPropName = propname;
228
229 sPropName.TrimLeft();
230 sPropName.TrimRight();
231
232 if (sPropName.GetLength() == 0)
233 return;
234
235 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) {
236 pData->data.nType = JS_GLOBALDATA_TYPE_OBJECT;
237 pData->data.objData.Copy(array);
238 } else {
239 CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
240 pNewData->data.sKey = sPropName;
241 pNewData->data.nType = JS_GLOBALDATA_TYPE_OBJECT;
242 pNewData->data.objData.Copy(array);
243
244 m_arrayGlobalData.Add(pNewData);
245 }
246}
247
248void CJS_GlobalData::SetGlobalVariableNull(const FX_CHAR* propname) {
249 ASSERT(propname != NULL);
250 CFX_ByteString sPropName = propname;
251
252 sPropName.TrimLeft();
253 sPropName.TrimRight();
254
255 if (sPropName.GetLength() == 0)
256 return;
257
258 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) {
259 pData->data.nType = JS_GLOBALDATA_TYPE_NULL;
260 } else {
261 CJS_GlobalData_Element* pNewData = new CJS_GlobalData_Element;
262 pNewData->data.sKey = sPropName;
263 pNewData->data.nType = JS_GLOBALDATA_TYPE_NULL;
264
265 m_arrayGlobalData.Add(pNewData);
266 }
267}
268
269FX_BOOL CJS_GlobalData::SetGlobalVariablePersistent(const FX_CHAR* propname,
270 FX_BOOL bPersistent) {
271 ASSERT(propname != NULL);
272 CFX_ByteString sPropName = propname;
273
274 sPropName.TrimLeft();
275 sPropName.TrimRight();
276
277 if (sPropName.GetLength() == 0)
278 return FALSE;
279
280 if (CJS_GlobalData_Element* pData = GetGlobalVariable(sPropName)) {
281 pData->bPersistent = bPersistent;
282 return TRUE;
283 }
284
285 return FALSE;
286}
287
288FX_BOOL CJS_GlobalData::DeleteGlobalVariable(const FX_CHAR* propname) {
289 ASSERT(propname != NULL);
290 CFX_ByteString sPropName = propname;
291
292 sPropName.TrimLeft();
293 sPropName.TrimRight();
294
295 if (sPropName.GetLength() == 0)
296 return FALSE;
297
298 int nFind = FindGlobalVariable(sPropName);
299
300 if (nFind >= 0) {
301 delete m_arrayGlobalData.GetAt(nFind);
302 m_arrayGlobalData.RemoveAt(nFind);
303 return TRUE;
304 }
305
306 return FALSE;
307}
308
309int32_t CJS_GlobalData::GetSize() const {
310 return m_arrayGlobalData.GetSize();
311}
312
313CJS_GlobalData_Element* CJS_GlobalData::GetAt(int index) const {
314 return m_arrayGlobalData.GetAt(index);
315}
316
317void CJS_GlobalData::LoadGlobalPersistentVariables() {
318 uint8_t* pBuffer = NULL;
319 int32_t nLength = 0;
320
321 LoadFileBuffer(m_sFilePath.c_str(), pBuffer, nLength);
322 CRYPT_ArcFourCryptBlock(pBuffer, nLength, JS_RC4KEY, sizeof(JS_RC4KEY));
323
324 if (pBuffer) {
325 uint8_t* p = pBuffer;
326 FX_WORD wType = *((FX_WORD*)p);
327 p += sizeof(FX_WORD);
328
329 // FX_WORD wTemp = (FX_WORD)(('X' << 8) | 'F');
330
331 if (wType == (FX_WORD)(('X' << 8) | 'F')) {
332 FX_WORD wVersion = *((FX_WORD*)p);
333 p += sizeof(FX_WORD);
334
335 ASSERT(wVersion <= 2);
336
337 FX_DWORD dwCount = *((FX_DWORD*)p);
338 p += sizeof(FX_DWORD);
339
340 FX_DWORD dwSize = *((FX_DWORD*)p);
341 p += sizeof(FX_DWORD);
342
343 if (dwSize == nLength - sizeof(FX_WORD) * 2 - sizeof(FX_DWORD) * 2) {
344 for (int32_t i = 0, sz = dwCount; i < sz; i++) {
345 if (p > pBuffer + nLength)
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700346 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700347
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700348 FX_DWORD dwNameLen = *((FX_DWORD*)p);
349 p += sizeof(FX_DWORD);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700350
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700351 if (p + dwNameLen > pBuffer + nLength)
352 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700353
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700354 CFX_ByteString sEntry = CFX_ByteString(p, dwNameLen);
355 p += sizeof(char) * dwNameLen;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700356
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700357 FX_WORD wDataType = *((FX_WORD*)p);
358 p += sizeof(FX_WORD);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700359
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700360 switch (wDataType) {
361 case JS_GLOBALDATA_TYPE_NUMBER: {
362 double dData = 0;
363 switch (wVersion) {
364 case 1: {
365 FX_DWORD dwData = *((FX_DWORD*)p);
366 p += sizeof(FX_DWORD);
367 dData = dwData;
368 } break;
369 case 2: {
370 dData = *((double*)p);
371 p += sizeof(double);
372 } break;
373 }
374 SetGlobalVariableNumber(sEntry, dData);
375 SetGlobalVariablePersistent(sEntry, TRUE);
376 } break;
377 case JS_GLOBALDATA_TYPE_BOOLEAN: {
378 FX_WORD wData = *((FX_WORD*)p);
379 p += sizeof(FX_WORD);
380 SetGlobalVariableBoolean(sEntry, (bool)(wData == 1));
381 SetGlobalVariablePersistent(sEntry, TRUE);
382 } break;
383 case JS_GLOBALDATA_TYPE_STRING: {
384 FX_DWORD dwLength = *((FX_DWORD*)p);
385 p += sizeof(FX_DWORD);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700386
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700387 if (p + dwLength > pBuffer + nLength)
388 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700389
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700390 SetGlobalVariableString(sEntry, CFX_ByteString(p, dwLength));
391 SetGlobalVariablePersistent(sEntry, TRUE);
392 p += sizeof(char) * dwLength;
393 } break;
394 case JS_GLOBALDATA_TYPE_NULL: {
395 SetGlobalVariableNull(sEntry);
396 SetGlobalVariablePersistent(sEntry, TRUE);
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700397 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700398 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700399 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700400 }
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700401 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700402 FX_Free(pBuffer);
403 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700404}
405
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700406void CJS_GlobalData::SaveGlobalPersisitentVariables() {
407 FX_DWORD nCount = 0;
408 CFX_BinaryBuf sData;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700409
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700410 for (int i = 0, sz = m_arrayGlobalData.GetSize(); i < sz; i++) {
411 CJS_GlobalData_Element* pElement = m_arrayGlobalData.GetAt(i);
412 ASSERT(pElement != NULL);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700413
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700414 if (pElement->bPersistent) {
415 CFX_BinaryBuf sElement;
416 MakeByteString(pElement->data.sKey, &pElement->data, sElement);
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700417
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700418 if (sData.GetSize() + sElement.GetSize() > JS_MAXGLOBALDATA)
419 break;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700420
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700421 sData.AppendBlock(sElement.GetBuffer(), sElement.GetSize());
422 nCount++;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700423 }
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700424 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700425
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700426 CFX_BinaryBuf sFile;
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700427
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700428 FX_WORD wType = (FX_WORD)(('X' << 8) | 'F');
429 sFile.AppendBlock(&wType, sizeof(FX_WORD));
430 FX_WORD wVersion = 2;
431 sFile.AppendBlock(&wVersion, sizeof(FX_WORD));
432 sFile.AppendBlock(&nCount, sizeof(FX_DWORD));
433 FX_DWORD dwSize = sData.GetSize();
434 sFile.AppendBlock(&dwSize, sizeof(FX_DWORD));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700435
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700436 sFile.AppendBlock(sData.GetBuffer(), sData.GetSize());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700437
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700438 CRYPT_ArcFourCryptBlock(sFile.GetBuffer(), sFile.GetSize(), JS_RC4KEY,
439 sizeof(JS_RC4KEY));
440 WriteFileBuffer(m_sFilePath.c_str(), (const FX_CHAR*)sFile.GetBuffer(),
441 sFile.GetSize());
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700442}
443
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700444void CJS_GlobalData::LoadFileBuffer(const FX_WCHAR* sFilePath,
445 uint8_t*& pBuffer,
446 int32_t& nLength) {
447 // UnSupport.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700448}
449
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700450void CJS_GlobalData::WriteFileBuffer(const FX_WCHAR* sFilePath,
451 const FX_CHAR* pBuffer,
452 int32_t nLength) {
453 // UnSupport.
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700454}
455
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700456void CJS_GlobalData::MakeByteString(const CFX_ByteString& name,
457 CJS_KeyValue* pData,
458 CFX_BinaryBuf& sData) {
459 FX_WORD wType = (FX_WORD)pData->nType;
460 switch (wType) {
461 case JS_GLOBALDATA_TYPE_NUMBER: {
462 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
463 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
464 sData.AppendString(name);
465 sData.AppendBlock(&wType, sizeof(FX_WORD));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700466
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700467 double dData = pData->dData;
468 sData.AppendBlock(&dData, sizeof(double));
469 } break;
470 case JS_GLOBALDATA_TYPE_BOOLEAN: {
471 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
472 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
473 sData.AppendString(name);
474 sData.AppendBlock(&wType, sizeof(FX_WORD));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700475
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700476 FX_WORD wData = (FX_WORD)pData->bData;
477 sData.AppendBlock(&wData, sizeof(FX_WORD));
478 } break;
479 case JS_GLOBALDATA_TYPE_STRING: {
480 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
481 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
482 sData.AppendString(name);
483 sData.AppendBlock(&wType, sizeof(FX_WORD));
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700484
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700485 FX_DWORD dwDataLen = (FX_DWORD)pData->sData.GetLength();
486 sData.AppendBlock(&dwDataLen, sizeof(FX_DWORD));
487 sData.AppendString(pData->sData);
488 } break;
489 case JS_GLOBALDATA_TYPE_NULL: {
490 FX_DWORD dwNameLen = (FX_DWORD)name.GetLength();
491 sData.AppendBlock(&dwNameLen, sizeof(FX_DWORD));
492 sData.AppendString(name);
493 sData.AppendBlock(&wType, sizeof(FX_DWORD));
494 } break;
Tom Sepez2f2ffec2015-07-23 14:42:09 -0700495 default:
Nico Weber9d8ec5a2015-08-04 13:00:21 -0700496 break;
497 }
John Abd-El-Malek3f3b45c2014-05-23 17:28:10 -0700498}