XR3X

Jump to content


Photo

RC4 [FASM]


  • You cannot start a new topic
  • Please log in to reply
15 replies to this topic

#1 Jochen

Jochen

    Intermediate Member

  • Notorious
  • 149 posts
Contributor

Posted 17 September 2014 - 04:59 PM

Just something i needed translated from MASM for FASM.

Maybe someone can use it to, so i might as well post it here :)

 

Credits for original MASM version go to the tiny banker bot coder.

 

 

--------------------------------------------------------------------------------------

 

 proc crypt stdcall lpData:dword, dwLen:dword

        locals
        dwlpKeyTable dd ?
        endl

        pushad
        invoke VirtualAlloc, 0, 256, MEM_COMMIT or MEM_RESERVE, PAGE_READWRITE
        mov  [dwlpKeyTable], eax

        stdcall RC4SetKey, [dwlpKeyTable], szPassword, 20; <-- Lenght of password
        stdcall RC4Crypt,  [dwlpKeyTable], [lpData], [dwLen]

        invoke VirtualFree,[dwlpKeyTable], 0, MEM_RELEASE
        popad
        ret
        endp


        proc RC4SetKey stdcall lpKeyTable:dword, lpPass:dword, nPass:dword
        pushad
        mov  edi,[lpKeyTable]
        xor  ecx, ecx
        @@: mov  [edi + ecx], cl
        inc  ecx
        cmp  ecx, 256
        jne  @b
        mov  esi,[lpPass]
        xor  ebx, ebx
        xor  ecx, ecx
        xor  edx, edx
        @@: mov  al, [edi + ecx]
        add  bl, [esi + edx]
        add  bl, al
        mov  ah, [edi + ebx]
        mov  [edi + ecx], ah
        mov  [edi + ebx], al
        inc  ecx
        cmp  ecx, 256
        je   @f
        inc  edx
        cmp  edx,[nPass]
        jl   @b
        xor  edx, edx
        jmp  @b
        @@: popad
        leave
        retn 4*3; Size of dword * 3
        endp



        proc RC4Crypt stdcall pKeyTable:dword, lpData:dword, nData:dword
        pushad
        mov  edi,[pKeyTable]
        mov  esi,[lpData]
        xor  eax, eax
        xor  ebx, ebx
        xor  ecx, ecx
        xor  edx, edx
        @@:inc  bl
        mov  dl, [edi + ebx]
        add  al, dl
        mov  cl, [edi + eax]
        mov  [edi + ebx], cl
        mov  [edi + eax], dl
        add  cl, dl
        mov  cl, [edi + ecx]
        xor  [esi], cl
        inc  esi
        dec  [nData]
        jnz  @b
        popad
        leave
        retn 4*3; Size of dword * 3 params pushed by this proc :)
        endp

 



#2 Tigerass

Tigerass

    Member

  • Loyalist
  • 709 posts
  • LocationNorthern Syria
Contributor

Posted 17 September 2014 - 07:45 PM

Why do you use asm for this? I see no need for such kind of functions.



#3 Jochen

Jochen

    Intermediate Member

  • Notorious
  • 149 posts
Contributor

Posted 18 September 2014 - 09:20 AM

Why do you use asm for this? I see no need for such kind of functions.

 

Well .. if you program FASM you need an ASM version of it. Seems logic .. no ?

Im having a hard time compiling Delphi or C++ code in the FASM compiler :D

 



#4 Tigerass

Tigerass

    Member

  • Loyalist
  • 709 posts
  • LocationNorthern Syria
Contributor

Posted 18 September 2014 - 10:42 AM

Hm not neccessarily. Or what do you think .lib/.obj/.a's are? :P

Thanks god that there is a thing called linker ;)



#5 Jochen

Jochen

    Intermediate Member

  • Notorious
  • 149 posts
Contributor

Posted 18 September 2014 - 12:26 PM

Hm not neccessarily. Or what do you think .lib/.obj/.a's are? :P

Thanks god that there is a thing called linker ;)

 

I dont do .lib/.obj/... This is a FASM code in an ASM section. ;)



#6 LeFF

LeFF

    Expert

  • Moderator
  • 830 posts
Contributor

Posted 18 September 2014 - 12:34 PM

@Tigerass if someone wants to develop software like it was done in stone age, just let him do it...



