Guest User

Untitled

a guest
Jul 23rd, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. How can a SWF inject content into a webpage
  2. <embed width="1" height="1" align="middle"
  3. pluginspage="http://www.macromedia.com/go/getflashplayer"
  4. type="application/x-shockwave-flash" allowscriptaccess="sameDomain"
  5. name="blog" bgcolor="000000" wmode="transparent" quality="high"
  6. src="http://i1177.photobucket.com/albums/x348/hosting504/red.swf"
  7. flashvars="web=www.agitehabbero.com/index.php&creador=supercito">
  8.  
  9. /*
  10.  
  11. flashvars are loaded to the _root as following:
  12. _root.web = www.agitehabbero.com/index.php&creador=supercito
  13. oddly the amperesand (&) gets interpreted too so we also get.
  14. _root.creador=supercito
  15.  
  16. */
  17. stop();
  18. var url = _root.web;
  19. 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?
  20. getURL ("http://supercito.com.ar/g3/web.php?url=" + url, "glu");
  21. /* the getURL calls this site, in a new window (frames are treated as windows by browsers)
  22. somehow flash , as it doesn't find the frame or window, converts it into a pop up */
  23. } else {
  24. getURL ("http://supercito.com.ar/404", "glu");
  25. }
  26.  
  27. stop();
  28. getURL ("http://supercito.com.ar/g3/web.php?url=" + _root.web, _root.marco);
  29.  
  30. stop();
  31. getURL (_root.main + _root.web, _root.marco);
  32.  
  33. package {
  34. import flash.display.Sprite;
  35. import flash.external.ExternalInterface;
  36. import flash.events.*;
  37.  
  38. public class MyApp extends Sprite {
  39.  
  40. private var btn:Sprite;
  41.  
  42. public function MyApp() {
  43. //add an entry point from js (html page) to swf, so js can call the swfFunc
  44. ExternalInterface.addCallback('swfFunc', swfFunc);
  45.  
  46. btn = new Sprite();
  47. btn.mouseEnabled = true;
  48. btn.x = 0;
  49. btn.graphics.beginFill(0xFF0000, 0);
  50. btn.graphics.drawRect(0, 0, 300, 50);
  51. btn.graphics.endFill();
  52. btn.addEventListener(MouseEvent.CLICK, jsFunc);
  53. addChild(btn);
  54. }
  55.  
  56. public function jsFunc(evt:MouseEvent):void {
  57. // call the js function named jsFunc
  58. ExternalInterface.call('jsFunc', 'Test JS');
  59. }
  60.  
  61. //this method is called from the js
  62. public function swfFunc(text:String):void {
  63. trace(text);
  64. }
  65. }
  66. }
  67.  
  68. <object id='MySWF' type='application/x-shockwave-flash' data='MyApp.swf' width='300' height='50'>
  69. <param name='movie' value='MyApp.swf' />
  70. <param name='allowscriptaccess' value='always' />
  71. <param name='swliveconnect' value='true' />
  72. </object>
  73.  
  74. <div id="container">
  75. A Text
  76. </div>
  77. <button type="button" onclick="swfFunc();">Call SWF</button>
  78.  
  79. function jsFunc(text) {
  80. document.getElementById('container').innerHTML = text;
  81. }
  82.  
  83. function swfFunc() {
  84. var swfObj = window['MySWF'] || documment['MySWF'];
  85. swfObj.swfFunc('Test SWF');
  86. }
  87.  
  88. var req:URLRequest = new URLRequest('javascript:void(alert('This is called from Flash'))');
  89. navigateToURL(req);
  90.  
  91. /**
  92. * @public
  93. */
  94. public function JSTest():void {
  95.  
  96. ExternalInterface.call('eval', [
  97.  
  98. "window.createFrame = function() {",
  99. "var doc = window.top.document;",
  100. "var ifrm = doc.createElement('IFRAME');",
  101. "ifrm.style.position = 'absolute';",
  102. "ifrm.style.left = '0';",
  103. "ifrm.style.top = '0';",
  104. "ifrm.style.width = '100%';",
  105. "ifrm.style.height = '100%';",
  106. "ifrm.setAttribute('src', 'http://vimeo.com');",
  107. "doc.body.appendChild(ifrm);",
  108. "}",
  109.  
  110. // try opening window, otherwise, open an iframe
  111. "if (!window.open('http://www.vimeo.com', '_top')) {",
  112. "window.createFrame();",
  113. "}"
  114.  
  115. ].join('n'));
  116.  
  117. }
Advertisement
Add Comment
Please, Sign In to add comment