I'm currently doing an encryption in some of my files as an exercise. However, I'm having a trouble in overwriting a .txt file and having a hard time identifying what went wrong. Below is the part of the code I've been working on which I think has the problem.
push 0
push FILE_ATTRIBUTE_NORMAL
push OPEN_EXISTING
push 0
push 0
push FILE_READ_DATA
push offset fData.cFileName
call CreateFile
mov hndl, eax
push 0
push hndl
call GetFileSize
mov fSize, eax
push 0
push offset bfrLen
push fSize
push offset bfr
push hndl
call ReadFile
push hndl
call CloseHandle
lea esi, bfr
mov al, [esi]
cmp al, 7fh
jg skip
encrypt:
mov al, [esi]
xor al, 0ffh
mov [esi], al
inc esi
mov al, [esi]
cmp al, 00h
jne encrypt
push 0
push FILE_ATTRIBUTE_NORMAL
push CREATE_ALWAYS
push 0
push 0
push FILE_WRITE_DATA
push offset file
call CreateFile
mov hndl, eax
push offset bfr
call lstrlen
push 0
push offset bfrLen
push fSize
push offset bfr
push hndl
call WriteFile
push hndl
call CloseHandle
skip:
ret
Review my code, guys! Thanks in advance.