EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Saving UserContext data

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#12852
Posted: 03/25/2010 01:12:58
by cristiano moraes (Standard support level)
Joined: 03/23/2010
Posts: 5

How Can I save the deleted file ?

I saw that we can not make any file operation when OnCanFileBeDeletedC is fired, that is ok.
So, if I understood, I need to get the data of UserContext variable and later save this data to a file (like a backup).
How Can I do that ? I need to convert this data to a stream or string, then write to a file ?
First, I am trying to read this data, to see in a text box or list box.
I got a small txt file to test, when I delete this file I get an error (Handle is not initialized) and when a WATCH the UserContext it is equal zero.
I tried using the VB.NET code below, the events are working normally.





Imports CbFlt
Imports System
Imports System.IO
Imports System.Threading
Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Security.Permissions
Public Class Form1

Public Delegate Sub CbFltOpenFileEventN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal DesiredAccess As UInt32, ByVal FileAttributes As UInt16, ByVal ShareMode As UInt16, ByVal Options As UInt32, ByVal CreateDisposition As UInt16)
Public Delegate Sub CbFltSetAllocationSizeEventN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal AllocationSize As Long)
Public Delegate Sub CbFltSetEndOfFileEventN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal EndOfFile As Long)
'Public Delegate Sub CbFltSetFileAttributesEventN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal CreationTime As DateTime, ByVal LastAccessTime As DateTime, ByVal LastWriteTime As DateTime, ByVal FileAttributes As Int32)
Public Delegate Sub CbFltCanFileBeDeletedEventN(ByVal Sender As CallbackFilter, ByVal FileName As String)
Public Delegate Sub CbFltRenameOrMoveFileEventN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal NewFileName As String)
Public Delegate Sub CbFltReadFileEventN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal Position As Long, ByVal BytesToRead As Int32)
'Public Delegate Sub CbFltWriteFileEventN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal Position As Long, ByVal BytesToWrite As Int32, ByRref UserContext As IntPtr)
Public Delegate Sub CbFltEnumerateDirectoryN(ByVal Sender As CallbackFilter, ByVal DirectoryName As String, ByVal FileName As String, ByVal CreationTime As DateTime, ByVal LastAccessTime As DateTime, ByVal LastWriteTime As DateTime, ByVal EndOfFile As Long, ByVal AllocationSize As Long, ByVal FileId As Long, ByVal FileAttributes As UInt32)
Public Delegate Sub CbFltCloseFileEventN(ByVal Sender As CallbackFilter, ByVal FileName As String)
'Public Delegate Sub CbFltSetFileSecurityEventN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal uint SecurityInformation, ByVal IntPtr SecurityDescriptor, ByVal Length As UInt32)
Delegate Sub CbFltCanFileBeDeletedEventC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByRef DeleteFile As Boolean, ByRef UserContext As IntPtr, ByRef ProcessRequest As Boolean)
Delegate Sub CbFltRenameOrMoveFileEventC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal NewFileName As String, ByRef UserContext As IntPtr, ByRef ProcessRequest As Boolean)

Private mFilter As New CallbackFilter
Dim tw As TextWriter = System.Console.Out
Dim gch As GCHandle = GCHandle.Alloc(tw)

Private Const mProductName = "18189531-48ED-43fc-8582-E8BD2F9AB533"
Private Const keySerial = "8782...8933"
Private Sub SUB_CbFltOpenFileN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal DesiredAccess As UInt32, ByVal FileAttributes As UInt16, ByVal ShareMode As UInt16, ByVal Options As UInt32, ByVal CreateDisposition As UInt16)
AddToLog("Open =>" & "File name = " & FileName)
End Sub
Private Sub SUB_CbFltSetAllocationSizeN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal AllocationSize As Long)
AddToLog("SetAllocationSize =>" & "File name = " & FileName)
End Sub
Private Sub SUB_CbFltSetEndOfFileN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal EndOfFile As Long)
AddToLog("SetEndOfFile =>" & "File name = " & FileName)
End Sub
' Private Sub SUB_CbFltSetFileAttributesN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal CreationTime As DateTime, ByVal LastAccessTime As DateTime, ByVal LastWriteTime As DateTime, ByVal FileAttributes As Int32)
' AddToLog("SetFileFileAttibutes =>" & "File name = " & FileName)
'End Sub
Private Sub SUB_CbFltCanFileBeDeletedN(ByVal Sender As CallbackFilter, ByVal FileName As String)
AddToLog("CanFileBeDeleted Notify =>" & "File name = " & FileName)
End Sub
Private Sub SUB_CbFltCanFileBeDeletedC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByRef DeleteFile As Boolean, ByRef UserContext As IntPtr, ByRef ProcessRequest As Boolean)

