Protect your flash (as3) Program-transfer SWF files through socket

Source: Internet
Author: User

Some time ago, someone mentioned in flashseer that the SWF file can be transmitted through socket, so that users cannot get the SWF file... at that time, there was no as3 decompilation, so I didn't care about program protection. with the popularization of decompilation programs, friends who don't want others to see the source code will be worried...

The idea of transmitting SWF files through socket to avoid source code leakage (only applicable to as3): Let the loader (foreground SWF) of the main program connect to the background program through socket, request the required main program file. the background reads the main program data and sends it to the loader of the main program through socket. the front-end SWF is applicable to loader. the loadbytes method displays the main program file.

The following is the test source code:

Front-end loader:
//-------------
// Search for base64 and stringutil on the Internet.
Import base64;
Import stringutil;
VaR socket = new socket ();
Socket. Connect ("localhost", 11915 );

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 {
// Accept data
VaR STR: String = socket. readutfbytes (socket. bytesavailable );
Response + = STR;
// When data ends with end, data transmission ends.
If (stringutil. endswith (STR, 'end '))
{
Response = response. substr (0, response. Length-3 );
// Convert the string to bytearray
VaR BA = base64.decodetobytearray (response );
// Trace ('bytearray ==== ', BA );
VaR L: loader = new loader ();
// Load the binary data stored in the bytearray object.
L. loadbytes (BA );
// Trace (L. content );
Addchild (L );
}
}

Function closehandler (Event: Event): void {
Trace ("closehandler:" + Event );
}

Function connecthandler (Event: Event): void {
Trace ("connecthandler:" + Event );
Sendrequest ();
}

Function ioerrorhandler (Event: ioerrorevent): void {
Trace ("ioerrorhandler:" + Event );
}

Function securityerrorhandler (Event: securityerrorevent): void {
Trace ("securityerrorhandler:" + Event );
}

Function socketdatahandler (Event: progressevent): void {
Trace ("socketdatahandler:" + Event );
Readresponse ();
}

// The scoket program in the background. It is easy to write because it is applicable to PhP.
<? PHP
// Error_reporting (e_all );
Error_reporting (0 );
Set_time_limit (0 );

Ob_implicit_flush ();

$ Address = 'localhost ';
$ Port = 11915;

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 ')
{
// Read Master Program Data
$ F = fopen('main.swf ', 'R ');
$ DATA = fread(ff,filesize('main.swf '));
Fclose ($ F );
// Convert to a string
// Echo base64_encode ($ data );
$ Talkback = base64_encode ($ data). 'end ';
}
// Send
Socket_send ($ msgsock, $ Talkback, strlen ($ talkback), 0 );
} While (true );
Socket_close ($ msgsock );
} While (true );

Socket_close ($ sock );
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.