A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: Unmask javascript websocket messages to Adobe Air server

  1. #1
    Client Software Programmer AS3.0's Avatar
    Join Date
    Apr 2011
    Posts
    1,404

    Unmask javascript websocket messages to Adobe Air server

    Adobe Air serversocket after base64+sha1 handshake with js client:
    PHP Code:
    function decodeMask(a){
    var 
    encoded=a.splice(4,a.length)
    var 
    arr_of_keys=a.splice(0,4)
    var 
    str    
    str
    =""
    for(var i=0;i<encoded.length;i++){
    var 
    key arr_of_keys[4]
    str += String.fromCharCode(encoded[i] ^ key)
    }
    return 
    str;
    }

    function 
    byteArrayToArray(a){
    var 
    arr=[]
    for(var 
    i=2;i<a.length;i++){
    arr.push(a[i])
    }
    return 
    arr
    }


    function 
    onClientSocketData(e:ProgressEvent){
    var 
    buffer:ByteArray = new ByteArray();
    e.currentTarget.readBytes(buffer0e.currentTarget.bytesAvailable);
        
    trace(decodeMask(byteArrayToArray(buffer)))//unmasked websocket messages

    javascript client > messages AIR server:
    PHP Code:
    <html>
    <
    script>

    var 
    exampleSocket = new WebSocket("ws://localhost:80");
    exampleSocket.onopen = function (event) {
    console.log("open");
    setTimeout(test,1000);
    };

    exampleSocket.onmessage = function (event) {
    alert(event.data);
    }
    function 
    test(){
    exampleSocket.send('hello AIR server');
    setTimeout(test,1000);
    }

    </
    script>
    </
    html
    Last edited by AS3.0; 12-11-2021 at 07:15 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center