问题描述
我使用以解码从一个BT Tracker的B编码响应。
Tracker的回应是:
pre $ d $ d $ filesd20: ¼€™rÄ2ÞÊþVA? 。]á^ |d8:completei285e10:downloadedi22911e10:incompletei9eeee
使用以下代码进行解码:
require'bencoded.php';
$ be = new BEncoded;
//保存在scrape.txt中的响应
$ data = file_get_contents('scrape.txt');
print_r($ be-> Decode($ data));
输出结果为:
Array([files] => Array(> Array> [complete] => 285 [已下载] => 22911 [不完整] => 9 [isDct] => 1)[isDct] => 1)[isDct] => 1)
我的问题
上面输出中的问题是如何解码输出中的那些神秘字母。
链接:由user3690414发布几乎解释了不同的键代表什么。
解释原始的正码字符串:
d5:filesd20: ¼€™rÄ2ÞÊþVA]答^ |d8:completei285e10:downloadedi22911e10:incompletei9eeee
您需要了解如何bencoding作品:
这里最重要的一点是,每个词典中的每个条目都是一个 Key,Value 对。
Where Key 是字节字符串
和值以下类型之一:字符串, ,列表或字典。
字符串可以像这样分解:
d //第一个d表示Root字典的开始处
5 :文件//有5个字节的字符串名称为'files'的Key,
d //'files'-key的值是第二个字典
20:¼? //有一个键20字节= 160位big endian SHA1 info-hash
d //该键的值是第三个字典
8:完成//有一个带有8字节字符串的键名称'complete',
i285e //该键的值是一个Integer = 285
10:已下载//具有一个带有10个字节的字符串名称的密钥'已下载',
i22911e //该键的值是一个Integer = 22911
10:不完整//有一个带有10个字节的字符串名为'incomplete'的键,
i9e //该键的值是一个Integer = 9
e //这个e表示第三个字典的结尾
e / / this e表示第二个字典的结尾
e //这个e表示根字典的结尾
希望这有助于理解'bencoded.php'的输出。
编辑。
如果您想使160位big endian SHA1 info-hash [$rā2Êþþ。]á^ |]
更具人类可读性,我建议您将它输出为40字节的十六进制编码字符串:
0xBC801B9D9972C432DECAFE56410F092E5DE15EA6
I am using BEncoded PHP Library to decode the bencoded response from a Bittorrent tracker.
The response of Tracker is:
d5:filesd20:¼€™rÄ2ÞÊþVA .]á^¦d8:completei285e10:downloadedi22911e10:incompletei9eeee
after decoding it using the below code:
require 'bencoded.php';
$be = new BEncoded;
//Response saved in scrape.txt
$data =file_get_contents('scrape.txt');
print_r($be->Decode($data));
the output is:
Array ( [files] => Array ( [¼€™rÄ2ÞÊþVA .]á^¦] => Array ( [complete] => 285 [downloaded] => 22911 [incomplete] => 9 [isDct] => 1 ) [isDct] => 1 ) [isDct] => 1 )
My Problemmy problem in the above output is how to decode those mysterious letters in output.
The link: http://wiki.vuze.com/w/Scrape posted by user3690414 pretty much explains what the different keys stands for.
To interpret the raw bencoded string:
d5:filesd20:¼€™rÄ2ÞÊþVA .]á^¦d8:completei285e10:downloadedi22911e10:incompletei9eeee
you need to understand how bencoding works: https://wiki.theory.org/BitTorrentSpecification#Bencoding
The most essential to know here is that that every entry in a bencoded dictionary is a Key,Value-pair.
Where Key is a byte string
and Value one of the following types: byte string, integer, a list or a dictionary.
With that in mind the raw string can be broken down like this:
d // The first d indicates the start of the Root dictionary
5:files // that has a Key with a 5 byte string name 'files',
d // the value of the 'files'-key is a second dictionary
20:¼€™rÄ2ÞÊþVA .]á^¦ // that has a Key 20 byte = 160 bit big endian SHA1 info-hash
d // the value of that key is a third dictionary
8:complete // that has a Key with a 8 byte string name 'complete',
i285e // the value of that key is a Integer=285
10:downloaded // that has a Key with a 10 byte string name 'downloaded',
i22911e // the value of that key is a Integer=22911
10:incomplete // that has a Key with a 10 byte string name 'incomplete',
i9e // the value of that key is a Integer=9
e // this e indicates the end of the third dictionary
e // this e indicates the end of the second dictionary
e // this e indicates the end of the Root dictionary
Hope this helps to understand the output from 'bencoded.php'.
edit.
If you want to make the 160 bit big endian SHA1 info-hash [¼€™rÄ2ÞÊþVA .]á^¦]
more human readable, I suggest that you output it as 40 byte hex-encoded string:0xBC801B9D9972C432DECAFE56410F092E5DE15EA6
这篇关于解码洪流跟踪器刮的洪流哈希?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!