Dim gch As GCHandle = GCHandle.FromIntPtr(UserContext)
Dim tw As TextWriter = CType(gch.Target, TextWriter)
tw.WriteLine(Handle)



AddToLog("CanFileBeDeleted Control =>" & "File name = " & FileName)
End Sub
Private Sub SUB_CbFltRenameOrMoveFileEN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal NewFileName As String)

AddToLog("RenameOfMoveFile =>" & "File name = " & FileName)
End Sub
Private Sub SUB_CbFltRenameOrMoveFileEC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal NewFileName As String, ByRef UserContext As IntPtr, ByRef ProcessRequest As Boolean)

Dim gch As GCHandle = GCHandle.FromIntPtr(UserContext)
Dim tw As TextWriter = CType(gch.Target, TextWriter)
tw.WriteLine(Handle)

AddToLog("RenameOfMoveFile =>" & "File name = " & FileName & " - New file: " & NewFileName)
End Sub
Private Sub SUB_CbFltReadFileN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal Position As Long, ByVal BytesToRead As Int32)
AddToLog("ReadFile =>" & "File name = " & FileName)
End Sub
'Private Sub SUB_CbFltWriteFileN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal Position As Long, ByVal BytesToWrite As Int32, ByRref UserContext As IntPtr)
' AddToLog("Enum WriteFileN =>" & "File name = " & FileName)
'End Sub
Private Sub SUB_CbFltEnumerateDirectoryN(ByVal Sender As CallbackFilter, ByVal DirectoryName As String, ByVal FileName As String, ByVal CreationTime As DateTime, ByVal LastAccessTime As DateTime, ByVal LastWriteTime As DateTime, ByVal EndOfFile As Long, ByVal AllocationSize As Long, ByVal FileId As Long, ByVal FileAttributes As UInt32)
AddToLog("Enum directory =>" & "File name = " & FileName)
End Sub
Private Sub SUB_CbFltCloseFileN(ByVal Sender As CallbackFilter, ByVal FileName As String)
AddToLog("CloseFile =>" & "File name = " & FileName)
End Sub
' Private Sub SUB_CbFltSetFileSecurityN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal uint SecurityInformation, ByVal IntPtr SecurityDescriptor, ByVal Length As UInt32)
' AddToLog("Enum SetFileSecurity =>" & "File name = " & FileName)
' End Sub
Private Sub AddToLog(ByVal Valor As String)

ListBox1.Items.Add(Valor)
End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim DriveInstalado As Boolean
Dim VersionLow As Integer
Dim VersionHigh As Integer
CallbackFilter.SetRegistrationKey(keySerial)

ListBox1.CheckForIllegalCrossThreadCalls = False
gch.Free()

Dim serviceStatus As SERVICE_STATUS
DriveInstalado = False
CallbackFilter.GetDriverStatus(mProductName, DriveInstalado, VersionHigh, VersionLow, serviceStatus)
If DriveInstalado = True Then
AddToLog("Driver installed: " & VersionHigh & "." & VersionLow)
Else
MsgBox("Driver not installed.", MsgBoxStyle.Information, "Acronus")
End If

