It is currently Sun May 19, 2013 12:24 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Read/write ADS to file?
PostPosted: Mon Jul 02, 2012 3:57 am 
Offline
Addict
Addict
User avatar

Joined: Wed Feb 17, 2010 12:00 am
Posts: 972
Location: Anderson Island, WA
I have a need to (primarily) read alternate data streams of file(s)...
I found a couple of examples, but nothing worked.
Has anyone done any work with ADS that they'd be willing to share?


Top
 Profile  
 
 Post subject: Re: Read/write ADS to file?
PostPosted: Fri Jul 13, 2012 9:14 pm 
Offline
Enthusiast
Enthusiast

Joined: Sun Jan 11, 2004 11:34 am
Posts: 233
Location: France
I have this code, sorry comment in french:


Code:
;----------------
; PureBasic 4.50
;----------------
;-----------------------------------------------------------------------------------------------------------------------
; Lecture, écriture et extraction d'un Alternate Data Stream (ADS); en Français (flux de données additionnels)
; Info sur les ADS --> http://www.paperblog.fr/2964348/le-danger-des-flux-additionnels-ads-alternate-data-stream/
; Fonctionne sur le système de Fichier NTFS 2000, NT, XP, Vista, Window 7
;-----------------------------------------------------------------------------------------------------------------------
; ----------------------------------------------------------------------------------------------------------------------------------
; Ce code vous permet d'associer un fichier (On dira un Stream) à un autre fichier ou un répertoire
; Le Stream que vous aurez associé au fichier ne sera pas visible dans l'explorateur de Window
; Seul la date de modification du fichier changera mais pas sa taille
; L'utilisateur Lambda ne sera jamais qu'il a certains fichiers cachés dans son système
; C'est un bon moyen de sauvegarder des données sensibles et les cachées, car impossible de les supprimer,
; sans effacer le fichier principal ou le répertoire
; Il faut en effet des outils spécifiques pour scanner et ainsi voir tous ces fichiers cachés
; j'en ai essayer certains comme ADS Spy ou hijackthis qui fonctionne très bien
; ----------------------------------------------------------------------------------------------------------------------------------


; Récupère l'adresse d'un dossier spécifique de Windows
Procedure.s GetSpecialFolderLocation(Valeur.l)
  Protected SpecialFolderLocation.s, Dossier_ID.l
  If SHGetSpecialFolderLocation_(0, Valeur, @Dossier_ID) = 0
    SpecialFolderLocation = Space(#MAX_PATH)
    SHGetPathFromIDList_(Dossier_ID, @SpecialFolderLocation)
    If SpecialFolderLocation
      If Right(SpecialFolderLocation, 1) <> "\"
        SpecialFolderLocation + "\"
      EndIf
    EndIf
  EndIf
  ProcedureReturn SpecialFolderLocation
EndProcedure


Procedure CreateStream(Chemin_ou_CheminFichier.s, NomdeFichier.s, *Buffer.i, longueur.l)
  Protected Res.l
 
  If CreateFile(0, Chemin_ou_CheminFichier+":"+NomdeFichier)
    WriteData(0, *Buffer,longueur)
    CloseFile(0)
    Res=1
  EndIf
 
  ProcedureReturn Res
EndProcedure


Procedure ExtractStream(Chemin_ou_CheminFichier.s, NomdeFichier.s, Destination.s)
  Protected Longueur.l, *Buffer.i, Res.l
 
  If ReadFile(0, Chemin_ou_CheminFichier+":"+NomdeFichier)
    Longueur=Lof(0)
    *Buffer=AllocateMemory(Longueur)
    ReadData(0, *Buffer,longueur)
    CloseFile(0)
   
    If CreateFile(0, Destination)
      WriteData(0, *Buffer,longueur)
      CloseFile(0)
      Res=1
    EndIf
   
    FreeMemory(*Buffer)
  EndIf
 
  ProcedureReturn Res
EndProcedure


Procedure.l DeleteStream(Chemin_ou_CheminFichier.s, NomdeFichier.s)
  Protected Res.l
 
  Res=DeleteFile(Chemin_ou_CheminFichier+":"+NomdeFichier)
 
  ProcedureReturn Res
EndProcedure

; --------------------------------------------------------------------
; Création d'un Fichier nommé Test.txt sur le bureau
; On écrira le texte :PureBasic
CheminBureau.s=GetSpecialFolderLocation(#CSIDL_DESKTOPDIRECTORY)
CheminFichier.s=CheminBureau+"Test.txt"
If CreateFile(0,CheminFichier)
  WriteString(0,"PureBasic")
  CloseFile(0)
EndIf
; --------------------------------------------------------------------

; --------------------------------------------------------------------
; Création d'un ADS "Fred.txt" associé au fichier "Test.txt"
Texte.s="Fred, le créateur de PureBasic"
CreateStream(CheminFichier,"Fred.txt",@Texte,Len(Texte))
; --------------------------------------------------------------------

; --------------------------------------------------------------------
; Extraction de l' ADS "Fred.txt" associé au Fichier "Test.txt"
;ExtractStream(CheminFichier,"Fred.txt", CheminBureau+"Extract.txt")
; --------------------------------------------------------------------

; --------------------------------------------------------------------
; Supression de l'ADS
;DeleteStream(CheminFichier,"Fred.txt")
; --------------------------------------------------------------------


Top
 Profile  
 
 Post subject: Re: Read/write ADS to file?
PostPosted: Sat Jul 14, 2012 2:07 am 
Offline
Addict
Addict
User avatar

Joined: Wed Feb 17, 2010 12:00 am
Posts: 972
Location: Anderson Island, WA
Thank you! Will check it out..
-josh


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye