Programming
FASM: Create Process
by admin 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.