flat assembler
Message board for the users of flat assembler.

Index > Windows > how ot make .bin executable?

Author
Thread Post new topic Reply to topic
Stancliff



Joined: 30 Jun 2024
Posts: 54
Location: Florida
Stancliff 30 Jun 2024, 19:45
Finally started a project I stalled since college 40 years ago.
3 months at 2-4 hrs a day using flat 1.73 and now it compiles.
Now I have no idea what to do with a 24k .bin! I use Win 10
and need to convert to .exe I can run. I don't see it in flat manual
so I need clear guidance please. Is the issue in my code or windows?
RDS
Post 30 Jun 2024, 19:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 30 Jun 2024, 20:19
You can begin your code with the format directive.
Code:
format pe executable
 ; ... your code    
There are example sources in the fasm download that generate executable files.
Post 30 Jun 2024, 20:19
View user's profile Send private message Visit poster's website Reply with quote
Stancliff



Joined: 30 Jun 2024
Posts: 54
Location: Florida
Stancliff 30 Jun 2024, 21:07
My first executable line is now
format pe executable
and flat 1.73 flagged it as an error... extra characters on line
do I need a more current version?
Post 30 Jun 2024, 21:07
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20454
Location: In your JS exploiting you and your system
revolution 30 Jun 2024, 21:15
That was me confusing elf with pe. For PE you either use gui or console, the 'executable" argument is only for ELF.

Here is the pe64demo.asm that comes with fasm.
Code:
; Example of 64-bit PE program

format PE64 GUI
entry start

section '.text' code readable executable

  start:
        sub     rsp,8*5         ; reserve stack for API use and make stack dqword aligned

        mov     r9d,0
        lea     r8,[_caption]
        lea     rdx,[_message]
        mov     rcx,0
        call    [MessageBoxA]

        mov     ecx,eax
        call    [ExitProcess]

section '.data' data readable writeable

  _caption db 'Win64 assembly program',0
  _message db 'Hello World!',0

section '.idata' import data readable writeable

  dd 0,0,0,RVA kernel_name,RVA kernel_table
  dd 0,0,0,RVA user_name,RVA user_table
  dd 0,0,0,0,0

  kernel_table:
    ExitProcess dq RVA _ExitProcess
    dq 0
  user_table:
    MessageBoxA dq RVA _MessageBoxA
    dq 0

  kernel_name db 'KERNEL32.DLL',0
  user_name db 'USER32.DLL',0

  _ExitProcess dw 0
    db 'ExitProcess',0
  _MessageBoxA dw 0
    db 'MessageBoxA',0    
Post 30 Jun 2024, 21:15
View user's profile Send private message Visit poster's website Reply with quote
Stancliff



Joined: 30 Jun 2024
Posts: 54
Location: Florida
Stancliff 30 Jun 2024, 21:25
To emulate the hello program
I changed 'format pe executable'
to "include 'fasmw17332\include\win32ax.inc' "
then added .data, .code, and .end
now it gives me a .exe
I still need to make additions to see proof it is running
Post 30 Jun 2024, 21:25
View user's profile Send private message Reply with quote
MatQuasar2



Joined: 10 Jun 2024
Posts: 26
MatQuasar2 01 Jul 2024, 19:42
If you craft the PE header yourself in the program, you can use :

Code:
format binary as "exe"    


Otherwise use like what have been suggested by @revolution above.
Post 01 Jul 2024, 19:42
View user's profile Send private message Reply with quote
Stancliff



Joined: 30 Jun 2024
Posts: 54
Location: Florida
Stancliff 02 Jul 2024, 19:47
The Minipad example starts like this...
format PE GUI 4.0
entry start
include 'win32a.inc'

This is important to me SOON since I want my program to have a screen for I/O. The example confuses me since I don't know what all the stuff in .data is doing. I expect to do some searches for more details until I am more confident.

Current issue... the Hello example starts...
include 'win32ax.inc'
.code
start:

and it opens two MessageBox's like...
invoke MessageBox,HWND_DESKTOP,"Hi! I'm the example program!",\
"Hello!",MB_OK

and that works, but my program currently has...
format PE GUI
entry start
include 'win32ax.inc'
section '.data' data readable writeable

which blends both of the above examples and the MessageBox is giving
"undefined symbol 'MesssageBox'" everywhere I try to use it.
The Hello example is so simple but when moved into my code it fails.
Post 02 Jul 2024, 19:47
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1043
Location: Russia
macomics 03 Jul 2024, 03:54
Add to your code
Code:
section '.idata' import readable writeable
library kernel32,user32
include "API\kernel32.inc"
include "API\user32.inc"    
This will specify the name of the MessageBox function, which is located in the dynamically linked library USER32.DLL
Post 03 Jul 2024, 03:54
View user's profile Send private message Reply with quote
Stancliff



