Gonzalez Posted September 11, 2009 Report Posted September 11, 2009 .386p.model flat, stdcalloption casemap:none ; Case sensitiveinclude \Masm32\include\windows.incinclude \Masm32\include\kernel32.incinclude \Masm32\include\user32.incincludelib \Masm32\lib\kernel32.libincludelib \Masm32\lib\user32.libEnDeCryptfile proto :DWORDEnDeCryptfile2 proto :DWORD,:DWORDRc4_setkey proto :DWORD,:DWORDRc4_crypt proto :DWORD, :DWORD CTEXT MACRO text:VARARG LOCAL TxtName .data TxtName BYTE text,0 .code EXITM <ADDR TxtName> ENDM.datamykey db "omgwtfjusthappenedtherethen",0.data?data db 1024 dup(?) ; bytes read/write, can be turned uprc4keytable db 256 dup (?)HoldBuf db 256 dup(?)hFileRead dd ?SizeWritten dd ?SizeWritten2 dd ?hFileRead2 dd ?.codestart:invoke EnDeCryptfile,CTEXT("RC4d.exe") ; encrypts RC4.exe;invoke EnDeCryptfile,CTEXT("RC4d.exe"); decrypt RC4.exe;file test 2invoke EnDeCryptfile2,CTEXT("original.exe"),CTEXT("ENCRYPTED")invoke EnDeCryptfile2,CTEXT("ENCRYPTED"),CTEXT("DENCRYPTED.exe")invoke ExitProcess,0;writes encrypted/decrypted data back into same fileEnDeCryptfile proc inputfile:DWORDinvoke CreateFile,inputfile,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULLcmp eax,INVALID_HANDLE_VALUEje @Fmov hFileRead,eax.while TRUE invoke ReadFile,hFileRead,addr data,1,ADDR SizeWritten,NULL.break .if eax && SizeWritten == 0 invoke lstrlen,addr mykey invoke Rc4_setkey,addr mykey,eax invoke Rc4_crypt,addr data,1 invoke SetFilePointer,hFileRead,-1,0,FILE_CURRENT invoke WriteFile,hFileRead,addr data,1,ADDR SizeWritten2,NULL.endwinvoke CloseHandle,hFileRead @@:retEnDeCryptfile endp;writes en/decrypted file to external file, reads and writes 1024 bytes at a time but you can read as many as you like if you change the buffer sizeEnDeCryptfile2 proc inputfile:DWORD,savepath:DWORDinvoke CreateFile,inputfile,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,NULLcmp eax,INVALID_HANDLE_VALUEje @Fmov hFileRead,eaxinvoke CreateFile,savepath,GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_ARCHIVE,NULLmov hFileRead2,eax.while TRUE invoke ReadFile,hFileRead,addr data,1024,ADDR SizeWritten,NULL.break .if eax && SizeWritten == 0 invoke lstrlen,addr mykey invoke Rc4_setkey,addr mykey,eax invoke Rc4_crypt,addr data,1024 invoke WriteFile,hFileRead2,addr data,1024,ADDR SizeWritten2,NULL.endwinvoke CloseHandle,hFileReadinvoke CloseHandle,hFileRead2 @@:retEnDeCryptfile2 endpRc4_setkey proc Pass:DWORD, LenPass:DWORDpushadmov eax, 0FFFEFDFChmov ecx, 256/4Init_rc4keytable:mov dword ptr [rc4keytable+4*ecx-4], eaxsub eax, 04040404hdec ecxjnz Init_rc4keytablexor eax, eaxmov edi, PassKey_return:xor ebx, ebxmov esi ,LenPassjmp New_keyKey_loop:inc bldec esijz Key_returnNew_key:mov dl, byte ptr [rc4keytable+ecx]add al, byte ptr [edi+ebx]add al, dlmov dh, byte ptr [rc4keytable+eax]mov byte ptr [rc4keytable+ecx], dhmov byte ptr [rc4keytable+eax], dlinc cljnz Key_looppopadretRc4_setkey endpRc4_crypt proc iData:DWORD, LenData:DWORDpushadmov edi, LenDatamov esi, iDatatest edi, edijz Rc4_enc_exitxor eax, eaxxor edx, edxxor ecx, ecx xor ebx, ebxRc4_enc_loop:inc blmov dl, byte ptr [rc4keytable+ebx]add al, dlmov cl, byte ptr [rc4keytable+eax]mov byte ptr [rc4keytable+ebx], clmov byte ptr [rc4keytable+eax], dladd cl, dlmov cl, byte ptr [rc4keytable+ecx]xor byte ptr [esi], clinc esidec edijnz Rc4_enc_loopxor eax, eaxmov edi, offset rc4keytablemov ecx, 256/4cldrep stosdRc4_enc_exit:popadretRc4_crypt endpend starteNj0Y! Quote