Вопрос

I'm reading a file's content into a buffer using

System::Alloc $Size
pop $Buffer
System::Call "Kernel32::ReadFile(i r0, i $Buffer, i $Size, t.,)"

But I can't figure out how to read from (or write into) $Buffer.

Is there a way do to so (preferably natively, but any suggestion would be appreciated).

Thanks

P.S.
I know about System::Copy but it only lets you write into a buffer and only from another buffer
(trying System::Copy 1 $Buffer "A" crashes the executable)

Это было полезно?

Решение

The built-in NSIS functions FileRead/FileReadUTF16LE and FileReadByte can be used to read text and bytes but you can also call Windows functions directly. To read from a memory buffer you have to use the system struct syntax:

Section
InitPluginsDir
FileOpen $0 "$pluginsdir\test.txt" a

DetailPrint "NSIS:"
FileWrite $0 "Foo"
FileSeek $0 0 SET
FileRead $0 $1
DetailPrint |$1|


DetailPrint "System::Call:"
System::Alloc 100
Pop $1
System::Call '*$1(&m3 "Bar")' ; Write ASCII text into buffer using struct syntax
System::Call 'kernel32::WriteFile(i$0,i$1,i3,*i.r2,i0)i.r9'
DetailPrint "Write: OK=$9 ($2 bytes)"
System::Free $1
System::Call '*(&i100)i.r1' ; Alloc a 100 byte buffer using struct syntax
FileSeek $0 0 SET
System::Call 'kernel32::ReadFile(i$0,i$1,i6,*i.r2,i0)i.r9'
DetailPrint "Read: OK=$9 ($2 bytes)"
System::Call '*$1(&m${NSIS_MAX_STRLEN}.r2)' ; Read ASCII text into variable using struct syntax
System::Free $1
DetailPrint |$2|

FileClose $0
SectionEnd
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top