pyxdia 0.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ Copyright 2024 Matt Borgerson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
4
+ this software and associated documentation files (the “Software”), to deal in
5
+ the Software without restriction, including without limitation the rights to
6
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
7
+ of the Software, and to permit persons to whom the Software is furnished to do
8
+ so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
20
+
21
+ --------------------------------------------------------------------------------
22
+ Dependencies
23
+ --------------------------------------------------------------------------------
24
+
25
+ pyxdia releases include binaries which are governed under separate licenses.
26
+ See respective *.LICENSE.txt files in release package for more details.
@@ -0,0 +1,6 @@
1
+ graft pyxdia
2
+ include LICENSE.txt
3
+ graft tests
4
+ global-exclude *.so
5
+ global-exclude *.gitignore
6
+ global-exclude *.pyc
pyxdia-0.0.0/PKG-INFO ADDED
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyxdia
3
+ Version: 0.0.0
4
+ Summary: pyxdia
5
+ Classifier: Programming Language :: Python
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3 :: Only
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE.txt
14
+ Provides-Extra: docs
15
+ Requires-Dist: furo; extra == "docs"
16
+ Requires-Dist: ipython; extra == "docs"
17
+ Requires-Dist: myst-parser; extra == "docs"
18
+ Requires-Dist: sphinx; extra == "docs"
19
+ Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
20
+
21
+ pyxdia
22
+ ======
23
+ pyxdia is a Python library for extracting useful program information from a [PDB file](https://en.wikipedia.org/wiki/Program_database). pyxdia runs on Windows, macOS, Linux, and other platforms.
24
+
25
+ ## Dependencies
26
+
27
+ pyxdia depends on [xdia](https://github.com/mborgerson/xdia), a native Windows executable. For cross-platform support, a thin loader and compatibility layer (xdialdr) and emulator ([Blink](https://github.com/jart/blink)) are used to run xdia. These dependencies are included in wheels for convenient installation, and in source distributions will be downloaded at installation time.
28
+
29
+ ## License
30
+
31
+ pyxdia source is released under MIT license. pyxdia wheels include binaries that are released under individual licenses, with license text available within the wheel.
pyxdia-0.0.0/README.md ADDED
@@ -0,0 +1,11 @@
1
+ pyxdia
2
+ ======
3
+ pyxdia is a Python library for extracting useful program information from a [PDB file](https://en.wikipedia.org/wiki/Program_database). pyxdia runs on Windows, macOS, Linux, and other platforms.
4
+
5
+ ## Dependencies
6
+
7
+ pyxdia depends on [xdia](https://github.com/mborgerson/xdia), a native Windows executable. For cross-platform support, a thin loader and compatibility layer (xdialdr) and emulator ([Blink](https://github.com/jart/blink)) are used to run xdia. These dependencies are included in wheels for convenient installation, and in source distributions will be downloaded at installation time.
8
+
9
+ ## License
10
+
11
+ pyxdia source is released under MIT license. pyxdia wheels include binaries that are released under individual licenses, with license text available within the wheel.
@@ -0,0 +1,13 @@
1
+ [build-system]
2
+ requires = ["setuptools", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [tool.black]
6
+ line-length = 120
7
+ target-version = ['py310']
8
+
9
+ [tool.ruff]
10
+ line-length = 120
11
+ extend-ignore = [
12
+ "E402", # Bottom imports
13
+ ]
@@ -0,0 +1,3 @@
1
+ from .pdb import PDB
2
+
3
+ __all__ = ["PDB"]
@@ -0,0 +1,16 @@
1
+ import argparse
2
+
3
+ from .pdb import PDB
4
+
5
+
6
+ def main():
7
+ ap = argparse.ArgumentParser("pyxdia")
8
+ ap.add_argument("pdb", help="Path to PDB file")
9
+ args = ap.parse_args()
10
+
11
+ pdb = PDB(args.pdb)
12
+ pdb.pp()
13
+
14
+
15
+ if __name__ == "__main__":
16
+ main()
@@ -0,0 +1 @@
1
+ __version__ = "0.0.0"
@@ -0,0 +1,62 @@
1
+ import json
2
+ import os
3
+ import pathlib
4
+ import platform
5
+ import subprocess
6
+ from pprint import pprint
7
+
8
+
9
+ ROOT_PATH = pathlib.Path(__file__).parent.absolute()
10
+ XDIA_EXE_PATH = ROOT_PATH / "bin" / "xdia.exe"
11
+ MSDIA_DLL_PATH = ROOT_PATH / "bin" / "msdia140.dll"
12
+ XDIALDR_PATH = ROOT_PATH / "bin" / "xdialdr"
13
+ BLINK_PATH = ROOT_PATH / "bin" / "blink"
14
+
15
+
16
+ class PDB:
17
+ """
18
+ This class interfaces with the xdia utility to extract useful program information from a Program Database (PDB) file.
19
+ """
20
+
21
+ _pdb_data: dict
22
+
23
+ def __init__(self, pdb_path: str | pathlib.Path):
24
+ self._load_pdb(pdb_path)
25
+
26
+ def _load_pdb(self, pdb_path: str | pathlib.Path) -> None:
27
+ # Ensure pdb_path is a pathlib.Path
28
+ if not isinstance(pdb_path, pathlib.Path):
29
+ pdb_path = pathlib.Path(pdb_path).absolute()
30
+
31
+ env = {"MSDIA_PATH": str(MSDIA_DLL_PATH), "XDIA_PATH": str(XDIA_EXE_PATH)}
32
+
33
+ if platform.system() == "Windows":
34
+ cmd = [XDIA_EXE_PATH]
35
+ else:
36
+ blink_required = (platform.system() != "Linux") or (platform.machine() != "x86_64")
37
+ if blink_required:
38
+ # XXX: Work around blink VFS mount issue
39
+ env["BLINK_PREFIX"] = "/tmp"
40
+ env["MSDIA_PATH"] = "/SystemRoot" + env["MSDIA_PATH"]
41
+ env["XDIA_PATH"] = "/SystemRoot" + env["XDIA_PATH"]
42
+ pdb_path = pathlib.Path("/SystemRoot") / pdb_path.relative_to("/")
43
+ xdialdr_path = pathlib.Path("/SystemRoot") / XDIALDR_PATH.relative_to("/")
44
+ cmd = [BLINK_PATH, xdialdr_path]
45
+ else:
46
+ cmd = [XDIALDR_PATH]
47
+
48
+ diadump_s = subprocess.check_output(cmd + [str(pdb_path)], encoding="utf-8", env=env)
49
+ self._pdb_data = json.loads(diadump_s)
50
+
51
+ def pp(self) -> None:
52
+ """
53
+ Pretty-print all available info.
54
+ """
55
+ pprint(self._pdb_data, indent=2)
56
+
57
+ @property
58
+ def globals(self) -> list[dict[str, int | str]]:
59
+ """
60
+ List all globals.
61
+ """
62
+ return self._pdb_data["globals"]
@@ -0,0 +1,31 @@
1
+ Metadata-Version: 2.1
2
+ Name: pyxdia
3
+ Version: 0.0.0
4
+ Summary: pyxdia
5
+ Classifier: Programming Language :: Python
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: Programming Language :: Python :: 3 :: Only
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Python: >=3.10
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE.txt
14
+ Provides-Extra: docs
15
+ Requires-Dist: furo; extra == "docs"
16
+ Requires-Dist: ipython; extra == "docs"
17
+ Requires-Dist: myst-parser; extra == "docs"
18
+ Requires-Dist: sphinx; extra == "docs"
19
+ Requires-Dist: sphinx-autodoc-typehints; extra == "docs"
20
+
21
+ pyxdia
22
+ ======
23
+ pyxdia is a Python library for extracting useful program information from a [PDB file](https://en.wikipedia.org/wiki/Program_database). pyxdia runs on Windows, macOS, Linux, and other platforms.
24
+
25
+ ## Dependencies
26
+
27
+ pyxdia depends on [xdia](https://github.com/mborgerson/xdia), a native Windows executable. For cross-platform support, a thin loader and compatibility layer (xdialdr) and emulator ([Blink](https://github.com/jart/blink)) are used to run xdia. These dependencies are included in wheels for convenient installation, and in source distributions will be downloaded at installation time.
28
+
29
+ ## License
30
+
31
+ pyxdia source is released under MIT license. pyxdia wheels include binaries that are released under individual licenses, with license text available within the wheel.
@@ -0,0 +1,17 @@
1
+ LICENSE.txt
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ setup.cfg
6
+ setup.py
7
+ pyxdia/__init__.py
8
+ pyxdia/__main__.py
9
+ pyxdia/__version__.py
10
+ pyxdia/pdb.py
11
+ pyxdia.egg-info/PKG-INFO
12
+ pyxdia.egg-info/SOURCES.txt
13
+ pyxdia.egg-info/dependency_links.txt
14
+ pyxdia.egg-info/requires.txt
15
+ pyxdia.egg-info/top_level.txt
16
+ tests/test_cli.py
17
+ tests/test_pdb.py
@@ -0,0 +1,7 @@
1
+
2
+ [docs]
3
+ furo
4
+ ipython
5
+ myst-parser
6
+ sphinx
7
+ sphinx-autodoc-typehints
@@ -0,0 +1 @@
1
+ pyxdia
pyxdia-0.0.0/setup.cfg ADDED
@@ -0,0 +1,32 @@
1
+ [metadata]
2
+ name = pyxdia
3
+ version = attr: pyxdia.__version__.__version__
4
+ description = pyxdia
5
+ long_description = file: README.md
6
+ long_description_content_type = text/markdown
7
+ license_files = LICENSE.txt
8
+ classifiers =
9
+ Programming Language :: Python
10
+ Programming Language :: Python :: 3
11
+ Programming Language :: Python :: 3 :: Only
12
+ Programming Language :: Python :: 3.10
13
+ Programming Language :: Python :: 3.11
14
+ Programming Language :: Python :: 3.12
15
+
16
+ [options]
17
+ packages =
18
+ pyxdia
19
+ python_requires = >=3.10
20
+
21
+ [options.extras_require]
22
+ docs =
23
+ furo
24
+ ipython
25
+ myst-parser
26
+ sphinx
27
+ sphinx-autodoc-typehints
28
+
29
+ [egg_info]
30
+ tag_build =
31
+ tag_date = 0
32
+
pyxdia-0.0.0/setup.py ADDED
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env python3
2
+
3
+ import gzip
4
+ import shutil
5
+ import platform
6
+ import os
7
+ import stat
8
+ import tarfile
9
+ from zipfile import ZipFile
10
+ from urllib.request import urlretrieve, urlcleanup
11
+ from pathlib import Path
12
+ from setuptools import setup, Command
13
+ from setuptools.command.build import build as _build
14
+ from setuptools.command.build import SubCommand
15
+ from setuptools.command.install import install as _install
16
+ from setuptools.command.develop import develop as _develop
17
+ from wheel.bdist_wheel import bdist_wheel
18
+
19
+
20
+ root_dir = Path(__file__).parent.absolute()
21
+ pyxdia_dir = root_dir / "pyxdia"
22
+
23
+
24
+ with open(pyxdia_dir / "__version__.py") as f:
25
+ ns = {}
26
+ exec(f.read(), ns)
27
+ version = ns["__version__"]
28
+
29
+
30
+ class CustomBdistWheel(bdist_wheel):
31
+ """
32
+ Overrides bdist_wheel to generate platform tag marking the wheel as
33
+ platform specific.
34
+ """
35
+
36
+ @staticmethod
37
+ def _get_darwin_tag():
38
+ # FIXME: This is based only on blink requirement. Check the binary to find the
39
+ # actual requirement. This works for 1.1.0 release.
40
+ return "macosx_" + ("14" if platform.machine() == "arm64" else "11") + "_0"
41
+
42
+ def get_tag(self):
43
+ plat_to_tag = {"Windows": "win", "Linux": "linux", "Darwin": self._get_darwin_tag()}
44
+ plat = plat_to_tag.get(platform.system(), None)
45
+ assert plat is not None, "FIXME: Unhandled platform tag"
46
+ return ("py3", "none", f"{plat}_{platform.machine().lower()}")
47
+
48
+
49
+ class CheckXdiaInstallation(Command):
50
+ """
51
+ Check for xdia, xdialdr, blink installation. For installations from
52
+ source, download and install necessary components if they are not already
53
+ installed.
54
+ """
55
+
56
+ description = 'Check xdia installation'
57
+ user_options = []
58
+ editable_mode: bool = False
59
+
60
+ def initialize_options(self):
61
+ pass
62
+
63
+ def finalize_options(self):
64
+ if self.editable_mode:
65
+ prefix = pyxdia_dir
66
+ else:
67
+ build_py = self.get_finalized_command('build_py')
68
+ prefix = Path(build_py.build_lib) / "pyxdia"
69
+
70
+ self._bin_dir = prefix / "bin"
71
+ self._xdia_exe_path = self._bin_dir / "xdia.exe"
72
+ self._xdialdr_path = self._bin_dir / "xdialdr"
73
+ self._msdia140_dll_path = self._bin_dir / "msdia140.dll"
74
+ self._blink_path = self._bin_dir / "blink"
75
+
76
+ @staticmethod
77
+ def _download_file(url, filename = "") -> str:
78
+ print(f'Downloading {url}...')
79
+ if not filename:
80
+ filename = url.split("/")[-1]
81
+ urlretrieve(url, filename)
82
+ urlcleanup()
83
+ return filename
84
+
85
+ @staticmethod
86
+ def _mark_file_executable(path):
87
+ os.chmod(path, 0o755)
88
+
89
+ def _get_xdia_install_list(self) -> list[str]:
90
+ files = [self._xdia_exe_path, self._msdia140_dll_path]
91
+ if platform.system() != "Windows":
92
+ files.append(self._xdialdr_path)
93
+ return files
94
+
95
+ def _is_xdia_installed(self) -> bool:
96
+ return all(file.exists() for file in self._get_xdia_install_list())
97
+
98
+ def _install_xdia(self):
99
+ if ".dev" in version:
100
+ # FIXME: On Windows, run cmake to build xdia
101
+ raise RuntimeError("xdia not available for dev version. Please build and install xdia manually.")
102
+
103
+ xdia_release_url = "https://github.com/mborgerson/xdia/releases/download"
104
+
105
+ # Install xdia
106
+ path = self._download_file(f"{xdia_release_url}/v{version}/xdia.zip")
107
+ with ZipFile(path) as z:
108
+ z.extractall(self._bin_dir)
109
+
110
+ # Install xdialdr, if required
111
+ if platform.system() != "Windows":
112
+ path = self._download_file(f"{xdia_release_url}/v{version}/xdialdr.tar.xz")
113
+ with tarfile.open(path, "r:xz") as tar:
114
+ tar.extractall(path=self._bin_dir)
115
+
116
+ @staticmethod
117
+ def _is_blink_required() -> bool:
118
+ return platform.system() != "Windows" and (platform.system() != "Linux" or platform.machine() != "x86_64")
119
+
120
+ def _get_blink_install_list(self) -> list[str]:
121
+ return [self._blink_path]
122
+
123
+ def _is_blink_installed(self) -> bool:
124
+ return all(file.exists() for file in self._get_blink_install_list())
125
+
126
+ @staticmethod
127
+ def gunzip(src, dst):
128
+ with gzip.open(src, "rb") as s_file, open(dst, "wb") as d_file:
129
+ shutil.copyfileobj(s_file, d_file, 65536)
130
+
131
+ def _install_blink(self):
132
+ blink_version = "1.1.0"
133
+ blink_release_platform_filename_parts = {
134
+ "darwin-arm64": "darwin-arm64.gz", # ???
135
+ "darwin-x86_64": "darwin-x86_64.elf", # ???
136
+ "freebsd-x86_64": "freebsd-x86_64.elf.gz",
137
+ "linux-aarch64": "linux-aarch64.elf.gz",
138
+ "linux-arm": "linux-arm.elf.gz",
139
+ "linux-i486": "linux-i486.elf.gz",
140
+ "linux-mips": "linux-mips.elf.gz",
141
+ "linux-mips64": "linux-mips64.elf.gz",
142
+ "linux-mips64el": "linux-mips64el.elf.gz",
143
+ "linux-mipsel": "linux-mipsel.elf.gz",
144
+ "linux-powerpc": "linux-powerpc.elf.gz",
145
+ "linux-powerpc64le": "linux-powerpc64le.elf.gz",
146
+ "linux-s390x": "linux-s390x.elf.gz",
147
+ "linux-x86_64": "linux-x86_64.elf.gz",
148
+ "openbsd-x86_64": "openbsd-x86_64.elf.gz",
149
+ }
150
+ tag = f"{platform.system().lower()}-{platform.machine().lower()}"
151
+ blink_platform = blink_release_platform_filename_parts.get(tag, None)
152
+ assert blink_platform is not None, "FIXME: Unhandled platform tag"
153
+
154
+ blink_filename = f"blink-{blink_version}-{blink_platform}"
155
+ blink_release_url = f"https://github.com/jart/blink/releases/download/{blink_version}/{blink_filename}"
156
+
157
+ self._download_file(blink_release_url)
158
+ if blink_filename.endswith(".gz"):
159
+ self.gunzip(blink_filename, self._blink_path)
160
+ else:
161
+ shutil.copyfile(blink_filename, self._blink_path)
162
+ self._mark_file_executable(self._blink_path)
163
+
164
+ blink_license_url = "https://raw.githubusercontent.com/jart/blink/master/LICENSE"
165
+ self._download_file(blink_license_url, self._blink_path.parent / "blink.LICENSE.txt")
166
+
167
+ def run(self):
168
+ if not self._is_xdia_installed():
169
+ self._install_xdia()
170
+
171
+ if self._is_blink_required():
172
+ if not self._is_blink_installed():
173
+ self._install_blink()
174
+
175
+ def get_outputs(self):
176
+ outputs = self._get_xdia_install_list()
177
+ if self._is_blink_required():
178
+ outputs += self._get_blink_install_list()
179
+ return outputs
180
+
181
+
182
+ class build(_build):
183
+ sub_commands = _build.sub_commands + [('check_xdia_install', None)]
184
+
185
+
186
+ setup(
187
+ cmdclass={
188
+ 'build': build,
189
+ 'check_xdia_install': CheckXdiaInstallation,
190
+ 'bdist_wheel': CustomBdistWheel
191
+ },
192
+ packages=["pyxdia"],
193
+ package_data={"pyxdia": ["bin/*"]},
194
+ )
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env python3
2
+ # pylint:disable=no-self-use
3
+
4
+ import os
5
+ import subprocess
6
+ import sys
7
+ import unittest
8
+
9
+ from pyxdia import PDB
10
+
11
+
12
+ PDB_TEST_FILES = os.getenv("PDB_TEST_FILES")
13
+ assert PDB_TEST_FILES is not None, "Set environment variable PDB_TEST_FILES"
14
+
15
+
16
+ class TestCli(unittest.TestCase):
17
+ """
18
+ Test pyxdia module command line interface
19
+ """
20
+
21
+ def test_cli(self):
22
+ subprocess.run([sys.executable, "-m", "pyxdia", os.path.join(PDB_TEST_FILES, "hello-wdm.pdb")], check=True)
23
+
24
+
25
+ if __name__ == "__main__":
26
+ unittest.main()
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env python3
2
+ # pylint:disable=no-self-use
3
+
4
+ import os
5
+ import unittest
6
+
7
+ from pyxdia import PDB
8
+
9
+
10
+ PDB_TEST_FILES = os.getenv("PDB_TEST_FILES")
11
+ assert PDB_TEST_FILES is not None, "Set environment variable PDB_TEST_FILES"
12
+
13
+
14
+ class TestPDB(unittest.TestCase):
15
+ """
16
+ Test PDB class.
17
+ """
18
+
19
+ def test_instantiate(self):
20
+ pdb = PDB(os.path.join(PDB_TEST_FILES, "hello-wdm.pdb"))
21
+
22
+ def test_list_globals(self):
23
+ pdb = PDB(os.path.join(PDB_TEST_FILES, "hello-wdm.pdb"))
24
+ assert len(pdb.globals) == 78
25
+
26
+ globals_by_name = {g["name"]: g for g in pdb.globals}
27
+ assert globals_by_name["DriverEntry"] == {
28
+ "addressOffset": 0,
29
+ "addressSection": 5,
30
+ "name": "DriverEntry",
31
+ "relativeVirtualAddress": 20480,
32
+ "symTag": "Function",
33
+ "undecoratedName": "DriverEntry",
34
+ }
35
+
36
+
37
+ if __name__ == "__main__":
38
+ unittest.main()