SWF 如何将内容注入网页

How can a SWF inject content into a webpage

本文关键字:注入 网页 SWF      更新时间:2023-09-26

通过嵌入以下 SWF 代码,当在单个页面中运行时,新标签会出现所需的 URL 和顶部的广告栏。无需用户交互。

<embed width="1" height="1" align="middle"
       pluginspage="http://www.macromedia.com/go/getflashplayer"
       type="application/x-shockwave-flash" allowscriptaccess="sameDomain"
       name="blog" bgcolor="000000" wmode="transparent" quality="high"
       src="http://i1177.photobucket.com/albums/x348/hosting504/red.swf" 
       flashvars="web=www.agitehabbero.com/index.php&creador=supercito">

如果将代码嵌入到框架中,则不会创建新选项卡,而是修改框架以添加 html 页面。

编辑:页面上没有JAVASCRIPT。

SWF 文件如何做到这一点?(将内容注入网页)?

此 ActionScript3.0 代码将注入一个匿名函数,然后在传递单个参数"hello"时执行它: ExternalInterface.call("function(msg){ alert(msg); }", "hello");(这像这个Javascript代码一样执行:function(msg){ alert(msg); }("hello");)。

由于可以注入代码,因此可以编写代码来操作文档(添加元素、修改样式、更改元素值等)。例如,此 AS3 代码:ExternalInterface.call("function(){ document.write('"Hello, world!'"); }");将在 HTML 页面上显示"Hello, world!

另外,从文档中:

  • 在包含的 HTML 页面中 SWF 文件的对象标记中,设置以下参数: <param name="allowScriptAccess" value="always" />
  • 在 SWF 文件中,添加以下操作脚本: flash.system.Security.allowDomain(sourceDomain)

我测试了上述所有内容,它在我的浏览器上运行良好:Google Chrome 19,Internet Explorer 8,Firefox 12。

按照您的要求,文档端没有 javascript :)

在 AS 中有一个名为 ExternalInterface 的类。它有助于闪存与JS通信(调用js函数或JS调用闪存函数)。然后抛出 DOM 可以将内容添加到页面中。可能是这个。

一个例子

AS3

package {
    import flash.display.Sprite;
    import flash.external.ExternalInterface;
    import flash.events.*;
    public class MyApp extends Sprite {
        private var btn:Sprite;
        public function MyApp() {
            //add an entry point from js (html page) to swf, so js can call the swfFunc
            ExternalInterface.addCallback('swfFunc', swfFunc);
            btn = new Sprite();
            btn.mouseEnabled = true;
            btn.x = 0;
            btn.graphics.beginFill(0xFF0000, 0);
            btn.graphics.drawRect(0, 0, 300, 50);
            btn.graphics.endFill();
            btn.addEventListener(MouseEvent.CLICK, jsFunc);
            addChild(btn);
        }
        public function jsFunc(evt:MouseEvent):void {
            // call the js function named jsFunc 
            ExternalInterface.call('jsFunc', 'Test JS');
        }
        //this method is called from the js
        public function swfFunc(text:String):void {
            trace(text);
        }
    }
}

.HTML

<object id='MySWF' type='application/x-shockwave-flash' data='MyApp.swf' width='300' height='50'>
    <param name='movie' value='MyApp.swf' />
    <param name='allowscriptaccess' value='always' />
    <param name='swliveconnect' value='true' />
</object>
<div id="container">
    A Text
</div>
<button type="button" onclick="swfFunc();">Call SWF</button>

.JS

function jsFunc(text) {
    document.getElementById('container').innerHTML = text;
}
function swfFunc() {
    var swfObj =  window['MySWF'] || documment['MySWF'];
    swfObj.swfFunc('Test SWF');
}

知道了!
没有Javascript,就像你说的。
偷偷摸摸的代码,我不完全明白为什么,但设法让它工作。下载并反编译 red.swf,有 2 帧,只有第二个有以下代码(评论是我的)

    /*
flashvars are loaded to the _root as following:
_root.web = www.agitehabbero.com/index.php&creador=supercito
oddly the amperesand (&) gets interpreted too so we also get.
_root.creador=supercito
*/
    stop();
    var url = _root.web;
    if ("supercito" == _root.creador) {//verifies that the url passed has a value pair creador=supercito I guess to avoid it being used for something else?
        getURL ("http://supercito.com.ar/g3/web.php?url=" + url, "glu");
        /* the getURL calls this site, in a new window (frames are treated as windows by browsers) 
        somehow flash , as it doesn't find the frame or window, converts it into a pop up */
    } else {
        getURL ("http://supercito.com.ar/404", "glu");
    }

哦,这几乎不是ActionScript 2,看起来像AS1(使用相同的VM)。

为了进一步测试,我简化了闪存代码并上传到服务器:

stop();
getURL ("http://supercito.com.ar/g3/web.php?url=" + _root.web, _root.marco);

现在在服务器中,我们可以玩不同的输入,看看会发生什么。链接是:http://m0.cl/t/dwit/assets/no-usar/testing-odd.php

(对不起,我正在处理其他事情的混乱地址)
如果我们对框架参数使用任何值,则 http://supercito.com.ar 页面加载并使窗口成为弹出窗口,除非我们使用_self。
问题是我看不到这个新窗口变成弹出窗口的部分,也许它隐藏在它加载的 jquery 文件中。打败我。甚至与查尔斯核实过。如果有人有想法,请告诉我,我会尝试。
希望这有帮助。
这是我在这里的第一篇文章:)

编辑:
我上传了一个修改以获得更好的测试。
现在我们也可以更改主 URL。

stop();
getURL (_root.main + _root.web, _root.marco);


编辑 Nº2
是闪光灯!
使用新设置,您可以尝试任何URL,只要目标窗口不_self或_top,它就会将其变成弹出窗口,问题是,Chrome将其解释为弹出窗口,但IE只是将其读取为_blank窗口。
对我来说看起来像一个错误。

几种方法可以从Flash打开新的浏览器窗口(没有HTML页面的帮助): http://helpx.adobe.com/flash-player/kb/create-pop-browser-windows-flash.html

不确定这是否可能。

现代浏览器具有相当强大的弹出窗口阻止程序,在大多数情况下,如果没有用户交互,则不允许打开新窗口/选项卡。

即使您设法欺骗了一个浏览器,它也可能无法在不同的浏览器/操作系统中工作。

顺便说一句,如果页面上没有JS,并且您无法编辑HTML,则可以使用"伪协议"直接从Flash运行JS:

var req:URLRequest = new URLRequest('javascript:void(alert('This is called from Flash'))');
navigateToURL(req);

因此,从理论上讲,您可以将非常复杂的JS"注入"到HTML页面上。

首先,你应该确保你使用的是window.top.document。 从那里尝试打开窗口 - 如果您的窗口句柄为空,则打开 100% iframe。

    /**
     *  @public
     */
    public function JSTest():void {
        ExternalInterface.call('eval', [
            "window.createFrame = function() {",
                "var doc                = window.top.document;",
                "var ifrm               = doc.createElement('IFRAME');",
                "ifrm.style.position    = 'absolute';",
                "ifrm.style.left        = '0';",
                "ifrm.style.top         = '0';",
                "ifrm.style.width       = '100%';",
                "ifrm.style.height      = '100%';",
                "ifrm.setAttribute('src', 'http://vimeo.com');",
                "doc.body.appendChild(ifrm);",
            "}",
            // try opening window, otherwise, open an iframe
            "if (!window.open('http://www.vimeo.com', '_top')) {",
                "window.createFrame();",
            "}"
        ].join(''n'));
    }