MCPcopy Create free account
hub / github.com/avast/retdec / addPattern

Method addPattern

src/patterngen/pattern_extractor/pattern_extractor.cpp:446–484  ·  view source on GitHub ↗

* 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 */

Source from the content-addressed store, hash-verified

444 * @param size size of symbol
445 */
446void 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.

Callers

nothing calls this directly

Calls 15

isLittleEndianMethod · 0.80
setArchitectureNameMethod · 0.80
setSourcePathMethod · 0.80
setRuleNameMethod · 0.80
getSectionOffsetMethod · 0.80
getMaskMethod · 0.80
addReferenceMethod · 0.80
getBytesMethod · 0.45
getWordLengthMethod · 0.45
setNameMethod · 0.45
getPathToFileMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected