Xionghui's profileSteve's spacePhotosBlogLists Tools Help

Xionghui Guo

Photo 1 of 14

Steve's space

Focus on technical developing
June 09

Cross-compile GDB 6.8 for Android

Step1: Download gdb and arm cross-compile toolchain.
The following assumes you extract the arm cross-compile toolchain into /usr/local/arm-2008q3/.
$export PATH=$PATH:/usr/local/arm-2008q3/bin
 
Step2: Download and compile ncurses.
$tar zxvf ncurses-5.7.tar.gz
$cd ncurses-5.7
$./configure --host=arm-none-linux-gnueabi --target=arm-none-linux-gnueabi --prefix="$HOME/install"
$sudo cp ~/install/lib/libncurses.a /usr/local/arm-2008q3/arm-none-linux-gnueabi/libc/usr/lib
$sudo cp ~/install/include/ncurses/ /usr/local/arm-2008q3/arm-none-linux-gnueabi/libc/usr/include -rf
This step is to fix the compile warning "configure: error: no termcap library found". Although GDB complain no termcap, actually it needs libncurses. All we did is to let arm-none-linux-gnueabi toolchain can find the library and header files. The misterious directory is found by:
$arm-none-linux-gnueabi-gcc -print-search-dirs
 
Step3: Configure and Make GDB
$tar zxvf gdb-6.8.tar.gz
$cd gdb-6.8
$./configure --host=arm-none-linux-gnueabi --target=arm-none-linux-gnueabi LDFLAGS="-static"
$make
Now you should find gdb and gdbserver. It can run on Android. We must add the above LDFLAGS to let gdb statically linked, otherwise it cannot run on Android.
 
Step4: Run GDB on board
#export SHELL=/system/bin/sh
#gdb XXX
The SHELL env is set to fix the runtime error "Cannot exec /bin/sh: No such file or directory.", so that GDB can work now. But it still cannot debug multi-thread app because missing of libthread_db. Although Android has a libthread_db.so, it only exposes a little function, GDB needs more. //sigh. When will google add the missing features? It's a nightmare for native programmer under Android without multi-thread debugging capability.

Android VNC Server

I have ported libvncserver for Android and write a simple VNC server based on it. Currently it supports key input and touch input(but still needs you plug a USB keyboard into the board). 

To use it. Simply run this on shell in the board (Of course, you need root access because it needs directly access some dev nodes):

#androidvncserver &

You can also run "androidvncserver -h" to see the full accepted options.

On your host machine, you should do:

$sudo apt-get install vncviewer

$vncviewer 50.1.1.10::5901

50.1.1.10 is the IP of your dev board(Yours maybe different from mine). Now you should see the Android UI. Have fun. You can get the binary and source code from: http://code.google.com/p/android-vnc-server/

May 15

How to automatically configure usb0 on hotplug

[First written by Steve Guo, please keep the mark if forwarding.]

1> Edit the file "/etc/network/interfaces"

Add the following lines (You may need to change address and broadcast according to your dev board):

auto usb0
iface usb0 inet static
address 192.168.1.100
netmask 255.255.255.0
broadcast 192.168.1.255

2> Edit the file "/etc/udev/rules.d/85-ifupdown.rules"

Comment out the original two ACTION lines and add the following 2 lines below the commented lines

ACTION=="add", RUN+="/root/myifup $env{INTERFACE}"
ACTION=="remove", RUN+="/sbin/ifdown $env{INTERFACE}"
3> Create a script fie " /root/myifup ", with the following entries. Remember to change the mode to allow execute.

#!/bin/sh
ifdown $1
ifup $1
exit $?

4> Restart network by "sudo /etc/init.d/networking restart"

Okay. Now your ubuntu should be automatically configure usb0 for each time hotplug.

How to connect Android dev board to internet through usb0

[First written by Steve Guo, please keep the mark if forwarding.]

Assume your dev board’s IP address on usb0 is 192.168.1.101, your host machine’s IP address is 192.168.1.100.

On your host side, two things are necessary

% sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

% sudo iptables -t nat -A POSTROUTING -s 192.168.1.0/255.255.255.0 -j MASQUERADE

On dev board, two things are necessary

#route add default gw 192.168.1.100 dev usb0

#setprop net.dns1 XXX.XXX.XXX.XXX

XXX.XXX.XXX.XXX is your host machine’s DNS server. You can get it at /etc/resolv.conf.

May 14

sina tudou youku 在线视频下载地址获取原理

