Archive: How to work with ntfs streams


How to work with ntfs streams
  Hello everyone. Can you help me with NTFS-streams in NSIS, please? I can't understand how to write something in the stream.

!macro CreateNtfsStream sHandle sPath sName

System::Call 'Kernel32::CreateFile(t, i, i, i, i, i, i) i ("${sPath}:${sName}", 0xC0000000, 7, 0, 2, 0x80, 0) .s'
Pop ${sHandle}
!macroend
>!define CreateNtfsStream "!insertmacro CreateNtfsStream"

>!macro WriteNtfsStream sHandle sPath sName sText
...
!macroend
>!define WriteNtfsStream "!insertmacro WriteNtfsStream"

>!macro DeleteNtfsStream sHandle sPath sName
Push '${sPath}:${sName}'
System::Call 'Kernel32::DeleteFile((t) i (s)) .s'
Pop ${sHandle}
!macroend
>!define DeleteNtfsStream "!insertmacro DeleteNtfsStream"

Once you have a handle you can just write to it with WriteFile, you probably don't even need the system plugin to open or delete, just use the normal instructions.

That syntax for delete looks wrong, it is Kernel32::DeleteFile(t)i AKA Kernel32::DeleteFile(ts)i.s and it returns != 0 on success, not a handle...


Thanks for the reply.

Originally posted by Anders
you can just write to it with WriteFile
I tried, but i'm newbie in NSIS coding, and i cant write correct code syntax. That's why I ask for help.

Originally posted by Anders
Kernel32::DeleteFile(ts)i.s and it returns != 0 on success, not a handle...
It's just a variable name, but I'll keep that in my mind ;)

Originally posted by Nothuman
I tried, but i'm newbie in NSIS coding, and i cant write correct code syntax. That's why I ask for help.
The manual has code examples for most commands:
http://nsis.sourceforge.net/Docs/Chapter4.html#4.9.5.8

MSG, i will tried use FileWrite function. She is not able to record the stream.


MSG, thanks for reminding me about that. I tried again, but differently way:

!macro WriteNtfsStream sOutput sPath sName sValue

System::Call 'Kernel32::CreateFile(t, i, i, i, i, i, i) i ("${sPath}:${sName}", 0xC0000000, 7, 0, 2, 0x80, 0)i.s'
Pop $1
ClearErrors
FileWrite$1 '${sValue}'
IfErrors +1 +3
StrCpy${sOutput} 0
Goto+2
StrCpy${sOutput} 1
Pop${sOutput}
System::Call 'kernel32::CloseHandle(i $1)'
>!macroend
>!define WriteNtfsStream '!insertmacro WriteNtfsStream'
This is work fine, but one problem is left. Characters such as ض recorded as ?. Any ideas? I'm using NSIS 2.46 (Unicode).

Originally posted by Nothuman
This is work fine, but one problem is left. Characters such as ض recorded as ? .
It is converted to a narrow string using the active codepage (Machine specific). If you want to write UTF16LE the fork should have a function to write out UCS2 characters at least, going outside the BMP is probably not supported. Writing UTF8 cannot be done without calling kernel32::WideCharToMultiByte and then calling kernel32::WriteFile...