flat assembler
Message board for the users of flat assembler.

Index > Windows > First Usefull Program!

Author
Thread Post new topic Reply to topic
0x004549554F4C



Joined: 16 Mar 2004
Posts: 14
0x004549554F4C 14 Jun 2004, 19:38
Code:
;This program loads name lists from text files and kills duplicates
;Than saves the duplicate killed list
; LISTBOX KILL DUPES
; FASM SOURCE
; If you want to compile this source code get...
; FlatASM for free at http://flatassembler.net/

format PE GUI 4.0
entry start

include 'C:\Documents and Settings\siu\Desktop\zLouie\ASM1\INCLUDE\win32a.inc'

IDM_ADD = 101  ;Menu Constant
IDM_DK = 102   ;Menu const for the save list


section '.data' data readable writeable
  hprocess dd ?
  ThrID dd ?
  ThrIDs dd ?
  lbcnt dd ?
  scnt dd ?
  dcnt dd ?
  _crlf db 0x0d, 0x0a
  linebuff rb 000000FFh     ;256byte buffer for each line
  txtbuff rb 000fffffh        ;1000k-ish overyly huge reserved byte buffer for the file text
  bwritten   dd ?
  _SaveName db 'nlist.txt',0
  _FileName db 'list.txt',0
  _title db 'LBKILLDUPES r22',0
  _class db 'LBKILLDUPESr22',0
  _edit db 'ListBox',0
  bread dd ?
  hfile dd ?
  hfiles dd ?
  hwnd dd ?
  hinstance dd ?
  edithwnd dd ?
  editfont dd ?
  msg MSG
  wc WNDCLASS
  client RECT


section '.code' code readable executable

  start:

      invoke  GetModuleHandle,0
   mov     [hinstance],eax
     invoke  LoadIcon,0,17
       mov     [wc.hIcon],eax
      invoke  LoadCursor,0,IDC_ARROW
      mov     [wc.hCursor],eax
    mov     [wc.style],0
        mov     [wc.lpfnWndProc],WindowProc
 mov     [wc.cbClsExtra],0
   mov     [wc.cbWndExtra],0
   mov     eax,[hinstance]
     mov     [wc.hInstance],eax
  mov     [wc.hbrBackground],COLOR_WINDOW+1
   mov     [wc.lpszMenuName],0
 mov     [wc.lpszClassName],_class
   invoke  RegisterClass,wc
    invoke  LoadMenu,[hinstance],37
     invoke  CreateWindowEx,0,_class,_title,WS_VISIBLE+WS_DLGFRAME+WS_SYSMENU,0,0,300,300,0,eax,[hinstance],0
    mov     [hwnd],eax
  invoke  GetCurrentProcess
   mov     [hprocess], eax

  msg_loop:
      invoke  GetMessage,msg,0,0,0
        or      eax,eax
     jz      end_loop
    invoke  TranslateMessage,msg
        invoke  DispatchMessage,msg
 jmp     msg_loop

  end_loop:
     invoke  ExitProcess,[msg.wParam]

proc WindowProc, hwnd,wmsg,wparam,lparam
    push    ebx esi edi
 cmp     [wmsg],WM_CREATE
    je      wmcreate
    cmp     [wmsg],WM_COMMAND
   je      wmcommand
   cmp     [wmsg],WM_DESTROY
   je      wmdestroy
  defwndproc:
      invoke  DefWindowProc,[hwnd],[wmsg],[wparam],[lparam]
       jmp     finish
  wmcreate:
   invoke  GetClientRect,[hwnd],client
 invoke  CreateWindowEx,WS_EX_CLIENTEDGE,_edit,0,LBS_HASSTRINGS+LBS_NOTIFY+WS_VISIBLE+WS_CHILD+WS_VSCROLL,[client.left],[client.top],[client.right],[client.bottom],[hwnd],0,[hinstance],0
   or      eax,eax
     jz      failed
      mov     [edithwnd],eax
      invoke  CreateFont,16,0,0,0,0,FALSE,FALSE,FALSE,ANSI_CHARSET,OUT_RASTER_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FIXED_PITCH+FF_DONTCARE,0
        or      eax,eax
     jz      failed
      mov     [editfont],eax
      invoke  SendMessage,[edithwnd],WM_SETFONT,eax,FALSE
 xor     eax,eax
     jmp     finish
      failed:
 or      eax,-1
      jmp     finish
  wmcommand:
  mov     eax,[wparam]
        and     eax,0FFFFh
  cmp     eax,IDM_ADD
 je      AddFile
     cmp     eax,IDM_DK
  je      SaveKillDupes
       jmp     defwndproc

       AddFile:
       invoke  CreateThread,0,0,RADDER,0,0,ThrID
   invoke  CloseHandle,[ThrID]
 jmp     finish

       SaveKillDupes:
     invoke  CreateThread,0,0,RSAVER,0,0,ThrIDs
  invoke  CloseHandle,[ThrIDs]
        jmp     finish
  wmdestroy:
  invoke  DeleteObject,[editfont]
     invoke  PostQuitMessage,0
   xor     eax,eax
  finish:
    pop     edi esi ebx
 return
