"""S1 真值:Word 最后保存时记录的页数。DOCX 读 docProps/app.xml 的 ,旧版 DOC 读 OLE SummaryInformation 的 PIDSI_PAGECOUNT。""" import json, re, sys, zipfile, pathlib sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent)) import olefile from common import IDS, sample_file, sniff OUT = pathlib.Path(__file__).parent / "out" rows = {} for sid in IDS: f = sample_file(sid) kind = sniff(f) info = {"kind": kind, "pages": None, "app": None, "ole_objects": 0} if kind == "docx": with zipfile.ZipFile(f) as z: names = z.namelist() if "docProps/app.xml" in names: app = z.read("docProps/app.xml").decode("utf-8", "replace") m = re.search(r"(\d+)", app) info["pages"] = int(m.group(1)) if m else None a = re.search(r"([^<]*)", app) info["app"] = a.group(1) if a else None info["ole_objects"] = sum(1 for n in names if n.startswith("word/embeddings/")) info["has_ole_xml"] = b"