flat assembler
Message board for the users of flat assembler.
Index
> Windows > How to transfer functions two variables in one parameter? |
Author |
|
Vladislaw 21 Apr 2011, 18:56
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
|
|||||||||||
21 Apr 2011, 18:56 |
|
Vladislaw 21 Apr 2011, 19:25
I need MessageBox with title and the message for example "UserComputer", if lpUN = "User" lpCN = "Computer".
"[lpText+4]" -- why 4? |
|||
21 Apr 2011, 19:25 |
|
JohnFound 21 Apr 2011, 19:45
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 |
|||
21 Apr 2011, 19:45 |
|
typedef 21 Apr 2011, 20:44
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 |
|||
21 Apr 2011, 20:44 |
|
JohnFound 21 Apr 2011, 21:06
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.
|
|||
21 Apr 2011, 21:06 |
|
typedef 21 Apr 2011, 21:09
JohnFound wrote: It is not exactly the same. Yes, But always will work for Windows |
|||
21 Apr 2011, 21:09 |
|
JohnFound 21 Apr 2011, 21:20
typedef wrote: Yes, 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. |
|||
21 Apr 2011, 21:20 |
|
Vladislaw 21 Apr 2011, 22:24
Thanks, works, but now need to understand how)
|
|||
21 Apr 2011, 22:24 |
|
JohnFound 21 Apr 2011, 22:35
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 ) Regards |
|||
21 Apr 2011, 22:35 |
|
typedef 21 Apr 2011, 22:57
JohnFound wrote: (although, it is not so stylish ) Explaining to a beginner ? He has to know different ways of doing it. 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... |
|||
21 Apr 2011, 22:57 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.