flat assembler
Message board for the users of flat assembler.

Index > Main > Define symbolic variable on the command line

Author
Thread Post new topic Reply to topic
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 05 Jul 2016, 16:54
I tried to see if fasm reads environment variables, apparently it doesn't. Then I tried to include my variable in my code:

I tried to "fasm" it with the following command: "fasm -d DATE="'2016 01 01'" /tmp/test.asm"

But it returns error: "invalid definition provided."

Is there any way I can insert my variables this way in code?

I was thinking about doing this: "fasm -d DATE="'$(date +'%Y/%m/%d - %H:%M:%S %Z')'" /tmp/test.asm". But it does not work as fasm does not allow spaces (as seen above).

Maybe there is a way I can do this?!

Code:
format ELF executable

entry main

segment readable executable

align 8
main:
         mov            eax,4
         mov            ebx,1
         mov            ecx,str_date
         mov            edx,_str_date
         int            $80
         mov            eax,1
         xor            ebx,ebx
         int            $80
         ret

segment readable

align 8
str_date:                    db DATE,$0A
_str_date = $-str_date

align 8
dq $0000000000000000

segment readable writeable

align 8
data01:                      rb 128
data02:                      dd ?
    
Post 05 Jul 2016, 16:54
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 06 Jul 2016, 01:28
When using the command line the spaces need to be "escaped" with a backslash (\)
Code:
fasm -d DATE='2016\ 01\ 01' ... ;DATE = '2016 01 01' including the quotes    
Post 06 Jul 2016, 01:28
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 06 Jul 2016, 05:25
It did not work.

This works: "fasm -d DATE="'201601'" /tmp/test.asm"
This doesn't: "fasm -d DATE="'2016\ 01'" /tmp/test.asm"

Thank you!
Post 06 Jul 2016, 05:25
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 06 Jul 2016, 05:31
What version of fasm are you using?
Code:
C:\Documents and settings\WeAreTheBorg\Our Documents>type test.asm
format binary
db DATE

C:\Documents and settings\WeAreTheBorg\Our Documents>fasm -d DATE="'2016\ 01'" test.asm
flat assembler  version 1.71.54  (3145344 kilobytes memory)
1 passes, 9 bytes.

C:\Documents and settings\WeAreTheBorg\Our Documents>type test.bin
'2016 01'    
Post 06 Jul 2016, 05:31
View user's profile Send private message Visit poster's website Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 06 Jul 2016, 16:14
I'm using "flat assembler version 1.71.54", Linux version (no libc)

In my command the "" has no effect, because of bash. The actual command fasm receives is:
Code:
fasm -d DATE='2016\ 01' /tmp/test.asm
    
Post 06 Jul 2016, 16:14
View user's profile Send private message Reply with quote
HaHaAnonymous



Joined: 02 Dec 2012
Posts: 1178
Location: Unknown
HaHaAnonymous 06 Jul 2016, 18:40
If anyone is interested, I could make it work with this:
Code:
fasm -d DATE=$(date +'%Y/%m/%d - %H:%M:%S %Z' | hexdump -v -e '/1 "0x%02X,"' | head --bytes -1) /tmp/test.asm
    


It defines the symbol as an array of bytes:
Code:
fasm -d DATE=0x32,0x30,0x31,0x36,0x2F,0x30,0x37,0x2F,0x30,0x36,0x20,0x2D,0x20,0x31,0x35,0x3A,0x33,0x36,0x3A,0x34,0x30,0x20,0x42,0x52,0x54,0x0A /tmp/test.asm
    


Then, if that was not a bug you can consider this as solved.

Thank you!
Post 06 Jul 2016, 18:40
View user's profile Send private message Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2493
Furs 13 Jul 2016, 17:22
Looks like a bug in Fasm to me. Same thing happens on Windows version if you double quote the entire DATE= argument. In effect, Fasm looks for "next" argument on purpose when a space is encountered.

i.e: fasm -d "DATE='2016\ 01\ 01'" fails.

Without the double quotes, the above would actually be the following arguments:

Code:
fasm
-d
DATE='2016\
01\
01'    


Won't work in bash/unux since it's different when treating arguments. Maybe you could use "eval" but probably not.

I use Linux too but Fasm with Wine so still windows syntax. (so I only have one Fasm useable from both Linux and Windows, and VMs, plus I'm more familiar with it and the IDE works fine too)
Post 13 Jul 2016, 17:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20298
Location: In your JS exploiting you and your system
revolution 14 Jul 2016, 00:39
Furs: fasm.exe does not use the quotes as special characters in the definition of the variable. All those single and double quotes are passed directly to the code unaltered. The space is always a delimiter unless it is escaped.

However it appears as though in Linux sh, bash, or whatever is the shell processor, will alter what the user types into the command line and try to be smart by expanding some things. So in Linux you have to comply with the shell requirements before fasm will see the command line.
Post 14 Jul 2016, 00:39
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.