flat assembler
Message board for the users of flat assembler.

Index > Windows > error: undefined symbol, are you sure?

Author
Thread Post new topic Reply to topic
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
hi, i came with another weird situation, maybe it is my mistake, hopefully your guys could check with the following code.

Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.data' data readable writeable
 insH            dd ?
        
section '.code' code readable executable
start:
        invoke  GetModuleHandle,0
           mov  [insH],eax
     invoke  DialogBoxParam,eax,30,NULL,dialog_procedureA,NULL

proc dialog_procedureA,hDlg,uMsg,wParam,lParam
.test1       dd ?                                            ;define the symbol
enter
 cmp  [uMsg],WM_CLOSE
        je   wdmCLOSE
       cmp  [uMsg],WM_INITDIALOG
   je   wdmINITDIALOG
       return

     wdmCLOSE:
               invoke  EndDialog,[hDlg],0
          return

  wdmINITDIALOG:
                  ;lea  eax,[.test1]              ; error: undefined symbol?
              stdcall testing,2,4,6,8
             return
endp

proc testing,a,b,c,d
.test1    dd ?
enter
       lea  eax,[.test1]                               ; ok here
   mov  [.test1],eax
   return
endp

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

        include '%fasminc%\apia\Kernel32.inc'
   include '%fasminc%\apia\User32.inc'

section '.rsrc' resource data readable
     directory RT_DIALOG,appDialog

   resource appDialog,\
                30,LANG_NEUTRAL,dlgTest

        dialog dlgTest,'Test',0,0,170,50,\
               DS_MODALFRAME + WS_VISIBLE + WS_CAPTION + WS_POPUP + WS_SYSMENU
             dialogitem      'STATIC','On Test',0,17,14,40,10,SS_LEFT + WS_GROUP + WS_VISIBLE
        enddialog
    
Post 04 Nov 2004, 21:28
View user's profile Send private message Visit poster's website Reply with quote
Tommy



Joined: 17 Jun 2003
Posts: 489
Location: Norway
Tommy
that's because you're not using local labels inside the proc... you're using wdmINITDIALOG.test1... it's defined as dialog_procedureA.test1
Post 04 Nov 2004, 21:54
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
thanks tommy,
i didn't realize that once we use a : we are in another scope!

Code:
  wdmINITDIALOG:
          jmp there
           .test1  dd ?
                there:
                  lea  eax,[wdmINITDIALOG.test1]
                      lea  eax,[dialog_procedureA.test1]
          stdcall testing,2,4,6,8
             return
    

this clear my confuse Smile, thanks
Post 04 Nov 2004, 23:19
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17347
Location: In your JS exploiting you and your system
revolution
It's not the : that makes a new scope, it is a label that does nos begin with a . that makes a new scope.

Try this with the four extra .'s instead.

Code:
proc dialog_procedureA,hDlg,uMsg,wParam,lParam 
.test1  dd ?                                            ;define the symbol 
enter 
        cmp  [uMsg],WM_CLOSE 
        je   .wdmCLOSE 
        cmp  [uMsg],WM_INITDIALOG 
        je   .wdmINITDIALOG 
             return 

        .wdmCLOSE: 
                invoke  EndDialog,[hDlg],0 
                return 

        .wdmINITDIALOG: 
                        lea  eax,[.test1]              ; Now it works. 
                stdcall testing,2,4,6,8 
                return 
endp 

    
Post 05 Nov 2004, 01:22
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
thanks revolution but ...
Code:
format PE GUI 4.0
entry start

include '%fasminc%\win32a.inc'

section '.data' data readable writeable
   insH            dd ?
        wndTitle        db 'On Test',0

        buf1    rb 0x30
     buf2    rb 0x30
     f1      db '.wdmINITDIALOG -> %lu',0
   f2      db '.wdmCTLCOLORSTATIC -> %lu',0
       
section '.code' code readable executable
start:
        invoke  GetModuleHandle,0
           mov  [insH],eax
     invoke  DialogBoxParam,eax,30,NULL,dialog_procedureA,NULL

