flat assembler
Message board for the users of flat assembler.

flat assembler > Windows > Creating a batch file using FASM?

Author
Thread Post new topic Reply to topic
Archvile



Joined: 03 Dec 2018
Posts: 3
Location: Uruguay
Greetings board. I am not a senior Programmer at all. I've done some C#, JS, C and Pascal before, and I'm trying to get into Assembler. I've always been interested in this particular language, and it's really hard to find someone IRL who is willing to give you a crash course through this ancient language.

Anyhow, I am trying to do something that requires creating a batch files through FASM, with parameters and all that and then executing that file through another program. My question is, how do I do that first part? I am still trying to learn the ropes and I'd really appreciate if someone either showed me what I need to do, or if that is not possible, what are the limitations of FASM.

Thank you very much in advance!

_________________
Mind over matter.
Post 03 Dec 2018, 00:48
View user's profile Send private message Reply with quote
ssjcoder



Joined: 20 Nov 2018
Posts: 6
Do you mean like a ".bat"/".cmd" file?

Because if that's what you mean, you can probably use some kind of file-writing command to write to a text file & put all the commands into the file, and give it the ".bat"/".cmd" extension

I could give you a basic example (for windows 7 32-bit) if this is the case (should work on win 10 too)
Post 03 Dec 2018, 17:48
View user's profile Send private message Reply with quote
Archvile



Joined: 03 Dec 2018
Posts: 3
Location: Uruguay
ssjcoder wrote:
Do you mean like a ".bat"/".cmd" file?

Because if that's what you mean, you can probably use some kind of file-writing command to write to a text file & put all the commands into the file, and give it the ".bat"/".cmd" extension

I could give you a basic example (for windows 7 32-bit) if this is the case (should work on win 10 too)


Yes, that is exactly what I was thinking about! I would love to read your example if you could give me some quick insight on the syntaxis you will use.

Also, what are some big/important differences between Windows 7 32-bit and 64-bit for assembler?

_________________
Mind over matter.
Post 04 Dec 2018, 01:10
View user's profile Send private message Reply with quote
ssjcoder



Joined: 20 Nov 2018
Posts: 6
Code:
;***;  Format  ;***;
format PE console
entry  _main


;***;  Includes  ;***;
include 'import32.inc'


;***;  Data  ;***;
section 'data' data readable writeable
Path  db 'out.cmd', 0
Cmmd1 db '<first command>', 0
Cmmd2 db '<second command>', 0
_endl db 0xD, 0xA, 0

_bwr       dd 0
FileHandle dd 0


;***;  Code  ;***;
section 'code' code readable executable
_main:
        ; clear file
        push Path
        call [W32_FileDelete]
        
        ; open file
        push 0
        push 0x80
        push 1
        push 0
        push 0
        push 0x40000000
        push Path
        call [W32_FileOpen]
        mov  [FileHandle], eax
        
        ; reset 'bytes written'
        mov dword [_bwr], 0
        
        ; write first command
        push 0
        push _bwr
        push 15 ; write size
        push Cmmd1
        push [FileHandle]
        call [W32_FileWrite]
        
        ; reset 'bytes written'
        mov dword [_bwr], 0
        
        ; write end of the line
        push 0
        push _bwr
        push 2 ; write size
        push _endl
        push [FileHandle]
        call [W32_FileWrite]
        
        ; reset 'bytes written'
        mov dword [_bwr], 0
        
        ; write second command
        push 0
        push _bwr
        push 16 ; write size
        push Cmmd2
        push [FileHandle]
        call [W32_FileWrite]
        
        ; close file
        push [FileHandle]
        call [W32_FileClose]
        
        ; close
        .quit:
        push 0
        call [CS_Close]



;***;  Import  ;***;
section 'impr' import data readable writeable

library\
L_msvcrt, 'msvcrt.dll',\
L_kernel32, 'kernel32.dll'

import L_msvcrt,\
CS_System, 'system',\
CS_Close,  'exit'

import L_kernel32,\
W32_FileWrite,  'WriteFile',\
W32_FileClose,  'CloseHandle',\
W32_FileOpen,   'CreateFileA',\
W32_FileDelete, 'DeleteFileA'    


The program above will create a file called 'out.cmd' and write two commands (well they're not really commands in this case), <first command> and <second command>.

However this program is very specifically written such that if you change the commands you have to also change the "write size" of every write call in order to write the correct number of characters, and uses the Windows API (https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/) to perform file writing calls.

---

A major difference between 32-bit and 64-bit is that 32-bit uses 32-bit wide memory operations, 64-bit uses 64.

Also, 64-bit computers can run 32-bit programs, but 32-bit computers can't run 64-bit programs, so you should release both instead of just 64-bit if you want to maximize compatibility.

Due to being unfamiliar with programming in 64-bit mode I can't tell you much else on that matter.

---

I'm making a video to introduce assembly to people who are new and have no idea how assembly works, will post it here once I upload it to youtube (hopefully it will help clear things up for you)
Post 05 Dec 2018, 01:55
View user's profile Send private message Reply with quote
ssjcoder



Joined: 20 Nov 2018
Posts: 6
Post 05 Dec 2018, 02:32
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 570
Location: Belarus
ssjcoder wrote:
Also, 64-bit computers can run 32-bit programs, but 32-bit computers can't run 64-bit programs, so you should release both instead of just 64-bit if you want to maximize compatibility.

Or you can stick with 32-bit programs for the next 10 years unless you require some very specific 64-bit feature ’cause users don’t care whether it is 32- or 64-bit and 32-bit programs, theoretically, run everywhere from Windows 95 till Windows 10 v1809. Besides, if you write assembly code the calling conventions are more assembly programmer friendly with 32 bits.
Post 05 Dec 2018, 05:53
View user's profile Send private message Visit poster's website Reply with quote
Archvile



Joined: 03 Dec 2018
Posts: 3
Location: Uruguay
ssjcoder wrote:
Code:
;***;  Format  ;***;
format PE console
entry  _main


;***;  Includes  ;***;
include 'import32.inc'


;***;  Data  ;***;
section 'data' data readable writeable
Path  db 'out.cmd', 0
Cmmd1 db '<first command>', 0
Cmmd2 db '<second command>', 0
_endl db 0xD, 0xA, 0

_bwr       dd 0
FileHandle dd 0


;***;  Code  ;***;
section 'code' code readable executable
_main:
        ; clear file
        push Path
        call [W32_FileDelete]
        
        ; open file
        push 0
        push 0x80
        push 1
        push 0
        push 0
        push 0x40000000
        push Path
        call [W32_FileOpen]
        mov  [FileHandle], eax
        
        ; reset 'bytes written'
        mov dword [_bwr], 0
        
        ; write first command
        push 0
        push _bwr
        push 15 ; write size
        push Cmmd1
        push [FileHandle]
        call [W32_FileWrite]
        
        ; reset 'bytes written'
        mov dword [_bwr], 0
        
        ; write end of the line
        push 0
        push _bwr
        push 2 ; write size
        push _endl
        push [FileHandle]
        call [W32_FileWrite]
        
        ; reset 'bytes written'
        mov dword [_bwr], 0
        
        ; write second command
        push 0
        push _bwr
        push 16 ; write size
        push Cmmd2
        push [FileHandle]
        call [W32_FileWrite]
        
        ; close file
        push [FileHandle]
        call [W32_FileClose]
        
        ; close
        .quit:
        push 0
        call [CS_Close]



;***;  Import  ;***;
section 'impr' import data readable writeable

library\
L_msvcrt, 'msvcrt.dll',\
L_kernel32, 'kernel32.dll'

import L_msvcrt,\
CS_System, 'system',\
CS_Close,  'exit'

import L_kernel32,\
W32_FileWrite,  'WriteFile',\
W32_FileClose,  'CloseHandle',\
W32_FileOpen,   'CreateFileA',\
W32_FileDelete, 'DeleteFileA'    


The program above will create a file called 'out.cmd' and write two commands (well they're not really commands in this case), <first command> and <second command>.

However this program is very specifically written such that if you change the commands you have to also change the "write size" of every write call in order to write the correct number of characters, and uses the Windows API (https://docs.microsoft.com/en-us/windows/desktop/api/fileapi/) to perform file writing calls.

---

A major difference between 32-bit and 64-bit is that 32-bit uses 32-bit wide memory operations, 64-bit uses 64.

Also, 64-bit computers can run 32-bit programs, but 32-bit computers can't run 64-bit programs, so you should release both instead of just 64-bit if you want to maximize compatibility.

Due to being unfamiliar with programming in 64-bit mode I can't tell you much else on that matter.

---

I'm making a video to introduce assembly to people who are new and have no idea how assembly works, will post it here once I upload it to youtube (hopefully it will help clear things up for you)

ssjcoder wrote:
Here's the video:

https://youtu.be/iQhAjTxbcNc


Thank you very much for that explanation. Very insightful and useful for me. I'll make sure to look into the code and make the best of it, perhaprs rewrite it a little so it can suit my purposes. I will take a look at that video as soon as I can. I repeat, thank you very much!

DimonSoft wrote:

Or you can stick with 32-bit programs for the next 10 years unless you require some very specific 64-bit feature ’cause users don’t care whether it is 32- or 64-bit and 32-bit programs, theoretically, run everywhere from Windows 95 till Windows 10 v1809. Besides, if you write assembly code the calling conventions are more assembly programmer friendly with 32 bits.


I didn't know that. Thanks for letting me know.

_________________
Mind over matter.
Post 06 Dec 2018, 21:40
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-2019, Tomasz Grysztar.

Powered by rwasa.