#include #recurse.asm to read the file structure recursively and fill a tree. Depending #on your cpu speed ,this could take some time (even upto 35s on #my Pentium MMX 200) as it follows each subdirectory #down to the last child #Please drop me an email for any clarifications,suggestions,comments begin imports #many frequently used functions are here [Kernel32.dll] GetLogicalDriveStringsA GetModuleHandleA GetCommandLineA LoadLibraryA ExitProcess GlobalAlloc GlobalSize GlobalFree GlobalReAlloc Sleep CreateFileA ReadFile WriteFile CloseHandle GetFileSize CreateThread CreateProcessA SuspendThread ResumeThread ExitThread TerminateThread FindFirstFileA FindNextFileA FindClose [user32.dll] RegisterClassExA CreateWindowExA ShowWindow UpdateWindow DefWindowProcA GetMessageA TranslateMessage DispatchMessageA SendMessageA LoadCursorA LoadIconA LoadMenuA BeginPaint EndPaint DrawTextA GetClientRect PostQuitMessage MessageBoxA SetForegroundWindow SetActiveWindow BringWindowToTop FindWindowA DestroyWindow PostMessageA CreatePopupMenu AppendMenuA SetMenu CreateMenu GetCursorPos TrackPopupMenu SetFocus LoadImageA [gdi32.dll] DeleteObject CreateFontIndirectA Rectangle CreateSolidBrush SelectObject SetBkMode ExtFloodFill CreatePen SetTextColor [comctl32.dll] InitCommonControls ImageList_Add ImageList_Create [comdlg32.dll] GetOpenFileNameA GetSaveFileNameA [crtdll.dll] fopen fclose fgets fputs fgetc fputc feof malloc realloc free fread fwrite fprintf fscanf _itoa memcpy memcmp memmove memset sprintf atoi strcpy strstr strncat end imports #-----------------Constants---------------------------------------------- begin const #many commonly used constants are here SW_HIDE 0 SW_SHOW 5 WS_CHILD 1073741824 WS_VISIBLE 268435456 WS_BORDER 8388608 WS_HSCROLL 1048576 WS_VSCROLL 2097152 WS_CAPTION 12582912 WS_CHILDWINDOW 1073741824 WS_OVERLAPPEDWINDOW 13565952 WS_POPUPWINDOW 2156396544 WS_SYSMENU 524288 WS_CLIENTEDGE 512 WS_MINIMIZEBOX 131072 WS_MAXIMIZEBOX 65536 WM_CREATE 1 WM_COPY 769 WM_CUT 768 WM_PASTE 770 WM_CLOSE 16 WM_COMMAND 273 WM_DESTROY 2 WM_ENABLE 10 WM_GETTEXT 13 WM_GETTEXTLENGTH 14 WM_INITDIALOG 272 WM_INITMENU 278 WM_KEYDOWN 256 WM_KEYUP 257 WM_KILLFOCUS 8 WM_LBUTTONDBLCLK 515 WM_LBUTTONDOWN 513 WM_LBUTTONUP 514 WM_MOVE 3 WM_NOTIFY 78 WM_PAINT 15 WM_ACTIVATE 6 WM_QUIT 18 WM_RBUTTONDBLCLK 518 WM_RBUTTONDOWN 516 WM_RBUTTONUP 517 WM_SETFOCUS 7 WM_SETFONT 48 WM_SETTEXT 12 WM_SIZE 5 WM_TIMER 275 WM_UNDO 772 LB_ADDSTRING 384 LB_RESETCONTENT 388 LB_SELECTSTRING 396 LB_SETTOPINDEX 407 LBS_HASSTRINGS 64 DT_SINGLELINE 32 DT_CENTER 1 DT_VCENTER 4 DT_BOTTOM 8 IDI_APPLICATION 32512 IDC_CROSS 32515 ES_AUTOVSCROLL 64 ES_AUTOHSCROLL 128 ES_MULTILINE 4 ES_WANTRETURN 4096 ES_LEFT 0 ES_NOHIDESEL 256 EN_MSGFILTER 1792 EN_CHANGE 768 ENM_MOUSEEVENTS 131072 ENM_SELCHANGE 524288 ENM_PROTECTED 2097152 ENM_KEYEVENTS 65536 ENM_UPDATE 2 ENM_SCROLL 4 ENM_CHANGE 1 EM_STREAMIN 1097 EM_STREAMOUT 1098 EM_GETFIRSTVISIBLELINE 206 EM_FINDTEXTEX 1103 EM_LINEFROMCHAR 201 EM_LINESCROLL 182 EM_SETLIMITTEXT 197 EM_SETEVENTMASK 1093 MF_ENABLED 0 MF_BYPOSITION 1024 MF_SEPARATOR 2048 MF_STRING 0 MF_POPUP 16 MF_DISABLED 2 MF_BYCOMMAND 0 GENERIC_READ 2147483648 GENERIC_WRITE 1073741824 OPEN_EXISTING 3 FILE_ATTRIBUTE_NORMAL 128 GMEM_ZEROINIT 64 SFF_SELECTION 32768 SFF_PLAINRTF 16384 SF_TEXT 1 SF_RTF 2 CB_ADDSTRING 323 CB_DELETESTRING 324 CB_GETCOUNT 326 CB_GETLBTEXT 328 CB_GETLBTEXTLEN 329 CB_INSERTSTRING 330 CB_RESETCONTENT 331 CB_GETCURSEL 327 CB_SETCURSEL 334 CB_FINDSTRINGEXACT 344 CBS_DROPDOWN 2 CBS_DROPDOWNLIST 3 CBS_HASSTRINGS 512 CBS_SORT 256 CBS_SIMPLE 1 CBN_DROPDOWN 7 CBN_SELENDOK 9 CBN_SELCHANGE 1 CBN_CLOSEUP 8 OFN_EXPLORER 524288 OFN_HIDEREADONLY 4 OFN_LONGNAMES 2097152 OFN_PATHMUSTEXIST 2048 MB_ICONASTERISK 64 FILE_ATTRIBUTE_DIRECTORY 16 INVALID_HANDLE_VALUE 4294967295 LBS_SORT 2 LR_LOADFROMFILE 16 TVS_HASLINES 2 TVS_LINESATROOT 4 TVS_HASBUTTONS 1 TVIF_TEXT 1 TVI_FIRST -65535 TVM_INSERTITEM 4352 TVI_LAST 65534 TVM_SETIMAGELIST 4361 TVIF_IMAGE 2 TVIF_SELECTEDIMAGE 32 TVN_SELCHANGEDA -402 TVM_SORTCHILDREN 4371 TVM_DELETEITEM 4353 TVM_GETITEM 4364 TVGN_PARENT 3 TVM_GETNEXTITEM 4362 TVM_EXPAND 4354 TVE_EXPAND 2 TVM_SELECTITEM 4363 TVM_ENSUREVISIBLE 4372 TVN_SELCHANGING -401 TVN_ITEMEXPANDED -406 TVGN_CHILD 4 TVN_ITEMEXPANDING -405 PBM_SETSTEP 1028 PBM_STEPIT 1029 PBM_SETPOS 1026 end const #-----------------Data Section------------------------------------------- #some useful predefined variables are here begin data dword hwndMain 0 string Class Window dword hInstance 0 string ClassName WinClass string AppName Windows Template ! string MenuName Menu string btn button string text Edit string combo combobox string list listbox string pbar msctls_progress32 string rich RICHED32.DLL string riched RICHEDIT string colon : dword quit 0 string font1 ms sans serif string font2 Courier New sequence fon1 60 sequence fon2 60 dword hfont1 0 dword hfont2 0 string ofnfilter All Files string read r string write w string readb rb string writeb wb string WindowCaption Recursive Directory Tree Fill ! string ab About ... string ab1 MyApp Version 1.0 string ab2 by .... string ab3 ---------------------------------------------------- string spc string spc6 dword hmenu 0 dword hfilemenu 0 dword heditmenu 0 dword hviewmenu 0 dword hhelpmenu 0 string fmenu &File string new &New string open &Open string save &Save string hyphen - string exit E&xit string emenu &Edit string undo &Undo string cut &Cut string copy C&opy string paste &Paste string find &Find... string replace &Replace... string selall &Select All string pmenu &Help string about &About ... sequence buffer 256 sequence buf 48 sequence listbuf 48 sequence icobuf 24 sequence pt 8 sequence ofnfname 256 dword htext1 0 dword htext2 0 dword htext3 0 dword htext4 0 dword htext5 0 dword hbtn1 0 dword hbtn2 0 dword hbtn3 0 dword hbtn4 0 dword hbtn5 0 dword hbtn6 0 dword hbtn7 0 dword hlist 0 dword hlist1 0 dword hcombo1 0 sequence blank 1 dword CommandLine 0 dword hmem 0 sequence wndclass 16 sequence msg 28 sequence ibuf 32 dword mem 0 string allfiles c:\*.* sequence winfindata 318 string tree SysTreeView32 string listv SysListView32 dword htree 0 dword fhnd 0 dword himlist 0 dword hbmp 0 sequence drbuffer 256 dword selitem 0 sequence tvitem 40 sequence tvtext 128 string slash \ dword parent 0 dword selected 0 string stars *.* string slashStars \*.* dword filepath 0 dword seltext 0 string ccolon c: sequence path 256 dword dir 0 sequence tvins 48 string dot + string cprog c:\program files string recurs Recursive fill dword pbar1 0 dword dataend 4294967295 end data #------------------------------------------------------------------------- begin code #the real code begin here ! proc strlen dword q push ebp mov ebp esp mov edi [q] mov eax 0 mov ecx 0 cld search_loop: inc ecx scasb jne search_loop dec ecx mov eax ecx leave ret 4 endp #------------------------------------------------------------------------ proc strcat dword s1 dword s2 dword len1 0 dword len2 0 dword addr 0 dword len 0 push ebp mov ebp esp add esp -48 invoke strlen s1 mov len1 eax invoke strlen s2 mov len2 eax add eax len1 inc eax len = eax invoke malloc eax invoke memset eax 0 len mov addr eax mov edi eax mov ecx len1 mov esi s1 rep_movsb mov ecx len2 mov esi s2 rep_movsb mov eax addr leave ret 8 endp #------------------------------------------------------------------------ proc left dword s dword n dword slen 0 push ebp mov ebp esp add esp -16 cld eax = n inc eax slen = eax invoke malloc eax edi = eax invoke memset eax 0 slen esi = s ecx = n rep_movsb leave ret 8 endp #------------------------------------------------------------------------ proc addTreeItem dword level dword string #returns handle of inserted item dword n 0 sequence tvins 48 push ebp mov ebp esp add esp -180 eax=level [tvins]=eax [tvins+4]= {TVI_LAST} or eax {TVIF_TEXT} [tvins+8]=eax [tvins+12]=0 [tvins+16]=0 [tvins+20]=0 eax=string #memory to memory [tvins+24]=eax [tvins+28]=18 [tvins+32]=0 [tvins+36]=1 [tvins+40]=0 [tvins+44]=0 lea eax tvins invoke SendMessageA [htree] {TVM_INSERTITEM} 0 eax leave ret 8 endp #------------------------------------------------------------------------ proc RecursiveFill dword path dword parent dword n 0 dword winfind 0 dword filehnd 0 dword st 0 dword nparent 0 dword dir 0 push ebp mov ebp esp add esp -48 winfind = malloc 318 st=strcat path slashStars filehnd=FindFirstFileA st winfind cmp eax {INVALID_HANDLE_VALUE} je gf_out gf_loop: eax=winfind ebx=[eax] if ebx={FILE_ATTRIBUTE_DIRECTORY} add eax 44 dir=eax ebx=0 bl=[eax] if ebx <> 46 #invoke addTreeItem parent eax eax=parent [tvins]=eax eax=dir [tvins+24]=eax invoke SendMessageA htree {TVM_INSERTITEM} 0 tvins nparent=eax st=strcat path slash st=strcat st dir push filehnd push winfind invoke RecursiveFill st nparent #this is the recursion. the function calls itself invoke SendMessageA htree {TVM_SORTCHILDREN} 0 nparent invoke SendMessageA pbar1 {PBM_STEPIT} 0 0 pop winfind pop filehnd endif endif invoke FindNextFileA filehnd winfind if eax=0 jmp gf_out endif jmp gf_loop gf_out: invoke free winfind invoke SendMessageA pbar1 {PBM_SETPOS} 100 0 leave ret 8 endp #------------------------------------------------------------------------ proc WndProc dword hwnd dword msg dword wparam dword lparam sequence lvitem 36 sequence lvcol 24 dword fn 0 dword hdc 4 sequence rect 16 dword ordata 0 dword fn 0 dword n 0 dword m 0 dword x 0 dword y 0 dword st 0 dword first 0 dword winfind 0 dword val 0 sequence exp 128 sequence ps 64 dword drive 0 push ebp mov ebp esp add esp -180 cmp msg {WM_CREATE} je wmcreate cmp msg {WM_PAINT} je wmpaint cmp msg {WM_COMMAND} je wmcommand cmp [msg] {WM_NOTIFY} je wmnotify cmp msg {WM_DESTROY} jne default push 0 call PostQuitMessage jmp exit wmcreate: mov eax {WS_CHILD} or eax {WS_BORDER} or eax {WS_VISIBLE} or eax {WS_VSCROLL} or eax {TVS_HASLINES} or eax {TVS_LINESATROOT} or eax {TVS_HASBUTTONS} ordata= eax invoke CreateWindowExA 0 tree blank ordata 20 40 200 250 hwnd 0 hInstance 0 mov htree eax invoke SendMessageA htree {WM_SETFONT} hfont1 0 selected=0 [tvins+4]= {TVI_LAST} or eax {TVIF_TEXT} [tvins+8]=eax [tvins+12]=0 [tvins+16]=0 [tvins+20]=0 [tvins+28]=180 [tvins+32]=0 [tvins+36]=1 [tvins+40]=0 [tvins+44]=0 mov eax {WS_CHILD} or eax {WS_BORDER} or eax {WS_VISIBLE} ordata= eax invoke CreateWindowExA 0 btn recurs ordata 20 10 200 25 hwnd 0 hInstance 0 mov hbtn1 eax invoke SendMessageA hbtn1 {WM_SETFONT} hfont1 0 invoke CreateWindowExA 0 pbar blank ordata 20 300 200 25 hwnd 0 hInstance 0 mov pbar1 eax invoke SendMessageA pbar1 {WM_SETFONT} hfont1 0 invoke SendMessageA pbar1 {PBM_SETSTEP} 2 0 jmp exit wmpaint: lea eax ps invoke BeginPaint hwnd eax mov hdc eax lea eax ps invoke EndPaint hwnd eax jmp exit wmcommand: #menu items if lparam = 0 if wparam = 101 jmp exit endif if wparam = 102 jmp exit endif if wparam = 200 jmp exit endif if wparam = 202 jmp exit endif if wparam = 203 jmp exit endif if wparam = 204 endif if wparam = 806 endif jmp default endif #end of menu items btn1: mov eax hbtn1 cmp lparam eax jne btn2 invoke GetLogicalDriveStringsA 256 drbuffer n=0 eax=drbuffer ebx=[eax] while ebx <> 0 drive=left eax 2 invoke addTreeItem 0 drive m=eax invoke RecursiveFill drive eax invoke SendMessageA htree {TVM_SORTCHILDREN} 0 m add n 4 eax=drbuffer add eax n ebx=[eax] endw jmp exit btn2: mov eax hbtn2 cmp lparam eax jne btn3 invoke addTreeItem 0 cprog n=eax invoke RecursiveFill cprog eax invoke SendMessageA htree {TVM_SORTCHILDREN} 0 n jmp exit btn3: mov eax hbtn3 cmp lparam eax jne btn4 jmp exit btn4: mov eax hbtn4 cmp lparam eax jne btn5 jmp exit btn5: mov eax hbtn5 cmp lparam eax jne btn6 jmp exit btn6: mov eax hbtn6 cmp lparam eax jne default jmp exit wmnotify: #WM_NOTIFY message jmp exit default: invoke DefWindowProcA hwnd msg wparam lparam leave ret 16 exit: xor eax eax leave ret 16 endp #------------------------------------------------------------------------ proc WinMain dword hinst dword previnst dword comline dword cmdshow sequence wc 48 dword ordata 0 dword len 0 dword topmenu 0 dword dropmenu 0 dword sepmenu 0 push ebp mov ebp esp add esp -80 call InitCommonControls mov eax fon2 mov [eax] 16 add eax 16 mov [eax] 400 add eax 12 invoke strcpy eax font2 hfont2 = CreateFontIndirectA fon2 mov eax fon1 mov [eax] 10 add eax 16 mov [eax] 400 add eax 12 invoke strcpy eax font1 hfont1 = CreateFontIndirectA fon1 [wc]= 48 [wc+4] =3 [wc+8]= WndProc [wc+12]= 0 [wc+16] =0 eax =hInstance [wc+20]= eax push 1 push hInstance call LoadIconA [wc+24]= eax [wc+44]= eax push {IDC_CROSS} push 0 call LoadCursorA [wc+28] =eax [wc+32]= 16 [wc+36]= 0 [wc+40]= ClassName lea eax wc invoke RegisterClassExA eax or eax {WS_SYSMENU} or eax {WS_MINIMIZEBOX} ordata=eax invoke CreateWindowExA {WS_CLIENTEDGE} ClassName WindowCaption ordata 50 50 250 380 0 0 hInstance 0 hwndMain= eax #this is old style before the advent of invoke push 1 push hwndMain call ShowWindow push hwndMain call UpdateWindow MsgLoop: invoke GetMessageA msg 0 0 0 cmp eax 0 je exitprocess invoke TranslateMessage msg invoke DispatchMessageA msg jmp MsgLoop exitprocess: mov eax [msg+8] leave ret 16 endp #------------------------------------------------------------------------ EntryPoint #this is old style before the advent of invoke push 0 call GetModuleHandleA mov hInstance eax call GetCommandLineA mov CommandLine eax invoke WinMain hInstance 0 CommandLine 10 push eax call ExitProcess end code #-----------------Icon Resource--------------------------------------- #the one and only resource (at the moment) icon win32app.ico oke push 0 call GetModuleHandleA mov hInstance eax call GetCommandLineA mov CommandLine eax invoke WinMain hInstance 0 CommandLine 10 push eax call ExitProcess end code #-----------------Resources--------------------------------------- begin resources icon win32app.ico end resources