Home » File Formats » File_Bittorrent » Bug #3970
Problems with decoding
Details
| Submitted | 2005-03-27 14:30 UTC |
|---|---|
| From | gaggge at gmail dot com |
| Assigned | tacker |
| Status | Closed |
| Package | File_Bittorrent |
| PHP Version | Irrelevant |
| OS | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2005-03-27 14:30 UTC] gaggge at gmail dot com
Description:
------------
I'm having some problems with decoding a torrent and generating an info_hash.
(You can get the info_hash like this: pack("H*", sha1($info)) where $info is the bencoded info key)
First i decode a torrent to $torrent, then encode $torrent['info'], now the 'length' key should be an integer, but it's a string, however that's not a problem, can be fixed easily with settype().
A bigger problem is that the length of 'pieces' always is incorrect.
Maybe you could do an info_hash function?
Again, pack("H*", sha1($torrent['info'])) to get the info_hash
Reproduce code:
---------------
<?php
require("decode.php");
require("encode.php");
$bdecode = new File_Bittorrent_Decode;
$bencode = new File_Bittorrent_Encode;
$torrent = $bdecode->decodeFile("file.torrent");
$info = $bencode->encode($torrent['info']);
$infohash = pack("H*", sha1($info));
?>
Expected result:
----------------
'length' in 'files' should be int, is string
strlen of 'pieces' is incorrect
[2005-03-27 14:33 UTC] gaggge at gmail dot com
A little note: 'piece length' should be an int too.
[2005-03-27 17:13 UTC] gaggge at gmail dot com
I think the problem is that strlen doesn't work correct on the pieces stuff, I've made a working but pretty nasty function for getting the info_hash, I'm not sure if it works all the time, it depends on the number of e's at the end of the torrent.
<?php
$filesrc = @file_get_contents("file.torrent");
$start = @strpos($filesrc, 'd5:files');
$match = @substr($filesrc, $start, (@strlen($filesrc)-$start-1));
$file_info['info_hash'] = @urlencode(@pack("H*", sha1($match)));
?>
It generates the hash for the text between d5:files and the second last e in the torrent.
4:info -> d5:files ... e <- e
Try doing a strlen on the info key and you'll see that it probably returns a different value than what's in the torrent.
Hope you manage to get this working, i'll try myself to do a 100% working solution.
Sorry for my bad english :-)
[2005-03-27 22:14 UTC] gaggge at gmail dot com
Maybe I should add some stuff, don't query a tracker with a info_hash in the query string through your browser if that's what you've been trying, won't work for me.
Build a torrent, BitComet works fine, and set the announce url to whatever.php.
Add file_put_contents(print_r($_GET, true)); (or something like that) to whatever.php.
(Will get bad data from tracker, don't mind that)
Check if you can get the same info_hash with your script as your client sends to the announce url.