Merge pull request #1436 from Anonymous78e/tools/pe-inspect-shared-report-path

pe_inspect: ask report_paths for the report-path guard (PE-INSPECT-SHARED-REPORT-PATH)
This commit is contained in:
MoonEyes
2026-11-29 02:31:54 +01:00
committed by GitHub
2 changed files with 21 additions and 10 deletions

View File

@ -382,6 +382,22 @@ class PeInspectTest(unittest.TestCase):
self.assertEqual(r["pdata_functions"], 0)
self.assertFalse(r["has_relocs"])
def test_case_only_spelling_of_a_missing_report_is_one_path(self):
# normcase keeps case on macOS, and samefile cannot see a report that has not been written yet.
with tempfile.TemporaryDirectory() as tmp:
folder = os.path.join(tmp, "Reports")
os.mkdir(folder)
probe = os.path.join(folder, "Probe.tmp")
with open(probe, "wb"):
pass
insensitive = os.path.exists(os.path.join(folder, "probe.tmp"))
os.remove(probe)
if not insensitive:
self.skipTest("volume keeps case")
first = os.path.join(tmp, "Reports", "game.exe.json")
second = os.path.join(tmp, "reports", "game.exe.json")
self.assertTrue(pe_inspect.same_output_path(first, second))
def test_cli_reports_an_unusable_output_directory(self):
out = os.path.join(self.dir, "report-file")
with open(out, "w", encoding="utf-8") as f:

View File

@ -32,6 +32,11 @@ import sys
from collections import Counter
from collections.abc import Iterator
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from report_paths import same_report_path # noqa: E402
same_output_path = same_report_path # True when writing the second would truncate the first
SYSTEM32 = os.path.join(os.environ.get("SystemRoot", r"C:\Windows"), "System32")
# Whether this host is Windows: there SYSTEM32 and the OS API-set schema answer `system`; elsewhere a Wine prefix's
# system32 does (classify_dll). A module flag so that a test can stand in for either host.
@ -978,16 +983,6 @@ def version_summary(r: dict) -> str | None:
+ (f", problems: {len(res['problems'])}" if res["problems"] else ""))
def same_output_path(first: str, second: str) -> bool:
"""True when writing ``second`` would truncate ``first`` (same file, path or hard link)."""
if os.path.normcase(os.path.realpath(first)) == os.path.normcase(os.path.realpath(second)):
return True
try:
return os.path.samefile(first, second)
except OSError:
return False
def main(argv: list[str] | None = None) -> int:
ap = argparse.ArgumentParser()
ap.add_argument("image", nargs="+")