Skip to content

Instantly share code, notes, and snippets.

@arizvisa
Created March 28, 2019 16:58
Show Gist options
  • Save arizvisa/0be819aacc83f508ccc9c022ada236ba to your computer and use it in GitHub Desktop.
Save arizvisa/0be819aacc83f508ccc9c022ada236ba to your computer and use it in GitHub Desktop.
Generate a dependency graph for a bunch of PE (*.dll and *.exe) files linking imports to dlls and exports
(
echo 'digraph lamegraph {'
find . -name '*.exe' -type f -o -name '*.dll' -type f | while read fn; do
sn=$( basename "$fn" )
python $SYRINGE/tools/pe.py -Olist -e "$fn" | tr -d $'\r' | cut -d: -f3 | while read e; do
printf '"%s" -> "%s!%s";\n' "$sn" "$sn" "$e"
break
done
python $SYRINGE/tools/pe.py -Olist -i "$fn" | while IFS=: read i module; do
wtf=`echo -n "$module" | tr -d $'\r'`
python $SYRINGE/tools/pe.py -Olist -I $i "$fn" | cut -d' ' -f2 | cut -d: -f2 | while read name; do
printf '"%s!%s" -> "%s";\n' "$wtf" "$name" "$sn"
done
done
done
echo '}'
) | tee $yourfile.dot
@arizvisa
Copy link
Author

Point the SYRINGE variable at the base of https://github.com/arizvisa/syringe.git

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment