There may be a more elegant way than how I do it, but here's a working example:
Outfile BufferStuffer.exe
Var Buffer
Var DataSize
!macro FillBuffer Data # Hex string expected for Data
StrLen $DataSize ${Data}
IntOp $DataSize $DataSize / 2
System::Alloc $DataSize
Pop $Buffer
StrCpy $9 0
IntOp $0 $9 * 2
StrCpy $0 ${Data} 2 $0
System::Call "*$Buffer(&v$9, &i1 '0x$0')"
IntOp $9 $9 + 1
IntCmp $9 $DataSize 0 -4
!macroend
!define FillBuffer "!insertmacro FillBuffer"
Function .onInit
${FillBuffer} "497420776F726B7321"
FileOpen $R0 "$EXEDIR\doesitwork.txt" w
System::Call "kernel32::WriteFile(i R0, i $Buffer, i $DataSize, *i.r1, i '') i.r0"
FileClose $R0
System::Free $Buffer
IntCmp $0 0 +2
IntCmp $1 $Datasize +2
MessageBox MB_OK|MB_ICONSTOP "Error writing file."
Abort
FunctionEnd
Section Blank
SectionEnd