Skip to content
strip-all.sh 1.3 KiB
Newer Older
#!/bin/bash
# With this step, we remove some additional debug infos from binaries, that, if
# present, some decompilers take advantage to perform optimizations orthogonal
# to our evaluation purposes.

if [ $# -eq 0 ]; then
  echo "No arguments supplied"
  exit 1
fi

arch=$1
basepath=$(pwd)
workdir=$basepath/workdir-$arch
stripped_dir=$workdir/stripped

if [ ! -d $stripped_dir ]; then
  mkdir $stripped_dir;
fi

cd $arch

# Use the `objcopy` tool to remove the `.dynstr` section from the ELF
for filename in *
do
  echo "Removing the .dynstr section from the ELF"
  if [[ "$arch" == "x86-64"* ]]; then
    cp $filename $stripped_dir/$filename.stripped
    $basepath/scripting/ida-extraction-scripts/elf-replace-dynstr.py $stripped_dir/$filename.stripped
  else
    echo "Unsupported architecture"
    exit 1
  fi
done;

# Use the `strip` tool to remove dbg info
for filename in *
do
  echo "Stripping input: $filename"
  if [[ "$arch" == "x86-64"* ]]; then
    strip --strip-debug $stripped_dir/$filename.stripped
  elif [[ "$arch" == "arm"* ]]; then
    armv7a-hardfloat-linux-uclibceabi-strip --strip-debug $stripped_dir/$filename.stripped
  elif [[ "$arch" == "mips"* ]]; then
    mips-unknown-linux-musl-strip --strip-debug $stripped_dir/$filename.stripped
  else
    echo "Unsupported architecture"
    exit 1
  fi
done;