LoranRendel Posted November 7, 2012 Share Posted November 7, 2012 (edited) Hello,This is my UDF working with *.torrent files.It converts torrent file to readable and editable text structure and back to torrent.Binary data will be encoded in base64.Written on pure AutoIt, except base64 located Due to limitation of this version of base64 code, code will not work on x64 compilation.Updated to new x64 compatible code.This code can also be used to edit utorrent/BitTorrent config files (like settings.dat), as it encoded using bencode.Examples are included.torrentUDF.zip Edited November 8, 2012 by xrewndel Link to comment Share on other sites More sharing options...
wraithdu Posted November 8, 2012 Share Posted November 8, 2012 Look here for x64 compatible machine code functions. LoranRendel 1 Link to comment Share on other sites More sharing options...
LoranRendel Posted November 8, 2012 Author Share Posted November 8, 2012 Look here for x64 compatible machine code functions.Thanks. I have updated the archive. Link to comment Share on other sites More sharing options...
garbb Posted October 30, 2013 Share Posted October 30, 2013 (edited) Thanks for making this, I was having trouble working with torrent files in autoit until I found this thread. I modified your _Torrent_Parse function slightly to add outputting of the infohash for a torrent file because I had a need to do this: expandcollapse popup#include <Crypt.au3> Func _Torrent_Parse($File) Local $Data, $Binary, $hFile, $Byte, $Number, $String, $Size, $infodictlevel, $recording_info_bytes=false, $infobytes $hFile = FileOpen($File, 16) If @error Then Return SetError(1, 0, '') While True $Byte = BinaryToString(FileRead($hFile, 1)) if $recording_info_bytes then $infobytes &= $Byte If @error Then ExitLoop Switch $Byte Case 'd'; Dictionary -> $Data &= __Torrents_StringFormat('Dictionary') __Torrents_Level(1) if $string='info' then $infodictlevel=__Torrents_Level() $recording_info_bytes = true $infobytes = $Byte EndIf Case 'l'; List -> $Data &= __Torrents_StringFormat('List') __Torrents_Level(1) Case 'i'; Integer $Number = '' Do $Number &= $Byte $Byte = BinaryToString(FileRead($hFile, 1)) if $recording_info_bytes then $infobytes &= $Byte If @error Then ExitLoop Until $Byte = 'e' VarTrim($Number, 1) Switch $String Case 'length', 'piece length' If $Number < 2 ^ 20 Then $Number &= ' (' & Round($Number / 2 ^ 10, 3) & ' KiB)' ElseIf $Number >= 2 ^ 20 And $Number < 2 ^ 30 Then $Number &= ' (' & Round($Number / 2 ^ 20, 3) & ' MiB)' Else $Number &= ' (' & Round($Number / 2 ^ 30, 3) & ' GiB)' EndIf Case 'creation date' $Number &= ' (' & _DateAdd('s', $Number, "1970/01/01 00:00:00") & ')' EndSwitch $Data &= __Torrents_StringFormat('integer: ' & $Number) Case 'e'; End of element <- __Torrents_Level(-1) if __Torrents_Level()=$infodictlevel-1 then $recording_info_bytes = false $Data &= __Torrents_StringFormat('End') Case '0' To '9'; String's size $Size &= $Byte Case ':'; String $String = BinaryToString(FileRead($hFile, $Size)) if $recording_info_bytes then $infobytes &= $String $Size = '' If StringInStr($String, @LF) or StringInStr($String, @CR) Then $Data &= __Torrents_StringFormat('binary: ' & _Base64Encode(StringToBinary($String), 0)) Else $Data &= __Torrents_StringFormat('string: ' & $String) EndIf Case Else; Error Return SetError(2, 0, '') EndSwitch WEnd Local $bHash = _Crypt_HashData($infobytes, $CALG_SHA1) $Data &= @CRLF& 'Infohash: '&StringTrimLeft($bHash,2) Return StringAddCR($Data) EndFunc ;==>_Torrent_Parse Edited October 30, 2013 by garbb Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now