function loadFile($fileName) { $result = parent::loadFile($fileName); if (PEAR::isError($result)) { return $result; } // Fix any wrong-case clickTAG if (phpAds_SWFCompressed($this->content)) { $buffer = phpAds_SWFDecompress($this->content); $buffer = preg_replace('/clickTAG/i', 'clickTAG', $buffer); $this->content = phpAds_SWFCompress($buffer); } else { $this->content = preg_replace('/clickTAG/i', 'clickTAG', $this->content); } return true; }
function phpAds_SWFConvert($buffer, $compress, $allowed) { global $swf_variable, $swf_target_var; // Decompress if file is a Flash MX compressed file if (phpAds_SWFCompressed($buffer)) { $buffer = phpAds_SWFDecompress($buffer); } $parameters = array(); $linkcount = 1; $allowedcount = 1; $final = $buffer; while (preg_match('/ # begin ^ ( .+? # match anything from the start \\x00 # match a swf_tag_null ) ( \\x83 # match a swf_tag_geturl .. # match a UI16 (combined length) ( (?:https?:\\/\\/|javascript:).+? # match the url ) \\x00 # match a swf_tag_null ( .*? # match the target ) \\x00 # match a swf_tag_null | # or \\x96 # match a swf_tag_actionpush .. # match a U16 word (length) \\x00 # match a swf_tag_null ( (?:https?:\\/\\/|javascript:).+? # match the url ) \\x00 # match a swf_tag_null \\x96 # match a swf_tag_actionpush .. # match a UI16 (length) \\x00 # match a swf_tag_null ( .*? # match the target ) \\x00 # match a swf_tag_null \\x9A\\x01 # match a swf_tag_geturl2 ) /sx', $buffer, $m)) { $geturl_part = $m[2]; $previous_part = $m[1]; $allowed_types = array(12, 26, 34); // DoAction, PlaceObject2, DefineButton2 $original = ''; for ($len = 2; $len < strlen($previous_part); $len++) { $recordheader = substr($previous_part, -$len); $object_tag = substr($recordheader, 0, 2); $expected_len = strlen($geturl_part) + $len; $tag_type = (ord($object_tag[1]) << 2 | (ord($object_tag[0]) & ~0x3f) >> 6) & 0xff; if (!in_array($tag_type, $allowed_types)) { continue; } // Check for long RECORDHEADER if ($len > 6 && (ord($object_tag[0]) & 0x3f) == 0x3f) { $object_extended = true; $object_len = unpack('V', substr($recordheader, 2, 4)); $object_len = current($object_len); $expected_len -= 6; } else { $object_extended = false; $object_len = ord($object_tag[0]) & 0x3f; $expected_len -= 2; } if ($object_len >= $expected_len) { $original = $replacement = $recordheader . $geturl_part; break; } } if (!strlen($original)) { die("Error: unsupported tag"); } $geturl2_part = swf_tag_actionpush . chr(strlen('_root') + 2) . swf_tag_null . swf_tag_null . '_root' . swf_tag_null . swf_tag_actiongetvariable . swf_tag_actionpush . chr(strlen($swf_variable . $linkcount) + 2) . swf_tag_null . swf_tag_null . $swf_variable . $linkcount . swf_tag_null . swf_tag_actiongetmember . swf_tag_actionpush . chr(strlen('_root') + 2) . swf_tag_null . swf_tag_null . '_root' . swf_tag_null . swf_tag_actiongetvariable . swf_tag_actionpush . chr(strlen($swf_target_var . $linkcount) + 2) . swf_tag_null . swf_tag_null . $swf_target_var . $linkcount . swf_tag_null . swf_tag_actiongetmember . swf_tag_actiongeturl2 . swf_tag_null . swf_tag_null; if (preg_match('/(\\x9B(..).*?)(..)$/s', $previous_part, $m)) { $fheader_len = unpack('v', $m[2]); $fheader_len = current($fheader_len); $fbody_len = unpack('v', $m[3]); $fbody_len = current($fbody_len); if ($fheader_len == strlen($m[1]) - 1) { // getURL is inside an ActionDefineFunction $fbody_len += strlen($geturl2_part) - strlen($geturl_part); $geturl_part = $m[0] . $geturl_part; $geturl2_part = $m[1] . pack('v', $fbody_len) . $geturl2_part; } } $replacement = str_replace($geturl_part, $geturl2_part, $replacement); $object_len2 = $object_len + strlen($geturl2_part) - strlen($geturl_part); $replacement = substr($replacement, $object_extended ? 6 : 2); if ($object_len2 < 0x3f) { $replacement = chr(0x80 | $object_len2) . $object_tag[1] . $replacement; } else { $replacement = chr(ord($object_tag[0]) | 0x3f) . $object_tag[1] . pack('V', $object_len2) . $replacement; } // Is this link allowed to be converted? if (in_array($allowedcount, $allowed)) { // Convert $final = str_replace($original, $replacement, $final); // Fix file size $file_size = unpack('V', substr($final, 4, 4)); $file_size = current($file_size) + strlen($replacement) - strlen($original); $final = substr($final, 0, 4) . pack('V', $file_size) . substr($final, 8); $parameters[$linkcount] = $allowedcount; $linkcount++; } $allowedcount++; $buffer = str_replace($original, '', $buffer); } if ($compress == true) { $final = phpAds_SWFCompress($final); } else { $final = phpAds_SWFUpgrade($final); } return array($final, $parameters); }
} else { // Banner is not a flash banner, return to banner-edit.php header("Location: banner-edit.php?clientid=" . $clientid . "&campaignid=" . $campaignid . "&bannerid=" . $bannerid); exit; } } else { // Banner does not exist, return to banner-edit.php header("Location: banner-edit.php?clientid=" . $clientid . "&campaignid=" . $campaignid); exit; } /*********************************************************/ /* Main code */ /*********************************************************/ $result = phpAds_SWFInfo($swf_file); $version = phpAds_SWFVersion($swf_file); $compressed = phpAds_SWFCompressed($swf_file); if ($result) { echo $strConvertSWF . '<br>'; echo "<table border='0' width='100%' cellpadding='0' cellspacing='0' bgcolor='#F6F6F6'>"; echo "<form action='banner-swf.php' method='post'>"; echo "<input type='hidden' name='clientid' value='{$clientid}'>"; echo "<input type='hidden' name='campaignid' value='{$campaignid}'>"; echo "<input type='hidden' name='bannerid' value='{$bannerid}'>"; echo "<tr><td height='25' colspan='4' bgcolor='#FFFFFF'><img src='images/" . $phpAds_TextDirection . "/icon-undo.gif' align='absmiddle'> <b>" . $strHardcodedLinks . "</b></td></tr>"; echo "<tr><td height='1' colspan='4' bgcolor='#888888'><img src='images/break.gif' height='1' width='100%'></td></tr>"; echo "<tr><td height='10' colspan='4'> </td></tr>"; $i = 0; while (list($key, $val) = each($result)) { list($url, $target) = $val; if ($i > 0) { echo "<tr><td height='20' colspan='4'> </td></tr>";
function phpAds_SWFConvert($buffer, $compress, $allowed) { global $swf_variable, $swf_target_var; // Decompress if file is a Flash MX compressed file if (phpAds_SWFCompressed($buffer)) { $buffer = phpAds_SWFDecompress($buffer); } $parameters = array(); $pos = 0; $linkcount = 1; $allowedcount = 1; while ($result = strpos($buffer, swf_tag_geturl, $pos)) { $result++; if (strtolower(substr($buffer, $result + 3, 7)) == 'http://' || strtolower(substr($buffer, $result + 3, 11)) == 'javascript:') { $parameter_length = ord(substr($buffer, $result + 1, 1)); $parameter_total = substr($buffer, $result + 3, $parameter_length); $parameter_split = strpos($parameter_total, swf_tag_null); $parameter_url = substr($parameter_total, 0, $parameter_split); $parameter_target = substr($parameter_total, $parameter_split + 1, strlen($parameter_total) - $parameter_split - 2); $replacement = swf_tag_actionpush . chr(strlen($swf_variable . $linkcount) + 2) . swf_tag_null . swf_tag_null . $swf_variable . $linkcount . swf_tag_null . swf_tag_actiongetvariable . swf_tag_actionpush . chr(strlen($swf_target_var . $linkcount) + 2) . swf_tag_null . swf_tag_null . $swf_target_var . $linkcount . swf_tag_null . swf_tag_actiongetvariable . swf_tag_actiongeturl2; if (strlen($replacement) > $parameter_length + 3) { break; } elseif (strlen($replacement) < $parameter_length + 3) { $padding = $parameter_length + 3 - strlen($replacement); for ($i = 0; $i < $padding; $i++) { $replacement .= swf_tag_null; } } // Is this link allowed to be converted? if (in_array($allowedcount, $allowed)) { // Convert $replacement = substr($buffer, 0, $result) . $replacement . substr($buffer, $result + strlen($replacement), strlen($buffer) - ($result + strlen($replacement))); $buffer = $replacement; $parameters[$linkcount] = $allowedcount; $linkcount++; } $allowedcount++; } $pos = $result; } if ($compress == true) { $buffer = phpAds_SWFCompress($buffer); } return array($buffer, $parameters); }