The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: akna on June 13, 2009, 02:53:17 PM

Title: 3 string into 1 variable
Post by: akna on June 13, 2009, 02:53:17 PM
Hi!

My code does not work.
What's wrong?


.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include \masm32\include\advapi32.inc
includelib \masm32\lib\advapi32.lib

.data

dir db "c:\Documents and Settings\",0
file db "\log.txt",0
.data?

user_name db 64 DUP(?)
b_size dd ?

.code
start:
invoke GetUserName,addr user_name,addr b_size
invoke CreateFile,addr dir and user_name and file,GENERIC_READ,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
invoke ExitProcess,0
end start
Title: Re: 3 string into 1 variable
Post by: dedndave on June 13, 2009, 02:57:25 PM
addr dir and user_name and file

make one variable with the complete path/file

AND is a logical operator
Title: Re: 3 string into 1 variable
Post by: dedndave on June 13, 2009, 02:59:38 PM
also, instead of....

.386
.model flat,stdcall
option casemap:none
include \masm32\include\windows.inc
include \masm32\include\kernel32.inc
includelib \masm32\lib\kernel32.lib
include \masm32\include\user32.inc
includelib \masm32\lib\user32.lib
include \masm32\include\advapi32.inc
includelib \masm32\lib\advapi32.lib

just use

        include \masm32\include\masm32rt.inc

it takes care of all that stuff (including .486, model, case)
Title: Re: 3 string into 1 variable
Post by: akna on June 13, 2009, 03:12:11 PM
thx, but how I know the 3 string to bind?
Title: Re: 3 string into 1 variable
Post by: ramguru on June 13, 2009, 03:20:58 PM
'and' doesn't work with strings, it's only for bits
you want to:
1) copy DIRECTORY_name to a big enough char buffer
2) append FILE_name to that buffer
like:

.data?
    recv_buf db 64 dup (?)
..
invoke lstrcpy, ADDR recv_buf, ADDR dir
invoke lstrcat, ADDR recv_buf, ADDR file
invoke CreateFile,addr recv_buf...
Title: Re: 3 string into 1 variable
Post by: dedndave on June 13, 2009, 03:23:41 PM
lol
well - you need to take the pieces and make one string
there are string concatonation macros in the masm32 files, but i would probably make my own little routine
try to avoid using names like "dir" and "file" - bad habit

        .DATA

PathStr  db "c:\Documents and Settings\"
PathCat  db 80 dup(0)
;end of Path structure

FileNam  db "\log.txt",0

        .DATA?

user_name db 64 DUP(?)
b_size dd ?

        .CODE

.
.
.
        cld
        mov     esi,offset user_name
        mov     edi,offset PathCat

loop01: lodsb
        or      al,al
        jz      AddFil

        stosb
        jmp     loop01

AddFil: mov     esi,offset FileNam

loop02: lodsb
        or      al,al
        jz      PnDone

        stosb
        jmp     loop02

PnDone: stosb
.
.
.
Title: Re: 3 string into 1 variable
Post by: akna on June 13, 2009, 03:29:20 PM
.data?
    recv_buf db 64 dup (?)
..
invoke lstrcpy, ADDR recv_buf, ADDR dir
invoke lstrcat, ADDR recv_buf, ADDR file
invoke CreateFile,addr recv_buf...

Thanx man, it's work!
Title: Re: 3 string into 1 variable
Post by: dedndave on June 13, 2009, 03:32:41 PM
my pleasure.....
$50 please