flat assembler
Message board for the users of flat assembler.

Index > Projects and Ideas > Bittorrent client in FASM - impossible?

Goto page Previous  1, 2, 3  Next
Author
Thread Post new topic Reply to topic
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Or, Split a file into nodes. Hash them, and link each node to it's appropriate preceding/succeeding node using the unique hash.
Post 13 May 2012, 07:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16861
Location: In your JS exploiting you and your system
revolution
Or, you know, like normal people do it, just encrypt it and post the key elsewhere.

All these disguising schemes are rather pointless since the public have to know how to undisguise it. They won't help you to hide whatever it is that you are trying to hide.
Post 13 May 2012, 07:34
View user's profile Send private message Visit poster's website Reply with quote
rohagymeg



Joined: 19 Aug 2011
Posts: 77
rohagymeg
sleepsleep reordering a 1gb file divided into 512kb pieces could take 2000!(factorial: 2000*1999*1998....*2*1) tries. This is very impractical, bad idea.
Post 13 May 2012, 12:00
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8487
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
revolution,
could the DMCA take down any website that host decrypt key?
Post 13 May 2012, 15:54
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8487
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
rohagymeg,
i don't understand, if you got the ordering key, you just need to reorder it 1 time.

the idea is more to skip the legal problem,
because this will makes torrent download doesn't mean you get exact file.

only further process of reordering result the corrupted file to be exact file.

so, the lawyer cannot prove you pirate any digital bits through torrent, (because u get different thing through download)

he needs to gather evidence that you do further process to reorder back those pieces.

now, does it makes sense?


Last edited by sleepsleep on 13 May 2012, 16:03; edited 1 time in total
Post 13 May 2012, 15:59
View user's profile Send private message Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
sleepsleep wrote:
rohagymeg,
i don't understand, if you got the ordering key, you just need to reorder it 1 time.

He was talking about implementation and speed. The one time you are talking about would require multiple stages. Wink
Post 13 May 2012, 16:01
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16861
Location: In your JS exploiting you and your system
revolution
sleepsleep wrote:
revolution,
could the DMCA take down any website that host decrypt key?
Not sure why you ask me, but AFAIK, DMCA is only a US law. So just post your stuff on non-US hosted sites. Or another option is not to go posting keys for any US copyrighted material.
Post 13 May 2012, 16:04
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8487
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
typedef,
multiple stages,, i don't get it too.
Post 13 May 2012, 16:06
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16861
Location: In your JS exploiting you and your system
revolution
sleepsleep wrote:
the idea is more to skip the legal problem,
because this will makes torrent download doesn't mean you get exact file.

only further process of reordering result the corrupted file to be exact file.

so, the lawyer cannot prove you pirate any digital bits through torrent, (because u get different thing through download)

he needs to gather evidence that you do further process to reorder back those pieces.

now, does it makes sense?
No, that doesn't make sense. Don't go fooling yourself to think that such things will somehow magically protect you.
Post 13 May 2012, 16:06
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8487
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
revolution wrote:
sleepsleep wrote:
revolution,
could the DMCA take down any website that host decrypt key?
Not sure why you ask me, but AFAIK, DMCA is only a US law. So just post your stuff on non-US hosted sites. Or another option is not to go posting keys for any US copyrighted material.


afaik, US law == everywhere law except in a few big countries...
Post 13 May 2012, 16:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16861
Location: In your JS exploiting you and your system
revolution
sleepsleep wrote:
afaik, US law == everywhere law except in a few big countries...
Let the brainwashing begin ...
Post 13 May 2012, 16:12
View user's profile Send private message Visit poster's website Reply with quote
rohagymeg



Joined: 19 Aug 2011
Posts: 77
rohagymeg
Now I understand what you meant sleepsleep. The problem with that is it's centralized.
However, your idea seems reasonable too. But still not practical.

The only real thing that could protect someone from law is VPN. And that is independent from p2p apps.
Post 13 May 2012, 16:21
View user's profile Send private message Reply with quote
rohagymeg



Joined: 19 Aug 2011
Posts: 77
rohagymeg
I made it guys! Test it yourself inside OllyDbg. I tested it with small data like below 64 byte, and with large data that needs multiple chunk processing(1MB random data). Don't forget to give the exact size in bytes of the data too.

I commented everything, and made the cleanest code possible in the sense that every small function is seperated. If you knowledgeable guys find anything that could be optimized better, show it!

Btw I will have to leave the project for a month, because of my studies. After that I'll have time to continue this project.
UPDATE1: I got an advice from SFeLi to use local labels. Changed the code accordingly.

