beta.blog

Programming

FASM: Create Process

by on Jan.21, 2011, under Programming

The example code below will create and start a new process. In order to execute another program via assembler code, you have to import the corresponding API functions. As I’m using Windows 7 at the moment, I’m going to use the Win32 API. (Well, I have a 64-bit OS, but it doesn’t matter anyway). Creating/starting a process in flat assembler is actually a piece of cake.

Here’s my FASM code:

format PE GUI 4.0
entry start

include 'win32a.inc'

start:
 invoke CreateProcessA,txt_location,0,0,0,0,CREATE_NEW_CONSOLE,0,0,StartupInfo,ProcessInfo
 call [ExitProcess]

; Custom Data: Contains the location of notepad.exe, StartupInfo and ProcessInfo:
section '.data' data readable writeable
 txt_location db 'C:\Windows\System32\notepad.exe',0
 StartupInfo STARTUPINFO
 ProcessInfo PROCESS_INFORMATION

; Imported functions and corresponding names of DLL files:
section '.idata' import data readable writeable
 library kernel,'KERNEL32.DLL'

 import kernel,\
 CreateProcessA, "CreateProcessA",\
 ExitProcess,'ExitProcess'

My sample application will start notepad.exe and terminate itself after doing so.
I recommend viewing this code in FASMW to get proper code highlighting, simply copy/paste it.

3 Comments more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!