Appending extra data to Files

Share your advanced PureBasic knowledge/code with the community.
wayne-c
Enthusiast
Enthusiast
Posts: 337
Joined: Tue Jun 08, 2004 10:29 am
Location: Zurich, Switzerland

Appending extra data to Files

Post by wayne-c »

Code updated for 5.20+

Requires NTFS 5 File-System (Windows 2000 and later).

Code: Select all

;
;
; ---Important:
; This example requires NTFS 5 Filesystem (Windows 2000 and later)
;

;
; Create test file (12 bytes)
;
If CreateFile(1, "Test.txt")
  WriteString(1, "Hello World!", #PB_Ascii)
  CloseFile(1)
  Debug FileSize("Test.txt")
EndIf

;
; Append some extra information to the file
; The data is written to a "stream".
; You can have multiple streams with different names for every file.
; Just add the name of your stream after the colon.
;
If OpenFile(1, "Test.txt:ExtraData")
  WriteString(1, "Hello Extra Data!")
  CloseFile(1)
EndIf

;
; The file size is STILL 12 bytes, but the extra data is there...
;
Debug FileSize("Test.txt")

;
; ...so read the extra data from the file:
;
If ReadFile(1, "Test.txt:ExtraData")
  Debug ReadString(1, #PB_Ascii)
  CloseFile(1)
EndIf

;
; Remove the additional data from the file.
;
DeleteFile_("Test.txt:ExtraData")
As you walk on by, Will you call my name? Or will you walk away?
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Very interesting.

Where is this data stored?
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

ricardo wrote:Very interesting.

Where is this data stored?
Hidden Threat: Alternate Data Streams
http://www.windowsecurity.com/articles/ ... reams.html

Windows NTFS Alternate Data Streams
http://www.securityfocus.com/infocus/1822

Best regards
Henrik
Num3
PureBasic Expert
PureBasic Expert
Posts: 2812
Joined: Fri Apr 25, 2003 4:51 pm
Location: Portugal, Lisbon
Contact:

Post by Num3 »

Darn... Now you know :oops:

Welcome to one of windows biggest black holes :twisted:

That's why i still use FAT32 in my data and OS partitions ;)
Henrik
Enthusiast
Enthusiast
Posts: 404
Joined: Sat Apr 26, 2003 5:08 pm
Location: Denmark

Post by Henrik »

Num3 wrote: That's why i still use FAT32 in my data and OS partitions ;)
Me too :D

Well btw. you can use this littel commandline tool to list-ADS on your NTFS partitions.

http://www.heysoft.de/Frames/f_sw_la_en.htm

Best regrads
Henrik
ricardo
Addict
Addict
Posts: 2438
Joined: Fri Apr 25, 2003 7:06 pm
Location: Argentina

Post by ricardo »

Well, this could have some interesting uses, like use this feature to protect more your apps.
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

Henrik wrote:
ricardo wrote:Very interesting.

Where is this data stored?
Hidden Threat: Alternate Data Streams
http://www.windowsecurity.com/articles/ ... reams.html

Windows NTFS Alternate Data Streams
http://www.securityfocus.com/infocus/1822

Best regards
Henrik
no threat for Vista
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Post by Psychophanta »

Num3 wrote:That's why i still use FAT32 in my data and OS partitions ;)
1UP :wink:
Same here.
hehe, I have had several bad experiences with NTFS 5.
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
PB
PureBasic Expert
PureBasic Expert
Posts: 7581
Joined: Fri Apr 25, 2003 5:24 pm

Post by PB »

> That's why i still use FAT32 in my data and OS partitions

So how do you handle files larger than 4 GB (ISOs, DVDs, etc)?
I'd find it very inconvenient to be limited to 4 GB file sizes, not
to mention the lack of security too.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
Post Reply