flat assembler
Message board for the users of flat assembler.

Index > Windows > Push offset in a DLL

Author
Thread Post new topic Reply to topic
DustWolf



Joined: 26 Jan 2006
Posts: 373
Location: Ljubljana, Slovenia
DustWolf 23 Nov 2006, 17:17
Hello,

I'm evidently having a problem expressing myself properly in this code:
Code:
proc WriteEntry         uses esi edi ebx,fileName,entryText

locals
lineBreak    db      13,10,0
fileHandle   dd      ?
textLen      dd      0
lenGot       dd      ?
endl

     invoke     CreateFile,[fileName],GENERIC_WRITE,0,0,OPEN_ALWAYS,FILE_ATTRIBUTE_TEMPORARY,0
     mov        [fileHandle],eax

     ;code to calculate textLen here

     invoke     WriteFile,[fileHandle],entryText,[textLen],lenGot,0

     invoke     CloseHandle,[fileHandle]
     ret

endp    


The code is supposed to open a file, write something to it and close it.

The assembler says it has a problem in pushing the local "entryText" and "lenGot"'s offsets to the stack. How to fix this?

Am I getting at this problem the wrong way?
Post 23 Nov 2006, 17:17
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 23 Nov 2006, 18:06
local labels are defined as:

Code:
label lenGot dword at [ebp-8]
    


that means, if you try to just "push lenGot", it is as if you would write "push dword [ebp-8]". and this is not possible.

you can do it this way:
Code:
lea eax, [lenGot]  ;lea eax, [ebp-8]
invoke Proc, 1, 2, eax, 3
    
.

or, FASM high-level call macros have feature that does this for you. it's pseudo-operator "addr". used like this:

Code:
invoke     WriteFile,[fileHandle],addr entryText,[textLen],addr lenGot,0
    
Post 23 Nov 2006, 18:06
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan 23 Nov 2006, 20:09
i would suggest avoiding of using addr over other ways cuz it spoils edx and
Code:
invoke   SomeProc, [param1], edx, addr local1    

will compile correctly but behave WRONG.

_________________
Any offers?
Post 23 Nov 2006, 20:09
View user's profile Send private message Reply with quote
DustWolf



Joined: 26 Jan 2006
Posts: 373
Location: Ljubljana, Slovenia
DustWolf 23 Nov 2006, 20:22
vid wrote:
Code:
invoke     WriteFile,[fileHandle],addr entryText,[textLen],addr lenGot,0
    


This still generates the same error. The long version is fine tho.
Post 23 Nov 2006, 20:22
View user's profile Send private message Reply with quote
asmfan



Joined: 11 Aug 2006
Posts: 392
Location: Russian
asmfan 23 Nov 2006, 20:27
By the way, include extended inc files - *x.inc or *xp.inc instead of win32*.inc to have support of "addr"
Post 23 Nov 2006, 20:27
View user's profile Send private message Reply with quote
DustWolf



Joined: 26 Jan 2006
Posts: 373
Location: Ljubljana, Slovenia
DustWolf 23 Nov 2006, 23:25
I am having some further trouble here...

For example:
Code:
proc Plop         uses esi edi ebx,mesage
        mov     eax,[mesage]
        invoke  MessageBox,0,eax,0,MB_OK
        ret
endp
    


With imports defined and all, when used like this:
Code:
                invoke   Plop,entryText
                invoke  ExitProcess,0

entryText       db      'Works!',0    


Crashes. Why?
Post 23 Nov 2006, 23:25
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 24 Nov 2006, 00:26
because you are issuing a "call dword ptr [Plop]" due to the use of invoke instead of stdcall
Post 24 Nov 2006, 00:26
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.