Monday, August 28, 2006

[Software] Bencoding - Deciphering Torrent Files

Most torrent files are encoded using a method called BEncoding, I had trouble finding a .net version of the decoder, so I ended up writing my own.

You can download this here: BEncoding.dll.

Although it will decode a BEncoded file (ie. torrent file), it cannot create one (maybe another time).

This project is in no way complete, and still needs exception handling for the "Path" property and other areas

Code Example:

  • string filename = "afile.torrent";
    Bencoding.Decode bencodedfile = new Bencoding.Decode(filename);
    Bencoding.DebugDictionary db = new Bencoding.DebugDictionary(bencodedfile.Dictionary);

    Response.Write ( "/info/name = " + bencodedfile.get_Path("/info/name").toString());
    Response.Write ( "\n\n");

    // next section likely to cause an exception if used with a Single File Mode Torrent file

    Response.Write ( "/info/files/0/path/0 = " + bencodedfile.get_Path("/info/files/0/path/0").toString());
    Response.Write ( "\n\n");
    Response.Write ( "/info/files/1/path/0 = " + bencodedfile.get_Path("/info/files/1/path/0").toString());
    Response.Write ( "\n\n");

    Response.Write (db.toString);



Basic Documentation:
Constructor:

  • Bencoding.Decode dict = new Bencoding.Decode(actualFilePath);
  • Open and processes "actualFilePath"

    Property:
    Dictionary
  • return a Bencoding.Dictionary - basically an modified arraylist
  • example: dict.Dictionary - returns the Bencoding.Dictionary object ( if you wish to interogate the file in depth)

    Path
  • returns object within the dictionary based on a path
  • example: dict.Path("/info/name") - returns the Filename or Directory of the Torrent
  • example: dict.Path("/info/files/0/path/0") - returns the first filename in a multi file mode torrent

No comments: