Question: Can you comment these codes please? INCLUDE asmlib.inc CreateFileA Proto, fileName: PTR BYTE, accessMode: DWORD, shareMode : DWORD, securityAttrib : DWORD, creationDispo : DWORD, flagsAndAttrib
Can you comment these codes please?
INCLUDE asmlib.inc
CreateFileA Proto,
fileName: PTR BYTE,
accessMode: DWORD,
shareMode : DWORD,
securityAttrib : DWORD,
creationDispo : DWORD,
flagsAndAttrib : DWORD,
hTemplateFile : DWORD
ReadFile PROTO,
hHandle : DWORD,
lpBuffer : PTR BYTE,
nNumberOfBytesToRead : DWORD,
pNumberOfBytesRead : PTR DWORD,
lpOverlapped : PTR DWORD
CloseHandle PROTO, hObject : DWORD
WriteFile PROTO,
hHandle : DWORD,
lpBuffer : PTR BYTE,
nNumberOfBytesToWrite : DWORD,
pNumberOfBytesWritten : PTR DWORD,
lpOverlapped : PTR DWORD
GetLastError PROTO ; get most recent error return value
fWriteChar PROTO
fReadChar PROTO
GENERICREAD h
GENERICWRITE h
GENERICEXECUTE h
GENERICALL h
CREATENEW
CREATEALWAYS
OPENEXISTING
OPENALWAYS
TRUNCATEEXISTING
FILEATTRIBUTENORMAL h
NULL
data
fname BYTE "test.txt
buffer BYTE
code
main PROC
; Test fWriteChar
mov edx, OFFSET fname ; File name
mov eax,
call readChar
INVOKE fWriteChar
INVOKE fReadChar
exit
main ENDP
fWriteChar PROC uses edx eax
local outChar : BYTE, bytesWritten : DWORD, fHandle : DWORD
mov outChar, al ; Store the character to be written in the local variable
mov eax, ; Move the file name to eax register
; Open the file for writing
INVOKE CreateFileA, edx, GENERICWRITE, NULL, NULL, OPENALWAYS, FILEATTRIBUTENORMAL, NULL
mov fHandle, eax ; Store the file handle
; Write the character to the file
INVOKE WriteFile, fHandle, ADDR outChar, ADDR bytesWritten, NULL
; Close the file
INVOKE CloseHandle, fHandle
ret
fWriteChar ENDP
fReadChar PROC uses edx eax
local inChar: BYTE, bytesRead: DWORD, fHandle: DWORD
mov eax, ; Move the file name to eax register
; Open the file for reading
INVOKE CreateFileA, edx, GENERICREAD, NULL, NULL, OPENEXISTING, FILEATTRIBUTENORMAL, NULL
mov fHandle, eax ; Store the file handle
mov eax,
; Read a single character from the file
INVOKE ReadFile, fHandle, ADDR buffer, ADDR bytesRead, NULL
mov edx, OFFSET buffer
call writeLine
; Close the file
INVOKE CloseHandle, fHandle
mov al inChar ; Move the read character to al register for return
ret
fReadChar ENDP
END main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
