Jump to content
Sign in to follow this  

uTorrent, accessing resume.dat (binary file) via Bash and Cygwin through AutoIT

Recommended Posts


(all in windows)<---addition to forum subject line.

I wasted a couple of hours figuring this out, before going in a different design direction.

But it was fun - and it may help someone-else out so here it goes.

I wanted to access uTorrent's resume.dat in order to find where files are stored.

But - this is very useful for anyone who wants to process binary files or read binary files in Windows in a programmatic way. Ironically, you have to do it through a "Linux-like environment" which is cygwin.

1. After confirming you have AutoIt3 working (this was done on Windows Vista, x64).

2. Install cygwin - make sure you install vim,vi, or emacs as well. The default cygwin installation does not include them. This was Cygwin 1.7.1.

Browse to C:\Cygwin, and edit Cygwin bat to look like this:

@echo off


chdir C:\cygwin\bin

bash --login -i %1

3. Here's your AutoIT one-liners that will run the files:

Run(@ComSpec & " /c " &'c:\cygwin\bin\bash --login "triggerTorrentPaths.sh"', "", @SW_HIDE)

Run(@ComSpec & " /c " &'c:\cygwin\bin\bash --login "triggerTorrentCaptionsNames.sh"', "", @SW_HIDE)

Then you can use the standard _FileReadToArray, _Array functions to read through the contents.

Below are the sole contents of triggerTorrentPaths.sh and triggerTorrentCaptionNames.sh. Make sure you use an editor like eEditor to enter them because Windows based platforms have white-space issues as opposed to Unix environments.

triggerTorrentPaths.sh: (do not copy and paste...actually go get that or vim from cygwin, and type it in. Trust me!)


cat /cygdrive/c/users/lance/AppData/Roaming/uTorrent/resume.dat |sed 's/:/:\n/g'|sed -n '/path[0-9]*/{n;n;p;}'|sed 's/[0-9]:$//'|sed '/\\/!d' > /cygdrive/c/TheGoodSeed/uTorrentResumePathCache.txt



cat /cygdrive/c/users/yippeeskippee/AppData/Roaming/uTorrent/resume.dat |sed 's/:/:\n/g'|sed -n '/path[0-9]*/{n;n;p;}'|sed 's/[0-9]:$//'|sed '/\\/!d' > /cygdrive/c/TheGoodSeed/uTorrentResumePathCache.txt

Once you've got them entered in,namethe file triggerTorents.sh

In cygwin, chmod 755 triggerTorrentPaths.sh (and for the other file). This makes them executable.

Test out the files by typing in "./ triggerTorrentPaths.sh" without the quotes while in cygwin.

You know if they work if they produce your files in your desired folders.

Finallyl, run the AutoIT3 lines as listed above.

Below are my notes copied and pasted...I was working from something I found on the uTorrent forums, so was reverse-engineering.

Please do not ridicule me too much, as I know I'm exposing my lack of in-depth knowledge here. But here's how I ended up figuring out what's sed's doing here.

Run in cygwin, but direct it to text:


cat /cygdrive/c/users/yippeeskippee/AppData/Roaming/uTorrent/resume.dat |sed 's/:/:\n/g'|sed -n '/path[0-9]*/{n;n;p;}'|sed 's/[0-9]:$//'|sed '/\\/!d'


cat /cygdrive/c/users/yippeeskippee/AppData/Roaming/uTorrent/resume.dat |sed 's/:/:\n/g'|sed -n '/path[0-9]*/{n;n;p;}'|sed 's/[0-9]:$//'|sed '/\\/!d' > full command.txt

Then, drop off all the sed comments to

cat /cygdrive/c/users/yippeeskippee/AppData/Roaming/uTorrent/resume.dat > 1st.txt

cat /cygdrive/c/users/yippeeskippee/AppData/Roaming/uTorrent/resume.dat |sed 's/:/:\n/g' >2nd.txt

Etc, etc - you can see how the command works easily by comparing each consecutive version.

And below are my notes on breaking the above commands down. <====points to each section of code as it was broken down. Hope it helps!!!!



Display the contents of a file (concatenate)


cat [Options] [File]...

\Display a file

$ cat myfile.txt

Concatenate two files:

$ cat file1.txt file2.txt > union.txt


SED is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).

While in some ways similar to an editor which permits scripted edits, SED works by making only one pass over the input(s), and is consequently more efficient. But it is SED's ability to filter text in a pipeline which particularly distinguishes it from other types of editors.

cat /cygdrive/c/users/yippeeskippee/AppData/Roaming/uTorrent/resume.dat |sed 's/:/:\n/g'|sed -n '/path[0-9]*/{n;n;p;}'|sed 's/[0-9]:$//'|sed '/\\/!d'


display resume.dat

cat /cygdrive/c/users/yippeeskippee/AppData/Roaming/uTorrent/resume.dat<===============================

pipe to sed



This will select any line which matches the regular expression



Apply the replacement to *all* matches to the REGEXP, not

just the first.

inserts a new line at every : - actually substitutes :\n for :

sed 's/:/:\n/g'




By default, SED will print out the pattern space at then end of

each cycle through the script. These options disable this

automatic printing, and SED will only produce output when

explicitly told to via the `p' command.

sed 'n;n;n;n;G;'# add a blank line every 5 lines (after lines 5, 10, 15, 20, etc.)

# print the line immediately before a regexp, but not the line

# containing the regexp

sed -n '/regexp/{g;1!p;};h'<=================================================================

# print the line immediately after a regexp, but not the line

# containing the regexp

sed -n '/regexp/{n;p;}'

so...print the 2nd line after a regexp, but not the line itself?


# print n lines after match if there are n lines, but do not print the matched line itself

echo -n "${lines}" | sed -n '/line2/{n;p;}'

echo -n "${lines}" | sed -n '/line2/{n;{N;p;};}'

echo -n "${lines}" | sed -n '/line2/{n;{N;N;p;};}'

echo -n "${lines}" | sed -n '/line2/{n;{N;N;N;p;};}'

# print the matching line and n lines after the match if there are n lines

echo -n "${lines}" | sed -n '/line2/{N;p;}'

echo -n "${lines}" | sed -n '/line2/{N;N;p;}'

echo -n "${lines}" | sed -n '/line2/{N;N;N;p;}'

echo -n "${lines}" | sed -n '/line2/{N;N;N;N;p;}'

# print the matching line and n lines after the match (using grep)

echo -n "${lines}" | grep -A 1 'line2'

echo -n "${lines}" | grep -A 2 'line2'

echo -n "${lines}" | grep -A 3 'line2'

echo -n "${lines}" | grep -A 4 'line2'

echo -n "${lines}" | grep -A 10 'line2'

sed -n '/path[0-9]*/{n;n;p;}'<=============================================================

# print only lines which match regular expression (emulates "grep")

sed -n '/regexp/p' # method 1

sed '/regexp/!d' # method 2

The empty regular expression `//' repeats the last regular expression match (the same holds if the empty regular expression is passed to the s command). Note that modifiers to regular expressions are evaluated when the regular expression is compiled, thus it is invalid to specify them together with the empty regular expression.

sed '/\\/!d'<=============================================================

Edited by steppedup

Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this