Script usertools\dpdk-pmdinfo.py was enhanced to also be able to parse symbols from sections in PE images.
Signed-off-by: Andre Muezerie <andre...@linux.microsoft.com> --- usertools/dpdk-pmdinfo.py | 47 ++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py index 9189a2fdbc..77789c979c 100755 --- a/usertools/dpdk-pmdinfo.py +++ b/usertools/dpdk-pmdinfo.py @@ -40,6 +40,12 @@ import elftools from elftools.elf.elffile import ELFError, ELFFile +def is_windows(): + return os.name == 'nt' + +if is_windows(): + import pefile + # ---------------------------------------------------------------------------- def main() -> int: # pylint: disable=missing-docstring @@ -114,18 +120,23 @@ def parse_pmdinfo(paths: Iterable[Path], search_plugins: bool) -> List[dict]: A list of DPDK drivers info dictionaries. """ binaries = set(paths) - for p in paths: - binaries.update(get_needed_libs(p)) - if search_plugins: - # cast to list to avoid errors with update while iterating - binaries.update(list(get_plugin_libs(binaries))) + + if is_windows(): + section_name = ".rdata" + else: + section_name = ".rodata" + for p in paths: + binaries.update(get_needed_libs(p)) + if search_plugins: + # cast to list to avoid errors with update while iterating + binaries.update(list(get_plugin_libs(binaries))) drivers = [] for b in binaries: logging.debug("analyzing %s", b) try: - for s in get_elf_strings(b, ".rodata", "PMD_INFO_STRING="): + for s in get_section_strings(b, section_name, "PMD_INFO_STRING="): try: info = json.loads(s) scrub_pci_ids(info) @@ -269,6 +280,30 @@ def get_elf_strings(path: Path, section: str, prefix: str) -> Iterator[str]: yield from find_strings(sec.data(), prefix) +# ---------------------------------------------------------------------------- +def get_pe_strings(path: Path, section: str, prefix: str) -> Iterator[str]: + """ + Extract strings from a named PE section in a file. + """ + pe = pefile.PE(path) + for sec in pe.sections: + section_name = sec.Name.decode().strip('\x00') + if section_name != section: + continue + yield from find_strings(sec.get_data(), prefix) + + +# ---------------------------------------------------------------------------- +def get_section_strings(path: Path, section: str, prefix: str) -> Iterator[str]: + """ + Extract strings from a named section in an ELF or PE file. + """ + if is_windows(): + yield from get_pe_strings(path, section, prefix) + else: + yield from get_elf_strings(path, section, prefix) + + # ---------------------------------------------------------------------------- LDD_LIB_RE = re.compile( r""" -- 2.49.0.vfs.0.0