endp

proc RADDER
   push    esp
 invoke  SetPriorityClass,[hprocess],HIGH_PRIORITY_CLASS
     invoke  SetThreadPriority,[ThrID],THREAD_PRIORITY_TIME_CRITICAL
     invoke  CreateFile, _FileName, GENERIC_READ, FILE_SHARE_WRITE, 0, OPEN_ALWAYS, 0, 0
 mov     [hfile], eax
       morefile:
        invoke  ReadFile, [hfile], txtbuff, 000FFFFFh, bread, 0
     cmp     eax, -1
     je      failedsend
  cmp     [bread], 0
  je      failedsend




  mov     [scnt], 00000000h
   mov     [dcnt], 00000000h
   lea     esi, [txtbuff]
      dec     [scnt]
      dec     [dcnt]
       keepadding:
    inc     [dcnt]
       fixerror:
      inc     [scnt]
      mov     ecx, [scnt]
 mov     edx, [dcnt]
 mov     byte[linebuff+edx], 00h
     cmp     byte[esi+ecx], 0
    je      endadd
      cmp     byte[esi+ecx], 0dh
  je      skipstore
   mov     al, byte[esi+ecx]
   cmp     al, 0ah
     je      fixerror
    mov     byte[linebuff+edx], al
      jmp     keepadding
       skipstore:
 cmp     byte[linebuff+1], 0ah
       je      nextline
    cmp     byte[linebuff+1], 0dh
       je      nextline
    cmp     byte[linebuff+1], 00h
       je      nextline
    invoke  SendMessage, [edithwnd], LB_FINDSTRINGEXACT, 0, linebuff
    cmp     eax, LB_ERR
 jne      noadd
      invoke  SendMessage, [edithwnd], LB_ADDSTRING, 0, linebuff
  noadd:
       nextline:
  mov     [dcnt], 00000000h
   dec     [dcnt]
      inc     [scnt]
      jmp    keepadding
       endadd:

 invoke  UpdateWindow,[hwnd]
 mov     [scnt], 000FFFFFh
       cleanbuff:
  mov     ecx, [scnt]
 mov     byte[txtbuff+ecx], 00h
      dec     [scnt]
      cmp     [scnt], 0
   je      buffclear
   jmp     cleanbuff
       buffclear:
  jmp     morefile
    invoke  CloseHandle, [hfile]
        jmp     finish
       failedsend:
    invoke  CloseHandle, [hfile]
        invoke  SetPriorityClass,[hprocess],NORMAL_PRIORITY_CLASS
   pop     esp
 return
endp

proc RSAVER
   push esp
    invoke  SetThreadPriority,[ThrIDs],THREAD_PRIORITY_TIME_CRITICAL
    mov     [lbcnt], 00000000h
  invoke  CreateFile, _SaveName, GENERIC_WRITE, FILE_SHARE_WRITE, 0, CREATE_NEW, 0, 0
 mov     [hfiles], eax
      keepsaving:
      mov     ecx, 000000FFh
       lplnbuff:
      mov     byte[linebuff+ecx],00h
      dec     ecx
 cmp     ecx,0
       jne     lplnbuff
    invoke  SendMessage, [edithwnd], LB_GETTEXT, [lbcnt], linebuff
      cmp     eax, LB_ERR
 je      endsavedk
   mov     eax, 00000000h
      dec     eax
      looplen:
   inc     eax
 cmp     word[linebuff+eax], 0000h
   je      endlen
      jmp     looplen
      endlen:
        cmp     byte[linebuff+1], 0ah
       je      nextindex
   cmp     byte[linebuff+1], 0dh
       je      nextindex
   cmp     byte[linebuff+1], 00h
       je      nextindex

       invoke  WriteFile, [hfiles], linebuff, eax, bwritten, 0
     invoke  WriteFile, [hfiles], _crlf, 2, bwritten, 0
       nextindex:
 inc     [lbcnt]
     invoke  UpdateWindow,[hwnd]
 jmp     keepsaving
       endsavedk:
 invoke  CloseHandle, [hfiles]

   pop esp
     return
