Check cygwin apps for base conflicts

/ Published in: Bash
Save to your folder(s)

From: "Pierre A. Humblet"
The attached script takes the name of a .exe or .dll,
uses cygcheck to find the dll dependence and checks for conflicts.

This will allow you to check your favorite applications or dlls,
seeing if --enable-auto-image-base works for you.

A "conflict" is when the end of a dll overlaps the start of the next one.
A "guard conflict" includes the extra 0x10000 mentioned by Jason in this thread.
They occur with Windows dlls, not sure if that's a real issue.

I have extended the tool (attached) so that it takes a variable number
of arguments. You can check a program and all the dll's it might ever
load dynamically, or all the dll's in /bin, or whatever.
cygcheck will search the PATH if necessary.

Copy this code and paste it in your HTML
  1. #! /bin/bash
  3. # Checks for conflicts between all dll's that are loaded by the programs or dlls given as arguments.
  4. # cygcheck searches PATH to find arguments that are not absolute pathnames.
  6. final_dec=0
  7. final_guard_dec=0
  8. guard=0x10000
  10. #set -x
  12. cygcheck "[email protected]" |
  13. while read -r file
  14. do
  15. [ -n "$file" ] && [ "$file" = "${file#Found:}" ] && objdump -p "$file" |
  16. sed -n -e '2 {s:\\:/:g; s/^/ /; s/: .*$//; h}' -e '/ImageBase/ {s/ImageBase/ /; G; h}' -e '/SizeOfImage/ {s/SizeOfImage//; G; s/[\t\n]//gp; Q}'
  17. done |
  18. sort -f -u -k 2 |
  19. while read size base name
  20. do
  21. conflict=""
  22. base_dec=$(( 0x$base ))
  23. if [ "$final_dec" -ge "$base_dec" ]
  24. then
  25. conflict="CONFLICT End: $final_dec Start:$base_dec"
  26. else
  27. [ "$final_guard_dec" -ge "$base_dec" ] && conflict="GUARD CONFLICT End: $final_dec Start:$base_dec"
  28. fi
  29. echo $name $base $size $conflict
  30. final_dec=$(( 0x$base + 0x$size ))
  31. final_guard_dec=$(( $final_dec + $guard ))
  32. done

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.