SHA1:
Code:
;The main program calls this function whenever it needs to calculate the SHA1 identifier of a data.
;The 2 informations needed for an SHA1 function is the pointer to the data, and its size.
;The main code will push(pass) these 2 variables to this function, then call it.

;The calling convention is the following:

       ;push message_pointer
       ;push size_in_bytes
       ;call SHA1.ASM
       ;Now eax, ebx, ecx, edx, esi stores the h0, h1, h2, h3, h4 hashes respectively

;---------------------------------------------------------------------------------------------------


;Another copy needed for the size injection in the last chunk
        mov eax, [esp+4]
        mov [SHA1.Size], eax
;---------------------------------------------------------------------------------------------------


;Creating a 320 byte heap needed for storing the 80 dword
        invoke HeapCreate, HEAP_GENERATE_EXCEPTIONS, 0, 320
        mov [SHA1.Heap], eax
        invoke HeapAlloc, [SHA1.Heap], HEAP_GENERATE_EXCEPTIONS+HEAP_ZERO_MEMORY, 320 ;80 32bit words
        mov [SHA1.hMem], eax
;---------------------------------------------------------------------------------------------------


;Preprocessing - calculating how many 64B chunks are needed
        mov eax, [esp+4] ;Size in bytes
        inc eax ;for the appended 1 bit, 1 more byte is needed
        mov ecx, 64 ;512 bit
        idiv ecx
        push edx ;Saving remainder for the copying part
        cmp edx, 56 ;448 bit
        jbe SHA1.once
        add eax, 2 ;2 more chunks are needed
        mov [SHA1.chunk_option], 1
        jmp SHA1.twice

SHA1.once:
        inc eax ;Only 1 more chunk is needed
        mov [SHA1.chunk_option], 0

SHA1.twice:
        mov [SHA1.chunk_counter], ax ;Number of chunks needed for this data
;---------------------------------------------------------------------------------------------------


;The main loop starts here(repeats after every chunk) by copying the chunk to our allocated heap
SHA1.start_chunk_processing:
        mov esi, [esp+12] ;Source
        mov edi, [SHA1.hMem] ;Destination
        mov ecx, 64 ;For the 16 dwords
@@:
        cmp dword [esp+8], 0 ;If there is no more data then leave
        je SHA1.copying_done
        movsb
        dec dword [esp+8]
        loop @b

SHA1.copying_done:
        mov [esp+12], esi ;Updating the data pointer value
;---------------------------------------------------------------------------------------------------


;Append the necessary 1 bit after the data if the current chunk contains the last data
        cmp [SHA1.chunk_counter], 2 ;Are we in the last but one cycle(chunk)?
        jne @f
        cmp [SHA1.chunk_option], 0
        je  SHA1.skip_insert_size
        mov edx, [SHA1.hMem]
        add edx, [esp]
        dec edx
        mov byte [edx], 10000000b ;1 bit (80h) is appended to the end of data
        jmp SHA1.skip_insert_size

@@:
        cmp [SHA1.chunk_counter], 1 ;Are we in the last cicle(chunk)?
        jne SHA1.skip_insert_size
        cmp [SHA1.chunk_option], 0
        jne SHA1.bit_already_put
        mov edx, [SHA1.hMem]
        add edx, [esp]
        dec edx
        mov byte [edx], 10000000b ;1 bit (80h) is appended to the end of data
;---------------------------------------------------------------------------------------------------


;Insert size if this is the last chunk
SHA1.bit_already_put:
SHA1.insert_size:
        mov ebx, [SHA1.hMem]
        add ebx, 60
        mov ecx, [SHA1.Size]
        shl ecx, 3
        bswap ecx
        mov [ebx], ecx
;---------------------------------------------------------------------------------------------------


;Convert the 16 dwords to big endian
SHA1.skip_insert_size:
        mov esi, [SHA1.hMem]
        mov ecx, 16

SHA1.big_endian:
        mov eax, [esi]
        bswap eax
        mov [esi], eax
        add esi, 4
        loop SHA1.big_endian
;---------------------------------------------------------------------------------------------------


;Extending the 16 dword variables to 80 dword variables
        mov esi, [SHA1.hMem]
        add esi, 64
        mov ecx, 64

@@:
        mov edx, esi
        mov ebx, esi
        mov edi, esi
        mov eax, esi
        sub edx, 12 ;edx == i-3
        sub ebx, 32 ;ebx == i-8
        sub edi, 56 ;edi == i-14
        sub eax, 64 ;eax == i-16
        mov edx, [edx]
        mov ebx, [ebx]
        mov edi, [edi]
        mov eax, [eax]
        xor edx, ebx ;edx == (i-3) xor (i-8)
        xor edx, edi ;edx == (i-3) xor (i-8) xor (i-14)
        xor edx, eax ;edx == (i-3) xor (i-8) xor (i-14) xor (i-16)
        rol edx, 1 ;edx == leftrotate 1 [ (i-3) xor (i-8) xor (i-14) xor (i-16) ]
        mov [esi], edx ;Done
        add esi, 4 ;Next dword
        loop @b
