flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Is it possible to detect label type (code or data)?

Author
Thread Post new topic Reply to topic
seapoint



Joined: 25 May 2013
Posts: 8
seapoint
Code:
macro check l* {
if l is label pointing to code
something
else if l is label pointing to data
something2
end if
}

codelabel:
stillacodelabel:
mov eax, eax ;instruction

datalabel:
db 0 ;everything that is not a instruction, d*, r*, ...
    

So: a label is a code-label if it points to x86/amd64 instruction (generated by other macros possibly), it's a data-label otherwise.

My guess is, it's not possible, so I'm going to write a limited version in python, but with fasm macros you really never know Smile
Post 31 May 2013, 08:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17473
Location: In your JS exploiting you and your system
revolution
When you use a colon (:) to define the label there is no type attached to the label. So in your example there is no way to know just from the label name whether the following lines are data or instructions.

If you use a data definition to define a label then it might be possible, although I haven't thought about how yet:
Code:
datalabel db 0 ;define datalabel without using a colon and the type "byte" is now part of the label    
Post 31 May 2013, 09:21
View user's profile Send private message Visit poster's website Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 619
cod3b453
You can override the dx's with struc's to define an internal marker:
Code:
struc db [x]
{
 common
        .__isdata = 1
 forward
       db x
}

macro isData id
{
        if defined id#.__isdata
                display 'DATA',0x0D,0x0A
        else
                display 'CODE?',0x0D,0x0A
        end if
}

test0:
xor eax,eax

test1 db 'blah',0,'blah'
test2:
db 'blah',0,'blah'

isData test0
isData test1
isData test2

                      
Another option is to tag memory ranges and compare the address but this only works if data and code are separate. The fundamental problem is code is data Laughing
Post 31 May 2013, 16:13
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.