flat assembler
Message board for the users of flat assembler.

Index > Windows > Concenating Strings

Author
Thread Post new topic Reply to topic
calpol2004



Joined: 16 Dec 2004
Posts: 110
calpol2004 03 Jan 2006, 12:59
ive made a little messenger program for school it sends messages using the net.exe program (all it does is parse the information entered then lets net.exe do the dirty work Very Happy ) it was originally made in C, and a few days ago i thought to optimize it (i got bored) i thought id rewrite it in ASM, ive done a little .com applications before (im a asm newbie) so i got the dialog application included in the examples which i got with fasm edited it and got a skeleton for my application and played around with it. and now ive got this:

Code:
format PE GUI 4.0
entry start

include '..\..\include\win32a.inc'

ID_USERNAME = 100
ID_MESSAGE  = 101
ID_SEND     = 102
ID_CLEAR    = 103

section '.data' data readable writeable

   flags       dd ?
   open        db "open",0
   net         db "net",0
   path        db "send ",0
   sender      rb 21
   username    rb 21
   message     rb 450
   length      db 1

section '.code' code readable executable

  start:
        invoke  GetModuleHandle,0
        invoke  DialogBoxParam,eax,37,HWND_DESKTOP,DialogProc,0
        or      eax,eax
        jz      exit
  exit:
        invoke  ExitProcess,0

proc DialogProc hwnddlg,msg,wparam,lparam
        push    ebx esi edi
        cmp     [msg],WM_INITDIALOG
        je      wminitdialog
        cmp     [msg],WM_COMMAND
        je      wmcommand
        cmp     [msg],WM_CLOSE
        je      wmclose
        xor     eax,eax
        jmp     finish
  wminitdialog:
        invoke  SetWindowPos,[hwnddlg],HWND_TOPMOST,0,0,0,0,SWP_NOMOVE+SWP_NOSIZE
        jmp     processed
  wmcommand:
        mov     eax,[wparam]
        and     eax,0FFFFh
        cmp     eax,ID_SEND
        je      send
        cmp     eax,ID_CLEAR
        je      clear
        jmp     processed
        send:
                invoke GetUserName,sender,length+20
                invoke GetDlgItemText,[hwnddlg],ID_USERNAME,username,length+20
                invoke GetDlgItemText,[hwnddlg],ID_MESSAGE,message,length+449

                ;last few lines of code here i need function to concenate strings.

                invoke ShellExecute,[hwnddlg],open,net,path,0,SW_HIDE
                jmp     processed
        clear:
                invoke SetDlgItemText,[hwnddlg],ID_USERNAME,""
                invoke SetDlgItemText,[hwnddlg],ID_MESSAGE,""
        jmp     processed
  wmclose:
        invoke  EndDialog,[hwnddlg],0
  processed:
        mov     eax,1
  finish:
        pop     edi esi ebx
        ret
endp

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',user,'USER32.DLL',shell,'SHELL32.DLL',advapi,'ADVAPI32.DLL'
  import kernel,GetModuleHandle,'GetModuleHandleA',ExitProcess,'ExitProcess'
  import user,DialogBoxParam,'DialogBoxParamA',GetDlgItemText,'GetDlgItemTextA',\
  SetDlgItemText,'SetDlgItemTextA',MessageBox,'MessageBoxA',EndDialog,'EndDialog',\
  SetWindowPos,'SetWindowPos'
  import shell,ShellExecute,'ShellExecuteA'
  import advapi,GetUserName,'GetUserNameA'

section '.rsrc' resource data readable
  directory RT_DIALOG,dialogs
  resource dialogs,37,LANG_ENGLISH+SUBLANG_DEFAULT,messager
  dialog messager,'Messager',340,280,180,55,DS_MODALFRAME+DS_CENTER+WS_POPUP+WS_CAPTION+WS_SYSMENU+WS_MINIMIZEBOX
  dialogitem 'EDIT','Insert Username Here',ID_USERNAME,2,5,121,15,WS_VISIBLE+WS_BORDER+WS_TABSTOP
  dialogitem 'EDIT','Insert Message Here',ID_MESSAGE,2,25,121,15,WS_VISIBLE+WS_BORDER+WS_TABSTOP+ES_AUTOHSCROLL
  dialogitem 'BUTTON','Send',ID_SEND,125,5,50,15,WS_VISIBLE+WS_TABSTOP+BS_DEFPUSHBUTTON
  dialogitem 'BUTTON','Clear',ID_CLEAR,125,25,50,15,WS_VISIBLE+WS_TABSTOP+BS_PUSHBUTTON
  dialogitem 'STATIC','Created By Callum Lamb',-1,54,46,100,9,WS_VISIBLE
enddialog
    


ive just got to do a few more lines which are relatively simple i just need to concenate the label username to the end of the label path, then concenate a space then the variable sender then a colon then the label message. which in C would be a series of StrCat() functions however because im very new to asm i rly dont want to have to make my own macro to concenate strings and i cant find a function on msdn which i can import to concenate strings can anyone help?

also if anyone could see any faults with my code and point them out to me that would be very helpful.
Post 03 Jan 2006, 12:59
View user's profile Send private message MSN Messenger Reply with quote
Cthulhu



Joined: 12 May 2005
Posts: 29
Cthulhu 03 Jan 2006, 18:44
Check _snprintf in msvcrt.dll
http://msdn2.microsoft.com/2ts7cx93.aspx
Post 03 Jan 2006, 18:44
View user's profile Send private message Reply with quote
SDragon



Joined: 13 Sep 2005
Posts: 19
Location: Siberia
SDragon 04 Jan 2006, 11:54
Look for lstrcat in MSDN. But GetUserName and GetDlgItemText return the number of characters copied, so it's very easy to concatenate them without strcat(). Just add the returned length to the pointer: you will get the pointer to the end of the string. Then copy the next string to this location.
Post 04 Jan 2006, 11:54
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.