V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
linde
V2EX  ›  Java

求大佬用 Java 实现这段 AS3 的 socket 通讯功能

  •  
  •   linde · 2019-04-14 17:08:14 +08:00 · 1629 次点击
    这是一个创建于 1832 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近在分析一个直播网站,初步分析后发现是在 swf 中用 socket 通讯返回的 flv 地址。

    其中 Actionscript socket 通讯的关键代码如下:

         this._socket = new Socket();
         this._socket.addEventListener(Event.CONNECT,this.onConnect);
         this._socket.addEventListener(ProgressEvent.SOCKET_DATA,this.onSocketData);
         this._socket.addEventListener(Event.CLOSE,this.handleClose);
         this._socket.connect(this._ip,uint(this._port));
    
      private function onConnect(param1:Event) : void
      {
         var _loc1_:ByteArray = new ByteArray();
         _loc1_.endian = Endian.LITTLE_ENDIAN;
         _loc1_.writeUnsignedInt(uint(this._sid));
         _loc1_.writeUnsignedInt(uint(this._uid));
         _loc1_.writeByte(this._needRotation == 0?0:1);
         _loc1_.position = 0;
         this._socket.writeBytes(_loc1_);
         this._socket.flush();
      }
    
      private function onSocketData(param1:ProgressEvent) : void
      {
         if(this._socket.bytesAvailable > 0)
         {
            _loc5_ = new ByteArray();
            this._socket.readBytes(_loc5_);
            _loc5_.position = 0;
            this._render.put(_loc5_);
         }
      }
    

    其中几个变量都是在 html 中由 FlashVars,向 swf 传递。

    <param name="FlashVars" value="uid=3452777999&sid=2124798641&srv=45.255.132.43&port=7207&needRotation=0" />
    

    我尝试用 java 写了一下,但是始终得不到返回值。

            Socket socket = new Socket("45.255.132.43", 7207);
    
            OutputStream outputStream = socket.getOutputStream();
    
            ByteBuffer bb = ByteBuffer.allocate(16);
            bb.order(ByteOrder.LITTLE_ENDIAN);
            bb.putLong(2124798641L);
            bb.putLong(3452777999L);
            bb.put((byte)0);
            bb.position(0);
            outputStream.write(bb.array());
            outputStream.flush();
    
            socket.shutdownOutput();
            InputStream is = socket.getInputStream();
            System.out.println(is.available());
            System.out.println(is.read());
    

    特上 v2 向大佬求救。。。

    Aidenboss
        1
    Aidenboss  
       2019-04-15 08:04:28 +08:00   ❤️ 1
    可以先用 nc 45.255.132.43 7207 或者 telnet 测试下,
    感觉有问题呀
    daodao116
        2
    daodao116  
       2019-04-15 10:02:09 +08:00   ❤️ 1
    抓包看看差异。感觉 putLong 有点问题吧。
    linde
        3
    linde  
    OP
       2019-04-15 23:31:55 +08:00
    @Aidenboss 谢谢,IP 和端口没有问题。能够建立建立。应该是发送的数据有问题。
    @daodao116 谢谢,之前就是抓包抓不到 socket 通讯的信息,才想着分析一下 swf,结果还是卡住了。UnsignedInt 无符号 32 位整数,在 java 里貌似就是用 long,总之是发送数据这部分的有问题(大小端 /ENDIAN 和数据类型的问题)。 诶 不管了,最后还是抓包大法好,找到了 url 的拼接逻辑。

    谢谢两位的回复。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3235 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 10:46 · PVG 18:46 · LAX 03:46 · JFK 06:46
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.