flat assembler
Message board for the users of flat assembler.

Index > Main > How to push String constant(how does stdcall solve it?)

Author
Thread Post new topic Reply to topic
Memnarch



Joined: 13 Mar 2012
Posts: 7
Memnarch 20 Mar 2012, 09:21
Hello,
Ofcourse i dont think stdcall is pushing a whole string constant to the stack. But how does it solve a string constant? How does it receive an address?

example:

Code:
stdcall myproc, 'sometext'
    

Works fine. But how do i resolve this if i want to do this manually for example?

PS: Iam new to FASM/ASM

Greetings
Memnarch
Post 20 Mar 2012, 09:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 20 Mar 2012, 09:34
Code:
    call @f
    db   'sometext',0
@@: call myproc    


Last edited by revolution on 20 Mar 2012, 10:57; edited 1 time in total
Post 20 Mar 2012, 09:34
View user's profile Send private message Visit poster's website Reply with quote
Memnarch



Joined: 13 Mar 2012
Posts: 7
Memnarch 20 Mar 2012, 09:59
Ah thanks.
And in this case the address can be expected in eax?
Post 20 Mar 2012, 09:59
View user's profile Send private message Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 20 Mar 2012, 10:00
revolution wrote:
Code:
    call @f
    db   'sometext',0
@f: call myproc    
An alternate method to avoid return stack mispredictions.
Code:
  jmp @F
  .1: db 'sometext', 0
@@:
  push .1
  call myproc    
This is the method used in fasmx (operating system independent HLL macros).
In fasmx the call instruction is overloaded so the code would look like this:
Code:
  call myproc, 'sometext'    

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com


Last edited by Mike Gonta on 20 Mar 2012, 10:06; edited 1 time in total
Post 20 Mar 2012, 10:00
View user's profile Send private message Visit poster's website Reply with quote
Memnarch



Joined: 13 Mar 2012
Posts: 7
Memnarch 20 Mar 2012, 10:03
Ah great.
and @F was jumping forward to the next anonymous labe.
This method seems more usable in my case.
Thanks for your Help
Post 20 Mar 2012, 10:03
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 20 Mar 2012, 11:09
Just a slightly related fyi ... seems like you end up with a lot more false positives on virus scanners when you put constants in your code section.

Unreliable anecdotal evidence: when I was testing something with FASM at work I put a LUT in the .code section instead of properly in .data section and Symantec flagged it when I compiled.

Seems like the heuristics check for .code section memory accesses.

Anyways put string constants properly in your .data section, also align them by 8 bytes.
Post 20 Mar 2012, 11:09
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
Memnarch



Joined: 13 Mar 2012
Posts: 7
Memnarch 20 Mar 2012, 12:59
@r22: Ah ok. Thanks for the advice.

Another small question (if its allowed to ask it without creating a new thread).

Lets say i have 2 string values:

Code:
str1 db 'string1'
str2 db 'string2'
    


Now i need a variable, which points at str1 or str2. Normally i would use lea to get the adress.

But is it possible, to define a variable and initialise it with an address of another Variable?

so
Code:
str1 db 'string1'
str2 db 'string2'
myvar dd [adress of str1]
    


instead of
Code:
str1 db 'string1'
str2 db 'string2'
myvar dd ?
...
lea [myvar], str1
    
[/code]
Post 20 Mar 2012, 12:59
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1403
Location: Piraeus, Greece
Picnic 20 Mar 2012, 13:21
Code:
myvar dd str1    ; define a variable and initialise it with an address of another Variable
    

or
Code:
mov [myvar], str1 
    


Things are easier in Fasm Smile
Post 20 Mar 2012, 13:21
View user's profile Send private message Visit poster's website Reply with quote
Memnarch



Joined: 13 Mar 2012
Posts: 7
Memnarch 20 Mar 2012, 13:40
Ah thanks,
just noticed, that its not possible to load an address like this if its defined locally(in locals..endl), is this correct?
(Sofar it worked only with a globally declared string and a local var)

Greets
Memnarch
Post 20 Mar 2012, 13:40
View user's profile Send private message Reply with quote
Mike Gonta



Joined: 26 Dec 2010
Posts: 243
Mike Gonta 20 Mar 2012, 21:47
Memnarch wrote:
just noticed, that its not possible to load an address like this if its defined locally(in locals..endl), is this correct?
That's right, local variables are dynamic (allocated on the stack at runtime) and have no static address. But you can do this:
Code:
locals
mytext db 'sometext', 0   ; fasm initializes this at runtime
endl
  call someproc, addr mytext    

fasmx (operating system independent HLL macros).

_________________
Mike Gonta
look and see - many look but few see

https://mikegonta.com
Post 20 Mar 2012, 21:47
View user's profile Send private message Visit poster's website Reply with quote
Memnarch



Joined: 13 Mar 2012
Posts: 7
Memnarch 21 Mar 2012, 09:19
Thanks Mike.

As for the previous example:

When declaring a var and initialising it with the adress of another var, is it possible to add an offset?(Maybe if not directly, its possible to define a struct which has 2 integers, defining a var using it and defining a var for it which points at the second integer)

Greets
Memnarch
Post 21 Mar 2012, 09:19
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.