mFilter.OnOpenFileN = AddressOf SUB_CbFltOpenFileN
mFilter.OnSetAllocationSizeN = AddressOf SUB_CbFltSetAllocationSizeN
mFilter.OnSetEndOfFileN = AddressOf SUB_CbFltSetEndOfFileN
'mFilter.OnSetFileAttributesN = AddressOf SUB_CbFltSetFileAttributesN
mFilter.OnCanFileBeDeletedN = AddressOf SUB_CbFltCanFileBeDeletedN
mFilter.OnCanFileBeDeletedC = AddressOf SUB_CbFltCanFileBeDeletedC
mFilter.OnRenameOrMoveFileN = AddressOf SUB_CbFltRenameOrMoveFileEN
mFilter.OnRenameOrMoveFileC = AddressOf SUB_CbFltRenameOrMoveFileEC
mFilter.OnReadFileN = AddressOf SUB_CbFltReadFileN
'mFilter.OnWriteFileN = AddressOf SUB_CbFltWriteFileN
mFilter.OnEnumerateDirectoryN = AddressOf SUB_CbFltEnumerateDirectoryN
mFilter.OnCloseFileN = AddressOf SUB_CbFltCloseFileN
'mFilter.OnSetFileSecurityN = AddressOf SUB_CbFltSetFileSecurityN

End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

With mFilter
Dim filter As CbFlt.CbFltCallbackFlags
filter = filter Or CbFltCallbackFlags.ReadNotify
filter = filter Or CbFltCallbackFlags.CreateNotify
filter = filter Or CbFltCallbackFlags.RenameNotify
filter = filter Or CbFltCallbackFlags.RenameCallback
filter = filter Or CbFltCallbackFlags.SetSizesNotify
filter = filter Or CbFltCallbackFlags.DeleteNotify
filter = filter Or CbFltCallbackFlags.DeleteCallback
filter = filter Or CbFltCallbackFlags.SetBasicInfoNotify
filter = filter Or CbFltCallbackFlags.EnumerateDirectoryNotify
filter = filter Or CbFltCallbackFlags.OpenNotify
filter = filter Or CbFltCallbackFlags.CloseNotify

.AddFilterCallbackRule(txt_filter.Text, filter)
End With

Try
mFilter.AttachFilter(10000)
Catch ex As Exception
Throw
End Try

End Sub

End Class




Regards



Cristiano Moraes
#12853
Posted: 03/25/2010 03:30:42
by Vladimir Cherniga (EldoS Corp.)

If i have understood correctly you are trying to backup file during OnCanFileBeDeleted event. In this case you should open destination file with OpenFile() callback filter api. The best place to put this code is PostCreate and PostOpen file, than you should save this handle in UserContext parameter so you will be able to get this handle in the any following callbacks, until the last close request will arrive(in this case you should close handle). At the next step when OnCanFileBeDeletedC callback arrives you may create new file, than read data from deleting file and write to the new one. For read/write from/to filtered files inside callbacks you should utilize ReadFile/WriteFile CallbackFilter api. For details of using this apis look at the Encrypt sample and documentation.
#12862
Posted: 03/26/2010 10:33:44
by cristiano moraes (Standard support level)
Joined: 03/23/2010
Posts: 5

Hello Vladimir ! You are right, I am trying to do that. I tried, but I am getting error SPECIFIED CAST IS NOT VALID, when I try to write the data to the new file during OnCanFileBeDeleted event. Take a look in my code and see if you can help me please: ( I am doing a test with a small file, I mean, I tried to delete a file that has a 3k lenght of bytes.




Private Declare Function WriteFile Lib "kernel32" (ByVal hFile As IntPtr, ByVal lpBuffer As IntPtr, ByVal nNumberOfBytesToWrite As Int32, ByRef lpNumberOfBytesWritten As Int32, ByVal lpOverlapped As Overlapped) As Int32
Private Declare Function ReadFile Lib "kernel32.dll" (ByVal hFile As IntPtr, ByVal lpBuffer As IntPtr, ByVal nNumberOfBytesToRead As Int32, ByRef lpNumberOfBytesRead As Int32, ByVal lpOverlapped As Overlapped) As Int32
Declare Function VirtualAlloc Lib "kernel32" (ByVal lpAddress As IntPtr, ByVal dwSize As Int32, ByVal flAllocationType As Int32, ByVal flProtect As Int32) As IntPtr
Declare Auto Function GetDiskFreeSpace Lib "kernel32.dll" (ByVal lpRootPathName As String, ByRef lpSectorsPerCluster As UInt32, ByRef lpBytesPerSector As UInt32, ByRef lpNumberOfFreeClusters As UInt32, ByRef lpTotalNumberOfClusters As UInt32) As Integer


...
...
...
..

Private Sub SUB_CbFltPostOpenFileC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal DesiredAccess As UInt32, ByVal FileAttributes As UInt16, ByVal ShareMode As UInt16, ByVal Options As UInt32, ByVal CreateDisposition As UInt16, ByRef UserContext As IntPtr)

