flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved] having trouble with locals

Author
Thread Post new topic Reply to topic
DergMoney



Joined: 29 Apr 2015
Posts: 34
DergMoney
Hi,

Can anyone explain why this fails to assemble? I get an 'invalid value' error from fasm for

invoke FindFirstFile, fffStr, wfd

??
Code:
proc threadCheckForFiles

    locals
        wfd                    WIN32_FIND_DATA
        fffStr                 db "*.txt", 00
        searchingForFilesStr   db "Searching for files...", 00
        fnfHnd                 dd ?
    endl

        invoke  SetWindowText, [hWndMain], searchingForFileStr
        cmp     eax, TRUE
        je      .start
        call    showError
    .start:
        invoke  FindFirstFile, fffStr, wfd
        cmp     eax, INVALID_HANDLE_VALUE
        jne     @f
        jne     .start
        jmp     .finish
      @@:
        ; save FindNext handle
        mov     [fnfHnd], eax
    .finish:
        ret
endp
    
Post 07 Jun 2015, 08:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
You need to make it an address because of the implicit EBP offset:
Code:
invoke  SetWindowText, [hWndMain], addr searchingForFileStr
;...
invoke  FindFirstFile, addr fffStr, addr wfd    
Post 07 Jun 2015, 08:34
View user's profile Send private message Visit poster's website Reply with quote
DergMoney



Joined: 29 Apr 2015
Posts: 34
DergMoney
Thanks for the quick reply revolution. Unfortunately it didn't work Sad

flat assembler version 1.71.39 (1048576 kilobytes memory)
test.asm [72]:
invoke FindFirstFile, addr fffStr, addr wfd
D:\Program Files (x86)\Fasm\INCLUDE\macro/proc32.inc [17] invoke [3]:
pushd arg
error: invalid value.

Code:
proc threadCheckForFiles

    locals
        wfd                    WIN32_FIND_DATA
        fffStr                 db "*.txt", 00
        searchingForFilesStr   db "Searching for files...", 00
        fnfHnd                 dd ?
    endl

        invoke  SetWindowText, [hWndMain], addr searchingForFileStr
        cmp     eax, TRUE
        je      .start
        call    showError
    .start:
        invoke  FindFirstFile, addr fffStr, addr wfd
        cmp     eax, INVALID_HANDLE_VALUE
        jne     @f
        jne     .start
        jmp     .finish
      @@:
        ; save FindNext handle
        mov     [fnfHnd], eax
    .finish:
        ret
endp
    
Post 07 Jun 2015, 09:14
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
Are you including the win32ax.inc file?
Post 07 Jun 2015, 09:19
View user's profile Send private message Visit poster's website Reply with quote
DergMoney



Joined: 29 Apr 2015
Posts: 34
DergMoney
All the code is is a simple window that sets up a thread 'threadCheckForFiles'

If I comment out the two 'offensive' lines Rolling Eyes

Code:
invoke  SetWindowText, [hWndMain], addr searchingForFileStr
.
.
invoke  FindFirstFile, addr fffStr, addr wfd
    


it assembles without issue Question

Full code...

Code:
format PE GUI 4.0
entry start

include "%fasminc%\win32a.inc"

section '.code' code readable executable

    start:
        invoke  GetModuleHandle, 0
        mov         [wc.hInstance], eax
        invoke  LoadIcon, 0, IDI_APPLICATION
        mov         [wc.hIcon], eax
        invoke  LoadCursor, 0, IDC_ARROW
        mov         [wc.hCursor], eax
        invoke  RegisterClass, wc
        or          eax,eax
        jz          showError
        invoke  CreateWindowEx, NULL, ClassMain, AppName, WS_OVERLAPPEDWINDOW or WS_VISIBLE, 100, 100, 600, 200, NULL, NULL, [wc.hInstance], NULL
        test    eax,eax
        jz          showError
        mov     [hWndMain], eax
        invoke  CreateThread, NULL, 0, threadCheckForFiles, NULL,NORMAL_PRIORITY_CLASS, tcffId
        invoke  CloseHandle, eax

    msgLoop:
        invoke  GetMessage, msg, NULL, 0, 0
        or          eax, eax
        jz          endLoop
        invoke  TranslateMessage, msg
        invoke  DispatchMessage, msg
        jmp         msgLoop
    showError: 
        invoke  GetLastError 
        invoke  FormatMessage, FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, eax, LANG_NEUTRAL, errStrBuff, 0, NULL
        invoke  MessageBox, HWND_DESKTOP, [errStrBuff], NULL, MB_ICONERROR or MB_OK 
    endLoop:
        invoke  ExitProcess, [msg.wParam]

