flat assembler
Message board for the users of flat assembler.

Index > Windows > How to transfer functions two variables in one parameter?

Author
Thread Post new topic Reply to topic
Vladislaw



Joined: 21 Apr 2011
Posts: 3
Vladislaw
This code doesn't work correctly if to deduce a name of the computer and the user name separately - all works.
The help is very necessary.

Code:
         format  pe gui 4.0
         entry   EntryProc
         include 'C:\FASM\include\win32a.inc'

section '.code' code readable writeable executable
  lpUN   db 127 dup (?)
  lpCN  db 127 dup (?)
  nSize      dd 127
  nSize1     dd 127
  lpText     dd lpUN,lpCN

proc EntryProc
         invoke GetUserName,lpUN,nSize
         invoke GetComputerName,lpCN,nSize1
         invoke MessageBox,NULL,lpText,lpText, MB_OK
         invoke  ExitProcess,0
endp

         data    import
         library kernel32,'kernel32.dll',\
                 advapi32,'ADVAPI32.DLL',\
                 user32,'user32.dll'

         include 'C:\FASM\include\api\kernel32.inc'
         include 'C:\FASM\include\api\advapi32.inc'
         include 'C:\FASM\include\api\user32.inc'
         end     data    


Description: Compiled program.
Download
Filename: UN_and_CN.rar
Filesize: 458 Bytes
Downloaded: 46 Time(s)

Post 21 Apr 2011, 18:56
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Vladislaw wrote:
This code doesn't work correctly if to deduce a name of the computer and the user name separately - all works.
The help is very necessary.


Actually it work for me. You simply failed to display the results properly.
Use one of the following lines (they both do the same):
Code:
         invoke MessageBox,NULL,[lpText],[lpText+4], MB_OK
         invoke MessageBox,NULL,lpUN,lpCN, MB_OK
    
Post 21 Apr 2011, 19:18
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Vladislaw



Joined: 21 Apr 2011
Posts: 3
Vladislaw
I need MessageBox with title and the message for example "UserComputer", if lpUN = "User" lpCN = "Computer".

"[lpText+4]" -- why 4?
Post 21 Apr 2011, 19:25
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Ah, I think I got it. Try this one:
(I renamed the variables, only to make them more readable)
Code:
  buffer rb 256
  size     dd ?

proc EntryProc
         mov    [size], 256
         invoke GetUserName, buffer, size
         mov    eax, [size]
         add    eax, buffer
         mov    byte [eax-1], '@'
         mov    ecx, 100
         sub    ecx, [size]
         mov    [size], ecx
         invoke GetComputerName, eax, size

         invoke MessageBox,NULL,buffer,buffer, MB_OK
         invoke  ExitProcess,0
endp
    
Post 21 Apr 2011, 19:45
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Here is a new one

Code:
    format  pe gui 4.0
    entry   EntryProc
    include 'win32ax.inc'


section '.code' code readable writeable executable
  lpUN   rb 512
  lpCN   rb 256

proc EntryProc
         invoke GetEnvironmentVariable,'computername',lpCN,256
         invoke GetEnvironmentVariable,'username',lpUN,256
         mov    byte [lpUN+eax],'@'
         xor    ecx,ecx
@@:
         cmp    ecx,eax
         jae    @f
         mov    byte dl,[lpCN+ecx]
         mov    byte [lpUN+eax+ecx+1],dl
         inc    ecx
         jmp    @b
@@:
         invoke MessageBox,NULL,lpUN,lpCN, MB_OK
         invoke ExitProcess,0
endp

         data    import
         library kernel32,'kernel32.dll',\
                 advapi32,'ADVAPI32.DLL',\
                 user32,'user32.dll'

         include 'api\kernel32.inc'
         include 'api\advapi32.inc'
         include 'api\user32.inc'
         end     data  
    
Post 21 Apr 2011, 20:44
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
It is not exactly the same. I tried with success to change the environment variable %computername%, but GetComputerName still returns the proper name of the computer.
Post 21 Apr 2011, 21:06
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
JohnFound wrote:
It is not exactly the same.


Yes, Rolling Eyes
But always will work for Windows
Post 21 Apr 2011, 21:09
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
typedef wrote:
Yes, Rolling Eyes
But always will work for Windows


What do you mean? I tested it under WinXP.
Compile the source.
Start the console and type: "set computername=something"
Then run the program from the console - it will show "something" as a computer name. On the other hand GetComputerName works properly.
Post 21 Apr 2011, 21:20
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Vladislaw



Joined: 21 Apr 2011
Posts: 3
Vladislaw
Thanks, works, but now need to understand how)
Post 21 Apr 2011, 22:24
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Vladislaw wrote:
Thanks, works, but now need to understand how)


It is not so hard. In my example - the first function is invoked with address of the buffer "buffer". Then the ending NULL is replaced by "@" and the new address is computed to begin just after the "@", so the string returned by the second function is concatenated to the first string.

In the typedefs example, there is another approach. He just copies the second string byte by byte at the end of the first. (although, it is not so stylish Razz)

Regards
Post 21 Apr 2011, 22:35
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
JohnFound wrote:
(although, it is not so stylish Razz)

Regards


Explaining to a beginner ?


He has to know different ways of doing it. Razz Very Happy


GetEnviromentVariable just expands a local variable and returns its value.

That is what is does.

You look surprised with the results after you typed set computername=something and then you got "something" as computer name.

Right, it is like that because you changed the GetEnvironmentVariable...
Post 21 Apr 2011, 22:57
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.