This commit is contained in:
Félix Baylac Jacqué 2022-12-14 19:01:47 +01:00
parent 4b59c4f32e
commit 3deb47c537
1 changed files with 9 additions and 7 deletions

View File

@ -320,6 +320,7 @@ def copy_and_patch_libs(
we first copy them to the user's personal cache directory, we then we first copy them to the user's personal cache directory, we then
alter their runpath to point to the cache directory.""" alter their runpath to point to the cache directory."""
rpath = rpath if (rpath is not None) else dest_dir rpath = rpath if (rpath is not None) else dest_dir
new_paths: List[str] = []
for dso in dsos: for dso in dsos:
basename = os.path.basename(dso.fullpath) basename = os.path.basename(dso.fullpath)
newpath = os.path.join(dest_dir, basename) newpath = os.path.join(dest_dir, basename)
@ -327,7 +328,8 @@ def copy_and_patch_libs(
shutil.copyfile(dso.fullpath, newpath) shutil.copyfile(dso.fullpath, newpath)
# Provide write permissions to ensure we can patch this binary. # Provide write permissions to ensure we can patch this binary.
os.chmod(newpath, os.stat(dso.fullpath).st_mode | stat.S_IWUSR) os.chmod(newpath, os.stat(dso.fullpath).st_mode | stat.S_IWUSR)
patch_dso(newpath, rpath) new_paths.append(newpath)
patch_dsos(new_paths, rpath)
def log_info(string: str) -> None: def log_info(string: str) -> None:
@ -337,14 +339,14 @@ def log_info(string: str) -> None:
print(f"[+] {string}", file=sys.stderr) print(f"[+] {string}", file=sys.stderr)
def patch_dso(dsoPath: str, rpath: str) -> None: def patch_dsos(dsoPaths: List[str], rpath: str) -> None:
"""Call patchelf to change the DSOPATH runpath with RPATH.""" """Call patchelf to change the DSOS runpath with RPATH."""
log_info(f"Patching {dsoPath}") log_info(f"Patching {dsoPaths}")
log_info(f"Exec: {PATCHELF_PATH} --set-rpath {rpath} {dsoPath}") log_info(f"Exec: {PATCHELF_PATH} --set-rpath {rpath} {dsoPaths}")
res = subprocess.run([PATCHELF_PATH, "--set-rpath", rpath, dsoPath]) res = subprocess.run([PATCHELF_PATH, "--set-rpath", rpath] + dsoPaths)
if res.returncode != 0: if res.returncode != 0:
raise BaseException( raise BaseException(
f"Cannot patch {dsoPath}. Patchelf exited with {res.returncode}" f"Cannot patch {dsoPaths}. Patchelf exited with {res.returncode}"
) )