| 1463 | |
| 1464 | |
| 1465 | void 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')) || |
nothing calls this directly
no test coverage detected