|
前段時(shí)間在flashseer看到有人提到:可以通過socket方式傳送swf文件,讓用戶無法獲取到swf文件… 當(dāng)時(shí)還沒有出as3的反編譯,所以對(duì)程序的保護(hù)沒有在意.隨著反編譯程序的平民化,不希望別人看到源代碼的朋友就比較著急…
通過socket方式傳送swf文件來避免泄漏源代碼的思路(只適用as3): 讓主程序的loader(前臺(tái)swf)通過socket連接到后臺(tái)程序,然后請(qǐng)求需要的主程序文件.后臺(tái)讀取主程序數(shù)據(jù)通過socket發(fā)送給主程序的 loader.前臺(tái)swf適用Loader.loadBytes方法顯示主程序文件.
下面是測試的源程序:
package {import flash.display.Sprite;import flash.NET.Socket;import flash.events.*;import flash.errors.IOError;import flash.display.Loader;public class SocketTest extends Sprite { public function SocketTest() { var socket = new Socket(); socket.connect("localhost", 5277); socket.addEventListener(Event.CLOSE, closeHandler); socket.addEventListener(Event.CONNECT, connectHandler); socket.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler); socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler); socket.addEventListener(ProgressEvent.SOCKET_DATA, socketDataHandler); var response:String; function writeln(str:String):void { str+=""; try { socket.writeUTFBytes(str); } catch (e:IOError) { trace(e); } } function sendRequest():void { trace("sendRequest"); response=""; writeln('bin'); socket.flush(); } function readResponse():void { //接受數(shù)據(jù) var str:String=socket.readUTFBytes(socket.bytesAvailable); response+=str; //當(dāng)數(shù)據(jù)以end結(jié)束的時(shí)候,數(shù)據(jù)傳輸結(jié)束 if (StringUtil.endsWith(str,'end')) { response=response.substr(0,response.length-3); //把字符串轉(zhuǎn)換為ByteArray var ba=Base64.decodeToByteArray(response); //trace('bytearray=====',ba); var l:Loader = new Loader(); //從 ByteArray 對(duì)象中所存儲(chǔ)的二進(jìn)制數(shù)據(jù)中加載。 l.loadBytes(ba); //trace(l.content); addChild(l); } } function closeHandler(e:Event):void { trace("Socket closed! "); } function connectHandler(e:Event):void { trace("Socket connected!"); sendRequest(); } function ioErrorHandler(e:IOErrorEvent):void { trace("IOError!"); } function securityErrorHandler(e:SecurityErrorEvent):void { trace("SecurityError!"); } function socketDataHandler(e:ProgressEvent):void { trace("Socket have data!"); readResponse(); } }}}
php:
//后臺(tái)scoket程序,由于適用php寫比較簡單,就用php寫了.//error_reporting(E_ALL);error_reporting(0);set_time_limit(0);ob_implicit_flush();$address = 'localhost';$port = 5277;if (($sock = socket_create(AF_INET, SOCK_STREAM, SOL_TCP)) < 0) {echo 'socket_create() failed: reason: ' . socket_strerror($sock) . '/n';}if (($ret = socket_bind($sock, $address, $port)) < 0) {echo 'socket_bind() failed: reason: ' . socket_strerror($ret) . '/n';}if (($ret = socket_listen($sock, 5)) < 0) {echo 'socket_listen() failed: reason: ' . socket_strerror($ret) . '/n';}echo 'connect…………….';do {if (($msgsock = socket_accept($sock)) < 0) { echo 'socket_accept() failed: reason: ' . socket_strerror($msgsock) . '/n'; break;}do { socket_recv($msgsock, $buf, 2048, 0); if ($buf == "") { socket_close($msgsock); echo "some one quit"; break; } else if ($buf == "bin") { //讀取主程序數(shù)據(jù) $f = fopen('main.swf','r'); $data = fread($f,filesize('main.swf')); fclose($f); //轉(zhuǎn)換為字符串 //echo base64_encode($data); $talkback = base64_encode($data).'end'; } //發(fā)送 socket_send($msgsock, $talkback, strlen($talkback),0);} while (true);socket_close($msgsock);} while (true);socket_close($sock);
php技術(shù):php與flash as3 socket通信傳送文件實(shí)現(xiàn)代碼,轉(zhuǎn)載需保留來源!
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。