Skip to content

tool-maker/bencode-pretty

Repository files navigation

bencode-pretty

This code is for three programs to create a "pretty" version of a bencoded file that can easily be examined and edited. And a fourth program to "unpretty" it again after editing.

For an explanation of bencoding see for example:

To download this repository and build, in the user's home directory:

pushd ~
git clone https://github.com/tool-maker/bencode-pretty
pushd bencode-pretty
make
make clean
popd

I have tested with Linux, Cygwin and MSYS/MinGW.

Building produces three executables: "bencode_pretty", "bencode_prettier" and "bencode_unpretty". Each is a filter, meant to be run like this:

cat some_file.torrent | ./bencode_pretty > some_file.torrent.txt
bencode_pretty

Modifies the encoding of strings (see the references above) so that there is no length field preceding it, enclosing in quotes (") instead. And within the strings non-printable characters are encoded using "," as an escape character (because "," seems unlikely to appear in either tracker URL-s or file paths). The resulting file will have a single line of text.

bencode_prettier

The same as "bencode_pretty" except that newline characters are inserted so that each bencode element occupies its own line. No carriage returns are inserted. So on Windows use an editor such as Notepad++.

bencode_prettiest

The same as "bencode_prettier" except that indents are also inserted so that the logical structure of the data is more apparent.

bencode_unpretty

Takes "pretty", "prettier" or "prettiest" files and recreates bencode. The idea is that you will have changed some string(s) for tracker URL-s or file paths.

There is also a bash script.

bencode_many_prettiest.sh

This should called like this (for example):

pushd ~/bencode-pretty
mkdir work
cp -ia ~/private/rtorrent/work/*.rtorrent work
bash bencode_many_prettiest.sh work > many_rtorrents.txt
popd
The first (and only) argument is the name of a directory. The file that is produced ("many_rtorrents.txt" in the example) is itself a script. It will contain a "prettiest" version of each of the bencoded files contained in the directory that is passed as an argument, along with enough bash script wrapping so that when it is run, it will recreate the bencoded version of the files in the current working directory. The idea is to allow a mass edit of many bencoded files using the "replace all" operation of a text editor. After it has been edited, it should be run in an empty directory (it checks to be sure the current directory is empty), in which the individual files will be recreated.. Either this empty directory should be within the directory where "bencode_unpretty" et al were built, or "bencode_unpretty" must be in the program lookup path ("PATH" environment variable) when the script is run ("which bencode_unpretty"). So it could be called like this (for example):
pushd ~/bencode-pretty
mkdir work_new
pushd work_new
bash ../many_rtorrents.txt
popd
popd

The idea in this example is that an rtorrent installation is being copied to another server or under a different user (a different "slot" on a seedbox for example) where the absolute path for the user's home directory will have changed. One would:

  1. Build bencode_pretty on each "slot".
  2. Generate the script on the slot from which the rtorrent installation is being copied.
  3. Edit the home directory appearing in the generated script using a "replace all" operation in a text editor.
  4. Place the edited script onto the new slot.
  5. Run the edited script on the new slot.

The "*.rtorrent" files that get generated then replace the previous ones on the new slot.

About

programs to create a "pretty" version of a bencoded file that can be easily examined and edited, and another to "unpretty" it again

Resources

Stars

Watchers

Forks

Packages

No packages published