1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "resource_append.h"
17 #include <algorithm>
18 #include <iomanip>
19 #include <iostream>
20 #include <regex>
21 #include "config_parser.h"
22 #include "header.h"
23 #include "id_worker.h"
24 #include "key_parser.h"
25 #include "reference_parser.h"
26 #include "resource_table.h"
27 #include "resource_util.h"
28 #ifdef __WIN32
29 #include "windows.h"
30 #endif
31 #include "securec.h"
32
33 namespace OHOS {
34 namespace Global {
35 namespace Restool {
36 using namespace std;
37
ResourceAppend(const PackageParser & packageParser)38 ResourceAppend::ResourceAppend(const PackageParser &packageParser) : packageParser_(packageParser)
39 {
40 }
41
Append()42 uint32_t ResourceAppend::Append()
43 {
44 string outputPath = packageParser_.GetOutput();
45 for (const auto &iter : packageParser_.GetAppend()) {
46 if (!ScanResources(iter, outputPath)) {
47 return RESTOOL_ERROR;
48 }
49 }
50 return RESTOOL_SUCCESS;
51 }
52
Combine()53 uint32_t ResourceAppend::Combine()
54 {
55 for (const auto &iter : packageParser_.GetInputs()) {
56 if (!Combine(iter)) {
57 return RESTOOL_ERROR;
58 }
59 }
60
61 if (!ParseRef()) {
62 return false;
63 }
64
65 ResourceTable resourceTable;
66 if (resourceTable.CreateResourceTable(items_) != RESTOOL_SUCCESS) {
67 return RESTOOL_ERROR;
68 }
69 return RESTOOL_SUCCESS;
70 }
71
72 // private
Combine(const string & folderPath)73 bool ResourceAppend::Combine(const string &folderPath)
74 {
75 FileEntry entry(folderPath);
76 if (!entry.Init()) {
77 return false;
78 }
79
80 itemsForModule_.clear();
81 for (const auto &child : entry.GetChilds()) {
82 if (!child->IsFile()) {
83 cerr << "Error:" << child->GetFilePath().GetPath() << " not file" << endl;
84 return false;
85 }
86
87 if (!LoadResourceItem(child->GetFilePath().GetPath())) {
88 return false;
89 }
90 }
91 return true;
92 }
93
ParseRef()94 bool ResourceAppend::ParseRef()
95 {
96 for (auto &iter : refs_) {
97 ReferenceParser ref;
98 if (iter->GetResType() == ResType::PROF) {
99 string dst = FileEntry::FilePath(packageParser_.GetOutput()).Append(RESOURCES_DIR)
100 .Append("base").Append("profile").Append(iter->GetName()).GetPath();
101 if (ref.ParseRefInJson(iter->GetFilePath(), dst) != RESTOOL_SUCCESS) {
102 return false;
103 }
104
105 if (ResourceUtil::FileExist(dst)) {
106 iter->SetData(reinterpret_cast<const int8_t *>(dst.c_str()), dst.length());
107 }
108 continue;
109 }
110
111 if (ref.ParseRefInResourceItem(*iter) != RESTOOL_SUCCESS) {
112 return false;
113 }
114 }
115 return true;
116 }
117
ScanResources(const string & resourcePath,const string & outputPath)118 bool ResourceAppend::ScanResources(const string &resourcePath, const string &outputPath)
119 {
120 if (!ResourceUtil::FileExist(resourcePath)) {
121 string filePath = FileEntry::FilePath(outputPath).Append(ResourceUtil::GenerateHash(resourcePath)).GetPath();
122 if (remove(filePath.c_str()) != 0) {
123 cerr << "Error: remove failed '" << filePath << "', reason: " << strerror(errno) << endl;
124 return false;
125 }
126 return true;
127 }
128
129 FileEntry entry(resourcePath);
130 if (!entry.Init()) {
131 return false;
132 }
133
134 if (entry.IsFile()) {
135 return ScanSingleFile(resourcePath, outputPath);
136 }
137
138 return ScanSubResources(entry, resourcePath, outputPath);
139 }
140
ScanSubResources(const FileEntry entry,const string & resourcePath,const string & outputPath)141 bool ResourceAppend::ScanSubResources(const FileEntry entry, const string &resourcePath, const string &outputPath)
142 {
143 vector<KeyParam> keyParams;
144 if (KeyParser::Parse(entry.GetFilePath().GetFilename(), keyParams)) {
145 for (const auto &child : entry.GetChilds()) {
146 if (!ResourceUtil::IslegalPath(child->GetFilePath().GetFilename())) {
147 continue;
148 }
149 if (!ScanIegalResources(child->GetFilePath().GetPath(), outputPath)) {
150 return false;
151 }
152 }
153 return true;
154 }
155
156 if (ResourceUtil::IslegalPath(entry.GetFilePath().GetFilename())) {
157 return ScanIegalResources(resourcePath, outputPath);
158 }
159
160 return ScanSubLimitkeyResources(entry, resourcePath, outputPath);
161 }
162
ScanSubLimitkeyResources(const FileEntry entry,const string & resourcePath,const string & outputPath)163 bool ResourceAppend::ScanSubLimitkeyResources(const FileEntry entry, const string &resourcePath,
164 const string &outputPath)
165 {
166 for (const auto &child : entry.GetChilds()) {
167 string limitKey = child->GetFilePath().GetFilename();
168 if (ResourceUtil::IsIgnoreFile(limitKey, child->IsFile())) {
169 continue;
170 }
171
172 if (limitKey == RAW_FILE_DIR) {
173 if (!ScanRawFiles(child->GetFilePath().GetPath(), outputPath)) {
174 return false;
175 }
176 continue;
177 }
178
179 if (child->IsFile()) {
180 cerr << "Error: " << child->GetFilePath().GetPath() << " not directory" << endl;
181 return false;
182 }
183
184 if (!ScanLimitKey(child, limitKey, outputPath)) {
185 return false;
186 }
187 }
188 return true;
189 }
190
ScanIegalResources(const string & resourcePath,const string & outputPath)191 bool ResourceAppend::ScanIegalResources(const string &resourcePath, const string &outputPath)
192 {
193 FileEntry entry(resourcePath);
194 if (!entry.Init()) {
195 return false;
196 }
197 for (const auto &child : entry.GetChilds()) {
198 if (!ScanSingleFile(child->GetFilePath().GetPath(), outputPath)) {
199 return false;
200 }
201 }
202 return true;
203 }
ScanLimitKey(const unique_ptr<FileEntry> & entry,const string & limitKey,const string outputPath)204 bool ResourceAppend::ScanLimitKey(const unique_ptr<FileEntry> &entry,
205 const string &limitKey, const string outputPath)
206 {
207 vector<KeyParam> keyParams;
208 if (!KeyParser::Parse(limitKey, keyParams)) {
209 cerr << "Error: invalid limit key '" << limitKey << "'.";
210 cerr << NEW_LINE_PATH << entry->GetFilePath().GetPath() << endl;
211 return false;
212 }
213
214 for (const auto &child : entry->GetChilds()) {
215 string fileCuster = child->GetFilePath().GetFilename();
216 if (ResourceUtil::IsIgnoreFile(fileCuster, child->IsFile())) {
217 continue;
218 }
219
220 if (child->IsFile()) {
221 cerr << "Error: " << child->GetFilePath().GetPath() << " not directory" << endl;
222 return false;
223 }
224
225 ResType resType = ResourceUtil::GetResTypeByDir(fileCuster);
226 if (resType == ResType::INVALID_RES_TYPE) {
227 cerr << "Error: invalid resType." << NEW_LINE_PATH << child->GetFilePath().GetPath() << endl;
228 return false;
229 }
230
231 DirectoryInfo directoryInfo = { limitKey, fileCuster, child->GetFilePath().GetPath(), keyParams, resType};
232 if (!ScanFiles(child, directoryInfo, outputPath)) {
233 return false;
234 }
235 }
236 return true;
237 }
238
239
ScanFiles(const unique_ptr<FileEntry> & entry,const DirectoryInfo & directoryInfo,const string & outputPath)240 bool ResourceAppend::ScanFiles(const unique_ptr<FileEntry> &entry,
241 const DirectoryInfo &directoryInfo, const string &outputPath)
242 {
243 for (const auto &child : entry->GetChilds()) {
244 string filename = child->GetFilePath().GetFilename();
245 if (ResourceUtil::IsIgnoreFile(filename, child->IsFile())) {
246 continue;
247 }
248
249 if (!child->IsFile()) {
250 cerr << "Error: '" << child->GetFilePath().GetPath() << "' not file." << endl;
251 return false;
252 }
253
254 FileInfo fileInfo = {directoryInfo, child->GetFilePath().GetPath(), filename};
255 if (!ScanFile(fileInfo, outputPath)) {
256 return false;
257 }
258 }
259 return true;
260 }
261
ScanFile(const FileInfo & fileInfo,const string & outputPath)262 bool ResourceAppend::ScanFile(const FileInfo &fileInfo, const string &outputPath)
263 {
264 unique_ptr<IResourceCompiler> resourceCompiler =
265 FactoryResourceCompiler::CreateCompilerForAppend(fileInfo.dirType, outputPath);
266 if (resourceCompiler == nullptr) {
267 return true;
268 }
269
270 if (resourceCompiler->CompileForAppend(fileInfo) != RESTOOL_SUCCESS) {
271 return false;
272 }
273
274 ostringstream outStream;
275 const auto &items = resourceCompiler->GetResourceItems();
276 for (const auto &item : items) {
277 for (const auto &resourceItem : item.second) {
278 if (!WriteResourceItem(resourceItem, outStream)) {
279 return false;
280 }
281 }
282 }
283
284 string hash = ResourceUtil::GenerateHash(fileInfo.filePath);
285 FileEntry::FilePath output(outputPath);
286 if (!WriteFileInner(outStream, output.Append(hash).GetPath())) {
287 return false;
288 }
289 return true;
290 }
291
ScanSingleFile(const string & filePath,const string & outputPath)292 bool ResourceAppend::ScanSingleFile(const string &filePath, const string &outputPath)
293 {
294 if (filePath.find(RAW_FILE_DIR) != string::npos) {
295 return WriteRawFile(filePath, outputPath);
296 }
297
298 FileEntry::FilePath path(filePath);
299 string fileCuster = path.GetParent().GetFilename();
300 ResType resType = ResourceUtil::GetResTypeByDir(fileCuster);
301 if (resType == ResType::INVALID_RES_TYPE) {
302 cerr << "Error: invalid resType." << NEW_LINE_PATH << filePath << endl;
303 return false;
304 }
305
306 string limitKey = path.GetParent().GetParent().GetFilename();
307 vector<KeyParam> keyParams;
308 if (!KeyParser::Parse(limitKey, keyParams)) {
309 cerr << "Error: invalid limit key." << NEW_LINE_PATH << filePath << endl;
310 return false;
311 }
312
313 DirectoryInfo directoryInfo = {limitKey, fileCuster, path.GetParent().GetPath(), keyParams, resType};
314 FileInfo fileInfo = {directoryInfo, filePath, path.GetFilename() };
315 if (!ScanFile(fileInfo, outputPath)) {
316 return false;
317 }
318 return true;
319 }
320
WriteFileInner(ostringstream & outStream,const string & outputPath) const321 bool ResourceAppend::WriteFileInner(ostringstream &outStream, const string &outputPath) const
322 {
323 #ifdef __WIN32
324 HANDLE hWriteFile = CreateFile(outputPath.c_str(), GENERIC_WRITE, FILE_SHARE_WRITE,
325 nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
326 if (hWriteFile == INVALID_HANDLE_VALUE) {
327 cerr << "Error: '" << outputPath << "' " << GetLastError() << endl;
328 return false;
329 }
330
331 DWORD writeBytes;
332 if (!WriteFile(hWriteFile, outStream.str().c_str(), outStream.tellp(), &writeBytes, nullptr)) {
333 cerr << "Error: write '" << outputPath << "' " << GetLastError() << endl;
334 CloseHandle(hWriteFile);
335 return false;
336 }
337 CloseHandle(hWriteFile);
338 #else
339 ofstream out(outputPath, ofstream::out | ofstream::binary);
340 if (!out.is_open()) {
341 cerr << "Error: open failed '" << outputPath << "', reason: " << strerror(errno) << endl;
342 return false;
343 }
344 out << outStream.str();
345 #endif
346 return true;
347 }
348
WriteResourceItem(const ResourceItem & resourceItem,ostringstream & out)349 bool ResourceAppend::WriteResourceItem(const ResourceItem &resourceItem, ostringstream &out)
350 {
351 int32_t size = resourceItem.GetName().length();
352 out.write(reinterpret_cast<const char *>(&size), sizeof(int32_t));
353 out.write(reinterpret_cast<const char *>(resourceItem.GetName().c_str()), size);
354
355 size = resourceItem.GetLimitKey().length();
356 out.write(reinterpret_cast<const char *>(&size), sizeof(int32_t));
357 out.write(reinterpret_cast<const char *>(resourceItem.GetLimitKey().c_str()), size);
358
359 size = resourceItem.GetFilePath().length();
360 out.write(reinterpret_cast<const char *>(&size), sizeof(int32_t));
361 out.write(reinterpret_cast<const char *>(resourceItem.GetFilePath().c_str()), size);
362
363 int32_t type = static_cast<int32_t>(resourceItem.GetResType());
364 out.write(reinterpret_cast<const char *>(&type), sizeof(int32_t));
365
366 size = resourceItem.GetKeyParam().size();
367 out.write(reinterpret_cast<const char *>(&size), sizeof(int32_t));
368 for (const auto &keyParam : resourceItem.GetKeyParam()) {
369 out.write(reinterpret_cast<const char *>(&keyParam.keyType), sizeof(int32_t));
370 out.write(reinterpret_cast<const char *>(&keyParam.value), sizeof(int32_t));
371 }
372
373 size = resourceItem.GetDataLength();
374 out.write(reinterpret_cast<const char *>(&size), sizeof(int32_t));
375 out.write(reinterpret_cast<const char *>(resourceItem.GetData()), size);
376 return true;
377 }
378
LoadResourceItem(const string & filePath)379 bool ResourceAppend::LoadResourceItem(const string &filePath)
380 {
381 #ifdef __WIN32
382 return LoadResourceItemWin(filePath);
383 #else
384 ifstream in(filePath, ifstream::in | ifstream::binary);
385 if (!in.is_open()) {
386 cerr << "Error: open failed '" << filePath << "', reason: " << strerror(errno) << endl;
387 return false;
388 }
389
390 in.seekg(0, in.end);
391 int32_t length = in.tellg();
392 in.seekg(0, in.beg);
393 if (length <= 0) {
394 cerr << "Error: invalid file size = " << length << NEW_LINE_PATH << filePath << endl;
395 return false;
396 }
397 char buffer[length];
398 in.read(buffer, length);
399 return LoadResourceItemFromMem(buffer, length);
400 #endif
401 }
402
ScanRawFiles(const string & path,const string & outputPath)403 bool ResourceAppend::ScanRawFiles(const string &path, const string &outputPath)
404 {
405 FileEntry entry(path);
406 if (!entry.Init()) {
407 return false;
408 }
409
410 for (const auto &child : entry.GetChilds()) {
411 string filename = child->GetFilePath().GetFilename();
412 if (ResourceUtil::IsIgnoreFile(filename, child->IsFile())) {
413 continue;
414 }
415
416 bool ret = false;
417 if (child->IsFile()) {
418 ret = WriteRawFile(child->GetFilePath().GetPath(), outputPath);
419 } else {
420 ret = ScanRawFiles(child->GetFilePath().GetPath(), outputPath);
421 }
422
423 if (!ret) {
424 return false;
425 }
426 }
427 return true;
428 }
429
WriteRawFile(const string & filePath,const string & outputPath)430 bool ResourceAppend::WriteRawFile(const string &filePath, const string &outputPath)
431 {
432 string::size_type pos = filePath.find(RAW_FILE_DIR);
433 if (pos == string::npos) {
434 cerr << "Error: invaild raw file." << NEW_LINE_PATH << filePath << endl;
435 return false;
436 }
437
438 string sub = filePath.substr(pos);
439 sub = FileEntry::FilePath(RESOURCES_DIR).Append(sub).GetPath();
440 vector<KeyParam> keyParams;
441 ResourceItem resourceItem("", keyParams, ResType::RAW);
442 resourceItem.SetData(sub);
443 resourceItem.SetFilePath(filePath);
444 resourceItem.SetLimitKey("");
445
446 ostringstream outStream;
447 if (!WriteResourceItem(resourceItem, outStream)) {
448 return false;
449 }
450
451 string hash = ResourceUtil::GenerateHash(filePath);
452 FileEntry::FilePath output(outputPath);
453 if (!WriteFileInner(outStream, output.Append(hash).GetPath())) {
454 return false;
455 }
456 return true;
457 }
458
Push(const shared_ptr<ResourceItem> & resourceItem)459 bool ResourceAppend::Push(const shared_ptr<ResourceItem> &resourceItem)
460 {
461 string idName = ResourceUtil::GetIdName(resourceItem->GetName(), resourceItem->GetResType());
462 int32_t id = IdWorker::GetInstance().GenerateId(resourceItem->GetResType(), idName);
463 if (id < 0) {
464 return false;
465 }
466
467 if (!CheckModuleResourceItem(resourceItem, id)) {
468 return false;
469 }
470
471 const auto &result = items_.find(id);
472 if (result == items_.end()) {
473 items_[id].push_back(resourceItem);
474 AddRef(resourceItem);
475 return true;
476 }
477
478 if (find_if(result->second.begin(), result->second.end(), [resourceItem](auto &iter) {
479 return resourceItem->GetLimitKey() == iter->GetLimitKey();
480 }) != result->second.end()) {
481 return true;
482 }
483
484 items_[id].push_back(resourceItem);
485 AddRef(resourceItem);
486 return true;
487 }
488
AddRef(const shared_ptr<ResourceItem> & resourceItem)489 void ResourceAppend::AddRef(const shared_ptr<ResourceItem> &resourceItem)
490 {
491 string data(reinterpret_cast<const char *>(resourceItem->GetData()), resourceItem->GetDataLength());
492 ResType resType = resourceItem->GetResType();
493 if (resType == ResType::MEDIA) {
494 return;
495 }
496
497 if (resType == ResType::PROF) {
498 if (resourceItem->GetLimitKey() != "base" ||
499 FileEntry::FilePath(resourceItem->GetFilePath()).GetExtension() != ".json") {
500 return;
501 }
502 refs_.push_back(resourceItem);
503 return;
504 }
505
506 if (regex_match(data, regex(".*\\$.+:.*"))) {
507 refs_.push_back(resourceItem);
508 }
509 }
510
LoadResourceItemFromMem(const char buffer[],int32_t length)511 bool ResourceAppend::LoadResourceItemFromMem(const char buffer[], int32_t length)
512 {
513 int32_t offset = 0;
514 do {
515 // name
516 string nameStr = ParseString(buffer, length, offset);
517 // limit key
518 string limitKeyStr = ParseString(buffer, length, offset);
519 // file path
520 string filePathStr = ParseString(buffer, length, offset);
521 // ResType
522 int32_t type = ParseInt32(buffer, length, offset);
523 ResType resType = static_cast<ResType>(type);
524 // keyParam
525 int32_t keyParamSize = ParseInt32(buffer, length, offset);
526 vector<KeyParam> keyParams;
527 for (int i = 0; i < keyParamSize; i++) {
528 KeyParam keyParam;
529 keyParam.keyType = static_cast<KeyType>(ParseInt32(buffer, length, offset));
530 keyParam.value = ParseInt32(buffer, length, offset);
531 keyParams.push_back(keyParam);
532 }
533 // data
534 string data = ParseString(buffer, length, offset);
535 if (resType == ResType::RAW) {
536 FileEntry::FilePath outPath(packageParser_.GetOutput());
537 if (!ResourceUtil::CreateDirs(outPath.Append(data).GetParent().GetPath())) {
538 return false;
539 }
540
541 if (!ResourceUtil::FileExist(filePathStr)) {
542 continue;
543 }
544
545 if (!ResourceUtil::CopyFleInner(filePathStr, outPath.Append(data).GetPath())) {
546 return false;
547 }
548 continue;
549 }
550
551 shared_ptr<ResourceItem> resourceItem = make_shared<ResourceItem>(nameStr, keyParams, resType);
552 resourceItem->SetData(reinterpret_cast<const int8_t *>(data.c_str()), data.length());
553 resourceItem->SetLimitKey(limitKeyStr);
554 resourceItem->SetFilePath(filePathStr);
555 if (!Push(resourceItem)) {
556 return false;
557 }
558 } while (offset < length);
559 return true;
560 }
561
ParseString(const char buffer[],int32_t length,int32_t & offset) const562 string ResourceAppend::ParseString(const char buffer[], int32_t length, int32_t &offset) const
563 {
564 int32_t size = ParseInt32(buffer, length, offset);
565 if (size < 0 || offset + size > length) {
566 offset = length;
567 return "";
568 }
569
570 if (size == 0) {
571 return "";
572 }
573
574 string value(buffer + offset, size);
575 offset += size;
576 return value;
577 }
578
ParseInt32(const char buffer[],int32_t length,int32_t & offset) const579 int32_t ResourceAppend::ParseInt32(const char buffer[], int32_t length, int32_t &offset) const
580 {
581 if (offset + static_cast<int32_t>(sizeof(int32_t)) > length) {
582 offset = length;
583 return -1;
584 }
585
586 int32_t size = 0;
587 if (memcpy_s(&size, sizeof(int32_t), buffer + offset, sizeof(int32_t)) != EOK) {
588 offset = length;
589 return -1;
590 }
591 offset += sizeof(int32_t);
592 return size;
593 }
594
CheckModuleResourceItem(const shared_ptr<ResourceItem> & resourceItem,int32_t id)595 bool ResourceAppend::CheckModuleResourceItem(const shared_ptr<ResourceItem> &resourceItem, int32_t id)
596 {
597 const auto &result = itemsForModule_.find(id);
598 if (result == itemsForModule_.end()) {
599 itemsForModule_[id].push_back(resourceItem);
600 return true;
601 }
602
603 const auto &ret = find_if(result->second.begin(), result->second.end(), [resourceItem](auto iter) {
604 return resourceItem->GetLimitKey() == iter->GetLimitKey();
605 });
606
607 if (ret != result->second.end()) {
608 cerr << "Error: '" << resourceItem->GetName() << "' conflict, first declared.";
609 cerr << NEW_LINE_PATH << (*ret)->GetFilePath() << endl;
610 cerr << "but declared again." << NEW_LINE_PATH << resourceItem->GetFilePath() << endl;
611 return false;
612 }
613
614 itemsForModule_[id].push_back(resourceItem);
615 return true;
616 }
617
618 #ifdef __WIN32
LoadResourceItemWin(const string & filePath)619 bool ResourceAppend::LoadResourceItemWin(const string &filePath)
620 {
621 bool result = false;
622 HANDLE hReadFile = CreateFile(filePath.c_str(), GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_EXISTING,
623 FILE_ATTRIBUTE_READONLY | FILE_FLAG_RANDOM_ACCESS, nullptr);
624 if (hReadFile == INVALID_HANDLE_VALUE) {
625 cerr << "Error: "<< GetLastError() << NEW_LINE_PATH << filePath << endl;
626 return result;
627 }
628
629 DWORD fileSize = GetFileSize(hReadFile, nullptr);
630 HANDLE hFileMap = CreateFileMapping(hReadFile, nullptr, PAGE_READONLY, 0, fileSize, nullptr);
631 if (hFileMap == INVALID_HANDLE_VALUE) {
632 cerr << "Error: create file mapping " << GetLastError() << endl;
633 CloseHandle(hReadFile);
634 return result;
635 }
636
637 void* pBuffer = MapViewOfFile(hFileMap, FILE_MAP_READ, 0, 0, 0);
638 if (pBuffer == nullptr) {
639 cerr << "Error: map view of file " << GetLastError() << endl;
640 CloseHandle(hReadFile);
641 return result;
642 }
643
644 char* buffer = reinterpret_cast<char *>(pBuffer);
645 result = LoadResourceItemFromMem(buffer, fileSize);
646 UnmapViewOfFile(hFileMap);
647 CloseHandle(hReadFile);
648 return result;
649 }
650 #endif
651 }
652 }
653 }