The MASM Forum Archive 2004 to 2012
Welcome, Guest. Please login or register.
March 23, 2023, 07:58:37 AM

Login with username, password and session length
Search:     Advanced search
128553 Posts in 15254 Topics by 684 Members
Latest Member: mottt
* Home Help Search Login Register
+  The MASM Forum Archive 2004 to 2012
|-+  General Forums
| |-+  The Campus
| | |-+  3 string into 1 variable
« previous next »
Pages: [1] Print
Author Topic: 3 string into 1 variable  (Read 6019 times)
akna
Guest


Email
3 string into 1 variable
« 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
Logged
dedndave
Member
*****
Posts: 12523


Re: 3 string into 1 variable
« Reply #1 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
Logged
dedndave
Member
*****
Posts: 12523


Re: 3 string into 1 variable
« Reply #2 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)
Logged
akna
Guest


Email
Re: 3 string into 1 variable
« Reply #3 on: June 13, 2009, 03:12:11 PM »

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


Email
Re: 3 string into 1 variable
« Reply #4 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:
Code:
.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...
Logged
dedndave
Member
*****
Posts: 12523


Re: 3 string into 1 variable
« Reply #5 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
.
.
.
Logged
akna
Guest


Email
Re: 3 string into 1 variable
« Reply #6 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!
Logged
dedndave
Member
*****
Posts: 12523


Re: 3 string into 1 variable
« Reply #7 on: June 13, 2009, 03:32:41 PM »

my pleasure.....
$50 please
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP The MASM Forum Archive 2004 to 2012 | Powered by SMF 1.0.12.
© 2001-2005, Lewis Media. All Rights Reserved.
Valid XHTML 1.0! Valid CSS!