flat assembler
Message board for the users of flat assembler.
![]() |
Author |
|
catafest 04 Mar 2025, 13:45
I try to find files with fasm version 1.73.32 , the source code I used:
Code: format PE GUI 4.0 entry start include '\INCLUDE\win32a.inc' section '.data' data readable writeable class_name db 'FileListClass',0 window_name db 'Files on D: Drive',0 file_list rb 1024*1024 file_name rb 260 find_data WIN32_FIND_DATA <0> hwnd dd ? msg MSG <0> wc WNDCLASS <0> ps PAINTSTRUCT <0> rect RECT <0> section '.code' code readable executable start: invoke GetModuleHandle,0 mov [wc.hInstance],eax mov [wc.hIcon],eax mov [wc.hCursor],eax mov [wc.hbrBackground],COLOR_BTNFACE+1 mov [wc.lpszClassName],class_name mov [wc.lpfnWndProc],WndProc invoke RegisterClass,wc invoke CreateWindowEx,0,class_name,window_name,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,640,480,0,0,[wc.hInstance],0 mov [hwnd],eax invoke ShowWindow,[hwnd],SW_SHOW invoke UpdateWindow,[hwnd] message_loop: invoke GetMessage,msg,0,0,0 test eax,eax jz exit_program invoke TranslateMessage,msg invoke DispatchMessage,msg jmp message_loop exit_program: invoke ExitProcess,[msg.wParam] proc WndProc hWnd, uMsg, wParam, lParam cmp [uMsg],WM_PAINT je .wm_paint cmp [uMsg],WM_DESTROY je .wm_destroy invoke DefWindowProc,[hWnd],[uMsg],[wParam],[lParam] ret .wm_paint: invoke BeginPaint,[hWnd],ps mov [hDC],eax invoke GetClientRect,[hWnd],rect invoke GetFileList,'D:\\',file_list invoke SetTextColor,[hDC],COLOR_WINDOWTEXT invoke SetBkColor,[hDC],COLOR_WINDOW invoke DrawText,[hDC],file_list,-1,rect,DT_LEFT+DT_TOP+DT_WORDBREAK invoke EndPaint,[hWnd],ps ret .wm_destroy: invoke PostQuitMessage,0 ret endp proc GetFileList, directory, buffer local hFind:HANDLE local file_name[260]:byte local search_pattern[260]:byte local file_list_ptr:DWORD local file_size:DWORD invoke lstrcpy,search_pattern,[directory] invoke lstrcat,search_pattern,'*' invoke FindFirstFile,search_pattern,find_data mov [hFind],eax cmp eax,INVALID_HANDLE_VALUE je .end .next_file: invoke lstrcpy,file_name,find_data.cFileName invoke lstrcat,[buffer],file_name invoke lstrcat,[buffer],'\n' invoke FindNextFile,[hFind],find_data test eax,eax jnz .next_file .end: invoke FindClose,[hFind] ret endp section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL',\ gdi32,'GDI32.DLL' import kernel32,\ GetModuleHandle,'GetModuleHandleA',\ ExitProcess,'ExitProcess',\ FindFirstFile,'FindFirstFileA',\ FindNextFile,'FindNextFileA',\ FindClose,'FindClose' import user32,\ RegisterClass,'RegisterClassA',\ CreateWindowEx,'CreateWindowExA',\ ShowWindow,'ShowWindow',\ UpdateWindow,'UpdateWindow',\ GetMessage,'GetMessageA',\ TranslateMessage,'TranslateMessage',\ DispatchMessage,'DispatchMessageA',\ DefWindowProc,'DefWindowProcA',\ PostQuitMessage,'PostQuitMessage',\ BeginPaint,'BeginPaint',\ EndPaint,'EndPaint',\ GetClientRect,'GetClientRect',\ DrawText,'DrawTextA' import gdi32,\ SetTextColor,'SetTextColor',\ SetBkColor,'SetBkColor's The error comes with : Unexpected instruction 'else' at line 99. Any idea why this not work ? See this : Code: import kernel32,\ GetModuleHandle,'GetModuleHandleA',\ ExitProcess,'ExitProcess',\ FindFirstFile,'FindFirstFileA',\ FindNextFile,'FindNextFileA',\ FindClose,'FindClose' ... into import32.inc is this **else** at: Code: macro import name,[label,string] { common rb (- rva $) and 3 if defined name#.referred name#.lookup: forward if used label if string eqtype '' local _label dd RVA _label else ... enter code here
|
|||||||||||
![]() |
|
macomics 04 Mar 2025, 18:04
Code: struct FILE_PATH_BUFFER buf db 260 dup (?) ends proc GetFileList aDirectory, aBuffer ; <-- Extra comma local hFind:DWORD local file_name:FILE_PATH_BUFFER ; Incorrect declaration of local variables local search_pattern:FILE_PATH_BUFFER ; Incorrect declaration of local variables To understand that the error is in another place, simply move the import section to the beginning. Code: format PE GUI 4.0 entry start include '\INCLUDE\win32a.inc' section '.idata' import data readable writeable library kernel32,'KERNEL32.DLL',\ user32,'USER32.DLL',\ gdi32,'GDI32.DLL' import kernel32,\ GetModuleHandle,'GetModuleHandleA',\ ExitProcess,'ExitProcess',\ FindFirstFile,'FindFirstFileA',\ FindNextFile,'FindNextFileA',\ FindClose,'FindClose' import user32,\ RegisterClass,'RegisterClassA',\ CreateWindowEx,'CreateWindowExA',\ ShowWindow,'ShowWindow',\ UpdateWindow,'UpdateWindow',\ GetMessage,'GetMessageA',\ TranslateMessage,'TranslateMessage',\ DispatchMessage,'DispatchMessageA',\ DefWindowProc,'DefWindowProcA',\ PostQuitMessage,'PostQuitMessage',\ BeginPaint,'BeginPaint',\ EndPaint,'EndPaint',\ GetClientRect,'GetClientRect',\ DrawText,'DrawTextA' import gdi32,\ SetTextColor,'SetTextColor',\ SetBkColor,'SetBkColor' section '.data' data readable writeable class_name db 'FileListClass',0 window_name db 'Files on D: Drive',0 file_list rb 1024*1024 file_name rb 260 find_data WIN32_FIND_DATA <0> hwnd dd ? msg MSG <0> wc WNDCLASS <0> ps PAINTSTRUCT <0> rect RECT <0> section '.code' code readable executable start: invoke GetModuleHandle,0 mov [wc.hInstance],eax mov [wc.hIcon],eax mov [wc.hCursor],eax mov [wc.hbrBackground],COLOR_BTNFACE+1 mov [wc.lpszClassName],class_name mov [wc.lpfnWndProc],WndProc invoke RegisterClass,wc invoke CreateWindowEx,0,class_name,window_name,WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,CW_USEDEFAULT,640,480,0,0,[wc.hInstance],0 mov [hwnd],eax invoke ShowWindow,[hwnd],SW_SHOW invoke UpdateWindow,[hwnd] message_loop: invoke GetMessage,msg,0,0,0 test eax,eax jz exit_program invoke TranslateMessage,msg invoke DispatchMessage,msg jmp message_loop exit_program: invoke ExitProcess,[msg.wParam] proc WndProc hWnd, uMsg, wParam, lParam cmp [uMsg],WM_PAINT je .wm_paint cmp [uMsg],WM_DESTROY je .wm_destroy invoke DefWindowProc,[hWnd],[uMsg],[wParam],[lParam] ret .wm_paint: invoke BeginPaint,[hWnd],ps mov [hDC],eax invoke GetClientRect,[hWnd],rect invoke GetFileList,'D:\\',file_list invoke SetTextColor,[hDC],COLOR_WINDOWTEXT invoke SetBkColor,[hDC],COLOR_WINDOW invoke DrawText,[hDC],file_list,-1,rect,DT_LEFT+DT_TOP+DT_WORDBREAK invoke EndPaint,[hWnd],ps ret .wm_destroy: invoke PostQuitMessage,0 ret endp proc GetFileList, aDirectory, aBuffer local hFind:DWORD local file_name[260]:BYTE local search_pattern[260]:BYTE local file_list_ptr:DWORD local file_size:DWORD invoke lstrcpy,addr [search_pattern],[aDirectory] invoke lstrcat,addr [search_pattern],'*' invoke FindFirstFile,addr [search_pattern],find_data mov [hFind],eax cmp eax,INVALID_HANDLE_VALUE je .end .next_file: invoke lstrcpy,addr [file_name],find_data.cFileName invoke lstrcat,[aBuffer],addr [file_name] invoke lstrcat,[aBuffer],'\n' invoke FindNextFile,[hFind],find_data test eax,eax jnz .next_file .end: invoke FindClose,[hFind] ret endp AsmGuru62, you got ahead of me. |
|||
![]() |
|
AsmGuru62 04 Mar 2025, 18:47
macomics, it must be my IDE (I wrote it around 2009) -- just copy/paste code and compile it.
|
|||
![]() |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.