flat assembler
Message board for the users of flat assembler.

Index > Windows > My program crashes

Author
Thread Post new topic Reply to topic
Hydrogen



Joined: 15 Apr 2016
Posts: 6
Hydrogen 15 Apr 2016, 06:00
hi guys,

Newbie here with a really simple problem I can't figure out. I'm trying to create a very basic win64 console program. I have the code below and it compiles, but when I run it from the cmd prompt, it crashes. Shouldn't the program return and not do anything? What obvious mistake am I missing here?

Code:
format PE64 Console
entry start 

include 'win64a.inc'

section '.text' code readable executable

start:
        mov eax,1
        
section '.data' data readable writeable
       
        count dd ?
       
section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL'

  include 'api\kernel32.inc'
  include 'api\user32.inc'       
Post 15 Apr 2016, 06:00
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 670
system error 15 Apr 2016, 06:15
If u dont know whats your problem is, then let me show you the exit door.
Post 15 Apr 2016, 06:15
View user's profile Send private message Reply with quote
Hydrogen



Joined: 15 Apr 2016
Posts: 6
Hydrogen 15 Apr 2016, 06:30
system error wrote:
If u dont know whats your problem is, then let me show you the exit door.


Yikes! I know it's something simple, but I'm just not seeing it Sad

Here's my full code, but I've been debugging it to find the mistake.



Code:
        format PE64 Console
        entry start 

        include 'win64a.inc'


section '.text' code readable executable

start:
        mov eax,1 ;test

        invoke GetStdHandle, STD_INPUT_HANDLE
        mov [stdin], eax

        invoke GetStdHandle, STD_OUTPUT_HANDLE
        mov [stdout], eax

        invoke ReadConsole, [stdin],buff, 1024, addr count, 0

        invoke WriteConsole, [stdout], addr buff, [count], addr count, 0


section '.data' data readable writeable
        buff rb 1024
        count dd ?
        stdin dd ?
        stdout dd ?


section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL'

  include 'api\kernel32.inc'
  include 'api\user32.inc'         
Post 15 Apr 2016, 06:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20355
Location: In your JS exploiting you and your system
revolution 15 Apr 2016, 06:40
Code:
invoke ExitProcess,0    
Post 15 Apr 2016, 06:40
View user's profile Send private message Visit poster's website Reply with quote
Hydrogen



Joined: 15 Apr 2016
Posts: 6
Hydrogen 15 Apr 2016, 06:48
revolution wrote:
Code:
invoke ExitProcess,0    


thanks revolution! It works.

But I guess I'm a little confused. I was using this example:
Code:
        format PE Console 
        entry start 

        include 'win32ax.inc' 

;        section '.data' data readable writable 


        section '.code' code readable executable 
proc start uses ebx 
     local buff[1024]:BYTE 
     local count:DWORD 
     local stdin:DWORD 
     local stdout:DWORD 

        invoke GetStdHandle, STD_INPUT_HANDLE 
        mov [stdin], eax 

        invoke GetStdHandle, STD_OUTPUT_HANDLE 
        mov [stdout], eax 

        invoke ReadConsole, [stdin], addr buff, 1024, addr count, 0 

        invoke WriteConsole, [stdout], addr buff, [count], addr count, 0 

        ret 
endp 

        section '.idata' import data readable 
library kernel32,'kernel32.dll' 

import kernel32,\ 
       GetStdHandle,'GetStdHandle',\ 
       ReadConsole,'ReadConsoleA',\ 
       WriteConsole,'WriteConsoleA' 
    


from a previous post from here: http://board.flatassembler.net/topic.php?t=11964&view=next and I only adapted it to win64. It doesn't invoke Exitprocess, which is why I didn't use it.

Can you explain why my code needs it but his does not?

thanks again for your help
Post 15 Apr 2016, 06:48
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 670
system error 15 Apr 2016, 06:53
Good, but before you listen to the lady above me, Read it again so you can save yourself from the agony of your next problem. Welcome to the dark world full of extremely suicidal people.
Post 15 Apr 2016, 06:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20355
Location: In your JS exploiting you and your system
revolution 15 Apr 2016, 07:05
Hydrogen wrote:
from a previous post from here: http://board.flatassembler.net/topic.php?t=11964&view=next and I only adapted it to win64. It doesn't invoke Exitprocess, which is why I didn't use it.

Can you explain why my code needs it but his does not?
"ret" is a non-documented and non-standard way of "exiting" the program. Yes, it does work, but there is no guarantee that it will work for all version of Windows past, present and future.
Post 15 Apr 2016, 07:05
View user's profile Send private message Visit poster's website Reply with quote
system error



Joined: 01 Sep 2013
Posts: 670
system error 15 Apr 2016, 07:41
HAHA. I think your problem isn't with ret or invokeProcess. It's just that you can't hold the console window to see the output right? The prog exits abruptly? You're one of us now, so don't be shy. We been there too! Razz
Post 15 Apr 2016, 07:41
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.