proc WndProc hwnd, wmsg, wparam, lparam
        push    ebx esi edi
        cmp     [wmsg], WM_DESTROY
        je      .wmDestroy
    .defWndProc:
        invoke  DefWindowProc, [hwnd], [wmsg], [wparam], [lparam]
        jmp     .finish
    .showError:
        invoke  GetLastError 
        invoke  FormatMessage, FORMAT_MESSAGE_FROM_SYSTEM or FORMAT_MESSAGE_ALLOCATE_BUFFER, NULL, eax, LANG_NEUTRAL, errStrBuff, 0, NULL
        invoke  MessageBox, HWND_DESKTOP, [errStrBuff], NULL, MB_ICONERROR or MB_OK 
    .wmDestroy:
        invoke  PostQuitMessage, 0
        xor         eax, eax
    .finish:
        pop     edi esi ebx
        ret
endp

proc threadCheckForFiles

    locals
        wfd                    WIN32_FIND_DATA
        fffStr                 db "*.txt", 00
        searchingForFilesStr   db "Searching for files...", 00
        fnfHnd                 dd ?
    endl

        invoke  SetWindowText, [hWndMain], addr searchingForFileStr
        cmp     eax, TRUE
        je      .start
        call    showError
    .start:
        invoke  FindFirstFile, addr fffStr, addr wfd
        cmp     eax, INVALID_HANDLE_VALUE
        jne     @f
        jne     .start
        jmp     .finish
      @@:
        ; save FindNext handle
        mov     [fnfHnd], eax
    .finish:
        ret
endp




section '.data' data readable writeable
    ClassMain   db "WinClass", 00
    AppName     db "Test App", 00
    hWndMain    dd ?
    wc          WNDCLASS CS_HREDRAW or CS_VREDRAW, WndProc, 0, 0, NULL, NULL, NULL, COLOR_BTNFACE + 1, NULL, ClassMain
    msg         MSG
    errStrBuff  dd ?
    tcffId      dd ?

section '.idata' import data readable writeable 
library kernel32,'KERNEL32.DLL',\ 
        user32,  'USER32.DLL'

include '%fasminc%\api\Kernel32.inc' 
include '%fasminc%\api\User32.inc' 
    
Post 07 Jun 2015, 09:27
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17658
Location: In your JS exploiting you and your system
revolution
I see your problem: include "%fasminc%\win32a.inc".

You'll need the "x" version.
include "%fasminc%\win32ax.inc"
Post 07 Jun 2015, 09:29
View user's profile Send private message Visit poster's website Reply with quote
DergMoney



Joined: 29 Apr 2015
Posts: 34
DergMoney
Hadn't noticed you changed your last post.Here's fasm's output using win32ax

flat assembler version 1.71.39 (1048576 kilobytes memory)
test.asm [67]:
invoke SetWindowText, [hWndMain], addr searchingForFileStr
D:\Program Files (x86)\Fasm\INCLUDE\win32ax.inc [41] invoke [0]:
\{ \reverse pushd <arg>
D:\Program Files (x86)\Fasm\INCLUDE\win32ax.inc [37] pushd [27]:
pushd <value>
D:\Program Files (x86)\Fasm\INCLUDE\win32ax.inc [37] match [1]:
pushd <value>
D:\Program Files (x86)\Fasm\INCLUDE\win32ax.inc [78] pushd [6]:
if +var relativeto 0 | +var relativeto $
D:\Program Files (x86)\Fasm\INCLUDE\win32ax.inc [78] match [1]:
if +var relativeto 0 | +var relativeto $
error: undefined symbol 'searchingForFileStr'.
Post 07 Jun 2015, 09:31
View user's profile Send private message Reply with quote
DergMoney



Joined: 29 Apr 2015
Posts: 34
DergMoney
Duh!

searchingForFileStr vs searchingForFilesStr

sorry to waste your time Embarassed
Post 07 Jun 2015, 09:34
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.