donderdag 31 augustus 2023

WIN32 programming is not great.

Windows is a big operating system which is kept evergreen by windows updates. So, I would expect that the WIN32 API has a lot of strong libraries. For instance, a strong and easy to access JSON library is the least I expected. 

No. That is not available. WIN32 is only an operating system API.

It is a missed chance to say the least....

zondag 27 augustus 2023

FASM x86-64 example. Print string. Allocate memory.

format pe64 console
entry start

include 'win64a.inc'

section '.text' code readable executable
start:
  push	rbp  ; make stack 16 byte aligned. Needed for fastcall requirement.
  sub	rsp, 10*8  ; reserve stack for API use (for instance WriteFile needs 5 parameters)
  
  invoke GetStdHandle, STD_OUTPUT_HANDLE
  mov	[GetStdHandle_outputhandle], rax

  invoke GetProcessHeap
  mov	[processHeapHandle], rax

  invoke HeapAlloc, [processHeapHandle], HEAP_ZERO_MEMORY, 100*1024
  mov	[variableSpacePointer], rax

  invoke WriteFile, [GetStdHandle_outputhandle], str0, [str0Length], ResultBytesWritten, NULL
  invoke HeapFree, [processHeapHandle], 0, [variableSpacePointer]

  pop   rbp  ; 16-byte alignment lost here...
  invoke ExitProcess, 0


section '.idata' import data readable writeable
  library kernel32,'KERNEL32.DLL'
  include 'api\kernel32.inc'


section '.data' data readable writeable
processHeapHandle   dq  0
variableSpacePointer dq 0
GetStdHandle_outputhandle dq 0
ResultBytesWritten dd 0
str0 db 'Hello World!',0
str0Length dq $-str0