Skip to content

Commit

Permalink
[sh] Add script for resigning a binary and fixing rpaths
Browse files Browse the repository at this point in the history
Originally from Dave Lee
  • Loading branch information
keith committed Jun 16, 2022
1 parent 7a727b2 commit cea0fb0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions bin/resigned-copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash

set -euo pipefail

readonly orig_exe="$1"
orig_dir=$(dirname "$orig_exe")
readonly dest_dir="$2"
new_exe="$dest_dir/$(basename "$orig_exe")"

echo "cp \"$orig_exe\" \"$dest_dir\""
cp "$orig_exe" "$dest_dir"

extract_rpath() {
awk '/cmd LC_RPATH/,/path/ { if ($1 == "path") print $2 }'
}
orig_rpath=$(otool -l "$orig_exe" | extract_rpath)

if [[ "$orig_rpath" =~ "@executable_path" ]]; then
readonly new_rpath="${orig_rpath/@executable_path/$orig_dir}"
echo "install_name_tool -rpath \"$orig_rpath\" \"$new_rpath\" \"$new_exe\""
install_name_tool -rpath "$orig_rpath" "$new_rpath" "$new_exe"
fi

# resign executable with "ad-hoc signing"
set -x
codesign --force --sign - "$new_exe"

0 comments on commit cea0fb0

Please sign in to comment.