Skip to content

Commit

Permalink
0.20150709: init version
Browse files Browse the repository at this point in the history
  • Loading branch information
zvezdochiot committed Oct 10, 2019
0 parents commit baca1fc
Show file tree
Hide file tree
Showing 13 changed files with 1,098 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
PACKAGE = torreadwrite
TARGETS = torread torwrite

CC = gcc
LD = $(CC)
CFLAGS =
LDFLAGS = -s
SRCS = src
RM = rm -fv

.PHONY: all clean

all: $(TARGETS)

torread: $(SRCS)/torread.c
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

torwrite: $(SRCS)/torwrite.c
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)

clean:
$(RM) $(TARGETS)
63 changes: 63 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
torreadwrite 0.20150709
VL-LUG
XMPP: <xmpp:[email protected]>
URL: http://www.linuxdv.org/wiki/projects/torrents_editor
SRC: http://linuxdv.ru/forum/download/file.php?id=28


BUILD

$ bash build.sh

INSTALL

$ sudo cp torread /usr/bin
$ sudo cp torwrite /usr/bin
$ sudo cp torreadwrite.1.gz /usr/share/man/man1
$ sudo ln -s /usr/share/man/man1/torreadwrite.1.gz /usr/share/man/man1/torread.1.gz
$ sudo ln -s /usr/share/man/man1/torreadwrite.1.gz /usr/share/man/man1/torwrite.1.gz

SAMPLE

$ torread samplefile.torrent > samplefile.torrent.txt
$ nano samplefile.torrent.txt

$ torwrite samplefile.torrent.txt > samplefile.mod.torrent

STRUCTURE

Content torrent file

Content torrent file is encoded as described above. Himself torrent file is bencoded dictionary with the following keys:

    info: a dictionary describing the files in the torrent. There are two forms of the dictionary, the first to the torrent that contains only one file, and the second - for multi file torrent.
    announce: string with a URL of the tracker.
    announce-list: (optional) list of lists, each of which contains a string with a URL of the tracker.
    creation date: (optional) integer - the creation of a torrent in seconds era UNIX (number of seconds since 00:00:00 01/01/1970).
    comment: (optional) string with an arbitrary comment.
    created by: (optional) string with the name and version of the created torrent file program.
    encoding: (optional) any string of unknown purpose.

In beztrekernom torrent announce and no announce-list, but instead there is an element nodes, which is a list of lists, each of which contains a line with the address and the number of nodes - the port number. Something like nodes = [[«<host>», <port>], [«<host>», <port>], ...]. The simplest option - nodes = [[«127.0.0.1», 6881]].

Dictionary info

The parameters are the same for single-file and multi-file torrents.

    piece length: number of bytes in a piece, usually a power of two.
    pieces: a string of united 20-byte SHA1 hash pieces.
    private: (optional) number. If it is one, the customer to search for peers to be used only tracker (s) specified in the torrent file. If this number is zero, the customer can add peers any methods: manually, or via DHT and Peer Exchange t. D.

For single file torrents:

    name: string filename.
    length: the number of bytes in the file.
    md5sum: (optional) string MD5 sums file. Fucking useless.

For multi file torrent:

    name: string with the name of the directory where all files will be placed.
    files: a list of dictionaries, one for each file. Each dictionary contains the following keys:
    length: the number of bytes in the file.
    md5sum: (optional) string MD5 sums file. Fuck no one needs, as in the previous case.
    path: a list of one or more lines, representing together a file path. The last line - the name of the file, the previous - the sequence of nested directories. For example, the path «dir1 / dir2 / file.ext» will be presented in a list of three lines: «dir1», «dir2», «file.ext».
383 changes: 383 additions & 0 deletions html/ru/index.html

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions html/ru/index.rdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0"?>
<RDF:RDF xmlns:MAF="http://maf.mozdev.org/metadata/rdf#"
xmlns:NC="http://home.netscape.com/NC-rdf#"
xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<RDF:Description RDF:about="urn:root">
<MAF:originalurl RDF:resource="file:///home/mykaralw/Downloads/html/torreadwrite-wiki_www.linuxdv.org.utf8.html"/>
<MAF:title RDF:resource="Редактирование торрент-файлов - Linux во Владивостоке"/>
<MAF:archivetime RDF:resource="Thu, 09 Jul 2015 19:33:39 +0300"/>
<MAF:indexfilename RDF:resource="index.html"/>
<MAF:charset RDF:resource="UTF-8"/>
</RDF:Description>
</RDF:RDF>
Binary file added html/ru/index_files/button-dw.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/ru/index_files/button-monobook.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/ru/index_files/button-rss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added html/ru/index_files/button-xhtml.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
173 changes: 173 additions & 0 deletions html/ru/index_files/css.php.css

