简体   繁体   English

在PHP的种子发布公告请求中翻译info_hash

[英]Translating info_hash in the announce request of a torrent in PHP

I'm having an issue to understand how can I "translate" the info_hash value to a real hash. 我在了解如何将info_hash值“转换”为真实哈希值时遇到问题。 Here's an example of what I'm getting from uTorrent when it's announcing to my tracker: 这是当我向跟踪器发布uTorrent的示例:

{
passkey: "77ec6a27adcc441648d66d0b873550e4",
info_hash: "YNvÿ@p",
peer_id: "-UT3430-89 ",
port: "54790",
uploaded: "0",
downloaded: "491520",
left: "24928863",
corrupt: "0",
key: "A2DD5E96",
numwant: "200",
compact: "1",
no_peer_id: "1"
}

What I'm trying to understand is how do I take this strange value: "YNvÿ@p" and get the info hash as sha1 (like: 594E98760099B1CFC3BFAA4070C0CC02F6C1AA90)? 我想了解的是如何获取这个奇怪的值:“YNvÿ@ p”并以sha1的形式获取信息哈希(例如:594E98760099B1CFC3BFAA4070C0CC02F6C1AA90)? I'm using PHP on my server. 我在服务器上使用PHP。

Now I've read already the following statements: 现在,我已经阅读了以下语句:

info_hash info_hash

The 20 byte sha1 hash of the bencoded form of the info value from the metainfo file. metainfo文件中info值的bencoded形式的20字节sha1哈希。 Note that this is a substring of the metainfo file. 请注意,这是metainfo文件的子字符串。 The info-hash must be the hash of the encoded form as found in the .torrent file, regardless of it being invalid. 信息哈希必须是.torrent文件中找到的编码形式的哈希,无论它是无效的。 This value will almost certainly have to be escaped. 几乎可以肯定必须逃避该值。

But it didn't help me much to understand what's going on. 但这并不能帮助我了解正在发生的事情。

OK, I found the solution for that. 好的,我找到了解决方案。 For some reason, $_GET in PHP (we use CodeIgniter) won't get the full binary data, it looked like it was stripping it for some reason. 由于某种原因,PHP(我们使用CodeIgniter)中的$ _GET无法获得完整的二进制数据,它似乎出于某种原因正在剥离它。 And what's it left is only 'YNvÿ@p', but in matter of fact there were few more unknown binary symbols that got thrown on the way. 剩下的只是'YNvÿ@ p',实际上,几乎没有其他未知的二进制符号被抛出。

So... what I did is to get the full URL parameters is: 所以...我要做的是获取完整的URL参数是:

$parts = parse_url($_SERVER['REQUEST_URI']);

And then, I got this value in the 'info_hash' key: 然后,我在“ info_hash”键中得到了这个值:

D%3b%16%01%b2%af%d7%cbT%e1%a1%d0A%20%20%f7%ce%c2%d3%bf

Afterwards I just did this action: 之后,我只是执行了此操作:

$info_hash = bin2hex(urldecode($parts["info_hash"]));

And got a full hash! 并得到了完整的哈希!

@Sammitch, Thank you for pointing me to correct direction on this matter! @Sammitch,谢谢您指出我在此问题上的正确方向!

# php -r 'echo(hex2bin("594E98760099B1CFC3BFAA4070C0CC02F6C1AA90"));' | hexdump -C
00000000  59 4e 98 76 00 99 b1 cf  c3 bf aa 40 70 c0 cc 02  |YN.v.......@p...|
00000010  f6 c1 aa 90                                       |....|

Notice a pattern? 注意到模式吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM