Guest User

Check SWF for ASC 2.0 Type Coercion Bug

a guest
Aug 9th, 2015
344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.63 KB | None | 0 0
  1. #!/bin/bash
  2. set -o nounset
  3.  
  4. if [ "$#" -ne 3 ]; then
  5.     echo -e "Usage:\n\t$0 <fla file OR folder containing xfl> <swf file> <linux ssh host with swfdump>\n"
  6.     exit 1;
  7. fi
  8.  
  9. FLA_PATH=$(pwd)/$1
  10.  
  11. SWF=$(basename "$2")
  12. SWF_PATH=$2
  13.  
  14. SWFDUMP_SERVER=$3
  15.  
  16. #
  17. # Create the test script and move it to the server with the swfdump tool installed
  18. #
  19.  
  20. LOCAL_SCRIPT_TMP=$(mktemp "${TMPDIR:-/tmp}"$(basename $0).XXXXXX)
  21.  
  22. cat <<-HERETO > $LOCAL_SCRIPT_TMP
  23. #!/bin/bash
  24. set -o nounset
  25.  
  26. ASSET_CLASS=\$1
  27. DUMP_FILE=\$2
  28.  
  29. EXPORT_ID=\$(grep "exports [0-9]\+ as \"\$ASSET_CLASS\"" \$DUMP_FILE | awk '{ print \$2 }')
  30.  
  31. if [ -z "\$EXPORT_ID" ]
  32. then
  33.     echo 0
  34.     exit
  35. fi
  36.  
  37. grep "places id \$EXPORT_ID .* name " \$DUMP_FILE |  wc | awk '{ print \$1 }'
  38. HERETO
  39.  
  40. REMOTE_SCRIPT_TMP=$(ssh $SWFDUMP_SERVER mktemp)
  41. scp $LOCAL_SCRIPT_TMP ${SWFDUMP_SERVER}:$REMOTE_SCRIPT_TMP
  42. ssh $SWFDUMP_SERVER chmod +x $REMOTE_SCRIPT_TMP
  43.  
  44. #
  45. # Copy the swf to the server and create a dump file
  46. #
  47.  
  48. REMOTE_SWF_TMP=$(ssh $SWFDUMP_SERVER mktemp)
  49. REMOTE_SWF_DUMP_TMP=$(ssh $SWFDUMP_SERVER mktemp)
  50.  
  51. scp "$SWF_PATH" ${SWFDUMP_SERVER}:$REMOTE_SWF_TMP
  52. ssh $SWFDUMP_SERVER swfdump -u "$REMOTE_SWF_TMP" \> $REMOTE_SWF_DUMP_TMP
  53.  
  54. if [ -d $FLA_PATH ]
  55. then
  56.     pushd $FLA_PATH > /dev/null
  57.     DELETE_FLA_TMP_FOLDER=false
  58. else
  59.     FLA_TMP_FOLDER=$(mktemp -d "${TMPDIR:-/tmp}"$(basename $0).XXXXXX)
  60.     DELETE_FLA_TMP_FOLDER=true
  61.  
  62.     pushd $FLA_TMP_FOLDER > /dev/null
  63.     unzip -qq "$FLA_PATH" 2>/dev/null
  64. fi
  65.  
  66. BUILD_BAD=false
  67.  
  68. FLA_ASSETS=$(find LIBRARY -name '*.xml' -exec grep -l linkageClassName {} \+ | sed 's/^LIBRARY\/\(.*\)\.xml/\1/')
  69.  
  70. IFS=$'\n'
  71. for FLA_ASSET in $FLA_ASSETS
  72. do
  73.     echo "Asset: $FLA_ASSET"
  74.  
  75.     #
  76.     # We only want to count named uses of the asset in assets that are in the swf via linkage name.
  77.     # Only assets referenced in the source will be linked into the swf.
  78.     #
  79.  
  80.     NAMED_BY_FLA_ASSETS=$(find LIBRARY -name '*.xml' -exec grep "libraryItemName=\"$FLA_ASSET\"" {} \+ | grep Instance | grep name=\" | sed 's/^LIBRARY\/\(.*\)\.xml.*/\1/' | sort -u)
  81.  
  82.     if [ -z "$NAMED_BY_FLA_ASSETS" ]
  83.     then
  84.         continue
  85.     fi
  86.  
  87.     NAMED_USES=0
  88.  
  89.     for NAMED_BY_FLA_ASSET in $NAMED_BY_FLA_ASSETS
  90.     do
  91.         NAMED_BY_FLA_ASSET_CLASS=$(grep linkageClassName "LIBRARY/${NAMED_BY_FLA_ASSET}.xml" | sed 's/.*linkageClassName="\([^"]*\)".*/\1/')
  92.  
  93.         LINKED=$(ssh $SWFDUMP_SERVER grep "\"exports .*$NAMED_BY_FLA_ASSET_CLASS\"" $REMOTE_SWF_DUMP_TMP | wc | awk '{ print $1 }')
  94.  
  95.         if [ "$LINKED" == 0 ]
  96.         then
  97.             echo "  named by $NAMED_BY_FLA_ASSET but $NAMED_BY_FLA_ASSET_CLASS is not linked in swf"
  98.         else
  99.             NAMED_USES=$((NAMED_USES + 1))
  100.         fi
  101.     done
  102.  
  103.     if [ "$NAMED_USES" == 0 ]
  104.     then
  105.         echo "  not named in swf."
  106.         continue
  107.     fi
  108.  
  109.     #
  110.     # The asset is named at least once in another asset that is linked into the swf.
  111.     #
  112.  
  113.     FLA_ASSET_CLASS=$(grep linkageClassName "LIBRARY/${FLA_ASSET}.xml" | sed 's/.*linkageClassName="\([^"]*\)".*/\1/')
  114.  
  115.     SWF_USES=$(ssh $SWFDUMP_SERVER $REMOTE_SCRIPT_TMP $FLA_ASSET_CLASS $REMOTE_SWF_DUMP_TMP)
  116.  
  117.     if [ "$SWF_USES" != 0 ] || [ "$NAMED_USES" != 0 ]
  118.     then
  119.         echo "  linked as $FLA_ASSET_CLASS with $NAMED_USES expected named uses, found $SWF_USES named uses in swf"
  120.     fi
  121.  
  122.     if [ "$SWF_USES" != "$NAMED_USES" ]
  123.     then
  124.         echo "  **** Bad ****"
  125.         BUILD_BAD=true
  126.     fi
  127. done
  128.  
  129. popd > /dev/null
  130.  
  131. #
  132. # Cleanup
  133. #
  134.  
  135. rm $LOCAL_SCRIPT_TMP
  136. if $DELETE_FLA_TMP_FOLDER
  137. then
  138.     rm -rf "$FLA_TMP_FOLDER"
  139. fi
  140.  
  141. if $BUILD_BAD
  142. then
  143.     echo "Swf:    $REMOTE_SWF_TMP"
  144.     echo "Dump:   $REMOTE_SWF_DUMP_TMP"
  145.     echo "Script: $REMOTE_SCRIPT_TMP"
  146.  
  147.     echo -e "\nBuild is bad."
  148.  
  149.     exit 2
  150. else
  151.     echo -e "\nBuild is good!"
  152.  
  153.     ssh $SWFDUMP_SERVER rm $REMOTE_SCRIPT_TMP $REMOTE_SWF_TMP $REMOTE_SWF_DUMP_TMP
  154. fi
Advertisement
Add Comment
Please, Sign In to add comment