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

2019-04-14 17:08:14 +08:00
 linde

最近在分析一个直播网站,初步分析后发现是在 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 向大佬求救。。。

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

谢谢两位的回复。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/555040

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX