| 4268 | } |
| 4269 | |
| 4270 | UINT8 FfsEngine::findGuidPattern(const QModelIndex & index, const QByteArray & guidPattern, const UINT8 mode) |
| 4271 | { |
| 4272 | if (guidPattern.isEmpty()) |
| 4273 | return ERR_INVALID_PARAMETER; |
| 4274 | |
| 4275 | if (!index.isValid()) |
| 4276 | return ERR_SUCCESS; |
| 4277 | |
| 4278 | bool hasChildren = (model->rowCount(index) > 0); |
| 4279 | for (int i = 0; i < model->rowCount(index); i++) { |
| 4280 | findGuidPattern(index.child(i, index.column()), guidPattern, mode); |
| 4281 | } |
| 4282 | |
| 4283 | QByteArray data; |
| 4284 | if (hasChildren) { |
| 4285 | if (mode != SEARCH_MODE_BODY) |
| 4286 | data = model->header(index); |
| 4287 | } |
| 4288 | else { |
| 4289 | if (mode == SEARCH_MODE_HEADER) |
| 4290 | data.append(model->header(index)); |
| 4291 | else if (mode == SEARCH_MODE_BODY) |
| 4292 | data.append(model->body(index)); |
| 4293 | else |
| 4294 | data.append(model->header(index)).append(model->body(index)); |
| 4295 | } |
| 4296 | |
| 4297 | QString hexBody = QString(data.toHex()); |
| 4298 | QList<QByteArray> list = guidPattern.split('-'); |
| 4299 | if (list.count() != 5) |
| 4300 | return ERR_INVALID_PARAMETER; |
| 4301 | |
| 4302 | QByteArray hexPattern; |
| 4303 | // Reverse first GUID block |
| 4304 | hexPattern.append(list.at(0).mid(6, 2)); |
| 4305 | hexPattern.append(list.at(0).mid(4, 2)); |
| 4306 | hexPattern.append(list.at(0).mid(2, 2)); |
| 4307 | hexPattern.append(list.at(0).mid(0, 2)); |
| 4308 | // Reverse second GUID block |
| 4309 | hexPattern.append(list.at(1).mid(2, 2)); |
| 4310 | hexPattern.append(list.at(1).mid(0, 2)); |
| 4311 | // Reverse third GUID block |
| 4312 | hexPattern.append(list.at(2).mid(2, 2)); |
| 4313 | hexPattern.append(list.at(2).mid(0, 2)); |
| 4314 | // Append fourth and fifth GUID blocks as is |
| 4315 | hexPattern.append(list.at(3)).append(list.at(4)); |
| 4316 | |
| 4317 | // Check for "all substrings" pattern |
| 4318 | if (hexPattern.count('.') == hexPattern.length()) |
| 4319 | return ERR_SUCCESS; |
| 4320 | |
| 4321 | QRegExp regexp = QRegExp(QString(hexPattern), Qt::CaseInsensitive); |
| 4322 | INT32 offset = regexp.indexIn(hexBody); |
| 4323 | while (offset >= 0) { |
| 4324 | if (offset % 2 == 0) { |
| 4325 | msg(tr("GUID pattern \"%1\" found as \"%2\" in %3 at %4-offset %5h") |
| 4326 | .arg(QString(guidPattern)) |
| 4327 | .arg(hexBody.mid(offset, hexPattern.length()).toUpper()) |