Skip to content
ida-normalizer-wrapper.sh 1.01 KiB
Newer Older
#!/bin/bash

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

filename=$1
iteration=0
max_iteration=15

# Invoke a script which performs ad-hoc normalization for this decompiled output.
./ida-normalizer-pre.sh $filename

# First invocation of the compiler
clang-7 -ferror-limit=0 -S -emit-llvm -w $filename &> clang.log

# While we have errors output from the compiler, continue our fixed-point purge.
while [ -s clang.log ]; do

  # Invoke the script that, on the basis of the compiler output generated at the previous iteration, purges the decompiled file.
  ./ida-normalizer.sh $filename clang.log

  # Invoke the compiler.
  clang-7 -ferror-limit=0 -S -emit-llvm -w $filename &> clang.log
  iteration=$((iteration + 1))

  # Exit if we did not reach stability in an high number of runs (cheap way to detect instability).
  if [ "$iteration" -gt "$max_iteration" ]; then
    echo "Stability not reached"
    break
  fi
done

# Finally, create the output adding an adequate suffix.
cp $filename $filename.normalized.c