Arquivos - salvando um texto oculto num txt no NTFS

Top  Previous  Next

// APENAS para NTFS

// como salvar e ler um texto oculto de um txt

procedure TForm1.Button1Click(Sender: TObject);

begin

  Memo1.Lines.SaveToFile('c:\Junior.txt:senha');

end;

 

procedure TForm1.Button2Click(Sender: TObject);

begin

  Memo1.Lines.LoadFromFile('c:\Junior.txt:senha');

end;

 

// função que lista todos as chaves ocultas de um 

// somente para NTFS 

 

procedure GetFileADSNames(const AFileName: string; AList: TStrings);

var

  hHandle         : THandle;

  sName           : string;

  iNumRead,iLo,iHi: DWORD;

  pCtx            : pointer;

  pBuffer,pBytePtr: PByte;

  pWsi            : PWin32StreamID absolute pBuffer;

  wszStreamName   : array[0..MAX_PATH] of widechar;

begin

  AList.BeginUpdate;

  AList.Clear;

  GetMem(pBuffer,4096);

  pCtx := nil;

  hHandle := CreateFile(PChar(AFileName),GENERIC_READ,0,nil,OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS,0);

 

  if (hHandle <> INVALID_HANDLE_VALUE) then

  begin

    while true do

    begin

      // We are at the start of a stream header. read it.

      pBytePtr := pBuffer;

      if BackupRead(hHandle,pBytePtr,20,iNumRead, false,true,pCtx) then

      begin

        if iNumRead = 0 then

          break

        else

        begin

          // Can we get a stream name ?

          sName := '';

 

          if pWsi.dwStreamNameSize > 0 then

          begin

            FillChar(wszStreamName,SizeOf(wszStreamName),0);

 

            if BackupRead(hHandle,@(wszStreamName[0]),pWsi.dwStreamNameSize, iNumRead,false,true,pCtx) then

            begin

              if iNumRead <> pWsi.dwStreamNameSize then

                break

              else

              begin

                // Yep, have a name, convert from WideChar

                sName := WideCharToString(wszStreamName);

                // Clean up Name

                if sName <> '' then

                begin

                  sName := copy(sName,2,length(sName));

                  sName := ':' + copy(sName,1,pos(':',sName) - 1);

                end;

 

                AList.AddObject(AFileName + sName,TObject(pWsi.Size));

              end;

            end

            else

              break;

          end;

 

          // Skip to start of next stream data

          if pWsi.Size > 0 then

            BackupSeek(hHandle,high(DWORD),high(DWORD),iLo,iHi,@pCtx);

        end;

      end

      else

        break;

    end;

 

    // Release the context

    BackupRead(hHandle,pBuffer,0,iNumRead,true,false,pCtx);

    CloseHandle(hHandle);

  end;

 

  FreeMem(pBuffer);

  AList.EndUpdate;

end;

 

procedure ListarTodosAsPalavrasChavesdeJunior

begin

  GetFileADSNames('c:\Junior.txt',Memo1.Lines);

end;