flat assembler
Message board for the users of flat assembler.

Index > Main > static variables

Author
Thread Post new topic Reply to topic
Alessio



Joined: 26 Sep 2003
Posts: 35
Location: Viterbo, Italy
Alessio 12 Nov 2008, 10:27
Hi,

sorry for my weird question but I've not found posts through search option.
I'm switching from C to assembler and my question is:

there is a way to create static variables into procs ?
or static variables should be considered global variables as defined in .data section ?


thanks.
Post 12 Nov 2008, 10:27
View user's profile Send private message MSN Messenger 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 12 Nov 2008, 11:01
Static (global) variables are best placed in one of your data sections.

Proc local variables are on the stack so they can't be static.
Post 12 Nov 2008, 11:01
View user's profile Send private message Visit poster's website Reply with quote
sleepsleep



Joined: 05 Oct 2006
Posts: 13061
Location: ˛                             ⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣⁣Posts: 0010456
sleepsleep 12 Nov 2008, 20:18
i don't know whether if you has the option to create a new section with readable but no writeable option.

something like.

section '.data2' data2 readable

but nothing is impossible in programming right...
Post 12 Nov 2008, 20:18
View user's profile Send private message Reply with quote
windwakr



Joined: 30 Jun 2004
Posts: 827
windwakr 12 Nov 2008, 21:00
I believe the correct name for a readable only data section is '.rdata'

section '.rdata' data readable

Here is a simple example:
Code:
format PE GUI 4.0
entry start

include 'win32a.inc'

section '.data' data readable writeable
buf rb 256

section '.rdata' data readable
number dd 2
fmt db '%u',0
title db '...',0

section '.code' code readable executable
start:
cinvoke wsprintf,buf,fmt,[number]
invoke MessageBox,NULL,buf,title,MB_OK
invoke ExitProcess,0

section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL'

  include 'api/kernel32.inc'
  include 'api/user32.inc'
    

_________________
----> * <---- My star, won HERE
Post 12 Nov 2008, 21:00
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 19 Nov 2008, 14:10
windwakr wrote:
I believe the correct name for a readable only data section is '.rdata'
I don't think there is any such thing as a "correct name" for sections. Perhaps a better way of describing it would be to say "the commonly used name ...". Sections names are arbitrary and no meaning should be implied when reading them.
Post 19 Nov 2008, 14:10
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4073
Location: vpcmpistri
bitRAKE 19 Nov 2008, 17:01
They can even be blank - OS doesn't use them.
Post 19 Nov 2008, 17:01
View user's profile Send private message Visit poster's website 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.