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

Method findHexPattern

ffsengine.cpp:4220–4268  ·  view source on GitHub ↗

Search routines

Source from the content-addressed store, hash-verified

4218
4219// Search routines
4220UINT8 FfsEngine::findHexPattern(const QModelIndex & index, const QByteArray & hexPattern, const UINT8 mode)
4221{
4222 if (!index.isValid())
4223 return ERR_SUCCESS;
4224
4225 if (hexPattern.isEmpty())
4226 return ERR_INVALID_PARAMETER;
4227
4228 // Check for "all substrings" pattern
4229 if (hexPattern.count('.') == hexPattern.length())
4230 return ERR_SUCCESS;
4231
4232 bool hasChildren = (model->rowCount(index) > 0);
4233 for (int i = 0; i < model->rowCount(index); i++) {
4234 findHexPattern(index.child(i, index.column()), hexPattern, mode);
4235 }
4236
4237 QByteArray data;
4238 if (hasChildren) {
4239 if (mode != SEARCH_MODE_BODY)
4240 data = model->header(index);
4241 }
4242 else {
4243 if (mode == SEARCH_MODE_HEADER)
4244 data.append(model->header(index));
4245 else if (mode == SEARCH_MODE_BODY)
4246 data.append(model->body(index));
4247 else
4248 data.append(model->header(index)).append(model->body(index));
4249 }
4250
4251 QString hexBody = QString(data.toHex());
4252 QRegExp regexp = QRegExp(QString(hexPattern), Qt::CaseInsensitive);
4253 INT32 offset = regexp.indexIn(hexBody);
4254 while (offset >= 0) {
4255 if (offset % 2 == 0) {
4256 msg(tr("Hex pattern \"%1\" found as \"%2\" in %3 at %4-offset %5h")
4257 .arg(QString(hexPattern))
4258 .arg(hexBody.mid(offset, hexPattern.length()).toUpper())
4259 .arg(model->name(index))
4260 .arg(mode == SEARCH_MODE_BODY ? tr("body") : tr("header"))
4261 .hexarg(offset / 2),
4262 index);
4263 }
4264 offset = regexp.indexIn(hexBody, offset + 1);
4265 }
4266
4267 return ERR_SUCCESS;
4268}
4269
4270UINT8 FfsEngine::findGuidPattern(const QModelIndex & index, const QByteArray & guidPattern, const UINT8 mode)
4271{

Callers 1

searchMethod · 0.80

Calls 5

rowCountMethod · 0.80
childMethod · 0.80
headerMethod · 0.45
bodyMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected