Created
January 8, 2021 15:52
-
-
Save JCash/d8dbfb3fb5d25c9aaa60055d8ec55eec to your computer and use it in GitHub Desktop.
Unpacks a static library (.a) and strips all the debug symbols, then repacks the library again. Overwrites original file!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# usage: repack.sh file.a | |
# used on macOS | |
# Originally from https://stackoverflow.com/a/49632127/468516 | |
if [ -z "$1" ]; then | |
echo "usage: repack file.a" | |
exit 1 | |
fi | |
if [ -d tmprepack ]; then | |
/bin/rm -rf tmprepack | |
fi | |
mkdir tmprepack | |
cp $1 tmprepack | |
pushd tmprepack | |
basename=${1##*/} | |
ar xv $basename | |
/bin/rm -f $basename | |
ls -la . | |
i=1000 | |
for p in *.o ; do | |
if [[ $p == *.o ]]; then | |
strip -S $p | |
mv $p ${i}.o | |
((i++)) | |
fi | |
done | |
ar crus $basename *.o | |
mv $basename .. | |
popd | |
/bin/rm -rf tmprepack | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment