Base64Encode proto :DWORD, :DWORD
Base64Decode proto :DWORD, :DWORD
MainProc proto :DWORD,:DWORD,:DWORD,:DWORD
.data
szBuffer db 255 dup(0)
szText db 340 dup(0)
szMsg db 450 dup(0)
szTemplate_Encode db "%s", 13, 10, 13, 10, "%s", 0
szTemplate_Decode db "%s", 13, 10, 13, 10, "%s", 0
;Base64 -> ASCII mapping table
base64_alphabet db "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
;ASCII -> Base64 mapping table
base64table db 43 dup (255)
db 62,255,255,255,63,52,53,54,55,56,57,58,59,60,61,255
db 255,255,0,255,255,255,0,1,2,3,4,5,6,7,8,9,10,11,12,13
db 14,15,16,17,18,19,20,21,22,23,24,25,255,255,255,255
db 255,255,26,27,28,29,30,31,32,33,34,35,36,37,38
db 39,40,41,42,43,44,45,46,47,48,49,50,51
db 132 dup (255)
.data?
hInst dd ?
szUserName dd ?
szUserCode dd ?
xchg al,ah ;flip eax completely
rol eax, 16 ;can this be done faster
xchg al,ah
@@:
push eax
and eax, 0FC000000h ;get the last 6 high bits
rol eax, 6 ;rotate them into al
mov al, byte ptr [offset base64_alphabet + eax] ;get encode character
stosb ;write to destination
pop eax
shl eax, 6 ;shift left 6 bits
dec ecx
jnz @B ;loop
cmp sourcelen, 0
jnz @@base64loop ;main loop
mov eax, edx ;add padding and null terminate
stosd
ret
Base64Encode endp
;**********************************************************
;函数功能:进行Base64解码
;参数:
; source = 传入的编码
; destination = 返回的字符串
;**********************************************************
Base64Decode proc uses ebx edi esi source:DWORD, destination:DWORD
LOCAL sourcelen:DWORD