mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-29 09:35:38 +00:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cfe07b0848 | ||
|
|
6346b5ebdf | ||
|
|
2702ba2db8 |
No files matched your search
@@ -12,7 +12,7 @@ EA games install, update and start without the EA app. The research behind it is
|
||||
| Queries | `app/src/main/resources/ea/graphql/*.gql` | EA's own query texts, byte for byte. The gateway matches persisted queries by SHA-256, so these files must not be reformatted (`-text` in `.gitattributes`). |
|
||||
| Downloads | Rust `src/ea/` in `libdroiddeckstores.so`, `EaInstaller.kt` | A build is one ZIP on EA's CDN. The engine reads its central directory with ranged reads, keeps files whose size and CRC match, and streams every other entry through inflate into place. `.droiddeck-ea-files` records what it placed, so a resume or update does not re-hash those files; files a new build drops are removed. |
|
||||
| Updates | `EaUpdates` in `EaBackend.kt` | The game page compares the installed version with the offer's live `gameVersion` (every 30 minutes at most). Update runs the same install, which only fetches changed files. |
|
||||
| Launch, guest | `droiddeck-store-launch` (`prepare_ea`) | Creates the prefix, reads the machine as Wine reports it (`wmic`, `vol`, `hostname`; cached in `pfx/.droiddeck-ea-hw.json`), writes EA app presence keys and the game's `Install Dir` keys in both registry views, runs the build's Touchup once per installed build, then asks the app for the session and writes any licence files. |
|
||||
| Launch, guest | `droiddeck-store-launch` (`prepare_ea`) | Creates the prefix, reads the machine as Wine reports it (`wmic`, `vol`, `hostname`, CPUID from a 32-bit and a 64-bit probe; cached in `pfx/.droiddeck-ea-hw.json` until the Proton version or its FEX libraries change; a probe that times out, fails or misses a value keeps the older complete cache), writes EA app presence keys and the game's `Install Dir` keys in both registry views, runs the build's Touchup once per installed build, then asks the app for the session and writes any licence files. |
|
||||
| Launch, Steam copy | `prepare_steam_ea` in `droiddeck-store-launch`, the Proton wrapper | Steam starts its EA titles with `steam2ea://`, which only the EA app handles, and the EA app does not install here. When the prefix has no EA app, the hook reads the game's `__Installer/installerdata.xml` and its offers (`__Installer/LOC/Origin.OFR.*.dat`), runs `prepare_ea` with a `steam` request (the app answers with the launch environment instead of a sidecar file), and writes `droiddeck-ea-steam.bat` in the game's compatdata. The wrapper runs that launcher in place of the link. Writing the EA app presence keys also satisfies the install script, so Steam stops running the EA app installer. |
|
||||
| Launch, app | `EaLaunch.kt`, `EaOoa.kt`, `EaLsx.kt` | Answers `ea-prepare`: starts the LSX endpoint on `127.0.0.1:3216`, mints the short-lived opaque token, writes `.droiddeck-ea-env` (read once and deleted by the launcher `.bat`), and for games with a `Core` folder requests an online-activation licence for the machine hash. |
|
||||
| LSX | `EaLsx.kt` | The local endpoint EA's SDK talks to instead of the EA app: challenge, AES session key, config, profile, settings, game info, auth codes for the game's own client ids, licences with Denuvo tokens, entitlements. Friends, presence and the overlay answer empty. |
|
||||
@@ -21,8 +21,10 @@ EA games install, update and start without the EA app. The research behind it is
|
||||
|
||||
The licence names a hash of the machine the game's activation layer computes itself. The hash
|
||||
version follows the activation library's product version (`Core/activation.dll` or `awc.dll`):
|
||||
5.x → 4, 4.7.6+ → 3, 4.7.x → 2, 4.x → 1. Versions 2 and 3 also need CPUID leaf 1 ECX, which Wine's
|
||||
WMI does not expose, so those use `00000000` unless the probe learns it.
|
||||
5.x → 4, 4.7.6+ → 3, 4.7.x → 2, 4.x → 1. Versions 2 and 3 also hash CPUID leaf 1 ECX, which FEX
|
||||
reports differently to 32-bit (WOW64) and 64-bit (ARM64EC) processes when their AVX support differs,
|
||||
so the game is sent the CPUID its own exe's bitness sees. A cache from before the 64-bit probe has
|
||||
only the 32-bit values, and every game gets those until a probe with Proton found succeeds.
|
||||
|
||||
## Not done yet
|
||||
|
||||
|
||||
@@ -1258,39 +1258,69 @@ def wmi_value(text):
|
||||
CPUID_LEAVES = (0, 1, 0x80000002, 0x80000003, 0x80000004)
|
||||
|
||||
|
||||
def cpuid_exe():
|
||||
"""A 32-bit console program that writes the raw CPUID leaves an x86 game sees under the emulator."""
|
||||
def cpuid_exe(wide=False):
|
||||
"""A console program that writes the raw CPUID leaves an x86 game sees under the emulator: 32-bit, or 64-bit when wide."""
|
||||
import struct
|
||||
base, rva = 0x400000, 0x1000
|
||||
buf, written = base + rva + 0x180, base + rva + 0x1D0
|
||||
iat = base + rva + 0x138
|
||||
code = b"\x53\x57\xbf" + struct.pack("<I", buf)
|
||||
rva = 0x1000
|
||||
if wide:
|
||||
base, thunk, optional, names, dll, buf, written = 0x140000000, 8, 0xF0, (0x168, 0x178, 0x184), 0x192, 0x1A0, 0x1F0
|
||||
else:
|
||||
base, thunk, optional, names, dll, buf, written = 0x400000, 4, 0xE0, (0x148, 0x158, 0x164), 0x172, 0x180, 0x1D0
|
||||
ilt, iat = 0x128, 0x128 + 4 * thunk
|
||||
code = bytearray()
|
||||
|
||||
def rip(op, target):
|
||||
code.extend(op + struct.pack("<i", target - len(code) - len(op) - 4))
|
||||
|
||||
if wide:
|
||||
code += b"\x53\x57\x48\x83\xec\x38"
|
||||
rip(b"\x48\x8d\x3d", buf)
|
||||
else:
|
||||
code += b"\x53\x57\xbf" + struct.pack("<I", base + rva + buf)
|
||||
for leaf in CPUID_LEAVES:
|
||||
code += b"\xb8" + struct.pack("<I", leaf) + b"\x31\xc9\x0f\xa2\x89\x07\x89\x5f\x04\x89\x4f\x08\x89\x57\x0c\x83\xc7\x10"
|
||||
code += b"\x6a\xf5\xff\x15" + struct.pack("<I", iat)
|
||||
code += b"\x6a\x00\x68" + struct.pack("<I", written) + b"\x6a\x50\x68" + struct.pack("<I", buf) + b"\x50\xff\x15" + struct.pack("<I", iat + 4)
|
||||
code += b"\x6a\x00\xff\x15" + struct.pack("<I", iat + 8)
|
||||
code += b"\xb8" + struct.pack("<I", leaf) + b"\x31\xc9\x0f\xa2\x89\x07\x89\x5f\x04\x89\x4f\x08\x89\x57\x0c"
|
||||
code += b"\x48\x83\xc7\x10" if wide else b"\x83\xc7\x10"
|
||||
if wide:
|
||||
code += b"\xb9\xf5\xff\xff\xff"
|
||||
rip(b"\xff\x15", iat)
|
||||
code += b"\x48\x89\xc1"
|
||||
rip(b"\x48\x8d\x15", buf)
|
||||
code += b"\x41\xb8\x50\x00\x00\x00"
|
||||
rip(b"\x4c\x8d\x0d", written)
|
||||
code += b"\x48\xc7\x44\x24\x20\x00\x00\x00\x00"
|
||||
rip(b"\xff\x15", iat + 8)
|
||||
code += b"\x31\xc9"
|
||||
rip(b"\xff\x15", iat + 16)
|
||||
else:
|
||||
at = base + rva
|
||||
code += b"\x6a\xf5\xff\x15" + struct.pack("<I", at + iat)
|
||||
code += b"\x6a\x00\x68" + struct.pack("<I", at + written) + b"\x6a\x50\x68" + struct.pack("<I", at + buf)
|
||||
code += b"\x50\xff\x15" + struct.pack("<I", at + iat + 4) + b"\x6a\x00\xff\x15" + struct.pack("<I", at + iat + 8)
|
||||
section = bytearray(0x200)
|
||||
section[:len(code)] = code
|
||||
names = [(0x148, b"GetStdHandle"), (0x158, b"WriteFile"), (0x164, b"ExitProcess")]
|
||||
struct.pack_into("<IIIII", section, 0x100, rva + 0x128, 0, 0, rva + 0x172, rva + 0x138)
|
||||
for i, (at, name) in enumerate(names):
|
||||
struct.pack_into("<I", section, 0x128 + 4 * i, rva + at)
|
||||
struct.pack_into("<I", section, 0x138 + 4 * i, rva + at)
|
||||
struct.pack_into("<IIIII", section, 0x100, rva + ilt, 0, 0, rva + dll, rva + iat)
|
||||
entry = "<Q" if wide else "<I"
|
||||
for i, (at, name) in enumerate(zip(names, (b"GetStdHandle", b"WriteFile", b"ExitProcess"))):
|
||||
struct.pack_into(entry, section, ilt + thunk * i, rva + at)
|
||||
struct.pack_into(entry, section, iat + thunk * i, rva + at)
|
||||
section[at + 2:at + 2 + len(name)] = name
|
||||
section[0x172:0x172 + 12] = b"KERNEL32.dll"
|
||||
section[dll:dll + 12] = b"KERNEL32.dll"
|
||||
header = bytearray(0x200)
|
||||
header[0:2] = b"MZ"
|
||||
struct.pack_into("<I", header, 0x3C, 0x40)
|
||||
header[0x40:0x44] = b"PE\0\0"
|
||||
struct.pack_into("<HHIIIHH", header, 0x44, 0x14C, 1, 0, 0, 0, 0xE0, 0x0103)
|
||||
opt = struct.pack("<HBBIIIIIIIIIHHHHHHIIIIHHIIIIII", 0x10B, 0, 0, 0x200, 0, 0, rva, rva, rva, base, 0x1000, 0x200,
|
||||
4, 0, 0, 0, 4, 0, 0, 0x2000, 0x200, 0, 3, 0, 0x100000, 0x1000, 0x100000, 0x1000, 0, 16)
|
||||
struct.pack_into("<HHIIIHH", header, 0x44, 0x8664 if wide else 0x14C, 1, 0, 0, 0, optional, 0x0023 if wide else 0x0103)
|
||||
if wide:
|
||||
opt = struct.pack("<HBBIIIIIQIIHHHHHHIIIIHHQQQQII", 0x20B, 0, 0, 0x200, 0, 0, rva, rva, base, 0x1000, 0x200,
|
||||
5, 2, 0, 0, 5, 2, 0, 0x2000, 0x200, 0, 3, 0, 0x100000, 0x1000, 0x100000, 0x1000, 0, 16)
|
||||
else:
|
||||
opt = struct.pack("<HBBIIIIIIIIIHHHHHHIIIIHHIIIIII", 0x10B, 0, 0, 0x200, 0, 0, rva, rva, rva, base, 0x1000, 0x200,
|
||||
4, 0, 0, 0, 4, 0, 0, 0x2000, 0x200, 0, 3, 0, 0x100000, 0x1000, 0x100000, 0x1000, 0, 16)
|
||||
dirs = bytearray(128)
|
||||
struct.pack_into("<II", dirs, 8, rva + 0x100, 40)
|
||||
struct.pack_into("<II", dirs, 96, rva + 0x138, 16)
|
||||
header[0x58:0x58 + 0xE0] = opt + bytes(dirs)
|
||||
header[0x138:0x138 + 40] = struct.pack("<8sIIIIIIHHI", b".text", 0x1000, rva, 0x200, 0x200, 0, 0, 0, 0, 0xE0000060)
|
||||
struct.pack_into("<II", dirs, 96, rva + iat, 4 * thunk)
|
||||
header[0x58:0x58 + optional] = opt + bytes(dirs)
|
||||
header[0x58 + optional:0x58 + optional + 40] = struct.pack("<8sIIIIIIHHI", b".text", 0x1000, rva, 0x200, 0x200, 0, 0, 0, 0, 0xE0000060)
|
||||
return bytes(header) + bytes(section)
|
||||
|
||||
|
||||
@@ -1342,24 +1372,65 @@ def cpuid_values(raw):
|
||||
"cpuEcx": "%08x" % regs[1][2], "cpuBrand": brand}
|
||||
|
||||
|
||||
EA_PROBE_FIELDS = ("boardManufacturer", "biosManufacturer", "osInstallDate", "osSerial", "volumeSerial", "hostname",
|
||||
"cpuVendor", "cpuEax", "cpuEdx", "cpuEcx")
|
||||
EA_CPU_FIELDS = ("cpuVendor", "cpuEax", "cpuEdx", "cpuEcx")
|
||||
EA_PROBE_FIELDS = ("boardManufacturer", "biosManufacturer", "osInstallDate", "osSerial", "volumeSerial",
|
||||
"hostname") + EA_CPU_FIELDS
|
||||
|
||||
|
||||
def probe_complete(values):
|
||||
return all(str(values.get(key) or "").strip() for key in EA_PROBE_FIELDS)
|
||||
EA_CPU64 = "cpu64"
|
||||
EA_RUNTIME = "runtime"
|
||||
EA_RUNTIME_FILES = ("version", "files/lib/wine/aarch64-windows/libarm64ecfex.dll", "files/lib/wine/aarch64-windows/libwow64fex.dll")
|
||||
|
||||
|
||||
def probe_complete(values, fields=EA_PROBE_FIELDS):
|
||||
return all(str(values.get(key) or "").strip() for key in fields)
|
||||
|
||||
|
||||
def runtime_stamp(proton):
|
||||
if not proton or not Path(proton).is_file():
|
||||
return ""
|
||||
root = Path(proton).parent
|
||||
parts = []
|
||||
for name in EA_RUNTIME_FILES:
|
||||
try:
|
||||
parts.append(name + " " + hashlib.sha256((root / name).read_bytes()).hexdigest())
|
||||
except OSError:
|
||||
parts.append(name + " -")
|
||||
return hashlib.sha256("\n".join(parts).encode("utf-8")).hexdigest()
|
||||
|
||||
|
||||
def read_cpuid(path):
|
||||
try:
|
||||
return cpuid_values(path.read_bytes())
|
||||
except OSError:
|
||||
return {}
|
||||
|
||||
|
||||
def ea_game_hardware(values, folder, sidecar):
|
||||
chosen = {key: value for key, value in values.items() if key not in (EA_CPU64, EA_RUNTIME)}
|
||||
wide = values.get(EA_CPU64)
|
||||
exe = find_case(folder, str(sidecar.get("exe") or ""))
|
||||
if isinstance(wide, dict) and exe is not None and exe.is_file():
|
||||
pe = runpy.run_path(str(Path(__file__).resolve().parent / "droiddeck-wine-pe"))
|
||||
if pe["pe_machine"](str(exe)) == 0x8664:
|
||||
chosen.update(wide)
|
||||
return chosen
|
||||
|
||||
|
||||
def ea_hardware(compat_data, proton, timeout=240):
|
||||
pfx = Path(compat_data) / "pfx"
|
||||
cache = pfx / EA_HARDWARE
|
||||
runtime = runtime_stamp(proton)
|
||||
stale = {}
|
||||
try:
|
||||
cached = json.loads(cache.read_text())
|
||||
if isinstance(cached, dict) and probe_complete(cached):
|
||||
return cached, "cached"
|
||||
if not runtime or cached.get(EA_RUNTIME) == runtime:
|
||||
return cached, "cached"
|
||||
stale = cached
|
||||
except (OSError, ValueError):
|
||||
pass
|
||||
if not proton or not Path(proton).is_file():
|
||||
if not runtime:
|
||||
return {}, "no-proton"
|
||||
values = {}
|
||||
with tempfile.TemporaryDirectory(prefix="droiddeck-ea-") as tmp:
|
||||
@@ -1369,17 +1440,18 @@ def ea_hardware(compat_data, proton, timeout=240):
|
||||
lines.append('wmic path %s get %s > "%s"' % (cls, prop, windows_path(str(folder / (key + ".txt")))))
|
||||
lines.append('vol C: > "%s"' % windows_path(str(folder / "volume.txt")))
|
||||
lines.append('hostname > "%s"' % windows_path(str(folder / "hostname.txt")))
|
||||
(folder / "cpuid.exe").write_bytes(cpuid_exe())
|
||||
lines.append('"%s" > "%s"' % (windows_path(str(folder / "cpuid.exe")), windows_path(str(folder / "cpuid.bin"))))
|
||||
for name, wide in (("cpuid", False), ("cpuid64", True)):
|
||||
(folder / (name + ".exe")).write_bytes(cpuid_exe(wide))
|
||||
lines.append('"%s" > "%s"' % (windows_path(str(folder / (name + ".exe"))), windows_path(str(folder / (name + ".bin")))))
|
||||
bat = folder / "probe.bat"
|
||||
bat.write_bytes(("\r\n".join(lines) + "\r\n").encode())
|
||||
try:
|
||||
subprocess.run([proton, "run", "cmd.exe", "/d", "/c", windows_path(str(bat))], stdin=subprocess.DEVNULL,
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=timeout)
|
||||
except subprocess.TimeoutExpired:
|
||||
return {}, "timeout"
|
||||
return stale, "timeout"
|
||||
except OSError:
|
||||
return {}, "failed"
|
||||
return stale, "failed"
|
||||
for key, _, _ in EA_WMI:
|
||||
try:
|
||||
values[key] = wmi_value(decode_output((folder / (key + ".txt")).read_bytes()))
|
||||
@@ -1394,17 +1466,18 @@ def ea_hardware(compat_data, proton, timeout=240):
|
||||
values["hostname"] = decode_output((folder / "hostname.txt").read_bytes()).strip().splitlines()[0].strip()
|
||||
except (OSError, IndexError):
|
||||
values["hostname"] = ""
|
||||
try:
|
||||
values.update(cpuid_values((folder / "cpuid.bin").read_bytes()))
|
||||
except OSError:
|
||||
pass
|
||||
if probe_complete(values):
|
||||
values.update(read_cpuid(folder / "cpuid.bin"))
|
||||
wide = read_cpuid(folder / "cpuid64.bin")
|
||||
if wide:
|
||||
values[EA_CPU64] = wide
|
||||
if probe_complete(values) and probe_complete(values.get(EA_CPU64, {}), EA_CPU_FIELDS):
|
||||
values[EA_RUNTIME] = runtime
|
||||
try:
|
||||
cache.write_text(json.dumps(values))
|
||||
except OSError:
|
||||
pass
|
||||
return values, "probed"
|
||||
return values, "incomplete"
|
||||
return stale or values, "incomplete"
|
||||
|
||||
|
||||
def ea_registry_entries(folder, sidecar):
|
||||
@@ -1571,7 +1644,7 @@ def prepare_ea(folder, sidecar, compat_data, launch_dir, steam=None):
|
||||
hardware, probe = ea_hardware(compat_data, proton) if ready else ({}, "no-prefix")
|
||||
answer = None
|
||||
if launch_dir:
|
||||
request = {"op": "ea-prepare", "store": "ea", "id": game, "hardware": hardware}
|
||||
request = {"op": "ea-prepare", "store": "ea", "id": game, "hardware": ea_game_hardware(hardware, folder, sidecar)}
|
||||
if steam is not None:
|
||||
request["steam"] = steam
|
||||
answer = ask(Path(launch_dir) / "stores", request, timeout=40.0)
|
||||
@@ -1691,10 +1764,11 @@ def prepare_steam_ea(argv, compat_data, launch_dir):
|
||||
log("steam ea: no channel to DroidDeck, left to the EA app")
|
||||
return 0
|
||||
exe = manifest["exe"]
|
||||
sidecar = {"store": "ea", "id": offers[0], "title": manifest["title"],
|
||||
relative = str(exe.relative_to(folder))
|
||||
sidecar = {"store": "ea", "id": offers[0], "title": manifest["title"], "exe": relative,
|
||||
"extra": {"contentIds": ",".join(manifest["contentIds"]), "displayName": manifest["title"], "locale": "en_US"}}
|
||||
steam = {"folder": str(folder), "offers": offers, "contentIds": manifest["contentIds"], "title": manifest["title"],
|
||||
"version": manifest["version"], "locale": "en_US", "exe": str(exe.relative_to(folder))}
|
||||
"version": manifest["version"], "locale": "en_US", "exe": relative}
|
||||
answer = prepare_ea(folder, sidecar, compat_data, launch_dir, steam)
|
||||
env = answer.get("env") if answer and answer.get("ok") else None
|
||||
if not isinstance(env, dict):
|
||||
|
||||
@@ -532,6 +532,32 @@ class SteamEa(unittest.TestCase):
|
||||
self.assertEqual(0, store.main(['--exited', 'steam2ea://launchgame/1237970']))
|
||||
self.assertEqual([{'op': 'ea-exited', 'store': 'ea', 'id': 'Origin.OFR.50.0001452'}], asked)
|
||||
|
||||
def test_a_steam_copy_is_sent_the_cpuid_of_its_exes_bitness(self):
|
||||
narrow = dict({key: 'x' for key in store.EA_PROBE_FIELDS}, cpuEcx='82d8230f')
|
||||
values = dict(narrow, cpu64={'cpuEcx': 'bed8330f'}, runtime='stamp')
|
||||
for image, expected in ((store.cpuid_exe(True), dict(narrow, cpuEcx='bed8330f')), (store.cpuid_exe(), narrow)):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder, data = self.steam_copy(root)
|
||||
(folder / 'Titanfall2.exe').write_bytes(image)
|
||||
asked = []
|
||||
|
||||
def fake_ask(channel, request, timeout=5.0, claim=False):
|
||||
asked.append(request)
|
||||
return {'ok': True, 'id': 'Origin.OFR.50.0001452', 'env': {'EALsxPort': '3216'}}
|
||||
|
||||
env = {'STEAM_COMPAT_INSTALL_PATH': str(folder), 'STEAM_COMPAT_DATA_PATH': str(data),
|
||||
'DD_LAUNCH_DIR': str(Path(root) / 'session'), 'DD_STORE_PROTON': ''}
|
||||
with patch.dict(os.environ, env), patch.object(store, 'ask', side_effect=fake_ask), \
|
||||
patch.object(store, 'create_prefix', return_value='present'), \
|
||||
patch.object(store, 'install_origin_stub', return_value='ready'), \
|
||||
patch.object(store, 'ea_hardware', return_value=(values, 'cached')), \
|
||||
patch.object(store, 'ea_registry', return_value='ready'), \
|
||||
patch.object(store, 'ea_touchup', return_value='none'):
|
||||
self.assertEqual(store.REPLACED, store.main(['steam2ea://launchgame/1237970']))
|
||||
self.assertEqual('ea-prepare', asked[0]['op'])
|
||||
self.assertEqual('Titanfall2.exe', asked[0]['steam']['exe'])
|
||||
self.assertEqual(expected, asked[0]['hardware'])
|
||||
|
||||
def test_the_manifests_launch_parameters_keep_their_quotes(self):
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
folder, data = self.steam_copy(root)
|
||||
|
||||
@@ -3,6 +3,8 @@ import importlib.machinery
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import re
|
||||
import struct
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
@@ -15,6 +17,53 @@ store = importlib.util.module_from_spec(spec)
|
||||
loader.exec_module(store)
|
||||
|
||||
|
||||
def called_imports(exe):
|
||||
wide = struct.unpack_from('<H', exe, 0x58)[0] == 0x20B
|
||||
base = struct.unpack_from('<Q', exe, 0x58 + 24)[0] if wide else struct.unpack_from('<I', exe, 0x58 + 28)[0]
|
||||
dirs = 0x58 + struct.unpack_from('<H', exe, 0x54)[0] - 128
|
||||
raw = lambda rva: 0x200 + rva - 0x1000
|
||||
ilt, _, _, dll, iat = struct.unpack_from('<IIIII', exe, raw(struct.unpack_from('<I', exe, dirs + 8)[0]))
|
||||
thunk = 8 if wide else 4
|
||||
slots = {}
|
||||
for i in range(3):
|
||||
hint = struct.unpack_from('<Q' if wide else '<I', exe, raw(iat) + thunk * i)[0]
|
||||
if hint != struct.unpack_from('<Q' if wide else '<I', exe, raw(ilt) + thunk * i)[0]:
|
||||
return None
|
||||
slots[iat + thunk * i] = exe[raw(hint) + 2:].split(b'\0')[0]
|
||||
code = exe[0x200:0x300]
|
||||
called = []
|
||||
for at in range(len(code) - 6):
|
||||
if code[at:at + 2] == b'\xff\x15':
|
||||
value = struct.unpack_from('<i' if wide else '<I', code, at + 2)[0]
|
||||
called.append(slots.get(0x1000 + at + 6 + value if wide else value - base))
|
||||
return exe[raw(dll):].split(b'\0')[0], called
|
||||
|
||||
|
||||
PROBE_NARROW = bytes.fromhex('1600000047656e756e74656c696e654961060a00000805000f23d882fffb8b27436f727465782d4135323000000000000000000000000000000000000000000000000000000000000000000000000000')
|
||||
PROBE_WIDE = bytearray(PROBE_NARROW)
|
||||
PROBE_WIDE[16 + 8:16 + 12] = bytes.fromhex('0f33d8be')
|
||||
|
||||
|
||||
def fake_probe(wide):
|
||||
def run(argv, **kwargs):
|
||||
bat = Path(argv[-1][2:].replace('\\', '/'))
|
||||
for line in bat.read_text().splitlines():
|
||||
found = re.search(r'"?([^"]*)"? > "([^"]*)"$', line)
|
||||
if not found:
|
||||
continue
|
||||
source, out = found.group(1), Path(found.group(2)[2:].replace('\\', '/'))
|
||||
if source.endswith('cpuid64.exe'):
|
||||
if wide is not None:
|
||||
out.write_bytes(wide)
|
||||
elif source.endswith('cpuid.exe'):
|
||||
out.write_bytes(PROBE_NARROW)
|
||||
elif source.startswith('vol'):
|
||||
out.write_text(' Volume Serial Number is 1A2B-3C4D\r\n')
|
||||
else:
|
||||
out.write_text('Header\r\nvalue\r\n')
|
||||
return run
|
||||
|
||||
|
||||
class EaHook(unittest.TestCase):
|
||||
def test_wmi_output_reads_the_value_under_the_header(self):
|
||||
text = 'Manufacturer \r\r\nThe Wine Project \r\r\n\r\r\n'
|
||||
@@ -101,6 +150,112 @@ class EaHook(unittest.TestCase):
|
||||
self.assertEqual(struct.unpack_from('<H', exe, 0x58 + 68)[0], 3)
|
||||
self.assertIn(b'KERNEL32.dll', exe)
|
||||
self.assertEqual(len(exe), 0x400)
|
||||
self.assertEqual(called_imports(exe), (b'KERNEL32.dll', [b'GetStdHandle', b'WriteFile', b'ExitProcess']))
|
||||
|
||||
def test_cpuid_probe_has_a_64_bit_form_that_writes_the_same_leaves(self):
|
||||
exe = store.cpuid_exe(True)
|
||||
self.assertEqual(exe[:2], b'MZ')
|
||||
self.assertEqual(struct.unpack_from('<H', exe, 0x44)[0], 0x8664)
|
||||
self.assertEqual(struct.unpack_from('<H', exe, 0x58)[0], 0x20B)
|
||||
self.assertEqual(struct.unpack_from('<H', exe, 0x58 + 68)[0], 3)
|
||||
self.assertEqual(len(exe), 0x400)
|
||||
self.assertEqual(called_imports(exe), (b'KERNEL32.dll', [b'GetStdHandle', b'WriteFile', b'ExitProcess']))
|
||||
code = exe[0x200:0x300]
|
||||
self.assertEqual(code.count(b'\x0f\xa2'), len(store.CPUID_LEAVES))
|
||||
loads = {}
|
||||
for at in range(len(code) - 7):
|
||||
if code[at:at + 3] in (b'\x48\x8d\x3d', b'\x48\x8d\x15', b'\x4c\x8d\x0d'):
|
||||
loads[code[at:at + 3]] = at + 7 + struct.unpack_from('<i', code, at + 3)[0]
|
||||
self.assertEqual(loads[b'\x48\x8d\x3d'], loads[b'\x48\x8d\x15'])
|
||||
self.assertGreaterEqual(loads[b'\x4c\x8d\x0d'], loads[b'\x48\x8d\x15'] + 16 * len(store.CPUID_LEAVES))
|
||||
self.assertLessEqual(loads[b'\x4c\x8d\x0d'] + 4, 0x200)
|
||||
self.assertFalse(any(exe[0x200 + loads[b'\x48\x8d\x15']:0x200 + loads[b'\x4c\x8d\x0d'] + 4]))
|
||||
self.assertEqual(store.cpuid_exe(False), store.cpuid_exe())
|
||||
|
||||
def test_each_game_is_sent_the_cpuid_of_its_own_bitness(self):
|
||||
narrow = {'cpuVendor': 'GenuineIntel', 'cpuEax': '000A0661', 'cpuEdx': '278BFBFF', 'cpuEcx': '82d8230f', 'cpuBrand': 'Cortex-A520'}
|
||||
probe = dict({key: 'x' for key in store.EA_PROBE_FIELDS}, **narrow)
|
||||
values = dict(probe, cpu64=dict(narrow, cpuEcx='bed8330f'), runtime='stamp')
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
folder = Path(tmp)
|
||||
(folder / 'Game64.exe').write_bytes(store.cpuid_exe(True))
|
||||
(folder / 'bin').mkdir()
|
||||
(folder / 'bin/Game32.exe').write_bytes(store.cpuid_exe())
|
||||
self.assertEqual(store.ea_game_hardware(values, folder, {'exe': 'game64.exe'}), dict(probe, cpuEcx='bed8330f'))
|
||||
self.assertEqual(store.ea_game_hardware(values, folder, {'exe': 'bin/Game32.exe'}), probe)
|
||||
self.assertEqual(store.ea_game_hardware(values, folder, {'exe': 'Missing.exe'}), probe)
|
||||
self.assertEqual(store.ea_game_hardware(values, folder, {}), probe)
|
||||
self.assertEqual(store.ea_game_hardware(probe, folder, {'exe': 'Game64.exe'}), probe)
|
||||
|
||||
def test_a_probe_from_another_proton_or_fex_build_is_taken_again(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton = Path(tmp) / 'tool/proton'
|
||||
fex = proton.parent / 'files/lib/wine/aarch64-windows/libwow64fex.dll'
|
||||
fex.parent.mkdir(parents=True)
|
||||
proton.write_text('')
|
||||
(proton.parent / 'version').write_text('1 experimental-11.0')
|
||||
fex.write_bytes(b'fex 1')
|
||||
runtime = store.runtime_stamp(str(proton))
|
||||
self.assertTrue(runtime)
|
||||
self.assertEqual(store.runtime_stamp(str(proton)), runtime)
|
||||
self.assertEqual(store.runtime_stamp(''), '')
|
||||
compat = Path(tmp) / 'compat'
|
||||
(compat / 'pfx').mkdir(parents=True)
|
||||
cached = dict({key: 'x' for key in store.EA_PROBE_FIELDS}, runtime=runtime)
|
||||
(compat / 'pfx' / store.EA_HARDWARE).write_text(json.dumps(cached))
|
||||
with patch.object(store.subprocess, 'run', side_effect=AssertionError('probed again')):
|
||||
self.assertEqual(store.ea_hardware(str(compat), str(proton)), (cached, 'cached'))
|
||||
self.assertEqual(store.ea_hardware(str(compat), ''), (cached, 'cached'))
|
||||
fex.write_bytes(b'fex 2')
|
||||
self.assertNotEqual(store.runtime_stamp(str(proton)), runtime)
|
||||
with patch.object(store.subprocess, 'run', side_effect=OSError) as run:
|
||||
self.assertEqual(store.ea_hardware(str(compat), str(proton)), (cached, 'failed'))
|
||||
run.assert_called_once()
|
||||
(proton.parent / 'version').write_text('2 experimental-11.0')
|
||||
self.assertNotEqual(store.runtime_stamp(str(proton)), runtime)
|
||||
|
||||
def test_the_probe_records_both_bitnesses_and_the_runtime(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton = Path(tmp) / 'tool/proton'
|
||||
proton.parent.mkdir()
|
||||
proton.write_text('')
|
||||
compat = Path(tmp) / 'compat'
|
||||
(compat / 'pfx').mkdir(parents=True)
|
||||
with patch.object(store.subprocess, 'run', side_effect=fake_probe(bytes(PROBE_WIDE))):
|
||||
values, how = store.ea_hardware(str(compat), str(proton))
|
||||
self.assertEqual(how, 'probed')
|
||||
self.assertEqual(values['cpuEcx'], '82d8230f')
|
||||
self.assertEqual(values['cpu64']['cpuEcx'], 'bed8330f')
|
||||
self.assertEqual(values['volumeSerial'], '1a2b3c4d')
|
||||
self.assertEqual(values['runtime'], store.runtime_stamp(str(proton)))
|
||||
self.assertEqual(json.loads((compat / 'pfx' / store.EA_HARDWARE).read_text()), values)
|
||||
|
||||
def test_a_failed_64_bit_probe_keeps_the_old_cache_and_is_retried(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
proton = Path(tmp) / 'tool/proton'
|
||||
proton.parent.mkdir()
|
||||
proton.write_text('')
|
||||
compat = Path(tmp) / 'compat'
|
||||
(compat / 'pfx').mkdir(parents=True)
|
||||
cache = compat / 'pfx' / store.EA_HARDWARE
|
||||
for wide in (None, PROBE_NARROW[:40]):
|
||||
with patch.object(store.subprocess, 'run', side_effect=fake_probe(wide)):
|
||||
values, how = store.ea_hardware(str(compat), str(proton))
|
||||
self.assertEqual(how, 'incomplete')
|
||||
self.assertEqual(values['cpuEcx'], '82d8230f')
|
||||
self.assertNotIn('cpu64', values)
|
||||
self.assertNotIn('runtime', values)
|
||||
self.assertFalse(cache.exists())
|
||||
stale = dict({key: 'x' for key in store.EA_PROBE_FIELDS}, cpu64={'cpuEcx': 'bed8330f'}, runtime='old')
|
||||
cache.write_text(json.dumps(stale))
|
||||
with patch.object(store.subprocess, 'run', side_effect=fake_probe(None)):
|
||||
self.assertEqual(store.ea_hardware(str(compat), str(proton)), (stale, 'incomplete'))
|
||||
self.assertEqual(json.loads(cache.read_text()), stale)
|
||||
with patch.object(store.subprocess, 'run', side_effect=fake_probe(bytes(PROBE_WIDE))):
|
||||
values, how = store.ea_hardware(str(compat), str(proton))
|
||||
self.assertEqual(how, 'probed')
|
||||
self.assertEqual(values['cpu64']['cpuEcx'], 'bed8330f')
|
||||
self.assertEqual(json.loads(cache.read_text()), values)
|
||||
|
||||
def test_origin_stub_is_a_windowless_program_installed_once(self):
|
||||
import struct
|
||||
|
||||
Reference in new issue
Block a user