extract-vsssdk-headers 937 B

1234567891011121314151617181920212223242526272829303132333435
  1. #! /bin/bash
  2. # extract-vsssdk-headers
  3. # Author: Paolo Bonzini <pbonzini@redhat.com>
  4. set -e
  5. if test $# != 1 || ! test -f "$1"; then
  6. echo 'Usage: extract-vsssdk-headers /path/to/setup.exe' >&2
  7. exit 1
  8. fi
  9. if ! command -v msiextract > /dev/null; then
  10. echo 'msiextract not found. Please install msitools.' >&2
  11. exit 1
  12. fi
  13. if test -e inc; then
  14. echo '"inc" already exists.' >&2
  15. exit 1
  16. fi
  17. # Extract .MSI file in the .exe, looking for the OLE compound
  18. # document signature. Extra data at the end does not matter.
  19. export LC_ALL=C
  20. MAGIC=$'\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1'
  21. offset=$(grep -abom1 "$MAGIC" "$1" | sed -n 's/:/\n/; P')
  22. tmpdir=$(mktemp -d)
  23. trap 'rm -fr -- "$tmpdir" vsssdk.msi' EXIT HUP INT QUIT ALRM TERM
  24. tail -c +$(($offset+1)) -- "$1" > vsssdk.msi
  25. # Now extract the files.
  26. msiextract -C $tmpdir vsssdk.msi
  27. mv "$tmpdir/Program Files/Microsoft/VSSSDK72/inc" inc
  28. echo 'Extracted SDK headers into "inc" directory.'
  29. exit 0