MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / AddCOFFSymbol

Method AddCOFFSymbol

view/pe/coffview.cpp:1465–1552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1463
1464
1465void COFFView::AddCOFFSymbol(BNSymbolType type, const string& dll, const string& name, uint64_t addr,
1466 BNSymbolBinding binding, uint64_t ordinal, TypeLibrary* lib)
1467{
1468 // If name is empty, symbol is not valid
1469 if (name.size() == 0)
1470 return;
1471
1472 // Ensure symbol is within the executable
1473 NameSpace nameSpace = GetInternalNameSpace();
1474 if (type == ExternalSymbol)
1475 {
1476 nameSpace = GetExternalNameSpace();
1477 }
1478 else if (!IsValidOffset(m_imageBase + addr))
1479 {
1480 return;
1481 }
1482 else if (dll.size())
1483 {
1484 nameSpace = NameSpace(dll);
1485 }
1486
1487 if (!(type == ExternalSymbol || type == ImportedDataSymbol || type == ImportedFunctionSymbol))
1488 {
1489 // Ensure symbol is within the executable
1490 bool ok = false;
1491 for (auto& i : m_sections)
1492 {
1493 if ((addr >= i.virtualAddress) && (addr < (i.virtualAddress + i.virtualSize)))
1494 {
1495 ok = true;
1496 break;
1497 }
1498 }
1499 if (!ok)
1500 {
1501 m_logger->LogDebug("COFF: %s symbol %s at %#" PRIx64 " is not in any section", __func__, name.c_str(), addr);
1502 return;
1503 }
1504 }
1505
1506 Ref<Type> symbolTypeRef;
1507 auto address = type == ExternalSymbol ? addr : m_imageBase + addr;
1508 if (lib && ((type == ImportAddressSymbol) || (type == ImportedDataSymbol)))
1509 {
1510 QualifiedName n(name);
1511 Ref<TypeLibrary> appliedLib = lib;
1512 symbolTypeRef = ImportTypeLibraryObject(appliedLib, n);
1513 if (symbolTypeRef && type != ExternalSymbol)
1514 {
1515 m_logger->LogDebug("COFF: type library '%s' found hit for '%s'", lib->GetGuid().c_str(), name.c_str());
1516 RecordImportedObjectLibrary(GetDefaultPlatform(), m_imageBase + addr, appliedLib, n);
1517 }
1518 }
1519
1520 // If name does not start with alphabetic character or symbol, prepend an underscore
1521 string rawName = name;
1522 if (!(((name[0] >= 'A') && (name[0] <= 'Z')) ||

Callers

nothing calls this directly

Calls 10

DemangleGenericFunction · 0.85
LogDebugMethod · 0.80
c_strMethod · 0.80
Get<bool>Method · 0.80
GetStringAfterNameMethod · 0.80
GetFunctionByNameMethod · 0.80
NameSpaceClass · 0.50
sizeMethod · 0.45
GetGuidMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected