rulimine/stage23/gensyms.sh

49 lines
957 B
Bash
Raw Normal View History

2022-01-21 04:24:36 +03:00
#! /bin/sh
2021-02-25 03:24:54 +03:00
set -e
2022-01-21 04:24:36 +03:00
export LC_ALL=C
TMP0=$(mktemp)
2021-08-07 08:26:34 +03:00
cat >"$TMP0" <<EOF
#! /bin/sh
set -e
set -o pipefail 2>/dev/null
EOF
chmod +x "$TMP0"
"$TMP0" && set -o pipefail
rm "$TMP0"
2021-02-25 03:24:54 +03:00
TMP1=$(mktemp)
TMP2=$(mktemp)
TMP3=$(mktemp)
TMP4=$(mktemp)
2021-07-26 19:27:05 +03:00
$1 -t "$2" | ( sed '/[[:<:]]d[[:>:]]/d' 2>/dev/null || sed '/\bd\b/d' ) | sort > "$TMP1"
2021-02-25 03:24:54 +03:00
grep "\.text" < "$TMP1" | cut -d' ' -f1 > "$TMP2"
grep "\.text" < "$TMP1" | awk 'NF{ print $NF }' > "$TMP3"
echo "section .$3_map" > "$TMP4"
2021-02-25 03:24:54 +03:00
echo "global $3_map" >> "$TMP4"
echo "$3_map:" >> "$TMP4"
2021-04-08 02:15:35 +03:00
if [ "$4" = "32" ]; then
2021-07-26 19:27:05 +03:00
paste -d'$' "$TMP2" "$TMP3" | sed 's/^/dd 0x/g;s/$/", 0/g;s/\$/\
db "/g' >> "$TMP4"
2021-04-08 02:15:35 +03:00
echo "dd 0xffffffff" >> "$TMP4"
nasm -f elf32 "$TMP4" -o $3.map.o
elif [ "$4" = "64" ]; then
2021-07-26 19:27:05 +03:00
paste -d'$' "$TMP2" "$TMP3" | sed 's/^/dq 0x/g;s/$/", 0/g;s/\$/\
db "/g' >> "$TMP4"
2021-04-08 02:15:35 +03:00
echo "dq 0xffffffffffffffff" >> "$TMP4"
nasm -f elf64 "$TMP4" -o $3.map.o
fi
2021-02-25 03:24:54 +03:00
rm "$TMP1" "$TMP2" "$TMP3" "$TMP4"