www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

compact-ndisasm.sh (728B)


      1 #!/bin/sh
      2 
      3 set -e
      4 
      5 in=$1
      6 out=$2
      7 
      8 # Add -s 0x1234 to te ndisasm command-line to specify that there is an
      9 # instruction starting at 0x1234. Use this when ndisasm misinterprets
     10 # some instructions due to db.
     11 skip="-s 0x16F40C -s 0x16F415 -s 0x16FBD0"
     12 for i in `seq 0 255`; do skip="$skip -s 0x7e$(printf %02x $i)"; done
     13 (echo "[BITS 16]"; \
     14  echo "[ORG 0x7c00]"; \
     15  ndisasm -s 0x7c78 $skip -o 0x7C00 -b 16 "$in" \
     16  | uniq -s 8 -c \
     17  | sed -e 's/^\s*1 //' -e 't' -e 's/^\s*\([0-9]\+\) \([^ ]\+\s\+[^ ]\+\s\+\)/\2times \1 /' \
     18  | sed -e 's/\([^ ]\+\s\+[0-9A-F]\{4\}\s\+j[^ ]\+ \)0x/\1short 0x/') > "$out"
     19 # The last sed line just above fixes an issue with ndisasm
     20 # (it fails to annotate jz and jnc (and possibly other) with short).