In a program that I'm writing, the following call to CreateFile()
invoke CreateFile, offset bmp_path, GENERIC_WRITE+GENERIC_READ, \
0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
produces ERROR_NOACCESS (code 03E6h).
I intended to change the attributes but I get the same error.
Knows anybody what could be happening?
invoke CreateFile, offset bmp_path, GENERIC_WRITE+GENERIC_READ, \
0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
produces ERROR_NOACCESS (code 03E6h).
I intended to change the attributes but I get the same error.
Knows anybody what could be happening?
In a program that I'm writing, the following call to CreateFile()
invoke CreateFile, offset bmp_path, GENERIC_WRITE+GENERIC_READ, \
0, 0, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0
produces ERROR_NOACCESS (code 03E6h).
I intended to change the attributes but I get the same error.
Knows anybody what could be happening?
maby you should add FILE_SHARE_ flags ?
Try ADDR bmp_path instead of offset bmp_path. If that does not work, verify the validity of the content of your bmp_path. If the target file is not in the same directory as your app., the FULL path should be included.
Raymond
Raymond
Thak you for your help!
The problem here is the error code:
ERROR_NOACCESS
I understand that this error occurs when there is a invalid access to a memory location.
Here, I'm creating a file, I'm not intending access to any memory location. So that the
problem is not really this call.
I've finded the problem: bad stack alignment. I don't know if MASM cares about this
when it allocs local variables in the stack. But if you define local structures whose
size is not multiple of 4, your stack will stay bad alignmented and can occur errors
like this.
I resolve this adding this instruction after the local variables declarations:
and esp, -4
Some quotes:
> Try ADDR bmp_path instead of offset bmp_path
The "addr" directive is nice for local variables and here I use a global variable. This
directive only does:
lea eax, bmp_path
push eax
but "offset" does:
push offset bmp_path
> If that does not work, verify the validity of the content of your bmp_path. If the target
> file is not in the same directory as your app., the FULL path should be included.
I'm using the CREATE_ALWAYS, I'm creating a file, I'm not opening it.
Anyway, thank you :alright:
The problem here is the error code:
ERROR_NOACCESS
I understand that this error occurs when there is a invalid access to a memory location.
Here, I'm creating a file, I'm not intending access to any memory location. So that the
problem is not really this call.
I've finded the problem: bad stack alignment. I don't know if MASM cares about this
when it allocs local variables in the stack. But if you define local structures whose
size is not multiple of 4, your stack will stay bad alignmented and can occur errors
like this.
I resolve this adding this instruction after the local variables declarations:
and esp, -4
Some quotes:
> Try ADDR bmp_path instead of offset bmp_path
The "addr" directive is nice for local variables and here I use a global variable. This
directive only does:
lea eax, bmp_path
push eax
but "offset" does:
push offset bmp_path
> If that does not work, verify the validity of the content of your bmp_path. If the target
> file is not in the same directory as your app., the FULL path should be included.
I'm using the CREATE_ALWAYS, I'm creating a file, I'm not opening it.
Anyway, thank you :alright:
addr dose do
push offset ...
if it is used with a global variable.
as for your problem. If your calling GetLastError after CreateFile then that error code would sugest that there is a problem acess the memory at the offset suplied for the first paramater. Is there anything unusuall about this app?like self modifying code or the code has been placed in an arbitary area of memory.
push offset ...
if it is used with a global variable.
as for your problem. If your calling GetLastError after CreateFile then that error code would sugest that there is a problem acess the memory at the offset suplied for the first paramater. Is there anything unusuall about this app?like self modifying code or the code has been placed in an arbitary area of memory.
This is a "sample" of the erroneous code:
This is the correct code:
MASM generates this for the last:
Note that MASM automatically aligns the stack; it does:
add esp, -16
no:
add esp, -14
.386
.model flat, stdcall
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
include \masm32\include\user32.inc
includelib \masm32\lib\kernel32.lib
includelib \masm32\lib\user32.lib
.data
file db "file.txt", 0
caption db "error", 0
template db "Error code: %X", 0
.code
start:
call create
invoke ExitProcess, eax
create:
push ebp
mov ebp, esp
add esp, -14 ; <<<< no aligned buffer
invoke CreateFile, addr file, GENERIC_WRITE+GENERIC_READ, 0, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL, 0
inc eax
jne exit
invoke GetLastError
lea edx, [ebp-14]
invoke wsprintf, edx, addr template, eax
lea edx, [ebp-14]
invoke MessageBox, NULL, edx, addr caption, 0
xor eax, eax
leave
ret
exit:
dec eax
leave
ret
END start
This is the correct code:
.code
start:
call create
invoke ExitProcess, eax
create PROC
LOCAL buf[14]:byte
invoke CreateFile, addr file, GENERIC_WRITE+GENERIC_READ, 0, 0, CREATE_NEW,
FILE_ATTRIBUTE_NORMAL, 0
inc eax
jne exit
invoke GetLastError
invoke wsprintf, addr buf, addr template, eax
invoke MessageBox, NULL, addr buf, addr caption, 0
xor eax, eax
ret
exit:
dec eax
ret
create ENDP
MASM generates this for the last:
create proc
var_E = byte ptr -0Eh
push ebp
mov ebp, esp
add esp, 0FFFFFFF0h ; <- 0FFFFFFF0h = -10h (-16), is not -0Eh (-14)
push 0
push 80h
push 1
push 0
push 0
push 0C0000000h
push offset aFile_txt
call CreateFileA
inc eax
jnz short loc_40105D
call GetLastError
push eax
push offset ErrorCode
lea eax, [ebp+var_E]
push eax
call wsprintfA
add esp, 0Ch
push 0
push offset aError
lea eax, [ebp+var_E]
push eax
push 0
call MessageBoxA
xor eax, eax
leave
retn
Note that MASM automatically aligns the stack; it does:
add esp, -16
no:
add esp, -14