MCPcopy Create free account
hub / github.com/LongSoft/UEFITool / patchFromFile

Method patchFromFile

UEFIPatch/uefipatch.cpp:28–122  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26}
27
28UINT8 UEFIPatch::patchFromFile(const QString & path, const QString & patches, const QString & outputPath)
29{
30 QFileInfo patchInfo = QFileInfo(patches);
31
32 if (!patchInfo.exists())
33 return ERR_INVALID_FILE;
34
35 QFile file;
36 file.setFileName(patches);
37
38 if (!file.open(QFile::ReadOnly | QFile::Text))
39 return ERR_INVALID_FILE;
40
41 QFileInfo fileInfo = QFileInfo(path);
42
43 if (!fileInfo.exists())
44 return ERR_FILE_OPEN;
45
46 QFile inputFile;
47 inputFile.setFileName(path);
48
49 if (!inputFile.open(QFile::ReadOnly))
50 return ERR_FILE_READ;
51
52 QByteArray buffer = inputFile.readAll();
53 inputFile.close();
54
55 UINT8 result = ffsEngine->parseImageFile(buffer);
56 if (result)
57 return result;
58
59 UINT8 counter = 0;
60 while (!file.atEnd()) {
61 QByteArray line = file.readLine().trimmed();
62 // Use sharp sign as commentary
63 if (line.count() == 0 || line[0] == '#')
64 continue;
65
66 QList<QByteArray> list = line.split(' ');
67 if (list.count() < 3)
68 continue;
69
70 QUuid uuid = QUuid(list.at(0));
71 QByteArray guid = QByteArray::fromRawData((const char*)&uuid.data1, sizeof(EFI_GUID));
72 bool converted;
73 UINT8 sectionType = (UINT8)list.at(1).toUShort(&converted, 16);
74 if (!converted)
75 return ERR_INVALID_PARAMETER;
76
77 QVector<PatchData> patches;
78
79 for (int i = 2; i < list.count(); i++) {
80 QList<QByteArray> patchList = list.at(i).split(':');
81 PatchData patch;
82 patch.type = *(UINT8*)patchList.at(0).constData();
83 if (patch.type == PATCH_TYPE_PATTERN) {
84 patch.offset = 0xFFFFFFFF;
85 patch.hexFindPattern = patchList.at(1);

Callers 1

mainFunction · 0.80

Calls 3

parseImageFileMethod · 0.80
reconstructImageFileMethod · 0.80
indexMethod · 0.45

Tested by

no test coverage detected