Dim newFileName As String

'open the new file to the new location c:\temporario\
newFileName = "c:\temporario\" & Path.GetFileName(FileName)
UserContext = GCHandle.Alloc(mFilter.OpenFile(newFileName))
'UserContext = (mFilter.OpenFile(newFileName)).DangerousGetHandle


AddToLog("Post Open File Control =>" & "File name = " & FileName)
End Sub




Private Sub SUB_CbFltCanFileBeDeletedC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByRef DeleteFile As Boolean, ByRef UserContext As IntPtr, ByRef ProcessRequest As Boolean)
Dim x As Int32
Dim ret As Integer
Dim ret2 As Integer
Dim newFileName As String
Dim NewFileHandle As SafeHandle
Dim DelFilehandle As SafeHandle
Dim mBuffer As IntPtr
Dim mBufferSize As Int32, SectorsPerCluster As Int32, BytesPerSector As Int32, NumberOfFreeClusters As Int32, TotalNumberOfClusters As Int32
Dim SystemInfo As Win32Api.SYSTEM_INFO = New Win32Api.SYSTEM_INFO

GetDiskFreeSpace(Path.GetPathRoot(FileName), SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters)
Call Win32Api.GetSystemInfo(SystemInfo)
mBufferSize = Math.Max(SystemInfo.dwPageSize, SectorsPerCluster * BytesPerSector)
mBuffer = VirtualAlloc(IntPtr.Zero, mBufferSize, &H1000, &H4)

newFileName = "c:\temporario\" & Path.GetFileName(FileName)
'creating the file destination
NewFileHandle = mFilter.CreateFile(newFileName)

'reading the file that will be delete
DelFilehandle = mFilter.OpenFile(FileName)
x = ReadFile(DelFilehandle.DangerousGetHandle, mBuffer, mBufferSize, ret, Nothing)

'writing data to the file destination ******ERROR SPECIFIED CAST IS NOT VALID ****************
x = WriteFile(GCHandle.FromIntPtr(UserContext).Target, mBuffer, mBufferSize, ret2, Nothing)

'closing the data file
mFilter.CloseFile(DelFilehandle)

AddToLog("CanFileBeDeleted Control =>" & "File name = " & FileName)
End Sub




Private Sub SUB_CbFltCloseFileC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal UserContext As IntPtr)
AddToLog("CloseFile Notify =>" & "File name = " & FileName)


GCHandle.FromIntPtr(UserContext).Free()

End Sub





Regards



Cristiano Moraes
#12863
Posted: 03/26/2010 10:45:57
by cristiano moraes (Standard support level)
Joined: 03/23/2010
Posts: 5

I found the cast error, now is almost working, I change the line


'writing data to the file destination ******ERROR SPECIFIED CAST IS NOT VALID ****************
x = WriteFile(GCHandle.FromIntPtr(UserContext).Target, mBuffer, mBufferSize, ret2, Nothing)



to



'writing data to the file destination ******ERROR SPECIFIED CAST IS NOT VALID ****************
x = WriteFile(UserContext, mBuffer, mBufferSize, ret2, Nothing)




The file has been created, but a empty file, what I am doing wrong ?
#12864
Posted: 03/26/2010 13:09:32
by Vladimir Cherniga (EldoS Corp.)

CallbackFilter.OpenFile() api can be used for opening existent file within callback. And the handle obtained with it help must be used from callbacks only. I think you should open existent file from PostCreateCB, not the new one that you are going to use for backup purposes. Then in Delete callback create new file with CallbackFilter.CreateFile(), get opened file handle from UserContext, read file and write to the created new one.
#12865
Posted: 03/26/2010 15:06:05
by cristiano moraes (Standard support level)
Joined: 03/23/2010
Posts: 5

Hello Vladimir,