;---------------------------------------------------------------------------------------------------


;Initializing the counter (0-80) and the pointer plus the hash values as the SHA1 specification says
        xor ecx, ecx
        mov eax, [SHA1.hMem]
        mov esi, [SHA1.h0]
        mov [SHA1.a], esi ;a = h0
        mov esi, [SHA1.h1]
        mov [SHA1.b], esi ;b = h1
        mov esi, [SHA1.h2]
        mov [SHA1.c], esi ;c = h2
        mov esi, [SHA1.h3]
        mov [SHA1.d], esi ;d = h3
        mov esi, [SHA1.h4]
        mov [SHA1.e], esi ;e = h4
;---------------------------------------------------------------------------------------------------


;1st 20 cycle  ==>  f(edx) = (b and c) or ((not b) and d)
SHA1.chunk_cycle:
        cmp ecx, 80
        je SHA1.next_chunk
        cmp ecx, 19
        ja @f
        mov edx, [SHA1.b]
        and edx, [SHA1.c]
        mov esi, [SHA1.b]
        not esi
        and esi, [SHA1.d]
        or edx, esi
        mov ebx, 0x5A827999
        jmp SHA1.make_temp
;---------------------------------------------------------------------------------------------------


;2nd 20 cycle  ==>  f(edx) = b xor c xor d
@@:
        cmp ecx, 39
        ja @f
        mov edx, [SHA1.b]
        xor edx, [SHA1.c]
        xor edx, [SHA1.d]
        mov ebx, 0x6ED9EBA1
        jmp SHA1.make_temp
;---------------------------------------------------------------------------------------------------


;3rd 20 cycle  ==>  f(edx) = (b and c) or (b and d) or (c and d)
@@:
        cmp ecx, 59
        ja @f
        mov edx, [SHA1.b]
        and edx, [SHA1.c]
        mov esi, [SHA1.b]
        and esi, [SHA1.d]
        or edx, esi
        mov esi, [SHA1.c]
        and esi, [SHA1.d]
        or edx, esi
        mov ebx, 0x8F1BBCDC
        jmp SHA1.make_temp
;---------------------------------------------------------------------------------------------------


;4th 20 cycle  ==>  f(edx) = b xor c xor d
@@:
        mov edx, [SHA1.b]
        xor edx, [SHA1.c]
        xor edx, [SHA1.d]
        mov ebx, 0xCA62C1D6
;---------------------------------------------------------------------------------------------------


;temp(edi) = (a leftrotate 5) + f + e + k + w[i]
SHA1.make_temp:
        mov edi, [SHA1.a]
        rol edi, 5
        add edi, edx
        add edi, [SHA1.e]
        add edi, ebx
        add edi, [eax]
;---------------------------------------------------------------------------------------------------


;e = d; d = c; c = leftrotate 30 (b); b = a; a = temp(edi)
        mov esi, [SHA1.d]
        mov [SHA1.e], esi ;e = d
        mov esi, [SHA1.c]
        mov [SHA1.d], esi ;d = c
        mov esi, [SHA1.b]
        rol esi, 30
        mov [SHA1.c], esi ;c = b leftrotate 30
        mov esi, [SHA1.a]
        mov [SHA1.b], esi ;b = a
        mov [SHA1.a], edi ;a = temp(edi)
        inc ecx
        add eax, 4
        jmp SHA1.chunk_cycle
;----------------------------chunk processing done --------------------------------------------------


;This chunk's hash is added to the result
SHA1.next_chunk:
        mov esi, [SHA1.a]
        add [SHA1.h0], esi ;h0 += a
        mov esi, [SHA1.b]
        add [SHA1.h1], esi ;h1 += b
        mov esi, [SHA1.c]
        add [SHA1.h2], esi ;h2 += c
        mov esi, [SHA1.d]
        add [SHA1.h3], esi ;h3 += d
        mov esi, [SHA1.e]
        add [SHA1.h4], esi ;h4 += e
;---------------------------------------------------------------------------------------------------


