flat assembler
Message board for the users of flat assembler.

Index > DOS > Environment variable not visible

Author
Thread Post new topic Reply to topic
CandyMan



Joined: 04 Sep 2009
Posts: 412
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 09 Jan 2023, 22:22
assemble.bat file looks like:
Code:
set include=inc
fasm test.asm    

When I run the console version of fasm in dos using the HX dos extender the environment variables are invisible.

_________________
smaller is better
Post 09 Jan 2023, 22:22
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 917
Location: Russia
macomics 09 Jan 2023, 22:33
A semicolon is needed at the end. Without it, the latter value does not see
Code:
set include=inc;
fasm test.bat    
Post 09 Jan 2023, 22:33
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8346
Location: Kraków, Poland
Tomasz Grysztar 09 Jan 2023, 23:12
You can test the GetEnvironmentVariableA results with a small program like this:
Code:
format PE console
entry start

section '.text' code readable executable

start:

        push    0FFFFFFF5h ; STD_OUTPUT_HANDLE
        call    [GetStdHandle]
        mov     ebx,eax

        call    [GetCommandLineA]
        mov     esi,eax
      @@:
        lodsb
        test    al,al
        jz      fail
        cmp     al,20h
        jne     @b
      @@:
        lodsb
        cmp     al,20h
        je      @b
        dec     esi

        push    1000h
        push    buffer
        push    esi
        call    [GetEnvironmentVariableA]
        push    0
        push    tmp
        push    eax
        push    buffer
        push    ebx
        call    [WriteFile]

fail:
        push    0
        call    [ExitProcess]


display_string:
        ret

section '.data' data readable writeable

  buffer rb 1000h
  tmp dd ?

section '.idata' import data readable writeable

  dd 0,0,0,RVA kernel_name,RVA kernel_table
  dd 0,0,0,0,0

  kernel_table:
    ExitProcess dd RVA _ExitProcess
    GetCommandLineA dd RVA _GetCommandLineA
    GetEnvironmentVariableA dd RVA _GetEnvironmentVariableA
    GetStdHandle dd RVA _GetStdHandle
    WriteFile dd RVA _WriteFile
    dd 0

  kernel_name db 'KERNEL32.DLL',0

  _ExitProcess dw 0
    db 'ExitProcess',0
  _GetCommandLineA dw 0
    db 'GetCommandLineA',0
  _GetEnvironmentVariableA dw 0
    db 'GetEnvironmentVariableA',0
  _GetStdHandle dw 0
    db 'GetStdHandle',0
  _WriteFile dw 0
    db 'WriteFile',0

section '.reloc' fixups data readable discardable       ; needed for Win32s    
It seems that HX implementation is case-sensitive, while DOS converts names to upper case:
Code:
C:\ASM\HXRT217\BIN>set include=C:\INCLUDE
C:\ASM\HXRT217\BIN>getenv include
C:\ASM\HXRT217\BIN>getenv INCLUDE
C:\INCLUDE    
Post 09 Jan 2023, 23:12
View user's profile Send private message Visit poster's website Reply with quote
CandyMan



Joined: 04 Sep 2009
Posts: 412
Location: film "CandyMan" directed through Bernard Rose OR Candy Shop
CandyMan 11 Jan 2023, 15:29
Now I will know to use capital letters.

Thanks Tomasz! I can always count on you to solve any problem.

_________________
smaller is better
Post 11 Jan 2023, 15:29
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.