Пытаюсь сделать программу, которая читает файл и сохраняет в кодировке base64, не могу найти ошибку в ниже изложенном листинге...
.386
.model flat, stdcall
option casemap :none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\advapi32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\advapi32.lib
.data
b64Attach dd 0
b64AttachLen dd 0
lpDestFile db "file.exe",0
szSFileName db "base64.txt",0
.code
Base64Encode proc uses esi edi ebx lpSrc, lpDst, dwSrcLen: DWORD
mov esi, lpSrc
mov edi, lpDst
mov ecx, dwSrcLen
xor ebx, ebx
@l:
jecxz @b64_ret
lodsb
shl eax, 16
cmp ecx, 1
jz @work
lodsb
shl ax, 8
cmp ecx, 2
jz @work
lodsb
@work:
; Output b64 quad
mov edx, eax
ror edx, 24
push ecx
push 4
pop ecx
@l2:
call @b64_write
loop @l2
pop ecx
inc ebx
.IF ebx == 18
xor ebx, ebx
mov ax, 0a0dh
stosw
.ENDIF
sub ecx, 3
jns @l
; Pad
neg ecx
sub edi, ecx
mov al, '='
rep stosb
@b64_ret:
ret
@b64_write:
rol edx, 6
mov eax, edx
and al, 00111111b
cmp al, 62
jae @write_spec
cmp al, 52
jae @write_number
; Uppercase
add al, 'A'
cmp al, 'A'+26
jb @write
; Lowercase
add al, 6
jmp @write
; Number
@write_number:
add al, '0'-52
jmp @write
; Special: +/
@write_spec:
sub al, 62
shl al, 2
add al, 43
@write:
stosb
retn
Base64Encode endp
FileToBase64 proc uses ebx edi lpDestFileName, outMem, outLen: DWORD
LOCAL hFile, dwFileSize: DWORD
xor edi, edi
invoke CreateFile, lpDestFileName, GENERIC_READ, FILE_SHARE_READ or FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0
mov hFile, eax
inc eax
jz @file_open_error
invoke GetFileSize, hFile, 0
mov dwFileSize, eax
inc eax
jz @file_open_close
invoke CreateFileMapping, hFile, NULL, PAGE_READONLY, 0, 0, NULL
.IF eax
mov ebx, eax
invoke MapViewOfFile, eax, FILE_MAP_READ, 0, 0, 0
.IF eax
push eax
mov eax, dwFileSize
shl eax, 1
invoke GlobalAlloc, GPTR, eax
mov edx, outMem
mov [edx], eax
mov edx, [esp]
invoke Base64Encode, edx, eax, dwFileSize
mov edx, outMem
invoke lstrlen, [edx]
mov edx, outLen
mov [edx], eax
call UnmapViewOfFile
inc edi
.ENDIF
invoke CloseHandle, ebx
.ENDIF
@file_open_close:
invoke CloseHandle, hFile
@file_open_error:
mov eax, edi
ret
FileToBase64 endp
Save2file proc lpMailMessage: DWORD
LOCAL hFile, bWritten: DWORD
invoke CreateFile, offset szSFileName, GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, NULL, CREATE_ALWAYS, 0, 0
mov hFile, eax
inc eax
jz @end
invoke lstrlen, lpMailMessage
mov edx, eax
invoke WriteFile, hFile, lpMailMessage, edx, addr bWritten, NULL
invoke CloseHandle, hFile
@end:
mov eax, 1
ret
Save2file endp
start:
invoke FileToBase64, lpDestFile, offset b64Attach, offset b64AttachLen
invoke Save2file,b64Attach
invoke ExitProcess, 0
end start