aboutcode-org / elf-inspector

A library to inspect ELF binary files
0 stars 0 forks source link

Ignore "fake" symbols #7

Open pombredanne opened 3 months ago

pombredanne commented 3 months ago

These are builtin and related: This is a small function worked out in go-inspector:

def is_fake_path(path):
    """
    Return True if a ``path`` string is for a fake path injected by the linker or compiler in the binary.
    See:
    https://github.com/smoofra/elfutils/blob/53b6f190892c738f28840e7481a09c7ee19b6720/src/srcfiles.cxx#L160

    For example:
    >>> is_fake_symbol("<built-in>")
    True
    >>> is_fake_symbol("foo/bar/<builtin>")
    True
    >>> is_fake_symbol("<artificial>")
    True
    >>> is_fake_symbol("/artificial/asdasdas/adsd")
    False
    >>> is_fake_symbol("<foo-bar>")
    False
    >>> is_fake_symbol("/sdfsdfsdf<unknown>/zffd")
    Trye

    """
    fake_paths = (
        #gcc intrinsics
        "<built-in>", "<builtin>",
        # seen in Go and C++
        "<artificial>",
        "<unknown>",
    )
    return isinstance(path, str) and any(fs in path for fs in fake_paths)