I made the changes, but still creating a empty file, the PostCreateFileC does not rise, just the PostOpenFile, so, in this callback I open the existent file as you can see below and I changed the OnDelete callback to create and open the new file, read the old file and write to new file the data and I close the new file, the file has been created to new location, but it is empty.
I debug one example and I saw this debug:
Open File Notify => c:\cris.txt
Post Open File Control => c:\cris.txt => Context = 9442632
Delete File Control => c:\cris.txt => Context = 9442632
Delete File Notify => c:\cris.txt
Close File control => c:\cris.txt => context = 0
Close File control => c:\cris.txt => context = 9442632


CODE:

Private Sub SUB_CbFltPostCreateFileC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal DesiredAccess As UInt32, ByVal FileAttributes As UInt16, ByVal ShareMode As UInt16, ByVal Options As UInt32, ByVal CreateDisposition As UInt16, ByRef UserContext As IntPtr)
AddToLog("Post Create File Control =>" & "File name = " & FileName)
End Sub
Private Sub SUB_CbFltCreateFileN(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal DesiredAccess As UInt32, ByVal FileAttributes As UInt16, ByVal ShareMode As UInt16, ByVal Options As UInt32, ByVal CreateDisposition As UInt16)
AddToLog("Create File Notify =>" & "File name = " & FileName)
End Sub
Private Sub SUB_CbFltPostOpenFileC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal DesiredAccess As UInt32, ByVal FileAttributes As UInt16, ByVal ShareMode As UInt16, ByVal Options As UInt32, ByVal CreateDisposition As UInt16, ByRef UserContext As IntPtr)
UserContext = GCHandle.Alloc(mFilter.OpenFile(FileName))
AddToLog("Post Open File Control =>" & "File name = " & FileName & " context = " & CStr(UserContext))
End Sub

....
....
.....

Private Sub SUB_CbFltCanFileBeDeletedC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByRef DeleteFile As Boolean, ByRef UserContext As IntPtr, ByRef ProcessRequest As Boolean)
Dim x As Int32
Dim ret As Integer
Dim ret2 As Integer
Dim newFileName As String
Dim NewFileHandle As SafeHandle
Dim mBuffer As IntPtr
Dim mBufferSize As Int32, SectorsPerCluster As Int32, BytesPerSector As Int32, NumberOfFreeClusters As Int32, TotalNumberOfClusters As Int32
Dim SystemInfo As Win32Api.SYSTEM_INFO = New Win32Api.SYSTEM_INFO

GetDiskFreeSpace(Path.GetPathRoot(FileName), SectorsPerCluster, BytesPerSector, NumberOfFreeClusters, TotalNumberOfClusters)
Call Win32Api.GetSystemInfo(SystemInfo)
mBufferSize = Math.Max(SystemInfo.dwPageSize, SectorsPerCluster * BytesPerSector)
mBuffer = VirtualAlloc(IntPtr.Zero, mBufferSize, &H1000, &H4)

'creating the file destination
newFileName = "c:\temporario\" & Path.GetFileName(FileName)
NewFileHandle = mFilter.CreateFile(newFileName)
NewFileHandle = mFilter.OpenFile(newFileName)

'reading the file that will be delete
x = ReadFile(UserContext, mBuffer, mBufferSize, ret, Nothing)

'writing data to the file destination
x = WriteFile(GCHandle.Alloc(NewFileHandle), mBuffer, mBufferSize, ret2, Nothing)

mFilter.CloseFile(NewFileHandle)

AddToLog("CanFileBeDeleted Control =>" & "File name = " & FileName & " context = " & CStr(UserContext))
End Sub



.....
......
.....
.....


Private Sub SUB_CbFltCloseFileC(ByVal Sender As CallbackFilter, ByVal FileName As String, ByVal UserContext As IntPtr)
AddToLog("CloseFile Control =>" & "File name = " & FileName & " context = " & CStr(UserContext))


If UserContext <> IntPtr.Zero Then GCHandle.FromIntPtr(UserContext).Free()
End Sub


......
......
......