endp

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL',\
   user,'USER32.DLL',\
      gdi,'GDI32.DLL'

  import kernel,\
        GetModuleHandle,'GetModuleHandleA',\
     CreateFile, 'CreateFileA',\
      GetCurrentProcess,'GetCurrentProcess',\
  SetPriorityClass,'SetPriorityClass',\
    SetThreadPriority,'SetThreadPriority',\
  ReadFile, 'ReadFile',\
   WriteFile, 'WriteFile',\
         CreateThread,'CreateThread',\
    CloseHandle, 'CloseHandle',\
     ExitProcess,'ExitProcess'

  import user,\
         FindWindow,'FindWindowA',\
       FindWindowEx,'FindWindowExA',\
   RegisterClass,'RegisterClassA',\
         CreateWindowEx,'CreateWindowExA',\
       DefWindowProc,'DefWindowProcA',\
         SetWindowLong,'SetWindowLongA',\
         RedrawWindow,'RedrawWindow',\
    GetMessage,'GetMessageA',\
       TranslateMessage,'TranslateMessage',\
    DispatchMessage,'DispatchMessageA',\
     SendMessage,'SendMessageA',\
     LoadCursor,'LoadCursorA',\
       LoadIcon,'LoadIconA',\
   LoadMenu,'LoadMenuA',\
   GetClientRect,'GetClientRect',\
  MoveWindow,'MoveWindow',\
        SetFocus,'SetFocus',\
    MessageBox,'MessageBoxA',\
       UpdateWindow,'UpdateWindow',\
    PostQuitMessage,'PostQuitMessage'

  import gdi,\
  CreateFont,'CreateFontA',\
       DeleteObject,'DeleteObject'

section '.rsrc' resource data readable

  ; resource directory

  directory RT_MENU,menus,\
        RT_ICON,icons,\
            RT_GROUP_ICON,group_icons,\
        RT_VERSION,versions

  ; resource subdirectories

  resource menus,\
          37,LANG_ENGLISH+SUBLANG_DEFAULT,main_menu

  resource icons,\
        1,LANG_NEUTRAL,icon_data

  resource group_icons,\
           17,LANG_NEUTRAL,main_icon

  resource versions,\
     1,LANG_NEUTRAL,version_info

  menu main_menu
       menuitem '&File',0,MFR_POPUP+MFR_END
       menuitem '&SaveList nlist.txt',IDM_DK,0
       menuitem '&AddFile list.txt',IDM_ADD,MFR_END

  icon main_icon,icon_data,'minipad.ico'

  version version_info,VOS__WINDOWS32,VFT_APP,VFT2_UNKNOWN,LANG_ENGLISH+SUBLANG_DEFAULT,0,\
        'FileDescription','List Dupe Killer',\
         'LegalCopyright','No rights reserved.',\
       'FileVersion','1.0',\
          'ProductVersion','1.0',\
       'OriginalFilename','r22asmdupekiller.exe'    
Post 14 Jun 2004, 19:38
View user's profile Send private message Reply with quote
Vortex



Joined: 17 Jun 2003
Posts: 318
Vortex 15 Jun 2004, 10:03
Your code imports a lot of unused API functions. The list below contains the functions required for your source code:
Code:
section '.idata' import data readable writeable

  library kernel32,'kernel32.dll',\
          user32,'user32.dll',\
          gdi32,'gdi32.dll'

  import kernel32,\
         CloseHandle,'CloseHandle',\
         CreateFile,'CreateFileA',\
         CreateThread,'CreateThread',\
         ExitProcess,'ExitProcess',\
         GetCurrentProcess,'GetCurrentProcess',\
         GetModuleHandle,'GetModuleHandleA',\
         ReadFile,'ReadFile',\
         SetPriorityClass,'SetPriorityClass',\
         SetThreadPriority,'SetThreadPriority',\
         WriteFile,'WriteFile'

  import user32,\
         CreateWindowEx,'CreateWindowExA',\
         DefWindowProc,'DefWindowProcA',\
         DispatchMessage,'DispatchMessageA',\
         GetClientRect,'GetClientRect',\
         GetMessage,'GetMessageA',\
         LoadCursor,'LoadCursorA',\
         LoadIcon,'LoadIconA',\
         LoadMenu,'LoadMenuA',\
         PostQuitMessage,'PostQuitMessage',\
         RegisterClass,'RegisterClassA',\
         SendMessage,'SendMessageA',\
         TranslateMessage,'TranslateMessage',\
         UpdateWindow,'UpdateWindow'

  import gdi32,\
         CreateFont,'CreateFontA',\
         DeleteObject,'DeleteObject'
    

_________________
Code it... That's all...
Post 15 Jun 2004, 10:03
View user's profile Send private message Visit poster's website Reply with quote
pelaillo
Missing in inaction


Joined: 19 Jun 2003
Posts: 878
Location: Colombia
pelaillo 15 Jun 2004, 12:59
0x004549554F4C wrote:
Code:
include 'C:\Documents and Settings\siu\Desktop\zLouie\ASM1\INCLUDE\win32a.inc'
    


Please use relative paths whenever possible,
to ease re-compilation of your sources by all people.
Hardcoded paths will cause trouble when your source
becomes larger and/or modular.

Code:
 '%fasminc/win32a.inc'    
Post 15 Jun 2004, 12:59
View user's profile Send private message Yahoo Messenger 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.