Skip to content

Commit

Permalink
fix: ldd was not always found
Browse files Browse the repository at this point in the history
  • Loading branch information
blackandred committed Mar 24, 2022
1 parent a49254c commit 4d6e9a8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
4 changes: 4 additions & 0 deletions assets/extraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ import (
func UnpackAll(targetDir string) (bool, error) {
var hasAtLeastOneError bool

if err := os.RemoveAll(targetDir); err != nil {
return false, errors.Wrapf(err, "Cannot delete temporary directory at path: '%s'", targetDir)
}

if err := os.MkdirAll(targetDir, 0755); err != nil {
return false, errors.Wrapf(err, "Cannot create directory '%s'", targetDir)
}
Expand Down
26 changes: 18 additions & 8 deletions hack/get-binary-with-libs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,24 @@ def copy_dependencies_for_path(bin_path: str, target_dir: str, depth: int = 0):
print(ldd)

for line in ldd:
if not line.strip() or "=>" not in line:
is_static_ld = "=>" not in line and "ld-" in line

if not line.strip() or ("=>" not in line and not is_static_ld):
continue

try:
parsed = re.findall('=>\s*([/A-Za-z\-_.0-9]+)\ ', line)
orig_name = re.findall('\s*([A-Za-z\-_.0-9]+)\s*=>', line)
finally:
print(">> Line caused error: ", line)
if is_static_ld:
parsed = re.findall('\s*([\/A-Za-z\-_.0-9]+)\ ', line)
orig_name = os.path.basename(parsed[0])
else:
try:
parsed = re.findall('=>\s*([\/A-Za-z\-_.0-9]+)\ ', line)
orig_name = re.findall('\s*([A-Za-z\-_.0-9]+)\s*=>', line)
except Exception as e:
print(">> Line caused error: ", line)
print(" Exception: ", e)
raise

orig_name = orig_name[0]
orig_name = orig_name[0]

if parsed[0] == "ldd":
# ['\tldd (0x7f5a18c9c000)', '\tlibc.musl-x86_64.so.1 => ldd (0x7f5a18c9c000)', '']
Expand All @@ -46,7 +54,9 @@ def copy_dependencies_for_path(bin_path: str, target_dir: str, depth: int = 0):
real_path = subprocess.check_output(['readlink', '-f', parsed[0]]).decode('utf-8').strip()
print((" " * depth * 2) + f">> Copying {real_path} -> {orig_name}")
subprocess.check_call(['cp', real_path, target_dir + "/" + orig_name])
copy_dependencies_for_path(real_path, target_dir, depth + 1)

if not is_static_ld:
copy_dependencies_for_path(real_path, target_dir, depth + 1)

ALREADY_COPIED.append(bin_path)

Expand Down

0 comments on commit 4d6e9a8

Please sign in to comment.