mFilter.OnOpenFileN = AddressOf SUB_CbFltOpenFileN
mFilter.OnSetAllocationSizeN = AddressOf SUB_CbFltSetAllocationSizeN
mFilter.OnSetEndOfFileN = AddressOf SUB_CbFltSetEndOfFileN
'mFilter.OnSetFileAttributesN = AddressOf SUB_CbFltSetFileAttributesN
mFilter.OnCanFileBeDeletedN = AddressOf SUB_CbFltCanFileBeDeletedN
mFilter.OnCanFileBeDeletedC = AddressOf SUB_CbFltCanFileBeDeletedC
mFilter.OnRenameOrMoveFileN = AddressOf SUB_CbFltRenameOrMoveFileEN
mFilter.OnRenameOrMoveFileC = AddressOf SUB_CbFltRenameOrMoveFileEC
mFilter.OnReadFileN = AddressOf SUB_CbFltReadFileN
'mFilter.OnWriteFileN = AddressOf SUB_CbFltWriteFileN
mFilter.OnEnumerateDirectoryN = AddressOf SUB_CbFltEnumerateDirectoryN
mFilter.OnCloseFileN = AddressOf SUB_CbFltCloseFileN
mFilter.OnCloseFileC = AddressOf SUB_CbFltCloseFileC
'mFilter.OnSetFileSecurityN = AddressOf SUB_CbFltSetFileSecurityN
mFilter.OnPostCreateFileC = AddressOf SUB_CbFltPostCreateFileC
mFilter.OnCreateFileN = AddressOf SUB_CbFltCreateFileN
mFilter.OnPostOpenFileC = AddressOf SUB_CbFltPostOpenFileC


......
......
......


With mFilter
Dim filter As CbFlt.CbFltCallbackFlags
filter = filter Or CbFltCallbackFlags.ReadNotify
'filter = filter Or CbFltCallbackFlags.CreateNotify
filter = filter Or CbFltCallbackFlags.RenameNotify
filter = filter Or CbFltCallbackFlags.RenameCallback
filter = filter Or CbFltCallbackFlags.SetSizesNotify
filter = filter Or CbFltCallbackFlags.DeleteNotify
filter = filter Or CbFltCallbackFlags.DeleteCallback
filter = filter Or CbFltCallbackFlags.SetBasicInfoNotify
filter = filter Or CbFltCallbackFlags.EnumerateDirectoryNotify
'filter = filter Or CbFltCallbackFlags.OpenNotify
filter = filter Or CbFltCallbackFlags.CloseNotify
filter = filter Or CbFltCallbackFlags.CloseCallback
filter = filter Or CbFltCallbackFlags.OpenCallback
filter = filter Or CbFltCallbackFlags.CreateCallback
filter = filter Or CbFltCallbackFlags.CreateNotify

.AddFilterCallbackRule(txt_filter.Text, filter)
End With

Try
mFilter.AttachFilter(10000)
Catch ex As Exception
Throw
End Try


......
......
......




......
......
......



Regards


Cristiano Moraes
#12866
Posted: 03/26/2010 15:55:46
by Vladimir Cherniga (EldoS Corp.)

In order to read data from FILTERED files use CallbackFilter.ReadFile() api. Use Win32 WriteFile() api in the case of writing data to the NON-FILTERED files .
#12867
Posted: 03/26/2010 21:55:01
by cristiano moraes (Standard support level)
Joined: 03/23/2010
Posts: 5

I used mfilter.openfile(..), mfilter.closefile(..), mfilter.createfile(..) but mfilter.readfile(..) and mfilter.writefile(..) does not exist and also CallbackFilter.ReadFile()..., I tried to search over the document (on-line, help file) and forum. I could not find anything how to call CallbackFilter.ReadFile() api
How Can I do that on VB.Net ?




Private mFilter As New CallbackFilter



Cristiano Moraes
#12896
Posted: 03/31/2010 02:43:39
by Vladimir Cherniga (EldoS Corp.)

Hi, sorry for misleading you. In all cases you should use win32 ReadFile and WriteFile api, but you must use handles obtained with CallbackFilter.OpenFile() only for those files, that are lays in callback filter path. If you get any problem writing file, check the number of bytes written and check error code with GetLastError() win32 api. It should help to locate the problem.
You may try to use CallbackFilter.CreateNonCbFile() api to create a new or open existing file. This function is more flexible with input parameters.
Also by EldoS: SecureBlackbox
200+ components and classes for digital security, signing, encryption and secure networking.

Reply

Statistics

Topic viewed 4948 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!