forked from threatrack/ghidra-fid-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path02-unpack-libs.sh
executable file
·30 lines (26 loc) · 970 Bytes
/
02-unpack-libs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
if [[ $# -ne 1 ]]; then
echo "usage: ${0} <lib>"
exit 1
fi
path="$(pwd)/${1}"
common="$(pwd)/${1}-common.txt"
cd "${path}"
find "$(pwd)" -regex ".*\.\(lib\|a\)" | while read lib; do
echo "${lib} ##########################################################"
subdir=$(echo "${lib}" | sed 's/\.\(a\|lib\)//g')
if ! 7z -y x "${lib}" -o"${subdir}"; then
echo "7z ERROR #####################################################"
mkdir "${subdir}"
fi
# fixup names. some .lib contain files with \ in names.
# 7z doesn't extract these to dirs but includes the \ in name
# for Ghidra \ = / ... so we must replace \ with _
find . -name '*\\*' -type f -exec bash -c 't="${0//\\//}"; mkdir -p "${t%/*}"; mv -v "$0" "$t"' {} \;
cd "${subdir}"
cat *.txt | awk '{print $2}' >> ${common}
find -type f -not -iname '*.o' -and -not -iname '*.obj' -exec rm {} \;
find -type l -exec rm {} \; # delete symlinks
rm -rf "${lib}"
done
sort -u ${common} -o ${common}