kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

03-pe-private-headers.sh (1245B)


      1 # Golden: objdump -p on a linked PE32+ executable. Asserts the
      2 # private-header walker prints the DOS/PE signature, optional-header
      3 # highlights, and at least one DLL import section. Gated on llvm-mingw
      4 # UCRT availability — most CI hosts won't have it.
      5 
      6 find_sdk() {
      7   local d
      8   for d in \
      9     /tmp/llvm-mingw*/llvm-mingw-*-ucrt-*/x86_64-w64-mingw32 \
     10     /tmp/llvm-mingw*/x86_64-w64-mingw32 \
     11     /private/tmp/llvm-mingw*/llvm-mingw-*-ucrt-*/x86_64-w64-mingw32 \
     12     /private/tmp/llvm-mingw*/x86_64-w64-mingw32; do
     13     if [ -d "$d/lib" ] && [ -r "$d/include/windows.h" ]; then
     14       printf '%s\n' "$d"
     15       return 0
     16     fi
     17   done
     18   return 1
     19 }
     20 
     21 SDK=$(find_sdk) || {
     22   echo "SKIP: no llvm-mingw UCRT sysroot"
     23   exit 0
     24 }
     25 
     26 cat > t.c <<'EOF'
     27 int main(void) { return 0; }
     28 EOF
     29 "$KIT" cc -target x86_64-windows --sysroot "$SDK" t.c -o t.exe
     30 "$KIT" objdump -p t.exe | awk '
     31 /PE32\+ private headers/ {print "found: PE32+ header line"; next}
     32 /^  Magic:/ {print $1, $2; next}
     33 /^  Subsystem:.*WINDOWS_CUI/ {print "subsystem: WINDOWS_CUI"; next}
     34 /^  DllCharacteristics:/ {print $1; next}
     35 /^Data Directories:/ {print; next}
     36 /^  Idx Name/ {print; next}
     37 /^The Import Tables:/ {print; next}
     38 /^  DLL Name: KERNEL32\.dll/ {print "import: KERNEL32.dll"; next}'