From: "Robin Jarry" <rjarry@redhat.com>
To: "Andre Muezerie" <andremue@linux.microsoft.com>
Cc: <dev@dpdk.org>
Subject: Re: [PATCH v2 3/4] usertools: parse strings from PE images
Date: Tue, 15 Apr 2025 13:19:20 +0200 [thread overview]
Message-ID: <D9766V1IAZ3F.31NUXAK24Q8GI@redhat.com> (raw)
In-Reply-To: <1744680096-17683-4-git-send-email-andremue@linux.microsoft.com>
Hi Andre,
Thanks for the respin. Could you format the code using ruff/black before
sending a v3?
Andre Muezerie, Apr 15, 2025 at 03:21:
> Script usertools\dpdk-pmdinfo.py was enhanced to also be able to parse
> symbols from sections in PE images.
>
> Signed-off-by: Andre Muezerie <andremue@linux.microsoft.com>
> ---
> usertools/dpdk-pmdinfo.py | 55 ++++++++++++++++++++++++++++++++-------
> 1 file changed, 45 insertions(+), 10 deletions(-)
>
> diff --git a/usertools/dpdk-pmdinfo.py b/usertools/dpdk-pmdinfo.py
> index 9189a2fdbc..9e1ae5b534 100755
> --- a/usertools/dpdk-pmdinfo.py
> +++ b/usertools/dpdk-pmdinfo.py
> @@ -37,8 +37,14 @@
> from pathlib import Path
> from typing import Iterable, Iterator, List, Union
>
> -import elftools
> -from elftools.elf.elffile import ELFError, ELFFile
> +def is_windows():
> + return os.name == 'nt'
Defining a function before imports is awkward and probably overkill.
Can you replace all is_windows() calls with os.name == "nt"?
> +
> +if is_windows():
if os.name == "nt":
> + import pefile
> +else:
> + import elftools
> + from elftools.elf.elffile import ELFError, ELFFile
>
>
> # ----------------------------------------------------------------------------
> @@ -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():
if os.name == "nt":
> + 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)
> @@ -232,8 +243,8 @@ def elftools_version():
> return (0, 24)
> return (int(match[1]), int(match[2]))
>
> -
> -ELFTOOLS_VERSION = elftools_version()
> +if not is_windows():
if os.name != "nt":
> + ELFTOOLS_VERSION = elftools_version()
>
>
> def from_elftools(s: Union[bytes, str]) -> str:
> @@ -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():
if os.name == "nt":
> + yield from get_pe_strings(path, section, prefix)
> + else:
> + yield from get_elf_strings(path, section, prefix)
> +
> +
> # ----------------------------------------------------------------------------
> LDD_LIB_RE = re.compile(
> r"""
next prev parent reply other threads:[~2025-04-15 11:19 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-11 19:39 [PATCH 0/4] allow pmdinfo to be inserted and parsed using MSVC Andre Muezerie
2025-04-11 19:39 ` [PATCH 1/4] eal: add macro to embed information in binaries Andre Muezerie
2025-04-11 19:39 ` [PATCH 2/4] buildtools: use " Andre Muezerie
2025-04-11 20:07 ` Dmitry Kozlyuk
2025-04-11 19:39 ` [PATCH 3/4] usertools: parse strings from PE images Andre Muezerie
2025-04-11 20:09 ` Dmitry Kozlyuk
2025-04-11 19:39 ` [PATCH 4/4] drivers: use macro to embed information in binaries Andre Muezerie
2025-04-15 1:21 ` [PATCH v2 0/4] allow pmdinfo to be inserted and parsed using MSVC Andre Muezerie
2025-04-15 1:21 ` [PATCH v2 1/4] eal: add macro to embed information in binaries Andre Muezerie
2025-04-15 1:21 ` [PATCH v2 2/4] buildtools: use " Andre Muezerie
2025-04-15 7:44 ` Dmitry Kozlyuk
2025-04-15 14:36 ` Andre Muezerie
2025-04-15 1:21 ` [PATCH v2 3/4] usertools: parse strings from PE images Andre Muezerie
2025-04-15 11:19 ` Robin Jarry [this message]
2025-04-15 1:21 ` [PATCH v2 4/4] drivers: use macro to embed information in binaries Andre Muezerie
2025-04-16 0:05 ` Stephen Hemminger
2025-04-17 17:10 ` Andre Muezerie
2025-04-15 22:31 ` [PATCH v3 0/4] allow pmdinfo to be inserted and parsed using MSVC Andre Muezerie
2025-04-15 22:31 ` [PATCH v3 1/4] eal: add macro to embed information in binaries Andre Muezerie
2025-04-15 22:31 ` [PATCH v3 2/4] buildtools: use " Andre Muezerie
2025-04-15 22:31 ` [PATCH v3 3/4] usertools: parse strings from PE images Andre Muezerie
2025-04-15 22:31 ` [PATCH v3 4/4] drivers: use macro to embed information in binaries Andre Muezerie
2025-04-16 21:44 ` [PATCH v4 0/4] allow pmdinfo to be inserted and parsed using MSVC Andre Muezerie
2025-04-16 21:44 ` [PATCH v4 1/4] eal: add macro to embed information in binaries Andre Muezerie
2025-04-16 21:44 ` [PATCH v4 2/4] buildtools: use " Andre Muezerie
2025-04-16 21:44 ` [PATCH v4 3/4] usertools: parse strings from PE images Andre Muezerie
2025-04-16 21:44 ` [PATCH v4 4/4] drivers: use macro to embed information in binaries Andre Muezerie
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=D9766V1IAZ3F.31NUXAK24Q8GI@redhat.com \
--to=rjarry@redhat.com \
--cc=andremue@linux.microsoft.com \
--cc=dev@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).