Large diffs are not rendered by default.

Binary file added html/ru/index_files/favicon_ico
Binary file not shown.
98 changes: 98 additions & 0 deletions man/torreadwrite.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
.TH torreadwrite "1" "09 Jul 2015" "0.20150709" "User Manual"
.PP
torreadwrite
.PP
VL-LUG
.PP
XMPP: <xmpp:[email protected]>
.PP
URL: http://www.linuxdv.org/wiki/projects/torrents_editor
.PP
SRC: http://linuxdv.ru/forum/download/file.php?id=28
.PP

.SH SAMPLE

$
.B torread
samplefile.torrent > samplefile.torrent.txt
.PP
$
.B nano
samplefile.torrent.txt
.PP
$
.B torwrite
samplefile.torrent.txt > samplefile.mod.torrent
.PP

.SH STRUCTURE

Content torrent file
.PP
Content torrent file is encoded as described above. Himself torrent file is bencoded dictionary with the following keys:
.PP
.B info:
a dictionary describing the files in the torrent. There are two forms of the dictionary, the first to the torrent that contains only one file, and the second - for multi file torrent.
.PP
.B announce:
string with a URL of the tracker.
.PP
.B announce-list:
(optional) list of lists, each of which contains a string with a URL of the tracker.
.PP
.B creation date:
(optional) integer - the creation of a torrent in seconds era UNIX (number of seconds since 00:00:00 01/01/1970).
.PP
.B comment:
(optional) string with an arbitrary comment.
.PP
.B created by:
(optional) string with the name and version of the created torrent file program.
.PP
.B encoding:
(optional) any string of unknown purpose.
.PP
In beztrekernom torrent announce and no announce-list, but instead there is an element nodes, which is a list of lists, each of which contains a line with the address and the number of nodes - the port number. Something like nodes = [[«<host>», <port>], [«<host>», <port>], \.\.\.]. The simplest option - nodes = [[«127.0.0.1», 6881]].
.PP
Dictionary info
.PP
The parameters are the same for single-file and multi-file torrents.
.PP
.B piece length:
number of bytes in a piece, usually a power of two.
.PP
.B pieces:
a string of united 20-byte SHA1 hash pieces.
.PP
.B private:
(optional) number. If it is one, the customer to search for peers to be used only tracker (s) specified in the torrent file. If this number is zero, the customer can add peers any methods: manually, or via DHT and Peer Exchange t. D.
.PP
For single file torrents:
.PP
.B name:
string filename.
.PP
.B length:
the number of bytes in the file.
.PP
.B md5sum:
(optional) string MD5 sums file. Fucking useless.
.PP
For multi file torrent:
.PP
.B name:
string with the name of the directory where all files will be placed.
.PP
.B files:
a list of dictionaries, one for each file. Each dictionary contains the following keys:
.PP
.B length:
the number of bytes in the file.
.PP
.B md5sum:
(optional) string MD5 sums file. Fuck no one needs, as in the previous case.
.PP
.B path:
a list of one or more lines, representing together a file path. The last line - the name of the file, the previous - the sequence of nested directories. For example, the path «dir1 / dir2 / file.ext» will be presented in a list of three lines: «dir1», «dir2», «file.ext».
.PP
178 changes: 178 additions & 0 deletions src/torread.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
/* $Id: torread.c 529 2009-09-11 08:44:53Z michael $ */
#include <fcntl.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdint.h>
#include <stdlib.h>

const uint8_t sp=' ';
const uint8_t ret='\n';
const uint8_t quo='\"';
const uint8_t scr='\\';
const uint8_t hxp='x';
const uint8_t blst='[';
const uint8_t elst=']';
const uint8_t bdct='(';
const uint8_t edct=')';
const uint8_t eqv='=';
const int stdout=1;

enum obj_type {OBJ_NUL, OBJ_INT, OBJ_STR, OBJ_LST, OBJ_DCT};

void Byte2Hex(uint8_t ch);
void PrintSpc(int num);
enum obj_type DetType(const uint8_t* d, size_t shift);
size_t FindSym(const uint8_t* d, uint8_t s, size_t shift, size_t len);
size_t PrintInt(const uint8_t* d, size_t shift, size_t len);
size_t PrintStr(const uint8_t* d, size_t shift, size_t len);
size_t PrintLst(const uint8_t* d, size_t shift, size_t len, int skip);
size_t PrintDct(const uint8_t* d, size_t shift, size_t len, int skip);
size_t PrintObj(const uint8_t* d, size_t shift, size_t len, int skip);