;Preparing for the next chunk
        mov esi, [SHA1.hMem] ;Zeroing our memory (after the 16 dwords it's not necessary)
        mov ecx, 16
@@:
        mov dword [esi], 0 ;Clear dword
        add esi, 4
        loop @b

        cmp [SHA1.chunk_counter], 1 ;If this was the last chunk,
        je @f ;SHA1 is calculated, quitting from main loop
        dec [SHA1.chunk_counter] ;Else start processing the next one
        jmp SHA1.start_chunk_processing
;---------------------------------------------------------------------------------------------------


;This is the point where the valid hash should be in the h0,h1,h2,h3,h4 variables
@@:
        mov eax, [esp+4] ;Cleaning up the stack
        mov [esp+12], eax
        add esp, 12
        mov eax, [SHA1.h0]
        mov ebx, [SHA1.h1]
        mov ecx, [SHA1.h2]
        mov edx, [SHA1.h3]
        mov esi, [SHA1.h4]
        bswap eax
        bswap ebx
        bswap ecx
        bswap edx
        bswap esi
;---------------------------------------------------------------------------------------------------


;Resetting variables to their initial value before returning
        mov [SHA1.a], 0x67452301
        mov [SHA1.b], 0xEFCDAB89
        mov [SHA1.c], 0x98BADCFE
        mov [SHA1.d], 0x10325476
        mov [SHA1.e], 0xC3D2E1F0
        mov [SHA1.h0], 0x67452301
        mov [SHA1.h1], 0xEFCDAB89
        mov [SHA1.h2], 0x98BADCFE
        mov [SHA1.h3], 0x10325476
        mov [SHA1.h4], 0xC3D2E1F0
;---------------------------------------------------------------------------------------------------


        ret


SHA1: ;Every label in this file is a local label of the SHA1 label
.a                       dd ?
.b                       dd ?
.c                       dd ?
.d                       dd ?
.e                       dd ?

.h0                      dd 0x67452301
.h1                      dd 0xEFCDAB89
.h2                      dd 0x98BADCFE
.h3                      dd 0x10325476
.h4                      dd 0xC3D2E1F0

.chunk_counter           dw ?
.chunk_option            db ?
.hMem                    dd ?
.Heap                    dd ?
.Size                    dd ?
    


I used these sources:
http://www.itl.nist.gov/fipspubs/fip180-1.htm
http://en.wikipedia.org/wiki/SHA-1
http://www.faqs.org/rfcs/rfc3174.html


Last edited by rohagymeg on 24 Oct 2012, 00:42; edited 5 times in total
Post 20 May 2012, 19:10
View user's profile Send private message Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 8487
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 334455
sleepsleep
there is a qbittorrent in sourceforge that maybe could be your reference, btw, i use qbittorrent for my daily download.
Post 24 May 2012, 18:50
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3500
Location: Bulgaria
JohnFound
I also use qbittorrent, but only because I hate uTorrent more. Very Happy
Qt is big, slow and non responsive.
I really need fTorrent! Smile
Post 24 May 2012, 19:13
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
rohagymeg



Joined: 19 Aug 2011
Posts: 77
rohagymeg
FASMTorrent/FlatTorrent would be good name choices Smile

I'm on it. But for now I don't have time. Also, I know nothing about DHT, trackers, peers communication, etc. At least the SHA1 part is done. The next 2 modules I'm gonna make is the torrent maker and its parser(reader). After that, I could dive into the more challenging part, which makes BitTorrent unique from other download managers, the protocol itself. I hope at that time I will have already had some assembly gurus join the project.

I'm ok with doing most of the work, but I'd need to ask lots of questions here.
I'm curious as to how many of you want to actively take part in this? By actively I mean making code. Testers would be also welcome, because bugs happen.
Post 24 May 2012, 19:56
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 204
Location: Brazil
ctl3d32
Count on me!
Post 15 Jul 2012, 18:31
View user's profile Send private message Reply with quote
rohagymeg



Joined: 19 Aug 2011
Posts: 77
rohagymeg
I'm almost done with the torrent maker UI. However I got into a funny problem that I didn't care about until I did the whole recreation of utorrent's maker window(well except the "skip files" part). A picture tells 1000 words:

Image

I have no idea why this is happening and what I should do to make my window's style look like utorrent's. Help please!
Post 23 Jul 2012, 16:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16861
Location: In your JS exploiting you and your system
revolution
You'll need a manifest to use the new styles in Windows. Search on this board for examples of using a manifest, there are many.
Post 23 Jul 2012, 16:50
View user's profile Send private message Visit poster's website Reply with quote
rohagymeg



Joined: 19 Aug 2011
Posts: 77
rohagymeg
GREAT! Another field to learn. That's what I wanted! I needed that so much! My head will surely not explode!

Image
Much better! Now ONLY the fonts are fucked up.
Post 23 Jul 2012, 18:28
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2, 3  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.