Skip to content

Commit

Permalink
make sure binfile patches are a full 256 bytes (#258)
Browse files Browse the repository at this point in the history
* make sure binfile patches are a full 256 bytes, including any necessary padding.

* assume binary patch values are always 256 byte zero filled.

* assume zero terminated patch values instead of a fixed length.

* add qmake patchs for qt_epfxpath and qt_hpfxpath.

* tighten up binary patch
  • Loading branch information
tsteven4 authored Jun 9, 2021
1 parent df43981 commit f865f5f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion aqt/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def _patch_binfile(self, file: pathlib.Path, key: bytes, newpath: bytes):
if idx < 0:
return
assert len(newpath) < 256, "Qt Prefix path is too long(255)."
data = data[:idx] + key + newpath + data[idx + len(key) + len(newpath) :]
oldlen = data[idx + len(key) :].find(b"\0")
assert oldlen >= 0
value = newpath + b"\0" * (oldlen - len(newpath))
data = data[: idx + len(key)] + value + data[idx + len(key) + len(value) :]
file.write_bytes(data)
os.chmod(str(file), st.st_mode)

Expand Down Expand Up @@ -98,6 +101,16 @@ def patch_qmake(self):
key=b"qt_prfxpath=",
newpath=bytes(str(self.prefix), "UTF-8"),
)
self._patch_binfile(
self.qmake_path,
key=b"qt_epfxpath=",
newpath=bytes(str(self.prefix), "UTF-8"),
)
self._patch_binfile(
self.qmake_path,
key=b"qt_hpfxpath=",
newpath=bytes(str(self.prefix), "UTF-8"),
)

def patch_qmake_script(self, base_dir, qt_version, os_name):
if os_name == "linux":
Expand Down

0 comments on commit f865f5f

Please sign in to comment.