[First written by Steve Guo, please keep the mark if forwarding.]

最近在摆弄Flash的时候顺便研究了一下目前的Flash视频网站的原理。下面重点以新浪视频为例来说明基本原理(新浪的架构最简单,适合研究基本原理)。

目前网上有很多现成的视频网站下载工具,比如xmlbar;还有些网站能直接给出真实的下载地址,拿到地址自己再用下载工具去下;另外还有种方法就是从浏览器的cache中去寻找刚访问过的视频。但所有这些都只是授人以鱼,授人以鱼不如授之以渔,开始进入正题。

假定我们正在访问的网站地址是:http://news.sina.com.cn/c/p/2009-05-13/083417804263.shtml

在Linux下可以用wget来取回该网页对应的HTML文件,然后查看该文件,找到这一行"SinaBokePlayer_o.showFlashPlayer();”,它是Flash视频播放的入口点,SinaBokePlayer_o的实现在:http://v.sina.com.cn/js/pg/play/playflash.js。查看playflash.js文件,发现新浪直接使用了已有的SWFObject实现(访问http://blog.deconcept.com/swfobject/了解详细内容),它会装载http://p.you.video.sina.com.cn/swf/svplayer090506001.swf来真正实现播放视频。

Okay,是时候去看看这个swf文件在干吗了,先下载swf的反汇编工具,我用的是:Sothink Flash Decompiler 4.5。反汇编完重点查看ActionScript脚本(这些才是真正干活的主),看到可疑的了吧,com.main.bokePlayer.PlayVideo。看看下面的代码。

public function loadVid(param1:int, param2:int) : void
{
    if (_$isPlayOnce)
    {
        _$vc.clearV();
        _$testSpeed.sendLog(TestSpeed.END, 0);
    }// end if
    if (_$backpart && _$backpart.visible == true)
    {
        _$backpart.visible = false;
    }// end if
    if (_$isHeadPlayEnd)
    {
        _$skin.removeMsg();
        // Jump to 78;
    }// end if
    _$isPlayReady = false;
    _$isVidError = false;
    _$isDataLoad = false;
    _$pageVars_o.vid = param1;
    _$pageVars_o.uid = param2;
    if (_$lfx)
    {
        removeLoadDataListener();
        // Jump to 131;
    }// end if
    _$lfx = new LoadFLVXML();
    addLoadDataListener();
    var _loc_3:String;
    if (ExternalInterface.available)
    {
        _loc_3 = String(ExternalInterface.call("eval", "document.referrer"));
    }// end if
    _$lfx.loadData(_$xmlBasePath + param1 + "&uid=" + _$pageVars_o.uid + "&pid=" + _$pageVars_o.pid + "&tid=" + _$pageVars_o.tid + "&plid=" + _$pageVars_o.plid + "&ran=" + Math.random() + "&referrer=" + _loc_3, -1);
    _$loadIASKTimeOut = String(new Date().getTime()) + "-";
    return;
}// end function

上面的代码就是去拿真正的FLV视频地址。接下来就是去查其参数的来源了,这里我直接给出规则:

"http://v.iask.com/v_play.php?vid=” + $vid + "&uid=1234&pid=1&tid=2&plid=3001&ran=0.8692729324102401&referrer=”

其中vid是真正需要从HTML文件中传入的,下面再回去查看HTML文件,找到"SinaBokePlayer_o.addVars("vid",”,其后跟着的就是需要的$vid,所以最终我们得到地址:

http://v.iask.com/v_play.php?vid=20716877&uid=1234&pid=1&tid=2&plid=3001&ran=0.8692729324102401&referrer=
访问该地址,发现对应的是一段XML描述,看到了吧,最终的下载地址(http://d174.v.iask.com/f/1/42db7e544a7ceedc690cbddfad8b82eb20716877.flv)就在这个里面了。其播放实际上也就是Flash plugin去播放这段视频流。
恭喜,你已了解了基本的Flash视频播放原理。下面再直接放出我对土豆网的破解结果,分析过程略过。
查看任意土豆视频HTML源文件,找到"var iid =”行从而拿到$iid,实际视频地址可以访问:
"http://v2.tudou.com/v2/cdn?safekey=IAlsoNeverKnow&id="+$iid 来获知。
比如,http://www.tudou.com/programs/view/R9tVmitIoDU/ 对应的视频地址包含在:
http://v2.tudou.com/v2/cdn?safekey=IAlsoNeverKnow&id=30172438 
网上搜索到的:优酷网的下载地址获取过程