flat assembler
Message board for the users of flat assembler.

Index > Windows > strange problem with messagebox

Author
Thread Post new topic Reply to topic
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
So maybe someone could help.
I have an application and there is a function called on keystroke (F12).

If I press the key, the function is executed but not as expected.

Code:
        invoke  MessageBox,[hwnd],_welcome,_caption,MB_ICONERROR+MB_OK
initusb:
        invoke  FT_CreateDeviceInfoList,ftdevices
        mov     eax,[ftdevices]
        call    printeax   ; messagebox appears first time
        call    printeax   ; but not second time
        jmp  finished

  printeax:
        cinvoke  wsprintf,my_string_buffer,fmtprt,eax
        invoke  MessageBox,[hwnd],my_string_buffer,_caption,MB_ICONERROR+MB_OK
        ret

fmtprt  db '%#p',0

    


So the first messagebox is printed on screen when key pressed.
The second messagebox is printed after it in function printeax.
But when I call printeax second time (or third or whatever) no more messagebox appears.
If I copy the "welcome" messagebox of the first line, it's executed multiple times.
If I double the invoke of messagebox directly in the printeax function, it also is printed twice.
But why is the messagebox not shown when I repeat the call of the function ???

Things can get mad when you don't understand why. Shocked
Post 30 May 2012, 16:15
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
try using
Code:
jmp printeax    
instead of
Code:
call printeax    
Post 30 May 2012, 20:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17270
Location: In your JS exploiting you and your system
revolution
You didn't show all of your code so we have to assume some things not given. Is your code section posted inside a proc/endp section? If it is then the problem is caused by the ret. Use retn to avoid instantiating the ret macro:
Code:
  printeax:
        cinvoke  wsprintf,my_string_buffer,fmtprt,eax
        invoke  MessageBox,[hwnd],my_string_buffer,_caption,MB_ICONERROR+MB_OK
        retn ; <--- don't use the ret macro here    
Post 30 May 2012, 22:19
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
revolution wrote:
You didn't show all of your code so we have to assume some things not given. Is your code section posted inside a proc/endp section? If it is then the problem is caused by the ret. Use retn to avoid instantiating the ret macro:


Okay you are right.
It was in a proc section (Window Proc) and I didn't expect that ret is a macro instruction as it is also an official assembling instruction.

Works fine now with retn. Wink
Post 31 May 2012, 11:59
View user's profile Send private message Send e-mail Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
typedef wrote:
try using
Code:
jmp printeax    
instead of
Code:
call printeax    


That didn't help and I want to call a simple subroutine.
Okay now it's not much code which could be copied several times but it was more to understand principals than getting some workaround. Wink
Post 31 May 2012, 12:02
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
Then set up your calling right like revolution suggested.
Post 31 May 2012, 17:14
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
As you can read - i did and it worked.
I just wanted to let you know, that simply jmp instead of call is not working - with ret. Very Happy
Post 31 May 2012, 21:38
View user's profile Send private message Send e-mail Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
shutdownall wrote:
As you can read - i did and it worked.
I just wanted to let you know, that simply jmp instead of call is not working - with ret. Very Happy


lol. Dude, I assumed that you knew you don't mix jmp with ret.

If you JMP to X you have to JMP back to Y and not RET.


I thought you knew that. You fixed it so let's move on.
Post 01 Jun 2012, 02:39
View user's profile Send private message Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
As I know the difference between GOSUB/RETURN and GOTO I assume it is similar to call and jmp. Razz
Post 01 Jun 2012, 09:57
View user's profile Send private message Send e-mail 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.

Powered by rwasa.