Joined: 30 Jun 2024
Posts: 54
Location: Florida
Stancliff 03 Jul 2024, 17:15
Thanks for that advice, but it had one error I found.
library is a macro that expects two parameters so calling two libraries made it fail.
After inspecting the includes I dropped kernel32, as currently not being used.
My current header is...
format PE GUI
entry Cold
include 'win32ax.inc'

section '.idata' import readable writeable
library user32, "User32"
include "API\USER32.INC"

section '.data' data readable writeable

The program is compiling and I have started debugging.
Post 03 Jul 2024, 17:15
View user's profile Send private message Reply with quote
Stancliff



Joined: 30 Jun 2024
Posts: 54
Location: Florida
Stancliff 06 Jul 2024, 23:51
A week later... I want my program to use a full screen text box to provide a user command line followed by the system response. Everything scrolls.
I have been studying the MiniPad example since it seems to be closest to what I need, but Windows programming confuses me quite a bit.
Judging from Win training on the net I may be needing Edit_GetLineCount and Edit_GetLine to read the user input with maybe ListBox_AddString
or something similar for the system to write to the MiniPad with.
Having said that, I can't seem to find how to import those in flat. Are there better choices and/or have I overlooked the correct sources.

If there was a gui design tool for screen layout like html or Excel building this would be much simpler, but I am not ready to do a more complicated interface at this point.
Post 06 Jul 2024, 23:51
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4075
Location: vpcmpistri
bitRAKE 07 Jul 2024, 00:37
Do you intend to add graphics in the future or will this be a text only interface? The console functions might be a better choice for the later. Assuming you'd like a windowed interface, the source code to FASMW would be a great source of guidance.

The Edit and ListBox controls use messaging to communicate with the program. Learning how to setup a message loop comes first, then creating a hierarchy of controls.
Post 07 Jul 2024, 00:37
View user's profile Send private message Visit poster's website Reply with quote
Stancliff



Joined: 30 Jun 2024
Posts: 54
Location: Florida
Stancliff 07 Jul 2024, 18:07
Text only, no pics for now. I have an idea I might want to try in a year or so, but it might be easier to interface that one with a browser and feed it html.
By console fn's you mean the ones I mentioned? Using fasmw as a guide is a very interesting idea, thanks.

MiniPad has a msg loop and a window proc, but I am not sure where my app code goes... I am thinking the main line would be ahead of getmessage in the msg loop. I have no clue what messages/flags to test for to modify the window proc if it even needs changing.
I want my code to ask for a line of input, and the system to return one when Enter is hit. Then the results of processing have to be displayed to the window on following lines that scroll up.
An alternate would by to use the upper 35 to 40 lines for system output and reserve the bottom two or three lines for input. That choice would probably need the screen to be mapped out in separate window areas. Right now I don't even know how to make my window full screen using code. I haven't found a command that does that yet.
Post 07 Jul 2024, 18:07
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1043
Location: Russia
macomics 07 Jul 2024, 18:28
When programming in assembly, you obviously need to figure out how to use WinAPI

You can start from here.
Post 07 Jul 2024, 18:28
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4075
Location: vpcmpistri
bitRAKE 07 Jul 2024, 19:46
Stancliff wrote:
I want my code to ask for a line of input, and the system to return one when Enter is hit. Then the results of processing have to be displayed to the window on following lines that scroll up.
An alternate would by to use the upper 35 to 40 lines for system output and reserve the bottom two or three lines for input. That choice would probably need the screen to be mapped out in separate window areas. Right now I don't even know how to make my window full screen using code. I haven't found a command that does that yet.
What you describe would be easiest to implement with ANSI codes in a terminal window, but this would limit the project to later versions of Windows 10. There are ANSI codes to set the scroll area - dividing the terminal into two+ regions.

If a graphical approach is what you're after, macomics has given a good place to start.

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 07 Jul 2024, 19:46
View user's profile Send private message Visit poster's website Reply with quote
Stancliff



Joined: 30 Jun 2024
Posts: 54
Location: Florida
Stancliff 09 Jul 2024, 00:25
macomics has a important point and I have been studying windows functions for a week now... just scratching the surface, but more of it makes sense.

My application is a compiler and interface for Forth. A long standing personal interest of mine. Not quite a dead language but very niche after almost forty years in the shadows. This started as a learning method for Forth and Assembly,which it has in fact been, and now I really need to add a Windows interface since no modern program will get much attention without one. This will cause a severe rewrite of my 'ver.1' which assumed the use of BIOS or DOS interrupt calls as the old systems used. Now that I can compile my code it is clear the BiOS and/or DOS calls are not effective enough for what I want so Windows it is. This is especially true since no one writes public books about directly interfacing the computer bus and video cards. All my references are thirty to forty years old and have no concept of graphics beyond 600x400 resolution. There may well be a separate book on the subject for each video card, for a sufficient price, but you never hear about them.

I do appreciate your looking at my ramblings. Learning Windows is like wading through a swamp... I will probably get through it... eventually.
Post 09 Jul 2024, 00:25
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.