Stevie
(Starting to like KiXtart)
2003-07-19 09:13 PM
kix and i/o streams

Has there been any previous suggestion (I've already looked and can't find any...which doesn't mean it doesn't exist) regarding kix and i/o streams.

Specifically, modifying kix so that it will accept either a file or a generic i/o stream. If it's able to accept a stream, then it would be trivial to provide custom encryption/obfuscation/protection for scripts.


Sealeopard
(KiX Master)
2003-07-19 09:43 PM
Re: kix and i/o streams

Yes, see for example Suggestion: Binary file operations

Howard Bullock
(KiX Supporter)
2003-07-19 09:43 PM
Re: kix and i/o streams

Notepad and KiXtart can create and access NTFS streams. Notepad must do it from the commandline.

Create a file with notepad.exe called "test.txt". add some text and save.

Then use the line below to create a stream. Add some text and save.

Check your directory there will be only test.txt. Reopen the file and the stream with notepad to verify their existence.
code:
notepad test.txt:stream1.txt  

Now run this code with KiXtart.

KiXtart 4.02 can read streams.
code:
IF Open(3, "c:\data\scripts\test.txt:stream1.txt") = 0
$x = ReadLine(3)
WHILE @ERROR = 0
? "Line read: [" + $x + "]"
$x = ReadLine(3)
LOOP
ENDIF



[ 19. July 2003, 22:18: Message edited by: Howard Bullock ]


Howard Bullock
(KiX Supporter)
2003-07-19 09:49 PM
Re: kix and i/o streams

Kixtart creating, writing, and reading an NTFS stream.

IF Open(3, "c:\data\scripts\test.txt:stream1.txt") = 0
$x = ReadLine(3)
WHILE @ERROR = 0
? "Line read: [" + $x + "]"
$x = ReadLine(3)
LOOP
ENDIF
$rc=close (3)
?
IF Open(5, "c:\data\scripts\test.txt:stream5.txt",5) = 0
WriteLine(5, "This is stream5"+@CRLF)
else
? "Failed to open stream"
ENDIF
$rc=close (5)
IF Open(3, "c:\data\scripts\test.txt:stream5.txt") = 0
$x = ReadLine(3)
WHILE @ERROR = 0
? "Line read: [" + $x + "]"
$x = ReadLine(3)
LOOP
ENDIF
$rc=close (3)


KiXtart is not required to have the ".txt" as part of the stream name, but if you want to verify the stream with notepad.exe you will have to include the ".txt".

[ 19. July 2003, 22:19: Message edited by: Howard Bullock ]


Howard Bullock
(KiX Supporter)
2003-07-20 01:35 AM
Re: kix and i/o streams

More info about using streams.

quote:
Note that files with single-character names cannot contain alternate streams because these file names are treated by Windows as drive letters. When a drive letter is specified with a relative path, a colon separates the drive letter from the path. When there is an ambiguity about whether a single-character name is a drive letter or a file name, Windows will assume a drive letter if the string following the colon is a valid path, and a file name otherwise. This will occur regardless of whether the drive letter or file name is valid.




Richard H.Administrator
(KiX Supporter)
2003-07-22 10:58 AM
Re: kix and i/o streams

Ok, for anyone else (like me) who saw this and got interested - NTFS streams are not the answer.

When Stevie is asking about reading from IO streams, what he is specifically referring to is what in the *nix world would be stdin. This is normally attached to keyboard input but can be attched to the output of another program where the operating system supports pipes.

NTFS streams are not IO streams as most people understand them They are simply named file sections. You cannot use them to communicate between processes, or "pipe" information.

Note, KiXtart can read piped input using GetS, but it is kludgy and there is no way to reconnect input back to the keyboard.

Some ways of achieving this:
  • Support for named pipes would be interesting, however these are not fully supported under Win9x.
  • Anonymous pipes are another option. These are supported by (later) versions of Win9x, but passing the handle may be tricky.
  • KiXtart could read the script from stdin, and when the stream terminates reconnect stdin to the keyboard.
  • The decrypting program could pass the script directly to KiXtart via COM automation.


Stevie
(Starting to like KiXtart)
2003-07-23 08:21 PM
Re: kix and i/o streams

quote:
KiXtart could read the script from stdin, and when the stream terminates reconnect stdin to the keyboard.
That sounds most appealing to me. It's also the most straightforward.

Before I get all carried away, is this even something Ruud would consider adding?


Howard Bullock
(KiX Supporter)
2003-07-23 08:47 PM
Re: kix and i/o streams

Forgive for being thick. what would be the application for:
quote:
KiXtart could read the script from stdin, and when the stream terminates reconnect stdin to the keyboard.


Stevie
(Starting to like KiXtart)
2003-07-23 10:55 PM
Re: kix and i/o streams

The bottom line on this is that it would allow you to send a script to kix32 without that script needing to be a file.

A possible usage of this would be to have an encrypted script file decrypted by some external process (kixcrypt perhaps??) and then sent directly to kix without having to create an unencrypted version of the file.

It would make script encryption/obfuscation even more secure.

Another possible use would be to dynamically create a script and spawn it via a second instance of kix without writing it out to a file first.