Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -o nounset
- if [ "$#" -ne 3 ]; then
- echo -e "Usage:\n\t$0 <fla file OR folder containing xfl> <swf file> <linux ssh host with swfdump>\n"
- exit 1;
- fi
- FLA_PATH=$(pwd)/$1
- SWF=$(basename "$2")
- SWF_PATH=$2
- SWFDUMP_SERVER=$3
- #
- # Create the test script and move it to the server with the swfdump tool installed
- #
- LOCAL_SCRIPT_TMP=$(mktemp "${TMPDIR:-/tmp}"$(basename $0).XXXXXX)
- cat <<-HERETO > $LOCAL_SCRIPT_TMP
- #!/bin/bash
- set -o nounset
- ASSET_CLASS=\$1
- DUMP_FILE=\$2
- EXPORT_ID=\$(grep "exports [0-9]\+ as \"\$ASSET_CLASS\"" \$DUMP_FILE | awk '{ print \$2 }')
- if [ -z "\$EXPORT_ID" ]
- then
- echo 0
- exit
- fi
- grep "places id \$EXPORT_ID .* name " \$DUMP_FILE | wc | awk '{ print \$1 }'
- HERETO
- REMOTE_SCRIPT_TMP=$(ssh $SWFDUMP_SERVER mktemp)
- scp $LOCAL_SCRIPT_TMP ${SWFDUMP_SERVER}:$REMOTE_SCRIPT_TMP
- ssh $SWFDUMP_SERVER chmod +x $REMOTE_SCRIPT_TMP
- #
- # Copy the swf to the server and create a dump file
- #
- REMOTE_SWF_TMP=$(ssh $SWFDUMP_SERVER mktemp)
- REMOTE_SWF_DUMP_TMP=$(ssh $SWFDUMP_SERVER mktemp)
- scp "$SWF_PATH" ${SWFDUMP_SERVER}:$REMOTE_SWF_TMP
- ssh $SWFDUMP_SERVER swfdump -u "$REMOTE_SWF_TMP" \> $REMOTE_SWF_DUMP_TMP
- if [ -d $FLA_PATH ]
- then
- pushd $FLA_PATH > /dev/null
- DELETE_FLA_TMP_FOLDER=false
- else
- FLA_TMP_FOLDER=$(mktemp -d "${TMPDIR:-/tmp}"$(basename $0).XXXXXX)
- DELETE_FLA_TMP_FOLDER=true
- pushd $FLA_TMP_FOLDER > /dev/null
- unzip -qq "$FLA_PATH" 2>/dev/null
- fi
- BUILD_BAD=false
- FLA_ASSETS=$(find LIBRARY -name '*.xml' -exec grep -l linkageClassName {} \+ | sed 's/^LIBRARY\/\(.*\)\.xml/\1/')
- IFS=$'\n'
- for FLA_ASSET in $FLA_ASSETS
- do
- echo "Asset: $FLA_ASSET"
- #
- # We only want to count named uses of the asset in assets that are in the swf via linkage name.
- # Only assets referenced in the source will be linked into the swf.
- #
- NAMED_BY_FLA_ASSETS=$(find LIBRARY -name '*.xml' -exec grep "libraryItemName=\"$FLA_ASSET\"" {} \+ | grep Instance | grep name=\" | sed 's/^LIBRARY\/\(.*\)\.xml.*/\1/' | sort -u)
- if [ -z "$NAMED_BY_FLA_ASSETS" ]
- then
- continue
- fi
- NAMED_USES=0
- for NAMED_BY_FLA_ASSET in $NAMED_BY_FLA_ASSETS
- do
- NAMED_BY_FLA_ASSET_CLASS=$(grep linkageClassName "LIBRARY/${NAMED_BY_FLA_ASSET}.xml" | sed 's/.*linkageClassName="\([^"]*\)".*/\1/')
- LINKED=$(ssh $SWFDUMP_SERVER grep "\"exports .*$NAMED_BY_FLA_ASSET_CLASS\"" $REMOTE_SWF_DUMP_TMP | wc | awk '{ print $1 }')
- if [ "$LINKED" == 0 ]
- then
- echo " named by $NAMED_BY_FLA_ASSET but $NAMED_BY_FLA_ASSET_CLASS is not linked in swf"
- else
- NAMED_USES=$((NAMED_USES + 1))
- fi
- done
- if [ "$NAMED_USES" == 0 ]
- then
- echo " not named in swf."
- continue
- fi
- #
- # The asset is named at least once in another asset that is linked into the swf.
- #
- FLA_ASSET_CLASS=$(grep linkageClassName "LIBRARY/${FLA_ASSET}.xml" | sed 's/.*linkageClassName="\([^"]*\)".*/\1/')
- SWF_USES=$(ssh $SWFDUMP_SERVER $REMOTE_SCRIPT_TMP $FLA_ASSET_CLASS $REMOTE_SWF_DUMP_TMP)
- if [ "$SWF_USES" != 0 ] || [ "$NAMED_USES" != 0 ]
- then
- echo " linked as $FLA_ASSET_CLASS with $NAMED_USES expected named uses, found $SWF_USES named uses in swf"
- fi
- if [ "$SWF_USES" != "$NAMED_USES" ]
- then
- echo " **** Bad ****"
- BUILD_BAD=true
- fi
- done
- popd > /dev/null
- #
- # Cleanup
- #
- rm $LOCAL_SCRIPT_TMP
- if $DELETE_FLA_TMP_FOLDER
- then
- rm -rf "$FLA_TMP_FOLDER"
- fi
- if $BUILD_BAD
- then
- echo "Swf: $REMOTE_SWF_TMP"
- echo "Dump: $REMOTE_SWF_DUMP_TMP"
- echo "Script: $REMOTE_SCRIPT_TMP"
- echo -e "\nBuild is bad."
- exit 2
- else
- echo -e "\nBuild is good!"
- ssh $SWFDUMP_SERVER rm $REMOTE_SCRIPT_TMP $REMOTE_SWF_TMP $REMOTE_SWF_DUMP_TMP
- fi
Advertisement
Add Comment
Please, Sign In to add comment