* Creates and stores one pattern from given symbol information. * * @param section pointer to symbol associated section * @param name name of the symbol * @param offset symbol offset from start of the section * @param size size of symbol */
| 444 | * @param size size of symbol |
| 445 | */ |
| 446 | void PatternExtractor::addPattern( |
| 447 | const Section *section, |
| 448 | const std::string &name, |
| 449 | const unsigned long long offset, |
| 450 | const unsigned long long size) |
| 451 | { |
| 452 | std::vector<unsigned char> symbolData; |
| 453 | if (size && section->getBytes(symbolData, offset, size)) |
| 454 | { |
| 455 | SymbolPattern pattern(inputFile->isLittleEndian(), |
| 456 | inputFile->getWordLength()); |
| 457 | pattern.setName(name); |
| 458 | pattern.setArchitectureName(getArchAsString()); |
| 459 | pattern.setSourcePath(inputFile->getPathToFile()); |
| 460 | pattern.setRuleName(groupName + "_" + std::to_string(patterns.size())); |
| 461 | |
| 462 | // Add relocations. |
| 463 | for (const auto *relTab : inputFile->getRelocationTables()) { |
| 464 | for (std::size_t i = 0; i < relTab->getNumberOfRelocations(); ++i) { |
| 465 | // Get relocation's section link and compare with section index. |
| 466 | unsigned long long sectionLink; |
| 467 | auto reloc = relTab->getRelocation(i); |
| 468 | if (!reloc || !reloc->getLinkToSection(sectionLink) |
| 469 | || sectionLink != section->getIndex()) { |
| 470 | continue; |
| 471 | } |
| 472 | |
| 473 | auto relocOffset = reloc->getSectionOffset(); |
| 474 | if (relocOffset >= offset && relocOffset < offset + size) { |
| 475 | const auto mask = reloc->getMask(); |
| 476 | pattern.addReference(reloc->getName(), |
| 477 | relocOffset - offset, mask); |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | pattern.loadData(std::move(symbolData)); |
| 482 | patterns.push_back(pattern); |
| 483 | } |
| 484 | } |
| 485 | |
| 486 | /** |
| 487 | * Get architecture info as string. |
nothing calls this directly
no test coverage detected