flat assembler
Message board for the users of flat assembler.

Index > Linux > [SOLVED] Question: Getting environment variables

Author
Thread Post new topic Reply to topic
n0tmuch



Joined: 10 Oct 2025
Posts: 2
n0tmuch 10 Oct 2025, 19:38
Hello! This may sound a bit dumb as the solution is probably simple, but how do I get the environment variables for my program? The flat assembler.'s examples doesn't include this right now. Sad
Arch is x86_64.


Last edited by n0tmuch on 10 Oct 2025, 20:32; edited 1 time in total
Post 10 Oct 2025, 19:38
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8461
Location: Kraków, Poland
Tomasz Grysztar 10 Oct 2025, 20:09
You can find an example in fasmg source:
Code:
  start:
        mov     rcx,[rsp]
        mov     [argc],rcx
        lea     rbx,[rsp+8]
        mov     [argv],rbx
        lea     rsi,[rsp+8+rcx*8+8]
        mov     [env],rsi    
This pointer is then used by get_environment_variable function in system.inc.
Post 10 Oct 2025, 20:09
View user's profile Send private message Visit poster's website Reply with quote
n0tmuch



Joined: 10 Oct 2025
Posts: 2
n0tmuch 10 Oct 2025, 20:31
That explains it! The simplified code for anyone else finding this:
Code:
mov rbp, [rsp]
lea rbx, [rsp+8+rbp*8+8]
mov [env], rbx    

Idea This could be used for execve and similar, by moving [env] into rdx.
Post 10 Oct 2025, 20:31
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.