void Byte2Hex(uint8_t ch)
{
static const uint8_t cnv[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
write(stdout,cnv+((ch&(15<<4))>>4),1);
write(stdout,cnv+(ch&15),1);
}

void PrintSpc(int num)
{
int i;
for(i=0;i<num;i++) write(stdout,&sp,1);
}

enum obj_type DetType(const uint8_t* d, size_t shift)
{
// write(2,d+shift,1);
if(d[shift]=='i') return OBJ_INT;
if(d[shift]=='l') return OBJ_LST;
if(d[shift]=='d') return OBJ_DCT;
if(d[shift]>=49 && d[shift]<=57) return OBJ_STR;
return OBJ_NUL;
}

size_t FindSym(const uint8_t* d, uint8_t s, size_t shift, size_t len)
{
size_t i;

for(i=shift;i<len;i++) if(d[i]==s) return i;
exit(2);
}

size_t PrintObj(const uint8_t* d, size_t shift, size_t len, int skip)
{
switch(DetType(d,shift))
{
case(OBJ_NUL): exit(2);
case(OBJ_INT): return PrintInt(d,shift,len);
case(OBJ_STR): return PrintStr(d,shift,len);
case(OBJ_LST): return PrintLst(d,shift,len,skip);
case(OBJ_DCT): return PrintDct(d,shift,len,skip);
}
exit(2);
}

size_t PrintInt(const uint8_t* d, size_t shift, size_t len)
{
size_t e=FindSym(d,'e',shift,len);
write(stdout,d+shift+1,e-shift-1);
return e+1;
}

size_t PrintStr(const uint8_t* d, size_t shift, size_t len)
{
size_t e=FindSym(d,':',shift,len);
int l=atoi((const char*)(d+shift));
if(e+l>=len) exit(2);
size_t p;

write(stdout,&quo,1);
for(p=e+1;p<=e+l;p++)
{
if(d[p]==127 || d[p]<32)
{
write(stdout,&scr,1);
write(stdout,&hxp,1);
Byte2Hex(d[p]);
}
else if(d[p]=='\\')
{
write(stdout,&scr,1);
write(stdout,&scr,1);
}
else if(d[p]=='\"')
{
write(stdout,&scr,1);
write(stdout,&quo,1);
}
else write(stdout,d+p,1);
}

write(stdout,&quo,1);
return e+l+1;
}

size_t PrintLst(const uint8_t* d, size_t shift, size_t len, int skip)
{
size_t ishift=shift+1;

write(stdout,&blst,1);
write(stdout,&ret,1);

while(d[ishift]!='e')
{
PrintSpc(skip+1);
ishift=PrintObj(d,ishift,len,skip+1);
write(stdout,&ret,1);
if(ishift>=len) exit(2);
}
PrintSpc(skip);
write(stdout,&elst,1);
return ishift+1;
}

size_t PrintDct(const uint8_t* d, size_t shift, size_t len, int skip)
{
size_t ishift=shift+1;

write(stdout,&bdct,1);
write(stdout,&ret,1);

while(d[ishift]!='e')
{
PrintSpc(skip+1);
if(DetType(d,ishift)!=OBJ_STR) exit(2);
ishift=PrintStr(d,ishift,len);
write(stdout,&sp,1);
write(stdout,&eqv,1);
write(stdout,&sp,1);
ishift=PrintObj(d,ishift,len,skip+1);
write(stdout,&ret,1);
if(ishift>=len) exit(2);
}
PrintSpc(skip);
write(stdout,&edct,1);
return ishift+1;
}

int main(int argc, char** argv)
{
if(argc!=2) return 1;

int fd;
struct stat st;
uint8_t *pdata;

fd=open(argv[1],O_RDONLY); if(fd==-1) return 1;
if(fstat(fd,&st)!=0) return 1;
if(st.st_size==0) return 1;
pdata=(uint8_t*) mmap(0,st.st_size,PROT_READ,MAP_SHARED,fd,0);
PrintDct(pdata,0,st.st_size,0);
write(stdout,&ret,1);
munmap(pdata,st.st_size);
close(fd);

return 0;
}
Loading

0 comments on commit baca1fc

Please sign in to comment.