Archive for August, 2008

Extract mp3 from imeem (or similar site)

Posted on August 18, 2008. Filed under: Uncategorized |

When I listen to Michael Jackson’s Billie Jean in Imeem, I want to download it, of course they won’t let me download it so easily, but I know that I must have the cache computer for song, here’s a way to extract it:

  • Use you *Firefox* to open this URL, if you have flash player, it plays right away
  • Entry about:cache in the address bar
  • Under Memory cache device, click into List Cache Entries
  • In the list of of cache entries, you will see one very long item and the data size is going up, that’s the cache for the mp3
  • Wait for a while for the cache to be fully downloaded, then click into Key, you will see this page
  • So now you have the content of the song in hex dump, you will need to extract it, go to File and Save Page As to save it to a file “billie_jean.dump”, use Text files as Save as type.
  • Use your favorite text editor to open billie_jean.dump, you will see something like this:

    Remove all the lines up to “00000000:” and save it.
  • Finally you need to run a small C++ problem to help you convert the hex dump to a binary file
    using namespace std;
    int hex2int(int v){
      if(v >= 'a' && v <= 'z' )
        return v - 'a' + 10;
      if(v >= 'A' && v <= 'Z' )
        return v - 'A' + 10;
      else return v - '0';
    int hex2int(int a,int b){
      return hex2int(a) << 4 | hex2int(b);
    int main(){
      string line;
        istringstream iss(line);
        string token;
        iss >> token;
        for(int i=0;i<16;++i){
          iss >> token;

    Save it to and compile it with your favorite compiler, in my case gcc, so I just do "make hex2bin" to build the program.

  • Run the program and use billie_jean.dump as input (Note the song is in flv format)
    ./hex2bin < billie_jean.dump > billie_jean.flv
  • Now you have the song in flv format, to convert it to mp3, I use ffmpeg:
    ffmpeg -i billie_jean.flv -acodec copy billie_jean.mp3
    and you have billie_jean.mp3 ! Nice song MJ!
Read Full Post | Make a Comment ( None so far )

A very short and neat code for Union-Find

Posted on August 13, 2008. Filed under: Algorithm |

This is the Union-Find code that my team use, we call it two-liner, because there’s only two lines responsible for the real stuff

int parent[N];

int find(int u){
return u == parent[u] ? u : parent[u] = find(parent[u]);

int join(int u,int v){
parent[find(u)] = find(v);

// init
for(int i=0;i

Read Full Post | Make a Comment ( None so far )

Minimum Weighted Aborescence (Directed MST)

Posted on August 13, 2008. Filed under: Algorithm, Graph, UVA | Tags: , , |

Source code for my AC solution to UVA 11183 with 0.14s which is an implementation of directed minimum spanning tree algorithm from here.


using namespace std;

#define N 1002

int pred[N],mins[N],parent[N];
int adjc[N],radjc[N];
int adj[N][N],radj[N][N],cost[N][N];
bool visit[N],cycle[N];
int mine;

int find(int u){
return parent[u]==u?u:parent[u]=find(parent[u]);

void join(int u,int v){

bool dfs(int r,int u){
if(visit[u])return r==u;visit[u]=true;
for(int i=0;i=0){
int k=pred[i]; adj[k][adjc[k]++]=i;
if(first) mc+=mins[i];
first = false;
int inc=mine=0x7fffffff;
bool hc=false;
for(int i=0;i Read Full Post | Make a Comment ( None so far )

Winny’s Protocol (handshake)

Posted on August 10, 2008. Filed under: P2P, Winny |

For those who are interested, here’s the protocol details about Winny.
I will first talk about the handshaking which is the beginning of all connections, the handshake begins with 6 bytes of data which contains the RC4 key used for decryption of upcoming data, the 6 bytes has the format:

—- —- —- —- —- —-
| x | | x | | a | | b | | c | | d |
—- —- —- —- —- —-

where xs are dummy and abcd 4 bytes are the encryption key.

After the encryption key, data packets are formatted as commands and has a common format:
| length of cmd | | pay load |
The length has 4 bytes in little endian and describes the number of bytes in payload.

Payload has the following format”
— ———————————-——–——–——
| code | | additional data associated with the code |
The code is of course the command code which is of 1 byte, length of data depends on the code.

During handshaking, the commands sent would be:
| key | | 97 | | 00 | | 01 | | 02 | | 03 |

key is the key packet described as above
97 is command 97 which means “Low version”
00 is Protocol Header
01 is Speed
02 is Connection Type
03 is Node Details

Command formats as follows:
97 = Low Version
| 97 |

00 = Protocol Header
| 00 | | minor version (4 bytes LE int) | | major version string |
where the information part of minor version and major version is encrypted using RC4 with key:
[ 0x39, 0x38, 0x37, 0x38, 0x39, 0x61, 0x73, 0x6a ]

01 = Speed
| 01 | | speed (4 bytes LE float, i.e. IEEE 754) |

02 = Connection Type
| 02 | | link type (1 byte) | | is port 0 (1 byte) | | is bad port 0 (1 byte) | | is bbs link (1 byte) |
link type = {Search = 0, Transfer = 1, BBS Search = 2|, others are boolean values

03 = Node Details
| 03 | | ipv4 address (4 bytes BE int) | | port (4 bytes LE int) | | DDNS name length (1 byte) |
| cluster word 1 length (1 byte) | | cluster word 2 length (1 byte) | | cluster word 3 length (1 byte) |
| DDNS | | cluster word 1 | | cluster word 2 | | cluster word 3 |

Read Full Post | Make a Comment ( 1 so far )

Winny in Java

Posted on August 10, 2008. Filed under: Java, P2P, Winny |

This summer I finally have the free time that I longed for. I always wanted to investigate Winny which is a Japanese P2P software.
There’s some functions that I needed but updates is impossible because the author is caught for making it.
So I think it would be good to create my own Winny compatible P2P client. Here’s some screen capture of it.
I uses Berkeley DB JE to store files discovered in the network and have Apache Lucene to index all the file names.
The result is pretty good and Lucene is working amazingly fast, but Berkeley DB JE is a bit slower than I expected..

I am able to search 200k files in about 11s. Query in Lucene takes 1 – 2s, but joining to data in Berkeley DB is unexpectedly slow. Maybe I need to do some more tuning.

By now I have implemented basic connections and queries, and it is now running in Port 0 mode, file downloading (uploading) is yet to come…

Read Full Post | Make a Comment ( None so far )

Liked it here?
Why not try sites on the blogroll...