flat assembler
Message board for the users of flat assembler.

Index > Windows > [solved] user32.dll, Error illegal instruction

Author
Thread Post new topic Reply to topic
Iron-Man



Joined: 27 Feb 2023
Posts: 3
Iron-Man 27 Feb 2023, 17:51
I am trying to run the following code from: Mastering Assembly Programming


I am receiving the following error: user32.dll, Error illegal instruction

include 'win32a.inc'

format PE GUI
entry _start

section '.text' code readable executable
_start:
push 0
push 0
push title
push message
push 0
call [MessageBox]
call [ExitProcess]

section '.data' data readable writeable
message db 'Hello from FASM!', 0x00
title db 'Hello!', 0x00

section '.idata' import data readable writeable
library kernel, 'kernel32.dll',
user, 'user32.dll'

import kernel,\
ExitProcess, 'ExitProcess'

import user,\
MessageBox, 'MessageBoxA'

Any ideas on why this is an error?

Thanks !
Post 27 Feb 2023, 17:51
View user's profile Send private message Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1588
Location: Toronto, Canada
AsmGuru62 27 Feb 2023, 18:03
Your code missed something:

Code:
section '.idata' import data readable writeable
library kernel, 'kernel32.dll',\      ; <--- SLASH IS NOT THERE!
user, 'user32.dll'
    


Also, it is much easier to use invoke macro-extension provided by FASM:
Code:
include 'win32a.inc'

format PE GUI
entry _start

section '.text' code readable executable
_start:
invoke MessageBox, 0, message, title, 0
invoke ExitProcess, 0

section '.data' data readable writeable
message db 'Hello from FASM!', 0x00
title db 'Hello!', 0x00

section '.idata' import data readable writeable
library kernel, 'kernel32.dll',\
user, 'user32.dll'

import kernel,\
ExitProcess, 'ExitProcess'

import user,\
MessageBox, 'MessageBoxA'
    
Post 27 Feb 2023, 18:03
View user's profile Send private message Send e-mail Reply with quote
Iron-Man



Joined: 27 Feb 2023
Posts: 3
Iron-Man 27 Feb 2023, 22:23
Hello AsmGuru62 !

Your code works perfect. I made the change to my code but it now reports, Error: write failed.
Any ideas?

Thanks
Post 27 Feb 2023, 22:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20116
Location: In your JS exploiting you and your system
revolution 27 Feb 2023, 22:32
Windows will lock all executable files that are running.

You need to find the existing task, and close/exit/kill it.
Post 27 Feb 2023, 22:32
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1588
Location: Toronto, Canada
AsmGuru62 27 Feb 2023, 22:37
Iron-Man: you should post the code change you did.
Usually, "write failed" happens if your code never calls ExitProcess function.
Basically, the previous version of your EXE is still running, as revolution mentioned.
Post 27 Feb 2023, 22:37
View user's profile Send private message Send e-mail Reply with quote
Iron-Man



Joined: 27 Feb 2023
Posts: 3
Iron-Man 27 Feb 2023, 23:45
Thanks revolution, AsmGuru62 !!

All is working now.
Post 27 Feb 2023, 23:45
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.