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.
March 23rd, 2011 on 02:10
Spunto veramente interessante…
September 15th, 2011 on 12:27
Neato…
Addressing the more common programming problems and interfaces bridging the gap between Assembler and HLL as an obvious means to educate.
Nice choice — external tools from inside an existing environment — “use editor of choice” button implementation is a breath away.
April 27th, 2021 on 05:53
Is there a way to set affinity during process creating, or should I do it after the creation took place?