News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

3 string into 1 variable

Started by akna, June 13, 2009, 02:53:17 PM

Previous topic - Next topic

akna

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

dedndave

addr dir and user_name and file

make one variable with the complete path/file

AND is a logical operator

dedndave

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)

akna

thx, but how I know the 3 string to bind?

ramguru

'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...

dedndave

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
.
.
.

akna

.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!

dedndave