#7 Tigerass

Tigerass

    Member

  • Loyalist
  • 709 posts
  • LocationNorthern Syria
Contributor

Posted 18 September 2014 - 01:58 PM

I mean... there really is no difference between compiled C and asm code. Maybe the C one is smaller / more efficient... No nned for that much possible errors and work.



#8 Jochen

Jochen

    Intermediate Member

  • Notorious
  • 149 posts
Contributor

Posted 20 September 2014 - 10:20 AM

I mean... there really is no difference between compiled C and asm code. Maybe the C one is smaller / more efficient... No nned for that much possible errors and work.

 

Maybe you should tell that here -->

Please Login or Register to see this Hidden Content

:D

 

 


Edited by Jochen, 20 September 2014 - 10:37 AM.


#9 Tigerass

Tigerass

    Member

  • Loyalist
  • 709 posts
  • LocationNorthern Syria
Contributor

Posted 20 September 2014 - 11:23 AM

There is a difference between serious developing and coding around as a hobby. But it's up to you.

I even started planning my projects with uml and other tools. Reduces errors, you have a good overview, and if you have implemented everything it just works on the first run.
  • LeFF likes this

#10 LeFF

LeFF

    Expert

  • Moderator
  • 830 posts
Contributor

Posted 20 September 2014 - 04:04 PM

I even started planning my projects with uml and other tools. Reduces errors, you have a good overview, and if you have implemented everything it just works on the first run.

yes, the more high the level the easier development process is... and I don't see any point in developing software in asm these days either... here is

Please Login or Register to see this Hidden Content

implementation from PolarSSL for example... it is simpler (even for a more complex algorithm), more readable, compiles to any processor (x86, x64, ARM, PowerPC you name it) and usually compiles down to more optimized code in terms of size and speed of execution... but again some people like to code in asm for some reason, some people likes to embed shellcode inside VB6, who am I to blame or make fun of them... :D



#11 Jochen

Jochen

    Intermediate Member

  • Notorious
  • 149 posts
Contributor

Posted 20 September 2014 - 08:46 PM

Yes i understand .. You call people dumb for programming in ASM.

I saw the link about RC4 in C you posted and it's nice clean to the point code.

If you would need it, you would just include it into your project right ?

I'ts the same for FASM. If you have it you can add it to your project.

I use to do everything in Delphi. And one of the stupid problems i came across was that I wanted the cursor to change in a hand when i moved from the form to a button.

In high level it's just a setting you have to do, in ASM you learn about a thing called sub classing. After you know it and need it, you just add it to your project.

I learn about making and understanding it as i go along. This is the reason why i like to program, i always discover something new and interesting.


Edited by Jochen, 20 September 2014 - 08:47 PM.


#12 LeFF

LeFF

    Expert

  • Moderator
  • 830 posts
Contributor

Posted 21 September 2014 - 09:02 AM

Yes i understand .. You call people dumb for programming in ASM

I don't call people dumb for programming in ASM, I'm saying that it doesn't make any sence nowadays, when you have a number of high quality compilers for languages at the higher level of abstraction, that provides portability, faster development time, easier code support and etc... anyone can code with whatever he/she wants, I don't give a whole lot of a shit really...



#13 Jochen

Jochen

    Intermediate Member

  • Notorious
  • 149 posts
Contributor

Posted 24 September 2014 - 09:33 PM

lea eax,[szBuffer]

push eax

 

Is more clean code then

 

push dword [szBuffer]

 

Im now doing tests and post the results soon.

frankly i think you to dumb to understand ASM

 

 



#14 LeFF

LeFF

    Expert

  • Moderator
  • 830 posts
Contributor

Posted 25 September 2014 - 05:08 AM

frankly i think you to dumb to understand ASM


  • Jochen, Rottweiler and GoodWill like this

#15 OnTheCore

OnTheCore

    Beginner

  • Members +
  • 11 posts

Posted 29 September 2014 - 12:24 AM

Productively is a little bit dumb, but is great for increasing the knowledge. Keep working in this way, mate.


  • Jochen and x58 like this

#16 tigo

tigo

    Member

  • Members +
  • 46 posts

Posted 07 February 2015 - 10:13 AM

The main reason is that you have a full control of code when you code in asm (Register, Memory, etc..)