| 122 | } |
| 123 | |
| 124 | UINT8 UEFIPatch::patchFromArg(const QString & path, const QString & patch, const QString & outputPath) |
| 125 | { |
| 126 | QFileInfo fileInfo = QFileInfo(path); |
| 127 | |
| 128 | if (!fileInfo.exists()) |
| 129 | return ERR_FILE_OPEN; |
| 130 | |
| 131 | QFile inputFile; |
| 132 | inputFile.setFileName(path); |
| 133 | |
| 134 | if (!inputFile.open(QFile::ReadOnly)) |
| 135 | return ERR_FILE_READ; |
| 136 | |
| 137 | QByteArray buffer = inputFile.readAll(); |
| 138 | inputFile.close(); |
| 139 | |
| 140 | UINT8 result = ffsEngine->parseImageFile(buffer); |
| 141 | if (result) |
| 142 | return result; |
| 143 | |
| 144 | if (patch != NULL && !patch.isEmpty()) { |
| 145 | QByteArray line = patch.toUtf8(); |
| 146 | |
| 147 | QList<QByteArray> list = line.split(' '); |
| 148 | if (list.count() < 3) |
| 149 | return ERR_INVALID_PARAMETER; |
| 150 | |
| 151 | QUuid uuid = QUuid(list.at(0)); |
| 152 | QByteArray guid = QByteArray::fromRawData((const char*)&uuid.data1, sizeof(EFI_GUID)); |
| 153 | bool converted; |
| 154 | UINT8 sectionType = (UINT8)list.at(1).toUShort(&converted, 16); |
| 155 | if (!converted) |
| 156 | return ERR_INVALID_PARAMETER; |
| 157 | |
| 158 | QVector<PatchData> patches; |
| 159 | |
| 160 | for (int i = 2; i < list.count(); i++) { |
| 161 | QList<QByteArray> patchList = list.at(i).split(':'); |
| 162 | PatchData patch; |
| 163 | patch.type = *(UINT8*)patchList.at(0).constData(); |
| 164 | if (patch.type == PATCH_TYPE_PATTERN) { |
| 165 | patch.offset = 0xFFFFFFFF; |
| 166 | patch.hexFindPattern = patchList.at(1); |
| 167 | patch.hexReplacePattern = patchList.at(2); |
| 168 | patches.append(patch); |
| 169 | } |
| 170 | else if (patch.type == PATCH_TYPE_OFFSET) { |
| 171 | patch.offset = patchList.at(1).toUInt(NULL, 16); |
| 172 | patch.hexReplacePattern = patchList.at(2); |
| 173 | patches.append(patch); |
| 174 | } |
| 175 | else { |
| 176 | // Ignore unknown patch type |
| 177 | continue; |
| 178 | } |
| 179 | } |
| 180 | result = patchFile(model->index(0, 0), guid, sectionType, patches); |
| 181 | if (result && result != ERR_NOTHING_TO_PATCH) |
no test coverage detected