flat assembler
Message board for the users of flat assembler.

Index > Windows > local variable order issue

Author
Thread Post new topic Reply to topic
nazha



Joined: 05 Mar 2009
Posts: 40
Location: Beijing, China
nazha 18 Mar 2009, 06:32
I wrote a function to create a file with specified flags:

format PE GUI

include 'win32ax.inc'

OPEN_READWRITE =0x00000002
OPEN_CREATE =0x00000004
OPEN_DELETEONCLOSE =0x00000008
OPEN_SHARE_WRITE =0x00000100

proc testproc filename, flags
locals
dwDesiredAccess dw 0
dwCreationDisposition dw 0
dwShareMode dw 0
dwFlagsAndAttributes dw 0
endl

;Flags And Attributes
xor eax, eax
mov eax, [flags]
and eax, OPEN_DELETEONCLOSE
.if eax=OPEN_DELETEONCLOSE
mov dword [dwFlagsAndAttributes], FILE_ATTRIBUTE_NORMAL or FILE_FLAG_DELETE_ON_CLOSE
.else
mov dword [dwFlagsAndAttributes], FILE_ATTRIBUTE_NORMAL
.endif

;Desired Access
xor eax, eax
mov eax, [flags]
and eax, OPEN_READWRITE
.if eax=OPEN_READWRITE
mov dword [dwDesiredAccess], GENERIC_READ or GENERIC_WRITE
.else
mov dword [dwDesiredAccess], GENERIC_READ
.endif

;Creation Disposition
xor eax, eax
mov eax, [flags]
and eax, OPEN_CREATE
.if eax=OPEN_CREATE
mov dword [dwCreationDisposition], OPEN_ALWAYS
.else
mov dword [dwCreationDisposition], OPEN_EXISTING
.endif

;Share Mode
xor eax, eax
mov eax, [flags]
and eax, OPEN_SHARE_WRITE
.if eax=OPEN_SHARE_WRITE
mov dword [dwShareMode], FILE_SHARE_READ or FILE_SHARE_WRITE
.else
mov dword [dwShareMode], FILE_SHARE_READ
.endif


invoke CreateFileA,[filename],dword [dwDesiredAccess],dword [dwShareMode],0,dword [dwCreationDisposition],dword [dwFlagsAndAttributes],0
ret
endp

section '.code' code readable executable
start:
stdcall testproc, "d:\test1.txt",OPEN_READWRITE or OPEN_CREATE
invoke ExitProcess,0
.end start



it does not work, but if I change the local variable's order:

locals
dwShareMode dw 0
dwDesiredAccess dw 0
dwCreationDisposition dw 0
dwFlagsAndAttributes dw 0
endl


it work well, why? also why I can not check [flags] directly like:.if [flags] and OPEN_SHARE_WRITE ?
Post 18 Mar 2009, 06:32
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20481
Location: In your JS exploiting you and your system
revolution 18 Mar 2009, 08:04
You need to define the locals as dwords
Code:
...
dwDesiredAccess dd 0
dwCreationDisposition dd 0
dwShareMode dd 0
dwFlagsAndAttributes dd 0
...    
Post 18 Mar 2009, 08:04
View user's profile Send private message Visit poster's website Reply with quote
nazha



Joined: 05 Mar 2009
Posts: 40
Location: Beijing, China
nazha 18 Mar 2009, 08:44
Oh, thanks!!!
Post 18 Mar 2009, 08:44
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.