proc dialog_procedureA,hDlg,uMsg,wParam,lParam
.t2  dd ?
enter
       cmp  [uMsg],WM_CLOSE
        je   .wdmCLOSE
      cmp  [uMsg],WM_INITDIALOG
   je   .wdmINITDIALOG
 cmp  [uMsg],WM_CTLCOLORSTATIC
       je   .wdmCTLCOLORSTATIC
          return

     .wdmCLOSE:
              invoke  EndDialog,[hDlg],0
          return

  .wdmINITDIALOG:
                 mov  [.t2],30                           ;<- so, we move 30 into it
                       mov  eax,[.t2]
              invoke  wsprintf,buf1,f1,eax
                invoke  MessageBox,NULL,buf1,wndTitle,MB_OK
                 return

  .wdmCTLCOLORSTATIC:
                     mov  eax,[.t2]                          ;<- now, do you have any idea
            invoke  wsprintf,buf2,f2,eax                    ;   why it shouldn't be 30?
                invoke  MessageBox,NULL,buf2,wndTitle,MB_OK
                 mov  eax,FALSE
                      return
endp

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

        include '%fasminc%\apia\Kernel32.inc'
   include '%fasminc%\apia\User32.inc'

section '.rsrc' resource data readable
     directory RT_DIALOG,appDialog

   resource appDialog,\
                30,LANG_NEUTRAL,dlgTest

        dialog dlgTest,'Test',0,0,170,50,\
               DS_MODALFRAME + WS_VISIBLE + WS_CAPTION + WS_POPUP + WS_SYSMENU
             dialogitem      'STATIC','',0,5,5,100,40,SS_LEFT + WS_VISIBLE
   enddialog
    
Post 05 Nov 2004, 03:30
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17347
Location: In your JS exploiting you and your system
revolution
The variable ".t2" is not a static variable. It is on the stack. Each time dialog_procedureA is called a new space is allocated within the stack. More than likely the value will be changed by many other things happening on the stack between calls the dialog_procedureA

You need to put ".t2" in the same place as buf1 and the others for it to keep values between calls.

Try viewing the actual code generated in a debugger. It may help you to understand how the stack is used by the "proc" macro.
Post 05 Nov 2004, 08:23
View user's profile Send private message Visit poster's website Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
Code:
stackerproc:
.t1 ; this is interpreted as stackerproc.t1
jmp .t2 ; now you see what is the case?
cxz: 
.t2 ; this is interpreted as cxz.t2
.t4 ; this is interpreted as cxz..t4
.t3 ; this is interpreted as cxz.t3
ret
    


local labels are referenced to the nearest global label/procedure upwards.
Post 05 Nov 2004, 11:06
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
arent the stack supposely cannot be modifed?
Post 07 Nov 2004, 14:43
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17347
Location: In your JS exploiting you and your system
revolution
Stacks are always being modified. It is one of the most volitile places to store data. Once the routine returns (RET) it releases the stack for use by other code.
Post 08 Nov 2004, 01:41
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
thanks you revolution, you RET clears my confuse Smile

ps: i am acutally quite new to assembly language, play with NASM before for a very short time, (no application produced!), any later on, i found FASM (which makes me stick until now) about 4 months already Smile
Post 08 Nov 2004, 09:22
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17347
Location: In your JS exploiting you and your system
revolution
Kembali.

PS: Selamat Hari Raya. Anda balik kampung untuk minggu depan?
Post 09 Nov 2004, 02:04
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
thank you revolution Smile never know you could speak malay hah :p
are you from malaysia? anyway, i am chinese :p

希望您开斋节快乐!

i don't have kampung to balik lah :p
Post 09 Nov 2004, 04:54
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17347
Location: In your JS exploiting you and your system
revolution
Saya tak cakap bahasa cina.

Saya cakap sedikit sahaja bahasa Melayu. Saya kerja dalam Malaysia sebelum ini. Suka berlatih bila-bila saya dapat peluang.
Post 10 Nov 2004, 08:20
View user's profile Send private message Visit poster's website Reply with quote
vbVeryBeginner



Joined: 15 Aug 2004
Posts: 884
Location: \\world\asia\malaysia
vbVeryBeginner
bagus lah, sedikit pun jadilah :p

chinese language is fun, if you got time, you could learn it Smile maybe someday you would work in china ?
Post 10 Nov 2004, 13:05
View user's profile Send private message Visit poster's website 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 YouTube, Twitter.

Website powered by rwasa.