26-02-2019, 14:51
Code :
proc cBase64 inbuf,outbuf,outbuflen
mov esi,[inbuf]
mov edi,[outbuf]
mov ecx,[outbuflen]
@re:
or byte [esi],0
jz @end
add dword [ecx],4
xor eax,eax
or byte [esi+2],0
jz @f
lodsb
ror eax,8
lodsw
bswap eax
call Encode
stosd
jmp @re
@@:
or byte [esi+1],0
jz @f
lodsw
ror ax,8
ror eax,8
call Encode
rol eax,8
mov al,0x3d
ror eax,8
stosd
jmp @re
@@:
lodsb
call Encode
rol eax,16
mov ax,0x3d3d
ror eax,16
stosd
jmp @re
@end:
ret
endp
proc Encode
push ecx
xor ecx,ecx
mov cl,4
@@:
xor ebx,ebx
mov bl,al
shr bl,2
rol eax,6
mov dl,byte [base64+ebx]
ror edx,8
dec cl
jnz @b
mov eax,edx
pop ecx
ret
endp
proc dBase64 inbuf,outbuf,outbuflen
mov esi,[inbuf]
mov edi,[outbuf]
mov ecx,[outbuflen]
@re:
or byte [esi],0
jz @end
or byte [esi+1],0
jz @end
cmp byte [esi+3],0x3d
jz @f
add dword [ecx],3
call Decode
stosw
ror eax,16
stosb
jmp @re
@@:
cmp byte [esi+2],0x3d
jz @f
mov byte [esi+3],0
add dword [ecx],2
call Decode
stosw
jmp @re
@@:
mov byte [esi+2],0
add dword [ecx],1
call Decode
stosb
jmp @re
@end:
ret
endp
proc Decode
push ecx
mov cl,4
@@:
lodsb
call strlen
shl dl,2
mov al,dl
shr eax,2
shl eax,8
dec cl
jnz @b
bswap eax
pop ecx
ret
endp
proc strlen
push edi
push ecx
xor cl,cl
mov edi,base64
not cl
repne scasb
not cl
dec cl
mov dl,cl
pop ecx
pop edi
ret
endp
base64 db 0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,\
0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,\
0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,\
0x59,0x5a,0x61,0x62,0x63,0x64,0x65,0x66,\
0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,\
0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,\
0x77,0x78,0x79,0x7a,0x30,0x31,0x32,0x33,\
0x34,0x35,0x36,0x37,0x38,0x39,0x2b,0x2f
Code :
format PE console
include 'include/windows/win32a.inc'
include 'base64.inc'
;--------------------------------------------------
section '.text' code readable executable
;--------------------------------------------------
entry $
invoke CreateFile,FilePath1,GENERIC_READ,NULL,NULL,\
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL
mov [hFile1],eax
invoke GetFileSize,[hFile1],NULL
mov [nSize],eax
invoke CreateFile,FilePath2,GENERIC_WRITE,NULL,NULL,\
CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
mov [hFile2],eax
invoke ReadFile,[hFile1],readbuf,[nSize],BytesRead,NULL
stdcall cBase64,readbuf,writebuf,BytesToWrite
invoke WriteFile,[hFile2],writebuf,[BytesToWrite],BytesWrite,NULL
invoke CloseHandle,[hFile1]
invoke CloseHandle,[hFile2]
invoke ExitProcess
proc ZeroMemory lpmem,length
mov edi,[lpmem]
xor ecx,ecx
mov ecx,[length]
xor al,al
repne stosb
ret
endp
;--------------------------------------------------
section '.data' data readable writeable
;--------------------------------------------------
fileptr dd 0
FilePath1 db 'file',0
FilePath2 db 'file64',0
hFile1 dd 0
hFile2 dd 0
nSize dd 0
NULL equ 0
readbuf rb 0x64
BytesRead dd 0
writebuf rb 0x64
BytesToWrite dd 0
BytesWrite dd 0
;--------------------------------------------------
section '.idata' import data readable writeable
;--------------------------------------------------
library kernel32, 'kernel32.dll',\
msvcrt, 'msvcrt.dll',\
user32, 'user32.dll',\
wsock32, 'Ws2_32.dll'
include 'include/windows/api/kernel32.inc'
include 'include/windows/api/user32.inc'
include 'include/windows/api/wsock32.inc'
import msvcrt,\
clock, 'clock',\
printf, 'printf',\
puts, 'puts',\
sprintf, 'sprintf',\
strcat, 'strcat'
A compiler avec Fasm
Connexion ou Inscription pour voir ce contenu ! C'est rapide ;)