Home > Web Front-end > JS Tutorial > body text

Node.js removes evil information from torrent files_node.js

WBOY
Release: 2016-05-16 16:07:25
Original
2387 people have browsed it

In 2012, a Japanese film called ABS-130 caused a shock on the Internet. The phenomenon of "I looked like a dog at first, but now I think I am ugly" appeared on the Internet, which became the Internet trend in 2012. a big event.

In 2014, the network cleanup operation was in full swing, and all major Internet companies set an example. For a while, XX Cloud and X Lei kept out the seeds of all evil. Long live Operation Net Cleanup! ! (Give it back to me, Teacher Cang!!)

Major network disks and downloading applications extract key information from seeds and exclude them. Where exactly is this critical information hidden? Let’s find out.

Torrent file structure

The following content is from Wikipedia

.torrent seed file is essentially a text file, containing Tracker information and file information. Tracker information is mainly the address of the Tracker server and the settings for the Tracker server that are needed for BT downloads. The file information is generated based on the calculation of the target file, and the calculation results are encoded according to the Bencode rules in the BitTorrent protocol. Its main principle is to virtually divide the files provided for download into equal-sized blocks. The block size must be an integer power of 2k (due to virtual blocking, individual block files are not generated on the hard disk), and each block is The index information and Hash verification code are written into the seed file; therefore, the seed file is the "index" of the downloaded file.

The picture above is the structure of a typical seed. The identified evil keywords are hidden in name and file. name contains the name of the torrent, such as: abcd-123 Sexy XXXX. The path in file contains the information of all files to be downloaded, such as: Latest address of CaoX community.txt and so on.

Node.js and parse-torrent library

In order to find the evil information in the torrent, we asked the Node.js and parse-torrent libraries as assistants.

Experiment preparation:

One seed to install Node.js on one computer

First we use npm to install the parse-torrent library, which helps us quickly find the information in the torrent.

<code>npm install parse-torrent</code>
Copy after login
var fs = require("fs");
var parseTorrent = require('parse-torrent');

var info = parseTorrent(fs.readFileSync('my.torrent'));
console.log(info);
Copy after login

This library will parse out the seed information and return it to us in the form of an object.

View results:

name:

files:

You can see that the name and files information parsed by the parse-torrent library are stored in Buffer form.

Cleaning seeds

How to clean the evil information in the seeds and strangle the evil seeds in the cradle. The most important thing is to clear the information of the path in the name and files.

function cleanInfo (info) {
 // 将种子名用 md5 加密
 info.name = md5(info.name);
 info['name.utf-8'] = md5(info['name.utf-8']);
 var files = info.files;
 for (var i = 0; i < files.length; i++) {
  var file = files[i];
  for (var key in file) {
   if (key == "path" || key == "path.utf-8") {
    for (var j = 0; j < file[key].length; j++) {
     var text = file[key][j].toString();
     var dotIndex = text.lastIndexOf(".");
     // 将种子名用 md5 加密
     file[key][j] = md5(text.slice(0,dotIndex)) + text.slice(dotIndex,text.length);
    }
   }
  }
 }
 return info;
}
Copy after login
// 将清洗干净后的 info 对象重新生成一个 torrent 文件
var buf = parseTorrent.toTorrentFile({
 info: cleanInfos[i]
});
fs.writeFile(dir + "/" + cleanInfos[i].name + ".torrent", buf);
Copy after login

After doing this, our evil torrent file will look like this:

Practical stage

First prepare a seed for offline download of XX Cloud.

At first it was rejected.

Then run the script to clean.

<code>node cleanTorrent IPTD-XXX.torrent</code>
Copy after login

Download successful!

The script source code is here, now you have to take a look at my download content! ! !

(Take off your clothes and show me this!!!)

Finally

This article is purely a technical discussion. Thank you for reading. Please point out any shortcomings.

Please take a moment to share the article with your friends or leave a comment. We will sincerely thank you for your support!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template